From ca400dd8d43826babee4a5bb7d120b3e7766a8bd Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 22 Jun 2018 09:47:00 +0000 Subject: [PATCH] EgtMachKernel : - aggiunta gestione regioni come geometria sorgente in Milling, Pocketing e Chiseling - corretto controllo calcolo angoli con rinvio da sotto. --- Chiseling.cpp | 146 +++++++++++++++++++++++++++++++++++++++--------- Chiseling.h | 3 +- MachineCalc.cpp | 6 +- Milling.cpp | 97 +++++++++++++++++++++++++++----- Pocketing.cpp | 97 +++++++++++++++++++++++++------- 5 files changed, 286 insertions(+), 63 deletions(-) diff --git a/Chiseling.cpp b/Chiseling.cpp index 9acca8c..579107a 100644 --- a/Chiseling.cpp +++ b/Chiseling.cpp @@ -25,6 +25,7 @@ #include "/EgtDev/Include/EGkOffsetCurve.h" #include "/EgtDev/Include/EGkSfrCreate.h" #include "/EgtDev/Include/EGkSurfTriMesh.h" +#include "/EgtDev/Include/EGkExtText.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGnStringKeyVal.h" #include "/EgtDev/Include/EgtPointerOwner.h" @@ -722,51 +723,85 @@ Chiseling::GetGeometry( SELVECTOR& vIds) const bool Chiseling::VerifyGeometry( SelData Id, int& nSubs, int& nType) { - // ammessi : tutte curve o tutte facce di trimesh + // ammessi : curve, testi, facce di trimesh o regioni const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ; if ( pGObj == nullptr) return false ; // se ammesse curve ed è tale - if ( nType != GEO_SURF && ( pGObj->GetType() & GEO_CURVE) != 0) { + if ( ( nType == GEO_NONE || nType == GEO_CURVE) && ( pGObj->GetType() & GEO_CURVE) != 0) { + nType = GEO_CURVE ; const ICurve* pCurve = nullptr ; // se direttamente la curva if ( Id.nSub == SEL_SUB_ALL) { pCurve = ::GetCurve( pGObj) ; - if ( pCurve != nullptr) { - if ( pCurve->GetType() == CRV_COMPO) - nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; - else - nSubs = 0 ; - } + if ( pCurve == nullptr) + return false ; + if ( pCurve->GetType() == CRV_COMPO) + nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; + else + nSubs = 0 ; } // altrimenti sottocurva di composita else { const ICurveComposite* pCompo = GetCurveComposite( pGObj) ; - if ( pCompo != nullptr) - pCurve = pCompo->GetCurve( Id.nSub) ; + pCurve = ( pCompo != nullptr ? pCompo->GetCurve( Id.nSub) : nullptr) ; + if ( pCurve == nullptr) + return false ; nSubs = 0 ; } - return ( pCurve != nullptr) ; + return true ; + } + // se altrimenti ammessi testi ed è tale + else if ( ( nType == GEO_NONE || nType == EXT_TEXT) && pGObj->GetType() == EXT_TEXT) { + nType = EXT_TEXT ; + const IExtText* pText = ::GetExtText( pGObj) ; + if ( pText == nullptr) + return false ; + // tutto bene + nSubs = 0 ; + return true ; } // se altrimenti ammesse superfici trimesh ed è tale - else if ( nType != GEO_CURVE && ( pGObj->GetType() & GEO_SURF) != 0) { + else if ( ( nType == GEO_NONE || nType == SRF_TRIMESH) && pGObj->GetType() == SRF_TRIMESH) { + nType = SRF_TRIMESH ; const ISurfTriMesh* pSurf = ::GetSurfTriMesh( pGObj) ; if ( pSurf == nullptr) return false ; // se direttamente la superficie if ( Id.nSub == SEL_SUB_ALL) { - nSubs = pSurf->GetFacetCount() ; - return true ; + // deve avere una sola faccia + if ( pSurf->GetFacetCount() != 1) + return false ; + nSubs = 1 ; } // altrimenti faccia di superficie trimesh else { // se faccia non esistente if ( Id.nSub > pSurf->GetFacetCount()) return false ; + nSubs = 0 ; + } + return true ; + } + // se altrimenti ammesse regioni ed è tale + else if ( ( nType == GEO_NONE || nType == SRF_FLATRGN) && pGObj->GetType() == SRF_FLATRGN) { + nType = SRF_FLATRGN ; + const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ; + if ( pReg == nullptr) + return false ; + // se direttamente la regione + if ( Id.nSub == SEL_SUB_ALL) { + nSubs = pReg->GetChunkCount() ; + } + // altrimenti chunk di regione + else { + // se chunk non esistente + if ( Id.nSub >= pReg->GetChunkCount()) + return false ; // tutto bene nSubs = 0 ; - return true ; } + return true ; } // altrimenti errore else @@ -774,10 +809,10 @@ Chiseling::VerifyGeometry( SelData Id, int& nSubs, int& nType) } //---------------------------------------------------------------------------- -ICurve* -Chiseling::GetCurve( SelData Id) +bool +Chiseling::GetCurves( SelData Id, ICURVEPLIST& lstPC) { - // ammessi : curve o facce di polymesh + // ammessi : curve, testi, facce di trimesh o regioni const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ; if ( pGObj == nullptr) return nullptr ; @@ -824,7 +859,23 @@ Chiseling::GetCurve( SelData Id) // la porto in globale pCurve->ToGlob( frGlob) ; // la restituisco - return Release( pCurve) ; + lstPC.emplace_back( Release( pCurve)) ; + return true ; + } + // se altrimenti testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pText = ::GetExtText( pGObj) ; + if ( pText == nullptr) + return false ; + // recupero l'outline del testo + if ( ! pText->GetOutline( lstPC)) + return false ; + // porto le curve in globale + for ( auto pCrv : lstPC) + pCrv->ToGlob( frGlob) ; + // ritorno + return true ; } // se altrimenti superficie else if ( ( pGObj->GetType() & GEO_SURF) != 0) { @@ -857,7 +908,46 @@ Chiseling::GetCurve( SelData Id) // sistemazioni varie AdjustCurveFromSurf( pCrvCompo, TOOL_ORTHO, FACE_CONT, 0) ; // la restituisco - return Release( pCrvCompo) ; + lstPC.emplace_back( Release( pCrvCompo)) ; + return true ; + } + // se altrimenti regione + else if ( pGObj->GetType() == SRF_FLATRGN) { + // recupero la regione + const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ; + if ( pReg == nullptr) + return false ; + // recupero la normale della regione + Vector3d vtN = pReg->GetNormVersor() ; + if ( vtN.IsSmall()) + return false ; + // determino intervallo di chunk + int nCstart = 0 ; + int nCend = pReg->GetChunkCount() ; + if ( Id.nSub != SEL_SUB_ALL) { + nCstart = Id.nSub ; + nCend = nCstart + 1 ; + } + // ciclo sui chunk + for ( int nC = nCstart ; nC < nCend ; ++ nC) { + // recupero i contorni del chunk + for ( int nL = 0 ; nL < pReg->GetLoopCount( nC) ; ++ nL) { + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo) || ! pCrvCompo->AddCurve( pReg->GetLoop( nC, nL))) + return false ; + // assegno l'estrusione dalla normale alla regione + pCrvCompo->SetExtrusion( vtN) ; + // unisco le eventuali parti allineate + pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ; + // la porto in globale + pCrvCompo->ToGlob( frGlob) ; + // sistemazioni varie + AdjustCurveFromSurf( pCrvCompo, TOOL_ORTHO, FACE_CONT, 0) ; + // la restituisco + lstPC.emplace_back( Release( pCrvCompo)) ; + } + } + return true ; } // altrimenti errore else @@ -871,15 +961,19 @@ Chiseling::Chain( int nGrpDestId) // vettore puntatori alle curve ICURVEPOVECTOR vpCrvs ; vpCrvs.reserve( m_vId.size()) ; + // vettore selettori delle curve originali + SELVECTOR vInds ; // recupero tutte le curve e le porto in globale for ( const auto& Id : m_vId) { - // prendo curva - vpCrvs.emplace_back( GetCurve( Id)) ; - // ne verifico la validità - if ( IsNull( vpCrvs.back())) { + // prendo le curve + ICURVEPLIST lstPC ; + if ( ! GetCurves( Id, lstPC)) { string sOut = "Entity " + ToString( Id) + " skipped by Chiseling" ; LOG_INFO( GetEMkLogger(), sOut.c_str()) ; - vpCrvs.back().Reset() ; + } + for ( auto pCrv : lstPC) { + vpCrvs.emplace_back( pCrv) ; + vInds.emplace_back( Id) ; } } // preparo i dati per il concatenamento @@ -925,7 +1019,7 @@ Chiseling::Chain( int nGrpDestId) for ( size_t i = 0 ; i < vnId2.size() ; ++ i) { int nId = abs( vnId2[i]) - 1 ; bool bInvert = ( vnId2[i] < 0) ; - vId2.emplace_back( m_vId[nId]) ; + vId2.emplace_back( vInds[nId]) ; // recupero la curva ICurve* pCrv = vpCrvs[nId] ; // se necessario, la inverto diff --git a/Chiseling.h b/Chiseling.h index 0bff432..09fcdf8 100644 --- a/Chiseling.h +++ b/Chiseling.h @@ -16,6 +16,7 @@ #include "Machining.h" #include "ChiselingData.h" #include "ToolData.h" +#include "/EgtDev/Include/EGkCurve.h" struct SqHole ; class ICurve ; @@ -66,7 +67,7 @@ class Chiseling : public Machining private : bool VerifyGeometry( SelData Id, int& nSubs, int& nType) ; - ICurve* GetCurve( SelData Id) ; + bool GetCurves( SelData Id, ICURVEPLIST& lstPC) ; bool Chain( int nGrpDestId) ; bool ProcessPath( int nPathId, int nPvId, int nClId) ; bool CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double& dElev) ; diff --git a/MachineCalc.cpp b/MachineCalc.cpp index 99b35d4..686de7b 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -837,9 +837,9 @@ Machine::GetMyAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, double dCompTOrtAxR1 = ( ( dTemp > EPS_ZERO) ? sqrt( dTemp) : 0) ; dTemp = 1 - dCompHSuAxR1 * dCompHSuAxR1 ; double dCompHOrtAxR1 = ( ( dTemp > EPS_ZERO) ? sqrt( dTemp) : 0) ; - // verifica ( max delta angolare < 0.002 deg) - const double SIN_ANG_ERROR = sin( 0.002 * DEGTORAD) ; - if ( fabs( dCompTOrtAxR1 * dCompHSuAxR1 - dCompHOrtAxR1 * dCompTSuAxR1) < SIN_ANG_ERROR) { + // verifica ( controllo verso e max delta angolare < 0.002 deg) + if ( fabs( dCompTSuAxR1 - dCompHSuAxR1) < EPS_SMALL && + fabs( dCompTOrtAxR1 * dCompHSuAxR1 - dCompHOrtAxR1 * dCompTSuAxR1) < 2 * SIN_EPS_ANG_SMALL) { nStat = 1 ; vtDirH1 = vtDirHn ; vtDirI1 = vtDirIn ; diff --git a/Milling.cpp b/Milling.cpp index 9e99dae..288dbe7 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -833,7 +833,7 @@ Milling::GetGeometry( SELVECTOR& vIds) const bool Milling::VerifyGeometry( SelData Id, int& nSubs, int& nType) { - // ammessi : o curve o testi o facce di trimesh + // ammessi : curve, testi, facce di trimesh o regioni const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ; if ( pGObj == nullptr) return false ; @@ -844,21 +844,22 @@ Milling::VerifyGeometry( SelData Id, int& nSubs, int& nType) // se direttamente la curva if ( Id.nSub == SEL_SUB_ALL) { pCurve = ::GetCurve( pGObj) ; - if ( pCurve != nullptr) { - if ( pCurve->GetType() == CRV_COMPO) - nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; - else - nSubs = 0 ; - } + if ( pCurve == nullptr) + return false ; + if ( pCurve->GetType() == CRV_COMPO) + nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; + else + nSubs = 0 ; } // altrimenti sottocurva di composita else { const ICurveComposite* pCompo = GetCurveComposite( pGObj) ; - if ( pCompo != nullptr) - pCurve = pCompo->GetCurve( Id.nSub) ; + pCurve = ( pCompo != nullptr ? pCompo->GetCurve( Id.nSub) : nullptr) ; + if ( pCurve == nullptr) + return false ; nSubs = 0 ; } - return ( pCurve != nullptr) ; + return true ; } // se altrimenti ammessi testi ed è tale else if ( ( nType == GEO_NONE || nType == EXT_TEXT) && pGObj->GetType() == EXT_TEXT) { @@ -878,18 +879,39 @@ Milling::VerifyGeometry( SelData Id, int& nSubs, int& nType) return false ; // se direttamente la superficie if ( Id.nSub == SEL_SUB_ALL) { - nSubs = pSurf->GetFacetCount() ; - return true ; + // deve avere una sola faccia + if ( pSurf->GetFacetCount() != 1) + return false ; + nSubs = 1 ; } // altrimenti faccia di superficie trimesh else { // se faccia non esistente if ( Id.nSub > pSurf->GetFacetCount()) return false ; + nSubs = 0 ; + } + return true ; + } + // se altrimenti ammesse regioni ed è tale + else if ( ( nType == GEO_NONE || nType == SRF_FLATRGN) && pGObj->GetType() == SRF_FLATRGN) { + nType = SRF_FLATRGN ; + const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ; + if ( pReg == nullptr) + return false ; + // se direttamente la regione + if ( Id.nSub == SEL_SUB_ALL) { + nSubs = pReg->GetChunkCount() ; + } + // altrimenti chunk di regione + else { + // se chunk non esistente + if ( Id.nSub >= pReg->GetChunkCount()) + return false ; // tutto bene nSubs = 0 ; - return true ; } + return true ; } // altrimenti errore else @@ -900,7 +922,7 @@ Milling::VerifyGeometry( SelData Id, int& nSubs, int& nType) bool Milling::GetCurves( SelData Id, ICURVEPLIST& lstPC) { - // ammessi : curve, testi o facce di polymesh + // ammessi : curve, testi, facce di trimesh o regioni const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ; if ( pGObj == nullptr) return false ; @@ -1010,6 +1032,53 @@ Milling::GetCurves( SelData Id, ICURVEPLIST& lstPC) lstPC.emplace_back( Release( pCrvCompo)) ; return true ; } + // se altrimenti regione + else if ( pGObj->GetType() == SRF_FLATRGN) { + // recupero la regione + const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ; + if ( pReg == nullptr) + return false ; + // recupero la normale della regione + Vector3d vtN = pReg->GetNormVersor() ; + if ( vtN.IsSmall()) + return false ; + // sistemazioni varie + int nToolDir ; + if ( ( m_Params.m_nFaceUse & 64) != 0) + nToolDir = TOOL_ORTUP ; + else if ( ( m_Params.m_nFaceUse & 32) != 0) + nToolDir = TOOL_ORTHO ; + else + nToolDir = TOOL_PARAL ; + int nFaceUse = ( m_Params.m_nFaceUse & 31) ; + // determino intervallo di chunk + int nCstart = 0 ; + int nCend = pReg->GetChunkCount() ; + if ( Id.nSub != SEL_SUB_ALL) { + nCstart = Id.nSub ; + nCend = nCstart + 1 ; + } + // ciclo sui chunk + for ( int nC = nCstart ; nC < nCend ; ++ nC) { + // recupero i contorni del chunk + for ( int nL = 0 ; nL < pReg->GetLoopCount( nC) ; ++ nL) { + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo) || ! pCrvCompo->AddCurve( pReg->GetLoop( nC, nL))) + return false ; + // assegno l'estrusione dalla normale alla regione + pCrvCompo->SetExtrusion( vtN) ; + // unisco le eventuali parti allineate + pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ; + // la porto in globale + pCrvCompo->ToGlob( frGlob) ; + // sistemazioni varie + AdjustCurveFromSurf( pCrvCompo, nToolDir, nFaceUse, m_TParams.m_dThick) ; + // la restituisco + lstPC.emplace_back( Release( pCrvCompo)) ; + } + } + return true ; + } // altrimenti errore else return false ; diff --git a/Pocketing.cpp b/Pocketing.cpp index 70c792c..47ffb1a 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -787,7 +787,7 @@ Pocketing::GetGeometry( SELVECTOR& vIds) const bool Pocketing::VerifyGeometry( SelData Id, int& nSubs, int& nType) { - // ammessi : o curve o testi o facce di trimesh + // ammessi : curve, testi, facce di trimesh o regioni const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ; if ( pGObj == nullptr) return false ; @@ -795,24 +795,25 @@ Pocketing::VerifyGeometry( SelData Id, int& nSubs, int& nType) if ( ( nType == GEO_NONE || nType == GEO_CURVE) && ( pGObj->GetType() & GEO_CURVE) != 0) { nType = GEO_CURVE ; const ICurve* pCurve = nullptr ; - // se direttamente la curva + // se direttamente la curva if ( Id.nSub == SEL_SUB_ALL) { pCurve = ::GetCurve( pGObj) ; - if ( pCurve != nullptr) { - if ( pCurve->GetType() == CRV_COMPO) - nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; - else - nSubs = 0 ; - } + if ( pCurve == nullptr) + return false ; + if ( pCurve->GetType() == CRV_COMPO) + nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; + else + nSubs = 0 ; } - // altrimenti sottocurva di composita + // altrimenti sottocurva di composita else { const ICurveComposite* pCompo = GetCurveComposite( pGObj) ; - if ( pCompo != nullptr) - pCurve = pCompo->GetCurve( Id.nSub) ; + pCurve = ( pCompo != nullptr ? pCompo->GetCurve( Id.nSub) : nullptr) ; + if ( pCurve == nullptr) + return false ; nSubs = 0 ; } - return ( pCurve != nullptr) ; + return true ; } // se altrimenti ammessi testi ed è tale else if ( ( nType == GEO_NONE || nType == EXT_TEXT) && pGObj->GetType() == EXT_TEXT) { @@ -820,7 +821,6 @@ Pocketing::VerifyGeometry( SelData Id, int& nSubs, int& nType) const IExtText* pText = ::GetExtText( pGObj) ; if ( pText == nullptr) return false ; - // tutto bene nSubs = 0 ; return true ; } @@ -832,18 +832,39 @@ Pocketing::VerifyGeometry( SelData Id, int& nSubs, int& nType) return false ; // se direttamente la superficie if ( Id.nSub == SEL_SUB_ALL) { - nSubs = pSurf->GetFacetCount() ; - return true ; + // deve avere una sola faccia + if ( pSurf->GetFacetCount() != 1) + return false ; + nSubs = 1 ; } // altrimenti faccia di superficie trimesh else { // se faccia non esistente - if ( Id.nSub > pSurf->GetFacetCount()) + if ( Id.nSub >= pSurf->GetFacetCount()) + return false ; + nSubs = 0 ; + } + return true ; + } + // se altrimenti ammesse regioni ed è tale + else if ( ( nType == GEO_NONE || nType == SRF_FLATRGN) && pGObj->GetType() == SRF_FLATRGN) { + nType = SRF_FLATRGN ; + const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ; + if ( pReg == nullptr) + return false ; + // se direttamente la regione + if ( Id.nSub == SEL_SUB_ALL) { + nSubs = pReg->GetChunkCount() ; + } + // altrimenti chunk di regione + else { + // se chunk non esistente + if ( Id.nSub >= pReg->GetChunkCount()) return false ; // tutto bene nSubs = 0 ; - return true ; } + return true ; } // altrimenti errore else @@ -854,7 +875,7 @@ Pocketing::VerifyGeometry( SelData Id, int& nSubs, int& nType) bool Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC) { - // ammessi : curve, testi o facce di polymesh + // ammessi : curve, testi, facce di trimesh o regioni const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ; if ( pGObj == nullptr) return false ; @@ -923,7 +944,7 @@ Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC) return true ; } // se altrimenti superficie - else if ( ( pGObj->GetType() & GEO_SURF) != 0) { + else if ( pGObj->GetType() == SRF_TRIMESH) { // recupero la trimesh const ISurfTriMesh* pSurf = ::GetSurfTriMesh( pGObj) ; if ( pSurf == nullptr) @@ -956,6 +977,44 @@ Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC) lstPC.emplace_back( Release( pCrvCompo)) ; return true ; } + // se altrimenti regione + else if ( pGObj->GetType() == SRF_FLATRGN) { + // recupero la regione + const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ; + if ( pReg == nullptr) + return false ; + // recupero la normale della regione + Vector3d vtN = pReg->GetNormVersor() ; + if ( vtN.IsSmall()) + return false ; + // determino intervallo di chunk + int nCstart = 0 ; + int nCend = pReg->GetChunkCount() ; + if ( Id.nSub != SEL_SUB_ALL) { + nCstart = Id.nSub ; + nCend = nCstart + 1 ; + } + // ciclo sui chunk + for ( int nC = nCstart ; nC < nCend ; ++ nC) { + // recupero i contorni del chunk + for ( int nL = 0 ; nL < pReg->GetLoopCount( nC) ; ++ nL) { + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo) || ! pCrvCompo->AddCurve( pReg->GetLoop( nC, nL))) + return false ; + // assegno l'estrusione dalla normale alla regione + pCrvCompo->SetExtrusion( vtN) ; + // unisco le eventuali parti allineate + pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ; + // la porto in globale + pCrvCompo->ToGlob( frGlob) ; + // sistemazioni varie + AdjustCurveFromSurf( pCrvCompo, TOOL_ORTHO, FACE_CONT, 0) ; + // la restituisco + lstPC.emplace_back( Release( pCrvCompo)) ; + } + } + return true ; + } // altrimenti errore else return false ;