Files
EgtGeomKernel/MultiGeomDB.cpp
T
Dario Sassi 176bbec8a7 EgtGeomKernel 2.7l3 :
- aggiunta funzione DuplicateGeomDB.
2025-12-23 15:35:32 +01:00

259 lines
10 KiB
C++

//----------------------------------------------------------------------------
// 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)
{
// recupero l'oggetto da copiare dal GeomDB sorgente
PtrOwner<IGeoObj> 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->GetGroupGlobFrame( 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<GeomDB*>( pSouGeomDB) ;
GeomDB* pDstGDB = static_cast<GeomDB*>( 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
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) ;
}
//----------------------------------------------------------------------------
static int
DuplicateGeoObj( const GeomDB* pSouGDB, int nSouId, GeomDB* pDstGDB, int nDestId, int nRefId)
{
// recupero l'oggetto da copiare dal GeomDB sorgente
PtrOwner<IGeoObj> 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<GeomDB*>( pSouGeomDB) ;
GeomDB* pDstGDB = static_cast<GeomDB*>( 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) ;
}