diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index b9099fc..d71a302 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -320,6 +320,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -340,6 +341,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 68e0c44..30abde1 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -552,6 +552,9 @@ File di origine\GeoOffset + + File di origine\Gdb + @@ -1235,6 +1238,9 @@ File di intestazione\Include + + File di intestazione\Include + diff --git a/GdbObj.cpp b/GdbObj.cpp index 8ddd1a2..d7cfb0f 100644 --- a/GdbObj.cpp +++ b/GdbObj.cpp @@ -101,6 +101,20 @@ GdbObj::CopyFrom( const GdbObj* pSou) return ( CopyAttribsFrom( pSou) && CopyTextureDataFrom( pSou) && CopyUserObjFrom( pSou)) ; } +//---------------------------------------------------------------------------- +bool +GdbObj::CopyStippleDataFrom( const GdbObj* pSou) +{ + // se l'oggetto sorgente non esiste + if ( pSou == nullptr) + return false ; + // copio stipple + m_nStpFactor = pSou->m_nStpFactor ; + m_nStpPattern = pSou->m_nStpPattern ; + + return true ; +} + //---------------------------------------------------------------------------- bool GdbObj::CopyAttribsFrom( const GdbObj* pSou) diff --git a/GdbObj.h b/GdbObj.h index f56e78c..d31689d 100644 --- a/GdbObj.h +++ b/GdbObj.h @@ -57,6 +57,7 @@ class GdbObj GdbObj( void) ; bool CopyFrom( const GdbObj* pSou) ; bool CopyAttribsFrom( const GdbObj* pSou) ; + bool CopyStippleDataFrom( const GdbObj* pSou) ; bool CopyTextureDataFrom( const GdbObj* pSou) ; bool CopyUserObjFrom( const GdbObj* pSou) ; diff --git a/GeomDB.cpp b/GeomDB.cpp index 2edf165..fd300d2 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -38,7 +38,7 @@ using namespace std ; class LockAddErase { public : - LockAddErase(std::atomic_flag& bAddEraseOn, bool bUse = true): m_bAddEraseOn( bAddEraseOn), m_bUse( bUse) + LockAddErase( atomic_flag& bAddEraseOn, bool bUse = true): m_bAddEraseOn( bAddEraseOn), m_bUse( bUse) { if ( ! m_bUse) return ; while ( m_bAddEraseOn.test_and_set()) { this_thread::sleep_for( chrono::nanoseconds{ 1}) ; @@ -51,7 +51,7 @@ class LockAddErase } ; private : - std::atomic_flag& m_bAddEraseOn ; + atomic_flag& m_bAddEraseOn ; bool m_bUse ; } ; diff --git a/GeomDB.h b/GeomDB.h index e5ad7eb..6e0f18a 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -29,6 +29,8 @@ class GeomDB : public IGeomDB friend class GdbObj ; friend class GdbGroup ; 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) ; public : ~GeomDB( void) override ; diff --git a/MultiGeomDB.cpp b/MultiGeomDB.cpp new file mode 100644 index 0000000..e0240a2 --- /dev/null +++ b/MultiGeomDB.cpp @@ -0,0 +1,161 @@ +//---------------------------------------------------------------------------- +// 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) ; +}