diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index df49ace..a1b1c5b 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Machine.h b/Machine.h index c7fc067..b767fd3 100644 --- a/Machine.h +++ b/Machine.h @@ -155,8 +155,9 @@ class Machine bool LuaCallFunction( const std::string& sFun, bool bSetModifiedOff = true) ; bool LuaCreateGlobTable( const std::string& sName) ; bool LuaResetGlobVar( const std::string& sName) ; + bool LuaChangeNameGlobVar( const std::string& sOldName, const std::string& sNewName) ; template - bool LuaSetGlobVar( const std::string& sVar, const T& Val, bool bMchRestore = false) ; + bool LuaSetGlobVar( const std::string& sVar, const T& Val) ; template bool LuaGetGlobVar( const std::string& sVar, T& Val) ; bool WriterOpen( const std::string& sOutFile) ; @@ -295,6 +296,7 @@ class Machine static int LuaEmtAddRapidMove( lua_State* L) ; static int LuaEmtAddLinearMove( lua_State* L) ; static int LuaEmtAddArcMove( lua_State* L) ; + static int LuaEmtGetMoveType( lua_State* L) ; static int LuaEmtGetAxesPos( lua_State* L) ; static int LuaEmtLinkRawPartToGroup( lua_State* L) ; static int LuaEmtUnlinkRawPartFromGroup( lua_State* L) ; @@ -315,7 +317,7 @@ class Machine //---------------------------------------------------------------------------- template bool -Machine::LuaSetGlobVar( const std::string& sVar, const T& Val, bool bMchRestore) +Machine::LuaSetGlobVar( const std::string& sVar, const T& Val) { // imposto contesto corretto int nOldCtx = ExeGetCurrentContext() ; @@ -329,8 +331,8 @@ Machine::LuaSetGlobVar( const std::string& sVar, const T& Val, bool bMchRestore) // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; - // ripristino o reset dell'oggetto corrente per Lua - m_pMchLua = ( bMchRestore ? pOldMchLua : nullptr) ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } @@ -344,13 +346,14 @@ Machine::LuaGetGlobVar( const std::string& sVar, T& Val) if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo la lettura bool bOk = ::LuaGetGlobVar( 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 dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } diff --git a/MachineCalc.cpp b/MachineCalc.cpp index 5bf557b..e9de76c 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -28,27 +28,28 @@ using namespace std ; //---------------------------------------------------------------------------- -static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo -static const string EVAR_TABNAME = ".TABNAME" ; // (string) nome della tavola macchina -static const string EVAR_HEAD = ".HEAD" ; // (string) nome della testa -static const string EVAR_EXIT = ".EXIT" ; // (int) numero dell'uscita -static const string EVAR_TOOL = ".TOOL" ; // (string) nome dell'utensile -static const string EVAR_TOTDIAM = ".TOTDIAM" ; // (num) diametro di ingombro dell'utensile -static const string EVAR_TOTLEN = ".TOTLEN" ; // (num) lunghezza di ingombro dell'utensile -static const string EVAR_L1 = ".L1" ; // (num) valore del primo asse lineare -static const string EVAR_L2 = ".L2" ; // (num) valore del secondo asse lineare -static const string EVAR_L3 = ".L3" ; // (num) valore del terzo asse lineare -static const string EVAR_R1 = ".R1" ; // (num) valore del primo asse rotante -static const string EVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante -static const string EVAR_R3 = ".R3" ; // (num) valore del terzo asse rotante -static const string EVAR_R4 = ".R4" ; // (num) valore del quarto asse rotante -static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) -static const string EVAR_STAT = ".STAT" ; // OUT (int) codice di stato ( 0 = ok) -static const string EVAR_AUXINFO = ".AUXINFO" ; // OUT (string) stringa con info ausiliarie +static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo +static const string EVAR_TABNAME = ".TABNAME" ; // (string) nome della tavola macchina +static const string EVAR_HEAD = ".HEAD" ; // (string) nome della testa +static const string EVAR_EXIT = ".EXIT" ; // (int) numero dell'uscita +static const string EVAR_TOOL = ".TOOL" ; // (string) nome dell'utensile +static const string EVAR_TOTDIAM = ".TOTDIAM" ; // (num) diametro di ingombro dell'utensile +static const string EVAR_TOTLEN = ".TOTLEN" ; // (num) lunghezza di ingombro dell'utensile +static const string EVAR_L1 = ".L1" ; // (num) valore del primo asse lineare +static const string EVAR_L2 = ".L2" ; // (num) valore del secondo asse lineare +static const string EVAR_L3 = ".L3" ; // (num) valore del terzo asse lineare +static const string EVAR_R1 = ".R1" ; // (num) valore del primo asse rotante +static const string EVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante +static const string EVAR_R3 = ".R3" ; // (num) valore del terzo asse rotante +static const string EVAR_R4 = ".R4" ; // (num) valore del quarto asse rotante +static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) +static const string EVAR_STAT = ".STAT" ; // OUT (int) codice di stato ( 0 = ok) +static const string EVAR_AUXINFO = ".AUXINFO" ; // OUT (string) stringa con info ausiliarie +static const string EMC_VAR_BACKUP = "QQQ_EMC" ; // nome del backup della tabella sopra indicata +static const string AXIS_NAME_PROTECTEDAREAS = "PRA" ; static const string ON_SET_TABLE = "OnSetTable" ; static const string ON_SET_HEAD = "OnSetHead" ; static const string ON_VERIFY_PROTECTEDAREAS = "OnVerifyProtectedAreas" ; -static const string AXIS_NAME_PROTECTEDAREAS = "PRA" ; //---------------------------------------------------------------------------- @@ -66,6 +67,8 @@ Machine::SetCurrTable( const string& sTable) } // lancio eventuale funzione lua di personalizzazione if ( LuaExistsFunction( ON_SET_TABLE)) { + // salvo eventuale variabile EMC_VAR già presente + bool bOldEMC = LuaChangeNameGlobVar( EMC_VAR, EMC_VAR_BACKUP) ; // definisco variabili bool bOk = LuaCreateGlobTable( EMC_VAR) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_TABNAME, sTable) ; @@ -73,6 +76,9 @@ Machine::SetCurrTable( const string& sTable) bOk = bOk && LuaCallFunction( ON_SET_TABLE) ; // reset variabili bOk = bOk && LuaResetGlobVar( EMC_VAR) ; + // ripristino eventuale variabile EMC_VAR già presente + if ( bOldEMC) + LuaChangeNameGlobVar( EMC_VAR_BACKUP, EMC_VAR) ; // restituisco risultato return bOk ; } @@ -267,6 +273,8 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) m_dCalcTOvRad = dTOvDiam / 2 ; // lancio eventuale funzione lua di personalizzazione if ( LuaExistsFunction( ON_SET_HEAD)) { + // salvo eventuale variabile EMC_VAR già presente + bool bOldEMC = LuaChangeNameGlobVar( EMC_VAR, EMC_VAR_BACKUP) ; // definisco variabili bool bOk = LuaCreateGlobTable( EMC_VAR) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_HEAD, sHead) ; @@ -278,6 +286,9 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) bOk = bOk && LuaCallFunction( ON_SET_HEAD) ; // reset variabili bOk = bOk && LuaResetGlobVar( EMC_VAR) ; + // ripristino eventuale variabile EMC_VAR già presente + if ( bOldEMC) + LuaChangeNameGlobVar( EMC_VAR_BACKUP, EMC_VAR) ; // in caso di errore esco if ( ! bOk) return false ; @@ -1392,6 +1403,8 @@ Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& // default bool bOk = true ; int nErr = 99 ; + // salvo eventuale variabile EMC_VAR già presente + bool bOldEMC = LuaChangeNameGlobVar( EMC_VAR, EMC_VAR_BACKUP) ; // definisco variabili bOk = bOk && LuaCreateGlobTable( EMC_VAR) ; bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_L1, dX) ; @@ -1426,6 +1439,9 @@ Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& } // reset variabili bOk = LuaResetGlobVar( EMC_VAR) && bOk ; + // ripristino eventuale variabile EMC_VAR già presente + if ( bOldEMC) + LuaChangeNameGlobVar( EMC_VAR_BACKUP, EMC_VAR) ; // esco return bOk ; } diff --git a/MachineLua.cpp b/MachineLua.cpp index 611715d..9db3f3b 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -107,6 +107,7 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtAddLinearMove", Machine::LuaEmtAddLinearMove) ; m_LuaMgr.RegisterFunction( "EmtAddArcMove", Machine::LuaEmtAddArcMove) ; // registro le funzioni di lettura entità CL per lua + m_LuaMgr.RegisterFunction( "EmtGetMoveType", Machine::LuaEmtGetMoveType) ; m_LuaMgr.RegisterFunction( "EmtGetAxesPos", Machine::LuaEmtGetAxesPos) ; // registro le funzioni di scrittura part program per lua m_LuaMgr.RegisterFunction( "EmtWrite", Machine::LuaEmtWrite) ; @@ -143,14 +144,15 @@ Machine::LuaExistsFunction( const string& sFun) const if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = const_cast( this) ; // verifico esistenza della funzione bool bOk = m_LuaMgr.ExistsFunction( sFun) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; - // reset dell'oggetto corrente per Lua - m_pMchLua = nullptr ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } @@ -169,17 +171,18 @@ Machine::LuaCallFunction( const string& sFun, bool bSetModifiedOff) ExeDisableModified() ; } // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo la funzione bool bOk = m_LuaMgr.CallFunction( sFun, 0) ; - // reset dell'oggetto corrente per Lua - m_pMchLua = nullptr ; // ripristino gestione segnalazione modifiche progetto if ( bSetModifiedOff && bOldMod) ExeEnableModified() ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } @@ -192,14 +195,15 @@ Machine::LuaCreateGlobTable( const string& sName) if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo la funzione bool bOk = ::LuaCreateGlobTable( m_LuaMgr.GetLuaState(), sName) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; - // reset dell'oggetto corrente per Lua - m_pMchLua = nullptr ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } @@ -212,17 +216,39 @@ Machine::LuaResetGlobVar( const string& sName) if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo la funzione bool bOk = ::LuaResetGlobVar( m_LuaMgr.GetLuaState(), sName) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; - // reset dell'oggetto corrente per Lua - m_pMchLua = nullptr ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } +//---------------------------------------------------------------------------- +bool +Machine::LuaChangeNameGlobVar( const string& sOldName, const string& sNewName) +{ + // 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 la funzione + bool bExists = ::LuaChangeNameGlobVar( m_LuaMgr.GetLuaState(), sOldName, sNewName) ; + // ripristino contesto originale + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( nOldCtx) ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; + return bExists ; +} + //---------------------------------------------------------------------------- bool Machine::LuaLoadMachine( const string& sFile) @@ -237,6 +263,7 @@ Machine::LuaLoadMachine( const string& sFile) // disabilito gestione segnalazione modifiche progetto SetModifiedOff modOff ; // imposto l'oggetto corrente per Lua + Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // carico la macchina bool bOk = m_LuaMgr.ExecFile( sFile) ; @@ -252,8 +279,8 @@ Machine::LuaLoadMachine( const string& sFile) // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; - // reset dell'oggetto corrente per Lua - m_pMchLua = nullptr ; + // ripristino dell'oggetto corrente per Lua + m_pMchLua = pOldMchLua ; return bOk ; } diff --git a/MachineLuaCL.cpp b/MachineLuaCL.cpp index 11e3431..82c4302 100644 --- a/MachineLuaCL.cpp +++ b/MachineLuaCL.cpp @@ -263,6 +263,31 @@ Machine::LuaEmtAddArcMove( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtGetMoveType( lua_State* L) +{ + // 1 parametri : nClEntId + int nClEntId ; + LuaCheckParam( L, 1, nClEntId) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva valida + if ( m_pMchLua == nullptr || + m_pMchLua->m_pMchMgr == nullptr || m_pMchLua->m_pGeomDB == nullptr) + return luaL_error( L, " Unknown Machine") ; + // recupero l'oggetto CamData + const CamData* pCamData = GetCamData( m_pMchLua->m_pGeomDB->GetUserObj( nClEntId)) ; + bool bOk = ( pCamData != nullptr) ; + if ( bOk) { + int nMove = pCamData->GetMoveType() ; + LuaSetParam( L, nMove) ; + } + else + LuaSetParam( L) ; + + return 1 ; +} + //---------------------------------------------------------------------------- int Machine::LuaEmtGetAxesPos( lua_State* L) @@ -287,4 +312,4 @@ Machine::LuaEmtGetAxesPos( lua_State* L) LuaSetParam( L) ; return 1 ; -} \ No newline at end of file +} diff --git a/Simulator.cpp b/Simulator.cpp index 6fc6739..cbef702 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -136,8 +136,8 @@ Simulator::Start( bool bFirst) // Definisco tabella variabili globali if ( ! m_pMachine->LuaCreateGlobTable( GLOB_VAR)) bOk = false ; - m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_INCHES, ! ExeUiUnitsAreMM(), true) ; - m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep, true) ; + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_INCHES, ! ExeUiUnitsAreMM()) ; + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep) ; // Richiamo funzione su avvio simulazione if ( ! OnStart( bFirst)) @@ -372,7 +372,7 @@ Simulator::SetStep( double dStep) { m_dStep = Clamp( dStep, MIN_STEP, MAX_STEP) ; // imposto step per movimenti gestiti nelle macro di simulazione ( con ripristino macchina Lua originale) - m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep, true) ; + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMSTEP, m_dStep) ; return true ; } @@ -382,7 +382,7 @@ Simulator::SetUiStatus( int nUiStatus) { m_nUiStatus = 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) ; + m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_SIMUISTAT, m_nUiStatus) ; return true ; }