EgtMachKernel :

- aggiunte funzioni lua di macchina EmtLinkPartToGroup, EmtUnlinkPartFromGroup e EmtUnlinkAllPartsFromGroups.
This commit is contained in:
Dario Sassi
2017-04-28 11:03:16 +00:00
parent 3660ddbf5a
commit 8903b225a8
5 changed files with 150 additions and 2 deletions
+80
View File
@@ -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 ;
}