diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 3b4927f..79d5298 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/MachMgr.h b/MachMgr.h index 33522c2..b2d0a0a 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -433,6 +433,8 @@ class MachMgr : public IMachMgr const ToolData* GetMachiningToolData( void) const ; // Simulation bool SimAddCollisionObj( int nInd, int nFrameId, int nType, double dPar1, double dPar2, double dPar3) ; + bool SimExecCollisionCheck( int& nCdInd, int& nObjInd) ; + bool SimOnCollision( int nCdInd, int nObjInd, int& nErr) ; // Machine bool GetHeadAbove( const std::string& sHead) const ; double GetAngDeltaMinForHome( void) const ; diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index 72f7439..6ab8ef6 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -158,3 +158,25 @@ MachMgr::SimAddCollisionObj( int nInd, int nFrameId, int nType, double dPar1, do // aggiungo un oggetto da verificare per la collisione con il grezzo return m_pSimul->AddCollisionObj( nInd, nFrameId, nType, dPar1, dPar2, dPar3) ; } + +//---------------------------------------------------------------------------- +bool +MachMgr::SimExecCollisionCheck( int& nCdInd, int& nObjInd) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // eseguo verifica di collisione (nessuna collisione -> true) + return m_pSimul->ExecCollisionCheck( nCdInd, nObjInd) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SimOnCollision( int nCdInd, int nObjInd, int& nErr) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // lancio funzione di gestione collisione + return m_pSimul->OnCollision( nCdInd, nObjInd, nErr) ; +} diff --git a/Machine.h b/Machine.h index 9f40508..32a9009 100644 --- a/Machine.h +++ b/Machine.h @@ -327,6 +327,8 @@ class Machine static int LuaEmtSetLastError( lua_State* L) ; static int LuaEmtSetWarning( lua_State* L) ; static int LuaEmtAddCollisionObj( lua_State* L) ; + static int LuaEmtExecCollisionCheck( lua_State* L) ; + static int LuaEmtOnCollision( lua_State* L) ; } ; //---------------------------------------------------------------------------- diff --git a/MachineLua.cpp b/MachineLua.cpp index e203a88..cc9bebf 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -120,6 +120,10 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtSetWarning", Machine::LuaEmtSetWarning) ; // registro la funzione per aggiungere un oggetto da verificare per la collisione in simulazione m_LuaMgr.RegisterFunction( "EmtAddCollisionObj", Machine::LuaEmtAddCollisionObj) ; + // registro la funzione di esecuzione della verifica di collisione in simulazione + m_LuaMgr.RegisterFunction( "EmtExecCollisionCheck", Machine::LuaEmtExecCollisionCheck) ; + // registro la funzione di gestione della collisione in simulazione + m_LuaMgr.RegisterFunction( "EmtOnCollision", Machine::LuaEmtOnCollision) ; return true ; } @@ -1179,3 +1183,44 @@ Machine::LuaEmtAddCollisionObj( lua_State* L) LuaSetParam( L, bOk) ; return 1 ; } + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtExecCollisionCheck( lua_State* L) +{ + // Nessun parametro + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // eseguo la verifica di collisione (nessuna collisione -> true) + int nCdInd = -1, nObjInd = -1 ; + bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimExecCollisionCheck( nCdInd, nObjInd)) ; + // assegno risultato + LuaSetParam( L, bOk) ; + LuaSetParam( L, nCdInd) ; + LuaSetParam( L, nObjInd) ; + return 3 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtOnCollision( lua_State* L) +{ + // Due parametri : nCdInd, nObjInd + int nCdInd ; + LuaCheckParam( L, 1, nCdInd) + int nObjInd ; + LuaCheckParam( L, 2, nObjInd) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // eseguo la verifica di collisione (nessuna collisione -> true) + int nErr = 0 ; + bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimOnCollision( nCdInd, nObjInd, nErr)) ; + // assegno risultato + LuaSetParam( L, bOk) ; + LuaSetParam( L, nErr) ; + return 2 ; +} diff --git a/Simulator.h b/Simulator.h index 2e454eb..2fc72c9 100644 --- a/Simulator.h +++ b/Simulator.h @@ -38,6 +38,8 @@ class Simulator bool GetOperationInfo( std::string& sName, int& nType) const ; bool GetMoveInfo( int& nGmove, double& dFeed) const ; bool AddCollisionObj( int nInd, int nFrameId, int nType, double dPar1, double dPar2, double dPar3) ; + bool ExecCollisionCheck( int& nCdInd, int& nObjInd) ; + bool OnCollision( int nCdInd, int nObjInd, int& nErr) ; private : bool UpdateTool( bool bFirst = false) ; @@ -62,7 +64,6 @@ class Simulator const Point3d& ptHf, const Vector3d& vtHf, const Vector3d& vtAf, const Frame3d& frVzmF) ; bool NeedCollisionCheck( void) const { return ( ! m_CollObj.empty() && ! m_CdId.empty()) ; } - bool ExecCollisionCheck( int& nCdInd, int& nObjInd) ; bool Stopped( void) { return ( m_nUiStatus == MCH_UISIM_STOP) ; } bool OnStart( bool bFirst) ; @@ -85,7 +86,6 @@ class Simulator bool OnPathEnd( int nAE) ; bool OnMoveStart( const CamData* pCamData, int& nErr) ; bool OnMoveEnd( void) ; - bool OnCollision( int nCdInd, int nObjInd, int& nErr) ; bool OnResetMachine( void) ; private :