From 8903b225a81fb405b451f9b41a16e704382c6908 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 28 Apr 2017 11:03:16 +0000 Subject: [PATCH] EgtMachKernel : - aggiunte funzioni lua di macchina EmtLinkPartToGroup, EmtUnlinkPartFromGroup e EmtUnlinkAllPartsFromGroups. --- MachMgrPhases.cpp | 4 ++- Machine.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++ Machine.h | 8 +++++ MachineLua.cpp | 57 +++++++++++++++++++++++++++++++++ Operation.cpp | 3 +- 5 files changed, 150 insertions(+), 2 deletions(-) diff --git a/MachMgrPhases.cpp b/MachMgrPhases.cpp index 5d38bbc..90f3925 100644 --- a/MachMgrPhases.cpp +++ b/MachMgrPhases.cpp @@ -87,7 +87,9 @@ MachMgr::PrepareCurrPhase( int nPhase, bool bDoDisp, bool bForced) m_pGeomDB->SetStatus( nFxtId, GDB_ST_OFF) ; nFxtId = m_pGeomDB->GetNextGroup( nFxtId) ; } - // riporto tutti i grezzi linkati nel gruppo dei grezzi + // riporto tutti i pezzi linkati nel loro grezzo + pMach->UnlinkAllPartsFromGroups() ; + // riporto tutti i grezzi linkati nel gruppo dei grezzi pMach->UnlinkAllRawPartsFromGroups() ; // tolgo i pezzi dai grezzi che non appartengono alla fase int nRawId = GetFirstRawPart() ; diff --git a/Machine.cpp b/Machine.cpp index 771353c..91f655e 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -1033,3 +1033,83 @@ Machine::UnlinkAllFixturesFromGroups( void) } return true ; } + +//---------------------------------------------------------------------------- +const string KEY_SOURCE_RAW_ID = "SouRawId" ; +const string KEY_ORIG_REF = "OrigRef" ; + +//---------------------------------------------------------------------------- +bool +Machine::LinkPartToGroup( int nPartId, const std::string& sGroupName) +{ + // verifico DB geometrico e gestore lavorazioni + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // verifico appartenenza del pezzo ad un grezzo + int nRawId = m_pMchMgr->GetRawPartFromPart( nPartId) ; + if ( nRawId == GDB_ID_NULL) + return false ; + // recupero il gruppo di macchina indicato + int nGrpId = GetGroup( sGroupName) ; + if ( nGrpId == GDB_ID_NULL) + return false ; + // scrivo nel pezzo l'identificativo del grezzo di origine + m_pGeomDB->SetInfo( nPartId, KEY_SOURCE_RAW_ID, nRawId) ; + // scrivo nel pezzo il suo riferimento originale + m_pGeomDB->SetInfo( nPartId, KEY_ORIG_REF, *m_pGeomDB->GetGroupFrame( nPartId)) ; + // aggancio il pezzo al gruppo + if ( ! m_pGeomDB->RelocateGlob( nPartId, nGrpId)) + return false ; + // inserisco il pezzo nell'elenco dei linkati + m_vLinkedParts.push_back( nPartId) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::IsLinkedPart( int nPartId) const +{ + return ( find( m_vLinkedParts.begin(), m_vLinkedParts.end(), nPartId) != m_vLinkedParts.end()) ; +} + +//---------------------------------------------------------------------------- +bool +Machine::UnlinkPartFromGroup( int nPartId) +{ + // verifico DB geometrico e gestore lavorazioni + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // recupero il riferimento originale del pezzo + Frame3d frPart ; + if ( ! m_pGeomDB->GetInfo( nPartId, KEY_ORIG_REF, frPart)) + return false ; + m_pGeomDB->RemoveInfo( nPartId, KEY_ORIG_REF) ; + // recupero il grezzo di origine dalle info del pezzo + int nRawId ; + if ( ! m_pGeomDB->GetInfo( nPartId, KEY_SOURCE_RAW_ID, nRawId)) + return false ; + m_pGeomDB->RemoveInfo( nPartId, KEY_SOURCE_RAW_ID) ; + // verifico che il pezzo indicato sia nell'elenco dei linkati + auto iIter = find( m_vLinkedParts.begin(), m_vLinkedParts.end(), nPartId) ; + if ( iIter == m_vLinkedParts.end()) + return false ; + // riporto il pezzo nel suo grezzo + if ( ! m_pGeomDB->Relocate( nPartId, nRawId)) + return false ; + *m_pGeomDB->GetGroupFrame( nPartId) = frPart ; + // tolgo il pezzo dall'elenco dei linkati + m_vLinkedParts.erase( iIter) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::UnlinkAllPartsFromGroups( void) +{ + while ( m_vLinkedParts.size() > 0) { + int nPartId = m_vLinkedParts.back() ; + if ( ! UnlinkPartFromGroup( nPartId)) + return false ; + } + return true ; +} diff --git a/Machine.h b/Machine.h index 7fbd00e..351f44a 100644 --- a/Machine.h +++ b/Machine.h @@ -128,6 +128,10 @@ class Machine bool IsLinkedFixture( int nFxtId) const ; bool UnlinkFixtureFromGroup( int nFxtId) ; bool UnlinkAllFixturesFromGroups( void) ; + bool LinkPartToGroup( int nPartId, const std::string& sGroupName) ; + bool IsLinkedPart( int nPartId) const ; + bool UnlinkPartFromGroup( int nPartId) ; + bool UnlinkAllPartsFromGroups( void) ; bool LuaExistsFunction( const std::string& sFun) ; bool LuaCallFunction( const std::string& sFun, bool bSetModifiedOff = true) ; bool LuaCreateGlobTable( const std::string& sName) ; @@ -223,6 +227,7 @@ class Machine double m_dExitMaxAdjust ; // massimo aggiustamento uscita da geometria a descrizione cinematica INTVECTOR m_vLinkedRawParts ; // elenco dei grezzi agganciati a gruppi della macchina INTVECTOR m_vLinkedFixtures ; // elenco dei bloccaggi agganciati a gruppi della macchina + INTVECTOR m_vLinkedParts ; // elenco dei pezzi agganciati a gruppi della macchina // dati di calcolo int m_nCalcTabId ; // tavola corrente per calcoli int m_nCalcHeadId ; // testa corrente per calcoli @@ -267,6 +272,9 @@ class Machine static int LuaEmtLinkFixtureToGroup( lua_State* L) ; static int LuaEmtUnlinkFixtureFromGroup( lua_State* L) ; static int LuaEmtUnlinkAllFixturesFromGroups( lua_State* L) ; + static int LuaEmtLinkPartToGroup( lua_State* L) ; + static int LuaEmtUnlinkPartFromGroup( lua_State* L) ; + static int LuaEmtUnlinkAllPartsFromGroups( lua_State* L) ; static int LuaEmtWrite( lua_State* L) ; } ; diff --git a/MachineLua.cpp b/MachineLua.cpp index 9d3cda1..8fcf54f 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -92,6 +92,9 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtLinkFixtureToGroup", Machine::LuaEmtLinkFixtureToGroup) ; m_LuaMgr.RegisterFunction( "EmtUnlinkFixtureFromGroup", Machine::LuaEmtUnlinkFixtureFromGroup) ; m_LuaMgr.RegisterFunction( "EmtUnlinkAllFixturesFromGroups", Machine::LuaEmtUnlinkAllFixturesFromGroups) ; + m_LuaMgr.RegisterFunction( "EmtLinkPartToGroup", Machine::LuaEmtLinkPartToGroup) ; + m_LuaMgr.RegisterFunction( "EmtUnlinkPartFromGroup", Machine::LuaEmtUnlinkPartFromGroup) ; + m_LuaMgr.RegisterFunction( "EmtUnlinkAllPartsFromGroups", Machine::LuaEmtUnlinkAllPartsFromGroups) ; // registro le funzioni di definizione entità CL per lua m_LuaMgr.RegisterFunction( "EmtAddRapidStart", Machine::LuaEmtAddRapidStart) ; m_LuaMgr.RegisterFunction( "EmtAddRapidMove", Machine::LuaEmtAddRapidMove) ; @@ -844,6 +847,60 @@ Machine::LuaEmtUnlinkAllFixturesFromGroups( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtLinkPartToGroup( lua_State* L) +{ + // 2 parametri : nPartId, sGroupName + int nPartId ; + LuaCheckParam( L, 1, nPartId) + string sGroupName ; + LuaCheckParam( L, 2, sGroupName) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // aggancio il pezzo al gruppo + bool bOk = m_pMchLua->LinkPartToGroup( nPartId, sGroupName) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtUnlinkPartFromGroup( lua_State* L) +{ + // 1 parametro : nRawId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // riporto il pezzo nel suo grezzo + bool bOk = m_pMchLua->UnlinkPartFromGroup( nPartId) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtUnlinkAllPartsFromGroups( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // riporto tutti i pezzi linkati nel loro grezzo + bool bOk = m_pMchLua->UnlinkAllPartsFromGroups() ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //---------------------------------------------------------------------------- int Machine::LuaEmtWrite( lua_State* L) diff --git a/Operation.cpp b/Operation.cpp index 343c97e..c081890 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -1740,7 +1740,8 @@ Operation::TestCollisionAvoid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEn } // Riporto la macchina in home pMch->ResetAllAxesPos() ; - // Sgancio grezzi e sottopezzi dalla tavola corrente + // Sgancio pezzi, grezzi e sottopezzi dalla tavola corrente + pMch->UnlinkAllPartsFromGroups() ; pMch->UnlinkAllRawPartsFromGroups() ; pMch->UnlinkAllFixturesFromGroups() ;