diff --git a/GdbExecutor.cpp b/GdbExecutor.cpp index 4bebc02..a6cc7b3 100644 --- a/GdbExecutor.cpp +++ b/GdbExecutor.cpp @@ -89,6 +89,8 @@ GdbExecutor::GdbExecutor( void) m_ExecMgr.Insert( "INF", &GdbExecutor::ExecuteInfo) ; m_ExecMgr.Insert( "INFO", &GdbExecutor::ExecuteInfo) ; m_ExecMgr.Insert( "COPY", &GdbExecutor::ExecuteCopy) ; + m_ExecMgr.Insert( "REL", &GdbExecutor::ExecuteRelocate) ; + m_ExecMgr.Insert( "RELOCATE", &GdbExecutor::ExecuteRelocate) ; m_ExecMgr.Insert( "ERASE", &GdbExecutor::ExecuteErase) ; m_ExecMgr.Insert( "MOV", &GdbExecutor::ExecuteTranslate) ; m_ExecMgr.Insert( "MOVE", &GdbExecutor::ExecuteTranslate) ; @@ -1506,6 +1508,34 @@ GdbExecutor::ExecuteCopy( const std::string& sCmd2, const STRVECTOR& vsParams) return ( nIdNew != GDB_ID_NULL) ; } +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteRelocate( const std::string& sCmd2, const STRVECTOR& vsParams) +{ + // 2 parametri ( Id, NewParentId) + if ( vsParams.size() != 2) + return false ; + // recupero lista nomi + INTVECTOR vnNames ; + if ( ! GetNamesParam( vsParams[0], vnNames)) + return false ; + // recupero flag per globale + bool bGlob = ( sCmd2 == "GLOB" || sCmd2 == "G") ; + // esecuzione rilocazioni + INTVECTOR::iterator Iter ; + for ( Iter = vnNames.begin() ; Iter != vnNames.end() ; ++Iter) { + if ( bGlob) { + if ( ! m_pGDB->RelocateGlob( *Iter, GetIdParam( vsParams[1]))) + return false ; + } + else { + if ( ! m_pGDB->Relocate( *Iter, GetIdParam( vsParams[1]))) + return false ; + } + } + return true ; +} + //---------------------------------------------------------------------------- bool GdbExecutor::ExecuteErase( const std::string& sCmd2, const STRVECTOR& vsParams) diff --git a/GdbExecutor.h b/GdbExecutor.h index d83c33e..0bb0ad8 100644 --- a/GdbExecutor.h +++ b/GdbExecutor.h @@ -61,6 +61,7 @@ class GdbExecutor : public IGdbExecutor bool ExecuteName( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteInfo( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteCopy( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteRelocate( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteErase( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteTranslate( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteRotate( const std::string& sCmd2, const STRVECTOR& vsParams) ; diff --git a/GeomDB.cpp b/GeomDB.cpp index a4fd7c1..f635267 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -306,10 +306,7 @@ GeomDB::AddToGeomDB( GdbObj* pGObj, int nParentId) if ( ! pGObj->AddTail( pGroup)) return false ; - // aggiorno gestore Id - m_IdManager.UpdateMaxId( pGObj->m_nId) ; - - // inserisco in mappa nomi + // inserisco in mappa Id return m_IdManager.AddObj( pGObj->m_nId, pGObj) ; } @@ -572,8 +569,8 @@ GeomDB::CopyGlob( int nIdSou, int nIdDest, int nParentIdDest) return GDB_ID_NULL ; // verifico esistenza del sorgente - GdbObj* pGdOSou ; - if ( ( pGdOSou = GetGdbObj( nIdSou)) == nullptr) + GdbObj* pGdOSou = GetGdbObj( nIdSou) ; + if ( pGdOSou == nullptr) return GDB_ID_NULL ; // recupero il riferimento del sorgente @@ -606,6 +603,64 @@ GeomDB::CopyGlob( int nIdSou, int nIdDest, int nParentIdDest) return nIdDest ; } +//---------------------------------------------------------------------------- +bool +GeomDB::Relocate( int nId, int nNewParentId, bool bGlob) +{ + // verifico esistenza dell'oggetto + GdbObj* pGdbObj = GetGdbObj( nId) ; + if ( pGdbObj == nullptr) + return false ; + + // verifico esistenza del padre + GdbGroup* pGroup = pGdbObj->GetParent() ; + if ( pGroup == nullptr) + return false ; + + // cerco il nuovo padre + GdbGroup* pNewGroup = GetGdbGroup( nNewParentId) ; + if ( pNewGroup == nullptr) + return false ; + + // se vecchio e nuovo padre coincidono, non devo fare alcunché + if ( pGroup->m_nId == pNewGroup->m_nId) + return true ; + + // se rilocazione in globale + if ( bGlob) { + // recupero il riferimento del sorgente + Frame3d frCurr ; + if ( ! pGroup->GetGlobFrame( frCurr)) + return false ; + // recupero il riferimento del nuovo padre + Frame3d frNew ; + if ( ! pNewGroup->GetGlobFrame( frNew)) + return false ; + // porto l'oggetto dal riferimento originale a quello nuovo + if ( ! AreSameFrame( frCurr, frNew)) { + pGdbObj->ToGlob( frCurr) ; + pGdbObj->ToLoc( frNew) ; + } + } + + // sistemazioni in eventuali GdbIterator con quell'oggetto corrente + m_IterManager.ResetObjIfSame( pGdbObj) ; + + // lo estraggo dalla posizione corrente del DB geometrico + pGdbObj->Remove() ; + + // lo inserisco in coda alla lista del padre + if ( ! pGdbObj->AddTail( pNewGroup)) { + // in caso di errore (condizione assai remota qui) cancello tutto + m_IdManager.RemoveObj( pGdbObj->m_nId) ; + m_SelManager.RemoveObj( pGdbObj) ; + delete pGdbObj ; + return false ; + } + + return true ; +} + //---------------------------------------------------------------------------- bool GeomDB::Erase( int nId) diff --git a/GeomDB.h b/GeomDB.h index d4a994e..3810a6b 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -49,6 +49,10 @@ class GeomDB : public IGeomDB virtual bool GetRefBBox( int nId, const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_NONE) const ; virtual int Copy( int nIdSou, int nIdDest, int nParentIdDest) ; virtual int CopyGlob( int nIdSou, int nIdDest, int nParentIdDest) ; + virtual bool Relocate( int nId, int nNewParentId) + { return Relocate( nId, nNewParentId, false) ; } + virtual bool RelocateGlob( int nId, int nNewParentId) + { return Relocate( nId, nNewParentId, true) ; } virtual bool Erase( int nId) ; virtual bool Translate( int nId, const Vector3d& vtMove) ; virtual bool TranslateGlob( int nId, const Vector3d& vtMove) ; @@ -124,6 +128,7 @@ class GeomDB : public IGeomDB GdbGroup* GetGdbGroup( int nId) { return dynamic_cast( GetGdbObj( nId)) ; } bool AddToGeomDB( GdbObj* pGObj, int nParentId) ; + bool Relocate( int nId, int nNewParentId, bool bGlob) ; bool Erase( GdbObj* pGObj) ; bool LoadHeader( Scanner& TheScanner) ; bool LoadOneObj( Scanner& TheScanner, bool& bEnd) ; diff --git a/IdManager.h b/IdManager.h index 186af9b..4289178 100644 --- a/IdManager.h +++ b/IdManager.h @@ -33,7 +33,8 @@ class IdManager else return nullptr ; } bool AddObj( int nId, GdbObj* pGObj) - { if ( nId > m_nMaxId) m_nMaxId = nId ; + { if ( nId > m_nMaxId) + m_nMaxId = nId ; return m_GdbIdMap.insert( INTPGDBO_UMAP::value_type( nId, pGObj)).second ; } bool RemoveObj( int nId) { m_GdbIdMap.erase( nId) ; return true ; } @@ -42,7 +43,8 @@ class IdManager int GetMaxId( void) const { return m_nMaxId ; } void UpdateMaxId( int nId) - { if ( nId > m_nMaxId) m_nMaxId = nId ; } + { if ( nId > m_nMaxId) + m_nMaxId = nId ; } private : typedef std::unordered_map< int, GdbObj*> INTPGDBO_UMAP ;