diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 04141b8..60d7285 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/GeomDB.cpp b/GeomDB.cpp index 964cf4b..ffe03d7 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -613,7 +613,7 @@ GeomDB::GetGdbObj( int nId) const // radice else if ( nId == GDB_ID_ROOT) return &m_GrpRadix ; - // un nodo qualubque + // un nodo qualunque else return m_IdManager.FindObj( nId) ; } @@ -660,7 +660,7 @@ GeomDB::InsertInGeomDB( GdbObj* pGObj, int nRefId, int nSonBeforeAfter, bool bLo return false ; } // inserisco come figlio, in testa alla lista del padre - else if ( nSonBeforeAfter == GDB_FIRST_SON){ + else if ( nSonBeforeAfter == GDB_FIRST_SON) { GdbGroup* pGroup = ::GetGdbGroup( pGRef) ; if ( pGroup == nullptr) return false ; diff --git a/GeomDB.h b/GeomDB.h index 6e0f18a..ef16fb8 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -31,6 +31,8 @@ class GeomDB : public IGeomDB friend class GdbGeo ; friend int CopyGeoObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId, int nSonBeforeAfter, bool bGlob) ; friend int CopyGroupObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId, int nSonBeforeAfter, bool bGlob) ; + friend int DuplicateGeoObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId) ; + friend int DuplicateGroupObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId, bool bSkipTemp) ; public : ~GeomDB( void) override ; diff --git a/MultiGeomDB.cpp b/MultiGeomDB.cpp index b81b1cd..a5c43d8 100644 --- a/MultiGeomDB.cpp +++ b/MultiGeomDB.cpp @@ -23,9 +23,6 @@ using namespace std ; static int CopyGeoObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId, int nSonBeforeAfter, bool bGlob) { - // verifico i puntatori ai GeomDB - if ( pSouGDB == nullptr || pDstGDB == nullptr) - return GDB_ID_NULL ; // recupero l'oggetto da copiare dal GeomDB sorgente PtrOwner pGObj( pSouGDB->GetGeoObj( nSouId)->Clone()) ; if ( IsNull( pGObj)) @@ -109,7 +106,7 @@ CopyGroupObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, i nSonNewId = CopyGeoObj( pSouGDB, nSonSouId, pDstGDB, GDB_ID_NULL, nNewId, GDB_LAST_SON, false) ; // se altrimenti è un gruppo else if ( nSonSouType == GDB_TY_GROUP) - nSonNewId = CopyGroupObj( pSouGDB, nSonSouId, pDstGDB, GDB_ID_NULL, nNewId, GDB_LAST_SON, false) ; + nSonNewId = CopyGroupObj( pSouGDB, nSonSouId, pDstGDB, GDB_ID_NULL, nNewId, GDB_LAST_SON, false) ; // se copia non riuscita, esco con errore if ( nSonNewId == GDB_ID_NULL) return GDB_ID_NULL ; @@ -129,6 +126,9 @@ Copy( IGeomDB* pSouGeomDB, int nSouId, IGeomDB* pDestGeomDB, int nDestId, int nR GeomDB* pDstGDB = static_cast( pDestGeomDB) ; if ( pSouGDB == nullptr || pDstGDB == nullptr) return GDB_ID_NULL ; + // il sorgente non può essere il gruppo radice + if ( nSouId == GDB_ID_ROOT) + return GDB_ID_NULL ; // nuovo identificativo oggetto destinazione int nNewId = GDB_ID_NULL ; // recupero il tipo di oggetto sorgente @@ -158,3 +158,101 @@ CopyGlob( IGeomDB* pSouGeomDB, int nSouId, IGeomDB* pDestGeomDB, int nDestId, in { return Copy( pSouGeomDB, nSouId, pDestGeomDB, nDestId, nRefId, nSonBeforeAfter, true) ; } + +//---------------------------------------------------------------------------- +static int +DuplicateGeoObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId) +{ + // recupero l'oggetto da copiare dal GeomDB sorgente + PtrOwner pGObj( pSouGDB->GetGeoObj( nSouId)->Clone()) ; + if ( IsNull( pGObj)) + return GDB_ID_NULL ; + // lo inserisco nel GeomDB destinazione + int nNewId = pDstGDB->InsertGeoObj( nDestId, nRefId, GDB_LAST_SON, Release( pGObj)) ; + if ( nNewId != nDestId) { + pDstGDB->Erase( nNewId) ; + return GDB_ID_NULL ; + } + // copio le caratteristiche non geometriche + const GdbObj* pSouGdbObj = pSouGDB->GetGdbObj( nSouId) ; + GdbObj* pDstGdbObj = pDstGDB->GetGdbObj( nNewId) ; + if ( pSouGDB == nullptr || pDstGdbObj == nullptr || + ! pDstGdbObj->CopyAttribsFrom( pSouGdbObj) || + ! pDstGdbObj->CopyTextureDataFrom( pSouGdbObj) || + ! pDstGdbObj->CopyStippleDataFrom( pSouGdbObj) || + ! pDstGdbObj->CopyUserObjFrom( pSouGdbObj)) { + pDstGDB->Erase( nNewId) ; + return GDB_ID_NULL ; + } + + return nNewId ; +} + +//---------------------------------------------------------------------------- +static int +DuplicateGroupObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId, bool bSkipTemp) +{ + int nNewId = GDB_ID_ROOT ; + if ( nSouId != GDB_ID_ROOT) { + // recupero il riferimento del gruppo + Frame3d frFrame = *( pSouGDB->GetGroupFrame( nSouId)) ; + // inserisco un nuovo gruppo nel GeomDB destinazione + nNewId = pDstGDB->InsertGroup( nDestId, nRefId, GDB_LAST_SON, frFrame) ; + if ( nNewId != nSouId) { + pDstGDB->Erase( nNewId) ; + return GDB_ID_NULL ; + } + // copio le caratteristiche non geometriche + const GdbObj* pSouGdbObj = pSouGDB->GetGdbObj( nSouId) ; + GdbObj* pDstGdbObj = pDstGDB->GetGdbObj( nNewId) ; + if ( pSouGDB == nullptr || pDstGdbObj == nullptr || + ! pDstGdbObj->CopyAttribsFrom( pSouGdbObj) || + ! pDstGdbObj->CopyTextureDataFrom( pSouGdbObj) || + ! pDstGdbObj->CopyStippleDataFrom( pSouGdbObj) || + ! pDstGdbObj->CopyUserObjFrom( pSouGdbObj)) { + pDstGDB->Erase( nNewId) ; + return GDB_ID_NULL ; + } + } + // copio gli eventuali figli + int nSonSouId = pSouGDB->GetFirstInGroup( nSouId) ; + while ( nSonSouId != GDB_ID_NULL) { + // verifico se non richiesto di saltare i temporanei oppure non lo è + int nLevel ; + if ( ! bSkipTemp || ! pSouGDB->GetLevel( nSonSouId, nLevel) || nLevel != GDB_LV_TEMP) { + // nuovo identificativo oggetto destinazione + int nSonNewId = GDB_ID_NULL ; + // recupero il tipo di oggetto sorgente + int nSonSouType = pSouGDB->GetGdbType( nSonSouId) ; + // se l'oggetto da copiare è geometrico + if ( nSonSouType == GDB_TY_GEO) + nSonNewId = DuplicateGeoObj( pSouGDB, nSonSouId, pDstGDB, nSonSouId, nNewId) ; + // se altrimenti è un gruppo + else if ( nSonSouType == GDB_TY_GROUP) + nSonNewId = DuplicateGroupObj( pSouGDB, nSonSouId, pDstGDB, nSonSouId, nNewId, bSkipTemp) ; + // se copia non riuscita, esco con errore + if ( nSonNewId != nSonSouId) + return GDB_ID_NULL ; + } + // passo al figlio successivo + nSonSouId = pSouGDB->GetNext( nSonSouId) ; + } + + return nNewId ; +} + +//---------------------------------------------------------------------------- +bool +DuplicateGeomDB( IGeomDB* pSouGeomDB, IGeomDB* pDestGeomDB, bool bSkipTemp) +{ + // adatto e verifico i GeomDB + const GeomDB* pSouGDB = static_cast( pSouGeomDB) ; + GeomDB* pDstGDB = static_cast( pDestGeomDB) ; + if ( pSouGDB == nullptr || pDstGDB == nullptr) + return false ; + // verifico che la destinazione sia vuota + if ( pDstGDB->GetFirstInGroup( GDB_ID_ROOT) != GDB_ID_NULL) + return false ; + // eseguo la copia di tutto (se richiesto salto gli oggetti temporanei) + return ( DuplicateGroupObj( pSouGDB, GDB_ID_ROOT, pDstGDB, GDB_ID_ROOT, GDB_ID_ROOT, bSkipTemp) != GDB_ID_NULL) ; +}