From 90449cad408cdc30049293e65a900437ae12d163 Mon Sep 17 00:00:00 2001 From: DarioS Date: Fri, 7 Jul 2023 17:07:16 +0200 Subject: [PATCH] EgtExecutor 2.5g1 : - aggiunte funzioni Exe e Lua SurfTmVertexCount, SurfTmGetVertex, SurfTmGetNearestVertex, SurfTmGetAllVertInFacet e SurfTmMoveVertex. --- EXE_GdbGetSurf.cpp | 80 +++++++++++++++++++++++++++++--- EXE_GdbModifySurf.cpp | 47 +++++++++++++++++-- EgtExecutor.rc | Bin 18890 -> 18890 bytes LUA_GdbGetSurf.cpp | 104 ++++++++++++++++++++++++++++++++++++++---- LUA_GdbModifySurf.cpp | 25 ++++++++++ 5 files changed, 237 insertions(+), 19 deletions(-) diff --git a/EXE_GdbGetSurf.cpp b/EXE_GdbGetSurf.cpp index 21997fa..8113edc 100644 --- a/EXE_GdbGetSurf.cpp +++ b/EXE_GdbGetSurf.cpp @@ -28,6 +28,7 @@ #include "/EgtDev/Include/EGkSurfFlatRegion.h" #include "/EgtDev/Include/EGkSurfTriMesh.h" #include "/EgtDev/Include/EGkSurfBezier.h" +#include "/EgtDev/Include/EGkDistPointSurfTm.h" #include "/EgtDev/Include/EGkSurfLocal.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -367,16 +368,16 @@ ExeSurfFrGetZigZagInfill( int nId, int nDestGrpId, double dStep, double dAng, bo //---------------------------------------------------------------------------- int -ExeSurfTmPartCount( int nId) +ExeSurfTmVertexCount( int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, -1) + VERIFY_GEOMDB( pGeomDB, 0) // recupero la superficie trimesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; if ( pStm == nullptr) - return -1 ; - // recupero il numero di parti - return pStm->GetPartCount() ; + return 0 ; + // recupero il numero di vertici + return pStm->GetVertexCount() ; } //---------------------------------------------------------------------------- @@ -393,6 +394,59 @@ ExeSurfTmFacetCount( int nId) return pStm->GetFacetCount() ; } +//---------------------------------------------------------------------------- +int +ExeSurfTmPartCount( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return -1 ; + // recupero il numero di parti + return pStm->GetPartCount() ; +} + +//----------------------------------------------------------------------------- +bool +ExeSurfTmGetVertex( int nId, int nVert, int nRefId, Point3d& ptVert) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // recupero il vertice di indice dato + if ( ! pStm->GetVertex( nVert, ptVert)) + return false ; + // gestione trasformazioni ( eventuali) + return TransformPoint( pGeomDB, nId, nRefId, ptVert) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSurfTmGetNearestVertex( int nId, const Point3d& ptNear, int nRefId, int& nVert, Point3d& ptVert) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // porto il punto Near nel riferimento dell'entità + Point3d ptNearL = ptNear ; + if ( ! InvTransformPoint( pGeomDB, nId, nRefId, ptNearL)) + return false ; + // recupero il vertice più vicino della superficie + nVert = GetSurfTmNearestVertex( ptNearL, *pStm) ; + if ( ! pStm->GetVertex( nVert, ptVert)) + return false ; + // gestione trasformazioni ( eventuali) + return TransformPoint( pGeomDB, nId, nRefId, ptVert) ; +} + //---------------------------------------------------------------------------- int ExeSurfTmFacetFromTria( int nId, int nT) @@ -936,6 +990,20 @@ ExeCopySurfTmFacet( int nId, int nFacet, int nDestGrpId) return nFacId ; } +//----------------------------------------------------------------------------- +bool +ExeSurfTmGetAllVertInFacet( int nId, int nFacet, INTVECTOR& vVert) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // recupero l'elenco dei vertici nella faccia + return pStm->GetAllVertInFacet( nFacet, vVert) ; +} + //----------------------------------------------------------------------------- bool ExeSurfTmGetFacetBBox( int nId, int nFacet, int nFlag, BBox3d& b3Box) @@ -1344,4 +1412,4 @@ ExeExtractSurfBezierLoops( int nId, int nDestGrpId, int* pnCount) if ( pnCount != nullptr) *pnCount = nCount ; return nFirstId ; -} \ No newline at end of file +} diff --git a/EXE_GdbModifySurf.cpp b/EXE_GdbModifySurf.cpp index d40bd50..f24a13c 100644 --- a/EXE_GdbModifySurf.cpp +++ b/EXE_GdbModifySurf.cpp @@ -410,6 +410,43 @@ ExeSurfFrRotateSimpleNoCollision( int nId1, int nId2, const Point3d& ptCen, doub return ( bOk && CAvSimpleSurfFrMove( *pSfr1, *pSfr2L).Rotate(ptCenL, dAngDeg)) ; } +//------------------------------------------------------------------------------- +bool +ExeSurfTmMoveVertex( int nId, int nVert, const Point3d& ptNewVert, int nRefType, bool bUpdate) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // 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) ; + // eseguo la modifica + if ( bOk) { + // porto il nuovo vertice nel riferimento della superficie + Point3d ptNewVertL = GetPointLocal( pGeomDB, ptNewVert, nRefType, frStm) ; + // eseguo la modifica + bOk = pStm->MoveVertex( nVert, ptNewVertL) ; + // se richiesto, semplificazione della trimesh + if ( bUpdate) + bOk = bOk && pStm->DoCompacting() ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmMoveVertex(" + IdToString( nId) + "," + + ToString( nVert) + ",{" + + ToString( ptNewVert) + "}," + + 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) @@ -468,7 +505,7 @@ ExeSurfTmToTriangles( int nId, int* pnCount) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLua = "EgtSurfTmToTriangles(" + ToString( nId) + ")" + + string sLua = "EgtSurfTmToTriangles(" + IdToString( nId) + ")" + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -492,7 +529,7 @@ ExeSurfTmRemoveFacet( int nId, int nFacet) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLua = "EgtSurfTmRemoveFacet(" + ToString( nId) + "," + + string sLua = "EgtSurfTmRemoveFacet(" + IdToString( nId) + "," + ToString( nFacet) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -515,7 +552,7 @@ ExeSurfTmSwapFacets( int nId, int nFacet1, int nFacet2) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLua = "EgtSurfTmSwapFacets(" + ToString( nId) + "," + + string sLua = "EgtSurfTmSwapFacets(" + IdToString( nId) + "," + ToString( nFacet1) + "," + ToString( nFacet2) + ")" + " -- Ok=" + ToString( bOk) ; @@ -539,7 +576,7 @@ ExeSurfTmRemovePart( int nId, int nPart) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLua = "EgtSurfTmRemovePart(" + ToString( nId) + "," + + string sLua = "EgtSurfTmRemovePart(" + IdToString( nId) + "," + ToString( nPart) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -571,7 +608,7 @@ ExeCutSurfTmPlane( int nId, const Point3d& ptOn, const Vector3d& vtN, bool bSave ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLua = "EgtCutSurfTmPlane(" + ToString( nId) + ",{" + + string sLua = "EgtCutSurfTmPlane(" + IdToString( nId) + ",{" + ToString( ptOn) + "},{" + ToString( vtN) + "}," + ( bSaveOnEq ? "true" : "false") + "," + diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 6eee72644fa65b066b558129e022231bfe73b709..1b98ab1695ef6ce72d629899e56cacbe2b4e40ea 100644 GIT binary patch delta 105 zcmX>#neo(Q#tq-tSj`!97z{W6W^-m{P6sj^xfZj)#f~#g-XK^35})kImAtu6$O0yJ US`4aQPzqIjgCatGoKlWD0Dy8HfB*mh delta 105 zcmX>#neo(Q#tq-tSj`x87>qanW^-m{P6IL=xfZj)#f~#g-XK^35})kImAtu6$O0yJ US`4aQPzqIjgCatGoKlWD0D<-%hyVZp diff --git a/LUA_GdbGetSurf.cpp b/LUA_GdbGetSurf.cpp index 43935f4..20f347f 100644 --- a/LUA_GdbGetSurf.cpp +++ b/LUA_GdbGetSurf.cpp @@ -270,18 +270,15 @@ LuaSurfFrGetZigZagInfill( lua_State* L) //---------------------------------------------------------------------------- static int -LuaSurfTmPartCount( lua_State* L) +LuaSurfTmVertexCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; - // recupero il numero di parti della superficie trimesh - int nParts = ExeSurfTmPartCount( nId) ; - if ( nParts >= 0) - LuaSetParam( L, nParts) ; - else - LuaSetParam( L) ; + // recupero il numero di vertici della superficie trimesh + int nNbr = ExeSurfTmVertexCount( nId) ; + LuaSetParam( L, nNbr) ; return 1 ; } @@ -299,6 +296,72 @@ LuaSurfTmFacetCount( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmPartCount( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il numero di parti della superficie trimesh + int nParts = ExeSurfTmPartCount( nId) ; + if ( nParts >= 0) + LuaSetParam( L, nParts) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmGetVertex( lua_State* L) +{ + // 2 o 3 parametri : Id, nVert, [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nVert ; + LuaCheckParam( L, 2, nVert) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il vertice di indice dato (0-based) + Point3d ptVert ; + bool bOk = ExeSurfTmGetVertex( nId, nVert, nRefId, ptVert) ; + if ( bOk) + LuaSetParam( L, ptVert) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmGetNearestVertex( lua_State* L) +{ + // 2 o 3 parametri : Id, ptNear [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptNear ; + LuaCheckParam( L, 2, ptNear) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il vertice più vicino della superficie + int nVert ; + Point3d ptVert ; + bool bOk = ExeSurfTmGetNearestVertex( nId, ptNear, nRefId, nVert, ptVert) ; + if ( bOk) { + LuaSetParam( L, nVert) ; + LuaSetParam( L, ptVert) ; + } + else { + LuaSetParam( L) ; + LuaSetParam( L) ; + } + return 2 ; +} + //---------------------------------------------------------------------------- static int LuaSurfTmFacetFromTria( lua_State* L) @@ -319,6 +382,27 @@ LuaSurfTmFacetFromTria( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmGetAllVertInFacet( lua_State* L) +{ + // 2 parametri : nId, nFacet + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + LuaClearStack( L) ; + // recupero l'elenco dei vertici nella faccia + INTVECTOR vVert ; + bool bOk = ExeSurfTmGetAllVertInFacet( nId, nFacet, vVert) ; + // restituisco il risultato + if ( bOk) + LuaSetParam( L, vVert) ; + else + LuaSetParam( L) ; + return 1 ; +} + //---------------------------------------------------------------------------- static int LuaSurfTmGetFacetBBox( lua_State* L) @@ -961,9 +1045,13 @@ LuaInstallGdbGetSurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrMoveSimpleNoCollision", LuaSurfFrMoveSimpleNoCollision) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrRotateSimpleNoCollision", LuaSurfFrRotateSimpleNoCollision) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetSurfFrZigZagInfill", LuaSurfFrGetZigZagInfill) ; - bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPartCount", LuaSurfTmPartCount) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmVertexCount", LuaSurfTmVertexCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCount", LuaSurfTmFacetCount) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPartCount", LuaSurfTmPartCount) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetVertex", LuaSurfTmGetVertex) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetNearestVertex", LuaSurfTmGetNearestVertex) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetFromTria", LuaSurfTmFacetFromTria) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetAllVertInFacet", LuaSurfTmGetAllVertInFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBox", LuaSurfTmGetFacetBBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBoxGlob", LuaSurfTmGetFacetBBoxGlob) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBoxRef", LuaSurfTmGetFacetBBoxRef) ; diff --git a/LUA_GdbModifySurf.cpp b/LUA_GdbModifySurf.cpp index db04052..d865e4d 100644 --- a/LUA_GdbModifySurf.cpp +++ b/LUA_GdbModifySurf.cpp @@ -141,6 +141,30 @@ LuaSurfFrOffset( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmMoveVertex( lua_State* L) +{ + // 3 o 4 o 5 parametri : nId, nVert, ptNewVert [, nRefId] [, bUpdate] + int nId ; + LuaCheckParam( L, 1, nId) + int nVert ; + LuaCheckParam( L, 2, nVert) + Point3d ptNewVert ; + LuaCheckParam( L, 3, ptNewVert) + int nRefType = RTY_DEFAULT ; + bool bUpdate = true ; + if ( LuaGetParam( L, 4, nRefType)) + LuaGetParam( L, 5, bUpdate) ; + else + LuaGetParam( L, 4, bUpdate) ; + LuaClearStack( L) ; + // sposto il vertice di indice dato della trimesh + bool bOk = ExeSurfTmMoveVertex( nId, nVert, ptNewVert, nRefType, bUpdate) ; + LuaSetParam( L, bOk) ; + return 1 ; +} + //---------------------------------------------------------------------------- static int LuaSurfTmToTriangles( lua_State* L) @@ -376,6 +400,7 @@ LuaInstallGdbModifySurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrSubtract", LuaSurfFrSubtract) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrIntersect", LuaSurfFrIntersect) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrOffset", LuaSurfFrOffset) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmMoveVertex", LuaSurfTmMoveVertex) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmToTriangles", LuaSurfTmToTriangles) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRemoveFacet", LuaSurfTmRemoveFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSwapFacets", LuaSurfTmSwapFacets) ;