From 15a8df7f30f14d069811ebf110b12c99bf410722 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Fri, 9 May 2025 16:11:45 +0200 Subject: [PATCH] EgtMachKernel : - In PocketingNT aggiunta la gestione dei lati aperti interni al grezzo. - Rimozione parametro in eccesso per ModifyRawPart. --- MachMgr.h | 2 +- MachMgrRawParts.cpp | 6 +- PocketingNT.cpp | 673 ++++++++++++++++++++++++++++++++++---------- PocketingNT.h | 11 +- 4 files changed, 532 insertions(+), 160 deletions(-) diff --git a/MachMgr.h b/MachMgr.h index 71a06c6..63ed2db 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -125,7 +125,7 @@ class MachMgr : public IMachMgr int AddRawPart( const Point3d& ptOrig, double dLen, double dWidth, double dHeight, Color cCol) override ; int AddRawPartWithPart( int nPartId, int nCrvSrfId, double dOverMat, Color cCol) override ; bool ModifyRawPart( int nRawId, const Point3d& ptOrig, double dLen, double dWidth, double dHeight, Color cCol) override ; - bool ModifyRawPart( int nRawId, int nCrvId, double dOverMat, double dZmin, double dHeight, Color cCol) override ; + bool ModifyRawPart( int nRawId, int nCrvId, double dOverMat, double dHeight, Color cCol) override ; bool ModifyRawPartSize( int nRawId, double dLength, double dWidth, double dHeight) override ; bool ModifyRawPartHeight( int nRawId, double dHeight) override ; bool KeepRawPart( int nRawId, int nSouPhase) override ; diff --git a/MachMgrRawParts.cpp b/MachMgrRawParts.cpp index 15547f3..a015c25 100644 --- a/MachMgrRawParts.cpp +++ b/MachMgrRawParts.cpp @@ -285,7 +285,7 @@ MachMgr::AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight, // assegno la fase al gruppo m_pGeomDB->SetInfo( nRawId, MACH_RAW_PHASE, m_nCurrPhase) ; // creo solido e outline - bOk = bOk && ModifyRawPart( nRawId, nCrvId, dOverMat, dZmin, dHeight, cCol) ; + bOk = bOk && ModifyRawPart( nRawId, nCrvId, dOverMat, dHeight, cCol) ; // se qualcosa è andato storto, cancello tutto if ( ! bOk) { m_pGeomDB->Erase( nRawId) ; @@ -297,7 +297,7 @@ MachMgr::AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight, //---------------------------------------------------------------------------- bool -MachMgr::ModifyRawPart( int nRawId, int nCrvId, double dOverMat, double dZmin, double dHeight, Color cCol) +MachMgr::ModifyRawPart( int nRawId, int nCrvId, double dOverMat, double dHeight, Color cCol) { // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) @@ -338,7 +338,7 @@ MachMgr::ModifyRawPart( int nRawId, int nCrvId, double dOverMat, double dZmin, d if ( IsNull( pOffsCrv)) return false ; // creo il solido - PtrOwner pStm( GetSurfTriMeshByExtrusion( pOffsCrv, Vector3d(0,0,dHeight), true)) ; + PtrOwner pStm( GetSurfTriMeshByExtrusion( pOffsCrv, Vector3d( 0, 0, dHeight), true)) ; if ( IsNull( pStm)) return false ; // cancello eventuali vecchi solidi e curve di outline diff --git a/PocketingNT.cpp b/PocketingNT.cpp index 547e2ec..015521f 100644 --- a/PocketingNT.cpp +++ b/PocketingNT.cpp @@ -44,6 +44,7 @@ #include "/EgtDev/Include/EGkCalcPocketing.h" #include "/EgtDev/Include/EGkSurfLocal.h" #include "/EgtDev/Include/EGkDistPointSurfFr.h" +#include "/EgtDev/Include/EGkDistPointSurfTm.h" #include using namespace std ; @@ -58,7 +59,6 @@ const string UN_MAXELEV = "MaxElev" ; const string UN_OPEN = "Open" ; const string UN_OPENOUTRAW = "OpenOutRaw" ; const string UN_OPENMINSAFE = "OpenMinSafe" ; -const string UN_OPENEXTENSION = "OpenExtension" ; //------------------------------ Errors -------------------------------------- // 2401 = "Error in PocketingNT : UpdateToolData failed" @@ -93,6 +93,8 @@ const string UN_OPENEXTENSION = "OpenExtension" ; // 2431 = "Error in PocketingNT : LeadIn with Mill NoTip in material" // 2432 = "Error in PocketingNT : Mirror for Double calculation failed" // 2433 = "Error in PocketingNT : Calc Region Elevation failed" +// 2434 = "Error in PocketingNT : Managing Open Edges inside Raw failed" +// 2435 = "Error in PocketingNT : Managing Open Edges on Raw failed" // 2451 = "Warning in PocketingNT : Skipped entity (xx)" // 2452 = "Warning in PocketingNT : No machinable pocket" // 2453 = "Warning in PocketingNT : Tool name changed (xx)" @@ -106,8 +108,9 @@ const string UN_OPENEXTENSION = "OpenExtension" ; //---------------------------------------------------------------------------- // _debug #define DEBUG_OPEN_EDGE_EXTENSION 0 +#define DEBUG_OPEN_EDGE_IN_RAW 0 #define DEBUG_FLATREGIONS 0 -#if DEBUG_OPEN_EDGE_EXTENSION || DEBUG_FLATREGIONS +#if DEBUG_OPEN_EDGE_EXTENSION || DEBUG_OPEN_EDGE_IN_RAW || DEBUG_FLATREGIONS #include "EgtDev/Include/EGkGeoPoint3d.h" #include "EgtDev/Include/EGkFrame3d.h" #endif @@ -742,10 +745,8 @@ PocketingNT::MyApply( bool bRecalc, bool bPostApply) } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) { - m_pMchMgr->SetLastError( 2421, "Error in PocketingNT : Chaining failed") ; + if ( bChain && ! Chain( nAuxId)) return false ; - } // lavoro ogni singola catena bool bOk = true ; @@ -1544,18 +1545,21 @@ PocketingNT::Chain( int nGrpDestId) vCrvCompo.back()->SetTempParam( dThick, 1) ; } - // per ogni curva estendo i suoi lati aperti fino al bordo del grezzo) + // ordino le curve creando una regione piana SurfFlatRegionByContours SfrByC ; for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) { - Vector3d vtExtr ; vCrvCompo[i]->GetExtrusion( vtExtr) ; - double dThick = vCrvCompo[i]->GetTempParam( 1) ; - if ( ! ExtendOpenEdgesToRaw( vCrvCompo[i], vtExtr)) - return false ; - vCrvCompo[i]->SetExtrusion( vtExtr) ; - vCrvCompo[i]->SetTempParam( dThick, 1) ; + // memorizzo la Thickness nei TempParams + vCrvCompo[i]->SetTempParam( vCrvCompo[i]->GetTempParam( 1), 1) ; SfrByC.AddCurve( Release( vCrvCompo[i])) ; } + // recupero il pezzo corrente + PtrOwner pStmRaw( GetRaw()) ; + if ( IsNull( pStmRaw) || ! pStmRaw->IsValid() || pStmRaw->GetTriangleCount() == 0) { + m_pMchMgr->SetLastError( 3025, "Error in PocketingNT : RawPart not computable") ; + return false ; + } + // scorro le regioni piane ricavate dalle curve int nGroupName = -1 ; PtrOwner pSfrCurr( SfrByC.GetSurf()) ; @@ -1572,19 +1576,34 @@ PocketingNT::Chain( int nGrpDestId) PtrOwner pSfrChunk( pSfrCurr->CloneChunk( nC)) ; if ( IsNull( pSfrChunk) || ! pSfrChunk->IsValid()) return false ; - // salvo eventuali lati aperti per il Chunk corrente + // recupero la ThickNess e l'Estrusione dal Loop esterno + PtrOwner pCrvInfo( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, 0))) ; + if ( IsNull( pCrvInfo) || ! pCrvInfo->IsValid()) + return false ; + double dThick = pCrvInfo->GetTempParam( 1) ; + Vector3d vtExtr ; pCrvInfo->GetExtrusion( vtExtr) ; + // -------------- Controllo esistenza di lati aperti interni al grezzo -------------- + // Questi lati vengono Offsettati, raccordati e considerati poi come chiusi + if ( ! ManageOpenEdges( pSfrChunk, pStmRaw)) { + m_pMchMgr->SetLastError( 2434, "Error in PocketingNT : Managing Open Edges inside Part failed") ; + return false ; + } + // ------------- Estendo i lati aperti sul bordo per possibili proiezioni ------------- + if ( ! ExtendOpenEdges( pSfrChunk, pStmRaw)) { + m_pMchMgr->SetLastError( 2435, "Error in PocketingNT : Managing Open Edges on Raw failed") ; + return false ; + } + // scorro i suoi Loop int nNewId = GDB_ID_NULL ; for ( int nL = 0 ; nL < pSfrChunk->GetLoopCount( 0) ; ++ nL) { // recupero il Loop - PtrOwner pCrvLoop( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, nL))) ; - if ( IsNull( pCrvLoop) || ! pCrvLoop->IsValid()) + PtrOwner pCrvLoop( CreateCurveComposite()) ; + if ( IsNull( pCrvLoop) || + ! pCrvLoop.Set( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, nL))) || + ! pCrvLoop->IsValid()) return false ; - // se loop esterno + // se loop esterno, aggiungo la superfifice al gruppo con le relative informazioni if ( nL == 0) { - // recupero la ThickNess e l'Estrusione - double dThick = pCrvLoop->GetTempParam( 1) ; - Vector3d vtExtr ; pCrvLoop->GetExtrusion( vtExtr) ; - // aggiungo la superfifice al gruppo con le relative informazioni nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::CloneSurfFlatRegion( pSfrChunk)) ; if ( nNewId == GDB_ID_NULL) return false ; @@ -1651,6 +1670,48 @@ PocketingNT::GetRaw( void) return ( ( pStmRaw->IsValid() && pStmRaw->GetTriangleCount() > 0) ? Release( pStmRaw) : nullptr) ; } +//---------------------------------------------------------------------------- +ISurfTriMesh* +PocketingNT::GetRawPart( void) +{ + // controllo MachManager e database geometrico + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return nullptr ; + + // creo Stm del grezzo + PtrOwner pStmRaw( CreateSurfTriMesh()) ; + if ( IsNull( pStmRaw)) + return nullptr ; + pStmRaw->AdjustTopology() ; + + // Id prima RawPart + int nRawId = m_pMchMgr->GetFirstRawPart() ; + + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, m_nPhase)) { + // recupero l'oggetto dal database con tale Id + int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( nRawSolidId) ; + if ( pGObj == nullptr) + return nullptr ; + // recupero il frame in cui si trova + Frame3d frRaw ; + m_pGeomDB->GetGlobFrame( nRawSolidId, frRaw) ; + // controllo che sia una Trimesh + if ( pGObj->GetType() == SRF_TRIMESH) { + SurfLocal StmRawPart( GetSurfTriMesh( pGObj), frRaw, GLOB_FRM) ; + // lo aggiungo alla Trimesh complessiva + pStmRaw->Add( *GetSurfTriMesh( StmRawPart)) ; + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + + return ( ( pStmRaw->IsValid() && pStmRaw->GetTriangleCount() > 0) ? Release( pStmRaw) : nullptr) ; +} + //---------------------------------------------------------------------------- ISurfTriMesh* PocketingNT::GetExtrusionStm( const ISurfFlatRegion* pSfr, const Vector3d& vtTrasl, const Vector3d& vtExtr) @@ -1857,160 +1918,194 @@ PocketingNT::GetHomogeneousParts( const ICurveComposite* pCrvCompo, ICRVCOMPOPOV //---------------------------------------------------------------------------- bool -PocketingNT::ExtendOpenEdgesToRaw( ICurveComposite* pCompo, const Vector3d& vtExtr) +PocketingNT::ExtendOpenEdges( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStm) { - // controllo validità della curva - if ( pCompo == nullptr || ! vtExtr.IsValid()) + /* I lati aperti vengono estesi (mediante proiezione del box di pStm tagliata da un piano definito + * da pSfr) in modo da estendere la regione di lavoro */ + + // controllo dei parametri + if ( pSfr == nullptr || pStm == nullptr) return false ; - if ( ! pCompo->IsValid()) + if ( ! pSfr->IsValid()) return true ; + // se la superficie non ha lati aperti, allora non devo fare nulla + bool bAllClosed = true ; + for ( int nC = 0 ; nC < pSfr->GetChunkCount() && bAllClosed ; ++ nC) { + for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) && bAllClosed ; ++ nL) { + for ( int nU = 0 ; nU < pSfr->GetLoopCurveCount( nC, nL) && bAllClosed ; ++ nU) { + int nTmpProp = TEMP_PROP_INVALID ; + bAllClosed = ( pSfr->GetCurveTempProp( nC, nL, nU, nTmpProp, 0) && + nTmpProp == TEMP_PROP_CLOSE_EDGE) ; + } + } + } + if ( bAllClosed) + return true ; + + // recupero i Chunk della superficie + ISURFFRPOVECTOR vChunks( pSfr->GetChunkCount()) ; + for ( int nC = 0 ; nC < int( vChunks.size()) ; ++ nC) + vChunks[nC].Set( pSfr->CloneChunk( nC)) ; + #if DEBUG_OPEN_EDGE_EXTENSION int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; m_pGeomDB->SetName( nLay, "Open_edge_extension") ; - _debug_draw_loop( pCompo, nLay, false) ; + _debug_draw_sfr( pSfr, false, nLay) ; #endif - - // recupero i tratti con proprietà uniformi della superficie - ICRVCOMPOPOVECTOR vpCrv ; - if ( ! GetHomogeneousParts( pCompo, vpCrv)) + // clono la superficie trimesh ( devo effettuare un taglio) + PtrOwner pStmCL( CloneSurfTriMesh( pStm)) ; + if ( IsNull( pStmCL) || ! pStmCL->IsValid() || pStmCL->GetTriangleCount() == 0) return false ; - // se non esistono lati aperti, non devo fare nulla - if ( int( vpCrv.size()) == 1 && vpCrv[0]->GetTempProp() == TEMP_PROP_CLOSE_EDGE) - return true ; - - // recupero la superficie del grezzo - PtrOwner pStmRaw( GetRaw()) ; - if ( IsNull( pStmRaw) || ! pStmRaw->IsValid() || pStmRaw->GetTriangleCount() == 0) { - m_pMchMgr->SetLastError( 3025, "Error in PocketingNT : RawPart not computable") ; - return false ; - } - // definisco un piano di taglio per il grezzo, mediante la curva Plane3d plCut ; - Point3d ptC ; pCompo->GetCentroid( ptC) ; - if ( ! plCut.Set( ptC, - vtExtr)) + Point3d ptC ; pSfr->GetCentroid( ptC) ; + if ( ! plCut.Set( ptC, - pSfr->GetNormVersor())) return false ; - // taglio il grezzo con il piano - if ( ! pStmRaw->Cut( plCut, true)) + if ( ! pStmCL->Cut( plCut, true)) return false ; - if ( ! pStmRaw->IsValid() || pStmRaw->GetTriangleCount() == 0) + if ( ! pStmCL->IsValid() || pStmCL->GetTriangleCount() == 0) return true ; - #if DEBUG_OPEN_EDGE_EXTENSION - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pStmRaw->Clone()) ; + int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pStmCL->Clone()) ; m_pGeomDB->SetMaterial( a, Color( 0.2, 0.2, 0.8, .65)) ; #endif - // recupero il Box del grezzo definito dal frame implicito dal piano Frame3d frCut ; - if ( ! frCut.Set( ptC, vtExtr)) + if ( ! frCut.Set( ptC, pSfr->GetNormVersor())) return false ; frCut.Invert() ; BBox3d BBoxRawCut ; - if ( ! pStmRaw->GetBBox( frCut, BBoxRawCut)) + if ( ! pStmCL->GetBBox( frCut, BBoxRawCut)) return false ; - #if DEBUG_OPEN_EDGE_EXTENSION frCut.Invert() ; - _degub_draw_box( BBoxRawCut, frCut, nLay) ; + _debug_draw_box( BBoxRawCut, frCut, nLay) ; frCut.Invert() ; #endif - // definisco offset di estensione per tratti aperti - m_dOpenExtension = 0 ; - GetValInNotes( m_Params.m_sUserNotes, UN_OPENEXTENSION, m_dOpenExtension) ; - double dOffs = 0 ; - if ( m_dOpenExtension < EPS_SMALL) - dOffs = max( BBoxRawCut.GetDimX(), BBoxRawCut.GetDimY()) + m_TParams.m_dDiam ; - else - dOffs = abs( m_dOpenExtension) ; - - // sostiuisco ogni tratto aperto con il suo Offset - for ( int i = 0 ; i < int( vpCrv.size()) ; ++ i) { - if ( vpCrv[i]->GetTempProp() == TEMP_PROP_OPEN_EDGE) { - vpCrv[i]->SetExtrusion( vtExtr) ; - OffsetCurve OffsCurve ; - OffsCurve.Make( vpCrv[i], dOffs, ICurve::OFF_EXTEND) ; - PtrOwner pCompoOpenOffs( ConvertCurveToComposite( OffsCurve.GetLongerCurve())) ; ; - if ( ! IsNull( pCompoOpenOffs) && pCompoOpenOffs->IsValid()) { - for ( int j = 0 ; j < pCompoOpenOffs->GetCurveCount() ; ++ j) - pCompoOpenOffs->SetCurveTempProp( j, TEMP_PROP_OPEN_EDGE, 0) ; - pCompoOpenOffs->SetTempProp( TEMP_PROP_OPEN_EDGE, 0) ; - vpCrv[i].Set( Release( pCompoOpenOffs)) ; - } - // se la curva era tutta aperta, ho finito - if ( int( vpCrv.size()) == 1 && vpCrv[0]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE) { - pCompo->Clear() ; - pCompo->CopyFrom( vpCrv[0]) ; - #if DEBUG_OPEN_EDGE_EXTENSION - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pCompo->Clone()) ; - m_pGeomDB->SetMaterial( a, ORANGE) ; - #endif - return ( pCompo != nullptr && pCompo->IsValid()) ; + // scorro i Chunk della superficie + bool bModifSfr = false ; + for ( int nC = 0 ; nC < int( vChunks.size()) ; ++ nC) { + // recupero il Loop esterno ( per ora non considero le isole) + PtrOwner pCrvExtLoop( ConvertCurveToComposite( vChunks[nC]->GetLoop( 0, 0))) ; + if ( IsNull( pCrvExtLoop) || ! pCrvExtLoop->IsValid()) + return false ; + // recupero i tratti con proprietà uniformi della superficie + ICRVCOMPOPOVECTOR vpCrvs ; + if ( ! GetHomogeneousParts( pCrvExtLoop, vpCrvs)) + return false ; + // se il bordo è tutto chiuso, allora passo al prossimo Chunk + if ( int( vpCrvs.size()) == 1 && vpCrvs[0]->GetTempProp() == TEMP_PROP_CLOSE_EDGE) + continue ; + // definisco la nuova curva di bordo + PtrOwner pCrvNewBorder( CreateCurveComposite()) ; + if ( IsNull( pCrvNewBorder)) + return false ; + // definisco offset di estensione per tratti aperti + double dOffs = max( BBoxRawCut.GetDimX(), BBoxRawCut.GetDimY()) + m_TParams.m_dDiam ; + // sostiuisco ogni tratto aperto con il suo Offset + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( vpCrvs[i]->GetTempProp() == TEMP_PROP_OPEN_EDGE) { + vpCrvs[i]->SetExtrusion( pSfr->GetNormVersor()) ; + OffsetCurve OffsCurve ; + OffsCurve.Make( vpCrvs[i], dOffs, ICurve::OFF_EXTEND) ; + PtrOwner pCompoOpenOffs( ConvertCurveToComposite( OffsCurve.GetLongerCurve())) ; + if ( ! IsNull( pCompoOpenOffs) && pCompoOpenOffs->IsValid()) { + for ( int j = 0 ; j < pCompoOpenOffs->GetCurveCount() ; ++ j) + pCompoOpenOffs->SetCurveTempProp( j, TEMP_PROP_OPEN_EDGE, 0) ; + pCompoOpenOffs->SetTempProp( TEMP_PROP_OPEN_EDGE, 0) ; + vpCrvs[i].Set( Release( pCompoOpenOffs)) ; + } } } - } - - // scorro i tratti omogenei - PtrOwner pCompoExtended( CreateCurveComposite()) ; - if ( IsNull( pCompoExtended)) - return false ; - Point3d ptLineS, ptLineE ; - for ( int i = 0 ; i < int( vpCrv.size()) ; ++ i) { - if ( vpCrv[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE) { - // recupero l'indice del tratto chiuso precedente e successivo - int nIndCLprec = ( i == 0 ? int( vpCrv.size()) -1 : i - 1) ; - int nIndCLsucc = ( i == int( vpCrv.size()) -1 ? 0 : i + 1) ; - // tratto lineare chiuso precedente - vpCrv[nIndCLprec]->GetEndPoint( ptLineS) ; - vpCrv[i]->GetStartPoint( ptLineE) ; - PtrOwner pLinePrec( CreateCurveLine()) ; - if ( ! IsNull( pLinePrec) && pLinePrec->Set( ptLineS, ptLineE)) { - #if DEBUG_OPEN_EDGE_EXTENSION - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pLinePrec->Clone()) ; - m_pGeomDB->SetMaterial( a, AQUA) ; - #endif - if ( ! pCompoExtended->AddCurve( Release( pLinePrec))) - return false ; - pCompoExtended->SetCurveTempProp( pCompoExtended->GetCurveCount() - 1, 0, TEMP_PROP_CLOSE_EDGE) ; - } - // tratto aperto esteso - #if DEBUG_OPEN_EDGE_EXTENSION - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, vpCrv[i]->Clone()) ; - m_pGeomDB->SetMaterial( a, ORANGE) ; - #endif - if ( ! pCompoExtended->AddCurve( vpCrv[i]->Clone())) - return false ; - // tratto lineare chiuso successivo - vpCrv[i]->GetEndPoint( ptLineS) ; - vpCrv[nIndCLsucc]->GetStartPoint( ptLineE) ; - PtrOwner pLineSucc( CreateCurveLine()) ; - if ( ! IsNull( pLineSucc) && pLineSucc->Set( ptLineS, ptLineE)) { - #if DEBUG_OPEN_EDGE_EXTENSION - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pLineSucc->Clone()) ; - m_pGeomDB->SetMaterial( a, AQUA) ; - #endif - if ( ! pCompoExtended->AddCurve( Release( pLineSucc))) - return false ; - pCompoExtended->SetCurveTempProp( pCompoExtended->GetCurveCount() - 1, 0, TEMP_PROP_CLOSE_EDGE) ; + // caso limite : tutta la curva è aperta + if ( int( vpCrvs.size()) == 1 && vpCrvs[0]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE) + pCrvNewBorder.Set( Release( vpCrvs[0])) ; + else { + // scorro i tratti omogenei + Point3d ptLineS, ptLineE ; + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE) { + // recupero l'indice del tratto chiuso precedente e successivo + int nIndCLprec = ( i == 0 ? int( vpCrvs.size()) -1 : i - 1) ; + int nIndCLsucc = ( i == int( vpCrvs.size()) -1 ? 0 : i + 1) ; + // tratto lineare chiuso precedente + vpCrvs[nIndCLprec]->GetEndPoint( ptLineS) ; + vpCrvs[i]->GetStartPoint( ptLineE) ; + PtrOwner pLinePrec( CreateCurveLine()) ; + if ( ! IsNull( pLinePrec) && pLinePrec->Set( ptLineS, ptLineE)) { + #if DEBUG_OPEN_EDGE_EXTENSION + int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pLinePrec->Clone()) ; + m_pGeomDB->SetMaterial( a, AQUA) ; + #endif + if ( ! pCrvNewBorder->AddCurve( Release( pLinePrec))) + return false ; + pCrvNewBorder->SetCurveTempProp( pCrvNewBorder->GetCurveCount() - 1, 0, TEMP_PROP_CLOSE_EDGE) ; + } + // tratto aperto esteso + #if DEBUG_OPEN_EDGE_EXTENSION + int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, vpCrvs[i]->Clone()) ; + m_pGeomDB->SetMaterial( a, ORANGE) ; + #endif + if ( ! pCrvNewBorder->AddCurve( vpCrvs[i]->Clone())) + return false ; + // tratto lineare chiuso successivo + vpCrvs[i]->GetEndPoint( ptLineS) ; + vpCrvs[nIndCLsucc]->GetStartPoint( ptLineE) ; + PtrOwner pLineSucc( CreateCurveLine()) ; + if ( ! IsNull( pLineSucc) && pLineSucc->Set( ptLineS, ptLineE)) { + #if DEBUG_OPEN_EDGE_EXTENSION + int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pLineSucc->Clone()) ; + m_pGeomDB->SetMaterial( a, AQUA) ; + #endif + if ( ! pCrvNewBorder->AddCurve( Release( pLineSucc))) + return false ; + pCrvNewBorder->SetCurveTempProp( pCrvNewBorder->GetCurveCount() - 1, 0, TEMP_PROP_CLOSE_EDGE) ; + } + } + else if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_CLOSE_EDGE) { + #if DEBUG_OPEN_EDGE_EXTENSION + int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, vpCrvs[i]->Clone()) ; + m_pGeomDB->SetMaterial( a, AQUA) ; + #endif + if ( ! pCrvNewBorder->AddCurve( vpCrvs[i]->Clone())) + return false ; + } } } - else if ( vpCrv[i]->GetTempProp( 0) == TEMP_PROP_CLOSE_EDGE) { - #if DEBUG_OPEN_EDGE_EXTENSION - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, vpCrv[i]->Clone()) ; - m_pGeomDB->SetMaterial( a, AQUA) ; - #endif - if ( ! pCompoExtended->AddCurve( vpCrv[i]->Clone())) + // ricostruisco il Chunk con il nuovo bordo + PtrOwner pNewChunk( CreateSurfFlatRegion()) ; + if ( IsNull( pNewChunk) || ! pNewChunk->AddExtLoop( Release( pCrvNewBorder))) + return false ; + for ( int nI = 1 ; nI < vChunks[nC]->GetLoopCount( 0) ; ++ nI) { + if ( ! pNewChunk->AddIntLoop( vChunks[nC]->GetLoop( 0, nI))) return false ; } + vChunks[nC].Set( Release( pNewChunk)) ; + bModifSfr = true ; } - pCompo->Clear() ; - pCompo->CopyFrom( pCompoExtended) ; - return ( pCompo != nullptr && pCompo->IsValid()) ; + // recupero la regione finale + if ( bModifSfr) { + PtrOwner pSfrTmp( CreateSurfFlatRegion()) ; + if ( IsNull( pSfrTmp)) + return false ; + for ( auto& pSfrC : vChunks) { + if ( pSfrTmp->IsValid()) + pSfrTmp->Add( *pSfrC) ; + else + pSfrTmp.Set( pSfrC) ; + } + pSfr->CopyFrom( pSfrTmp) ; + } + + #if DEBUG_OPEN_EDGE_EXTENSION + _debug_draw_sfr( pSfr, false, nLay) ; + #endif + return ( pSfr->IsValid()) ; } //---------------------------------------------------------------------------- @@ -2197,6 +2292,263 @@ PocketingNT::CalcLimitRegion( const ISurfFlatRegion* pSfrPock, const ISurfFlatRe return true ; } +//---------------------------------------------------------------------------- +bool +PocketingNT::ManageOpenEdges( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStm) +{ + /* Bisogna distingere tra lati aperti sul bordo del pezzo e lati aperti all'interno del pezzo ; + * I lati aperti all'interno del pezzo vanno estesi di circa il raggio utensile e poi considerati + * come chiusi */ + + // controllo dei parametri + if ( pSfr == nullptr || ! pSfr->IsValid() || + pStm == nullptr) + return false ; + if ( ! pStm->IsValid()) + return true ; + + // recupero i Chunk della superficie + ISURFFRPOVECTOR vChunks( pSfr->GetChunkCount()) ; + for ( int nC = 0 ; nC < int( vChunks.size()) ; ++ nC) + vChunks[nC].Set( pSfr->CloneChunk( nC)) ; + + // definisco un frame locale nel piano XY + Frame3d frXY ; + Point3d ptCenter ; pSfr->GetCentroid( ptCenter) ; + if ( ! frXY.Set( ptCenter, pSfr->GetNormVersor())) + return false ; + + // definisco Offset di tolleranza + m_dOpenInRawExtension = 1.05 * ( m_TParams.m_dDiam / 2.) ; + double dOpenExtension = 0. ; + if ( GetValInNotes( m_Params.m_sUserNotes, UN_OPEN, dOpenExtension) && dOpenExtension > EPS_SMALL) + m_dOpenInRawExtension = dOpenExtension ; + const double LEN_EXTENSION = 1000. ; + const double TOL_PT_INSIDE_STM = 3. ; + #if DEBUG_OPEN_EDGE_IN_RAW + int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; + m_pGeomDB->SetName( nGrp, "_OpenEdgeInRaw") ; + int nLayBase = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; + m_pGeomDB->SetName( nLayBase, "Orig") ; + int nLayConstr = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; + m_pGeomDB->SetName( nLayConstr, "Construction") ; + int nLayResult = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; + m_pGeomDB->SetName( nLayResult, "Result") ; + int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayBase, pStm->Clone()) ; + m_pGeomDB->SetMaterial( _a, Color( .35, .65, .45, .35)) ; + #endif + + // recupero solo la curva di bordo esterno, le isole aperte per ora sono trascurate + // scorro i Chunk della regione piana da lavorare + bool bModifSfr = false ; + for ( int nC = 0 ; nC < int( vChunks.size()) ; ++ nC) { + // recupero la curva di bordo + PtrOwner pCrvBorder( ConvertCurveToComposite( vChunks[nC]->GetLoop( 0, 0))) ; + if ( IsNull( pCrvBorder) || ! pCrvBorder->IsValid()) + return false ; + // recupero i tratti omogenei + ICRVCOMPOPOVECTOR vpCrvs ; + GetHomogeneousParts( pCrvBorder, vpCrvs) ; + // se tutta chiusa, non faccio nulla + if ( int( vpCrvs.size()) == 1 && vpCrvs[0]->GetTempProp( 0) == TEMP_PROP_CLOSE_EDGE) + continue ; + // scorro i tratti alla ricerca di lati aperti ( esistono necessariamente) + bool bOpenCrvInPart = false ; + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE) { + // analizzo le sottocurve del tratto + for ( int j = 0 ; j < vpCrvs[i]->GetCurveCount() ; ++ j) { + // per ogni sottocurva considero punto iniziale, finale e medio per campionarla + // ( si potrebbe in futuro campionare in maniera più fitta ) + PNTVECTOR vPt( 3, P_INVALID) ; + vpCrvs[i]->GetCurve( j)->GetStartPoint( vPt[0]) ; + vpCrvs[i]->GetCurve( j)->GetMidPoint( vPt[1]) ; + vpCrvs[i]->GetCurve( j)->GetEndPoint( vPt[2]) ; + // classifico tali punti rispetto alla superficie + bool bOpenEdgeInStm = false ; + double dDist = 0. ; + for ( int nPt = 0 ; nPt < int( vPt.size()) && ! bOpenEdgeInStm ; ++ nPt) { + DistPointSurfTm DistPtStm( vPt[nPt], *pStm) ; + bOpenEdgeInStm = ( DistPtStm.IsPointInside() && + DistPtStm.GetDist( dDist) && + dDist > TOL_PT_INSIDE_STM) ; + } + // se curva aperta nel pezzo, la classifico + if ( bOpenEdgeInStm) { + vpCrvs[i]->SetCurveTempProp( j, TEMP_PROP_OPEN_EDGE_IN_RAW, 0) ; + bOpenCrvInPart = true ; + } + } + } + } + // se non sono state trovate curve interne al pezzo, allora passo al bordo successivo + if ( ! bOpenCrvInPart) + continue ; + // ricostruisco il bordo mediante proprietà assegnate ( esistono lati aperti interni al pezzo) + PtrOwner pCrvNewBorder( CreateCurveComposite()) ; + if ( IsNull( pCrvNewBorder)) + return false ; + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( ! pCrvNewBorder->AddCurve( Release( vpCrvs[i]))) + return false ; + } + // recupero i nuovi tratti omogenei + GetHomogeneousParts( pCrvNewBorder, vpCrvs) ; + #if DEBUG_OPEN_EDGE_IN_RAW + _debug_draw_OpenEdgesInRaw( vpCrvs, nLayBase) ; + #endif + // caso limite : tutta la curva è aperta ed interna alla regione + if ( int( vpCrvs.size()) == 1 && vpCrvs[0]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE_IN_RAW) { + // Offset del bordo del Chunk + OffsetCurve OffsCrv ; + OffsCrv.Make( pCrvNewBorder, m_dOpenInRawExtension, ICurve::OFF_FILLET) ; + pCrvNewBorder.Set( ConvertCurveToComposite( OffsCrv.GetLongerCurve())) ; + if ( IsNull( pCrvNewBorder) || ! pCrvNewBorder->IsValid()) + return false ; + // considero il bordo come tutto chiuso ( evito entrate da fuori dal pezzo) + for ( int i = 0 ; i < pCrvNewBorder->GetCurveCount() ; ++ i) + pCrvNewBorder->SetCurveTempProp( i, TEMP_PROP_CLOSE_EDGE, 0) ; + } + // se invece presenta solo alcuni tratti Open interni al pezzo + else { + // porto tutti i tratti ricavati nel piano XY per le intersezioni + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) + vpCrvs[i]->ToLoc( frXY) ; + // scorro i tratti con proprietà uniformi + bool bOk = true ; + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( ! bOk) { + // considero il tratto precedente come chiuso + for ( int j = 0 ; j < vpCrvs[i-1]->GetCurveCount() ; ++ j) + vpCrvs[i-1]->SetCurveTempProp( j, TEMP_PROP_CLOSE_EDGE, 0) ; + bOk = true ; + } + // se tratto Open interno al grezzo + if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE_IN_RAW) { + // effettuo Offset del tratto in esame + OffsetCurve OffsCrv ; + OffsCrv.Make( vpCrvs[i], m_dOpenInRawExtension, ICurve::OFF_FILLET) ; + PtrOwner pCrvOffsOpenInPart( ConvertCurveToComposite( OffsCrv.GetLongerCurve())) ; + if ( IsNull( pCrvOffsOpenInPart) || ! pCrvOffsOpenInPart->IsValid()) { + bOk = false ; + continue ; + } + // recupero tratto precedente e successivo + int nIndPrev = ( i > 0 ? i - 1 : int( vpCrvs.size()) - 1) ; + int nIndAfter = ( i < int( vpCrvs.size()) - 1 ? i + 1 : 0) ; + // estendo per sicurezza il tratto di Offset ( per angoli acuti con i tratti adiacenti) + pCrvOffsOpenInPart->ExtendStartByLen( LEN_EXTENSION) ; + pCrvOffsOpenInPart->ExtendEndByLen( LEN_EXTENSION) ; + #if DEBUG_OPEN_EDGE_IN_RAW + int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayConstr, pCrvOffsOpenInPart->Clone()) ; + m_pGeomDB->SetMaterial( _a, ORANGE) ; + #endif + // definisco due segmenti lineari + PtrOwner pLinePrev( CreateCurveLine()) ; + PtrOwner pLineAfter( CreateCurveLine()) ; + if ( IsNull( pLinePrev) || IsNull( pLineAfter)) + return false ; + Point3d ptInters ; + // ----------------------- Segmento iniziale ----------------------------- + Point3d myPt ; + Vector3d myVect ; + vpCrvs[nIndPrev]->GetEndPoint( myPt) ; + vpCrvs[nIndPrev]->GetEndDir( myVect) ; + if ( ! pLinePrev->Set( myPt, myPt + LEN_EXTENSION * myVect)) + return false ; + #if DEBUG_OPEN_EDGE_IN_RAW + _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayConstr, pLinePrev->Clone()) ; + m_pGeomDB->SetMaterial( _a, BLACK) ; + #endif + IntersCurveCurve ICC_Prev( *pLinePrev, *pCrvOffsOpenInPart) ; + if ( ICC_Prev.GetIntersCount() > 0 && ICC_Prev.GetIntersPointNearTo( 0, myPt, ptInters)) { + double dU ; + pLinePrev->GetParamAtPoint( ptInters, dU) ; + pLinePrev->TrimEndAtParam( dU) ; + pLinePrev->SetTempProp( vpCrvs[nIndPrev]->GetTempProp( 0), 0) ; + pCrvOffsOpenInPart->GetParamAtPoint( ptInters, dU) ; + pCrvOffsOpenInPart->TrimStartAtParam( dU) ; + } + else { + bOk = false ; + continue ; + } + // ----------------------- Segmento finale ------------------------------- + vpCrvs[nIndAfter]->GetStartPoint( myPt) ; + vpCrvs[nIndAfter]->GetStartDir( myVect) ; + if ( ! pLineAfter->Set( myPt - LEN_EXTENSION * myVect, myPt)) + return false ; + #if DEBUG_OPEN_EDGE_IN_RAW + _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayConstr, pLineAfter->Clone()) ; + m_pGeomDB->SetMaterial( _a, BLACK) ; + #endif + IntersCurveCurve ICC_After( *pLineAfter, *pCrvOffsOpenInPart) ; + if ( ICC_After.GetIntersCount() > 0 && ICC_After.GetIntersPointNearTo( 0, myPt, ptInters)) { + double dU ; + pLineAfter->GetParamAtPoint( ptInters, dU) ; + pLineAfter->TrimStartAtParam( dU) ; + pLineAfter->SetTempProp( vpCrvs[nIndAfter]->GetTempProp( 0), 0) ; + pCrvOffsOpenInPart->GetParamAtPoint( ptInters, dU) ; + pCrvOffsOpenInPart->TrimEndAtParam( dU) ; + } + else { + bOk = false ; + continue ; + } + // aggiorno tutte le curve + vpCrvs[nIndPrev]->AddCurve( Release( pLinePrev), true) ; + vpCrvs[nIndAfter]->AddCurve( Release( pLineAfter), false) ; + vpCrvs[i].Set( Release( pCrvOffsOpenInPart)) ; + // considero questo tratto come chiuso + for ( int j = 0 ; j < vpCrvs[i]->GetCurveCount() ; ++ j) + vpCrvs[i]->SetCurveTempProp( j, TEMP_PROP_CLOSE_EDGE, 0) ; + } + + } + // ricostrusico il nuovo bordo + pCrvNewBorder->Clear() ; + #if DEBUG_OPEN_EDGE_IN_RAW + _debug_draw_OpenEdgesInRaw( vpCrvs, nLayResult) ; + #endif + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( ! pCrvNewBorder->AddCurve( Release( vpCrvs[i]))) + return false ; + } + // lo riporto nel frame globale + pCrvNewBorder->ToGlob( frXY) ; + } + // ricostruisco il Chunk con il nuovo bordo + PtrOwner pNewChunk( CreateSurfFlatRegion()) ; + if ( IsNull( pNewChunk) || ! pNewChunk->AddExtLoop( Release( pCrvNewBorder))) + return false ; + for ( int nI = 1 ; nI < vChunks[nC]->GetLoopCount( 0) ; ++ nI) { + if ( ! pNewChunk->AddIntLoop( vChunks[nC]->GetLoop( 0, nI))) + return false ; + } + vChunks[nC].Set( Release( pNewChunk)) ; + bModifSfr = true ; + } + + // recupero la regione finale + if ( bModifSfr) { + PtrOwner pSfrTmp( CreateSurfFlatRegion()) ; + if ( IsNull( pSfrTmp)) + return false ; + for ( auto& pSfrC : vChunks) { + if ( pSfrTmp->IsValid()) + pSfrTmp->Add( *pSfrC) ; + else + pSfrTmp.Set( pSfrC) ; + } + pSfr->CopyFrom( pSfrTmp) ; + } + + #if DEBUG_OPEN_EDGE_IN_RAW + _debug_draw_sfr( pSfr, false, nLayResult) ; + #endif + return ( pSfr->IsValid()) ; +} + //---------------------------------------------------------------------------- bool PocketingNT::ProcessPath( int nPathId, int nPvId, int nClId) @@ -2533,7 +2885,10 @@ PocketingNT::ProcessPath( int nPathId, int nPvId, int nClId) return false ; } #if DEBUG_FLATREGIONS - _debug_draw_sfr( pSfrPock, false) ; + int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; + int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; + m_pGeomDB->SetName( nLay, "Sfr_Pocketing") ; + _debug_draw_sfr( pSfrPock, false, nLay) ; #endif // determino la regione limite PtrOwner pSfrLimit( CreateSurfFlatRegion()) ; @@ -2543,10 +2898,7 @@ PocketingNT::ProcessPath( int nPathId, int nPvId, int nClId) return false ; } #if DEBUG_FLATREGIONS - int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; - int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; - m_pGeomDB->SetName( nLay, "Sfr_Limit") ; - int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrLimit->Clone()) ; + int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pSfrLimit->Clone()) ; m_pGeomDB->SetMaterial( _a, Color( .5, .5, .5, .5)) ; #endif // inserisco le informazioni dello step nel vettore @@ -3051,10 +3403,13 @@ PocketingNT::AddPocket( STEPINFOPOVECTOR& vStepInfo, const Vector3d& vtTool, dou dNextElev = dCurrElev ; } } - else if ( bNextIsBelow) + else if ( bNextIsBelow) { dNextElev += ( ptEnd - ptDest) * vtTool ; + if ( bSafePock) + dNextElev = max( 0., dNextElev - EXTRA_ELEV) ; + } else { - dCurrElev += ( ptDest - ptEnd) * vtTool - currStep.dRelativeDepth ; + dCurrElev += ( ptDest - ptEnd) * vtTool - currStep.dRelativeDepth ; dNextElev -= currStep.dRelativeDepth ; } } @@ -3774,8 +4129,8 @@ PocketingNT::GetRadiusForStartEndElevation( void) bool PocketingNT::GetForcedClosed( void) { - int nOpen ; - return ( GetValInNotes( m_Params.m_sUserNotes, UN_OPEN, nOpen) && nOpen == 0) ; + double dOpenLen ; + return ( GetValInNotes( m_Params.m_sUserNotes, UN_OPEN, dOpenLen) && dOpenLen < EPS_ZERO) ; } //---------------------------------------------------------------------------- @@ -4178,20 +4533,17 @@ PocketingNT::CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const V // debug functions //---------------------------------------------------------------------------- void -PocketingNT::_debug_draw_sfr( const ISurfFlatRegion* pSfr, bool bUniform) +PocketingNT::_debug_draw_sfr( const ISurfFlatRegion* pSfr, bool bUniform, int nLayer) { if ( pSfr == nullptr || ! pSfr->IsValid()) return ; - int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; - int nLay = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrp, GLOB_FRM) ; - m_pGeomDB->SetName( nLay, "Sfr_Pocketing") ; - int nInd = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLay, pSfr->Clone()) ; + int nInd = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayer, pSfr->Clone()) ; m_pGeomDB->SetMaterial( nInd, Color( 0., 255., 0., .5)) ; for ( int nC = 0 ; nC < pSfr->GetChunkCount() ; ++ nC) { for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) ; ++ nL) { PtrOwner pCrvCompo( ConvertCurveToComposite( pSfr->GetLoop( nC, nL))) ; - _debug_draw_loop( pCrvCompo->Clone(), nLay, bUniform) ; + _debug_draw_loop( pCrvCompo->Clone(), nLayer, bUniform) ; } } @@ -4216,7 +4568,7 @@ PocketingNT::_debug_draw_loop( const ICurveComposite* pCrvCompo, int nLayer, boo //---------------------------------------------------------------------------- void -PocketingNT::_degub_draw_box( const BBox3d& BBox, const Frame3d& FrBox, int nLayer) +PocketingNT::_debug_draw_box( const BBox3d& BBox, const Frame3d& FrBox, int nLayer) { Point3d ptMin = BBox.GetMin() ; ptMin.ToGlob( FrBox) ; Point3d ptMax = BBox.GetMax() ; ptMax.ToGlob( FrBox) ; @@ -4253,3 +4605,20 @@ PocketingNT::_degub_draw_box( const BBox3d& BBox, const Frame3d& FrBox, int nLay fr->Set( FrBox) ; _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayer, fr->Clone()) ; } + +//---------------------------------------------------------------------------- +void +PocketingNT::_debug_draw_OpenEdgesInRaw( const ICRVCOMPOPOVECTOR& vpCrvs, int nlayer) +{ + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + Color myColor = BLACK ; + if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_CLOSE_EDGE) + myColor = BLUE ; + else if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE) + myColor = RED ; + else if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE_IN_RAW) + myColor = ORANGE ; + int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nlayer, vpCrvs[i]->Clone()) ; + m_pGeomDB->SetMaterial( _a, myColor) ; + } +} \ No newline at end of file diff --git a/PocketingNT.h b/PocketingNT.h index 3649fd7..182eb2c 100644 --- a/PocketingNT.h +++ b/PocketingNT.h @@ -101,10 +101,12 @@ class PocketingNT : public Machining bool ResetCurveAllTempProp( ICurve* pCurve) ; bool Chain( int nGrpDestId) ; ISurfTriMesh* GetRaw( void) ; + ISurfTriMesh* GetRawPart( void) ; ISurfTriMesh* GetExtrusionStm( const ISurfFlatRegion* pSfr, const Vector3d& vtTrasl, const Vector3d& vtExtr) ; ISurfFlatRegion* GetSfrByStmIntersection( const IntersParPlanesSurfTm& IPPStm, double dDist, double dSmallOffs = 0) ; + bool ManageOpenEdges( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmPart) ; bool GetHomogeneousParts( const ICurveComposite* pCrvCompo, ICRVCOMPOPOVECTOR& vpCrvs) const ; - bool ExtendOpenEdgesToRaw( ICurveComposite* pCompo, const Vector3d& vtExtr) ; + bool ExtendOpenEdges( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStm) ; bool ChooseCloseOrOpenEdge( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmExtrusion) ; bool CalcLimitRegion( const ISurfFlatRegion* pSfrPock, const ISurfFlatRegion* pSfrRaw, ISurfFlatRegion* pSfrLimit) ; bool ProcessPath( int nPathId, int nPvId, int nClId) ; @@ -144,9 +146,10 @@ class PocketingNT : public Machining bool VerifyLeadInZigZag( const ISurfFlatRegion* pSfr, const Point3d& ptStart, const Point3d& ptPa, const Point3d& ptPb) ; bool CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist, Vector3d& vtNorm) ; // debug - void _debug_draw_sfr( const ISurfFlatRegion* pSfr, bool bUniform) ; + void _debug_draw_sfr( const ISurfFlatRegion* pSfr, bool bUniform, int nlayer = GDB_ID_NULL) ; void _debug_draw_loop( const ICurveComposite* pCrvCompo, int nLayer, bool bUniform) ; - void _degub_draw_box( const BBox3d& BBox, const Frame3d& FrBox, int nlayer) ; + void _debug_draw_box( const BBox3d& BBox, const Frame3d& FrBox, int nlayer) ; + void _debug_draw_OpenEdgesInRaw( const ICRVCOMPOPOVECTOR& vpCrvsm, int nlayer) ; private : double GetSpeed( void) const @@ -199,7 +202,7 @@ class PocketingNT : public Machining AggrBottom m_AggrBottom ; // dati eventuale aggregato da sotto bool m_bOpenOutRaw ; // flag forzatura lati aperti sempre fuori dal grezzo double m_dOpenMinSafe ; // minima distanza di sicurezza di attacco su lato aperto - double m_dOpenExtension ; // estensione dei tratti aperti dentro al grezzo + double m_dOpenInRawExtension ; // estensione dei tratti aperti dentro al grezzo bool m_bAllClose ; // flag per forzare i lati come tutti chiusi bool m_bRunning ; // flag di calcoli in corso } ; \ No newline at end of file