diff --git a/MachMgr.h b/MachMgr.h index 6b22dee..ef0bb46 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -68,6 +68,10 @@ class MachMgr : public IMachMgr int nContextId, const std::string& sLuaLibsDir, const std::string& sLuaLastRequire) override ; bool Update( void) override ; bool Insert( int nInsGrp) override ; + int GetLastErrorId( void) override + { return m_nLastError ; } + std::string GetLastErrorString( void) override + { return m_sLastError ; } // Machines bool SetCurrMachine( const std::string& sMachineName) override ; bool GetCurrMachineName( std::string& sMachineName) const override ; @@ -307,6 +311,7 @@ class MachMgr : public IMachMgr { return m_sLuaLibsDir ; } std::string GetLuaLastRequire( void) const { return m_sLuaLastRequire ; } + bool SetLastError( int nErr, const std::string& sErr) ; // Current Machine std::string GetCurrSetupDir( void) const { Machine* pMch = GetCurrMachine() ; @@ -394,6 +399,8 @@ class MachMgr : public IMachMgr std::string m_sMachinesDir ; // direttorio delle macchine std::string m_sLuaLibsDir ; // direttorio delle librerie lua std::string m_sLuaLastRequire ; // nome ultima libreria caricata + int m_nLastError ; // identificativo ultimo errore + std::string m_sLastError ; // descrittivo ultimo errore int m_nMachBaseId ; // identificativo gruppo base per le macchinate int m_nMachAuxId ; // identificativo gruppo base per le macchine int m_nCurrMGrpId ; // identificativo macchinata corrente diff --git a/MachMgrBasic.cpp b/MachMgrBasic.cpp index e893662..03334d7 100644 --- a/MachMgrBasic.cpp +++ b/MachMgrBasic.cpp @@ -43,6 +43,7 @@ MachMgr::MachMgr( void) { m_nContextId = 0 ; m_pGeomDB = nullptr ; + m_nLastError = 0 ; m_nMachBaseId = GDB_ID_NULL ; m_nMachAuxId = GDB_ID_NULL ; m_nCurrMGrpId = GDB_ID_NULL ; @@ -287,3 +288,14 @@ MachMgr::CreateMachAux( void) m_pGeomDB->SetLevel( m_nMachAuxId, GDB_LV_TEMP) ; return true ; } + +//---------------------------------------------------------------------------- +bool +MachMgr::SetLastError( int nErr, const string& sErr) +{ + m_nLastError = nErr ; + m_sLastError = sErr ; + string sInfo = m_sLastError + " (" + ToString( nErr) + ")" ; + LOG_INFO( GetEMkLogger(), sInfo.c_str()) ; + return true ; +} diff --git a/Pocketing.cpp b/Pocketing.cpp index 2cfe14b..cba90fe 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -31,6 +31,18 @@ using namespace std ; +//------------------------------ Errors -------------------------------------- +// 2501 = "Error in Milling : 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" + //---------------------------------------------------------------------------- USEROBJ_REGISTER( "EMkPocketing", Pocketing) ; @@ -73,7 +85,7 @@ Pocketing::Dump( string& sOut, bool bMM, const char* szNewLine) const sOut += m_Params.ToString( i) + szNewLine ; for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) sOut += m_TParams.ToString( i) + szNewLine ; - sOut += KEY_NUM + EQUAL + ToString( m_nMills) + szNewLine ; + sOut += KEY_NUM + EQUAL + ToString( m_nPockets) + szNewLine ; return true ; } @@ -94,7 +106,7 @@ Pocketing::Save( STRVECTOR& vString) const vString[++k] = m_TParams.ToString( i) ; if ( ! SetVal( KEY_PHASE, m_nPhase, vString[++k])) return false ; - if ( ! SetVal( KEY_NUM, m_nMills, vString[++k])) + if ( ! SetVal( KEY_NUM, m_nPockets, vString[++k])) return false ; } catch( ...) { @@ -141,7 +153,7 @@ Pocketing::Load( const STRVECTOR& vString, int nBaseGdbId) return false ; } else if ( sKey == KEY_NUM) { - if ( ! FromString( sVal, m_nMills)) + if ( ! FromString( sVal, m_nPockets)) return false ; } } @@ -156,7 +168,7 @@ Pocketing::Pocketing( void) m_Params.m_sToolName = "*" ; m_TParams.m_sName = "*" ; m_TParams.m_sHead = "*" ; - m_nMills = 0 ; + m_nPockets = 0 ; } //---------------------------------------------------------------------------- @@ -354,8 +366,8 @@ Pocketing::SetGeometry( const SELVECTOR& vIds) bool Pocketing::Preview( bool bRecalc) { - // reset numero percorsi di lavoro generati - m_nMills = 0 ; + // reset numero percorsi di svuotatura generati + m_nPockets = 0 ; // verifico validità gestore DB geometrico e Id del gruppo if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId)) @@ -381,7 +393,7 @@ Pocketing::Preview( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2501, "Error in Pocketing : UpdateToolData failed") ; return false ; } @@ -417,8 +429,8 @@ Pocketing::Preview( bool bRecalc) bool Pocketing::Apply( bool bRecalc) { - // reset numero percorsi di lavoro generati - m_nMills = 0 ; + // reset numero percorsi di svuotatura generati + m_nPockets = 0 ; // verifico validità gestore DB geometrico e Id del gruppo if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId)) @@ -444,7 +456,7 @@ Pocketing::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + m_pMchMgr->SetLastError( 2501, "Error in Pocketing : UpdateToolData failed") ; return false ; } @@ -466,15 +478,18 @@ Pocketing::Apply( bool bRecalc) m_pGeomDB->EmptyGroup( nClId) ; // lavoro ogni singola catena + bool bOk = true ; int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ; while ( nPathId != GDB_ID_NULL) { if ( ! ProcessPath( nPathId, GDB_ID_NULL, nClId)) - return false ; + bOk = false ; nPathId = m_pGeomDB->GetNextGroup( nPathId) ; } + if ( ! bOk) + return false ; // se lavorazione vuota, esco - if ( m_nMills == 0) + if ( m_nPockets == 0) return true ; // calcolo gli assi macchina @@ -943,25 +958,41 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) m_pGeomDB->SetLevel( nTempId, GDB_LV_TEMP) ; m_pGeomDB->SetStatus( nTempId, GDB_ST_OFF) ; - // copio la curva composita da elaborare + // verifico sia una curva chiusa (deve delimitare l'area da svuotare) int nCrvId = m_pGeomDB->GetFirstInGroup( nPathId) ; if ( m_pGeomDB->GetGeoType( nCrvId) != CRV_COMPO) return false ; + ICurve* pCrv = ::GetCurve( m_pGeomDB->GetGeoObj( nCrvId)) ; + if ( pCrv == nullptr || ! pCrv->IsClosed()) { + m_pMchMgr->SetLastError( 2502, "Error in Pocketing : Open Contour") ; + return false ; + } + + // copio la curva composita da elaborare int nCopyId = m_pGeomDB->CopyGlob( nCrvId, GDB_ID_NULL, nTempId) ; if ( nCopyId == GDB_ID_NULL) return false ; ICurveComposite* pCompo = GetCurveComposite( m_pGeomDB->GetGeoObj( nCopyId)) ; - // eventuale inversione percorso - if ( m_Params.m_bInvert) - pCompo->Invert() ; - // recupero estrusione e spessore - Vector3d vtExtr ; + Vector3d vtExtr = Z_AX ; pCompo->GetExtrusion( vtExtr) ; double dThick ; pCompo->GetThickness( dThick) ; + // 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") ; + 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") ; + return false ; + } + if ( plPlane.vtN * vtExtr * dArea < 0) + pCompo->Invert() ; + // unisco le parti allineate (tranne inizio-fine se chiusa) if ( ! pCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, false)) return false ; @@ -973,7 +1004,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()) { - LOG_INFO( GetEMkLogger(), "Error in Milling : Empty RawBox") ; + m_pMchMgr->SetLastError( 2505, "Error in Pocketing : Empty RawBox") ; return false ; } @@ -990,7 +1021,7 @@ Pocketing::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( 2506, "Error in Pocketing : Depth not computable") ; return false ; } // se spessore positivo, lo sottraggo dal risultato @@ -1034,10 +1065,8 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) } } - // calcolo il versore fresa - Vector3d vtTool = Z_AX ; - if ( ! vtExtr.IsSmall()) - vtTool = vtExtr ; + // assegno il versore fresa + Vector3d vtTool = vtExtr ; // calcolo l'elevazione massima double dElev ; @@ -1051,27 +1080,25 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) else return false ; - // per frese normali, verifico di non superare il massimo materiale - if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) { - const double MAXMAT_TOL = EPS_SMALL ; - if ( ( m_Params.m_dStep < EPS_SMALL && dElev > m_TParams.m_dMaxMat + MAXMAT_TOL) || - ( m_Params.m_dStep > EPS_SMALL && m_Params.m_dStep > m_TParams.m_dMaxMat + EPS_SMALL)) { - if ( dDepth + max( dThick, 0.0) > m_TParams.m_dMaxMat) { - dDepth = m_TParams.m_dMaxMat - max( dThick, 0.0) ; - string sInfo = "Warning in Milling : machining depth (" + ToString( dElev, 1) + - ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; - LOG_INFO( GetEMkLogger(), sInfo.c_str()) ; - } - 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()) ; - return false ; - } + // verifico di non superare il massimo materiale + const double MAXMAT_TOL = EPS_SMALL ; + if ( ( m_Params.m_dStep < EPS_SMALL && dElev > m_TParams.m_dMaxMat + MAXMAT_TOL) || + ( m_Params.m_dStep > EPS_SMALL && m_Params.m_dStep > m_TParams.m_dMaxMat + EPS_SMALL)) { + if ( dDepth + max( dThick, 0.0) > m_TParams.m_dMaxMat) { + dDepth = m_TParams.m_dMaxMat - max( dThick, 0.0) ; + string sInfo = "Warning in Pocketing : machining depth (" + ToString( dElev, 1) + + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; + LOG_INFO( GetEMkLogger(), sInfo.c_str()) ; + } + 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) ; + return false ; } } - // verifiche per fresatura dal basso + // verifiche per svuotature dal basso m_bAggrBottom = false ; if ( ! VerifyPathFromBottom( pCompo, vtTool)) { return false ; @@ -1109,7 +1136,7 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) SetToolDir( vtTool) ; // Se una sola passata - if ( ! AddStandardMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) + if ( ! AddSpiralIn( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) return false ; // assegno al gruppo l'ingombro del percorso di lavoro @@ -1119,8 +1146,8 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) m_pGeomDB->SetInfo( nPxId, KEY_PMAX, b3Grp.GetMax()) ; } - // incremento numero di fresate - ++ m_nMills ; + // incremento numero di svuotature + ++ m_nPockets ; return true ; } @@ -1161,7 +1188,7 @@ Pocketing::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2508, "Error in Pocketing : Entity GetElevation") ; return false ; } // da una parte @@ -1171,7 +1198,7 @@ Pocketing::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2508, "Error in Pocketing : Entity GetElevation") ; return false ; } // dall'altra parte @@ -1181,7 +1208,7 @@ Pocketing::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtT dElev = dCurrElev ; } else { - LOG_INFO( GetEMkLogger(), "Error in Milling : Entity GetElevation") ; + m_pMchMgr->SetLastError( 2508, "Error in Pocketing : Entity GetElevation") ; return false ; } } @@ -1203,8 +1230,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) { - string sOut = "Milling error : missing aggregate from bottom" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2509, "Error in Pocketing : missing aggregate from bottom") ; return false ; } // recupero la massima distanza consentita dal rinvio @@ -1244,8 +1270,7 @@ Pocketing::VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& } // se supera il limite, errore if ( dDist > dAgbDmax) { - string sOut = "Milling error : path too far from part sides" ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + m_pMchMgr->SetLastError( 2510, "Error in Pocketing : path too far from part sides") ; return false ; } // assegno direzione di accesso e segnalo utilizzo aggregato da sotto @@ -1311,8 +1336,8 @@ Pocketing::GenerateMillingPv( int nPathId, const ICurveComposite* pCompo) //---------------------------------------------------------------------------- bool -Pocketing::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, - double dDepth, double dElev, bool bSplitArcs) +Pocketing::AddSpiralIn( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, + double dDepth, double dElev, bool bSplitArcs) { // recupero distanza di sicurezza double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() ; diff --git a/Pocketing.h b/Pocketing.h index 1bcdc81..a8a2501 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -34,7 +34,7 @@ class Pocketing : public Machining public : // Operation bool IsEmpty( void) const override - { return ( m_nMills == 0) ; } + { return ( m_nPockets == 0) ; } protected : // Operation int GetSolCh( void) const override @@ -70,8 +70,8 @@ class Pocketing : public Machining bool CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double& dElev) ; bool VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& vtTool) ; bool GenerateMillingPv( int nPathId, const ICurveComposite* pCompo) ; - bool AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, - double dDepth, double dElev, bool bSplitArcs) ; + bool AddSpiralIn( 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 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, @@ -102,6 +102,6 @@ class Pocketing : public Machining SELVECTOR m_vId ; // identificativi entità geometriche da lavorare PocketingData m_Params ; // parametri lavorazione ToolData m_TParams ; // parametri utensile - int m_nMills ; // numero di percorsi di lavoro generati + int m_nPockets ; // numero di percorsi di svuotatura generati bool m_bAggrBottom ; // flag di utilizzo dell'aggregato da sotto } ; \ No newline at end of file