//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : API_GeoTransform.cpp Data : 30.09.14 Versione : 1.5i5 // Contenuto : Funzioni di trasformazione geometrica per API. // // // // Modifiche : 30.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "API.h" #include "API_Macro.h" #include "AuxTools.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EInConst.h" #include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //------------------------------------------------------------------------------- BOOL __stdcall EgtMove( int nId, double vVtMove[3], int nRefType) { INTVECTOR vIds ; vIds.push_back( nId) ; return ( EgtMove( vIds, vVtMove, nRefType) ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- bool EgtMove( INTVECTOR& vIds, const Vector3d& vtMove, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // se traslazione espressa in locale if ( nRefType == RTY_LOC) { // verifico che tutti gli oggetti siano nello stesso riferimento bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo traslazione singola if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->Translate( vIds[i], vtMove) ; } // eseguo traslazione dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->Translate( nI, vtMove)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // altrimenti in globale o in griglia else { Vector3d vtMoveG = vtMove ; // se griglia, porto il vettore in globale if ( nRefType == RTY_GRID) vtMoveG.ToGlob( pGeomDB->GetGridFrame()) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo traslazione singola if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->TranslateGlob( vIds[i], vtMoveG) ; } // eseguo traslazione dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->TranslateGlob( nI, vtMoveG)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sIds ; for ( size_t i = 0 ; i < vIds.size() ; ++ i) { if ( i > 0) sIds += "," ; sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") ; } string sLua = "EgtMove({" + sIds + "},{" + ToString( vtMove) + "}," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtRotate( int nId, double vPtAx[3], double vVtAx[3], double dAngRotDeg, int nRefType) { INTVECTOR vIds ; vIds.push_back( nId) ; return ( EgtRotate( vIds, vPtAx, vVtAx, dAngRotDeg, nRefType) ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- bool EgtRotate( INTVECTOR& vIds, const Point3d& ptAx, const Vector3d& vtAx, double dAngRotDeg, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // se rotazione espressa in locale if ( nRefType == RTY_LOC) { // verifico che tutti gli oggetti siano nello stesso riferimento bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo rotazione singola if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->Rotate( vIds[i], ptAx, vtAx, dAngRotDeg) ; } // eseguo rotazione dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->Rotate( nI, ptAx, vtAx, dAngRotDeg)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // altrimenti in globale o in griglia else { Point3d ptAxG = ptAx ; Vector3d vtAxG = vtAx ; // se griglia, porto punto e vettore in globale if ( nRefType == RTY_GRID) { ptAxG.ToGlob( pGeomDB->GetGridFrame()) ; vtAxG.ToGlob( pGeomDB->GetGridFrame()) ; } // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo rotazione singola if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->RotateGlob( vIds[i], ptAxG, vtAxG, dAngRotDeg) ; } // eseguo rotazione dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->RotateGlob( nI, ptAxG, vtAxG, dAngRotDeg)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sIds ; for ( size_t i = 0 ; i < vIds.size() ; ++ i) { if ( i > 0) sIds += "," ; sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") ; } string sLua = "EgtRotate({" + sIds + "},{" + ToString( ptAx) + "},{" + ToString( vtAx) + "}," + ToString( dAngRotDeg) + "," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtScale( int nId, const double vOrig[3], const double vX[3], const double vY[3], const double vZ[3], double dCoeffX, double dCoeffY, double dCoeffZ, int nRefType) { INTVECTOR vIds ; vIds.push_back( nId) ; // costruisco il riferimento di scalatura Frame3d frFrame ; if ( ! frFrame.Set( vOrig, vX, vY, vZ)) return FALSE ; // eseguo return ( EgtScale( vIds, frFrame, dCoeffX, dCoeffY, dCoeffZ, nRefType) ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- bool EgtScale( INTVECTOR& vIds, const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // se scalatura espressa in locale if ( nRefType == RTY_LOC) { // verifico che tutti gli oggetti siano nello stesso riferimento bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo scalatura singola if ( vIds[i] != GDB_ID_SEL) { bOk = bOk && pGeomDB->Scale( vIds[i], frRef, dCoeffX, dCoeffY, dCoeffZ) ; } // eseguo scalatura dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->Scale( nI, frRef, dCoeffX, dCoeffY, dCoeffZ)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // altrimenti in globale o in griglia else { Frame3d frRefG = frRef ; // se griglia, porto riferimento in globale if ( nRefType == RTY_GRID) frRefG.ToGlob( pGeomDB->GetGridFrame()) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo scalatura singola if ( vIds[i] != GDB_ID_SEL) { bOk = bOk && pGeomDB->ScaleGlob( vIds[i], frRefG, dCoeffX, dCoeffY, dCoeffZ) ; } // eseguo scalatura dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->ScaleGlob( nI, frRefG, dCoeffX, dCoeffY, dCoeffZ)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sIds ; for ( size_t i = 0 ; i < vIds.size() ; ++ i) { if ( i > 0) sIds += "," ; sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") ; } string sLua = "EgtScale({" + sIds + "},{{" + ToString( frRef.Orig()) + "},{" + ToString( frRef.VersX()) + "},{" + ToString( frRef.VersY()) + "},{" + ToString( frRef.VersZ()) + "}}," + ToString( dCoeffX) + "," + ToString( dCoeffY) + "," + ToString( dCoeffZ) + "," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtMirror( int nId, const double vPnt[3], const double vN[3], int nRefType) { INTVECTOR vIds ; vIds.push_back( nId) ; return ( EgtMirror( vIds, vPnt, vN, nRefType) ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- bool EgtMirror( INTVECTOR& vIds, const Point3d& ptP, const Vector3d& vtN, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // se specularità espressa in locale if ( nRefType == RTY_LOC) { // verifico che tutti gli oggetti siano nello stesso riferimento bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo specularità singola if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->Mirror( vIds[i], ptP, vtN) ; } // eseguo specularità dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->Mirror( nI, ptP, vtN)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // altrimenti in globale o in griglia else { Point3d ptPG = ptP ; Vector3d vtNG = vtN ; // se griglia, porto riferimento in globale if ( nRefType == RTY_GRID) { ptPG.ToGlob( pGeomDB->GetGridFrame()) ; vtNG.ToGlob( pGeomDB->GetGridFrame()) ; } // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo specularità singola if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->MirrorGlob( vIds[i], ptPG, vtNG) ; } // eseguo specularità dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->MirrorGlob( nI, ptPG, vtNG)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sIds ; for ( size_t i = 0 ; i < vIds.size() ; ++ i) { if ( i > 0) sIds += "," ; sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") ; } string sLua = "EgtMirror({" + sIds + "},{" + ToString( ptP) + "},{" + ToString( vtN) + "}," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtShear( int nId, const double vPnt[3], const double vN[3], const double vDir[3], double dCoeff, int nRefType) { INTVECTOR vIds ; vIds.push_back( nId) ; return ( EgtShear( vIds, vPnt, vN, vDir, dCoeff, nRefType) ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- bool EgtShear( INTVECTOR& vIds, const Point3d& ptP, const Vector3d& vtN, const Vector3d& vtDir, double dCoeff, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // se stiramento espresso in locale if ( nRefType == RTY_LOC) { // verifico che tutti gli oggetti siano nello stesso riferimento bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo stiramento singolo if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->Shear( vIds[i], ptP, vtN, vtDir, dCoeff) ; } // eseguo stiramento dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->Shear( nI, ptP, vtN, vtDir, dCoeff)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // altrimenti in globale o in griglia else { Point3d ptPG = ptP ; Vector3d vtNG = vtN ; Vector3d vtDirG = vtDir ; // se griglia, porto riferimento in globale if ( nRefType == RTY_GRID) { ptPG.ToGlob( pGeomDB->GetGridFrame()) ; vtNG.ToGlob( pGeomDB->GetGridFrame()) ; vtDirG.ToGlob( pGeomDB->GetGridFrame()) ; } // ciclo sul vettore degli identificativi for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { // eseguo stiramento singolo if ( vIds[i] != GDB_ID_SEL) { bOk = pGeomDB->ShearGlob( vIds[i], ptPG, vtNG, vtDirG, dCoeff) ; } // eseguo stiramento dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->ShearGlob( nI, ptPG, vtNG, vtDirG, dCoeff)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } } } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sIds ; for ( size_t i = 0 ; i < vIds.size() ; ++ i) { if ( i > 0) sIds += "," ; sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") ; } string sLua = "EgtShear({" + sIds + "},{" + ToString( ptP) + "},{" + ToString( vtN) + "},{" + ToString( vtDir) + "}," + ToString( dCoeff) + "," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtMoveGroup( int nId, double vVtMove[3]) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // eseguo traslazione singola if ( nId != GDB_ID_SEL) { bOk = pGeomDB->TranslateGroup( nId, vVtMove) ; } // eseguo traslazione dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->TranslateGroup( nI, vVtMove)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtRotateGroup( int nId, double vPtAx[3], double vVtAx[3], double dAngRotDeg) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // eseguo rotazione singola if ( nId != GDB_ID_SEL) { bOk = pGeomDB->RotateGroup( nId, vPtAx, vVtAx, dAngRotDeg) ; } // eseguo rotazione dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->RotateGroup( nI, vPtAx, vVtAx, dAngRotDeg)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtScaleGroup( int nId, const double vOrig[3], const double vX[3], const double vY[3], const double vZ[3], double dCoeffX, double dCoeffY, double dCoeffZ) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // costruisco il riferimento di scalatura Frame3d frFrame ; if ( ! frFrame.Set( vOrig, vX, vY, vZ)) bOk = false ; // eseguo scalatura singola if ( nId != GDB_ID_SEL) { bOk = bOk && pGeomDB->ScaleGroup( nId, frFrame, dCoeffX, dCoeffY, dCoeffZ) ; } // eseguo scalatura dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->ScaleGroup( nI, frFrame, dCoeffX, dCoeffY, dCoeffZ)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtMirrorGroup( int nId, const double vPnt[3], const double vN[3]) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // eseguo specularità singola if ( nId != GDB_ID_SEL) { bOk = pGeomDB->MirrorGroup( nId, vPnt, vN) ; } // eseguo specularità dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->MirrorGroup( nI, vPnt, vN)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtShearGroup( int nId, const double vPnt[3], const double vN[3], const double vDir[3], double dCoeff) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, FALSE) bool bOk = true ; // eseguo stiramento singolo if ( nId != GDB_ID_SEL) { bOk = pGeomDB->ShearGroup( nId, vPnt, vN, vDir, dCoeff) ; } // eseguo stiramento dei selezionati else { int nI = pGeomDB->GetFirstSelectedObj() ; while ( nI != GDB_ID_NULL && bOk) { if ( ! pGeomDB->ShearGroup( nI, vPnt, vN, vDir, dCoeff)) bOk = false ; nI = pGeomDB->GetNextSelectedObj() ; } } // restituisco risultato return ( bOk ? TRUE : FALSE) ; }