diff --git a/MachMgr.h b/MachMgr.h index 5e8dfe5..8960fb0 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -475,7 +475,7 @@ class MachMgr : public IMachMgr const INTVECTOR& vVmill, bool bFirst) ; bool SimEnableToolsForVmill( bool bEnable) ; int SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) ; - bool SimSaveCmd( int nType, int nPar, const std::string& sPar) ; + bool SimSaveCmd( int nType, int nPar, const std::string& sPar, const std::string& sPar2) ; // Machine bool GetHeadAbove( const std::string& sHead) const ; diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index b434abd..f1fe345 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -223,11 +223,11 @@ MachMgr::SimMoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) //---------------------------------------------------------------------------- bool -MachMgr::SimSaveCmd( int nType, int nPar, const string& sPar) +MachMgr::SimSaveCmd( int nType, int nPar, const string& sPar, const string& sPar2) { // verifico simulatore if ( m_pSimul == nullptr) return false ; // salvo il comando - return m_pSimul->SaveCmd( nType, nPar, sPar) ; + return m_pSimul->SaveCmd( nType, nPar, sPar, sPar2) ; } diff --git a/MachineLua.cpp b/MachineLua.cpp index b3151a5..c27e41f 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -1574,12 +1574,46 @@ Machine::LuaEmtSaveCmd( lua_State* L) LuaGetParam( L, 2, nPar) ; string sPar ; LuaGetParam( L, 3, sPar) ; + string sPar2 ; + if ( nType == 4) { + switch ( lua_type( L, 4)) { + case LUA_TNIL : + nPar = 0 ; + break ; + case LUA_TBOOLEAN : + { nPar = 1 ; + bool bVal ; + LuaGetParam( L, 4, bVal) ; + sPar2 = ( bVal ? "1" : "0") ; + } break ; + case LUA_TNUMBER : + if ( lua_isinteger( L, 4)) { + nPar = 2 ; + int nVal ; + LuaGetParam( L, 4, nVal) ; + sPar2 = ToString( nVal) ; + } + else { + nPar = 3 ; + double dVal ; + LuaGetParam( L, 4, dVal) ; + sPar2 = ToString( dVal, 9) ; + } + break ; + case LUA_TSTRING : + { nPar = 4 ; + LuaGetParam( L, 4, sPar2) ; + } break ; + default : + return luaL_error( L, " Unknown Type") ; + } + } LuaClearStack( L) ; // verifico ci sia una macchina attiva if ( m_pMchLua == nullptr) return luaL_error( L, " Unknown Machine") ; // salvo il comando - bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimSaveCmd( nType, nPar, sPar)) ; + bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimSaveCmd( nType, nPar, sPar, sPar2)) ; // assegno risultato LuaSetParam( L, bOk) ; return 1 ; diff --git a/OutputConst.h b/OutputConst.h index 1ee6854..7736a71 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -185,6 +185,7 @@ static const std::string GVAR_SAFEDIST = ".SAFEDIST" ; // (num) distanza static const std::string GVAR_SIMVMID = ".SIMVMID" ; // (int) identificativo grezzo Vmill in collisione static const std::string GVAR_SIMCOBIND = ".SIMCOBIND" ; // (int) indice oggetto in collisione static const std::string GVAR_MPSIM = ".MPSIM" ; // (bool) flag simulazione multiprocesso +static const std::string GVAR_RECORD = ".RECORD" ; // (bool) flag modalità registrazione comandi in simulazione // Funzioni generazione static const std::string ON_START = "OnStart" ; static const std::string ON_END = "OnEnd" ; diff --git a/Simulator.h b/Simulator.h index d2704e3..1e62a04 100644 --- a/Simulator.h +++ b/Simulator.h @@ -59,5 +59,5 @@ class __declspec( novtable) ISimulator double dPar1, double dPar2, const INTVECTOR& vVmill, bool bFirst) = 0 ; virtual bool EnableToolsForVmill( bool bEnable) = 0 ; virtual int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) = 0 ; - virtual bool SaveCmd( int nType, int nPar, const std::string& sPar) = 0 ; + virtual bool SaveCmd( int nType, int nPar, const std::string& sPar, const std::string& sPar2) = 0 ; } ; diff --git a/SimulatorMP.cpp b/SimulatorMP.cpp index 2c9a5d8..9b6170f 100644 --- a/SimulatorMP.cpp +++ b/SimulatorMP.cpp @@ -79,7 +79,7 @@ SimulatorMP::SimulatorMP( void) m_nEntId = GDB_ID_NULL ; m_nEntInd = 0 ; m_dCoeff = 0 ; - m_bChangedTool = false ; + m_nChangeTool = 0 ; m_nAuxSTot = 0 ; m_nAuxSInd = 0 ; m_nAuxETot = 0 ; @@ -131,7 +131,6 @@ SimulatorMP::Init( MachMgr* pMchMgr) m_nStatus = SIS_INITIALIZED ; if ( ExeGetDebugLevel() >= 1) LOG_INFO( GetEMkLogger(), " * SimulatorMP *") - return true ; } @@ -164,7 +163,7 @@ SimulatorMP::Start( bool bFirst) m_nExit = 0 ; m_dTDiam = 0 ; m_bCutOnTip = false ; - m_bChangedTool = false ; + m_nChangeTool = 0 ; ResetInterpolation() ; ResetAxes() ; ResetAuxAxes() ; @@ -201,7 +200,7 @@ SimulatorMP::Start( bool bFirst) // Arrivo alla preparazione per la prima lavorazione int nStatus ; - if ( ! FindAndManageOperationStart( true, bFirst, m_bChangedTool, nStatus) && nStatus != MCH_SIM_STOP) + if ( ! FindAndManageOperationStart( true, bFirst, m_nChangeTool, nStatus) && nStatus != MCH_SIM_STOP) bOk = false ; // se sono ancora su disposizione if ( m_pMchMgr->GetOperationType( m_nOpId) == OPER_DISP) { @@ -212,6 +211,8 @@ SimulatorMP::Start( bool bFirst) while ( m_nAuxSInd < m_nAuxSTot) { if ( ! ManagePathStartAux( nStatus)) return false ; + if ( ! ExecAllCmdData( nStatus)) + return false ; } // aggiornamento assi per eventuali teste caricate UpdateAxes() ; @@ -288,7 +289,7 @@ SimulatorMP::Move( int& nStatus) } // Recupero tempo impiegato (calcolo + visualizzazione precedenti) - if ( m_pPerfCnt != nullptr && ExeGetDebugLevel() >= 5) { + if ( m_pPerfCnt != nullptr && ExeGetDebugLevel() >= 8) { double dElapsed = m_pPerfCnt->Stop() ; string sOut = "Elapsed=" + ToString( dElapsed, 1) ; LOG_DBG_INFO( GetEMkLogger(), sOut.c_str()) @@ -305,29 +306,38 @@ SimulatorMP::Move( int& nStatus) m_dCoeff = 0 ; } + // Se comandi in lista ancora da eseguire, procedo con uno step + if ( m_nCmdInd < int( m_CmdData.size())) { + return ExecCmdData( nStatus) ; + } + else { + m_CmdData.clear() ; + m_nCmdInd = 0 ; + } + // Se appena arrivato alla fine di un percorso di lavoro (verifico anche completamento dei comandi aux di start per path vuote) - if ( m_nEntId == GDB_ID_NULL && m_nAuxEInd == 0 && m_nCLPathInd > 0 && m_nAuxSInd >= m_nAuxSTot) { + if ( m_nChangeTool == 0 && m_nEntId == GDB_ID_NULL && m_nAuxEInd == 0 && m_nCLPathInd > 0 && m_nAuxSInd >= m_nAuxSTot) { // gestione fine percorso di lavoro if ( ! ManagePathEnd( nStatus)) return false ; } // Se alla fine del percorso dopo esecuzione azioni ausiliarie (verifico anche completamento dei comandi aux di start per path vuote) - if ( m_nEntId == GDB_ID_NULL && m_nAuxEInd >= m_nAuxETot && m_nAuxSInd >= m_nAuxSTot) { + if ( m_nChangeTool == 0 && m_nEntId == GDB_ID_NULL && m_nAuxEInd >= m_nAuxETot && m_nAuxSInd >= m_nAuxSTot) { // ricerca e gestione inizio percorso di lavoro if ( ! FindAndManagePathStart( nStatus)) return false ; } // Se arrivato alla fine di una operazione o appena scaricato utensile - if ( m_nCLPathId == GDB_ID_NULL || m_bChangedTool) { + if ( m_nCLPathId == GDB_ID_NULL || m_nChangeTool != 0) { // gestione fine operazione - if ( m_nCLPathId == GDB_ID_NULL && ! ManageOperationEnd( nStatus)) + if ( m_nChangeTool == 0 && m_nCLPathId == GDB_ID_NULL && ! ManageOperationEnd( nStatus)) return false ; // ricerca e gestione nuova operazione - if ( ! FindAndManageOperationStart( false, false, m_bChangedTool, nStatus)) + if ( ! FindAndManageOperationStart( false, false, m_nChangeTool, nStatus)) return false ; - if ( m_bChangedTool) + if ( m_nChangeTool != 0) return true ; // se non ce ne sono altre, sono alla fine if ( m_nOpId == GDB_ID_NULL) { @@ -340,15 +350,6 @@ SimulatorMP::Move( int& nStatus) return false ; } - // Se comandi in lista ancora da eseguire, procedo con uno step - if ( m_nCmdInd < int( m_CmdData.size())) { - return ExecCmdData( nStatus) ; - } - else { - m_CmdData.clear() ; - m_nCmdInd = 0 ; - } - // Se sto eseguendo i movimenti ausiliari di inizio percorso if ( m_nAuxSInd < m_nAuxSTot) return ManagePathStartAux( nStatus) ; @@ -357,6 +358,10 @@ SimulatorMP::Move( int& nStatus) if ( m_nAuxEInd < m_nAuxETot) return ManagePathEndAux( nStatus) ; + // Se ci sono comandi da eseguire + if ( ! m_CmdData.empty()) + return true ; + // Gestione movimento assi return ManageMove( nStatus) ; } @@ -498,7 +503,7 @@ SimulatorMP::GoHome( void) //---------------------------------------------------------------------------- bool -SimulatorMP::UpdateMachiningTool( bool bFirst, bool& bDeselected, int& nErr) +SimulatorMP::UpdateMachiningTool( bool bFirst, int& nChangeTool, int& nErr) { // Reset stato nErr = ERR_NONE ; @@ -526,11 +531,11 @@ SimulatorMP::UpdateMachiningTool( bool bFirst, bool& bDeselected, int& nErr) // verifico se cambierà bool bDiffTool = ( sTool != m_sTool) ; // se cambierà ed esiste il corrente, lo scarico - if ( bDiffTool && ! m_sTool.empty() && ! bDeselected) { + if ( bDiffTool && ! m_sTool.empty() && nChangeTool == 0) { // eventuale lancio script per scarico utensile int nCurrErr ; if ( OnToolDeselect( sTool, sHead, nExit, sTcPos, nCurrErr)) { - bDeselected = true ; + nChangeTool = 1 ; return true ; } else { @@ -539,7 +544,6 @@ SimulatorMP::UpdateMachiningTool( bool bFirst, bool& bDeselected, int& nErr) return false ; } } - bDeselected = false ; // se prima volta, pulisco la testa if ( bFirst) m_pMchMgr->ResetHeadSet( sHead) ; @@ -562,14 +566,17 @@ SimulatorMP::UpdateMachiningTool( bool bFirst, bool& bDeselected, int& nErr) if ( ! UpdateAxes()) return false ; // se cambiato oppure prima volta, lancio lo script di selezione - if ( bDiffTool || bFirst) { + if ( ( bDiffTool || bFirst) && nChangeTool != 2) { int nCurrErr ; if ( ! OnToolSelect( m_sTool, sHead, nExit, sTcPos, bFirst, nCurrErr)) { nErr = ( nErr != ERR_NONE ? nErr : nCurrErr) ; if ( nCurrErr != ERR_COLLISION) return false ; } + nChangeTool = 2 ; + return ( nErr == ERR_NONE) ; } + nChangeTool = 0 ; return ( nErr == ERR_NONE) ; } @@ -704,13 +711,13 @@ SimulatorMP::ResetAuxAxes( void) //---------------------------------------------------------------------------- bool -SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, bool& bChangedTool, int& nStatus) +SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, int& nChangeTool, int& nStatus) { // verifico parametri if ( ! bStart) bFirst = false ; // recupero la nuova operazione - if ( ! bChangedTool) { + if ( nChangeTool == 0) { if ( bStart) { m_nOpId = m_pMchMgr->GetFirstActiveOperation() ; m_nOpInd = 0 ; @@ -723,16 +730,15 @@ SimulatorMP::FindAndManageOperationStart( bool bStart, bool bFirst, bool& bChang // se lavorazione valida Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; if ( pMch != nullptr && ! pMch->IsEmpty()) { - bool bOk = true ; // aggiorno utensile e assi conseguenti int nErr ; - if ( ! UpdateMachiningTool( bFirst, bChangedTool, nErr)) { + if ( ! UpdateMachiningTool( bFirst, nChangeTool, nErr)) { string sOut = "Err=" + ToString( nErr) ; LOG_INFO( GetEMkLogger(), sOut.c_str()) nStatus = CalcStatusOnError( nErr) ; return false ; } - if ( bChangedTool) + if ( nChangeTool != 0) return true ; ++ m_nOpInd ; // imposto la lavorazione come corrente @@ -1612,24 +1618,42 @@ SimulatorMP::ResetCollisionMark( void) //---------------------------------------------------------------------------- bool -SimulatorMP::OnInit( void) +SimulatorMP::CallFunction( const string& sFun, bool bSetRecord, bool bSetModifiedOff) { // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_INIT)) + if ( ! m_pMachine->LuaExistsFunction( sFun)) return true ; + // se richiesto, imposto modalità registrazione + if ( bSetRecord && ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RECORD, true)) + return false ; + // eventuale log di inizio esecuzione + if ( ExeGetDebugLevel() >= 6) { + string sOut = "** " + sFun ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } + // chiamo la funzione di inizio disposizione + bool bOk = m_pMachine->LuaCallFunction( sFun, bSetModifiedOff) ; + // se necessario, annullo stato registrazione + if ( bSetRecord && ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RECORD, false)) + return false ; + // restituisco stato esecuzione + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +SimulatorMP::OnInit( void) +{ // chiamo la funzione di ingresso nella simulazione - return m_pMachine->LuaCallFunction( ON_SIMUL_INIT) ; + return CallFunction( ON_SIMUL_INIT) ; } //---------------------------------------------------------------------------- bool SimulatorMP::OnExit( void) { - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_EXIT)) - return true ; // chiamo la funzione di uscita dalla simulazione - return m_pMachine->LuaCallFunction( ON_SIMUL_EXIT) ; + return CallFunction( ON_SIMUL_EXIT) ; } //---------------------------------------------------------------------------- @@ -1638,11 +1662,8 @@ SimulatorMP::OnProgramStart( bool bFirst) { // assegno flag inizio simulazione bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIM1ST, bFirst) ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_START)) - return true ; // chiamo la funzione di inizio simulazione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_START) ; + bOk = bOk && CallFunction( ON_SIMUL_START) ; return bOk ; } @@ -1650,11 +1671,8 @@ SimulatorMP::OnProgramStart( bool bFirst) bool SimulatorMP::OnProgramEnd( void) { - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_END)) - return true ; // chiamo la funzione di fine simulazione - return m_pMachine->LuaCallFunction( ON_SIMUL_END) ; + return CallFunction( ON_SIMUL_END) ; } //---------------------------------------------------------------------------- @@ -1673,11 +1691,8 @@ SimulatorMP::OnDispositionStarting( int nOpId, int nOpInd, int nPhase, bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EMPTY, bEmpty) ; // assegno flag disposizione con operazioni manuali bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SBH, bSomeByHand) ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_STARTING)) - return true ; // chiamo la funzione di inizio disposizione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_STARTING) ; + bOk = bOk && CallFunction( ON_SIMUL_DISPOSITION_STARTING) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; return bOk ; @@ -1700,11 +1715,8 @@ SimulatorMP::OnDispositionStart( int nOpId, int nOpInd, int nPhase, bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EMPTY, bEmpty) ; // assegno flag disposizione con operazioni manuali bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SBH, bSomeByHand) ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_START)) - return true ; // chiamo la funzione di inizio disposizione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_START) ; + bOk = bOk && CallFunction( ON_SIMUL_DISPOSITION_START) ; // recupero i dati di ritorno m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_VMILL, m_VmId) ; m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_CODET, m_CdId) ; @@ -1717,11 +1729,8 @@ SimulatorMP::OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool SimulatorMP::OnDispositionEnd( void) { - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_END)) - return true ; // chiamo la funzione di fine disposizione - bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_END) ; + bool bOk = CallFunction( ON_SIMUL_DISPOSITION_END) ; // recupero i dati di ritorno m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_VMILL, m_VmId) ; m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_CODET, m_CdId) ; @@ -1766,11 +1775,8 @@ SimulatorMP::OnToolSelect( const string& sTool, const string& sHead, int nExit, // reset errore if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr)) return false ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_TOOL_SELECT)) - return true ; // chiamo la funzione di selezione utensile - bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_TOOL_SELECT) ; + bool bOk = CallFunction( ON_SIMUL_TOOL_SELECT, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; // recupero dati per verifica collisione @@ -1840,7 +1846,7 @@ SimulatorMP::OnToolDeselect( const string& sNextTool, const string& sNextHead, i if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_TOOL_DESELECT)) return bOk ; // chiamo la funzione di deselezione utensile - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_TOOL_DESELECT) ; + bOk = bOk && CallFunction( ON_SIMUL_TOOL_DESELECT, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; // verifico codice di errore @@ -1865,11 +1871,8 @@ SimulatorMP::OnMachiningStart( int nOpId, int nOpInd, const Point3d& ptMin, cons if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MAXMIN, vAxMin) || ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MAXMAX, vAxMax)) return false ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_START)) - return true ; - // chiamo la funzione di inizio disposizione - bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_START) ; + // chiamo la funzione di inizio lavorazione + bool bOk = CallFunction( ON_SIMUL_MACHINING_START, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; return bOk ; @@ -1879,11 +1882,8 @@ SimulatorMP::OnMachiningStart( int nOpId, int nOpInd, const Point3d& ptMin, cons bool SimulatorMP::OnMachiningEnd( void) { - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_END)) - return true ; // chiamo la funzione di fine lavorazione - bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_END) ; + bool bOk = CallFunction( ON_SIMUL_MACHINING_END, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; return bOk ; @@ -1912,11 +1912,8 @@ SimulatorMP::OnPathStart( int nClPathId, int nClPathInd, int nAS, const Point3d& bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PAXMAX, vAxMax) ; // assegno la massima elevazione bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ELEV, dElev) ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_START)) - return bOk ; // chiamo la funzione di inizio percorso di lavorazione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_PATH_START) ; + bOk = bOk && CallFunction( ON_SIMUL_PATH_START, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; return bOk ; @@ -1928,11 +1925,8 @@ SimulatorMP::OnPathEnd( int nAE) { // assegno numero di dati ausiliari finali bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_AUXTOT, nAE) ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_END)) - return bOk ; // chiamo la funzione di fine percorso di lavorazione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_PATH_END) ; + bOk = bOk && CallFunction( ON_SIMUL_PATH_END, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; return bOk ; @@ -1944,15 +1938,12 @@ SimulatorMP::OnPathStartAux( int nInd, const string& sAS, int& nErr) { // reset stato di errore da script nErr = ERR_NONE ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_START_AUX)) - return true ; // assegno indice, valore dato ausiliario e resetto errore bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_AUXIND, nInd) ; bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_AUX, sAS) ; bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; // chiamo la funzione di evento ausiliario all'inizio del percorso - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_PATH_START_AUX) ; + bOk = bOk && CallFunction( ON_SIMUL_PATH_START_AUX, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; // verifico codice di errore @@ -1966,15 +1957,12 @@ SimulatorMP::OnPathEndAux( int nInd, const string& sAE, int& nErr) { // reset stato di errore da script nErr = ERR_NONE ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_END_AUX)) - return true ; // assegno indice, valore dato ausiliario e resetto errore bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_AUXIND, nInd) ; bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_AUX, sAE) ; bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; // chiamo la funzione di evento ausiliario alla fine del percorso - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_PATH_END_AUX) ; + bOk = bOk && CallFunction( ON_SIMUL_PATH_END_AUX, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; // verifico codice di errore @@ -2037,30 +2025,20 @@ SimulatorMP::OnMoveStart( const CamData* pCamData, const CamData* pNextCamData, // reset numero assi ausiliari bOk = bOk && m_pMachine->LuaResetGlobVar( GLOB_VAR + GVAR_AUXAXES) ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_START)) { - ResetAuxAxes() ; - return bOk ; - } // chiamo la funzione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_START) ; - // con errore, esco - if ( ! bOk) { - ResetAuxAxes() ; - return false ; - } - - // verifico codice di errore - m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; - if ( nErr != ERR_NONE) - return false ; + bOk = bOk && CallFunction( ON_SIMUL_MOVE_START, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; - // reset assi ausiliari ResetAuxAxes() ; + // verifico codice di errore + bOk = bOk && m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; + // con errore, esco + if ( ! bOk || nErr != ERR_NONE) + return false ; + // recupero i dati di ritorno m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_MASK, m_nAxesMask) ; if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ENABAXES, m_bEnabAxes)) @@ -2144,14 +2122,11 @@ SimulatorMP::OnMoveEnd( int& nErr) { // reset stato di errore da script nErr = ERR_NONE ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_END)) - return true ; // reset errore if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr)) return false ; // chiamo la funzione - bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_END) ; + bool bOk = CallFunction( ON_SIMUL_MOVE_END, true) ; // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; // verifico codice di errore @@ -2165,9 +2140,6 @@ SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr) { // reset stato di errore da script nErr = ERR_NONE ; - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_COLLISION)) - return true ; // reset stato di errore if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_ERR, nErr)) return false ; @@ -2177,7 +2149,7 @@ SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr) if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMCOBIND, m_CollObj[nObjInd].nInd)) return false ; // chiamo la funzione - if ( ! m_pMachine->LuaCallFunction( ON_SIMUL_COLLISION)) + if ( ! CallFunction( ON_SIMUL_COLLISION)) return false ; // verifico codice di errore m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_ERR, nErr) ; @@ -2199,11 +2171,8 @@ SimulatorMP::OnCollision( int nCdInd, int nObjInd, int& nErr) bool SimulatorMP::OnResetMachine( void) { - // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_RESET_MACHINE)) - return true ; // eseguo reset macchina - return m_pMachine->LuaCallFunction( ON_RESET_MACHINE) ; + return CallFunction( ON_RESET_MACHINE) ; } //---------------------------------------------------------------------------- @@ -2361,7 +2330,7 @@ SimulatorMP::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) // Salvo i dati di movimento m_CmdData.emplace_back( nMoveType, vAxNaEpSt) ; // Log dati - if ( ExeGetDebugLevel() >= 4) { + if ( ExeGetDebugLevel() >= 6) { string sOut = "Save=SimulMoveAxes," + ToString( nMoveType) ; for ( int i = 0 ; i < int( vAxNaEpSt.size()) ; ++ i) sOut += "," + vAxNaEpSt[i].sName + @@ -2375,13 +2344,15 @@ SimulatorMP::MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) //---------------------------------------------------------------------------- bool -SimulatorMP::SaveCmd( int nType, int nPar, const string& sPar) +SimulatorMP::SaveCmd( int nType, int nPar, const string& sPar, const string& sPar2) { // Salvo il comando - m_CmdData.emplace_back( nType, nPar, sPar) ; + m_CmdData.emplace_back( nType, nPar, sPar, sPar2) ; // Log dati - if ( ExeGetDebugLevel() >= 4) { - string sOut = "Save=SimulSaveCmd," + ToString( nType) + "," + ToString( nPar) + "," + sPar ; + if ( ExeGetDebugLevel() >= 6) { + string sOut = "Save=SimulCmd," + ToString( nType) + "," + ToString( nPar) + "," + sPar ; + if ( ! IsEmptyOrSpaces( sPar2)) + sOut += "," + sPar2 ; LOG_INFO( GetEMkLogger(), sOut.c_str()) } return false ; @@ -2395,17 +2366,21 @@ SimulatorMP::ExecCmdData( int& nStatus) auto& CmdCurr = m_CmdData[m_nCmdInd] ; // Stampe di debug - if ( ExeGetDebugLevel() >= 4) { + if ( ExeGetDebugLevel() >= 6) { if ( CmdCurr.nType == 1) { - string sOut = "Cmd=SimulMoveAxes," + ToString( CmdCurr.nMoveType) ; - for ( int i = 0 ; i < int( CmdCurr.vAxNaEpSt.size()) ; ++ i) - sOut += "," + CmdCurr.vAxNaEpSt[i].sName + - "," + ToString( CmdCurr.vAxNaEpSt[i].dEndPos, 3) + - "," + ToString( CmdCurr.vAxNaEpSt[i].dStep, 3) ; - LOG_INFO( GetEMkLogger(), sOut.c_str()) + if ( m_dCmdCoeff < EPS_ZERO) { + string sOut = "Exec=SimulMoveAxes," + ToString( CmdCurr.nMoveType) ; + for ( int i = 0 ; i < int( CmdCurr.vAxNaEpSt.size()) ; ++ i) + sOut += "," + CmdCurr.vAxNaEpSt[i].sName + + "," + ToString( CmdCurr.vAxNaEpSt[i].dEndPos, 3) + + "," + ToString( CmdCurr.vAxNaEpSt[i].dStep, 3) ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } } else { - string sOut = "Cmd=SimulSaveCmd," + ToString( CmdCurr.nType) + "," + ToString( CmdCurr.nPar) + "," + CmdCurr.sPar ; + string sOut = "Exec=SimulCmd," + ToString( CmdCurr.nType) + "," + ToString( CmdCurr.nPar) + "," + CmdCurr.sPar ; + if ( ! IsEmptyOrSpaces( CmdCurr.sPar2)) + sOut += "," + CmdCurr.sPar2 ; LOG_INFO( GetEMkLogger(), sOut.c_str()) } } @@ -2535,6 +2510,37 @@ SimulatorMP::ExecCmdData( int& nStatus) m_nCmdInd += 1 ; m_dCmdCoeff = 0 ; } + // eseguo assegnazione di variabile globale + else if ( CmdCurr.nType == 4) { + bool bOk = false ; + switch ( CmdCurr.nPar) { + case 0 : + bOk = m_pMachine->LuaResetGlobVar( CmdCurr.sPar) ; + break ; + case 1 : + { bool bVal = ( CmdCurr.sPar2 == "1") ; + bOk = m_pMachine->LuaSetGlobVar( CmdCurr.sPar, bVal) ; + } break ; + case 2 : + { int nVal ; FromString( CmdCurr.sPar2, nVal) ; + bOk = m_pMachine->LuaSetGlobVar( CmdCurr.sPar, nVal) ; + } break ; + case 3 : + { double dVal ; FromString( CmdCurr.sPar2, dVal) ; + bOk = m_pMachine->LuaSetGlobVar( CmdCurr.sPar, dVal) ; + } break ; + case 4 : + bOk = m_pMachine->LuaSetGlobVar( CmdCurr.sPar, CmdCurr.sPar2) ; + break ; + } + if ( ! bOk) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // Aggiorno indice comandi eseguiti + m_nCmdInd += 1 ; + m_dCmdCoeff = 0 ; + } // eseguo chiamata funzione else if ( CmdCurr.nType == 5) { // chiamo la funzione @@ -2549,6 +2555,7 @@ SimulatorMP::ExecCmdData( int& nStatus) // altrimenti errore else { nStatus = MCH_SIM_ERR ; + LOG_DBG_INFO( GetEMkLogger(), " --> ExecCmdData nType Error <--") return false ; } diff --git a/SimulatorMP.h b/SimulatorMP.h index b768ddd..d25e19b 100644 --- a/SimulatorMP.h +++ b/SimulatorMP.h @@ -46,13 +46,13 @@ class SimulatorMP : public ISimulator double dPar1, double dPar2, const INTVECTOR& vVmill, bool bFirst) override ; bool EnableToolsForVmill( bool bEnable) override ; int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) override ; - bool SaveCmd( int nType, int nPar, const std::string& sPar) override ; + bool SaveCmd( int nType, int nPar, const std::string& sPar, const std::string& sPar2) override ; public : SimulatorMP( void) ; private : - bool UpdateMachiningTool( bool bFirst, bool& bDeselect, int& nErr) ; + bool UpdateMachiningTool( bool bFirst, int& nChangeTool, int& nErr) ; bool UpdateDispositionTool( bool bFirst, int& nErr) ; bool UpdateAxes( void) ; bool UpdateAxesPos( void) ; @@ -62,7 +62,7 @@ class SimulatorMP : public ISimulator private : bool VerifySetup( void) ; - bool FindAndManageOperationStart( bool bStart, bool bFirst, bool& bChangedTool, int& nStatus) ; + bool FindAndManageOperationStart( bool bStart, bool bFirst, int& nChangeTool, int& nStatus) ; bool ManageOperationEnd( int& nStatus) ; bool FindAndManagePathStart( int& nStatus) ; bool ManagePathEnd( int& nStatus) ; @@ -81,6 +81,7 @@ class SimulatorMP : public ISimulator { return ( m_nUiStatus == MCH_UISIM_STOP) ; } bool SetCollisionMark( int nCdInd, int nObjInd) ; bool ResetCollisionMark( void) ; + bool CallFunction( const std::string& sFun, bool bSetRecord = false, bool bSetModifiedOff = true) ; bool OnInit( void) ; bool OnExit( void) ; bool OnProgramStart( bool bFirst) ; @@ -146,11 +147,12 @@ class SimulatorMP : public ISimulator SAMVECTOR vAxNaEpSt ; int nPar ; std::string sPar ; + std::string sPar2 ; CmdData( void) : nType(0) {} CmdData( int nM, const SAMVECTOR& vAx) : nType( 1), nMoveType( nM), vAxNaEpSt( vAx) {} - CmdData( int nT, int nP, const std::string& sP) - : nType( nT), nPar( nP), sPar( sP) {} + CmdData( int nT, int nP, const std::string& sP, const std::string& sP2) + : nType( nT), nPar( nP), sPar( sP), sPar2( sP2) {} } ; typedef std::vector CMDVECTOR ; @@ -169,7 +171,7 @@ class SimulatorMP : public ISimulator int m_nEntId ; // identificativo dell'entità corrente int m_nEntInd ; // contatore dell'entità corrente nel percorso di lavoro double m_dCoeff ; // coefficiente di esecuzione del movimento corrente (0...1) - bool m_bChangedTool ; // flag di utensile appena scaricato + int m_nChangeTool ; // stato di carico e scarico dell'utensile int m_nAuxSTot ; // numero totale movimenti ausiliari di inizio percorso int m_nAuxSInd ; // indice del movimento ausiliario di inizio percorso corrente int m_nAuxETot ; // numero totale movimenti ausiliari di fine percorso diff --git a/SimulatorSP.cpp b/SimulatorSP.cpp index b969abd..a644e17 100644 --- a/SimulatorSP.cpp +++ b/SimulatorSP.cpp @@ -126,6 +126,8 @@ SimulatorSP::Init( MachMgr* pMchMgr) m_pMachine = m_pMchMgr->GetCurrMachine() ; m_pPerfCnt = new PerformanceCounter ; m_nStatus = SIS_INITIALIZED ; + if ( ExeGetDebugLevel() >= 1) + LOG_INFO( GetEMkLogger(), " * SimulatorSP *") return true ; } diff --git a/SimulatorSP.h b/SimulatorSP.h index e67af91..d2cddf6 100644 --- a/SimulatorSP.h +++ b/SimulatorSP.h @@ -46,7 +46,7 @@ class SimulatorSP : public ISimulator double dPar1, double dPar2, const INTVECTOR& vVmill, bool bFirst) override ; bool EnableToolsForVmill( bool bEnable) override ; int MoveAxes( int nMoveType, const SAMVECTOR& vAxNaEpSt) override ; - bool SaveCmd( int nType, int nPar, const std::string& sPar) override + bool SaveCmd( int nType, int nPar, const std::string& sPar, const std::string& sPar2) override { return false ; } public :