diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp index b1ddc16..7c2cf3a 100644 --- a/EXE_GdbCreateSurf.cpp +++ b/EXE_GdbCreateSurf.cpp @@ -354,7 +354,7 @@ MyCreateSurfTmPlaneInBBox( int nParentId, const Point3d& ptP, const Vector3d& vt // costruisco il piano nel box Plane3d plPlane ; plPlane.Set( ptP, vtN) ; - PtrOwner pStm( GetSurfTriMeshPlaneInBox( plPlane, b3Box)) ; + PtrOwner pStm( GetSurfTriMeshPlaneInBox( plPlane, b3Box, true, false)) ; if ( IsNull( pStm)) return GDB_ID_NULL ; // recupero il riferimento locale del gruppo destinazione @@ -534,12 +534,12 @@ MyCreateSurfTmConvexHullInBBox( int nParentId, int nId, const BBox3d& b3Box, int return MyCreateSurfTmPlaneInBBox( nParentId, vTria[nPlane1].GetP( 0), vTria[nPlane1].GetN(), b3Box, nRefType) ; // altrimenti due piani validi Polygon3d Polyg1 ; - if ( ! Polyg1.FromPlaneTrimmedWithBox( vTria[nPlane1].GetPlane(), b3Box.GetMin(), b3Box.GetMax())) + if ( ! Polyg1.FromPlaneTrimmedWithBox( vTria[nPlane1].GetPlane(), b3Box.GetMin(), b3Box.GetMax(), true, false)) return GDB_ID_NULL ; Polygon3d Polyg2 ; - if ( ! Polyg2.FromPlaneTrimmedWithBox( vTria[nPlane2].GetPlane(), b3Box.GetMin(), b3Box.GetMax())) + if ( ! Polyg2.FromPlaneTrimmedWithBox( vTria[nPlane2].GetPlane(), b3Box.GetMin(), b3Box.GetMax(), true, false)) return GDB_ID_NULL ; - if ( ! Polyg1.Trim( Polyg2, true, true) || ! Polyg2.Trim( Polyg1, true, false)) + if ( ! Polyg1.Trim( Polyg2, true, true, false) || ! Polyg2.Trim( Polyg1, true, false, false)) return GDB_ID_NULL ; // creo la trimesh dalle due facce PtrOwner pChStm( CreateSurfTriMesh()) ; diff --git a/EXE_GdbGetCurve.cpp b/EXE_GdbGetCurve.cpp index 092a849..d8f8894 100644 --- a/EXE_GdbGetCurve.cpp +++ b/EXE_GdbGetCurve.cpp @@ -114,7 +114,7 @@ ExeCurveIsClosed( int nId) //---------------------------------------------------------------------------- bool -ExeCurveIsFlat( int nId, Plane3d& Plane, double dToler) +ExeCurveIsFlat( int nId, Plane3d& Plane, bool bUseExtrusion, double dToler) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) @@ -124,7 +124,7 @@ ExeCurveIsFlat( int nId, Plane3d& Plane, double dToler) // recupero la curva ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; // ne verifico la planarità - return ( pCurve != nullptr && pCurve->IsFlat( Plane, dToler)) ; + return ( pCurve != nullptr && pCurve->IsFlat( Plane, bUseExtrusion, dToler)) ; } //---------------------------------------------------------------------------- diff --git a/EXE_GdbModifyCurve.cpp b/EXE_GdbModifyCurve.cpp index 3638b92..f6f2674 100644 --- a/EXE_GdbModifyCurve.cpp +++ b/EXE_GdbModifyCurve.cpp @@ -35,6 +35,7 @@ #include "/EgtDev/Include/EGkGdbIterator.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGkIntervals.h" +#include "/EgtDev/Include/EGkPolygon3d.h" #include "/EgtDev/Include/EgtPointerOwner.h" #include @@ -801,6 +802,115 @@ ExeTrimCurveWithRegion( int nCrvId, int nRegId, bool bInVsOut, bool bOn, int* pn return nFirstId ; } +//---------------------------------------------------------------------------- +static int +MyTrimFlatCurveWithBox( int nCrvId, const Frame3d& frBox, const Vector3d& vtDiag, bool bInVsOut, bool bOn, int nRefType, int& nCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // recupero il riferimento della curva + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( nCrvId, frCrv)) + return GDB_ID_NULL ; + // determino il piano della curva (annullo temporaneamente l'estrusione per non avere problemi) + Plane3d plPlane ; + if ( ! pCrv->IsFlat( plPlane, false, 10 * EPS_SMALL)) + return GDB_ID_NULL ; + // porto in locale alla curva il riferimento del box (il vettore è già in locale a questo stesso riferimento) + Frame3d frBoxL = GetFrameLocal( pGeomDB, frBox, nRefType, frCrv) ; + // determino la parte di piano (poligono) compresa nel box (applicando le opportune trasformazioni di riferimento) + plPlane.ToLoc( frBoxL) ; + Polygon3d Polyg ; + if ( ! Polyg.FromPlaneTrimmedWithBox( plPlane, ORIG, ORIG + vtDiag, bOn, bOn)) + return GDB_ID_NULL ; + Polyg.ToGlob( frBoxL) ; + // se poligono vuoto, la curva non interseca il box + if ( Polyg.GetSideCount() == 0) { + if ( bInVsOut) { + pGeomDB->Erase( nCrvId) ; + nCount = 0 ; + } + else + nCount = 1 ; + return nCrvId ; + } + // creo la regione corrispondente + PtrOwner pContour( CreateCurveComposite()) ; + if ( IsNull( pContour) || ! pContour->FromPolyLine( Polyg.GetPolyLine())) + return false ; + PtrOwner pSfr( CreateSurfFlatRegion()) ; + if ( IsNull( pSfr) || ! pSfr->AddExtLoop( Release( pContour))) + return false ; + // calcolo la classificazione della curva rispetto alla regione + CRVCVECTOR ccClass ; + if ( ! pSfr->GetCurveClassification( *pCrv, 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.dParS, ccOne.dParE) ; + } + // 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 +ExeTrimFlatCurveWithBox( int nCrvId, const Frame3d& frBox, const Vector3d& vtDiag, bool bInVsOut, bool bOn, int nRefType, int* pnCount) +{ + int nCount ; + int nFirstId = MyTrimFlatCurveWithBox( nCrvId, frBox, vtDiag, bInVsOut, bOn, nRefType, nCount) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTrimFlatCurveWithBox(" + ToString( nCrvId) + "," + + ToString( frBox) + "," + + ToString( vtDiag) + "," + + ToString( bInVsOut) + "," + + ToString( bOn) + "," + + RefTypeToString( nRefType) + ")" + + " -- 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/EgtExecutor.rc b/EgtExecutor.rc index 0fee2b7..eb66d81 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/LUA_GdbGetCurve.cpp b/LUA_GdbGetCurve.cpp index f8e68ad..fbdf590 100644 --- a/LUA_GdbGetCurve.cpp +++ b/LUA_GdbGetCurve.cpp @@ -83,7 +83,7 @@ LuaCurveIsFlat( lua_State* L) LuaClearStack( L) ; // verifico se curva piatta e restituisco il piano medio Plane3d Plane ; - bool bFlat = ExeCurveIsFlat( nId, Plane, dToler) ; + bool bFlat = ExeCurveIsFlat( nId, Plane, false, dToler) ; LuaSetParam( L, bFlat) ; LuaSetParam( L, Plane.GetVersN()) ; LuaSetParam( L, Plane.GetDist()) ; diff --git a/LUA_GdbModifyCurve.cpp b/LUA_GdbModifyCurve.cpp index 6267159..0e5a168 100644 --- a/LUA_GdbModifyCurve.cpp +++ b/LUA_GdbModifyCurve.cpp @@ -363,7 +363,7 @@ LuaTrimExtendCurveByLen( lua_State* L) static int LuaTrimCurveWithRegion( lua_State* L) { - // 4 parametro : nCrvId, nRegId, bInVsOut, bOn + // 4 parametri : nCrvId, nRegId, bInVsOut, bOn int nCrvId ; LuaCheckParam( L, 1, nCrvId) int nRegId ; @@ -384,6 +384,35 @@ LuaTrimCurveWithRegion( lua_State* L) return 2 ; } +//---------------------------------------------------------------------------- +static int +LuaTrimFlatCurveWithBox( lua_State* L) +{ + // 5 o 6 parametri : nCrvId, frBox, vtDiag, bInVsOut, bOn [, nRefType] + int nCrvId ; + LuaCheckParam( L, 1, nCrvId) + Frame3d frBox ; + LuaCheckParam( L, 2, frBox) + Vector3d vtDiag ; + LuaCheckParam( L, 3, vtDiag) + bool bInVsOut ; + LuaCheckParam( L, 4, bInVsOut) + bool bOn ; + LuaCheckParam( L, 5, bOn) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // conservo le parti di curva desiderate + int nCount ; + int nNewId = ExeTrimFlatCurveWithBox( nCrvId, frBox, vtDiag, bInVsOut, bOn, nRefType, &nCount) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + return 2 ; +} + //---------------------------------------------------------------------------- static int LuaSplitCurve( lua_State* L) @@ -799,6 +828,7 @@ LuaInstallGdbModifyCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtExtendCurveEndByLen", LuaExtendCurveEndByLen) ; bOk = bOk && luaMgr.RegisterFunction( "EgtTrimExtendCurveByLen", LuaTrimExtendCurveByLen) ; bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveWithRegion", LuaTrimCurveWithRegion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimFlatCurveWithBox", LuaTrimFlatCurveWithBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurve", LuaSplitCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtPoint", LuaSplitCurveAtPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtParam", LuaSplitCurveAtParam) ;