diff --git a/MachMgr.h b/MachMgr.h index e3a1c0c..bdee15b 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -488,11 +488,15 @@ class MachMgr : public IMachMgr bool GetOperationNewName( std::string& sName) const ; const ToolData* GetMachiningToolData( void) const ; // Simulation - bool SimAddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) ; + bool SimAddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, + const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) ; + bool SimRemoveCollisionObj( int nFrameId) ; + bool SimGetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) const ; bool SimExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) ; bool SimOnCollision( int nCdInd, int nObjInd, int& nErr) ; - bool SimSetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, double dPar1, double dPar2, - const INTVECTOR& vVmill, bool bFirst) ; + bool SimSetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, + double dPar1, double dPar2, 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, const std::string& sPar2) ; diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index 3ded32a..35e1cef 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -176,6 +176,29 @@ MachMgr::SimAddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, co return m_pSimul->AddCollisionObj( nInd, bToolOn, nFrameId, nType, vtMove, dPar1, dPar2, dPar3) ; } +//---------------------------------------------------------------------------- +bool +MachMgr::SimRemoveCollisionObj( int nFrameId) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // rimuovo gli oggetti da verificare per la collisione con il grezzo con FrameId indicato + return m_pSimul->RemoveCollisionObj( nFrameId) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SimGetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) const +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // recupero i dati dell'oggetto di collisione di posizione indicata nel relativo vettore + return m_pSimul->GetCollisionObj( nPos, nInd, bToolOn, nFrameId, nType, vtMove, dPar1, dPar2, dPar3) ; +} + //---------------------------------------------------------------------------- bool MachMgr::SimExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) diff --git a/Machine.h b/Machine.h index 5fbc446..f8f89a1 100644 --- a/Machine.h +++ b/Machine.h @@ -402,6 +402,8 @@ class Machine static int LuaEmtSetWarning( lua_State* L) ; static int LuaEmtAddCollisionObj( lua_State* L) ; static int LuaEmtAddCollisionObjEx( lua_State* L) ; + static int LuaEmtRemoveCollisionObj( lua_State* L) ; + static int LuaEmtGetCollisionObj( lua_State* L) ; static int LuaEmtExecCollisionCheck( lua_State* L) ; static int LuaEmtOnCollision( lua_State* L) ; static int LuaEmtSetToolForVmill( lua_State* L) ; diff --git a/MachineLua.cpp b/MachineLua.cpp index 63edcc0..ba6c000 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -144,6 +144,10 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtAddCollisionObj", Machine::LuaEmtAddCollisionObj) ; // registro la funzione estesa per aggiungere un oggetto da verificare per la collisione in simulazione m_LuaMgr.RegisterFunction( "EmtAddCollisionObjEx", Machine::LuaEmtAddCollisionObjEx) ; + // registro la funzione per rimuovere oggetti con dato FrameId da verificare per la collisione in simulazione + m_LuaMgr.RegisterFunction( "EmtRemoveCollisionObj", Machine::LuaEmtRemoveCollisionObj) ; + // registro la funzione per avere i dati dell'oggetto con posizione indicata nel vettore da verificare per la collisione in simulazione + m_LuaMgr.RegisterFunction( "EmtGetCollisionObj", Machine::LuaEmtGetCollisionObj) ; // 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 @@ -1428,6 +1432,65 @@ Machine::LuaEmtAddCollisionObjEx( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtRemoveCollisionObj( lua_State* L) +{ + // 1 parametro : nFrameId + int nFrameId ; + LuaCheckParam( L, 1, nFrameId) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // assegno i dati + bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && m_pMchLua->m_pMchMgr->SimRemoveCollisionObj( nFrameId)) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtGetCollisionObj( lua_State* L) +{ + // 1 parametro : nPos + int nPos ; + LuaCheckParam( L, 1, nPos) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // recupero i dati + int nInd ; + bool bToolOn ; + int nFrameId ; + int nType ; + Vector3d vtMove ; + double dPar1 ; + double dPar2 ; + double dPar3 ; + bool bOk = ( m_pMchLua->m_pMchMgr != nullptr && + m_pMchLua->m_pMchMgr->SimGetCollisionObj( nPos, nInd, bToolOn, nFrameId, nType, vtMove, dPar1, dPar2, dPar3)) ; + // assegno risultato + if ( bOk) { + LuaSetParam( L, true) ; + LuaSetParam( L, nInd) ; + LuaSetParam( L, bToolOn) ; + LuaSetParam( L, nFrameId) ; + LuaSetParam( L, nType) ; + LuaSetParam( L, vtMove) ; + LuaSetParam( L, dPar1) ; + LuaSetParam( L, dPar2) ; + LuaSetParam( L, dPar3) ; + return 9 ; + } + else { + LuaSetParam( L, false) ; + return 1 ; + } +} + //---------------------------------------------------------------------------- int Machine::LuaEmtExecCollisionCheck( lua_State* L) diff --git a/Simulator.h b/Simulator.h index 7c2ba80..2ce446d 100644 --- a/Simulator.h +++ b/Simulator.h @@ -53,6 +53,9 @@ class __declspec( novtable) ISimulator virtual bool GetMoveInfo( int& nGmove, double& dFeed) const = 0 ; virtual bool AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) = 0 ; + virtual bool RemoveCollisionObj( int nFrameId) = 0 ; + virtual bool GetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) = 0 ; virtual bool ExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) = 0 ; virtual bool OnCollision( int nCdInd, int nObjInd, int& nErr) = 0 ; virtual bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, diff --git a/SimulatorMP.cpp b/SimulatorMP.cpp index 199e4c8..2bcb705 100644 --- a/SimulatorMP.cpp +++ b/SimulatorMP.cpp @@ -2336,6 +2336,34 @@ SimulatorMP::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, c return true ; } +//---------------------------------------------------------------------------- +bool +SimulatorMP::RemoveCollisionObj( int nFrameId) +{ + erase_if( m_CollObj, [nFrameId]( CollObj Item) { return ( Item.nFrameId == nFrameId) ; }) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +SimulatorMP::GetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) +{ + // posizione nel vettore non valida + if ( nPos < 0 || nPos >= ssize( m_CollObj)) + return false ; + // assegno i dati + nInd = m_CollObj[nPos].nInd ; + bToolOn = m_CollObj[nPos].bToolOn ; + nFrameId = m_CollObj[nPos].nFrameId ; + nType = m_CollObj[nPos].nType ; + vtMove = m_CollObj[nPos].vtMove ; + dPar1 = m_CollObj[nPos].dPar1 ; + dPar2 = m_CollObj[nPos].dPar2 ; + dPar3 = m_CollObj[nPos].dPar3 ; + return true ; +} + //---------------------------------------------------------------------------- bool SimulatorMP::SetToolForVmill( const string& sTool, const string& sHead, int nExit, int nFlag, double dPar1, double dPar2, diff --git a/SimulatorMP.h b/SimulatorMP.h index afb1f83..9635854 100644 --- a/SimulatorMP.h +++ b/SimulatorMP.h @@ -40,6 +40,9 @@ class SimulatorMP : public ISimulator bool GetMoveInfo( int& nGmove, double& dFeed) const override ; bool AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) override ; + bool RemoveCollisionObj( int nFrameId) override ; + bool GetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) override ; bool ExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) override ; bool OnCollision( int nCdInd, int nObjInd, int& nErr) override ; bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag, diff --git a/SimulatorSP.cpp b/SimulatorSP.cpp index f2e1e92..f3572fc 100644 --- a/SimulatorSP.cpp +++ b/SimulatorSP.cpp @@ -2343,7 +2343,8 @@ SimulatorSP::OnResetMachine( void) //---------------------------------------------------------------------------- bool -SimulatorSP::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) +SimulatorSP::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, + const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) { // verifiche sui parametri if ( nInd <= 0 || nFrameId <= GDB_ID_NULL) @@ -2374,6 +2375,35 @@ SimulatorSP::AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, c } // aggiungo al vettore m_CollObj.emplace_back( nInd, bToolOn, nFrameId, nType, vtMove, dPar1, dPar2, dPar3) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +SimulatorSP::RemoveCollisionObj( int nFrameId) +{ + erase_if( m_CollObj, [nFrameId]( CollObj Item) { return ( Item.nFrameId == nFrameId) ; }) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +SimulatorSP::GetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) +{ + // posizione nel vettore non valida + if ( nPos < 0 || nPos >= ssize( m_CollObj)) + return false ; + // assegno i dati + nInd = m_CollObj[nPos].nInd ; + bToolOn = m_CollObj[nPos].bToolOn ; + nFrameId = m_CollObj[nPos].nFrameId ; + nType = m_CollObj[nPos].nType ; + vtMove = m_CollObj[nPos].vtMove ; + dPar1 = m_CollObj[nPos].dPar1 ; + dPar2 = m_CollObj[nPos].dPar2 ; + dPar3 = m_CollObj[nPos].dPar3 ; return true ; } diff --git a/SimulatorSP.h b/SimulatorSP.h index 983c3f6..ae54298 100644 --- a/SimulatorSP.h +++ b/SimulatorSP.h @@ -40,6 +40,9 @@ class SimulatorSP : public ISimulator bool GetMoveInfo( int& nGmove, double& dFeed) const override ; bool AddCollisionObj( int nInd, bool bToolOn, int nFrameId, int nType, const Vector3d& vtMove, double dPar1, double dPar2, double dPar3) override ; + bool RemoveCollisionObj( int nFrameId) override ; + bool GetCollisionObj( int nPos, int& nInd, bool& bToolOn, int& nFrameId, int& nType, + Vector3d& vtMove, double& dPar1, double& dPar2, double& dPar3) override ; bool ExecCollisionCheck( int& nCdInd, int& nObjInd, int nMoveType) override ; bool OnCollision( int nCdInd, int nObjInd, int& nErr) override ; bool SetToolForVmill( const std::string& sTool, const std::string& sHead, int nExit, int nFlag,