//---------------------------------------------------------------------------- // EgalTech 2025-2025 //---------------------------------------------------------------------------- // File : MultiGeomDB.cpp Data : 08.10.25 Versione : 2.7j1 // Contenuto : Implementazione delle funzioni tra due GeomDB. // // // // Modifiche : 08.10.25 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "GeomDB.h" #include "/EgtDev/Include/EGkMultiGeomDB.h" #include "/EgtDev/Include/EgtPointerOwner.h" 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)) return GDB_ID_NULL ; // se in globale if ( bGlob) { // recupero il riferimento del sorgente Frame3d frSou ; if ( ! pSouGDB->GetGlobFrame( nSouId, frSou)) return GDB_ID_NULL ; // recupero il riferimento del gruppo destinazione Frame3d frDest ; int nDestParentId = ( IS_GDB_SON( nSonBeforeAfter) ? nRefId : pDstGDB->GetParentId( nRefId)) ; if ( ! pDstGDB->GetGroupGlobFrame( nDestParentId, frDest)) return GDB_ID_NULL ; // porto la copia da riferimento sorgente a quello destinazione pGObj->LocToLoc( frSou, frDest) ; } // lo inserisco nel GeomDB destinazione int nNewId = pDstGDB->InsertGeoObj( nDestId, nRefId, nSonBeforeAfter, Release( pGObj)) ; if ( nNewId == GDB_ID_NULL) 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 CopyGroupObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId, int nSonBeforeAfter, bool bGlob) { // recupero il riferimento del gruppo Frame3d frFrame ; pSouGDB->GetGroupFrame( nSouId) ; // se in globale if ( bGlob) { // recupero il riferimento del gruppo in globale if ( ! pSouGDB->GetGlobFrame( nSouId, frFrame)) return GDB_ID_NULL ; // recupero il riferimento del gruppo destinazione Frame3d frDest ; int nDestParentId = ( IS_GDB_SON( nSonBeforeAfter) ? nRefId : pDstGDB->GetParentId( nRefId)) ; if ( ! pDstGDB->GetGroupGlobFrame( nDestParentId, frDest)) return GDB_ID_NULL ; // porto la copia da riferimento sorgente a quello destinazione frFrame.ToLoc( frDest) ; } // inserisco un nuovo gruppo nel GeomDB destinazione int nNewId = pDstGDB->InsertGroup( nDestId, nRefId, nSonBeforeAfter, frFrame) ; if ( nNewId == GDB_ID_NULL) 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) { // 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 = 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) ; // se copia non riuscita, esco con errore if ( nSonNewId == GDB_ID_NULL) return GDB_ID_NULL ; // passo al figlio successivo nSonSouId = pSouGDB->GetNext( nSonSouId) ; } return nNewId ; } //---------------------------------------------------------------------------- static int Copy( IGeomDB* pSouGeomDB, int nSouId, IGeomDB* pDestGeomDB, int nDestId, int nRefId, int nSonBeforeAfter, bool bGlob) { // adatto e verifico i GeomDB const GeomDB* pSouGDB = static_cast( pSouGeomDB) ; GeomDB* pDstGDB = static_cast( pDestGeomDB) ; if ( pSouGDB == nullptr || pDstGDB == nullptr) return GDB_ID_NULL ; // nuovo identificativo oggetto destinazione int nNewId = GDB_ID_NULL ; // recupero il tipo di oggetto sorgente int nSouType = pSouGDB->GetGdbType( nSouId) ; // se l'oggetto da copiare è geometrico if ( nSouType == GDB_TY_GEO) { nNewId = CopyGeoObj( pSouGDB, nSouId, pDstGDB, nDestId, nRefId, nSonBeforeAfter, bGlob) ; } // se altrimenti è un gruppo else if ( nSouType == GDB_TY_GROUP) { nNewId = CopyGroupObj( pSouGDB, nSouId, pDstGDB, nDestId, nRefId, nSonBeforeAfter, bGlob) ; } return nNewId ; } //---------------------------------------------------------------------------- int Copy( IGeomDB* pSouGeomDB, int nSouId, IGeomDB* pDestGeomDB, int nDestId, int nRefId, int nSonBeforeAfter) { return Copy( pSouGeomDB, nSouId, pDestGeomDB, nDestId, nRefId, nSonBeforeAfter, false) ; } //---------------------------------------------------------------------------- int CopyGlob( IGeomDB* pSouGeomDB, int nSouId, IGeomDB* pDestGeomDB, int nDestId, int nRefId, int nSonBeforeAfter) { return Copy( pSouGeomDB, nSouId, pDestGeomDB, nDestId, nRefId, nSonBeforeAfter, true) ; }