From 611c08bb4c1ea6104bcea3f5d4d276789138a61a Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Wed, 13 Mar 2024 09:24:16 +0100 Subject: [PATCH] EgtExecutor : - aggiunta funzione Exe e Lua SurfTmMoveFacet. --- EXE_GdbModifySurf.cpp | 60 +++++++++++++++++++++++++++++++++++++------ LUA_GdbModifySurf.cpp | 25 ++++++++++++++++++ 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/EXE_GdbModifySurf.cpp b/EXE_GdbModifySurf.cpp index 17366bb..9c7c941 100644 --- a/EXE_GdbModifySurf.cpp +++ b/EXE_GdbModifySurf.cpp @@ -77,7 +77,7 @@ MyExplodeSurfTriMesh( int nId, int& nCount) return GDB_ID_NULL ; // recupero il numero di componenti connesse int nParts = pStm->GetPartCount() ; - // se ci sono pi� parti, separo queste + // se ci sono più parti, separo queste if ( nParts > 1) { int nFirstId = GDB_ID_NULL ; nCount = 0 ; @@ -296,7 +296,7 @@ ExeSurfFrSubtract( int nId1, int nId2) bOk = bOk && ( pSfr2L != nullptr) ; // eseguo la sottrazione della seconda superficie dalla prima bOk = bOk && pSfr1->Subtract( *pSfr2L) ; - // se il risultato � vuoto, cancello la FlatRegion + // se il risultato è vuoto, cancello la FlatRegion if ( bOk && ! pSfr1->IsValid()) pGeomDB->Erase( nId1) ; ExeSetModified() ; @@ -328,7 +328,7 @@ ExeSurfFrIntersect( int nId1, int nId2) bOk = bOk && ( pSfr2L != nullptr) ; // eseguo l'intersezione tra le due superfici bOk = bOk && pSfr1->Intersect( *pSfr2L) ; - // se il risultato � vuoto, cancello la FlatRegion + // se il risultato è vuoto, cancello la FlatRegion if ( bOk && ! pSfr1->IsValid()) pGeomDB->Erase( nId1) ; ExeSetModified() ; @@ -353,7 +353,7 @@ ExeSurfFrOffset( int nId, double dDist, int nType) bool bOk = ( pSfr != nullptr) ; // eseguo l'offset bOk = bOk && pSfr->Offset( dDist, nType) ; - // se il risultato � vuoto, cancello la FlatRegion + // se il risultato è vuoto, cancello la FlatRegion if ( bOk && ! pSfr->IsValid()) pGeomDB->Erase( nId) ; ExeSetModified() ; @@ -443,11 +443,11 @@ bool ExeSurfTmMoveVertex( int nId, int nVert, const Point3d& ptNewVert, int nRefType, bool bUpdate) { IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + VERIFY_GEOMDB( pGeomDB, false) // recupero la superficie ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; bool bOk = ( pStm != nullptr) ; - // recupero il riferimento in cui � immersa la superficie + // recupero il riferimento in cui è immersa la superficie Frame3d frStm ; bOk = bOk && pGeomDB->GetGlobFrame( nId, frStm) ; // eseguo la modifica @@ -475,6 +475,50 @@ ExeSurfTmMoveVertex( int nId, int nVert, const Point3d& ptNewVert, int nRefType, return bOk ; } +//------------------------------------------------------------------------------- +bool +ExeSurfTmMoveFacet( int nId, int nFacet, const Vector3d& vtMove, int nRefType, bool bUpdate) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie + ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pStm != nullptr) ; + // recupero il riferimento in cui è immersa la superficie + Frame3d frStm ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frStm) ; + // porto in locale il movimento + Vector3d vtMoveL = GetVectorLocal( pGeomDB, vtMove, nRefType, frStm) ; + // recupero tutti i vertici della faccia + INTVECTOR vVert ; + bOk = bOk && pStm->GetAllVertInFacet( nFacet, vVert) ; + // sposto tutti i vertici della faccia della quantità desiderata + if ( bOk) { + for ( const auto nVert : vVert) { + // recupero la posizione originale del vertice + Point3d ptV ; + if ( pStm->GetVertex( nVert, ptV)) + pStm->MoveVertex( nVert, ptV + vtMoveL) ; + } + } + // se richiesto, semplificazione della trimesh + if ( bUpdate) + bOk = bOk && pStm->DoCompacting() ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmMoveFacet(" + IdToString( nId) + "," + + ToString( nFacet) + ",{" + + ToString( vtMove) + "}," + + RefTypeToString( nRefType) + "," + + ( bUpdate ? "true" : "false") + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + //------------------------------------------------------------------------------- static int MySurfTmToTriangles( int nId, int& nCount) @@ -487,7 +531,7 @@ MySurfTmToTriangles( int nId, int& nCount) return GDB_ID_NULL ; // recupero il numero di triangoli int nTria = pStm->GetTriangleCount() ; - // se ci sono pi� triangoli, li separo + // se ci sono più triangoli, li separo if ( nTria > 1) { // copio tutti triangoli int nFirstId = GDB_ID_NULL ; @@ -513,7 +557,7 @@ MySurfTmToTriangles( int nId, int& nCount) // restituisco risultati return nFirstId ; } - // non devo fare alcunch� + // non devo fare alcunché nCount = 1 ; return nId ; } diff --git a/LUA_GdbModifySurf.cpp b/LUA_GdbModifySurf.cpp index 03c9349..9e106dc 100644 --- a/LUA_GdbModifySurf.cpp +++ b/LUA_GdbModifySurf.cpp @@ -187,6 +187,30 @@ LuaSurfTmMoveVertex( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmMoveFacet( lua_State* L) +{ + // 3 o 4 o 5 parametri : nId, nFacet, vtMove [, nRefId] [, bUpdate] + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + Vector3d vtMove ; + LuaCheckParam( L, 3, vtMove) + int nRefType = RTY_DEFAULT ; + bool bUpdate = true ; + if ( LuaGetParam( L, 4, nRefType)) + LuaGetParam( L, 5, bUpdate) ; + else + LuaGetParam( L, 4, bUpdate) ; + LuaClearStack( L) ; + // sposto la faccia di indice dato della trimesh + bool bOk = ExeSurfTmMoveFacet( nId, nFacet, vtMove, nRefType, bUpdate) ; + LuaSetParam( L, bOk) ; + return 1 ; +} + //---------------------------------------------------------------------------- static int LuaSurfTmToTriangles( lua_State* L) @@ -491,6 +515,7 @@ LuaInstallGdbModifySurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrOffset", LuaSurfFrOffset) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrOffsetAdv", LuaSurfFrOffsetAdv) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmMoveVertex", LuaSurfTmMoveVertex) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmMoveFacet", LuaSurfTmMoveFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmToTriangles", LuaSurfTmToTriangles) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRemoveFacet", LuaSurfTmRemoveFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSwapFacets", LuaSurfTmSwapFacets) ;