//---------------------------------------------------------------------------- // EgalTech 2014-2015 //---------------------------------------------------------------------------- // File : EXE_GeoTransform.cpp Data : 04.05.15 Versione : 1.6e1 // Contenuto : Funzioni di trasformazione geometrica per EXE. // // // // Modifiche : 30.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" #include "AuxTools.h" #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //------------------------------------------------------------------------------- bool ExeTransform( const INTVECTOR& vIds, const Frame3d& frRef, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // se trasformazione 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo trasformazione IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; if ( pGObj == nullptr || ! pGObj->ToGlob( frRef)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } // altrimenti in globale o in griglia else { Frame3d frRefG = frRef ; // se griglia, porto il vettore 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo trasformazione IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; if ( pGObj == nullptr || ! pGObj->ToGlob( frRefG)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTransform({" + IdListToString( vIds) + "},{{" + ToString( frRef.Orig()) + "},{" + ToString( frRef.VersX()) + "},{" + ToString( frRef.VersY()) + "},{" + ToString( frRef.VersZ()) + "}}," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeMove( const 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo traslazione if ( ! pGeomDB->Translate( nId, vtMove)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo traslazione if ( ! pGeomDB->TranslateGlob( nId, vtMoveG)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtMove({" + IdListToString( vIds) + "},{" + ToString( vtMove) + "}," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeRotate( const 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo rotazione if ( ! pGeomDB->Rotate( nId, ptAx, vtAx, dAngRotDeg)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo rotazione if ( ! pGeomDB->RotateGlob( nId, ptAxG, vtAxG, dAngRotDeg)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtRotate({" + IdListToString( vIds) + "},{" + ToString( ptAx) + "},{" + ToString( vtAx) + "}," + ToString( dAngRotDeg) + "," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeScale( const 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo scalature if ( ! pGeomDB->Scale( nId, frRef, dCoeffX, dCoeffY, dCoeffZ)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo scalature if ( ! pGeomDB->ScaleGlob( nId, frRefG, dCoeffX, dCoeffY, dCoeffZ)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtScale({" + IdListToString( vIds) + "},{{" + 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 ExeMirror( const 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo riflessione if ( ! pGeomDB->Mirror( nId, ptP, vtN)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo riflessione if ( ! pGeomDB->MirrorGlob( nId, ptPG, vtNG)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtMirror({" + IdListToString( vIds) + "},{" + ToString( ptP) + "},{" + ToString( vtN) + "}," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeShear( const 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo stiramento if ( ! pGeomDB->Shear( nId, ptP, vtN, vtDir, dCoeff)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : 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) { int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; while ( nId != GDB_ID_NULL) { // eseguo stiramento if ( ! pGeomDB->ShearGlob( nId, ptPG, vtNG, vtDirG, dCoeff)) bOk = false ; // passo alla successiva nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; } } } ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtShear({" + IdListToString( vIds) + "},{" + ToString( ptP) + "},{" + ToString( vtN) + "},{" + ToString( vtDir) + "}," + ToString( dCoeff) + "," + RefTypeToString( nRefType) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeMoveGroup( int nId, const Vector3d& vtMove) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // eseguo traslazione ( solo singola) bool bOk = pGeomDB->TranslateGroup( nId, vtMove) ; ExeSetModified() ; // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeRotateGroup( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dAngRotDeg) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // eseguo rotazione ( solo singola) bool bOk = pGeomDB->RotateGroup( nId, ptAx, vtAx, dAngRotDeg) ; ExeSetModified() ; // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeScaleGroup( int nId, const Frame3d& frFrame, double dCoeffX, double dCoeffY, double dCoeffZ) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // eseguo scalatura ( solo singola) bool bOk = pGeomDB->ScaleGroup( nId, frFrame, dCoeffX, dCoeffY, dCoeffZ) ; ExeSetModified() ; // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeMirrorGroup( int nId, const Point3d& ptP, const Vector3d& vtN) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // eseguo riflessione ( solo singola) bool bOk = pGeomDB->MirrorGroup( nId, ptP, vtN) ; ExeSetModified() ; // restituisco risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeShearGroup( int nId, const Point3d& ptP, const Vector3d& vtN, const Vector3d& vtDir, double dCoeff) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // eseguo stiramento ( solo singolo) bool bOk = pGeomDB->ShearGroup( nId, ptP, vtN, vtDir, dCoeff) ; ExeSetModified() ; // restituisco risultato return bOk ; }