From 2d0ea787fa5e6967478cefae89bbd9c40365d425 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 20 Feb 2017 18:28:57 +0000 Subject: [PATCH] EgtMachKernel : - in svuotature gestione SpiralIn e SpiralOut ottimizzate per cerchi - in svuotatura aggiunti attacchi zigzag e elica e uscita Glide - in contornatura miglioramenti vari. --- Chiseling.cpp | 36 ++-- Disposition.cpp | 25 ++- Drilling.cpp | 34 ++- GenMachining.cpp | 30 +-- MachConst.h | 4 + Milling.cpp | 180 +++++++++------- Milling.h | 3 +- Operation.cpp | 107 ++++++++-- Operation.h | 8 + OperationCL.cpp | 79 +++++++ Pocketing.cpp | 512 +++++++++++++++++++++++++++++----------------- Pocketing.h | 37 +++- PocketingData.cpp | 18 +- PocketingData.h | 3 +- SawFinishing.cpp | 33 +-- SawRoughing.cpp | 26 ++- Sawing.cpp | 91 ++++---- 17 files changed, 825 insertions(+), 401 deletions(-) diff --git a/Chiseling.cpp b/Chiseling.cpp index 0f6e9b8..14a88c1 100644 --- a/Chiseling.cpp +++ b/Chiseling.cpp @@ -31,6 +31,15 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2901 = "Error in Chiseling : UpdateToolData failed" +// 2902 = "Error in Chiseling : Offset not computable" +// 2903 = "Error in Chiseling : Empty RawBox" +// 2904 = "Error in Chiseling : Depth not computable" +// 2905 = "Error in Chiseling : machining depth (xxx) bigger than MaxMaterial (yyy)" +// 2906 = "Error in Chiseling : Entity GetElevation" +// 2907 = "Error in Chiseling : Chaining failed" + //---------------------------------------------------------------------------- struct SqHole { @@ -371,14 +380,15 @@ Chiseling::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2901, "Error in Chiseling : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2907, "Error in Chiseling : Chaining failed") ; return false ; - + } // recupero gruppo per geometria di Preview int nPvId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_PV) ; // se non c'è, lo aggiungo @@ -434,13 +444,15 @@ Chiseling::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2901, "Error in Chiseling : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2907, "Error in Chiseling : Chaining failed") ; return false ; + } // recupero gruppo per geometria di lavorazione (Cutter Location) int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; @@ -975,7 +987,7 @@ Chiseling::ProcessPath( int nPathId, int nPvId, int nClId) } } if ( ! bOk) { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : Offset not computable") ; + m_pMchMgr->SetLastError( 2902, "Error in Chiseling : Offset not computable") ; return false ; } } @@ -988,7 +1000,7 @@ Chiseling::ProcessPath( int nPathId, int nPvId, int nClId) // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nPathId, 0.5 * m_TParams.m_dDiam, b3Raw) || b3Raw.IsEmpty()) { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : Empty RawBox") ; + m_pMchMgr->SetLastError( 2903, "Error in Chiseling : Empty RawBox") ; return false ; } @@ -1005,7 +1017,7 @@ Chiseling::ProcessPath( int nPathId, int nPvId, int nClId) double dDepth ; string sMyDepth = m_Params.m_sDepth ; if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : Depth not computable") ; + m_pMchMgr->SetLastError( 2904, "Error in Chiseling : Depth not computable") ; return false ; } // se spessore positivo, lo sottraggo dal risultato @@ -1046,7 +1058,7 @@ Chiseling::ProcessPath( int nPathId, int nPvId, int nClId) else { string sInfo = "Error in Chiseling : machining depth (" + ToString( dElev, 1) + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; - LOG_INFO( GetEMkLogger(), sInfo.c_str()) ; + m_pMchMgr->SetLastError( 2905, sInfo.c_str()) ; return false ; } } @@ -1187,7 +1199,7 @@ Chiseling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2906, "Error in Chiseling : Entity GetElevation") ; return false ; } // da una parte @@ -1197,7 +1209,7 @@ Chiseling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2906, "Error in Chiseling : Entity GetElevation") ; return false ; } // dall'altra parte @@ -1207,7 +1219,7 @@ Chiseling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Chiseling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2906, "Error in Chiseling : Entity GetElevation") ; return false ; } } diff --git a/Disposition.cpp b/Disposition.cpp index 80f613a..8420965 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -25,6 +25,13 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2001 = "Error adding fixture xx" +// 2002 = "Error placing fixture xx" +// 2003 = "Error in MoveToCornerRawPart xx" +// 2004 = "Error in MoveToCenterRawPart xx" +// 2005 = "Error in ApplyRotationToRawPart xx" + //---------------------------------------------------------------------------- static std::string DIS_TABLE = "Tab" ; static std::string DIS_PHASE = "Ph" ; @@ -360,6 +367,7 @@ Disposition::Apply( bool bVerifyTab) // verifico tavola if ( ( ! m_bTabOk || bVerifyTab) && ! SetTable( m_sTabName)) return false ; + bool bOk = true ; // aggiornamento sottopezzi for ( auto& FixData : m_vFixData) { // se sottopezzo da caricare @@ -367,7 +375,8 @@ Disposition::Apply( bool bVerifyTab) int nId = AddFixture( FixData.sName, FixData.ptPos, FixData.dAng, FixData.dMov, false) ; if ( nId == GDB_ID_NULL) { string sOut = "Error adding fixture " + FixData.sName ; - LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2001, sOut.c_str()) ; + bOk = false ; } else FixData.nId = nId ; @@ -376,7 +385,8 @@ Disposition::Apply( bool bVerifyTab) else { if ( ! PlaceFixture( FixData.nId, FixData.ptPos, FixData.dAng, FixData.dMov)) { string sOut = "Error placing fixture " + ToString( FixData.nId) ; - LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2002, sOut.c_str()) ; + bOk = false ; } } } @@ -397,25 +407,28 @@ Disposition::Apply( bool bVerifyTab) case MoveRawData::COR : if ( ! MoveToCornerRawPart( vMvrData.nRawId, vMvrData.ptP, vMvrData.nFlag, false)) { string sOut = "Error in MoveToCornerRawPart " + ToString( vMvrData.nRawId) ; - LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2003, sOut.c_str()) ; + bOk = false ; } break ; case MoveRawData::CEN : if ( ! MoveToCenterRawPart( vMvrData.nRawId, vMvrData.ptP, vMvrData.nFlag, false)) { string sOut = "Error in MoveToCenterRawPart " + ToString( vMvrData.nRawId) ; - LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2004, sOut.c_str()) ; + bOk = false ; } break ; case MoveRawData::ROT : if ( ! ApplyRotationToRawPart( vMvrData.nRawId, vMvrData.ptP.x, vMvrData.ptP.y, vMvrData.ptP.z, false)) { string sOut = "Error in ApplyRotationToRawPart " + ToString( vMvrData.nRawId) ; - LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2005, sOut.c_str()) ; + bOk = false ; } break ; } } - return true ; + return bOk ; } //---------------------------------------------------------------------------- diff --git a/Drilling.cpp b/Drilling.cpp index 919ab04..0c7274b 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -30,6 +30,16 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2101 = "Error in Drilling : UpdateToolData failed" +// 2102 = "Error in Drilling : Offset not computable" +// 2103 = "Error in Drilling : Overlap not computable" +// 2104 = "Error in Drilling : Depth not computable" +// 2105 = "Error in Drilling : Drill with zero depth" +// 2106 = "Error in Drilling : Entity xx skipped because missing aggregate from bottom" +// 2107 = "Error in Drilling : Entity xx skipped because too far from part sides" +// 2108 = "Error in Drilling : Chaining failed" + //---------------------------------------------------------------------------- struct Hole { @@ -405,7 +415,7 @@ Drilling::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Drilling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2101, "Error in Drilling : UpdateToolData failed") ; return false ; } @@ -446,7 +456,7 @@ Drilling::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Drilling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2101, "Error in Drilling : UpdateToolData failed") ; return false ; } @@ -535,8 +545,10 @@ Drilling::AlongCurveProcess( bool bRecalc, int nPvId, int nClId) } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2108, "Error in Drilling : Chaining failed") ; return false ; + } // calcolo ogni singola catena int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ; @@ -727,12 +739,12 @@ Drilling::ProcessPath( int nPathId, int nPvId, int nClId) ExeLuaSetGlobNumVar( "D", m_TParams.m_dDiam) ; double dOffset ; if ( ! ExeLuaEvalNumExpr( m_Params.m_sOffset, &dOffset)) { - LOG_INFO( GetEMkLogger(), "Offset not computable by Drilling") ; + m_pMchMgr->SetLastError( 2102, "Error in Drilling : Offset not computable") ; return false ; } double dOverlap ; if ( ! ExeLuaEvalNumExpr( m_Params.m_sOverlap, &dOverlap)) { - LOG_INFO( GetEMkLogger(), "Overlap not computable by Drilling") ; + m_pMchMgr->SetLastError( 2103, "Error in Drilling : Overlap not computable") ; return false ; } @@ -1153,11 +1165,11 @@ Drilling::GetHoleData( SelData Id, Hole& hole) double dDepth ; string sMyDepth = m_Params.m_sDepth ; if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) { - LOG_INFO( GetEMkLogger(), "Depth not computable by Drilling") ; + m_pMchMgr->SetLastError( 2104, "Error in Drilling : Depth not computable") ; return false ; } if ( fabs( dDepth) < EPS_SMALL) { - LOG_INFO( GetEMkLogger(), "Drill with zero depth") ; + m_pMchMgr->SetLastError( 2105, "Error in Drilling : Drill with zero depth") ; return false ; } // assegno Id @@ -1202,8 +1214,8 @@ Drilling::VerifyHoleFromBottom( const Hole& hole, SelData Id) int nHeadId = m_pMchMgr->GetHeadId( m_TParams.m_sHead) ; int nAgbType ; if ( ! m_pGeomDB->GetInfo( nHeadId, "AGB_TYPE", nAgbType) || nAgbType == 0) { - string sOut = "Entity " + ToString( Id) + " skipped by Drilling : missing aggregate from bottom" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + string sOut = "Error in Drilling : Entity " + ToString( Id) + " skipped because missing aggregate from bottom" ; + m_pMchMgr->SetLastError( 2106, sOut.c_str()) ; return false ; } // recupero la massima distanza consentita dal rinvio @@ -1213,8 +1225,8 @@ Drilling::VerifyHoleFromBottom( const Hole& hole, SelData Id) double dDist ; Vector3d vtDir ; if ( ! GetMinDistanceFromRawSide( m_nPhase, hole.ptIni, dDist, vtDir) || dDist > dAgbDmax) { - string sOut = "Entity " + ToString( Id) + " skipped by Drilling : too far from part sides" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + string sOut = "Error in Drilling : Entity " + ToString( Id) + " skipped because too far from part sides" ; + m_pMchMgr->SetLastError( 2107, sOut.c_str()) ; return false ; } // assegno direzione di accesso e segnalazione di utilizzo aggregato da sotto diff --git a/GenMachining.cpp b/GenMachining.cpp index 5943244..e356386 100644 --- a/GenMachining.cpp +++ b/GenMachining.cpp @@ -315,7 +315,7 @@ GenMachining::SetGeometry( const SELVECTOR& vIds) // test sull'entità int nSubs ; if ( ! VerifyGeometry( Id, nSubs, nType)) { - string sOut = "Entity " + ToString( Id) + " skipped by Milling" ; + string sOut = "Entity " + ToString( Id) + " skipped by GenMachining" ; LOG_INFO( GetEMkLogger(), sOut.c_str()) ; continue ; } @@ -356,7 +356,7 @@ GenMachining::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + LOG_INFO( GetEMkLogger(), "Error in GenMachining : UpdateToolData failed") ; return false ; } @@ -419,13 +419,15 @@ GenMachining::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + LOG_INFO( GetEMkLogger(), "Error in GenMachining : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + LOG_INFO( GetEMkLogger(), "Error in GenMachining : Chaining failed") ; return false ; + } // recupero gruppo per geometria di lavorazione (Cutter Location) int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; @@ -824,7 +826,7 @@ GenMachining::Chain( int nGrpDestId) vpCrvs.emplace_back( GetCurve( Id)) ; // ne verifico la validità if ( IsNull( vpCrvs.back())) { - string sOut = "Entity " + ToString( Id) + " skipped by Milling" ; + string sOut = "Entity " + ToString( Id) + " skipped by GenMachining" ; LOG_INFO( GetEMkLogger(), sOut.c_str()) ; vpCrvs.back().Reset() ; } @@ -1020,17 +1022,7 @@ GenMachining::ProcessPath( int nPathId, int nPvId, int nClId) } // verifiche sull'ampiezza dell'angolo al centro degli eventuali archi - const double MAX_ANG_CEN = 150 + EPS_ANG_SMALL ; - int nMaxInd = pCompo->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // se arco con angolo al centro oltre il limite, lo divido a metà - const ICurveArc* pArc = GetCurveArc( pCompo->GetCurve( i)) ; - if ( pArc != nullptr && abs( pArc->GetAngCenter()) > MAX_ANG_CEN) { - pCompo->AddJoint( i + 0.5) ; - ++ i ; - ++ nMaxInd ; - } - } + VerifyArcs( pCompo) ; // calcolo il versore fresa Vector3d vtTool = Z_AX ; @@ -1152,7 +1144,7 @@ GenMachining::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + LOG_INFO( GetEMkLogger(), "Error in GenMachining : Entity GetElevation") ; return false ; } // da una parte @@ -1162,7 +1154,7 @@ GenMachining::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + LOG_INFO( GetEMkLogger(), "Error in GenMachining : Entity GetElevation") ; return false ; } // dall'altra parte @@ -1172,7 +1164,7 @@ GenMachining::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + LOG_INFO( GetEMkLogger(), "Error in GenMachining : Entity GetElevation") ; return false ; } } diff --git a/MachConst.h b/MachConst.h index 805c72f..329fc71 100644 --- a/MachConst.h +++ b/MachConst.h @@ -86,6 +86,10 @@ const double RAW_MIN_H = 1 ; // Minima feed const double FEED_MIN = 1 ; +//---------------------------------------------------------------------------- +// Massimo angolo al centro per archi di CL +const double MAX_ANG_CEN = 150.001 ; + //---------------------------------------------------------------------------- // Per FlatParts (vedi Nesting di EgtExecutor) const std::string NST_EXT_LAYER = "OutLoop" ; diff --git a/Milling.cpp b/Milling.cpp index 589c175..faf6cbb 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -31,6 +31,21 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2301 = "Error in Milling : UpdateToolData failed" +// 2302 = "Error in Milling : Offset not computable" +// 2303 = "Error in Milling : Empty RawBox" +// 2304 = "Error in Milling : Depth not computable" +// 2305 = "Error in Milling : machining depth (xx) bigger than MaxMaterial (yy)" +// 2306 = "Error in Milling : Entity GetElevation" +// 2307 = "Error in Milling : missing aggregate from bottom" +// 2308 = "Error in Milling : path too far from part sides" +// 2309 = "Error in Milling : LeadIn not computable" +// 2310 = "Error in Milling : LeadOut not computable" +// 2311 = "Error in Milling : Linear Approx not computable" +// 2312 = "Error in Milling : LeadIn must be out of rawpart" +// 2313 = "Error in Milling : Chaining failed" + //---------------------------------------------------------------------------- USEROBJ_REGISTER( "EMkMilling", Milling) ; @@ -416,13 +431,15 @@ Milling::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2301, "Error in Milling : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2313, "Error in Milling : Chaining failed") ; return false ; + } // recupero gruppo per geometria di Preview int nPvId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_PV) ; @@ -479,13 +496,15 @@ Milling::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2301, "Error in Milling : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2313, "Error in Milling : Chaining failed") ; return false ; + } // recupero gruppo per geometria di lavorazione (Cutter Location) int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; @@ -1009,6 +1028,9 @@ Milling::Chain( int nGrpDestId) pCrvCompo->SetThickness( dThick) ; // aggiorno il nuovo punto vicino pCrvCompo->GetEndPoint( ptNear) ; + // se utile, approssimo con archi + if ( ! ApproxWithArcsIfUseful( pCrvCompo)) + return false ; // creo nuovo gruppo int nPathId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpDestId, Frame3d()) ; if ( nPathId == GDB_ID_NULL) @@ -1071,8 +1093,8 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) double dThick ; pCompo->GetThickness( dThick) ; - // eventuali allungamenti/accorciamenti per percorso aperto - if ( ! pCompo->IsClosed()) { + // eventuali allungamenti/accorciamenti per percorso aperto o chiuso senza sovrapposizione + if ( ! pCompo->IsClosed() || m_Params.m_dOverlap < EPS_SMALL) { // verifico che il percorso sia abbastanza lungo double dLen ; pCompo->GetLength( dLen) ; if ( dLen + m_Params.m_dStartAddLen + m_Params.m_dEndAddLen < 10 * EPS_SMALL) { @@ -1106,14 +1128,7 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) // valore offset double dSignOffs = ( m_Params.m_nWorkSide == MILL_WS_RIGHT) ? dOffs : - dOffs ; // flag offset - int nFlag = ICurve::OFF_EXTEND ; - // se percorso chiuso senza overlap ed inizio/fine è un angolo esterno - if ( pCompo->IsClosed() && m_Params.m_dOverlap < EPS_SMALL) { - Vector3d vtStart, vtEnd ; - if ( pCompo->GetStartDir( vtStart) && pCompo->GetEndDir( vtEnd) && - ( vtEnd ^ vtStart) * vtExtr * dSignOffs > 0) - nFlag += ICurve::OFF_FORCE_OPEN ; - } + int nFlag = ICurve::OFF_FILLET ; // esecuzione offset if ( ! pCompo->SimpleOffset( dSignOffs, nFlag)) { // se curva piatta, provo con offset avanzato @@ -1132,7 +1147,7 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) } } if ( ! bOk) { - LOG_INFO( GetEMkLogger(), "Error in Milling : Offset not computable") ; + m_pMchMgr->SetLastError( 2302, "Error in Milling : Offset not computable") ; return false ; } } @@ -1165,7 +1180,7 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nPathId, 0.5 * m_TParams.m_dDiam, b3Raw) || b3Raw.IsEmpty()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : Empty RawBox") ; + m_pMchMgr->SetLastError( 2303, "Error in Milling : Empty RawBox") ; return false ; } @@ -1182,7 +1197,7 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) double dDepth ; string sMyDepth = m_Params.m_sDepth ; if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : Depth not computable") ; + m_pMchMgr->SetLastError( 2304, "Error in Milling : Depth not computable") ; return false ; } // se spessore positivo, lo sottraggo dal risultato @@ -1200,31 +1215,13 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) bool bSplitArcs = ( nSplitArcs == SPLAR_ALWAYS || ( nSplitArcs == SPLAR_NO_XY_PLANE && ! vtExtr.IsZplus()) || ( nSplitArcs == SPLAR_GEN_PLANE && vtExtr.IsGeneric())) ; - if ( bSplitArcs) { - const double ANG_TOL_MAX_DEG = 90 ; - PolyLine PL ; - if ( pCompo->ApproxWithLines( 50 * EPS_SMALL, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) { - // sostituisco le linee alle curve originali - pCompo->Clear() ; - pCompo->FromPolyLine( PL) ; - // riassegno estrusione e spessore - pCompo->SetExtrusion( vtExtr) ; - pCompo->SetThickness( dThick) ; - } + if ( bSplitArcs && ! ApproxWithLines( pCompo)) { + m_pMchMgr->SetLastError( 2311, "Error in Milling : Linear Approx not computable") ; + return false ; } // verifiche sull'ampiezza dell'angolo al centro degli eventuali archi - const double MAX_ANG_CEN = 150 + EPS_ANG_SMALL ; - int nMaxInd = pCompo->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // se arco con angolo al centro oltre il limite, lo divido a metà - const ICurveArc* pArc = GetCurveArc( pCompo->GetCurve( i)) ; - if ( pArc != nullptr && abs( pArc->GetAngCenter()) > MAX_ANG_CEN) { - pCompo->AddJoint( i + 0.5) ; - ++ i ; - ++ nMaxInd ; - } - } + VerifyArcs( pCompo) ; // calcolo il versore fresa Vector3d vtTool = Z_AX ; @@ -1257,7 +1254,7 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) else { string sInfo = "Error in Milling : machining depth (" + ToString( dElev, 1) + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; - LOG_INFO( GetEMkLogger(), sInfo.c_str()) ; + m_pMchMgr->SetLastError( 2305, sInfo.c_str()) ; return false ; } } @@ -1377,7 +1374,7 @@ Milling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtToo dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2306, "Error in Milling : Entity GetElevation") ; return false ; } // da una parte @@ -1387,7 +1384,7 @@ Milling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtToo dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2306, "Error in Milling : Entity GetElevation") ; return false ; } // dall'altra parte @@ -1397,7 +1394,7 @@ Milling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtToo dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2306, "Error in Milling : Entity GetElevation") ; return false ; } } @@ -1419,8 +1416,8 @@ Milling::VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& vt int nHeadId = m_pMchMgr->GetHeadId( m_TParams.m_sHead) ; int nAgbType ; if ( ! m_pGeomDB->GetInfo( nHeadId, "AGB_TYPE", nAgbType) || nAgbType == 0) { - string sOut = "Milling error : missing aggregate from bottom" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + string sOut = "Error in Milling : missing aggregate from bottom" ; + m_pMchMgr->SetLastError( 2307, sOut.c_str()) ; return false ; } // recupero la massima distanza consentita dal rinvio @@ -1460,8 +1457,8 @@ Milling::VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& vt } // se supera il limite, errore if ( dDist > dAgbDmax) { - string sOut = "Milling error : path too far from part sides" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + string sOut = "Error in Milling : path too far from part sides" ; + m_pMchMgr->SetLastError( 2308, sOut.c_str()) ; return false ; } // assegno direzione di accesso e segnalo utilizzo aggregato da sotto @@ -1558,19 +1555,26 @@ Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTo Point3d ptP1 ; if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, false, ptP1)) return false ; - // aggiungo approccio per frese normali con spazio sopra attacco + // determino se l'inizio dell'attacco è fuori dal grezzo + bool bOutStart = GetPointOutOfRaw( ptP1, vtTool) ; + // aggiungo approccio per frese normali con spazio sopra attacco if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) { - // determino elevazione su inizio attacco + // determino elevazione su inizio percorso di lavoro double dStElev ; if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dStElev)) dStElev = dElev ; dStElev -= ( ptP1 - ptStart) * vtExtr ; // approccio al punto iniziale - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr, bOutStart)) return false ; } // altrimenti, approccio per lame o diretto else { + // verifico di entrare in aria + if ( ! bOutStart) { + m_pMchMgr->SetLastError( 2312, "Error in Milling : LeadIn must be out of rawpart") ; + return false ; + } // affondo al punto iniziale SetFlag( 0) ; if ( AddRapidStart( ptP1) == GDB_ID_NULL) @@ -1579,7 +1583,7 @@ Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTo // aggiungo attacco SetFeed( GetStartFeed()) ; if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, false, bSplitArcs)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadIn not computable") ; + m_pMchMgr->SetLastError( 2309, "Error in Milling : LeadIn not computable") ; return false ; } } @@ -1613,7 +1617,7 @@ Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTo Point3d ptP1 ; SetFeed( GetStartFeed()) ; if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, false, bSplitArcs, ptP1)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadOut not computable") ; + m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadOut not computable") ; return false ; } // aggiungo retrazione per frese normali @@ -1676,6 +1680,8 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, bInvert, ptP1)) return false ; + // determino se l'inizio dell'attacco è fuori dal grezzo + bool bOutStart = GetPointOutOfRaw( ptP1, vtTool) ; // se primo step aggiungo approccio per frese normali if ( j == 1 && ( m_TParams.m_nType & TF_SAWBLADE) == 0) { // determino elevazione su inizio attacco @@ -1684,7 +1690,7 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool dStElev = dElev ; dStElev -= ( ptP1 - ptStart) * vtExtr ; // approccio al punto iniziale - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr, bOutStart)) return false ; } // altrimenti, affondo al punto iniziale @@ -1693,6 +1699,12 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool if ( ( m_TParams.m_nType & TF_SAWBLADE) != 0) { SetFlag( 0) ; if ( j == 1) { + // verifico di entrare in aria + if ( ! bOutStart) { + m_pMchMgr->SetLastError( 2312, "Error in Milling : LeadIn must be out of rawpart") ; + return false ; + } + // eseguo affondo if ( AddRapidStart( ptP1) == GDB_ID_NULL) return false ; } @@ -1701,9 +1713,9 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool return false ; } } - // altrimenti, affondo in feed di testa + // altrimenti, affondo in feed opportuna else { - SetFeed( GetTipFeed()) ; + SetFeed( bOutStart ? GetStartFeed() : GetTipFeed()) ; if ( AddLinearMove( ptP1) == GDB_ID_NULL) return false ; } @@ -1711,7 +1723,7 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool // aggiungo attacco SetFeed( GetStartFeed()) ; if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, bInvert, bSplitArcs)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadIn not computable") ; + m_pMchMgr->SetLastError( 2309, "Error in Milling : LeadIn not computable") ; return false ; } } @@ -1745,7 +1757,7 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; SetFeed( GetStartFeed()) ; if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, bInvert, bSplitArcs, ptP1)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadOut not computable") ; + m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadOut not computable") ; return false ; } // se ultimo step aggiungo retrazione per frese normali @@ -1804,6 +1816,8 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, false, ptP1)) return false ; + // determino se l'inizio dell'attacco è fuori dal grezzo + bool bOutStart = GetPointOutOfRaw( ptP1, vtTool) ; // aggiungo approccio per frese normali if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) { // determino elevazione su inizio attacco @@ -1812,11 +1826,16 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool dStElev = dElev ; dStElev -= ( ptP1 - ptStart) * vtExtr ; // approccio al punto iniziale - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr, bOutStart)) return false ; } // altrimenti, approccio per lame else { + // verifico di entrare in aria + if ( ! bOutStart) { + m_pMchMgr->SetLastError( 2312, "Error in Milling : LeadIn must be out of rawpart") ; + return false ; + } // affondo al punto iniziale SetFlag( 0) ; if ( AddRapidStart( ptP1) == GDB_ID_NULL) @@ -1825,7 +1844,7 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool // aggiungo attacco SetFeed( GetStartFeed()) ; if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, false, bSplitArcs)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadIn not computable") ; + m_pMchMgr->SetLastError( 2309, "Error in Milling : LeadIn not computable") ; return false ; } } @@ -1859,7 +1878,7 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; SetFeed( GetStartFeed()) ; if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, false, bSplitArcs, ptP1)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadOut not computable") ; + m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadOut not computable") ; return false ; } // aggiungo retrazione per frese normali @@ -1928,6 +1947,8 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, false, ptP1)) return false ; + // determino se l'inizio dell'attacco è fuori dal grezzo + bool bOutStart = GetPointOutOfRaw( ptP1, vtTool) ; // aggiungo approccio per frese normali if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) { // determino elevazione su inizio attacco @@ -1936,11 +1957,17 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool dStElev = 0 ; dStElev -= ( ptP1 - ptStart) * vtExtr ; // approccio al punto iniziale - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr, bOutStart)) return false ; } // altrimenti, affondo al punto iniziale per lame else { + // verifico di entrare in aria + if ( ! bOutStart) { + m_pMchMgr->SetLastError( 2312, "Error in Milling : LeadIn must be out of rawpart") ; + return false ; + } + // eseguo affondamento SetFlag( 0) ; if ( AddRapidStart( ptP1) == GDB_ID_NULL) return false ; @@ -1948,7 +1975,7 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool // aggiungo attacco SetFeed( GetStartFeed()) ; if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, false, bSplitArcs)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadIn not computable") ; + m_pMchMgr->SetLastError( 2309, "Error in Milling : LeadIn not computable") ; return false ; } } @@ -1986,7 +2013,7 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; SetFeed( GetStartFeed()) ; if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, false, bSplitArcs, ptP1)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadOut not computable") ; + m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadOut not computable") ; return false ; } // aggiungo retrazione per frese normali @@ -2045,8 +2072,10 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dStElev)) dStElev = dElev ; dStElev -= ( ptP1 - ptStart) * vtExtr ; + // determino se l'inizio dell'attacco è fuori dal grezzo + bool bOutStart = GetPointOutOfRaw( ptP1, vtTool) ; // approccio al punto iniziale - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr, bOutStart)) return false ; } // altrimenti, affondo per lame @@ -2058,7 +2087,7 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool // aggiungo attacco SetFeed( GetStartFeed()) ; if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, bInvert, bSplitArcs)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadIn not computable") ; + m_pMchMgr->SetLastError( 2309, "Error in Milling : LeadIn not computable") ; return false ; } } @@ -2096,7 +2125,7 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptP1 ; SetFeed( GetStartFeed()) ; if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, bInvert, bSplitArcs, ptP1)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : LeadOut not computable") ; + m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadOut not computable") ; return false ; } // aggiungo retrazione per frese normali @@ -2118,7 +2147,7 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool //---------------------------------------------------------------------------- bool -Milling::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) +Milling::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutStart) { SetFlag( 1) ; // se con aggregato da sotto @@ -2164,6 +2193,7 @@ Milling::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, Point3d ptP1a = ptP1b + vtTool * ( dSafeZ - dAppr) ; if ( ( ! m_bAggrBottom && AddRapidStart( ptP1a) == GDB_ID_NULL) || ( m_bAggrBottom && AddRapidMove( ptP1a) == GDB_ID_NULL)) + return false ; // 1b -> punto appena sopra inizio if ( ( dElev + dAppr) > EPS_SMALL) { SetFlag( 0) ; @@ -2173,7 +2203,7 @@ Milling::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, } // affondo al punto iniziale SetFlag( 0) ; - SetFeed( GetTipFeed()) ; + SetFeed( bOutStart ? GetStartFeed() : GetTipFeed()) ; if ( AddLinearMove( ptP) == GDB_ID_NULL) return false ; } @@ -2514,5 +2544,17 @@ double Milling::GetRadiusForStartEndElevation( void) { const double DELTA_ELEV_RAD = 20.0 ; - return ( 0.5 * m_TParams.m_dTDiam + DELTA_ELEV_RAD) ; + double dDeltaRad = DELTA_ELEV_RAD + max( m_Params.m_dStartAddLen, m_Params.m_dEndAddLen) ; + return ( 0.5 * m_TParams.m_dTDiam + dDeltaRad) ; +} + +//---------------------------------------------------------------------------- +bool +Milling::GetPointOutOfRaw( const Point3d& ptP, const Vector3d& vtTool) +{ + // determino se l'inizio dell'attacco è fuori dal grezzo + double dTemp ; + if ( ! GetElevation( m_nPhase, ptP, vtTool, 0.5 * m_TParams.m_dDiam, dTemp)) + return false ; + return ( dTemp < 10 * EPS_SMALL) ; } diff --git a/Milling.h b/Milling.h index 7fe0b87..9544a3f 100644 --- a/Milling.h +++ b/Milling.h @@ -78,7 +78,7 @@ class Milling : public Machining double dDepth, double dElev, bool bSplitArcs) ; bool AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, double dDepth, double dElev, bool bSplitArcs) ; - bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ; + bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutStart) ; bool AddRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ; bool CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtN, bool bInvert, Point3d& ptP1) ; @@ -87,6 +87,7 @@ class Milling : public Machining bool AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d& vtN, bool bInvert, bool bSplitArcs, Point3d& ptP1) ; double GetRadiusForStartEndElevation( void) ; + bool GetPointOutOfRaw( const Point3d& ptP, const Vector3d& vtTool) ; private : double GetSpeed() const diff --git a/Operation.cpp b/Operation.cpp index ddce3d3..6831042 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -22,6 +22,7 @@ #include "/EgtDev/Include/EGkCurveLine.h" #include "/EgtDev/Include/EGkCurveArc.h" #include "/EgtDev/Include/EgkArcSpecial.h" +#include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EgkDistPointCurve.h" #include "/EgtDev/Include/EgkIntersCurves.h" #include "/EgtDev/Include/EGkIntersLineSurfTm.h" @@ -239,22 +240,16 @@ Operation::GetElevation( int nPhase, const Point3d& ptP, // considero il punto if ( ! GetElevation( nPhase, ptP, vtDir, dElev)) return false ; - // considero i 4 punti sulla circonferenza - Frame3d frLoc ; - frLoc.Set( ptP, vtDir) ; - double dElevT ; - if ( ! GetElevation( nPhase, ptP + frLoc.VersX() * dRad, vtDir, dElevT)) - return false ; - dElev = max( dElev, dElevT) ; - if ( ! GetElevation( nPhase, ptP - frLoc.VersX() * dRad, vtDir, dElevT)) - return false ; - dElev = max( dElev, dElevT) ; - if ( ! GetElevation( nPhase, ptP + frLoc.VersY() * dRad, vtDir, dElevT)) - return false ; - dElev = max( dElev, dElevT) ; - if ( ! GetElevation( nPhase, ptP - frLoc.VersY() * dRad, vtDir, dElevT)) - return false ; - dElev = max( dElev, dElevT) ; + // considero 8 punti sulla circonferenza + const int N_STEP = 8 ; + Vector3d vtRad = FromUprightOrtho( vtDir) * dRad ; + for ( int i = 0 ; i < N_STEP ; ++ i) { + double dElevT ; + vtRad.Rotate( vtDir, ANG_FULL / N_STEP) ; + if ( ! GetElevation( nPhase, ptP + vtRad, vtDir, dElevT)) + return false ; + dElev = max( dElev, dElevT) ; + } return true ; } @@ -326,7 +321,6 @@ Operation::GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3 return true ; } - //---------------------------------------------------------------------------- bool Operation::GetMinDistanceFromRawSide( int nPhase, const Point3d& ptP, double& dDist, Vector3d& vtDir) @@ -454,6 +448,85 @@ Operation::GetRawGlobBox( int nPhase, int nPathId, double dToler, BBox3d& b3Raw) return true ; } +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +bool +Operation::ApproxWithArcsIfUseful( ICurveComposite* pCompo) +{ + // costanti di approssimazione + const double LIN_TOL_MID = 0.05 ; + const double ANG_TOL_STD_DEG = 15 ; + const double LIN_FEA_STD = 20 ; + // recupero estrusione e spessore + Vector3d vtExtr = Z_AX ; + pCompo->GetExtrusion( vtExtr) ; + double dThick = 0 ; + pCompo->GetThickness( dThick) ; + // verifico se sono tante linee + double dLen = 0 ; + pCompo->GetLength( dLen) ; + int nCrvs = pCompo->GetCurveCount() ; + if ( nCrvs < 5 || dLen > nCrvs * LIN_FEA_STD) + return true ; + // calcolo approssimazione con archi + PolyArc PA ; + if ( ! pCompo->ApproxWithArcsEx( LIN_TOL_MID, ANG_TOL_STD_DEG, LIN_FEA_STD, PA)) + return false ; + // sostituisco gli archi alle curve originali + pCompo->Clear() ; + if ( ! pCompo->FromPolyArc( PA)) + return false ; + // riassegno estrusione e spessore + pCompo->SetExtrusion( vtExtr) ; + pCompo->SetThickness( dThick) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::ApproxWithLines( ICurveComposite* pCompo) +{ + // recupero estrusione e spessore + Vector3d vtExtr = Z_AX ; + pCompo->GetExtrusion( vtExtr) ; + double dThick = 0 ; + pCompo->GetThickness( dThick) ; + // calcolo approssimazione lineare + const double ANG_TOL_MAX_DEG = 90 ; + PolyLine PL ; + if ( ! pCompo->ApproxWithLines( 50 * EPS_SMALL, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) + return false ; + // sostituisco le linee alle curve originali + pCompo->Clear() ; + pCompo->FromPolyLine( PL) ; + // riassegno estrusione e spessore + pCompo->SetExtrusion( vtExtr) ; + pCompo->SetThickness( dThick) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::VerifyArcs( ICurveComposite* pCompo) +{ + // verifiche sull'ampiezza dell'angolo al centro degli eventuali archi + const double MAX_ANG_CEN = 150 + EPS_ANG_SMALL ; + int nMaxInd = pCompo->GetCurveCount() - 1 ; + for ( int i = 0 ; i <= nMaxInd ; ) { + // se arco con angolo al centro oltre il limite, lo divido a metà + const ICurveArc* pArc = GetCurveArc( pCompo->GetCurve( i)) ; + if ( pArc != nullptr && abs( pArc->GetAngCenter()) > MAX_ANG_CEN) { + pCompo->AddJoint( i + 0.5) ; + ++ nMaxInd ; + } + else + ++ i ; + } + return true ; +} + //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- bool diff --git a/Operation.h b/Operation.h index a10da9e..0cbc0e2 100644 --- a/Operation.h +++ b/Operation.h @@ -21,6 +21,8 @@ class MachMgr ; class CamData ; +class ICurve ; +class ICurveComposite ; //---------------------------------------------------------------------------- class Operation : public IUserObj @@ -66,6 +68,10 @@ class Operation : public IUserObj bool GetMinDistanceFromRawSide( int nPhase, const Point3d& ptP, double& dDist, Vector3d& vtDir) ; bool GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) ; bool GetRawGlobBox( int nPhase, int nPathId, double dToler, BBox3d& b3Raw) ; + + bool ApproxWithArcsIfUseful( ICurveComposite* pCompo) ; + bool ApproxWithLines( ICurveComposite* pCompo) ; + bool VerifyArcs( ICurveComposite* pCompo) ; bool GetInitialAxesValues( DBLVECTOR& vAxVal) ; bool GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal) ; @@ -109,6 +115,8 @@ class Operation : public IUserObj int AddLinearMove( const Point3d& ptP, const std::string& sName) ; int AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN) ; int AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN, const std::string& sName) ; + int AddCurveMove( const ICurve* pCrv) ; + int AddCurveMove( const ICurve* pCrv, const std::string& sName) ; bool ResetMoveData( void) ; protected : diff --git a/OperationCL.cpp b/OperationCL.cpp index 124c4d7..e619bc2 100644 --- a/OperationCL.cpp +++ b/OperationCL.cpp @@ -19,6 +19,7 @@ #include "/EgtDev/Include/EGkGeoPoint3d.h" #include "/EgtDev/Include/EGkCurveLine.h" #include "/EgtDev/Include/EGkCurveArc.h" +#include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EGkGeomDB.h" #include "/EgtDev/Include/EgtPointerOwner.h" @@ -300,6 +301,84 @@ Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, return nId ; } +//---------------------------------------------------------------------------- +int +Operation::AddCurveMove( const ICurve* pCrv) +{ + // verifico che la curva esista + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // se linea + if ( pCrv->GetType() == CRV_LINE) { + const ICurveLine* pLine = GetCurveLine( pCrv) ; + Point3d ptP3 = pLine->GetEnd() ; + return AddLinearMove( ptP3) ; + } + // se arco semplice + else if ( pCrv->GetType() == CRV_ARC && abs( GetCurveArc( pCrv)->GetAngCenter()) < MAX_ANG_CEN) { + const ICurveArc* pArc = GetCurveArc( pCrv) ; + Point3d ptCen = pArc->GetCenter() ; + double dAngCen = pArc->GetAngCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + Point3d ptP3 ; + pArc->GetEndPoint( ptP3) ; + return AddArcMove( ptP3, ptCen, dAngCen, vtN) ; + } + // altrimenti + else { + // in ogni caso, converto in archi e rette + PtrOwner pCompo( CreateCurveComposite()) ; + if ( ! pCompo->AddCurve( *pCrv)) + return GDB_ID_NULL ; + // verifico archi + VerifyArcs( pCompo) ; + // emetto curve componenti + int nFirstId = GDB_ID_NULL ; + const ICurve* pCrv = pCompo->GetFirstCurve() ; + while ( pCrv != nullptr) { + if ( pCrv->GetType() == CRV_LINE) { + const ICurveLine* pLine = GetCurveLine( pCrv) ; + Point3d ptP3 = pLine->GetEnd() ; + int nId = AddLinearMove( ptP3) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nId ; + } + else if ( pCrv->GetType() == CRV_ARC) { + const ICurveArc* pArc = GetCurveArc( pCrv) ; + Point3d ptCen = pArc->GetCenter() ; + double dAngCen = pArc->GetAngCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + Point3d ptP3 ; + pArc->GetEndPoint( ptP3) ; + int nId = AddArcMove( ptP3, ptCen, dAngCen, vtN) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nId ; + } + else + return GDB_ID_NULL ; + pCrv = pCompo->GetNextCurve() ; + } + return nFirstId ; + } +} + +//---------------------------------------------------------------------------- +int +Operation::AddCurveMove( const ICurve* pCrv, const string& sName) +{ + int nFirstId = AddCurveMove( pCrv) ; + int nId = nFirstId ; + while ( nId != GDB_ID_NULL) { + m_pGeomDB->SetName( nId, sName) ; + nId = m_pGeomDB->GetNext( nId) ; + } + return nFirstId ; +} + //---------------------------------------------------------------------------- bool Operation::ResetMoveData( void) diff --git a/Pocketing.cpp b/Pocketing.cpp index b528be9..d0c914b 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -28,26 +28,30 @@ #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGnStringKeyVal.h" #include "/EgtDev/Include/EgtPointerOwner.h" +#include "/EgtDev/Include/EgtNumUtils.h" using namespace std ; //------------------------------ Errors -------------------------------------- -// 2501 = "Error in Pocketing : UpdateToolData failed" -// 2502 = "Error in Pocketing : Open Contour" -// 2503 = "Error in Pocketing : Contour Not Flat" -// 2504 = "Error in Pocketing : Tool Dir not perpendicular to Flat Area" -// 2505 = "Error in Pocketing : Empty RawBox" -// 2506 = "Error in Pocketing : Depth not computable" -// 2507 = "Error in Pocketing : machining depth (xxx) bigger than MaxMaterial (yyy)" -// 2508 = "Error in Pocketing : Entity GetElevation" -// 2509 = "Error in Pocketing : missing aggregate from bottom" -// 2510 = "Error in Pocketing : path too far from part sides" -// 2511 = "Error in Pocketing : toolpath allocation failed" -// 2512 = "Error in Pocketing : Offset not computable" -// 2513 = "Error in Pocketing : Toolpath not computable" -// 2514 = "Error in Pocketing : LeadIn not computable" -// 2515 = "Error in Pocketing : LeadOut not computable" -// 2516 = "Error in Pocketing : Link not computable" +// 2401 = "Error in Pocketing : UpdateToolData failed" +// 2402 = "Error in Pocketing : Open Contour" +// 2403 = "Error in Pocketing : Contour Not Flat" +// 2404 = "Error in Pocketing : Tool Dir not perpendicular to Flat Area" +// 2405 = "Error in Pocketing : Empty RawBox" +// 2406 = "Error in Pocketing : Depth not computable" +// 2407 = "Error in Pocketing : machining depth (xxx) bigger than MaxMaterial (yyy)" +// 2408 = "Error in Pocketing : Entity GetElevation" +// 2409 = "Error in Pocketing : missing aggregate from bottom" +// 2410 = "Error in Pocketing : path too far from part sides" +// 2411 = "Error in Pocketing : toolpath allocation failed" +// 2412 = "Error in Pocketing : Offset not computable" +// 2413 = "Error in Pocketing : Toolpath not computable" +// 2414 = "Error in Pocketing : LeadIn not computable" +// 2415 = "Error in Pocketing : LeadOut not computable" +// 2416 = "Error in Pocketing : Link not computable" +// 2417 = "Error in Pocketing : Linear Approx not computable" +// 2418 = "Error in Pocketing : Return toolpath not computable" +// 2419 = "Error in Pocketing : Chaining failed" //---------------------------------------------------------------------------- USEROBJ_REGISTER( "EMkPocketing", Pocketing) ; @@ -311,6 +315,9 @@ Pocketing::SetParam( int nType, double dVal) case MPA_LITANG : m_Params.m_dLiTang = dVal ; return true ; + case MPA_LIELEV : + m_Params.m_dLiElev = dVal ; + return true ; case MPA_LOTANG : m_Params.m_dLoTang = dVal ; return true ; @@ -402,13 +409,15 @@ Pocketing::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - m_pMchMgr->SetLastError( 2501, "Error in Pocketing : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2401, "Error in Pocketing : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2419, "Error in Pocketing : Chaining failed") ; return false ; + } // recupero gruppo per geometria di Preview int nPvId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_PV) ; @@ -465,13 +474,15 @@ Pocketing::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - m_pMchMgr->SetLastError( 2501, "Error in Pocketing : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2401, "Error in Pocketing : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2419, "Error in Pocketing : Chaining failed") ; return false ; + } // recupero gruppo per geometria di lavorazione (Cutter Location) int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; @@ -593,6 +604,9 @@ Pocketing::GetParam( int nType, double& dVal) const case MPA_LITANG : dVal = m_Params.m_dLiTang ; return true ; + case MPA_LIELEV : + dVal = m_Params.m_dLiElev ; + return true ; case MPA_LOTANG : dVal = m_Params.m_dLoTang ; return true ; @@ -927,6 +941,9 @@ Pocketing::Chain( int nGrpDestId) pCrvCompo->SetThickness( dThick) ; // aggiorno il nuovo punto vicino pCrvCompo->GetEndPoint( ptNear) ; + // se utile, approssimo con archi + if ( ! ApproxWithArcsIfUseful( pCrvCompo)) + return false ; // creo nuovo gruppo int nPathId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpDestId, Frame3d()) ; if ( nPathId == GDB_ID_NULL) @@ -976,7 +993,7 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) return false ; ICurve* pCrv = ::GetCurve( m_pGeomDB->GetGeoObj( nCrvId)) ; if ( pCrv == nullptr || ! pCrv->IsClosed()) { - m_pMchMgr->SetLastError( 2502, "Error in Pocketing : Open Contour") ; + m_pMchMgr->SetLastError( 2402, "Error in Pocketing : Open Contour") ; return false ; } @@ -995,11 +1012,11 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) // verifico sia piana e sistemo senso antiorario visto dalla direzione di estrusione Plane3d plPlane ; double dArea ; if ( ! pCompo->GetArea( plPlane, dArea)) { - m_pMchMgr->SetLastError( 2503, "Error in Pocketing : Contour Not Flat") ; + m_pMchMgr->SetLastError( 2403, "Error in Pocketing : Contour Not Flat") ; return false ; } if ( abs( plPlane.vtN * vtExtr) < cos( 10 * EPS_ANG_SMALL)){ - m_pMchMgr->SetLastError( 2504, "Error in Pocketing : Tool Dir not perpendicular to Flat Area") ; + m_pMchMgr->SetLastError( 2404, "Error in Pocketing : Tool Dir not perpendicular to Flat Area") ; return false ; } if ( plPlane.vtN * vtExtr * dArea < 0) @@ -1016,7 +1033,7 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nPathId, 0.5 * m_TParams.m_dDiam, b3Raw) || b3Raw.IsEmpty()) { - m_pMchMgr->SetLastError( 2505, "Error in Pocketing : Empty RawBox") ; + m_pMchMgr->SetLastError( 2405, "Error in Pocketing : Empty RawBox") ; return false ; } @@ -1033,7 +1050,7 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) double dDepth ; string sMyDepth = m_Params.m_sDepth ; if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) { - m_pMchMgr->SetLastError( 2506, "Error in Pocketing : Depth not computable") ; + m_pMchMgr->SetLastError( 2406, "Error in Pocketing : Depth not computable") ; return false ; } // se spessore positivo, lo sottraggo dal risultato @@ -1046,37 +1063,6 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) string sPathName ; m_pGeomDB->GetName( nPathId, sPathName) ; - // eventuale approssimazione con segmenti di retta - int nSplitArcs = m_pMchMgr->GetCurrMachiningsMgr()->GetSplitArcs() ; - bool bSplitArcs = ( nSplitArcs == SPLAR_ALWAYS || - ( nSplitArcs == SPLAR_NO_XY_PLANE && ! vtExtr.IsZplus()) || - ( nSplitArcs == SPLAR_GEN_PLANE && vtExtr.IsGeneric())) ; - if ( bSplitArcs) { - const double ANG_TOL_MAX_DEG = 90 ; - PolyLine PL ; - if ( pCompo->ApproxWithLines( 50 * EPS_SMALL, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) { - // sostituisco le linee alle curve originali - pCompo->Clear() ; - pCompo->FromPolyLine( PL) ; - // riassegno estrusione e spessore - pCompo->SetExtrusion( vtExtr) ; - pCompo->SetThickness( dThick) ; - } - } - - // verifiche sull'ampiezza dell'angolo al centro degli eventuali archi - const double MAX_ANG_CEN = 150 + EPS_ANG_SMALL ; - int nMaxInd = pCompo->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // se arco con angolo al centro oltre il limite, lo divido a metà - const ICurveArc* pArc = GetCurveArc( pCompo->GetCurve( i)) ; - if ( pArc != nullptr && abs( pArc->GetAngCenter()) > MAX_ANG_CEN) { - pCompo->AddJoint( i + 0.5) ; - ++ i ; - ++ nMaxInd ; - } - } - // assegno il versore fresa Vector3d vtTool = vtExtr ; @@ -1105,7 +1091,7 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) else { string sInfo = "Error in Pocketing : machining depth (" + ToString( dElev, 1) + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; - m_pMchMgr->SetLastError( 2507, sInfo) ; + m_pMchMgr->SetLastError( 2407, sInfo) ; return false ; } } @@ -1138,6 +1124,15 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) m_pGeomDB->SetName( nPxId, sPathName) ; m_pGeomDB->SetMaterial( nPxId, BLUE) ; + // sposto l'inizio a metà del tratto più lungo + AdjustContourStart( pCompo) ; + + // verifico se archi vanno approssimati con segmenti di retta + int nSplitArcs = m_pMchMgr->GetCurrMachiningsMgr()->GetSplitArcs() ; + bool bSplitArcs = ( nSplitArcs == SPLAR_ALWAYS || + ( nSplitArcs == SPLAR_NO_XY_PLANE && ! vtExtr.IsZplus()) || + ( nSplitArcs == SPLAR_GEN_PLANE && vtExtr.IsGeneric())) ; + // assegno il vettore estrazione al gruppo del percorso m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ; // assegno il punto di inizio al gruppo del percorso @@ -1210,7 +1205,7 @@ Pocketing::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - m_pMchMgr->SetLastError( 2508, "Error in Pocketing : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; return false ; } // da una parte @@ -1220,7 +1215,7 @@ Pocketing::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - m_pMchMgr->SetLastError( 2508, "Error in Pocketing : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; return false ; } // dall'altra parte @@ -1230,7 +1225,7 @@ Pocketing::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - m_pMchMgr->SetLastError( 2508, "Error in Pocketing : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; return false ; } } @@ -1252,7 +1247,7 @@ Pocketing::VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& int nHeadId = m_pMchMgr->GetHeadId( m_TParams.m_sHead) ; int nAgbType ; if ( ! m_pGeomDB->GetInfo( nHeadId, "AGB_TYPE", nAgbType) || nAgbType == 0) { - m_pMchMgr->SetLastError( 2509, "Error in Pocketing : missing aggregate from bottom") ; + m_pMchMgr->SetLastError( 2409, "Error in Pocketing : missing aggregate from bottom") ; return false ; } // recupero la massima distanza consentita dal rinvio @@ -1292,7 +1287,7 @@ Pocketing::VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& } // se supera il limite, errore if ( dDist > dAgbDmax) { - m_pMchMgr->SetLastError( 2510, "Error in Pocketing : path too far from part sides") ; + m_pMchMgr->SetLastError( 2410, "Error in Pocketing : path too far from part sides") ; return false ; } // assegno direzione di accesso e segnalo utilizzo aggregato da sotto @@ -1385,10 +1380,10 @@ Pocketing::AddSpiralIn( const ICurveComposite* pCompo, const Vector3d& vtTool, c PtrOwner pMCrv( CreateCurveComposite()) ; PtrOwner pRCrv( CreateCurveComposite()) ; if ( IsNull( pMCrv) || IsNull( pRCrv)) { - m_pMchMgr->SetLastError( 2511, "Error in Pocketing : toolpath allocation failed") ; + m_pMchMgr->SetLastError( 2411, "Error in Pocketing : toolpath allocation failed") ; return false ; } - if ( ! CalcSpiral( pCompo, Get( pMCrv), Get( pRCrv))) + if ( ! CalcSpiral( pCompo, bSplitArcs, Get( pMCrv), Get( pRCrv))) return false ; // determino numero e affondamento degli step @@ -1419,33 +1414,38 @@ Pocketing::AddSpiralIn( const ICurveComposite* pCompo, const Vector3d& vtTool, c pCurve->GetStartPoint( ptStart) ; Vector3d vtStart ; pCurve->GetStartDir( vtStart) ; - // determino inizio attacco - Point3d ptP1 ; - if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, ptP1)) - return false ; // se primo step, approccio e affondo if ( j == 1) { + // determino inizio attacco + Point3d ptP1 ; + if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, ptP1)) + return false ; // determino elevazione su inizio attacco double dStElev ; if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dStElev)) dStElev = dElev ; dStElev -= ( ptP1 - ptStart) * vtExtr ; + // se attacco a zigzag o a spirale, l'elevazione va nell'attacco + if ( GetLeadInType() == POCKET_LI_ZIGZAG || GetLeadInType() == POCKET_LI_HELIX) { + ptP1 += vtExtr * dStElev ; + dStElev = 0 ; + } // approccio al punto iniziale if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) return false ; // aggiungo attacco SetFeed( GetStartFeed()) ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, bSplitArcs)) { - m_pMchMgr->SetLastError( 2514, "Error in Pocketing : LeadIn not computable") ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, ! m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2414, "Error in Pocketing : LeadIn not computable") ; return false ; } } // altrimenti solo collegamento else { - // per ora solo collegamento diretto !!! da estendere !!! SetFeed( GetStartFeed()) ; - if ( AddLinearMove( ptP1) == GDB_ID_NULL) { - m_pMchMgr->SetLastError( 2516, "Error in Pocketing : Link not computable") ; + Point3d ptP1 = ptStart + vtExtr * dStep ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, ! m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2416, "Error in Pocketing : Link not computable") ; return false ; } } @@ -1473,36 +1473,16 @@ Pocketing::AddSpiralIn( const ICurveComposite* pCompo, const Vector3d& vtTool, c if ( i == nMaxInd) { // se step intermedio, ritorno all'inizio direttamente if ( j < nStep) { - // ciclo sulle curve elementari del percorso di ritorno - for ( int k = 0 ; k <= nMaxRInd ; ++ k) { - // curva corrente - const ICurve* pCrvR = pRCrv->GetCurve( k) ; - // copio la curva - PtrOwner pRet( ::GetCurve( pCrvR->Clone())) ; - if ( IsNull( pRet)) - return false ; - // aggiungo affondamento - pRet->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; - // elaborazioni sulla curva corrente - if ( pRet->GetType() == CRV_LINE) { - ICurveLine* pLine = GetCurveLine( pRet) ; - Point3d ptP3 = pLine->GetEnd() ; - SetFeed( GetFeed()) ; - if ( AddLinearMove( ptP3) == GDB_ID_NULL) - return false ; - } - else if ( pRet->GetType() == CRV_ARC) { - ICurveArc* pArc = GetCurveArc( pRet) ; - Point3d ptCen = pArc->GetCenter() ; - double dAngCen = pArc->GetAngCenter() ; - Vector3d vtN = pArc->GetNormVersor() ; - Point3d ptP3 ; - pArc->GetEndPoint( ptP3) ; - SetFeed( GetFeed()) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; - } - } + // copio la curva di ritorno + PtrOwner pRet( ::GetCurve( pRCrv->Clone())) ; + if ( IsNull( pRet)) + return false ; + // aggiungo affondamento + pRet->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; + // emetto + SetFeed( GetFeed()) ; + if ( AddCurveMove( pRet) == GDB_ID_NULL) + return false ; } // atrimenti ultimo step, uscita e retrazione else { @@ -1513,16 +1493,12 @@ Pocketing::AddSpiralIn( const ICurveComposite* pCompo, const Vector3d& vtTool, c pCurve->GetEndDir( vtEnd) ; // aggiungo uscita Point3d ptP1 ; + double dEndElev = dElev ; SetFeed( GetStartFeed()) ; - if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, ptP1)) { - m_pMchMgr->SetLastError( 2515, "Error in Pocketing : LeadOut not computable") ; + if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, pRCrv, bSplitArcs, ptP1, dEndElev)) { + m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadOut not computable") ; return false ; } - // determino elevazione su fine uscita - double dEndElev ; - if ( ! GetElevation( m_nPhase, ptEnd - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dEndElev)) - dEndElev = dElev ; - dEndElev -= ( ptP1 - ptEnd) * vtExtr ; // aggiungo retrazione if ( ! AddRetract( ptP1, vtTool, dSafeZ, dEndElev, dAppr)) return false ; @@ -1547,10 +1523,10 @@ Pocketing::AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool, PtrOwner pMCrv( CreateCurveComposite()) ; PtrOwner pRCrv( CreateCurveComposite()) ; if ( IsNull( pMCrv) || IsNull( pRCrv)) { - m_pMchMgr->SetLastError( 2511, "Error in Pocketing : toolpath allocation failed") ; + m_pMchMgr->SetLastError( 2411, "Error in Pocketing : toolpath allocation failed") ; return false ; } - if ( ! CalcSpiral( pCompo, Get( pMCrv), Get( pRCrv))) + if ( ! CalcSpiral( pCompo, bSplitArcs, Get( pMCrv), Get( pRCrv))) return false ; pMCrv->Invert() ; pRCrv->Invert() ; @@ -1583,33 +1559,40 @@ Pocketing::AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool, pCurve->GetStartPoint( ptStart) ; Vector3d vtStart ; pCurve->GetStartDir( vtStart) ; - // determino inizio attacco - Point3d ptP1 ; - if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, ptP1)) - return false ; // se primo step, approccio e affondo if ( j == 1) { + // determino inizio attacco + Point3d ptP1 ; + if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, ptP1)) { + m_pMchMgr->SetLastError( 2414, "Error in Pocketing : LeadIn not computable") ; + return false ; + } // determino elevazione su inizio attacco double dStElev ; if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dStElev)) dStElev = dElev ; dStElev -= ( ptP1 - ptStart) * vtExtr ; + // se attacco a zigzag o a spirale, l'elevazione va nell'attacco + if ( GetLeadInType() == POCKET_LI_ZIGZAG || GetLeadInType() == POCKET_LI_HELIX) { + ptP1 += vtExtr * dStElev ; + dStElev = 0 ; + } // approccio al punto iniziale if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr)) return false ; // aggiungo attacco SetFeed( GetStartFeed()) ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, bSplitArcs)) { - m_pMchMgr->SetLastError( 2514, "Error in Pocketing : LeadIn not computable") ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2414, "Error in Pocketing : LeadIn not computable") ; return false ; } } // altrimenti solo collegamento else { - // per ora solo collegamento diretto !!! da estendere !!! SetFeed( GetStartFeed()) ; - if ( AddLinearMove( ptP1) == GDB_ID_NULL) { - m_pMchMgr->SetLastError( 2516, "Error in Pocketing : Link not computable") ; + Point3d ptP1 = ptStart + vtExtr * dStep ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2416, "Error in Pocketing : Link not computable") ; return false ; } } @@ -1637,36 +1620,16 @@ Pocketing::AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool, if ( i == nMaxInd) { // se step intermedio, ritorno all'inizio direttamente if ( j < nStep) { - // ciclo sulle curve elementari del percorso di ritorno - for ( int k = 0 ; k <= nMaxRInd ; ++ k) { - // curva corrente - const ICurve* pCrvR = pRCrv->GetCurve( k) ; - // copio la curva - PtrOwner pRet( ::GetCurve( pCrvR->Clone())) ; - if ( IsNull( pRet)) - return false ; - // aggiungo affondamento - pRet->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; - // elaborazioni sulla curva corrente - if ( pRet->GetType() == CRV_LINE) { - ICurveLine* pLine = GetCurveLine( pRet) ; - Point3d ptP3 = pLine->GetEnd() ; - SetFeed( GetFeed()) ; - if ( AddLinearMove( ptP3) == GDB_ID_NULL) - return false ; - } - else if ( pRet->GetType() == CRV_ARC) { - ICurveArc* pArc = GetCurveArc( pRet) ; - Point3d ptCen = pArc->GetCenter() ; - double dAngCen = pArc->GetAngCenter() ; - Vector3d vtN = pArc->GetNormVersor() ; - Point3d ptP3 ; - pArc->GetEndPoint( ptP3) ; - SetFeed( GetFeed()) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; - } - } + // copio la curva di ritorno + PtrOwner pRet( ::GetCurve( pRCrv->Clone())) ; + if ( IsNull( pRet)) + return false ; + // aggiungo affondamento + pRet->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; + // emetto + SetFeed( GetFeed()) ; + if ( AddCurveMove( pRet) == GDB_ID_NULL) + return false ; } // atrimenti ultimo step, uscita e retrazione else { @@ -1677,16 +1640,12 @@ Pocketing::AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool, pCurve->GetEndDir( vtEnd) ; // aggiungo uscita Point3d ptP1 ; + double dEndElev = dElev ; SetFeed( GetStartFeed()) ; - if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, ptP1)) { - m_pMchMgr->SetLastError( 2515, "Error in Pocketing : LeadOut not computable") ; + if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, pRCrv, bSplitArcs, ptP1, dEndElev)) { + m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadOut not computable") ; return false ; } - // determino elevazione su fine uscita - double dEndElev ; - if ( ! GetElevation( m_nPhase, ptEnd - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dEndElev)) - dEndElev = dElev ; - dEndElev -= ( ptP1 - ptEnd) * vtExtr ; // aggiungo retrazione if ( ! AddRetract( ptP1, vtTool, dSafeZ, dEndElev, dAppr)) return false ; @@ -1699,11 +1658,21 @@ Pocketing::AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool, //---------------------------------------------------------------------------- bool -Pocketing::CalcSpiral( const ICurveComposite* pCompo, ICurveComposite* pMCrv, ICurveComposite* pRCrv) +Pocketing::CalcSpiral( const ICurveComposite* pCompo, bool bSplitArcs, + ICurveComposite* pMCrv, ICurveComposite* pRCrv) { // primo offset pari al raggio utensile + sovramateriale double dOffs = 0.5 * m_TParams.m_dDiam + GetOffsR() ; + // se circonferenza, chiamo la funzione specializzata + Point3d ptCen ; Vector3d vtN ; double dRad ; bool bCCW ; + if ( pCompo->IsACircle( 10 * EPS_SMALL, ptCen, vtN, dRad, bCCW)) { + double dIntRad = 0 ; + if ( GetLeadInType() == POCKET_LI_HELIX || GetLeadInType() == POCKET_LI_ZIGZAG) + dIntRad = 0.5 * min( m_Params.m_dLiTang, m_TParams.m_dDiam) ; + return CalcCircleSpiral( ptCen, vtN, dRad - dOffs, dIntRad, bSplitArcs, pMCrv, pRCrv) ; + } + // ciclo di offset verso l'interno const int MAX_ITER = 100 ; int nIter = 0 ; @@ -1714,7 +1683,7 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, ICurveComposite* pMCrv, IC // calcolo OffsetCurve OffsCrv ; if ( ! OffsCrv.Make( pCurr, - dOffs, ICurve::OFF_FILLET)) { - m_pMchMgr->SetLastError( 2512, "Error in Pocketing : Offset not computable") ; + m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; return false ; } // accodo la curva offsettata al percorso di lavoro @@ -1743,16 +1712,23 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, ICurveComposite* pMCrv, IC dCurrRad = dRad ; pCurr = Get( pOffs) ; // nuovo valore pari allo step - dOffs = max( m_Params.m_dSideStep, min( 0.1 * m_TParams.m_dDiam, 1.)) ; + dOffs = GetSideStep() ; // incremento contatore iterazioni ++ nIter ; } // verifico il percorso di lavoro if ( pMCrv->GetCurveCount() == 0) { - m_pMchMgr->SetLastError( 2513, "Error in Pocketing : Toolpath not computable") ; + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; return false ; } + // se necessario, approssimo archi con rette + if ( bSplitArcs && ! ApproxWithLines( pMCrv)) { + m_pMchMgr->SetLastError( 2417, "Error in Pocketing : Linear Approx not computable") ; + return false ; + } + // eventuale sistemazione archi + VerifyArcs( pMCrv) ; // compatto e inverto il percorso di ritorno pRCrv->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, false) ; pRCrv->Invert() ; @@ -1760,6 +1736,75 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, ICurveComposite* pMCrv, IC return true ; } +//---------------------------------------------------------------------------- +bool +Pocketing::CalcCircleSpiral( const Point3d& ptCen, const Vector3d& vtN, double dOutRad, double dIntRad, + bool bSplitArcs, ICurveComposite* pMCrv, ICurveComposite* pRCrv) +{ + // raggio della circonferenza esterna + if ( dOutRad < 10 * EPS_SMALL) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } + + // creo e inserisco la circonferenza esterna + PtrOwner pArc( CreateCurveArc()) ; + if ( IsNull( pArc) || ! pArc->Set( ptCen, vtN, dOutRad)) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } + Vector3d vtDir = pArc->GetStartVersor() ; + pMCrv->AddCurve( Release( pArc)) ; + // se richiesta percorrenza invertita + if ( m_Params.m_bInvert) + pMCrv->Invert() ; + + // aggiungo le semicirconferenze della spirale ( devono essere in numero dispari) + int nStep = int( ceil( ( dOutRad - dIntRad) / ( 0.5 * GetSideStep()))) ; + if ( IsEven( nStep)) + nStep += 1 ; + double dStep = ( dOutRad - dIntRad) / nStep ; + for ( int i = 1 ; i <= nStep ; ++ i) { + if ( ! IsEven( i)) + pMCrv->AddArcTg( ptCen - vtDir * ( dOutRad - i * dStep)) ; + else + pMCrv->AddArcTg( ptCen + vtDir * ( dOutRad - i * dStep)) ; + } + + // aggiungo la circonferenza interna + pMCrv->AddArcTg( ptCen + vtDir * dIntRad) ; + pMCrv->AddArcTg( ptCen - vtDir * dIntRad) ; + + // verifico il percorso di lavoro + if ( pMCrv->GetCurveCount() == 0) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } + // se necessario, approssimo con rette + if ( bSplitArcs && ! ApproxWithLines( pMCrv)) { + m_pMchMgr->SetLastError( 2417, "Error in Pocketing : Linear Approx not computable") ; + return false ; + } + // eventuale sistemazione archi + VerifyArcs( pMCrv) ; + + // calcolo il percorso di ritorno + Point3d ptStart ; pMCrv->GetStartPoint( ptStart) ; + Point3d ptEnd ; pMCrv->GetEndPoint( ptEnd) ; + Vector3d vtStart ; pMCrv->GetStartDir( vtStart) ; + PtrOwner pArc2( CreateCurveArc()) ; + if ( IsNull( pArc2) || ! pArc2->Set2PVN( ptStart, ptEnd, - vtStart, vtN)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Return toolpath not computable") ; + return false ; + } + pRCrv->AddCurve( Release( pArc2)) ; + // inverto e eventualmente sistemo archi + pRCrv->Invert() ; + VerifyArcs( pRCrv) ; + + return true ; +} + //---------------------------------------------------------------------------- bool Pocketing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) @@ -1808,6 +1853,7 @@ Pocketing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafe Point3d ptP1a = ptP1b + vtTool * ( dSafeZ - dAppr) ; if ( ( ! m_bAggrBottom && AddRapidStart( ptP1a) == GDB_ID_NULL) || ( m_bAggrBottom && AddRapidMove( ptP1a) == GDB_ID_NULL)) + return false ; // 1b -> punto appena sopra inizio if ( ( dElev + dAppr) > EPS_SMALL) { SetFlag( 0) ; @@ -1891,7 +1937,7 @@ Pocketing::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, con Point3d& ptP1) { // Assegno tipo e parametri - int nType = m_Params.m_nLeadInType ; + int nType = GetLeadInType() ; double dLen= m_Params.m_dLiTang ; // senso di rotazione da dir tg a dir esterna bool bCcwRot = true ; @@ -1901,14 +1947,11 @@ Pocketing::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, con ptP1 = ptStart ; return true ; case POCKET_LI_GLIDE : - return false ; case POCKET_LI_ZIGZAG : - // !!! DA FARE !!! - return false ; case POCKET_LI_HELIX : - // !!! DA FARE !!! - return false ; + ptP1 = ptStart ; + return true ; default : return false ; } @@ -1917,18 +1960,10 @@ Pocketing::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, con //---------------------------------------------------------------------------- bool Pocketing::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& vtStart, - const Vector3d& vtN, bool bSplitArcs) + const Vector3d& vtN, bool bAtLeft, bool bSplitArcs) { // Assegno il tipo - int nType = m_Params.m_nLeadInType ; - // se archi da spezzare - if ( bSplitArcs) { - if ( nType == POCKET_LI_HELIX) - nType = POCKET_LI_ZIGZAG ; - } - // se parametro tg nullo, allora nessun attacco - if ( (( ptStart - ptP1) ^ vtN).IsSmall()) - nType = POCKET_LI_NONE ; + int nType = GetLeadInType() ; // Eseguo a seconda del tipo switch ( nType) { case POCKET_LI_NONE : @@ -1937,11 +1972,48 @@ Pocketing::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3 // !!! DA FARE !!! return false ; case POCKET_LI_ZIGZAG : - // !!! DA FARE !!! - return false ; + { + double dDeltaN = ( ptStart - ptP1) * vtN ; + int nStep = int( ceil( - dDeltaN / ( m_Params.m_dLiElev + 10 * EPS_SMALL))) ; + double dStep = - dDeltaN / nStep ; + Point3d ptPa = ptP1 + vtStart * 0.5 * min( m_Params.m_dLiTang, m_TParams.m_dDiam) ; + Point3d ptPb = ptP1 - vtStart * 0.5 * min( m_Params.m_dLiTang, m_TParams.m_dDiam) ; + for ( int i = 1 ; i <= nStep ; ++ i) { + if ( AddLinearMove( ptPa - vtN * ( i - 0.75) * dStep, MCH_CL_LEADIN) == GDB_ID_NULL) + return false ; + if ( AddLinearMove( ptPb - vtN * ( i - 0.25) * dStep, MCH_CL_LEADIN) == GDB_ID_NULL) + return false ; + } + if ( AddLinearMove( ptStart, MCH_CL_LEADIN) == GDB_ID_NULL) + return false ; + return true ; + } case POCKET_LI_HELIX : - // !!! DA FARE !!! - return false ; + { + // vettore dal punto al centro elica + Vector3d vtCen = vtStart ; + vtCen.Rotate( vtN, ( bAtLeft ? ANG_RIGHT : - ANG_RIGHT)) ; + // dati dell'elica + double dRad = 0.5 * min( m_Params.m_dLiTang, m_TParams.m_dDiam) ; + Point3d ptCen = ptP1 + vtCen * dRad ; + double dDeltaN = ( ptStart - ptP1) * vtN ; + double dAngCen = ceil( - dDeltaN / ( m_Params.m_dLiElev + 10 * EPS_SMALL)) * ( bAtLeft ? ANG_FULL : - ANG_FULL) ; + // creo l'elica + PtrOwner pArc( CreateCurveArc()) ; + if ( IsNull( pArc) || ! pArc->Set( ptCen, vtN, dRad, - vtCen, dAngCen, dDeltaN)) + return false ; + // eventuale spezzatura + if ( bSplitArcs) { + PtrOwner pCompo( CreateCurveComposite()) ; + if ( IsNull( pCompo) || ! pCompo->AddCurve( Release( pArc)) || ! ApproxWithLines( pCompo)) + return false ; + return ( AddCurveMove( pCompo, MCH_CL_LEADIN) != GDB_ID_NULL) ; + } + else { + // emetto l'elica + return ( AddCurveMove( pArc, MCH_CL_LEADIN) != GDB_ID_NULL) ; + } + } default : return false ; } @@ -1950,29 +2022,57 @@ Pocketing::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3 //---------------------------------------------------------------------------- bool Pocketing::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d& vtN, - Point3d& ptP1) + const ICurveComposite* pRCrv, bool bSplitArcs, Point3d& ptP1, double& dElev) { // assegno i parametri - int nType = m_Params.m_nLeadOutType ; + int nType = GetLeadOutType() ; double dTang = m_Params.m_dLoTang ; - double dPerp = 0 ; - double dElev = 0 ; - // se parametrt tg nullo, allora nessuna uscita - if ( abs( dTang) < EPS_SMALL) - nType = POCKET_LO_NONE ; - // senso di rotazione da dir tg a dir esterna - bool bCcwRot = true ; // eseguo a seconda del tipo switch ( nType) { case POCKET_LO_NONE : + // nessuna uscita ptP1 = ptEnd ; + // determino elevazione su fine uscita + double dEndElev ; + if ( GetElevation( m_nPhase, ptEnd - 10 * EPS_SMALL * vtN, vtN, GetRadiusForStartEndElevation(), dEndElev)) + dElev = dEndElev ; return true ; case POCKET_LO_GLIDE : - // !!! DA FARE !!! - return false ; + { + // recupero la parte richiesta della curva di ritorno + PtrOwner pCrv ; + double dU ; + if ( pRCrv->GetParamAtLength( dTang, dU)) { + if ( ! pCrv.Set( CreateCurveComposite()) || ! pCrv->AddCurve( pRCrv->CopyParamRange( 0, dU))) + return false ; + } + else { + if ( ! pCrv.Set( GetCurveComposite( pRCrv->Clone()))) + return false ; + } + // la porto alla giusta quota + Point3d ptIni ; pCrv->GetStartPoint( ptIni) ; + Vector3d vtMove = ptEnd - ptIni ; + pCrv->Translate( vtMove) ; + Point3d ptFin ; pCrv->GetEndPoint( ptFin) ; + ptFin += vtN * 1.0 ; + pCrv->ModifyEnd( ptFin) ; + // eventuale spezzatura + if ( bSplitArcs && ! ApproxWithLines( pCrv)) + return false ; + // emetto + AddCurveMove( pCrv) ; + // determino elevazione su fine uscita + ptP1 = ptFin ; + double dEndElev ; + if ( GetElevation( m_nPhase, ptP1 - 10 * EPS_SMALL * vtN, vtN, GetRadiusForStartEndElevation(), dEndElev)) + dElev = dEndElev ; + return true ; + } default : return false ; } + } //---------------------------------------------------------------------------- @@ -1982,3 +2082,29 @@ Pocketing::GetRadiusForStartEndElevation( void) const double DELTA_ELEV_RAD = 20.0 ; return ( 0.5 * m_TParams.m_dTDiam + DELTA_ELEV_RAD) ; } + +//---------------------------------------------------------------------------- +bool +Pocketing::AdjustContourStart( ICurveComposite* pCompo) +{ + // cerco il tratto più lungo + int i = 0 ; + int nMax = - 1 ; + double dLenMax = 0 ; + const ICurve* pCrv = pCompo->GetFirstCurve() ; + while ( pCrv != nullptr) { + double dLen ; + if ( pCrv->GetLength( dLen) && dLen > dLenMax) { + dLenMax = dLen ; + nMax = i ; + } + ++ i ; + pCrv = pCompo->GetNextCurve() ; + } + + // sposto inizio + if ( nMax >= 0) + pCompo->ChangeStartPoint( nMax + 0.5) ; + + return true ; +} diff --git a/Pocketing.h b/Pocketing.h index 3241644..faea029 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -16,6 +16,7 @@ #include "Machining.h" #include "PocketingData.h" #include "ToolData.h" +#include "/EgtDev/Include/EgtNumUtils.h" class ICurve ; class ICurveComposite ; @@ -74,31 +75,47 @@ class Pocketing : public Machining double dDepth, double dElev, bool bSplitArcs) ; bool AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, double dDepth, double dElev, bool bSplitArcs) ; - bool CalcSpiral( const ICurveComposite* pCompo, ICurveComposite* pMCrv, ICurveComposite* pRCrv) ; + bool CalcSpiral( const ICurveComposite* pCompo, bool bSplitArcs, + ICurveComposite* pMCrv, ICurveComposite* pRCrv) ; + bool CalcCircleSpiral( const Point3d& ptCen, const Vector3d& vtN, double dOutRad, double dIntRad, + bool bSplitArcs, ICurveComposite* pMCrv, ICurveComposite* pRCrv) ; bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ; bool AddRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ; bool CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtN, Point3d& ptP1) ; bool AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& vtStart, - const Vector3d& vtN, bool bSplitArcs) ; + const Vector3d& vtN, bool bAtLeft, bool bSplitArcs) ; bool AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d& vtN, - Point3d& ptP1) ; + const ICurveComposite* pRCrv, bool bSplitArcs, Point3d& ptP1, double& dElev) ; double GetRadiusForStartEndElevation( void) ; + bool AdjustContourStart( ICurveComposite* pCompo) ; private : - double GetSpeed() const + double GetSpeed( void) const { return ( abs( m_Params.m_dSpeed) < EPS_MACH_ANG_PAR ? m_TParams.m_dSpeed : m_Params.m_dSpeed) ; } - double GetFeed() const + double GetFeed( void) const { return ( abs( m_Params.m_dFeed) < EPS_MACH_LEN_PAR ? m_TParams.m_dFeed : m_Params.m_dFeed) ; } - double GetStartFeed() const + double GetStartFeed( void) const { return ( abs( m_Params.m_dStartFeed) < EPS_MACH_LEN_PAR ? m_TParams.m_dStartFeed : m_Params.m_dStartFeed) ; } - double GetEndFeed() const + double GetEndFeed( void) const { return ( abs( m_Params.m_dEndFeed) < EPS_MACH_LEN_PAR ? m_TParams.m_dEndFeed : m_Params.m_dEndFeed) ; } - double GetTipFeed() const + double GetTipFeed( void) const { return ( abs( m_Params.m_dTipFeed) < EPS_MACH_LEN_PAR ? m_TParams.m_dTipFeed : m_Params.m_dTipFeed) ; } - double GetOffsL() const + double GetOffsL( void) const { return ( abs( m_Params.m_dOffsL - UNKNOWN_PAR) < EPS_MACH_LEN_PAR ? m_TParams.m_dOffsL : m_Params.m_dOffsL) ; } - double GetOffsR() const + double GetOffsR( void) const { return ( abs( m_Params.m_dOffsR - UNKNOWN_PAR) < EPS_MACH_LEN_PAR ? m_TParams.m_dOffsR : m_Params.m_dOffsR) ; } + double GetSideStep( void) const + { return Clamp( m_Params.m_dSideStep, min( 0.1 * m_TParams.m_dDiam, 1.0), m_TParams.m_dDiam) ; } + int GetLeadInType( void) const + { if ( m_Params.m_dLiTang < min( 0.1 * m_TParams.m_dDiam, 1.0)) + return POCKET_LI_NONE ; + if ( m_Params.m_nLeadInType != POCKET_LI_GLIDE && m_Params.m_dLiElev < 10 * EPS_SMALL) + return POCKET_LI_NONE ; + return m_Params.m_nLeadInType ; } + int GetLeadOutType( void) const + { if ( m_Params.m_dLoTang < min( 0.1 * m_TParams.m_dDiam, 1.0)) + return POCKET_LO_NONE ; + return m_Params.m_nLeadOutType ; } private : SELVECTOR m_vId ; // identificativi entità geometriche da lavorare diff --git a/PocketingData.cpp b/PocketingData.cpp index 4382239..8b95934 100644 --- a/PocketingData.cpp +++ b/PocketingData.cpp @@ -32,6 +32,7 @@ enum nPocketingKey { KEY_FS, KEY_FT, KEY_INV, + KEY_LIEL, KEY_LITG, KEY_LITY, KEY_LOTG, @@ -60,6 +61,7 @@ static const std::array sPocketingKey = { "FS", "FT", "INV", + "LIEL", "LITG", "LITY", "LOTG", @@ -132,6 +134,7 @@ PocketingData::CopyFrom( const MachiningData* pMdata) m_dSideAngle = pSdata->m_dSideAngle ; m_nLeadInType = pSdata->m_nLeadInType ; m_dLiTang = pSdata->m_dLiTang ; + m_dLiElev = pSdata->m_dLiElev ; m_nLeadOutType = pSdata->m_nLeadOutType ; m_dLoTang = pSdata->m_dLoTang ; m_sSysNotes = pSdata->m_sSysNotes ; @@ -172,6 +175,7 @@ PocketingData::SameAs(const MachiningData* pMdata) const abs( m_dSideAngle - pSdata->m_dSideAngle) < EPS_MACH_ANG_PAR && m_nLeadInType == pSdata->m_nLeadInType && abs( m_dLiTang - pSdata->m_dLiTang) < EPS_MACH_LEN_PAR && + abs( m_dLiElev - pSdata->m_dLiElev) < EPS_MACH_LEN_PAR && m_nLeadOutType == pSdata->m_nLeadOutType && abs( m_dLoTang - pSdata->m_dLoTang) < EPS_MACH_LEN_PAR && m_sSysNotes == pSdata->m_sSysNotes && @@ -234,6 +238,9 @@ PocketingData::FromString( const string& sString, int& nKey) case KEY_INV : bOk = ::FromString( sVal, m_bInvert) ; break ; + case KEY_LIEL : + bOk = ::FromString( sVal, m_dLiElev) ; + break ; case KEY_LITG : bOk = ::FromString( sVal, m_dLiTang) ; break ; @@ -310,6 +317,7 @@ PocketingData::ToString( int nInd) const case KEY_FS : return ( sPocketingKey[KEY_FS] + "=" + ::ToString( m_dStartFeed)) ; case KEY_FT : return ( sPocketingKey[KEY_FT] + "=" + ::ToString( m_dTipFeed)) ; case KEY_INV : return ( sPocketingKey[KEY_INV] + "=" + ::ToString( m_bInvert)) ; + case KEY_LIEL : return ( sPocketingKey[KEY_LIEL] + "=" + ::ToString( m_dLiElev)) ; case KEY_LITG : return ( sPocketingKey[KEY_LITG] + "=" + ::ToString( m_dLiTang)) ; case KEY_LITY : return ( sPocketingKey[KEY_LITY] + "=" + ::ToString( m_nLeadInType)) ; case KEY_LOTG : return ( sPocketingKey[KEY_LOTG] + "=" + ::ToString( m_dLoTang)) ; @@ -337,7 +345,7 @@ PocketingData::ToString( int nInd) const bool PocketingData::IsOptional( int nKey) const { - return false ; + return ( nKey == KEY_LIEL) ; } //---------------------------------------------------------------------------- @@ -367,7 +375,7 @@ PocketingData::VerifyLeadInType( int nVal) const bool PocketingData::VerifyLeadOutType( int nVal) const { - return ( nVal == POCKET_LO_NONE || nVal == MILL_LO_GLIDE) ; + return ( nVal == POCKET_LO_NONE || nVal == POCKET_LO_GLIDE) ; } //---------------------------------------------------------------------------- @@ -479,6 +487,9 @@ PocketingData::SetParam( int nType, double dVal) case MPA_LITANG : m_dLiTang = dVal ; return true ; + case MPA_LIELEV : + m_dLiElev = dVal ; + return true ; case MPA_LOTANG : m_dLoTang = dVal ; return true ; @@ -602,6 +613,9 @@ PocketingData::GetParam( int nType, double& dVal) const case MPA_LITANG : dVal = m_dLiTang ; return true ; + case MPA_LIELEV : + dVal = m_dLiElev ; + return true ; case MPA_LOTANG : dVal = m_dLoTang ; return true ; diff --git a/PocketingData.h b/PocketingData.h index aae7f25..3d2380e 100644 --- a/PocketingData.h +++ b/PocketingData.h @@ -37,6 +37,7 @@ struct PocketingData : public MachiningData double m_dSideAngle ; // angolo dello ZigZag da X+ locale int m_nLeadInType ; // tipo di attacco (nessuno, lineare, tangente, inseguimento) double m_dLiTang ; // distanza tangente da inizio attacco + double m_dLiElev ; // elevazione di uno step di attacco int m_nLeadOutType ; // tipo di uscita (come attacco, nessuno, lineare, tangente, inseguimento) double m_dLoTang ; // distanza tangente verso fine uscita std::string m_sSysNotes ; // note interne @@ -46,7 +47,7 @@ struct PocketingData : public MachiningData : m_ToolUuid(), m_nSolCh( 0), m_dSpeed( 0), m_dFeed( 0), m_dStartFeed( 0), m_dEndFeed( 0), m_dTipFeed( 0), m_dOffsR( UNKNOWN_PAR), m_dOffsL( UNKNOWN_PAR), m_bInvert( false), m_dStartPos( 0), m_dStep( 0), m_dSideStep( 0), m_nSubType( 0), m_dSideAngle( 0), - m_nLeadInType( 0), m_dLiTang( 0), + m_nLeadInType( 0), m_dLiTang( 0), m_dLiElev( 0), m_nLeadOutType( 0), m_dLoTang( 0) {} PocketingData* Clone( void) const override ; bool CopyFrom( const MachiningData* pMdata) override ; diff --git a/SawFinishing.cpp b/SawFinishing.cpp index 93121ef..02f1e27 100644 --- a/SawFinishing.cpp +++ b/SawFinishing.cpp @@ -34,6 +34,15 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2701 = "Error in SawFinishing : UpdateToolData failed" +// 2702 = "Error in SawFinishing : Empty RawBox" +// 2703 = "Error in SawFinishing : Depth not computable" +// 2704 = "Error in SawFinishing : CalculateToolAndCorrVersors" +// 2705 = "Error in SawFinishing : ApproxWithLines" +// 2706 = "Error in SawFinishing : Guide Line not along X or Y" +// 2707 = "Error in SawFinishing : GetElevation" + //---------------------------------------------------------------------------- typedef PtrOwner POWNCURVE ; typedef std::vector POCRVVECTOR ; @@ -407,7 +416,7 @@ SawFinishing::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2701, "Error in SawFinishing : UpdateToolData failed") ; return false ; } @@ -798,7 +807,7 @@ SawFinishing::CalculateAlongToolPath( int nAuxId, int nClId) // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nGuideId, 2 * m_TParams.m_dThick, b3Raw) || b3Raw.IsEmpty()) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : Empty RawBox") ; + m_pMchMgr->SetLastError( 2702, "Error in SawFinishing : Empty RawBox") ; return false ; } @@ -807,7 +816,7 @@ SawFinishing::CalculateAlongToolPath( int nAuxId, int nClId) ExeLuaSetGlobNumVar( "RB", b3Raw.GetMax().z - b3Raw.GetMin().z) ; double dDepth ; if ( ! ExeLuaEvalNumExpr( m_Params.m_sDepth, &dDepth)) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : Depth not computable") ; + m_pMchMgr->SetLastError( 2703, "Error in SawFinishing : Depth not computable") ; return false ; } @@ -821,7 +830,7 @@ SawFinishing::CalculateAlongToolPath( int nAuxId, int nClId) // Determino versori fresa e correzione Vector3d vtTool, vtCorr ; if ( ! CalculateToolAndCorrVersors( vtGdDir, m_Params.m_nHeadSide, vtTool, vtCorr)) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : CalculateToolAndCorrVersors") ; + m_pMchMgr->SetLastError( 2704, "Error in SawFinishing : CalculateToolAndCorrVersors") ; return false ; } @@ -947,7 +956,7 @@ SawFinishing::CalculateAcrossToolPath( int nAuxId, int nClId) // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nGuideId, 2 * m_TParams.m_dThick, b3Raw) || b3Raw.IsEmpty()) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : Empty RawBox") ; + m_pMchMgr->SetLastError( 2702, "Error in SawFinishing : Empty RawBox") ; return false ; } @@ -956,7 +965,7 @@ SawFinishing::CalculateAcrossToolPath( int nAuxId, int nClId) ExeLuaSetGlobNumVar( "RB", b3Raw.GetMax().z - b3Raw.GetMin().z) ; double dDepth ; if ( ! ExeLuaEvalNumExpr( m_Params.m_sDepth, &dDepth)) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : Depth not computable") ; + m_pMchMgr->SetLastError( 2703, "Error in SawFinishing : Depth not computable") ; return false ; } @@ -970,7 +979,7 @@ SawFinishing::CalculateAcrossToolPath( int nAuxId, int nClId) // Determino versori fresa e correzione Vector3d vtTool, vtCorr ; if ( ! CalculateToolAndCorrVersors( vtGdDir, m_Params.m_nHeadSide, vtTool, vtCorr)) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : CalculateToolAndCorrVersors") ; + m_pMchMgr->SetLastError( 2704, "Error in SawFinishing : CalculateToolAndCorrVersors") ; return false ; } @@ -979,7 +988,7 @@ SawFinishing::CalculateAcrossToolPath( int nAuxId, int nClId) const double ANG_TOL_STD_DEG = 15 ; PolyLine PL ; if ( ! pCrv->ApproxWithLines( LIN_TOL_STD, ANG_TOL_STD_DEG, ICurve::APL_RIGHT, PL)) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : ApproxWithLines") ; + m_pMchMgr->SetLastError( 2705, "Error in SawFinishing : ApproxWithLines") ; return false ; } // Se standard, allungo inizio e fine della sezione dello spessore lama @@ -1162,14 +1171,14 @@ SawFinishing::CalculateGuideLine( int nGuideId, Point3d& ptGdStart, Point3d& ptG // per ora ammesse solo linee guida rettilinee dirette lungo X o Y if ( ! AreSameOrOppositeVectorApprox( vtGdDir, X_AX) && ! AreSameOrOppositeVectorApprox( vtGdDir, Y_AX)) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : Guide Line not along X or Y") ; + m_pMchMgr->SetLastError( 2706, "Error in SawFinishing : Guide Line not along X or Y") ; return false ; } // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nGuideId, 2 * m_TParams.m_dThick, b3Raw) || b3Raw.IsEmpty()) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishing : Empty RawBox") ; + m_pMchMgr->SetLastError( 2702, "Error in SawFinishing : Empty RawBox") ; return false ; } @@ -1278,7 +1287,7 @@ SawFinishing::CalcAlongVerticalCuts( ICurve* pSect, int nUmin, int nUmax, const double dElev, dElev2 ; if ( ! GetElevation( m_nPhase, ptStart, ptEnd, vtCorr, dElev) || ! GetElevation( m_nPhase, ptStart + vtThick, ptEnd + vtThick, vtCorr, dElev2) ) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishinging : GetElevation") ; + m_pMchMgr->SetLastError( 2707, "Error in SawFinishinging : GetElevation") ; return false ; } dElev = max( dElev, dElev2) ; @@ -1361,7 +1370,7 @@ SawFinishing::CalcAlongStdCuts( ICurve* pSect, double dUmin, double dUmax, double dElev, dElev2 ; if ( ! GetElevation( m_nPhase, ptStart, ptEnd, vtCorr, dElev) || ! GetElevation( m_nPhase, ptStart + vtThick, ptEnd + vtThick, vtCorr, dElev2) ) { - LOG_INFO( GetEMkLogger(), "Error in SawFinishinging : GetElevation") ; + m_pMchMgr->SetLastError( 2707, "Error in SawFinishing : GetElevation") ; return false ; } dElev = max( dElev, dElev2) ; diff --git a/SawRoughing.cpp b/SawRoughing.cpp index baaf7dc..3d302ae 100644 --- a/SawRoughing.cpp +++ b/SawRoughing.cpp @@ -33,6 +33,16 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2601 = "Error in SawRoughing : UpdateToolData failed" +// 2602 = "Error in SawRoughing : Guide Line not along X or Y" +// 2603 = "Error in SawRoughing : Empty RawBox" +// 2604 = "Error in SawRoughing : OffsetCurve" +// 2605 = "Error in SawRoughing : OffsetCurveOnX" +// 2606 = "Error in SawRoughing : Depth not computable" +// 2607 = "Error in SawRoughing : CalculateToolAndCorrVersors" +// 2608 = "Error in SawRoughing : GetElevation" + //---------------------------------------------------------------------------- typedef PtrOwner POWNCURVE ; typedef std::vector POCRVVECTOR ; @@ -391,7 +401,7 @@ SawRoughing::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2601, "Error in SawRoughing : UpdateToolData failed") ; return false ; } @@ -777,14 +787,14 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) // per ora ammesse solo linee guida rettilinee dirette lungo X o Y if ( ! AreSameOrOppositeVectorApprox( vtGdDir, X_AX) && ! AreSameOrOppositeVectorApprox( vtGdDir, Y_AX)) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : Guide Line not along X or Y") ; + m_pMchMgr->SetLastError( 2602, "Error in SawRoughing : Guide Line not along X or Y") ; return false ; } // recupero il box del grezzo in globale e nel riferimento locale delle sezioni BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nGuideId, 2 * m_TParams.m_dThick, b3Raw) || b3Raw.IsEmpty()) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : Empty RawBox") ; + m_pMchMgr->SetLastError( 2603, "Error in SawRoughing : Empty RawBox") ; return false ; } BBox3d b3RawLoc = b3Raw ; @@ -860,7 +870,7 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) OffsCrv.Make( pCurve, dOffsR, ICurve::OFF_FILLET) ; pOvrCrv.Set( OffsCrv.GetLongerCurve()) ; if ( IsNull( pOvrCrv)) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : OffsetCurve") ; + m_pMchMgr->SetLastError( 2604, "Error in SawRoughing : OffsetCurve") ; return false ; } @@ -871,7 +881,7 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) OffsCrvX.Make( pOvrCrv, dOffsX) ; pCrv.Set( OffsCrvX.GetLongerCurve()) ; if ( IsNull( pCrv)) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : OffsetCurveOnX") ; + m_pMchMgr->SetLastError( 2605, "Error in SawRoughing : OffsetCurveOnX") ; return false ; } // determino l'ingombro della curva risultante in locale @@ -886,7 +896,7 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) ExeLuaSetGlobNumVar( "RB", b3Raw.GetMax().z - b3Raw.GetMin().z) ; double dDepth ; if ( ! ExeLuaEvalNumExpr( m_Params.m_sDepth, &dDepth)) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : Depth not computable") ; + m_pMchMgr->SetLastError( 2606, "Error in SawRoughing : Depth not computable") ; return false ; } @@ -900,7 +910,7 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) // Determino versori fresa e correzione Vector3d vtTool, vtCorr ; if ( ! CalculateToolAndCorrVersors( vtGdDir, m_Params.m_nHeadSide, vtTool, vtCorr)) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughing : CalculateToolAndCorrVersors") ; + m_pMchMgr->SetLastError( 2607, "Error in SawRoughing : CalculateToolAndCorrVersors") ; return false ; } @@ -988,7 +998,7 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) double dElev, dElev2 ; if ( ! GetElevation( m_nPhase, ptStart, ptEnd, vtCorr, dElev) || ! GetElevation( m_nPhase, ptStart + vtThick, ptEnd + vtThick, vtCorr, dElev2) ) { - LOG_INFO( GetEMkLogger(), "Error in SawRoughinging : GetElevation") ; + m_pMchMgr->SetLastError( 2608, "Error in SawRoughing : GetElevation") ; return false ; } dElev = max( dElev, dElev2) ; diff --git a/Sawing.cpp b/Sawing.cpp index d127728..bf5d6df 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -32,6 +32,22 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2201 = "Error in Sawing : UpdateToolData failed" +// 2202 = "Error in Sawing : Center work not allowed with side angle" +// 2203 = "Error in Sawing : External side angle HeadSide must equal WorkSide" +// 2204 = "Error in Sawing : Internal side angle HeadSide must opposite WorkSide" +// 2205 = "Error in Sawing : Depth not computable" +// 2206 = "Error in Sawing : machining depth (xx) bigger than MaxMaterial (yy)" +// 2207 = "Error in Sawing : SideAngle not allowed on Arc" +// 2208 = "Error in Sawing : Entity CalculateToolAndCorrVersors" +// 2209 = "Error in Sawing : Entity AdjustForSide" +// 2210 = "Error in Sawing : Entity GetElevation" +// 2211 = "Error in Sawing : Entity AdjustForEdges" +// 2212 = "Error in Sawing : Entity CalculateToolAndCorrVersors 2nd" +// 2213 = "Error in Sawing : Center work not allowed with internal arc" +// 2214 = "Error in Sawing : Chaining failed" + //---------------------------------------------------------------------------- USEROBJ_REGISTER( "EMkSawing", Sawing) ; @@ -424,13 +440,15 @@ Sawing::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2201, "Error in Sawing : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2214, "Error in Sawing : Chaining failed") ; return false ; + } // verifiche per angolo di sbandamento if ( ! VerifySideAngle()) @@ -491,13 +509,15 @@ Sawing::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2201, "Error in Sawing : UpdateToolData failed") ; return false ; } // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria - if ( bChain && ! Chain( nAuxId)) + if ( bChain && ! Chain( nAuxId)) { + m_pMchMgr->SetLastError( 2214, "Error in Sawing : Chaining failed") ; return false ; + } // verifiche per angolo di sbandamento if ( ! VerifySideAngle()) @@ -815,20 +835,20 @@ Sawing::VerifySideAngle( void) if ( abs( m_Params.m_dSideAngle) > EPS_ANG_SMALL) { // non ammesso lato di lavoro in centro if ( m_Params.m_nWorkSide == SAW_WS_CENTER) { - LOG_INFO( GetEMkLogger(), "Center work not allowed with side angle") ; + m_pMchMgr->SetLastError( 2202, "Error in Sawing : Center work not allowed with side angle") ; return false ; } // se angolo esterno lato mandrino deve uguagliare lato di lavoro if ( m_Params.m_dSideAngle > 0) { if ( m_Params.m_nWorkSide == SAW_WS_RIGHT) { if ( m_Params.m_nHeadSide == SAW_HS_LEFT) { - LOG_INFO( GetEMkLogger(), "External side angle HeadSide must equal WorkSide") ; + m_pMchMgr->SetLastError( 2203, "Error in Sawing : External side angle HeadSide must equal WorkSide") ; m_Params.m_nHeadSide = SAW_HS_RIGHT ; } } if ( m_Params.m_nWorkSide == SAW_WS_LEFT) { if ( m_Params.m_nHeadSide == SAW_HS_RIGHT) { - LOG_INFO( GetEMkLogger(), "External side angle HeadSide must equal WorkSide") ; + m_pMchMgr->SetLastError( 2203, "Error in Sawing : External side angle HeadSide must equal WorkSide") ; m_Params.m_nHeadSide = SAW_HS_LEFT ; } } @@ -837,13 +857,13 @@ Sawing::VerifySideAngle( void) else { if ( m_Params.m_nWorkSide == SAW_WS_RIGHT) { if ( m_Params.m_nHeadSide == SAW_HS_RIGHT) { - LOG_INFO( GetEMkLogger(), "Internal side angle HeadSide must opposite WorkSide") ; + m_pMchMgr->SetLastError( 2204, "Error in Sawing : Internal side angle HeadSide must opposite WorkSide") ; m_Params.m_nHeadSide = SAW_HS_LEFT ; } } if ( m_Params.m_nWorkSide == SAW_WS_LEFT) { if ( m_Params.m_nHeadSide == SAW_HS_LEFT) { - LOG_INFO( GetEMkLogger(), "Internal side angle HeadSide must opposite WorkSide") ; + m_pMchMgr->SetLastError( 2204, "Error in Sawing : Internal side angle HeadSide must opposite WorkSide") ; m_Params.m_nHeadSide = SAW_HS_RIGHT ; } } @@ -1070,7 +1090,7 @@ Sawing::ProcessPath( int nPathId, int nPvId, int nClId) double dDepth ; string sMyDepth = m_Params.m_sDepth ; if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Depth not computable") ; + m_pMchMgr->SetLastError( 2205, "Error in Sawing : Depth not computable") ; return false ; } // se spessore positivo, lo sottraggo dal risultato @@ -1090,8 +1110,9 @@ Sawing::ProcessPath( int nPathId, int nPvId, int nClId) } // verifico di non superare il massimo materiale if ( dDepth > m_TParams.m_dMaxMat) { - string sOut = "Error in Sawing : Depth bigger than MaxMaterial" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + string sOut = "Error in Sawing : machining depth (" + ToString( dDepth, 1) + + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; + m_pMchMgr->SetLastError( 2206, sOut.c_str()) ; return false ; } @@ -1100,21 +1121,11 @@ Sawing::ProcessPath( int nPathId, int nPvId, int nClId) m_pGeomDB->GetName( nPathId, sPathName) ; // verifiche sull'ampiezza dell'angolo al centro degli eventuali archi - const double MAX_ANG_CEN = 180 + EPS_ANG_SMALL ; - int nMaxInd = pCompo->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // se arco con angolo al centro oltre il limite, lo divido a metà - const ICurveArc* pArc = GetCurveArc( pCompo->GetCurve( i)) ; - if ( pArc != nullptr && abs( pArc->GetAngCenter()) > MAX_ANG_CEN) { - pCompo->AddJoint( i + 0.5) ; - ++ i ; - ++ nMaxInd ; - } - } + VerifyArcs( pCompo) ; // ciclo sulle curve elementari bool bClosed = pCompo->IsClosed() ; - nMaxInd = pCompo->GetCurveCount() - 1 ; + int nMaxInd = pCompo->GetCurveCount() - 1 ; for ( int i = 0 ; i <= nMaxInd ; ++ i) { // curva precedente int j = (( i == 0 && bClosed) ? nMaxInd : i - 1) ; @@ -1154,7 +1165,7 @@ Sawing::ProcessEntity( const ICurve* pCrvP, const ICurve* pCrvC, const ICurve* p return false ; // verifico che non ci sia angolo di fianco if ( abs( m_Params.m_dSideAngle) > EPS_ANG_SMALL) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : SideAngle not allowed on Arc") ; + m_pMchMgr->SetLastError( 2207, "Error in Sawing : SideAngle not allowed on Arc") ; return false ; } // se arco lavorato dall'esterno @@ -1190,12 +1201,12 @@ Sawing::ProcessLine( const ICurve* pCrvP, const ICurveLine* pLineC, const ICurve // calcolo i versori fresa e correzione Vector3d vtTool, vtCorr ; if ( ! CalculateToolAndCorrVersors( vtDirC, m_Params.m_nHeadSide, m_Params.m_nWorkSide, m_Params.m_dSideAngle, vtTool, vtCorr)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity CalculateToolAndCorrVersors") ; + m_pMchMgr->SetLastError( 2208, "Error in Sawing : Entity CalculateToolAndCorrVersors") ; return false ; } // correzioni per lato lama, lato mandrino if ( ! AdjustForSide( pLine)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity AdjustForSide") ; + m_pMchMgr->SetLastError( 2209, "Error in Sawing : Entity AdjustForSide") ; return false ; } // aggiungo affondamento @@ -1207,7 +1218,7 @@ Sawing::ProcessLine( const ICurve* pCrvP, const ICurveLine* pLineC, const ICurve Vector3d vtThick = vtToolH * ( m_TParams.m_dThick / vtToolH.SqLen() + 10 * EPS_SMALL) ; if ( ! GetElevation( m_nPhase, pLine->GetStart() - vtSafe, pLine->GetEnd() - vtSafe, vtCorr, dElev) || ! GetElevation( m_nPhase, pLine->GetStart() + vtThick, pLine->GetEnd() + vtThick, vtCorr, dElev2) ) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2210, "Error in Sawing : Entity GetElevation") ; return false ; } dElev = max( dElev, dElev2) ; @@ -1239,7 +1250,7 @@ Sawing::ProcessLine( const ICurve* pCrvP, const ICurveLine* pLineC, const ICurve // aggiusto per tipo estremi bool bToSkip = false ; if ( ! AdjustLineForEdges( pLine, dElev, vtCorr, vtThick, bIsFirst, bIsLast, bExtAngPC, bExtAngCN, bToSkip)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity AdjustForEdges") ; + m_pMchMgr->SetLastError( 2211, "Error in Sawing : Entity AdjustForEdges") ; return false ; } if ( bToSkip) { @@ -1567,12 +1578,12 @@ Sawing::ProcessExtArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve ! CalculateToolAndCorrVersors( vtEndDirC, m_Params.m_nHeadSide, m_Params.m_nWorkSide, m_Params.m_dSideAngle, vtEndTool, vtEndCorr) || ! AreSameVectorApprox( vtStaCorr, vtMidCorr) || ! AreSameVectorApprox( vtStaCorr, vtEndCorr)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity CalculateToolAndCorrVersors") ; + m_pMchMgr->SetLastError( 2208, "Error in Sawing : Entity CalculateToolAndCorrVersors") ; return false ; } // correzioni per lato lama, lato mandrino if ( ! AdjustForSide( pArc)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity AdjustForSide") ; + m_pMchMgr->SetLastError( 2209, "Error in Sawing : Entity AdjustForSide") ; return false ; } // aggiungo affondamento @@ -1588,7 +1599,7 @@ Sawing::ProcessExtArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve Vector3d vtEndThick = vtEndTool * m_TParams.m_dThick ; if ( ! GetElevation( m_nPhase, ptStart, ptMid, ptEnd, vtStaCorr, dElev) || ! GetElevation( m_nPhase, ptStart + vtStaThick, ptMid + vtMidThick, ptEnd + vtEndThick, vtStaCorr, dElev2) ) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2210, "Error in Sawing : Entity GetElevation") ; return false ; } dElev = max( dElev, dElev2) ; @@ -1617,7 +1628,7 @@ Sawing::ProcessExtArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve // aggiusto per tipo estremi bool bToSkip = false ; if ( ! AdjustArcForEdges( pArc, dElev, 1.0, bIsFirst, bIsLast, bExtAngPC, bExtAngCN, bToSkip)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity AdjustForEdges") ; + m_pMchMgr->SetLastError( 2211, "Error in Sawing : Entity AdjustForEdges") ; return false ; } if ( bToSkip) { @@ -1631,7 +1642,7 @@ Sawing::ProcessExtArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve if ( ! CalculateToolAndCorrVersors( vtStaDirC, m_Params.m_nHeadSide, m_Params.m_nWorkSide, m_Params.m_dSideAngle, vtStaTool, vtStaCorr) || ! CalculateToolAndCorrVersors( vtMidDirC, m_Params.m_nHeadSide, m_Params.m_nWorkSide, m_Params.m_dSideAngle, vtMidTool, vtMidCorr) || ! CalculateToolAndCorrVersors( vtEndDirC, m_Params.m_nHeadSide, m_Params.m_nWorkSide, m_Params.m_dSideAngle, vtEndTool, vtEndCorr)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity CalculateToolAndCorrVersors 2nd") ; + m_pMchMgr->SetLastError( 2212, "Error in Sawing : Entity CalculateToolAndCorrVersors 2nd") ; return false ; } @@ -2182,7 +2193,7 @@ Sawing::ProcessIntArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve // Verifiche su lato di lavoro e lato testa (si lavora con angolo di sbandamento negativo) int nHeadSide = m_Params.m_nHeadSide ; if ( m_Params.m_nWorkSide == SAW_WS_CENTER) { - LOG_INFO( GetEMkLogger(), "Center work not allowed with internal arc") ; + m_pMchMgr->SetLastError( 2213, "Error in Sawing : Center work not allowed with internal arc") ; return false ; } else if ( m_Params.m_nWorkSide == SAW_WS_LEFT) { @@ -2205,12 +2216,12 @@ Sawing::ProcessIntArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve if ( ! CalculateToolAndCorrVersors( vtStaDirC, nHeadSide, m_Params.m_nWorkSide, dSideAng, vtStaTool, vtStaCorr) || ! CalculateToolAndCorrVersors( vtMidDirC, nHeadSide, m_Params.m_nWorkSide, dSideAng, vtMidTool, vtMidCorr) || ! CalculateToolAndCorrVersors( vtEndDirC, nHeadSide, m_Params.m_nWorkSide, dSideAng, vtEndTool, vtEndCorr)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity CalculateToolAndCorrVersors") ; + m_pMchMgr->SetLastError( 2208, "Error in Sawing : Entity CalculateToolAndCorrVersors") ; return false ; } // correzioni per lato lama, lato mandrino if ( ! AdjustIntArcForSide( pArc, dSideAng)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity AdjustForSide") ; + m_pMchMgr->SetLastError( 2209, "Error in Sawing : Entity AdjustForSide") ; return false ; } // aggiungo affondamento @@ -2226,7 +2237,7 @@ Sawing::ProcessIntArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve Vector3d vtEndThick = vtEndTool * m_TParams.m_dThick ; if ( ! GetElevation( m_nPhase, ptStart, ptMid, ptEnd, Z_AX, dElev) || ! GetElevation( m_nPhase, ptStart + vtStaThick, ptMid + vtMidThick, ptEnd + vtEndThick, Z_AX, dElev2) ) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2210, "Error in Sawing : Entity GetElevation") ; return false ; } dElev = max( dElev, dElev2) ; @@ -2259,7 +2270,7 @@ Sawing::ProcessIntArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve double dLenCoeff = ( dRad + 0.8 * dDelta) / dRad ; // coefficiente per riportare lunghezza bool bToSkip = false ; if ( ! AdjustArcForEdges( pArc, dSlantElev, dLenCoeff, bIsFirst, bIsLast, bExtAngPC, bExtAngCN, bToSkip)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity AdjustForEdges") ; + m_pMchMgr->SetLastError( 2211, "Error in Sawing : Entity AdjustForEdges") ; return false ; } if ( bToSkip) { @@ -2273,7 +2284,7 @@ Sawing::ProcessIntArc( const ICurve* pCrvP, const ICurveArc* pArcC, const ICurve if ( ! CalculateToolAndCorrVersors( vtStaDirC, nHeadSide, m_Params.m_nWorkSide, dSideAng, vtStaTool, vtStaCorr) || ! CalculateToolAndCorrVersors( vtMidDirC, nHeadSide, m_Params.m_nWorkSide, dSideAng, vtMidTool, vtMidCorr) || ! CalculateToolAndCorrVersors( vtEndDirC, nHeadSide, m_Params.m_nWorkSide, dSideAng, vtEndTool, vtEndCorr)) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : Entity CalculateToolAndCorrVersors 2nd") ; + m_pMchMgr->SetLastError( 2212, "Error in Sawing : Entity CalculateToolAndCorrVersors 2nd") ; return false ; }