From 064fb6071914ff46001e052c761615810b2028ea Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 7 Aug 2015 10:48:19 +0000 Subject: [PATCH] EgtExecutor 1.6h2 : - aggiunta CreateSurfFlatRegion per EXE e LUA - aggiunta TrimCurveWithRegion per EXE e LUA - aggiunta ExtractSurfFrLoop per EXE e LUA. --- EXE_GdbCreateSurf.cpp | 61 ++++++++++++++++++++++++++++ EXE_GdbModifyCurve.cpp | 89 +++++++++++++++++++++++++++++++++++++++++ EXE_GdbModifySurf.cpp | 35 ++++++++++++++++ EgtExecutor.rc | Bin 11686 -> 11686 bytes LUA_GdbCreateSurf.cpp | 22 ++++++++++ LUA_GdbModifyCurve.cpp | 26 ++++++++++++ LUA_GdbModifySurf.cpp | 23 +++++++++++ 7 files changed, 256 insertions(+) diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp index 41f65fe..9ebed35 100644 --- a/EXE_GdbCreateSurf.cpp +++ b/EXE_GdbCreateSurf.cpp @@ -19,6 +19,7 @@ #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkSurfFlatRegion.h" #include "/EgtDev/Include/EGkStmStandard.h" #include "/EgtDev/Include/EGkStmFromCurves.h" #include "/EgtDev/Include/EGkStmFromTriangleSoup.h" @@ -29,6 +30,66 @@ using namespace std ; +//------------------------------------------------------------------------------- +int +ExeCreateSurfFlatRegion( int nParentId, INTVECTOR& vCrvIds) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nParentId = AdjustId( nParentId) ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // creo la regione piana + PtrOwner pSFR( CreateSurfFlatRegion()) ; + bOk = bOk && ( ! IsNull( pSFR)) ; + // creo le copie locali delle curve + bool bFirst = true ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) { + int nId = (( vCrvIds[i] != GDB_ID_SEL) ? vCrvIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // recupero riferimento della curva + Frame3d frCrv ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frCrv) ; + // recupero la curva + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && pCrv != nullptr ; + // ne faccio una copia + PtrOwner pCopCrv( ( bOk ? pCrv->Clone() : nullptr)) ; + bOk = bOk && ! IsNull( pCopCrv) ; + // se i riferimenti sono diversi, eseguo la trasformazione + if ( ! AreSameFrame( frCrv, frLoc)) + bOk = bOk && pCopCrv->LocToLoc( frCrv, frLoc) ; + // la assegno alla regione + if ( bFirst) { + bOk = bOk && pSFR->SetExtLoop( Release( pCopCrv)) ; + bFirst = false ; + } + else + bOk = bOk && pSFR->AddIntLoop( Release( pCopCrv)) ; + // passo al successivo + nId = (( vCrvIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSFR)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sIds ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) + sIds += ToString( vCrvIds[i]) + "," ; + sIds.pop_back() ; + string sLua = "EgtSurfFlatRegion(" + IdToString( nParentId) + ",{" + + sIds + "}," + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + //------------------------------------------------------------------------------- int ExeCreateSurfTmBBox( int nParentId, const BBox3d& b3Box, int nRefType) diff --git a/EXE_GdbModifyCurve.cpp b/EXE_GdbModifyCurve.cpp index e4449a7..6d128aa 100644 --- a/EXE_GdbModifyCurve.cpp +++ b/EXE_GdbModifyCurve.cpp @@ -25,9 +25,12 @@ #include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EGkIntersCurves.h" #include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkCurveLocal.h" +#include "/EgtDev/Include/EGkSurfFlatRegion.h" #include "/EgtDev/Include/EGkExtTExt.h" #include "/EgtDev/Include/EGkGdbIterator.h" #include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGkIntervals.h" #include "/EgtDev/Include/EgtPointerOwner.h" #include @@ -487,6 +490,92 @@ ExeTrimExtendCurveByLen( int nId, double dLen, const Point3d& ptNear, int nRefTy return bOk ; } +//---------------------------------------------------------------------------- +static int +MyTrimCurveWithRegion( int nCrvId, int nRegId, bool bInVsOut, bool bOn, int& nCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la regione + ISurfFlatRegion* pSFR = GetSurfFlatRegion( pGeomDB->GetGeoObj( nRegId)) ; + if ( pSFR == nullptr) + return GDB_ID_NULL ; + // recupero il riferimento della regione + Frame3d frReg ; + if ( ! pGeomDB->GetGlobFrame( nRegId, frReg)) + return GDB_ID_NULL ; + // recupero la curva + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // recupero la curva in locale alla regione + CurveLocal CrvLoc( pGeomDB, nCrvId, frReg) ; + if ( CrvLoc.Get() == nullptr) + return GDB_ID_NULL ; + // calcolo la classificazione della curva rispetto alla regione + CRVCVECTOR ccClass ; + if ( ! pSFR->GetCurveClassification( *CrvLoc.Get(), ccClass)) + return GDB_ID_NULL ; + // determino gli intervalli di curva da conservare + Intervals inOk ; + for ( auto& ccOne : ccClass) { + if ( ( bInVsOut && ccOne.nClass == CRVC_IN) || + ( ! bInVsOut && ccOne.nClass == CRVC_OUT) || + ( bOn && ( ccOne.nClass == CRVC_ON_P || ccOne.nClass == CRVC_ON_M))) + inOk.Add( ccOne.dParE, ccOne.dParS) ; + } + // recupero un intervallo di id contigui per tutte le parti + int nFirstId = pGeomDB->GetNewId() ; + if ( ! pGeomDB->ChangeId( nCrvId, nFirstId)) + return GDB_ID_NULL ; + int nCurrId = nFirstId ; + // eseguo la divisione + nCount = 0 ; + double dParS, dParE ; + bool bFound = inOk.GetFirst( dParS, dParE) ; + while ( bFound) { + // copio la curva + int nCopyId = pGeomDB->Copy( nCurrId, GDB_ID_NULL, nCurrId, GDB_AFTER) ; + ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nCopyId)) ; + if ( pCopyCrv == nullptr) + return GDB_ID_NULL ; + ++ nCount ; + // modifico l'originale + if ( ! pCrv->TrimStartEndAtParam( dParS, dParE)) + return GDB_ID_NULL ; + // la copia diventa il nuovo corrente + nCurrId = nCopyId ; + pCrv = pCopyCrv ; + // passo alla successiva divisione + bFound = inOk.GetNext( dParS, dParE) ; + } + // cancello l'ultima copia (se non c'erano intervalli validi è l'originale) + pGeomDB->Erase( nCurrId) ; + return nFirstId ; +} + +//---------------------------------------------------------------------------- +int +ExeTrimCurveWithRegion( int nCrvId, int nRegId, bool bInVsOut, bool bOn, int* pnCount) +{ + int nCount ; + int nFirstId = MyTrimCurveWithRegion( nCrvId, nRegId, bInVsOut, bOn, nCount) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTrimCurveWithRegion(" + ToString( nCrvId) + "," + + ToString( nRegId) + "," + + ToString( bInVsOut) + "," + + ToString( bOn) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + //---------------------------------------------------------------------------- int ExeSplitCurve( int nId, int nParts) diff --git a/EXE_GdbModifySurf.cpp b/EXE_GdbModifySurf.cpp index 0d0eb45..9226804 100644 --- a/EXE_GdbModifySurf.cpp +++ b/EXE_GdbModifySurf.cpp @@ -20,6 +20,7 @@ #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EgkCurveComposite.h" +#include "/EgtDev/Include/EgkSurfFlatRegion.h" #include "/EgtDev/Include/EgkSurfTriMesh.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EgtPointerOwner.h" @@ -56,6 +57,40 @@ ExeInvertSurface( const INTVECTOR& vIds) return bOk ; } +//---------------------------------------------------------------------------- +int +ExeExtractSurfFrLoop( int nId, int nLoop, int nDestGrpId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la superficie FlatRegion + const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pSfr != nullptr) ; + // recupero il riferimento della superficie + Frame3d frSurf ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frSurf) ; + // recupero il riferimento di destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ; + // richiedo la curva che costituisce il loop + PtrOwner pCrv( pSfr->GetLoop( nLoop)) ; + bOk = bOk && ! IsNull( pCrv) ; + // la porto nel riferimento destinazione + bOk = bOk && pCrv->LocToLoc( frSurf, frDest) ; + // la inserisco nel DB geometrico + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pCrv)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtExtractSurfFrLoop(" + ToString( nId) + ",{" + + ToString( nLoop) + "," + + ToString( nDestGrpId) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + return nNewId ; +} + //---------------------------------------------------------------------------- int ExeExtractSurfTmFacetLoops( int nId, int nFacet, int nDestGrpId, int* pnCount) diff --git a/EgtExecutor.rc b/EgtExecutor.rc index d5aa52ffd7ae0f9bf62187979361201789bd8e76..eec05f8fda3da4d2cb848395da6f42d7cb6cd43b 100644 GIT binary patch delta 79 zcmZ1$y)1geFE&P_&A-`PnSqoe*K!sx?>N)s4T4pSMw1=6k~jAW*?>e(i-FY$N+HxV MD8kglDS2=M09@c2W&i*H delta 79 zcmZ1$y)1geFE&QQ&A-`PnSqoe*K!sx?>N)s4T4pShLat+k~jAW*?>e(i-FY$N+HxV MD8kglDS2=M09%wAUH||9 diff --git a/LUA_GdbCreateSurf.cpp b/LUA_GdbCreateSurf.cpp index 76ea059..16b3c6e 100644 --- a/LUA_GdbCreateSurf.cpp +++ b/LUA_GdbCreateSurf.cpp @@ -25,6 +25,27 @@ using namespace std ; //------------------------------------------------------------------------------- static const double LIN_TOL_DEF = 0.05 ; + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfFlatRegion( lua_State* L) +{ + // 2 parametri : ParentId, CrvIds + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vCrvIds ; + LuaCheckParam( L, 2, vCrvIds) + LuaClearStack( L) ; + // creo una regione piana + int nId = ExeCreateSurfFlatRegion( nParentId, vCrvIds) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaCreateSurfTmBBox( lua_State* L) @@ -440,6 +461,7 @@ bool LuaInstallGdbCreateSurf( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFlatRegion", LuaCreateSurfFlatRegion) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmBBox", LuaCreateSurfTmBBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmBox", LuaCreateSurfTmBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPyramid", LuaCreateSurfTmPyramid) ; diff --git a/LUA_GdbModifyCurve.cpp b/LUA_GdbModifyCurve.cpp index 321fb78..93b0f07 100644 --- a/LUA_GdbModifyCurve.cpp +++ b/LUA_GdbModifyCurve.cpp @@ -264,6 +264,31 @@ LuaTrimExtendCurveByLen( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaTrimCurveWithRegion( lua_State* L) +{ + // 4 parametro : nCrvId, nRegId, bInVsOut, bOn + int nCrvId ; + LuaCheckParam( L, 1, nCrvId) + int nRegId ; + LuaCheckParam( L, 2, nRegId) + bool bInVsOut ; + LuaCheckParam( L, 3, bInVsOut) + bool bOn ; + LuaCheckParam( L, 4, bOn) + LuaClearStack( L) ; + // conservo le parti di curva desiderate + int nCount ; + int nNewId = ExeTrimCurveWithRegion( nCrvId, nRegId, bInVsOut, bOn, &nCount) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + return 2 ; +} + //---------------------------------------------------------------------------- static int LuaSplitCurve( lua_State* L) @@ -421,6 +446,7 @@ LuaInstallGdbModifyCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveEndAtParam", LuaTrimCurveEndAtParam) ; bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveStartEndAtParam", LuaTrimCurveStartEndAtParam) ; bOk = bOk && luaMgr.RegisterFunction( "EgtTrimExtendCurveByLen", LuaTrimExtendCurveByLen) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveWithRegion", LuaTrimCurveWithRegion) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurve", LuaSplitCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtPoint", LuaSplitCurveAtPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtSelfInters", LuaSplitCurveAtSelfInters) ; diff --git a/LUA_GdbModifySurf.cpp b/LUA_GdbModifySurf.cpp index ddb90a3..e25d648 100644 --- a/LUA_GdbModifySurf.cpp +++ b/LUA_GdbModifySurf.cpp @@ -37,6 +37,28 @@ LuaInvertSurf( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaExtractSurfFrLoop( lua_State* L) +{ + // 3 parametri : nId, nLoop, nDestGrpId + int nId ; + LuaCheckParam( L, 1, nId) + int nLoop ; + LuaCheckParam( L, 2, nLoop) + int nDestGrpId ; + LuaCheckParam( L, 3, nDestGrpId) + LuaClearStack( L) ; + // eseguo inversione superfici + int nNewId = ExeExtractSurfFrLoop( nId, nLoop, nDestGrpId) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //---------------------------------------------------------------------------- static int LuaExtractSurfTmFacetLoops( lua_State* L) @@ -86,6 +108,7 @@ LuaInstallGdbModifySurf( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtInvertSurf", LuaInvertSurf) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfFrLoop", LuaExtractSurfFrLoop) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmFacetLoops", LuaExtractSurfTmFacetLoops) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeSurfTm", LuaExplodeSurfTm) ; return bOk ;