From 1d3c722fd3a8b9b1a601c1ae1005b7e560bcb840 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 19 Feb 2024 14:54:50 +0100 Subject: [PATCH] EgtMachKernel 2.6b4 : - in simulazione aggiunti eventi Init e Exit a cui possono rispondere le funzioni lua OnSimulInit e OnSimulExit. --- EgtMachKernel.rc | Bin 11774 -> 11774 bytes OutputConst.h | 2 ++ Simulator.cpp | 52 +++++++++++++++++++++++++++++++++++++++-------- Simulator.h | 11 ++++++++-- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index a9e602d31380dd8712a71f6fa8c0d3d122f0f311..5156166d5f5e6bdacb921656a72d16038777ca79 100644 GIT binary patch delta 97 zcmewt{V#gMFE&P#&A-`fnHfzcKa|wnoW?bQ1uSxrY4Qod0+^@}R1`^_2jk{d(jGv4 NK<#LXK~l;gTmUI`BbWdH delta 97 zcmewt{V#gMFE&Qw&A-`fnHh~IKa|wnoW?bQ1uSxrY4Qod0+^@}R1`^_2jk{d(jGv4 NK<#LXK~l;gTmUD-Bai?9 diff --git a/OutputConst.h b/OutputConst.h index 468f5ef..d0e27b0 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -206,6 +206,8 @@ static const std::string ON_ESTIM_RAPID = "OnEstimRapid" ; static const std::string ON_ESTIM_LINEAR = "OnEstimLinear" ; static const std::string ON_ESTIM_ARC = "OnEstimArc" ; // Funzioni simulazione +static const std::string ON_SIMUL_INIT = "OnSimulInit" ; +static const std::string ON_SIMUL_EXIT = "OnSimulExit" ; static const std::string ON_SIMUL_START = "OnSimulStart" ; static const std::string ON_SIMUL_END = "OnSimulEnd" ; static const std::string ON_SIMUL_DISPOSITION_STARTING = "OnSimulDispositionStarting" ; diff --git a/Simulator.cpp b/Simulator.cpp index 8800c31..dbb0cb6 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -61,6 +61,7 @@ Simulator::Simulator( void) m_pGeomDB = nullptr ; m_pMachine = nullptr ; m_pPerfCnt = nullptr ; + m_nStatus = SIS_CREATED ; m_dStep = MID_STEP ; m_nUiStatus = MCH_UISIM_NULL ; m_nOpId = GDB_ID_NULL ; @@ -92,6 +93,8 @@ Simulator::~Simulator( void) { // porto la macchina in posizione home GoHome() ; + // gestione evento uscita dal simulatore + OnExit() ; // rimuovo tavola variabili globali m_pMachine->LuaResetGlobVar( GLOB_VAR) ; // rimuovo performance counter @@ -113,6 +116,7 @@ Simulator::Init( MachMgr* pMchMgr) m_pGeomDB = m_pMchMgr->GetGeomDB() ; m_pMachine = m_pMchMgr->GetCurrMachine() ; m_pPerfCnt = new PerformanceCounter ; + m_nStatus = SIS_INITIALIZED ; return true ; } @@ -129,8 +133,8 @@ Simulator::Start( bool bFirst) bool bOk = true ; - // Se avvio vero - if ( bFirst) { + // Se appena entrati in simulazione + if ( m_nStatus == SIS_INITIALIZED) { // Forzo aggiornamento attrezzaggio della macchinata if ( ! m_pMchMgr->UpdateCurrSetup()) bOk = false ; @@ -167,8 +171,15 @@ Simulator::Start( bool bFirst) m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_VER, GetEMkVer()) ; m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MACHNAME, m_pMachine->GetMachineName()) ; - // Richiamo funzione su avvio simulazione - if ( ! OnStart( bFirst)) + // Se appena entrati in simulazione + if ( m_nStatus == SIS_INITIALIZED) { + if ( ! OnInit()) + bOk = false ; + m_nStatus = SIS_READYTOSTART ; + } + + // Richiamo funzione per evento avvio simulazione + if ( ! OnProgramStart( bFirst)) bOk = false ; // Arrivo alla preparazione per la prima lavorazione @@ -193,6 +204,9 @@ Simulator::Start( bool bFirst) if ( m_pPerfCnt != nullptr) m_pPerfCnt->Start() ; + // Imposto lo stato interno + m_nStatus = ( bOk ? SIS_READYTORUN : SIS_READYTOSTART) ; + return bOk ; } @@ -248,7 +262,7 @@ bool Simulator::Move( int& nStatus) { // Verifiche - if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr || m_pMachine == nullptr) { + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr || m_pMachine == nullptr || m_nStatus != SIS_READYTORUN) { nStatus = MCH_SIM_ERR ; return false ; } @@ -292,7 +306,7 @@ Simulator::Move( int& nStatus) return false ; // se non ce ne sono altre, sono alla fine if ( m_nOpId == GDB_ID_NULL) { - OnEnd() ; + OnProgramEnd() ; nStatus = MCH_SIM_END ; return false ; } @@ -1474,7 +1488,29 @@ Simulator::ExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) //---------------------------------------------------------------------------- bool -Simulator::OnStart( bool bFirst) +Simulator::OnInit( void) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_INIT)) + return true ; + // chiamo la funzione di ingresso nella simulazione + return m_pMachine->LuaCallFunction( ON_SIMUL_INIT) ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::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) ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnProgramStart( bool bFirst) { // assegno flag inizio simulazione bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIM1ST, bFirst) ; @@ -1488,7 +1524,7 @@ Simulator::OnStart( bool bFirst) //---------------------------------------------------------------------------- bool -Simulator::OnEnd( void) +Simulator::OnProgramEnd( void) { // verifico esistenza funzione if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_END)) diff --git a/Simulator.h b/Simulator.h index 3c340c6..a168e26 100644 --- a/Simulator.h +++ b/Simulator.h @@ -86,8 +86,10 @@ class Simulator { return ( ! m_CollObj.empty() && ! m_CdId.empty()) ; } bool Stopped( void) { return ( m_nUiStatus == MCH_UISIM_STOP) ; } - bool OnStart( bool bFirst) ; - bool OnEnd( void) ; + bool OnInit( void) ; + bool OnExit( void) ; + bool OnProgramStart( bool bFirst) ; + bool OnProgramEnd( void) ; bool OnDispositionStarting( int nOpId, int nOpInd, int nPhase, const std::string& sTable, const Point3d& ptOri1, bool bEmpty, bool bSomeByHand) ; bool OnDispositionStart( int nOpId, int nOpInd, int nPhase, @@ -135,12 +137,17 @@ class Simulator : sName( sN), sHead( sH), nExit( nE), dTdOffs( dT), dAdOffs( dA) {} } ; typedef std::vector VMTVECTOR ; + enum { SIS_CREATED = 0, + SIS_INITIALIZED = 1, + SIS_READYTOSTART = 2, + SIS_READYTORUN = 3} ; private : MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni IGeomDB* m_pGeomDB ; // puntatore al DB geometrico Machine* m_pMachine ; // puntatore alla macchina PerformanceCounter* m_pPerfCnt ; // timer per calcolo FPS + int m_nStatus ; // stato interno del simulatore (creato, inizializzato, pronto al movimento) 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