From 984f206d5653303f538eab01c04e351a849fd4b5 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Fri, 13 Mar 2026 17:28:21 +0100 Subject: [PATCH] EgtMachKernel (NewLink) : - primo commit per codice NewLink. --- Disposition.h | 2 + MachMgrOperations.cpp | 4 +- MachineLuaCL.cpp | 66 ++-- Machining.cpp | 2 +- Machining.h | 2 +- Operation.cpp | 771 ++++++++++++++++++++++++++++++++---------- Operation.h | 38 ++- 7 files changed, 666 insertions(+), 219 deletions(-) diff --git a/Disposition.h b/Disposition.h index 9d374a2..773587a 100644 --- a/Disposition.h +++ b/Disposition.h @@ -89,6 +89,8 @@ class Disposition : public Operation const std::string& GetHeadName( void) const override ; int GetExitNbr( void) const override ; const std::string& GetToolTcPos( void) const override ; + bool GetDoubleToolData( std::string& sDblTool, std::string& sDblHead, int& nDblExit) const override + { return false ; } int GetSolCh( void) const override { return 0 ; } bool NeedPrevHome( void) const override ; diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index 151020d..dadd4a9 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -1358,7 +1358,7 @@ MachMgr::GetMachiningStartAxes( bool bSkipClimb, DBLVECTOR& vAxVal) const if ( pMch == nullptr) return false ; // recupero i valori - return pMch->GetInitialAxesValues( bSkipClimb, vAxVal) ; + return pMch->GetInitialAxesValues( bSkipClimb, true, vAxVal) ; } //---------------------------------------------------------------------------- @@ -1374,5 +1374,5 @@ MachMgr::GetMachiningEndAxes( bool bSkipRise, DBLVECTOR& vAxVal) const if ( pMch == nullptr) return false ; // recupero i valori - return pMch->GetFinalAxesValues( bSkipRise, vAxVal) ; + return pMch->GetFinalAxesValues( bSkipRise, true, vAxVal) ; } diff --git a/MachineLuaCL.cpp b/MachineLuaCL.cpp index 7de769f..78c0fee 100644 --- a/MachineLuaCL.cpp +++ b/MachineLuaCL.cpp @@ -296,19 +296,22 @@ Machine::LuaEmtAddArcMove( lua_State* L) int Machine::LuaEmtAddClimb( lua_State* L) { - // 5 o 6 parametri : nMachId, vAxVal, nMask, nFlag, nFlag2 [, sInfo] + // 5 o 6 o 7 parametri : nMachId [, sMain], vAxVal, nMask, nFlag, nFlag2 [, sInfo] int nMachId ; LuaCheckParam( L, 1, nMachId) + string sMain = MCH_CL ; + int nOffs = ( LuaGetParam( L, 2, sMain) ? 1 : 0) ; + bool bMain = ( ! EqualNoCase( sMain, MCH_DBL)) ; DBLVECTOR vAxVal ; - LuaCheckParam( L, 2, vAxVal) + LuaCheckParam( L, 2 + nOffs, vAxVal) int nMask ; - LuaCheckParam( L, 3, nMask) + LuaCheckParam( L, 3 + nOffs, nMask) int nFlag ; - LuaCheckParam( L, 4, nFlag) + LuaCheckParam( L, 4 + nOffs, nFlag) int nFlag2 ; - LuaCheckParam( L, 5, nFlag2) + LuaCheckParam( L, 5 + nOffs, nFlag2) string sInfo = "" ; - LuaGetParam( L, 6, sInfo) ; + LuaGetParam( L, 6 + nOffs, sInfo) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva valida if ( m_pMchLua == nullptr || @@ -317,7 +320,7 @@ Machine::LuaEmtAddClimb( lua_State* L) // recupero l'operazione Operation* pOper = GetOperation( m_pMchLua->m_pGeomDB->GetUserObj( nMachId)) ; // imposto la discesa (primo movimento del primo percorso della lavorazione) - bool bOk = ( pOper != nullptr && pOper->AddSpecialClimb( vAxVal, ( nMask >= 0), GDB_ID_NULL, nFlag, nFlag2, nMask, sInfo, false)) ; + bool bOk = ( pOper != nullptr && pOper->AddSpecialClimb( vAxVal, ( nMask >= 0), GDB_ID_NULL, bMain, nFlag, nFlag2, nMask, sInfo, false)) ; if ( ! bOk) return luaL_error( L, " Error in EmtAddClimb") ; LuaSetParam( L, bOk) ; @@ -329,9 +332,12 @@ Machine::LuaEmtAddClimb( lua_State* L) int Machine::LuaEmtRemoveClimb( lua_State* L) { - // 1 parametro : nMachId + // 1 o 2 parametri : nMachId [, sMain] int nMachId ; LuaCheckParam( L, 1, nMachId) + string sMain = MCH_CL ; + LuaGetParam( L, 2, sMain) ; + bool bMain = ( ! EqualNoCase( sMain, MCH_DBL)) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva valida if ( m_pMchLua == nullptr || @@ -340,7 +346,7 @@ Machine::LuaEmtRemoveClimb( lua_State* L) // recupero l'operazione Operation* pOper = GetOperation( m_pMchLua->m_pGeomDB->GetUserObj( nMachId)) ; // elimino le discese (primi movimenti "CLIMB" del primo percorso della lavorazione) - bool bOk = ( pOper != nullptr && pOper->RemoveClimb()) ; + bool bOk = ( pOper != nullptr && pOper->RemoveClimb( GDB_ID_NULL, bMain)) ; LuaSetParam( L, bOk) ; return 1 ; @@ -350,19 +356,22 @@ Machine::LuaEmtRemoveClimb( lua_State* L) int Machine::LuaEmtAddRise( lua_State* L) { - // 5 o 6 parametri : nMachId, vAxVal, nMask, nFlag, nFlag2 [, sInfo] + // 5 o 6 o 7 parametri : nMachId [, sMain], vAxVal, nMask, nFlag, nFlag2 [, sInfo] int nMachId ; LuaCheckParam( L, 1, nMachId) + string sMain = MCH_CL ; + int nOffs = ( LuaGetParam( L, 2, sMain) ? 1 : 0) ; + bool bMain = ( ! EqualNoCase( sMain, MCH_DBL)) ; DBLVECTOR vAxVal ; - LuaCheckParam( L, 2, vAxVal) + LuaCheckParam( L, 2 + nOffs, vAxVal) int nMask ; - LuaCheckParam( L, 3, nMask) + LuaCheckParam( L, 3 + nOffs, nMask) int nFlag ; - LuaCheckParam( L, 4, nFlag) + LuaCheckParam( L, 4 + nOffs, nFlag) int nFlag2 ; - LuaCheckParam( L, 5, nFlag2) + LuaCheckParam( L, 5 + nOffs, nFlag2) string sInfo = "" ; - LuaGetParam( L, 6, sInfo) ; + LuaGetParam( L, 6 + nOffs, sInfo) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva valida if ( m_pMchLua == nullptr || @@ -371,7 +380,7 @@ Machine::LuaEmtAddRise( lua_State* L) // recupero l'operazione Operation* pOper = GetOperation( m_pMchLua->m_pGeomDB->GetUserObj( nMachId)) ; // aggiungo la risalita (ultimo movimento dell'ultimo percorso della lavorazione) - bool bOk = ( pOper != nullptr && pOper->AddSpecialRise( vAxVal, ( nMask >= 0), GDB_ID_NULL, nFlag, nFlag2, nMask, sInfo)) ; + bool bOk = ( pOper != nullptr && pOper->AddSpecialRise( vAxVal, ( nMask >= 0), GDB_ID_NULL, bMain, nFlag, nFlag2, nMask, sInfo)) ; if ( ! bOk) return luaL_error( L, " Error in EmtAddRise") ; LuaSetParam( L, bOk) ; @@ -383,9 +392,12 @@ Machine::LuaEmtAddRise( lua_State* L) int Machine::LuaEmtRemoveRise( lua_State* L) { - // 1 parametro : nMachId + // 1 o 2 parametri : nMachId [, bMain] int nMachId ; LuaCheckParam( L, 1, nMachId) + string sMain = MCH_CL ; + LuaGetParam( L, 2, sMain) ; + bool bMain = ( ! EqualNoCase( sMain, MCH_DBL)) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva valida if ( m_pMchLua == nullptr || @@ -394,7 +406,7 @@ Machine::LuaEmtRemoveRise( lua_State* L) // recupero l'operazione Operation* pOper = GetOperation( m_pMchLua->m_pGeomDB->GetUserObj( nMachId)) ; // elimino le risalite (ultimi movimenti "RISE" dell'ultimo percorso della lavorazione) - bool bOk = ( pOper != nullptr && pOper->RemoveRise()) ; + bool bOk = ( pOper != nullptr && pOper->RemoveRise( GDB_ID_NULL, bMain)) ; LuaSetParam( L, bOk) ; return 1 ; @@ -404,11 +416,14 @@ Machine::LuaEmtRemoveRise( lua_State* L) int Machine::LuaEmtGetInitialAxesPos( lua_State* L) { - // 1 o 2 parametri : nMachId [, bSkipClimb] + // 1 o 2 o 3 parametri : nMachId [, sMain] [, bSkipClimb] int nMachId ; LuaCheckParam( L, 1, nMachId) + string sMain = MCH_CL ; + int nOffs = ( LuaGetParam( L, 2, sMain) ? 1 : 0) ; + bool bMain = ( ! EqualNoCase( sMain, MCH_DBL)) ; bool bSkipClimb = true ; - LuaGetParam( L, 2, bSkipClimb) ; + LuaGetParam( L, 2 + nOffs, bSkipClimb) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva valida if ( m_pMchLua == nullptr || @@ -418,7 +433,7 @@ Machine::LuaEmtGetInitialAxesPos( lua_State* L) Operation* pOper = GetOperation( m_pMchLua->m_pGeomDB->GetUserObj( nMachId)) ; // acquisico il valore iniziale degli assi macchina DBLVECTOR vAxesVal ; - bool bOk = ( pOper != nullptr && pOper->GetInitialAxesValues( bSkipClimb, vAxesVal)) ; + bool bOk = ( pOper != nullptr && pOper->GetInitialAxesValues( bSkipClimb, bMain, vAxesVal)) ; if ( bOk) LuaSetParam( L, vAxesVal) ; else @@ -431,11 +446,14 @@ Machine::LuaEmtGetInitialAxesPos( lua_State* L) int Machine::LuaEmtGetFinalAxesPos( lua_State* L) { - // 1 o 2 parametri : nMachId [, bSkipRise] + // 1 o 2 o 3 parametri : nMachId [, sMain] [, bSkipRise] int nMachId ; LuaCheckParam( L, 1, nMachId) bool bSkipRise = true ; - LuaGetParam( L, 2, bSkipRise) ; + string sMain = MCH_CL ; + int nOffs = ( LuaGetParam( L, 2, sMain) ? 1 : 0) ; + bool bMain = ( ! EqualNoCase( sMain, MCH_DBL)) ; + LuaGetParam( L, 2 + nOffs, bSkipRise) ; LuaClearStack( L) ; // verifico ci sia una macchina attiva valida if ( m_pMchLua == nullptr || @@ -445,7 +463,7 @@ Machine::LuaEmtGetFinalAxesPos( lua_State* L) Operation* pOper = GetOperation( m_pMchLua->m_pGeomDB->GetUserObj( nMachId)) ; // acquisico il valore finale degli assi macchina DBLVECTOR vAxesVal ; - bool bOk = ( pOper != nullptr && pOper->GetFinalAxesValues( bSkipRise, vAxesVal)) ; + bool bOk = ( pOper != nullptr && pOper->GetFinalAxesValues( bSkipRise, bMain, vAxesVal)) ; if ( bOk) LuaSetParam( L, vAxesVal) ; else diff --git a/Machining.cpp b/Machining.cpp index ec6d97e..b50a114 100644 --- a/Machining.cpp +++ b/Machining.cpp @@ -698,7 +698,7 @@ Machining::GetToolPreviewStepCount( void) const int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; if ( nClId == GDB_ID_NULL) return 0 ; - // determino il numero di entità di tutti i sottogruppi, escludendo CLIMB e RISE + // determino il numero di entità di tutti i sottogruppi, escludendo CLIMB, RISE ed HOME int nCount = 0 ; int nPxId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; while ( nPxId != GDB_ID_NULL) { diff --git a/Machining.h b/Machining.h index ea81632..9fe89fe 100644 --- a/Machining.h +++ b/Machining.h @@ -62,7 +62,7 @@ class Machining : public Operation bool SpecialApply( std::string& sErr) ; bool PostApply( std::string& sErr) ; int GetDoubleType( const std::string& sUserNotes) ; - bool GetDoubleToolData( std::string& sDblTool, std::string& sDblHead, int& nDblExit) const ; + bool GetDoubleToolData( std::string& sDblTool, std::string& sDblHead, int& nDblExit) const override ; bool CalcMirrorByDouble( int nClId, const std::string& sUserNotes) ; bool ActivateDrillingUnit( int nHeadId, const INTVECTOR& vActExit) const ; diff --git a/Operation.cpp b/Operation.cpp index 53ab9c2..c569b44 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -192,11 +192,15 @@ Operation::GetFirstFullToolpath( bool bMain) const //---------------------------------------------------------------------------- int -Operation::GetNextFullToolpath( int nClPathId) const +Operation::GetNextFullToolpath( int nClPathId, bool bMain) const { + string sName ; do { nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; - } while ( nClPathId != GDB_ID_NULL && m_pGeomDB->GetFirstInGroup( nClPathId) == GDB_ID_NULL) ; + } while ( nClPathId != GDB_ID_NULL && + m_pGeomDB->GetFirstInGroup( nClPathId) == GDB_ID_NULL && + m_pGeomDB->GetName( nClPathId, sName) && + EqualNoCase( sName, bMain ? MCH_DBL : MCH_CL)) ; return nClPathId ; } @@ -214,11 +218,15 @@ Operation::GetLastFullToolpath( bool bMain) const //---------------------------------------------------------------------------- int -Operation::GetPrevFullToolpath( int nClPathId) const +Operation::GetPrevFullToolpath( int nClPathId, bool bMain) const { + string sName ; do { nClPathId = m_pGeomDB->GetPrevGroup( nClPathId) ; - } while ( nClPathId != GDB_ID_NULL && m_pGeomDB->GetFirstInGroup( nClPathId) == GDB_ID_NULL) ; + } while ( nClPathId != GDB_ID_NULL && + m_pGeomDB->GetFirstInGroup( nClPathId) == GDB_ID_NULL && + m_pGeomDB->GetName( nClPathId, sName) && + EqualNoCase( sName, bMain ? MCH_DBL : MCH_CL)) ; return nClPathId ; } @@ -1560,9 +1568,9 @@ Operation::CalcAndSetAxesBBox( void) //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- bool -Operation::GetInitialAxesValues( bool bSkipClimb, DBLVECTOR& vAxVal) const +Operation::GetInitialAxesValues( bool bSkipClimb, bool bMain, DBLVECTOR& vAxVal) const { - const CamData* pCamData = GetInitialCamData( bSkipClimb) ; + const CamData* pCamData = GetInitialCamData( bSkipClimb, bMain) ; vAxVal = ( pCamData != nullptr ? pCamData->GetAxesVal() : DBLVECTOR()) ; return ( vAxVal.size() > 0) ; } @@ -1578,9 +1586,9 @@ Operation::GetClPathInitialAxesValues( int nClPathId, bool bSkipClimb, DBLVECTOR //---------------------------------------------------------------------------- bool -Operation::GetFinalAxesValues( bool bSkipRise, DBLVECTOR& vAxVal) const +Operation::GetFinalAxesValues( bool bSkipRise, bool bMain, DBLVECTOR& vAxVal) const { - const CamData* pCamData = GetFinalCamData( bSkipRise) ; + const CamData* pCamData = GetFinalCamData( bSkipRise, bMain) ; vAxVal = ( pCamData != nullptr ? pCamData->GetAxesVal() : DBLVECTOR()) ; return ( vAxVal.size() > 0) ; } @@ -1632,10 +1640,10 @@ Operation::GetClPathFinalToolDir( int nClPathId, bool bSkipRise, Vector3d& vtToo //---------------------------------------------------------------------------- const CamData* -Operation::GetInitialCamData( bool bSkipClimb) const +Operation::GetInitialCamData( bool bSkipClimb, bool bMain) const { // recupero il primo percorso CL non vuoto - int nClPathId = GetFirstFullToolpath() ; + int nClPathId = GetFirstFullToolpath( bMain) ; if ( nClPathId == GDB_ID_NULL) return nullptr ; // recupero i dati Cam della prima entità del percorso @@ -1665,10 +1673,10 @@ Operation::GetClPathInitialCamData( int nClPathId, bool bSkipClimb) const //---------------------------------------------------------------------------- const CamData* -Operation::GetFinalCamData( bool bSkipRise) const +Operation::GetFinalCamData( bool bSkipRise, bool bMain) const { // recupero l'ultimo percorso CL non vuoto - int nClPathId = GetLastFullToolpath() ; + int nClPathId = GetLastFullToolpath( bMain) ; if ( nClPathId == GDB_ID_NULL) return nullptr ; // recupero i dati Cam dell'ultima entità del percorso @@ -1863,8 +1871,8 @@ Operation::CalculateAxesValues( const string& sHint, bool bSolChExact, double dS DBLVECTOR vAxRotPrec( nRotAxes, 0.) ; DBLVECTOR vAxVal ; // se non richiesti angoli Home e utensile non cambiato, uso gli angoli finali della lavorazione precedente - if ( ! bHintHome && GetUserNotesZmax() != 2 && ! sPrevTool.empty() && ! ToolChangeNeeded( *pPrevOp, *this) && - pPrevOp->GetFinalAxesValues( true, vAxVal)) { + if ( ! bHintHome && GetUserNotesZmax() != 2 && ! sPrevTool.empty() && ! ToolChangeNeeded( *pPrevOp, true, *this, true) && + pPrevOp->GetFinalAxesValues( true, true, vAxVal)) { for ( int i = 0 ; i < nRotAxes ; ++ i) vAxRotPrec[i] = vAxVal[nLinAxes + i] ; } @@ -3119,7 +3127,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) } // *** Se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente - else if ( ! ToolChangeNeeded( *pPrevOp, *this)) { + else if ( ! ToolChangeNeeded( *pPrevOp, true, *this, true)) { // imposto l'utensile per i calcoli macchina if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) return false ; @@ -3128,7 +3136,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) // cancello eventuale risalita finale lavorazione precedente pPrevOp->RemoveRise() ; // recupero posizione finale lavorazione precedente - if ( ! pPrevOp->GetFinalAxesValues( false, vAxVal)) + if ( ! pPrevOp->GetFinalAxesValues( false, true, vAxVal)) return false ; // determinazione eventuale offset asse X (L1) al cambio di fase if ( ! SpecialPrevMachiningOffset( pPrevOp, dPrevOffsX)) @@ -3137,7 +3145,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) RemoveClimb() ; // recupero posizione iniziale lavorazione DBLVECTOR vAxIni ; - if ( ! GetInitialAxesValues( false, vAxIni)) + if ( ! GetInitialAxesValues( false, true, vAxIni)) return false ; // recupero se ZHome è in basso bool bZHomeDown = GetZHomeDown() ; @@ -3191,7 +3199,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) if ( TestCollisionAvoid( vAxVal2, dPrevOffsX, vAxMid2) && TestCollisionAvoid( vAxMid2, dPrevOffsX, vAxIni2) && pPrevOp->AddRise( vAxVal2) && - pPrevOp->AddSpecialRise( vAxMid2, true, GDB_ID_NULL, 5)) { + pPrevOp->AddSpecialRise( vAxMid2, true, GDB_ID_NULL, true, 5)) { vAxVal = vAxMid2 ; bMaxZ = true ; } @@ -3214,7 +3222,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) // cancello eventuale risalita parziale della lavorazione precedente pPrevOp->RemoveRise() ; // aggiungo risalita a HomeZ/MaxZ - if ( ! pPrevOp->AddRise( vAxVal, NAN, GDB_ID_NULL, 0)) + if ( ! pPrevOp->AddRise( vAxVal, NAN, GDB_ID_NULL, true, 0)) return false ; // si parte da Z massima bMaxZ = true ; @@ -3272,7 +3280,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) // cancello eventuale risalita parziale della lavorazione precedente pPrevOp->RemoveRise() ; // recupero le nuove quote finali (per calcolare il corretto delta) - pPrevOp->GetFinalAxesValues( false, vAxVal) ; + pPrevOp->GetFinalAxesValues( false, true, vAxVal) ; // aggiungo risalita a Zsafe double dDelta = ( ! bZHomeDown ? max( dSafeZ - vAxVal[2], 0.) : min( dSafeZ - vAxVal[2], 0.)) ; if ( ! pPrevOp->AddRise( vAxVal, dDelta)) @@ -3315,7 +3323,7 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) // altrimenti non richiesta verifica collegamento con lavorazione precedente else { // recupero posizione finale lavorazione precedente - if ( ! pPrevOp->GetFinalAxesValues( false, vAxVal)) + if ( ! pPrevOp->GetFinalAxesValues( false, true, vAxVal)) return false ; } } @@ -3380,6 +3388,345 @@ Operation::AdjustStartEndMovementsStd( bool bVerifyPreviousLink) return bOk ; } +//---------------------------------------------------------------------------- +bool +Operation::MoveHeadFromHomeToMach( bool bCurrMain, const string& sToolName, const string& sHeadName, int nExitNbr) +{ + // verifico gestore delle lavorazioni e operazione + if ( m_pMchMgr == nullptr) + return false ; + + // imposto l'utensile corrente + if ( ! m_pMchMgr->SetCalcTool( sToolName, sHeadName, nExitNbr)) + return false ; + + // sistemo approccio a Zmax + DBLVECTOR vAxVal ; + if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath( bCurrMain), GDB_ID_NULL, nullptr, vAxVal, 0, true)) + return false ; + // eseguo collegamento speciale + if ( ! ManageSpecialLink( nullptr, GDB_ID_NULL, false, this, GDB_ID_NULL, bCurrMain)) + return false ; + + // riporto l'utensile corrente come originale + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::MoveHeadFromMachToMach( Operation* pPrevOpe, + bool bPrevMain, const string& sPrevToolName, const string& sPrevHeadName, int nPrevExitNbr, + bool bCurrMain, const string& sCurrToolName, const string& sCurrHeadName, int nCurrExitNbr, + bool bToolChangeNeeded) +{ + // verifico gestore delle lavorazioni e operazione precedente + if ( m_pMchMgr == nullptr || pPrevOpe == nullptr) + return false ; + + // se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente + if ( ! bToolChangeNeeded) { + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( sCurrToolName, sCurrHeadName, nCurrExitNbr)) + return false ; + + // cancello eventuale risalita finale lavorazione precedente + pPrevOpe->RemoveRise( GDB_ID_NULL, bPrevMain) ; + // recupero posizione finale lavorazione precedente + DBLVECTOR vAxVal ; + if ( ! pPrevOpe->GetFinalAxesValues( false, bPrevMain, vAxVal)) + return false ; + // determinazione eventuale offset asse X (L1) al cambio di fase + double dPrevOffsX = 0 ; + if ( ! SpecialPrevMachiningOffset( pPrevOpe, dPrevOffsX)) + return false ; + // sistemo collegamento con lavorazione precedente ( senza passare per Zmax) + if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath( bCurrMain), GDB_ID_NULL, pPrevOpe, vAxVal, dPrevOffsX, false)) + return false ; + // gestione collegamento speciale + if ( ! ManageSpecialLink( pPrevOpe, GDB_ID_NULL, bPrevMain, this, GDB_ID_NULL, bCurrMain)) + return false ; + } + + // se utensile diverso, agiungo uscita per camvio utensile alla lavorazione precedente e parto da questa + else { + // imposto la lavorazione precedente come corrente ed effettuo collegamento + m_pMchMgr->SetCurrMachining( pPrevOpe->GetOwner()) ; + if ( ! MoveHeadFromMachToHome( pPrevOpe, bPrevMain, sPrevToolName, sPrevHeadName, nPrevExitNbr)) + return false ; + + // ripristino la lavorazione corrente ed effettuo collegamento + m_pMchMgr->SetCurrMachining( GetOwner()) ; + if ( ! MoveHeadFromHomeToMach( bCurrMain, sCurrToolName, sCurrHeadName, nCurrExitNbr)) + return false ; + } + + // riporto l'utensile corrente come originale + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::MoveHeadFromMachToHome( Operation* pPrevOpe, bool bPrevMain, const string& sPrevToolName, const string& sPrevHeadName, int nPrevExitNbr) +{ + // verifico gestore delle lavorazioni e operazione precedente + if ( m_pMchMgr == nullptr || pPrevOpe == nullptr) + return false ; + + // imposto l'utensile precedente per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( sPrevToolName, sPrevHeadName, nPrevExitNbr)) + return false ; + // ricalcolo risalita di lavorazione precedente (se già calcolata) + if ( pPrevOpe->RemoveRise( GDB_ID_NULL, bPrevMain)) { + DBLVECTOR vAxVal ; + if ( ! pPrevOpe->AddRise( vAxVal, NAN, GDB_ID_NULL, bPrevMain)) + return false ; + } + // eventuale rilascio utensile speciale di lavorazione precedente + if ( ! pPrevOpe->ManageSpecialLink( pPrevOpe, GDB_ID_NULL, bPrevMain, nullptr, GDB_ID_NULL, false)) + return false ; + + // riporto l'utensile corrente come originale + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::ManageDoubleOperNew( Operation* pPrevOpe) +{ + // recupero i dati della lavorazione precedente + string sPrevTool, sPrevHead ; int nPrevExitNbr ; + string sPrevDblTool, sPrevDblHead ; int nPrevDblExitNbr ; + bool bPrevInDouble = false ; + if ( pPrevOpe != nullptr && ! pPrevOpe->IsEmpty( NEED_ONE_TP_OK)) { + sPrevTool = pPrevOpe->GetToolName() ; + sPrevHead = pPrevOpe->GetHeadName() ; + nPrevExitNbr = pPrevOpe->GetExitNbr() ; + bPrevInDouble = ( pPrevOpe->GetFirstFullToolpath( false) != GDB_ID_NULL) ; + } + if ( bPrevInDouble) { + if ( ! pPrevOpe->GetDoubleToolData( sPrevDblTool, sPrevDblHead, nPrevDblExitNbr)) + return false ; + } + + // verifico se la lavorazione corrente è singola e in caso contrario recupero i dati della testa in doppio + string sCurrDblTool, sCurrDblHead ; int nCurrDblExitNbr ; + bool bCurrInDouble = ( GetFirstFullToolpath( false) != GDB_ID_NULL) ; + if ( bCurrInDouble) { + if ( ! GetDoubleToolData( sCurrDblTool, sCurrDblHead, nCurrDblExitNbr)) + return false ; + } + + // se nessuna delle due è un'Operazione in doppio, allora errore + if ( ! bPrevInDouble && ! bCurrInDouble) + return false ; + + // *** [A] Se primo utensile o richiesto, uso la posizione Home + if ( sPrevTool.empty() || NeedPrevHome()) { + // -->! la lavorazione corrente è per forza in doppio !<-- + // Dalla sua posizione di Home porto la Testa Main sul percorso Main corrente + if ( ! MoveHeadFromHomeToMach( true, GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + // Dalla sua posizione di Home porto da Testa Double sul percorso Double corrente + if ( ! MoveHeadFromHomeToMach( false, sCurrDblTool, sCurrDblHead, nCurrDblExitNbr)) + return false ; + } + else { + // *** [B] Se la lavorazione precedente è singola, allora la corrente in doppio + if ( ! bPrevInDouble) { + // -->! 1) Verifico se l'unico utensile della lavorazione precedente ( in quanto singola) è compatibile + // con l'Utensile presente sul percorso Main della lavorazione corrente ( in doppio) !<-- + if ( ! ToolChangeNeeded( *pPrevOpe, true, *this, true)) { + // Come prima cosa sposto la testa Main della prima lavorazione sul percorso Main della lavorazione corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), false)) + return false ; + // Successivamente porto la testa Double dalla sua Home alla lavorazione corrente ( in doppio) sul percorso + if ( ! MoveHeadFromHomeToMach( false, sCurrDblTool, sCurrDblHead, nCurrDblExitNbr)) + return false ; + } + // -->! 2) Verifico se l'unico utensile della lavorazione precedente ( in quanto singola) è compatibile + // con l'utensile presente sul percorso Double della lavorazione corrente ( in doppio) !<-- + else if ( ! ToolChangeNeeded( *pPrevOpe, true, *this, false)) { + // Come prima cosa sposto la testa Main della lavorazione precedente sul percorso Double della lavorazione corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + false, sCurrDblTool, sCurrDblHead, nCurrDblExitNbr, false)) + return false ; + // Successivamente porto la testa Main dalla sua Home alla lavorazione corrente ( in doppio) sul percorso + if ( ! MoveHeadFromHomeToMach( true, GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + } + // -->! 3) In questo caso l'unico utensile della lavorazione precedente ( in quanto singola) non è compatibile + // con nessun utensile della lavorazione corrente ( in doppio) !<-- + else { + // Porto la Testa Main sul percorso Main corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), true)) + return false ; + // Dalla sua posizione di Home porto da Testa Double sul percorso Double corrente + if ( ! MoveHeadFromHomeToMach( false, sCurrDblTool, sCurrDblHead, nCurrDblExitNbr)) + return false ; + } + } + // *** [C] se la lavorazione corrente è singola, allora la precedente è in doppio + else if ( ! bCurrInDouble) { + // -->! 1) Verifico se l'utensile principale della lavorazione precedente ( in doppio) è compatibile + // con l'Utensile presente sul percorso Main della lavorazione corrente ( in quanto singola) !<-- + if ( ! ToolChangeNeeded( *pPrevOpe, true, *this, true)) { + // Come prima cosa sposto la testa Double della lavorazione precedente ( in doppio) in Home + if ( ! MoveHeadFromMachToHome( pPrevOpe, false, sPrevDblTool, sPrevDblHead, nPrevDblExitNbr)) + return false ; + // Sposto al testa Main della lavorazione precedente sul percorso Main corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), false)) + return false ; + } + // -->! 2) Verifico se l'utensile secondario della lavorazione precedente ( in doppio) è compatibile + // con l'Utensile presente sul percorso Double della lavorazione corrente ( in quanto singola) !<-- + else if ( ! ToolChangeNeeded( *pPrevOpe, false, *this, true)) { + // Come prima cosa sposto la testa Main della lavorazione precedente ( in doppio) in Home + if ( ! MoveHeadFromMachToHome( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr)) + return false ; + // Sposto al testa Double della lavorazione precedente sul percorso corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, false, sPrevDblTool, sPrevDblHead, nPrevDblExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), false)) + return false ; + } + // -->! 3) In questo caso l'unico utensile della lavorazione corrente ( in quanto singola) non è compatibile + // con nessun utensile della lavorazione precedente ( in doppio) !<-- + else { + // Come prima cosa sposto la testa Double della lavorazione precedente ( in doppio) in Home + if ( ! MoveHeadFromMachToHome( pPrevOpe, false, sPrevDblTool, sPrevDblHead, nPrevDblExitNbr)) + return false ; + // Sposto la testa Main della lavorazione precedente sul percorso corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), true)) + return false ; + } + } + // *** [D] entrambe le lavorazioni sono in doppio + else { + // -->! 1) Entrambe le lavorazioni in doppio sono compatibili tra di loro !<-- + if ( ! ToolChangeNeeded( *pPrevOpe, true, *this, true) && ! ToolChangeNeeded( *pPrevOpe, false, *this, false)) { + // Porto la testa Main dalla lavorazione precedente alla lavorazione corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), false)) + return false ; + // Porto la testa double delle lavorazione precednete alla lavorazine corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, false, sPrevDblTool, sPrevDblHead, nPrevDblExitNbr, + false, sCurrDblTool, sCurrDblHead, nCurrDblExitNbr, false)) + return false ; + } + // -->! 2) Per tutto il resto porto sempre in Home per sicurezza passando da una lavorazione all'altra !<-- + else { + // Porto la testa Main dalla lavorazione precedente alla lavorazione corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, true, sPrevTool, sPrevHead, nPrevExitNbr, + true, GetToolName(), GetHeadName(), GetExitNbr(), true)) + return false ; + // Porto la testa Double delle lavorazione precedente alla lavorazine corrente + if ( ! MoveHeadFromMachToMach( pPrevOpe, false, sPrevDblTool, sPrevDblHead, nPrevDblExitNbr, + false, sCurrDblTool, sCurrDblHead, nCurrDblExitNbr, true)) + return false ; + } + } + } + + // -->! [E] aggiusto il collegamento iniziale di ogni percoso di lavoro successivo al primo. Per ogni Path all'interno + // del gruppo CL ( o DBL) corrente creo i link per questi percorsi. All'ultimo aggiungo aggiungo la Home !<-- + bool bOk = true ; + // 1) se lavorazione singola, allora tutti i Path sono singoli + if ( ! bCurrInDouble) { + int nPrevCLPathId = GetFirstFullToolpath() ; + int nCLPathId = GetNextFullToolpath( nPrevCLPathId) ; + while ( bOk && nCLPathId != GDB_ID_NULL) { + // -->! recupero i nuovi finali senza risalite !<-- + RemoveRise( nPrevCLPathId) ; + DBLVECTOR vAxVal ; + bOk = bOk && GetClPathFinalAxesValues( nPrevCLPathId, false, vAxVal) ; + bOk = bOk && AdjustOneStartEndMovement( nCLPathId, nPrevCLPathId, nullptr, vAxVal, 0, false) ; + bOk = bOk && ManageSpecialLink( this, nPrevCLPathId, true, this, nCLPathId, true) ; + // passo al successivo + nPrevCLPathId = nCLPathId ; + nCLPathId = GetNextFullToolpath( nCLPathId) ; + pPrevOpe = nullptr ; + } + // -->! aggiungo risalita finale !<-- + DBLVECTOR vAxVal ; + bOk = bOk && AddRise( vAxVal) ; + // -->! nuova verifica di aree protette alla fine !<-- + bOk = bOk && ManageSpecialLink( this, GDB_ID_NULL, true, nullptr, GDB_ID_NULL, false) ; + // -->! se ultima operazione o la successiva lo richiede, vado in Home !<-- + int nNextOpId = m_pMchMgr->GetNextActiveOperation( m_nOwnerId) ; + Operation* pNextOp = GetOperation( m_pGeomDB->GetUserObj( nNextOpId)) ; + if ( pNextOp == nullptr || pNextOp->NeedPrevHome() || + ( IsValidMachiningType( pNextOp->GetType()) && ! pNextOp->IsAtLeastOnePathOk())) + bOk = bOk && AddHome() ; + } + // 2) se lavorazione in doppio, allora scorro a coppie i Path nel CL e in DBL + else { + int nPrevCLPathId = GetFirstFullToolpath() ; + int nPrevDBLPathId = GetFirstFullToolpath( false) ; + int nCLPathId = GetNextFullToolpath( nPrevCLPathId) ; + int nDBLPathId = GetNextFullToolpath( nPrevDBLPathId, false) ; + while ( bOk && nCLPathId != GDB_ID_NULL && nDBLPathId != GDB_ID_NULL) { + // -->! recupero i nuovi finali senza risalite !<-- + RemoveRise( nCLPathId) ; + RemoveRise( nDBLPathId, false) ; + DBLVECTOR vAxVal ; + // Utensile Main + bOk = bOk && GetClPathFinalAxesValues( nPrevCLPathId, false, vAxVal) ; + bOk = bOk && AdjustOneStartEndMovement( nCLPathId, nPrevCLPathId, nullptr, vAxVal, 0, false) ; + bOk = bOk && ManageSpecialLink( this, nPrevCLPathId, true, this, nCLPathId, true) ; + // Utensile Double + DBLVECTOR vAxDblVal ; + bOk = bOk && m_pMchMgr->SetCalcTool( sCurrDblTool, sCurrDblHead, nCurrDblExitNbr) ; + bOk = bOk && GetClPathFinalAxesValues( nPrevDBLPathId, false, vAxDblVal) ; + bOk = bOk && AdjustOneStartEndMovement( nDBLPathId, nPrevDBLPathId, nullptr, vAxDblVal, 0, false) ; + bOk = bOk && ManageSpecialLink( this, nPrevDBLPathId, false, this, nDBLPathId, false) ; + bOk = bOk && m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr()) ; + // passo al successivo + nPrevCLPathId = nCLPathId ; + nPrevDBLPathId = nDBLPathId ; + nCLPathId = GetNextFullToolpath( nCLPathId) ; + nDBLPathId = GetNextFullToolpath( nDBLPathId, false) ; + pPrevOpe = nullptr ; + } + // -->! aggiungo risalita finale e nuova verifica di aree protette alla fine !<-- + // per utensile Main + DBLVECTOR vAxVal ; + bOk = bOk && AddRise( vAxVal) ; + bOk = bOk && ManageSpecialLink( this, GDB_ID_NULL, true, nullptr, GDB_ID_NULL, true) ; + // per utensile Double + DBLVECTOR vAxDblVal ; + bOk = bOk && m_pMchMgr->SetCalcTool( sCurrDblTool, sCurrDblHead, nCurrDblExitNbr) ; + bOk = bOk && AddRise( vAxDblVal, NAN, GDB_ID_NULL, false) ; + bOk = bOk && ManageSpecialLink( this, GDB_ID_NULL, false, nullptr, GDB_ID_NULL, false) ; + bOk = bOk && m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr()) ; + // -->! se ultima operazione o la successiva lo richiede, vado in Home !<-- + int nNextOpId = m_pMchMgr->GetNextActiveOperation( m_nOwnerId) ; + Operation* pNextOp = GetOperation( m_pGeomDB->GetUserObj( nNextOpId)) ; + if ( pNextOp == nullptr || pNextOp->NeedPrevHome() || + ( IsValidMachiningType( pNextOp->GetType()) && ! pNextOp->IsAtLeastOnePathOk())) { + // per utensile Main + bOk = bOk && AddHome() ; + // per utensile Double + bOk = bOk && m_pMchMgr->SetCalcTool( sCurrDblTool, sCurrDblHead, nCurrDblExitNbr) ; + bOk = bOk && AddHome( false) ; + bOk = bOk && m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr()) ; + } + } + + return bOk ; +} + //---------------------------------------------------------------------------- bool Operation::AdjustStartEndMovementsNew( void) @@ -3398,159 +3745,176 @@ Operation::AdjustStartEndMovementsNew( void) } // recupero l'utensile precedente string sPrevTool ; - if ( pPrevOp != nullptr && ! pPrevOp->IsEmpty( NEED_ONE_TP_OK)) + bool bPrevDbl = false ; + if ( pPrevOp != nullptr && ! pPrevOp->IsEmpty( NEED_ONE_TP_OK)) { sPrevTool = pPrevOp->GetToolName() ; - - // *** Se primo utensile o richiesto, uso la posizione home - if ( sPrevTool.empty() || NeedPrevHome()) { - // imposto l'utensile per i calcoli macchina - if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) - return false ; - // sistemo approccio da Zmax - DBLVECTOR vAxVal ; - if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath(), GDB_ID_NULL, nullptr, vAxVal, 0, true)) - return false ; - // eseguo collegamento speciale - if ( ! ManageSpecialLink( nullptr, GDB_ID_NULL, this, GDB_ID_NULL)) - return false ; + bPrevDbl = ( pPrevOp->GetFirstFullToolpath( false) != GDB_ID_NULL) ; } - // *** Se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente - else if ( ! ToolChangeNeeded( *pPrevOp, *this)) { - // imposto l'utensile per i calcoli macchina - if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) - return false ; - // cancello eventuale risalita finale lavorazione precedente - pPrevOp->RemoveRise() ; - // recupero posizione finale lavorazione precedente - DBLVECTOR vAxVal ; - if ( ! pPrevOp->GetFinalAxesValues( false, vAxVal)) - return false ; - // determinazione eventuale offset asse X (L1) al cambio di fase - double dPrevOffsX = 0 ; - if ( ! SpecialPrevMachiningOffset( pPrevOp, dPrevOffsX)) - return false ; - // sistemo collegamento con lavorazione precedente - if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath(), GDB_ID_NULL, pPrevOp, vAxVal, dPrevOffsX, false)) - return false ; - // gestione collegamento speciale - if ( ! ManageSpecialLink( pPrevOp, GDB_ID_NULL, this, GDB_ID_NULL)) - return false ; - } + // verifico se la lavorazione corrente è in doppio + bool bCurrDbl = ( GetFirstFullToolpath( false) != GDB_ID_NULL) ; - // *** Altrimenti aggiungo uscita per cambio utensile alla lavorazione precedente e parto da questa - else { - // imposto la lavorazione precedente come corrente - m_pMchMgr->SetCurrMachining( pPrevOp->GetOwner()) ; - // imposto l'utensile precedente per i calcoli macchina - if ( ! m_pMchMgr->SetCalcTool( pPrevOp->GetToolName(), pPrevOp->GetHeadName(), pPrevOp->GetExitNbr())) - return false ; - // ricalcolo risalita di lavorazione precedente (se già calcolata) - if ( pPrevOp->RemoveRise()) { + // -->! se entrambe le lavorazioni sono singole !<-- + if ( ! bPrevDbl && ! bCurrDbl) { + + // *** Se primo utensile o richiesto, uso la posizione home + if ( sPrevTool.empty() || NeedPrevHome()) { + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + // sistemo approccio da Zmax DBLVECTOR vAxVal ; - if ( ! pPrevOp->AddRise( vAxVal)) + if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath(), GDB_ID_NULL, nullptr, vAxVal, 0, true)) + return false ; + // eseguo collegamento speciale + if ( ! ManageSpecialLink( nullptr, GDB_ID_NULL, true, this, GDB_ID_NULL, true)) return false ; } - // eventuale rilascio utensile speciale di lavorazione precedente - if ( ! pPrevOp->ManageSpecialLink( pPrevOp, GDB_ID_NULL, nullptr, GDB_ID_NULL)) - return false ; - // ripristino la lavorazione corrente - m_pMchMgr->SetCurrMachining( GetOwner()) ; - // imposto l'utensile per i calcoli macchina - if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) - return false ; - // sistemo approccio da Zmax + // *** Se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente + else if ( ! ToolChangeNeeded( *pPrevOp, true, *this, true)) { + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + // cancello eventuale risalita finale lavorazione precedente + pPrevOp->RemoveRise() ; + // recupero posizione finale lavorazione precedente + DBLVECTOR vAxVal ; + if ( ! pPrevOp->GetFinalAxesValues( false, true, vAxVal)) + return false ; + // determinazione eventuale offset asse X (L1) al cambio di fase + double dPrevOffsX = 0 ; + if ( ! SpecialPrevMachiningOffset( pPrevOp, dPrevOffsX)) + return false ; + // sistemo collegamento con lavorazione precedente + if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath(), GDB_ID_NULL, pPrevOp, vAxVal, dPrevOffsX, false)) + return false ; + // gestione collegamento speciale + if ( ! ManageSpecialLink( pPrevOp, GDB_ID_NULL, true, this, GDB_ID_NULL, true)) + return false ; + } + + // *** Altrimenti aggiungo uscita per cambio utensile alla lavorazione precedente e parto da questa + else { + // imposto la lavorazione precedente come corrente + m_pMchMgr->SetCurrMachining( pPrevOp->GetOwner()) ; + // imposto l'utensile precedente per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( pPrevOp->GetToolName(), pPrevOp->GetHeadName(), pPrevOp->GetExitNbr())) + return false ; + // ricalcolo risalita di lavorazione precedente (se già calcolata) + if ( pPrevOp->RemoveRise()) { + DBLVECTOR vAxVal ; + if ( ! pPrevOp->AddRise( vAxVal)) + return false ; + } + // eventuale rilascio utensile speciale di lavorazione precedente + if ( ! pPrevOp->ManageSpecialLink( pPrevOp, GDB_ID_NULL, true, nullptr, GDB_ID_NULL, true)) + return false ; + + // ripristino la lavorazione corrente + m_pMchMgr->SetCurrMachining( GetOwner()) ; + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + // sistemo approccio da Zmax + DBLVECTOR vAxVal ; + if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath(), GDB_ID_NULL, nullptr, vAxVal, 0, true)) + return false ; + // eseguo verifica + if ( ! ManageSpecialLink( nullptr, GDB_ID_NULL, true, this, GDB_ID_NULL, true)) + return false ; + } + + // aggiusto il collegamento iniziale di ogni percorso di lavoro successivo al primo + bool bOk = true ; + int nPrevClPathId = GetFirstFullToolpath() ; + int nClPathId = GetNextFullToolpath( nPrevClPathId) ; + while ( bOk && nClPathId != GDB_ID_NULL) { + // recupero nuovi finali senza risalite + RemoveRise( nPrevClPathId) ; + DBLVECTOR vAxVal ; + if ( ! GetClPathFinalAxesValues( nPrevClPathId, false, vAxVal)) + bOk = false ; + // sistemo collegamento con precedente + if ( ! AdjustOneStartEndMovement( nClPathId, nPrevClPathId, nullptr, vAxVal, 0, false)) + bOk = false ; + // gestione collegamento speciale ( tra due percorsi della stessa lavorazione) + if ( ! ManageSpecialLink( this, nPrevClPathId, true, this, nClPathId, true)) + return false ; + // passo al successivo + nPrevClPathId = nClPathId ; + nClPathId = GetNextFullToolpath( nClPathId) ; + pPrevOp = nullptr ; + } + + // Aggiungo risalita finale DBLVECTOR vAxVal ; - if ( ! AdjustOneStartEndMovement( GetFirstFullToolpath(), GDB_ID_NULL, nullptr, vAxVal, 0, true)) - return false ; - // eseguo verifica - if ( ! ManageSpecialLink( nullptr, GDB_ID_NULL, this, GDB_ID_NULL)) + bOk = bOk && AddRise( vAxVal) ; + // nuova verifica aree protette alla fine + if ( ! ManageSpecialLink( this, GDB_ID_NULL, true, nullptr, GDB_ID_NULL, true)) return false ; + + // se ultima operazione o la successiva lo richiede, vado in home + int nNextOpId = m_pMchMgr->GetNextActiveOperation( m_nOwnerId) ; + Operation* pNextOp = GetOperation( m_pGeomDB->GetUserObj( nNextOpId)) ; + if ( pNextOp == nullptr || pNextOp->NeedPrevHome() || + ( IsValidMachiningType( pNextOp->GetType()) && ! pNextOp->IsAtLeastOnePathOk())) + bOk = bOk && AddHome() ; + + return bOk ; + } - - // aggiusto il collegamento iniziale di ogni percorso di lavoro successivo al primo - bool bOk = true ; - int nPrevClPathId = GetFirstFullToolpath() ; - int nClPathId = GetNextFullToolpath( nPrevClPathId) ; - while ( bOk && nClPathId != GDB_ID_NULL) { - // recupero nuovi finali senza risalite - RemoveRise( nPrevClPathId) ; - DBLVECTOR vAxVal ; - if ( ! GetClPathFinalAxesValues( nPrevClPathId, false, vAxVal)) - bOk = false ; - // sistemo collegamento con precedente - if ( ! AdjustOneStartEndMovement( nClPathId, nPrevClPathId, nullptr, vAxVal, 0, false)) - bOk = false ; - // gestione collegamento speciale ( tra due percorsi della stessa lavorazione) - if ( ! ManageSpecialLink( this, nPrevClPathId, this, nClPathId)) - return false ; - // passo al successivo - nPrevClPathId = nClPathId ; - nClPathId = GetNextFullToolpath( nClPathId) ; - pPrevOp = nullptr ; - } - - // Aggiungo risalita finale - DBLVECTOR vAxVal ; - bOk = bOk && AddRise( vAxVal) ; - // nuova verifica aree protette alla fine - if ( ! ManageSpecialLink( this, GDB_ID_NULL, nullptr, GDB_ID_NULL)) - return false ; - - // se ultima operazione o la successiva lo richiede, vado in home - int nNextOpId = m_pMchMgr->GetNextActiveOperation( m_nOwnerId) ; - Operation* pNextOp = GetOperation( m_pGeomDB->GetUserObj( nNextOpId)) ; - if ( pNextOp == nullptr || pNextOp->NeedPrevHome() || - ( IsValidMachiningType( pNextOp->GetType()) && ! pNextOp->IsAtLeastOnePathOk())) - bOk = bOk && AddHome() ; - - return bOk ; + // -->! se presenza di una lavorazione in doppio !<-- + else + return ( ManageDoubleOperNew( pPrevOp)) ; } //---------------------------------------------------------------------------- bool -Operation::ManageSpecialLink( Operation* pPrevOpe, int nPrevClPathId, Operation* pNextOpe, int nNextClPathId) +Operation::ManageSpecialLink( Operation* pPrevOpe, int nPrevClPathId, bool bPrevMain, Operation* pNextOpe, int nNextClPathId, bool bNextMain) { // controlli if ( pPrevOpe == nullptr && pNextOpe == nullptr) return false ; - // codifica tipo di collegamento + // codifica tipo di collegamento ( 1, 2 o 3) int nLinkType = ( pPrevOpe != nullptr ? 2 : 0) + ( pNextOpe != nullptr ? 1 : 0) ; // assegno valori assi iniziali e finali, depurati di approcci/retrazioni aggiuntive (CLIMB e RISE) in area protetta DBLVECTOR vAxSta, vNeatAxSta ; if ( pPrevOpe != nullptr) { if ( nPrevClPathId == GDB_ID_NULL) { - pPrevOpe->GetFinalAxesValues( false, vAxSta) ; - pPrevOpe->GetFinalAxesValues( true, vNeatAxSta) ; + pPrevOpe->GetFinalAxesValues( false, bPrevMain, vAxSta) ; + pPrevOpe->GetFinalAxesValues( true, bPrevMain, vNeatAxSta) ; } else { - pPrevOpe->GetClPathFinalAxesValues( nPrevClPathId, false, vAxSta) ; - pPrevOpe->GetClPathFinalAxesValues( nPrevClPathId, true, vNeatAxSta) ; + pPrevOpe->GetClPathFinalAxesValues( nPrevClPathId, false, vAxSta) ; // dall'Id ricavo già se main o double + pPrevOpe->GetClPathFinalAxesValues( nPrevClPathId, true, vNeatAxSta) ; // dall'Id ricavo già se main o double } } else m_pMchMgr->GetAllCurrAxesHomePos( vNeatAxSta) ; + DBLVECTOR vAxEnd, vNeatAxEnd ; if ( pNextOpe != nullptr) { if ( nNextClPathId == GDB_ID_NULL) { - pNextOpe->GetInitialAxesValues( false, vAxEnd) ; - pNextOpe->GetInitialAxesValues( true, vNeatAxEnd) ; + pNextOpe->GetInitialAxesValues( false, bNextMain, vAxEnd) ; + pNextOpe->GetInitialAxesValues( true, bNextMain, vNeatAxEnd) ; } else { - pNextOpe->GetClPathInitialAxesValues( nNextClPathId, false, vAxEnd) ; - pNextOpe->GetClPathInitialAxesValues( nNextClPathId, true, vNeatAxEnd) ; + pNextOpe->GetClPathInitialAxesValues( nNextClPathId, false, vAxEnd) ; // dall'Id ricavo già se main o double + pNextOpe->GetClPathInitialAxesValues( nNextClPathId, true, vNeatAxEnd) ; // dall'Id ricavo già se main o double } } else m_pMchMgr->GetAllCurrAxesHomePos( vNeatAxEnd) ; - if ( vNeatAxSta.size() != vNeatAxEnd.size()) + + // verifico coerenza assi + if ( ssize( vNeatAxSta) != ssize( vNeatAxEnd)) return false ; // chiamo funzione script OnSpecialRapidMove per avere posizioni di movimento - bool bOk = SpecialLink( vNeatAxSta, vNeatAxEnd, nLinkType, pPrevOpe, pNextOpe) ; + bool bOk = SpecialLink( vNeatAxSta, vNeatAxEnd, nLinkType, pPrevOpe, bPrevMain, pNextOpe, bNextMain) ; // in caso di errore eseguo inserimento con segnalazione di errore if ( ! bOk) { @@ -3569,13 +3933,19 @@ bool Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operation* pPrevOp, const DBLVECTOR& vAxPrev, double dPrevOffsX, bool bMaxZ) { + // verifico gestore delle lavorazione, DB geometrico e macchina corrente if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; Machine* pMch = m_pMchMgr->GetCurrMachine() ; if ( pMch == nullptr) return false ; + // dagli Id dei Path verifico se è Main o Double + string sCLName ; m_pGeomDB->GetName( m_pGeomDB->GetParentId( nClPathId), sCLName) ; + bool bMain = ( ! EqualNoCase( sCLName, MCH_DBL)) ; + string sCLPrevName ; m_pGeomDB->GetName( m_pGeomDB->GetParentId( nPrevClPathId), sCLPrevName) ; + bool bPrevMain = ( ! EqualNoCase( sCLPrevName, MCH_DBL)) ; // elimino eventuali CLIMB già presenti - RemoveClimb( nClPathId) ; + RemoveClimb( nClPathId, bMain) ; // recupero la prima entità di questo percorso int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; // recupero i dati Cam dell'entità @@ -3705,17 +4075,17 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio // risalita sopra fine percorso precedente DBLVECTOR vAxNew1 ; if ( nPrevClPathId == GDB_ID_NULL) { - if ( pPrevOp == nullptr || ! pPrevOp->RemoveRise()) + if ( pPrevOp == nullptr || ! pPrevOp->RemoveRise( GDB_ID_NULL, bPrevMain)) return false ; DBLVECTOR vAxPrevNoRise ; - pPrevOp->GetFinalAxesValues( false, vAxPrevNoRise) ; + pPrevOp->GetFinalAxesValues( false, bPrevMain, vAxPrevNoRise) ; double dDelta = ( ! bZHomeDown ? max( dSafeZ - vAxPrevNoRise[2], 0.) : min( dSafeZ - vAxPrevNoRise[2], 0.)) ; - if ( ! pPrevOp->AddRise( vAxNew1, dDelta)) + if ( ! pPrevOp->AddRise( vAxNew1, dDelta, GDB_ID_NULL, bPrevMain)) return false ; } else { double dDelta = ( ! bZHomeDown ? max( dSafeZ - vAxPrev[2], 0.) : min( dSafeZ - vAxPrev[2], 0.)) ; - if ( ! AddRise( vAxNew1, dDelta, nPrevClPathId)) + if ( ! pPrevOp->AddRise( vAxNew1, dDelta, nPrevClPathId, bPrevMain)) return false ; } // aggiungo posizione elevata prima dell'inizio del percorso corrente @@ -3773,11 +4143,11 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio if ( pPrevOp == nullptr) return false ; // se non presente risalita finale - if ( m_pGeomDB->GetFirstNameInGroup( pPrevOp->GetLastFullToolpath(), MCH_CL_RISE) == GDB_ID_NULL) { + if ( m_pGeomDB->GetFirstNameInGroup( pPrevOp->GetLastFullToolpath( bPrevMain), MCH_CL_RISE) == GDB_ID_NULL) { // la aggiungo DBLVECTOR vAxNew ; double dDelta = ( ! bZHomeDown ? max( vAxCurr[2] - vAxPrev[2], 0.) : min( vAxCurr[2] - vAxPrev[2], 0.)) ; - if ( ! pPrevOp->AddRise( vAxNew, dDelta, GDB_ID_NULL)) + if ( ! pPrevOp->AddRise( vAxNew, dDelta, GDB_ID_NULL, bPrevMain)) return false ; } } @@ -3786,7 +4156,7 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio // aggiungo risalita alla fine del precedente percorso DBLVECTOR vAxNew ; double dDelta = ( ! bZHomeDown ? max( vAxCurr[2] - vAxPrev[2], 0.) : min( vAxCurr[2] - vAxPrev[2], 0.)) ; - if ( ! AddRise( vAxNew, dDelta, nPrevClPathId)) + if ( ! pPrevOp->AddRise( vAxNew, dDelta, nPrevClPathId, bPrevMain)) return false ; } } @@ -3904,7 +4274,7 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio return false ; // aggiungo risalita a Z opportuna alla fine del percorso precedente DBLVECTOR vAxNew = vAxPrev ; - if ( ! pPrevOp->AddRise( vAxNew, ptPStart.z - ptPEnd.z)) + if ( ! pPrevOp->AddRise( vAxNew, ptPStart.z - ptPEnd.z, GDB_ID_NULL, bPrevMain)) return false ; } // altrimenti precedente appartiene alla stessa operazione @@ -3912,7 +4282,7 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio // eventuali risalite finali già eliminate dal chiamante // aggiungo risalita a Z opportuna alla fine del percorso precedente DBLVECTOR vAxNew = vAxPrev ; - if ( ! AddRise( vAxNew, ptPStart.z - ptPEnd.z, nPrevClPathId)) + if ( ! AddRise( vAxNew, ptPStart.z - ptPEnd.z, nPrevClPathId, bPrevMain)) return false ; } } @@ -3933,7 +4303,7 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio return false ; // aggiungo risalita a Z max alla fine della lavorazione precedente DBLVECTOR vAxNew = vAxPrev ; - if ( ! pPrevOp->AddRise( vAxNew)) + if ( ! pPrevOp->AddRise( vAxNew, NAN, GDB_ID_NULL, bPrevMain)) return false ; } // altrimenti precedente appartiene alla stessa operazione @@ -3941,7 +4311,7 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio // eventuali risalite finali già eliminate dal chiamante // aggiungo risalita a Z max alla fine del percorso precedente DBLVECTOR vAxNew = vAxPrev ; - if ( ! AddRise( vAxNew, NAN, nPrevClPathId)) + if ( ! AddRise( vAxNew, NAN, nPrevClPathId, bPrevMain)) return false ; } // inserisco la posizione iniziale a Zmax in questo percorso @@ -3956,19 +4326,61 @@ Operation::AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operatio //---------------------------------------------------------------------------- bool -Operation::ToolChangeNeeded( const Operation& Ope1, const Operation& Ope2) const +Operation::ToolChangeNeeded( const Operation& Ope1, bool bMain1, const Operation& Ope2, bool bMain2) const { - // se non cambia l'utensile, non cambia la testa fisica - if ( EqualNoCase( Ope1.GetToolName(), Ope2.GetToolName())) - return false ; - // se non hanno TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica - if ( Ope1.GetToolTcPos().empty() && Ope2.GetToolTcPos().empty() && - EqualNoCase( Ope1.GetHeadName(), Ope2.GetHeadName()) && Ope1.GetExitNbr() != Ope2.GetExitNbr()) - return false ; - // se hanno lo stesso TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica - if ( EqualNoCase( Ope1.GetToolTcPos(), Ope2.GetToolTcPos()) && - EqualNoCase( Ope1.GetHeadName(), Ope2.GetHeadName()) && Ope1.GetExitNbr() != Ope2.GetExitNbr()) - return false ; + // se confronto con gli utensili principali + if ( bMain1 && bMain2) { + // se non cambia l'utensile, non cambia la testa fisica + if ( EqualNoCase( Ope1.GetToolName(), Ope2.GetToolName())) + return false ; + // se stanno sulla stessa testa e non è la stessa uscita, non cambia la testa fisica + if ( EqualNoCase( Ope1.GetHeadName(), Ope2.GetHeadName()) && Ope1.GetExitNbr() != Ope2.GetExitNbr()) + return false ; + } + // se confronto il principale di Ope1 con il secondario di Ope2 + else if ( bMain1 && ! bMain2) { + // verifico che la seconda operazione sia in doppio + string sDblTool2, sDblHead2 ; + int nDblExitNbr2 ; + if ( ! Ope2.GetDoubleToolData( sDblTool2, sDblHead2, nDblExitNbr2)) + return true ; + // se non cambia l'utensile, non cambia la testa fisica + if ( EqualNoCase( Ope1.GetToolName(), sDblTool2)) + return false ; + // se stanno sulla stessa testa e non è la stessa uscita, non cambia la testa fisica + if ( EqualNoCase( Ope1.GetHeadName(), sDblHead2) && Ope1.GetExitNbr() != nDblExitNbr2) + return false ; + } + // se confronto il secondario di Ope1 con il principale di Ope2 + else if ( ! bMain1 && bMain2) { + // verifico che la prima operazione sia in doppio + string sDblTool1, sDblHead1 ; + int nDblExitNbr1 ; + if ( ! Ope1.GetDoubleToolData( sDblTool1, sDblHead1, nDblExitNbr1)) + return true ; + // se non cambia l'utensile, non cambia la testa fisica + if ( EqualNoCase( sDblTool1, Ope2.GetToolName())) + return false ; + // se stanno sulla stessa testa e non è la stessa uscita, non cambia la testa fisica + if ( EqualNoCase( sDblHead1, Ope2.GetHeadName()) && nDblExitNbr1 != Ope2.GetExitNbr()) + return false ; + } + // se confronto utensili secondari + else { + // verifico che le due lavorazioni siano in doppio + string sDblTool1, sDblTool2, sDblHead1, sDblHead2 ; + int nDblExitNbr1, nDblExitNbr2 ; + if ( ! Ope1.GetDoubleToolData( sDblTool1, sDblHead1, nDblExitNbr1) || + ! Ope2.GetDoubleToolData( sDblTool2, sDblHead2, nDblExitNbr2)) + return true ; + // se non cambia l'utensile, non cambia la testa fisica + if ( EqualNoCase( sDblTool1, sDblTool2)) + return false ; + // se stanno sulla stessa testa e non è la stessa uscita, non cambia la testa fisica + if ( EqualNoCase( sDblHead1, sDblHead2) && nDblExitNbr1 != nDblExitNbr2) + return false ; + } + // altrimenti necessario un cambio return true ; } @@ -3976,20 +4388,20 @@ Operation::ToolChangeNeeded( const Operation& Ope1, const Operation& Ope2) const //---------------------------------------------------------------------------- // Inserisce sempre prima della prima entità del percorso ( se bFirst falso dopo tutti i Climb già inseriti) bool -Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, +Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, bool bMain, int nFlag, int nFlag2, int nMask, const string& sInfo, bool bFirst) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // se percorso CL specificato, verifico appartenga al gruppo della geometria di lavorazione (Cutter Location) if ( nClPathId != GDB_ID_NULL) { - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL || m_pGeomDB->GetParentId( nClPathId) != nClId) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), ( bMain ? MCH_CL : MCH_DBL)) ; + if ( nClId == GDB_ID_NULL || m_pGeomDB->GetParentId( nClPathId) != nClId) return false ; } // altrimenti, recupero il primo percorso CL non vuoto della operazione else { - nClPathId = GetFirstFullToolpath() ; + nClPathId = GetFirstFullToolpath( bMain) ; if ( nClPathId == GDB_ID_NULL) return false ; } @@ -4007,8 +4419,8 @@ Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, if ( pCamData == nullptr) return false ; // verifico che il numero di valori sia corretto - int nValCnt = int( vAxVal.size()) ; - int nAxesCnt = int( pCamData->GetAxesVal().size()) ; + int nValCnt = ssize( vAxVal) ; + int nAxesCnt = ssize( pCamData->GetAxesVal()) ; if ( nValCnt != nAxesCnt) { string sOut = "Error : " + ToString( nValCnt) + " values vs " + ToString( nAxesCnt) + " axes" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) @@ -4107,19 +4519,19 @@ Operation::RemoveClimb( int nClPathId, bool bMain) //---------------------------------------------------------------------------- bool -Operation::AddRise( DBLVECTOR& vAxVal, double dDelta, int nClPathId, int nToMinMaxZ) +Operation::AddRise( DBLVECTOR& vAxVal, double dDelta, int nClPathId, bool bMain, int nToMinMaxZ) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // se percorso CL specificato, verifico appartenga al gruppo della geometria di lavorazione (Cutter Location) if ( nClPathId != GDB_ID_NULL) { - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), ( bMain ? MCH_CL : MCH_DBL)) ; if ( nClId == GDB_ID_NULL || m_pGeomDB->GetParentId( nClPathId) != nClId) return false ; } // altrimenti, recupero l'ultimo percorso CL non vuoto della operazione else { - nClPathId = GetLastFullToolpath() ; + nClPathId = GetLastFullToolpath( bMain) ; if ( nClPathId == GDB_ID_NULL) return false ; } @@ -4268,20 +4680,20 @@ Operation::AddRise( DBLVECTOR& vAxVal, double dDelta, int nClPathId, int nToMinM //---------------------------------------------------------------------------- // Inserisce sempre dopo l'ultima entità del percorso bool -Operation::AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, +Operation::AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, bool bMain, int nFlag, int nFlag2, int nMask, const string& sInfo) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // se percorso CL specificato, verifico appartenga al gruppo della geometria di lavorazione (Cutter Location) if ( nClPathId != GDB_ID_NULL) { - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), ( bMain ? MCH_CL : MCH_DBL)) ; if ( nClId == GDB_ID_NULL || m_pGeomDB->GetParentId( nClPathId) != nClId) return false ; } // altrimenti, recupero l'ultimo percorso CL non vuoto della operazione else { - nClPathId = GetLastFullToolpath() ; + nClPathId = GetLastFullToolpath( bMain) ; if ( nClPathId == GDB_ID_NULL) return false ; } @@ -4294,8 +4706,8 @@ Operation::AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, if ( pCamData == nullptr) return false ; // verifico che il numero di valori sia corretto - int nValCnt = int( vAxVal.size()) ; - int nAxesCnt = int( pCamData->GetAxesVal().size()) ; + int nValCnt = ssize( vAxVal) ; + int nAxesCnt = ssize( pCamData->GetAxesVal()) ; if ( nValCnt != nAxesCnt) { string sOut = "Error : " + ToString( nValCnt) + " values vs " + ToString( nAxesCnt) + " axes" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) @@ -4401,12 +4813,12 @@ Operation::RemoveRise( int nClPathId, bool bMain) //---------------------------------------------------------------------------- bool -Operation::AddHome( void) +Operation::AddHome( bool bMain) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // recupero l'ultimo percorso CL non vuoto - int nLastPxClId = GetLastFullToolpath() ; + int nLastPxClId = GetLastFullToolpath( bMain) ; if ( nLastPxClId == GDB_ID_NULL) return false ; // recupero l'ultima entità del percorso di nome RISE @@ -4450,12 +4862,12 @@ Operation::AddHome( void) //---------------------------------------------------------------------------- bool -Operation::RemoveHome( void) +Operation::RemoveHome( bool bMain) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // recupero l'ultimo percorso CL non vuoto - int nClPathId = GetLastFullToolpath() ; + int nClPathId = GetLastFullToolpath( bMain) ; if ( nClPathId == GDB_ID_NULL) return false ; // elimino tutte le entità HOME alla fine del percorso @@ -4503,11 +4915,12 @@ Operation::AddRobotClimb( int nEntId, double dDeltaZ) if ( dNewDeltaZ < 100 * EPS_SMALL) return true ; // copio l'entità - if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL) + int nNewEntId = m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_BEFORE) ; + if ( nNewEntId == GDB_ID_NULL) return false ; // modifico quella originale (è la prima del percorso) - m_pGeomDB->SetName( nEntId, MCH_CL_CLIMB) ; - m_pGeomDB->RemoveInfo( nEntId, KEY_CL_DOUBLE) ; + m_pGeomDB->SetName( nNewEntId, MCH_CL_CLIMB) ; + m_pGeomDB->RemoveInfo( nNewEntId, KEY_CL_DOUBLE) ; pCdEnt->SetAxes( CamData::AS_OK, vAxClimb) ; pCdEnt->SetFlag( 2) ; pCdEnt->SetFlag2( ( bZmax ? 1 : 0)) ; @@ -5487,7 +5900,7 @@ Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, //---------------------------------------------------------------------------- bool Operation::SpecialLink( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int nLinkType, - const Operation* pPrevOpe, const Operation* pNextOpe) + const Operation* pPrevOpe, bool bPrevMain, const Operation* pNextOpe, bool bNextMain) { // recupero la macchina corrente Machine* pMch = ( m_pMchMgr != nullptr ? m_pMchMgr->GetCurrMachine() : nullptr) ; @@ -5497,8 +5910,10 @@ Operation::SpecialLink( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo static const string EVAR_PREVMCHID = ".PREVMCHID" ; // IN (int) identificativo lavorazione precedente static const string EVAR_PREVPHASE = ".PREVPHASE" ; // IN (int) indice fase della lavorazione precedente + static const string EVAR_PREVMAIN = ".PREVMAIN" ; // IN (bool) flag lavorazione principale o double precedente static const string EVAR_NEXTMCHID = ".NEXTMCHID" ; // IN (int) identificativo lavorazione successiva static const string EVAR_NEXTPHASE = ".NEXTPHASE" ; // IN (int) indice fase della lavorazione successiva + static const string EVAR_NEXTMAIN = ".NEXTMAIN" ; // IN (bool) flag lavorazione principale o double successiva static const string EVAR_LINKTYPE = ".LINKTYPE" ; // IN (int) codice tipo collegamento (1=Inizio, 2=Fine, 3=FinePrec+InizioSucc) static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) static const string ON_SPECIAL_LINK = "OnSpecialLink" ; @@ -5517,14 +5932,16 @@ Operation::SpecialLink( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + GVAR_EXIT, GetExitNbr()) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + GVAR_TCPOS, GetToolTcPos()) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_PREVMCHID, ( pPrevOpe != nullptr ? pPrevOpe->GetOwner() : GDB_ID_NULL)) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_PREVMAIN, ( bPrevMain ? MCH_CL : MCH_DBL)) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_PREVPHASE, ( pPrevOpe != nullptr ? pPrevOpe->m_nPhase : 0)) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_NEXTMCHID, ( pNextOpe != nullptr ? pNextOpe->GetOwner() : GDB_ID_NULL)) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_NEXTPHASE, ( pNextOpe != nullptr ? pNextOpe->m_nPhase : 0)) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_NEXTMAIN, ( bNextMain ? MCH_CL : MCH_DBL)) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + GVAR_PHASE, m_nPhase) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_LINKTYPE, nLinkType) ; // valore degli assi bool bIsRobot = m_pMchMgr->GetCurrIsRobot() ; - int nNumAxes = int( vAxStart.size()) ; + int nNumAxes = ssize( vAxStart) ; for ( int i = 1 ; i <= nNumAxes ; ++ i) bOk = bOk && pMch->LuaSetGlobVar( GetGlobVarAxisPrev( i, EMC_VAR, bIsRobot), vAxStart[i-1]) ; for ( int i = 1 ; i <= nNumAxes ; ++ i) diff --git a/Operation.h b/Operation.h index 4b7a19b..75c0ce2 100644 --- a/Operation.h +++ b/Operation.h @@ -45,7 +45,7 @@ class Operation : public IUserObj { m_nPhase = nPhase ; return true ; } virtual int GetPhase( void) const { return m_nPhase ; } - virtual bool RemoveHome( void) ; + virtual bool RemoveHome( bool bMain = true) ; std::string GetName( void) const ; public : @@ -54,8 +54,8 @@ class Operation : public IUserObj virtual bool UpdateStatus( int nModif) = 0 ; public : - bool GetInitialAxesValues( bool bSkipClimb, DBLVECTOR& vAxVal) const ; - bool GetFinalAxesValues( bool bSkipRise, DBLVECTOR& vAxVal) const ; + bool GetInitialAxesValues( bool bSkipClimb, bool bMain, DBLVECTOR& vAxVal) const ; + bool GetFinalAxesValues( bool bSkipRise, bool bMain, DBLVECTOR& vAxVal) const ; protected : virtual const std::string& GetToolName( void) const = 0 ; @@ -63,6 +63,7 @@ class Operation : public IUserObj virtual int GetExitNbr( void) const = 0 ; virtual int GetSolCh( void) const = 0 ; virtual const std::string& GetToolTcPos( void) const = 0 ; + virtual bool GetDoubleToolData( std::string& sDblTool, std::string& sDblHead, int& nDblExit) const = 0 ; virtual bool NeedPrevHome( void) const = 0 ; virtual bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) const { return true ; } @@ -125,9 +126,9 @@ class Operation : public IUserObj bool AreAllPathsOk( void) const ; bool GetToolpathsStatus( int& nCnt, int& nEmpty) const ; int GetFirstFullToolpath( bool bMain = true) const ; - int GetNextFullToolpath( int nClPathId) const ; + int GetNextFullToolpath( int nClPathId, bool bMain = true) const ; int GetLastFullToolpath( bool bMain = true) const ; - int GetPrevFullToolpath( int nClPathId) const ; + int GetPrevFullToolpath( int nClPathId, bool bMain = true) const ; bool UpdateFollowingOperationsStatus( int nModif) ; bool GetElevation( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dElev) const ; @@ -208,9 +209,9 @@ class Operation : public IUserObj bool GetClPathInitialToolDir( int nClPathId, bool bSkipClimb, Vector3d& vtTool) const ; bool GetFinalToolDir( bool bSkipRise, Vector3d& vtTool) const ; bool GetClPathFinalToolDir( int nClPathId, bool bSkipRise, Vector3d& vtTool) const ; - const CamData* GetInitialCamData( bool bSkipClimb) const ; + const CamData* GetInitialCamData( bool bSkipClimb, bool bMain = true) const ; const CamData* GetClPathInitialCamData( int nClPathId, bool bSkipClimb) const ; - const CamData* GetFinalCamData( bool bSkipRise) const ; + const CamData* GetFinalCamData( bool bSkipRise, bool bMain = true) const ; const CamData* GetClPathFinalCamData( int nClPathId, bool bSkipRise) const ; bool ApplyHintToPrevAxRot( const std::string& sHint, const Machine* pMch, DBLVECTOR& vAxRotPrec) ; bool CalculateClPathMcentAxesValues( int nClPathId, double dAngDeltaMinForHome, const DBLVECTOR& vAxRotHome, @@ -239,16 +240,25 @@ class Operation : public IUserObj bool AdjustStartEndMovementsStd( bool bVerifyPreviousLink) ; bool AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operation* pPrevOpe, const DBLVECTOR& vAxPrev, double dPrevOffsX, bool bMaxZ) ; bool AdjustStartEndMovementsNew( void) ; - bool ManageSpecialLink( Operation* pPrevOpe, int nPrevClPathId, Operation* pNextOpe, int nNextClPathId) ; - bool ToolChangeNeeded( const Operation& Ope1, const Operation& Ope2) const ; - bool AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk = true, int nClPathId = GDB_ID_NULL, + + bool MoveHeadFromHomeToMach( bool bMain, const std::string& sToolName, const std::string& sHeadName, int nExitNbr) ; + bool MoveHeadFromMachToMach( Operation* pPrevOpe, + bool bPrevMain, const std::string& sPrevToolName, const std::string& sPrevHeadName, int nPrevExitNbr, + bool bCurrMain, const std::string& sCurrToolName, const std::string& sCurrHeadName, int nCurrExitNbr, + bool bToolChange) ; + bool MoveHeadFromMachToHome( Operation* pPrevOpe, bool bCurrMain, const std::string& sCurrToolName, const std::string& sCurrHeadName, int nCurrExitNbr) ; + bool ManageDoubleOperNew( Operation* pPrevOpe) ; + + bool ManageSpecialLink( Operation* pPrevOpe, int nPrevClPathId, bool bPrevMain, Operation* pNextOpe, int nNextClPathId, bool bNextMain) ; + bool ToolChangeNeeded( const Operation& Ope1, bool bMain1, const Operation& Ope2, bool bMain2) const ; + bool AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk = true, int nClPathId = GDB_ID_NULL, bool bMain = true, int nFlag = 0, int nFlag2 = 0, int nMask = -1, const std::string& sInfo = "", bool bFirst = true) ; bool RemoveClimb( int nClPathId = GDB_ID_NULL, bool bMain = true) ; - bool AddRise( DBLVECTOR& vAxVal, double dDelta = NAN, int nClPathId = GDB_ID_NULL, int nToMinMaxZ = 0) ; - bool AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk = true, int nClPathId = GDB_ID_NULL, + bool AddRise( DBLVECTOR& vAxVal, double dDelta = NAN, int nClPathId = GDB_ID_NULL, bool bMain = true, int nToMinMaxZ = 0) ; + bool AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk = true, int nClPathId = GDB_ID_NULL, bool bMain = true, int nFlag = 0, int nFlag2 = 0, int nMask = -1, const std::string& sInfo = "") ; bool RemoveRise( int nClPathId = GDB_ID_NULL, bool bMain = true) ; - bool AddHome( void) ; + bool AddHome( bool bMain = true) ; bool AddRobotClimb( int nEntId, double dDeltaZ = NAN) ; bool CalcRobotAxesAbovePos( const Point3d& ptP, const Vector3d& vtT, const Vector3d& vtA, double dDeltaZ, DBLVECTOR& vAx, double* pdNewDeltaZ = nullptr) const ; @@ -267,7 +277,7 @@ class Operation : public IUserObj bool SpecialMoveZup( DBLVECTOR& vAx, Vector3d& vtTool, int& nFlag, int& nFlag2, bool& bModif) ; bool SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, DBLVECTOR& vAxNew, bool& bModif) ; bool SpecialLink( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int nLinkType, - const Operation* pPrevOpe, const Operation* pNextOpe) ; + const Operation* pPrevOpe, bool bPrevMain, const Operation* pNextOpe, bool bNextMain) ; bool SpecialPrevMachiningOffset( const Operation* pPrevOpe, double& dOffsetX) ; protected :