diff --git a/MachMgr.h b/MachMgr.h index 0ecb3ba..488085e 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -268,6 +268,7 @@ class MachMgr : public IMachMgr bool SimGetOperationInfo( std::string& sName, int& nType) const override ; bool SimGetMoveInfo( int& nGmove, double& dFeed) const override ; bool SimSetStep( double dStep) override ; + bool SimSetUiStatus( int nUiStatus) override ; bool SimGoHome( void) override ; bool SimStop( void) override ; // Generation diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index 31f93f9..a21b9ff 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -105,6 +105,17 @@ MachMgr::SimSetStep( double dStep) return m_pSimul->SetStep( dStep) ; } +//---------------------------------------------------------------------------- +bool +MachMgr::SimSetUiStatus( int nUiStatus) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // imposto lo stato utente del simulatore + return m_pSimul->SetUiStatus( nUiStatus) ; +} + //---------------------------------------------------------------------------- bool MachMgr::SimGoHome( void) diff --git a/Simulator.cpp b/Simulator.cpp index 7941d85..c21b5bf 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -334,6 +334,16 @@ Simulator::SetStep( double dStep) return true ; } +//---------------------------------------------------------------------------- +bool +Simulator::SetUiStatus( int nUiStatus) +{ + m_nUiStatus = nUiStatus ; + // imposto stato simulatore a livello utente per movimenti gestiti nelle macro di simulazione + m_pMachine->LuaSetGlobVar( GLOB_VAR + ".SIMUISTAT", m_nUiStatus) ; + return true ; +} + //---------------------------------------------------------------------------- bool Simulator::GoHome( void) @@ -396,7 +406,7 @@ Simulator::UpdateTool( bool bFirst) if ( sTool != m_sTool && ! m_sTool.empty()) { // eventuale lancio script per scarico utensile if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos)) - return false ; + return Stopped() ; } // se cambiato oppure prima volta, attivo l'utensile della lavorazione if ( sTool != m_sTool || bFirst) { @@ -429,7 +439,7 @@ Simulator::UpdateTool( bool bFirst) } // eventuale lancio script if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst)) - return false ; + return Stopped() ; } return true ; } @@ -443,7 +453,7 @@ Simulator::UpdateTool( bool bFirst) if ( ! m_sTool.empty() && sTool != m_sTool) { // eventuale lancio script per scarico utensile if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos)) - return false ; + return Stopped() ; } // carico l'utensile if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) @@ -454,7 +464,7 @@ Simulator::UpdateTool( bool bFirst) return false ; // eventuale lancio script if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst)) - return false ; + return Stopped() ; return true ; } return false ; @@ -562,8 +572,12 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) m_pMchMgr->SetCurrMachining( m_nOpId) ; // richiamo gestione evento inizio lavorazione if ( ! OnMachiningStart( m_nOpId, m_nOpInd)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } break ; } @@ -587,8 +601,12 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) if ( ! bEmpty) { // richiamo gestione evento appena prima di inizio disposizione if ( ! OnDispositionStarting( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, false, bSomeByHand)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } // cambio fase m_pMchMgr->SetCurrPhase( nPhase, ( nPhase == 1)) ; @@ -600,8 +618,12 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) ++ m_nOpInd ; // richiamo gestione evento inizio disposizione if ( ! OnDispositionStart( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, false, bSomeByHand)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } // se ci sono movimenti manuali, aggiorno visualizzazione e breve pausa (200 ms) if ( bSomeByHand) @@ -612,8 +634,12 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) else { // richiamo gestione evento appena prima di inizio disposizione if ( ! OnDispositionStarting( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, true, bSomeByHand)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } // cambio fase m_pMchMgr->SetCurrPhase( nPhase, ( nPhase == 1)) ; @@ -621,8 +647,12 @@ Simulator::FindAndManageOperationStart( bool bStart, bool bFirst, int& nStatus) // richiamo gestione evento inizio e fine disposizione if ( ! OnDispositionStart( m_nOpId, m_nOpInd, nPhase, sTable, ptOri1, true, bSomeByHand) || ! OnDispositionEnd()) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } // se non è inizio, aggiorno visualizzazione e breve pausa (200 ms) if ( nPhase != 1) { @@ -656,9 +686,15 @@ Simulator::ManageOperationEnd( int& nStatus) bOk = OnDispositionEnd() ; } // gestione stato - if ( ! bOk) - nStatus = MCH_SIM_ERR ; - return bOk ; + if ( ! bOk) { + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } + } + return true ; } //---------------------------------------------------------------------------- @@ -713,8 +749,12 @@ Simulator::FindAndManagePathStart( int& nStatus) m_nAuxETot = 0 ; // richiamo gestione evento inizio percorso di lavoro if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd, m_nAuxSTot, ptStart, vtExtr, ptMin, ptMax, dElev)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } } // se altrimenti trovato nuovo CL path vuoto @@ -741,8 +781,12 @@ Simulator::ManagePathEnd( int& nStatus) m_nAuxEInd = 0 ; // richiamo gestione evento fine percorso di lavoro if ( ! OnPathEnd( m_nAuxETot)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } return true ; } @@ -761,8 +805,12 @@ Simulator::ManagePathStartAux( int& nStatus) } // richiamo gestione evento ausiliario prima di inizio percorso di lavoro if ( ! OnPathStartAux( m_nAuxSInd, sAS)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } nStatus = MCH_SIM_END_STEP ; return true ; @@ -782,8 +830,12 @@ Simulator::ManagePathEndAux( int& nStatus) } // richiamo gestione evento ausiliario dopo fine percorso di lavoro if ( ! OnPathEndAux( m_nAuxEInd, sAE)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } nStatus = MCH_SIM_END_STEP ; return true ; @@ -833,8 +885,12 @@ Simulator::ManageMove( int& nStatus) if ( m_nEntId != GDB_ID_NULL && m_dCoeff < EPS_ZERO) { ++ m_nEntInd ; if ( ! OnMoveStart( pCamData)) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } } @@ -949,8 +1005,12 @@ Simulator::ManageMove( int& nStatus) nStatus = MCH_SIM_END_STEP ; // richiamo gestione evento fine entità if ( ! OnMoveEnd()) { - nStatus = MCH_SIM_ERR ; - return false ; + if ( Stopped()) + return true ; + else { + nStatus = MCH_SIM_ERR ; + return false ; + } } } // Altrimenti sto muovendomi all'interno dello step diff --git a/Simulator.h b/Simulator.h index 8d4d7f7..862c9a2 100644 --- a/Simulator.h +++ b/Simulator.h @@ -34,6 +34,7 @@ class Simulator bool GetOperationInfo( std::string& sName, int& nType) const ; bool GetMoveInfo( int& nGmove, double& dFeed) const ; bool SetStep( double dStep) ; + bool SetUiStatus( int nUiStatus) ; bool GoHome( void) ; bool Stop( void) ; @@ -56,6 +57,8 @@ class Simulator bool GetHeadCurrPosDirAux( Point3d& ptH, Vector3d& vtH, Vector3d& vtA) ; bool ExecVmillOnLine( const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI, const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF) ; + bool Stopped( void) + { return ( m_nUiStatus == MCH_UISIM_STOP) ; } bool OnStart( bool bFirst) ; bool OnEnd( void) ; bool OnDispositionStarting( int nOpId, int nOpInd, int nPhase, @@ -81,6 +84,7 @@ class Simulator IGeomDB* m_pGeomDB ; // puntatore al DB geometrico Machine* m_pMachine ; // puntatore alla macchina double m_dStep ; // lunghezza di riferimento per la velocità di simulazione + int m_nUiStatus ; // stato simulazione a livello utente int m_nOpId ; // identificativo della operazione (lavoraz.) corrente int m_nOpInd ; // contatore della operazione (lavoraz.) corrente int m_nCLPathId ; // identificativo del percorso di lavoro corrente