diff --git a/MachMgr.h b/MachMgr.h index 33583f1..66f4195 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -263,6 +263,7 @@ class MachMgr : public IMachMgr bool GetMachiningStartPoint( Point3d& ptStart) const override ; bool GetMachiningEndPoint( Point3d& ptEnd) const override ; // Simulation + bool SimInit( void) override ; bool SimStart( bool bFirst) override ; bool SimMove( int& nStatus) override ; bool SimGetAxisInfoPos( int nI, std::string& sName, std::string& sToken, bool& bLinear, double& dVal) const override ; @@ -272,7 +273,7 @@ class MachMgr : public IMachMgr bool SimSetStep( double dStep) override ; bool SimSetUiStatus( int nUiStatus) override ; bool SimGoHome( void) override ; - bool SimStop( void) override ; + bool SimExit( void) override ; // Generation bool Generate( const std::string& sCncFile, const std::string& sInfo) override ; bool Estimate( const std::string& sEstFile, const std::string& sInfo) override ; diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index 8cb2113..e25df57 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -360,7 +360,7 @@ MachMgr::PrepareCurrMachGroup( int nId) // se esiste gruppo corrente, lo disabilito if ( m_nCurrMGrpId != GDB_ID_NULL) { // termino eventuale simulazione attiva - SimStop() ; + SimExit() ; // riporto i pezzi nei grezzi precedenti nella loro posizione standard SwapParts( false) ; // nascondo precedente gruppo corrente e la relativa macchina @@ -395,7 +395,7 @@ MachMgr::ResetCurrMachGroup( void) if ( m_nCurrMGrpId == GDB_ID_NULL) return true ; // termino eventuale simulazione attiva - SimStop() ; + SimExit() ; // riporto i pezzi nei grezzi nella loro posizione standard SwapParts( false) ; // visualizzo pezzi rimasti sotto la radice diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index a21b9ff..012aa90 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -22,16 +22,24 @@ using namespace std ; //---------------------------------------------------------------------------- bool -MachMgr::SimStart( bool bFirst) +MachMgr::SimInit( void) { - // alloco simulatore + // alloco o rialloco il simulatore if ( m_pSimul != nullptr) delete m_pSimul ; m_pSimul = new( std::nothrow) Simulator ; if ( m_pSimul == nullptr) return false ; // lo inizializzo - if ( ! m_pSimul->Init( this)) + return m_pSimul->Init( this) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SimStart( bool bFirst) +{ + // verifico simulatore + if ( m_pSimul == nullptr) return false ; // lo avvio return m_pSimul->Start( bFirst) ; @@ -129,7 +137,7 @@ MachMgr::SimGoHome( void) //---------------------------------------------------------------------------- bool -MachMgr::SimStop( void) +MachMgr::SimExit( void) { // verifico simulatore if ( m_pSimul == nullptr) diff --git a/Machine.h b/Machine.h index 487b53f..215e48d 100644 --- a/Machine.h +++ b/Machine.h @@ -154,7 +154,7 @@ class Machine bool LuaCreateGlobTable( const std::string& sName) ; bool LuaResetGlobVar( const std::string& sName) ; template - bool LuaSetGlobVar( const std::string& sVar, const T& Val) ; + bool LuaSetGlobVar( const std::string& sVar, const T& Val, bool bMchRestore = false) ; template bool LuaGetGlobVar( const std::string& sVar, T& Val) ; bool WriterOpen( const std::string& sOutFile) ; @@ -304,21 +304,22 @@ class Machine //---------------------------------------------------------------------------- template bool -Machine::LuaSetGlobVar( const std::string& sVar, const T& Val) +Machine::LuaSetGlobVar( const std::string& sVar, const T& Val, bool bMchRestore) { // imposto contesto corretto int nOldCtx = ExeGetCurrentContext() ; if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo l'assegnamento bool bOk = ::LuaSetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; - // reset dell'oggetto corrente per Lua - m_pMchLua = nullptr ; + // ripristino o reset dell'oggetto corrente per Lua + m_pMchLua = ( bMchRestore ? pOldMchLua : nullptr) ; return bOk ; } diff --git a/Simulator.cpp b/Simulator.cpp index e890e8e..359cda8 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -70,7 +70,10 @@ Simulator::Simulator( void) //---------------------------------------------------------------------------- Simulator::~Simulator( void) { - Stop() ; + // porto la macchina in posizione home + GoHome() ; + // rimuovo tavola variabili globali + m_pMachine->LuaResetGlobVar( GLOB_VAR) ; } //---------------------------------------------------------------------------- @@ -104,8 +107,9 @@ Simulator::Start( bool bFirst) if ( bFirst && ! VerifySetup()) bOk = false ; - // Reset utensile e assi correnti + // Reset utensile, interpolazione e assi correnti m_sTool.clear() ; + ResetInterpolation() ; ResetAxes() ; ResetAuxAxes() ; // porto la macchina in home @@ -155,6 +159,28 @@ Simulator::VerifySetup( void) return false ; } +//---------------------------------------------------------------------------- +bool +Simulator::ResetInterpolation( void) +{ + m_nOpId = GDB_ID_NULL ; + m_nOpInd = 0 ; + m_nCLPathId = GDB_ID_NULL ; + m_nCLPathInd = 0 ; + m_nEntId = GDB_ID_NULL ; + m_nEntInd = 0 ; + m_dCoeff = 0 ; + m_nAuxSTot = 0 ; + m_nAuxSInd = 0 ; + m_nAuxETot = 0 ; + m_nAuxEInd = 0 ; + m_nVmId = GDB_ID_NULL ; + m_dVmTdOffs = 0 ; + m_dVmAdOffs = 0 ; + m_bEnabAxes = true ; + return true ; +} + //---------------------------------------------------------------------------- bool Simulator::Move( int& nStatus) @@ -334,8 +360,8 @@ bool Simulator::SetStep( double dStep) { m_dStep = Clamp( dStep, MIN_STEP, MAX_STEP) ; - // imposto step per movimenti gestiti nelle macro di simulazione - m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep) ; + // imposto step per movimenti gestiti nelle macro di simulazione ( con ripristino macchina Lua originale) + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep, true) ; return true ; } @@ -344,8 +370,8 @@ 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 + GVAR_SIMUISTAT, m_nUiStatus) ; + // imposto stato utente del simulatore per movimenti gestiti nelle macro di simulazione ( con ripristino macchina Lua originale) + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMUISTAT, m_nUiStatus, true) ; return true ; } @@ -364,27 +390,6 @@ Simulator::GoHome( void) return m_pMchMgr->GetAllCurrAxesHomePos( m_AxesVal) ; } -//---------------------------------------------------------------------------- -bool -Simulator::Stop( void) -{ - // porto in home - if ( ! GoHome()) - return false ; - // rimuovo tavola variabili globali - m_pMachine->LuaResetGlobVar( GLOB_VAR) ; - // reset dello stato - m_nOpId = GDB_ID_NULL ; - m_nCLPathId = GDB_ID_NULL ; - m_nEntId = GDB_ID_NULL ; - m_dCoeff = 0 ; - m_nAuxSTot = 0 ; - m_nAuxSInd = 0 ; - m_nAuxETot = 0 ; - m_nAuxEInd = 0 ; - return true ; -} - //---------------------------------------------------------------------------- bool Simulator::UpdateTool( bool bFirst) @@ -971,7 +976,7 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove) if ( m_nVmId != GDB_ID_NULL) { Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ; Frame3d frVzmF ; bool bOkF = GetHeadCurrPosDirAux( ptNoseF, vtDirF, vtAuxF) && m_pGeomDB->GetGlobFrame( m_nVmId, frVzmF) ; ; - ExecVmillOnLine( ptNoseI, vtDirI, vtAuxI, frVzmI, ptNoseF, vtDirF, vtAuxF, frVzmF) ; + ExecLineVmill( ptNoseI, vtDirI, vtAuxI, frVzmI, ptNoseF, vtDirF, vtAuxF, frVzmF) ; } } // Eseguo movimento su arco @@ -1007,7 +1012,7 @@ Simulator::ManageSingleMove( int& nStatus, double& dMove) if ( m_nVmId != GDB_ID_NULL) { Point3d ptNoseF ; Vector3d vtDirF ; Vector3d vtAuxF ; Frame3d frVzmF ; bool bOkF = GetHeadCurrPosDirAux( ptNoseF, vtDirF, vtAuxF) && m_pGeomDB->GetGlobFrame( m_nVmId, frVzmF) ; - ExecVmillOnLine( ptNoseI, vtDirI, vtAuxI, frVzmI, ptNoseF, vtDirF, vtAuxF, frVzmF) ; + ExecLineVmill( ptNoseI, vtDirI, vtAuxI, frVzmI, ptNoseF, vtDirF, vtAuxF, frVzmF) ; // aggiorno prossimo inizio ptNoseI = ptNoseF ; vtDirI = vtDirF ; @@ -1091,8 +1096,8 @@ Simulator::GetHeadCurrPosDirAux( Point3d& ptH, Vector3d& vtH, Vector3d& vtA) //---------------------------------------------------------------------------- bool -Simulator::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) +Simulator::ExecLineVmill( const Point3d& ptHi, const Vector3d& vtHi, const Vector3d& vtAi, const Frame3d& frVzmI, + const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF) { // Recupero Zmap IVolZmap* pVZM = GetVolZmap( m_pGeomDB->GetGeoObj( m_nVmId)) ; diff --git a/Simulator.h b/Simulator.h index fd52781..1d4d4d6 100644 --- a/Simulator.h +++ b/Simulator.h @@ -29,19 +29,19 @@ class Simulator bool Init( MachMgr* pMchMgr) ; bool Start( bool bFirst) ; bool Move( int& nStatus) ; + bool GoHome( void) ; + bool SetStep( double dStep) ; + bool SetUiStatus( int nUiStatus) ; bool GetAxisInfoPos( int nI, std::string& sName, std::string& sToken, bool& bLinear, double& dVal) const ; bool GetToolInfo( std::string& sName, double& dSpeed) const ; 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) ; private : bool UpdateTool( bool bFirst = false) ; bool UpdateAxes( void) ; bool UpdateAxesPos( void) ; + bool ResetInterpolation( void) ; bool ResetAxes( void) ; bool ResetAuxAxes( void) ; @@ -56,8 +56,8 @@ class Simulator bool ManageMove( int& nStatus) ; bool ManageSingleMove( int& nStatus, double& dMove) ; 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 ExecLineVmill( 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) ;