0bf2cc2a77
- aggiunte funzioni per copia da un db a un altro (CopyEx e CopyGlobEx).
1248 lines
34 KiB
C++
1248 lines
34 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2013
|
|
//----------------------------------------------------------------------------
|
|
// File : GdbObj.cpp Data : 05.03.14 Versione : 1.5c1
|
|
// Contenuto : Implementazione della classe GdbObj.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.11.13 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "GeomDB.h"
|
|
#include "GdbObj.h"
|
|
#include "GdbGroup.h"
|
|
#include "Attribs.h"
|
|
#include "TextureData.h"
|
|
#include "UserObjDefault.h"
|
|
#include "NgeWriter.h"
|
|
#include "NgeReader.h"
|
|
#include "/EgtDev/Include/EGkGdbFunct.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
#include "/EgtDev/Include/EGkUserObjFactory.h"
|
|
#include "/EgtDev/Include/EGnStringKeyVal.h"
|
|
#include <new>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
GdbObj::GdbObj( void)
|
|
: m_nId( GDB_ID_NULL), m_pAttribs( nullptr), m_nStpFactor( 0), m_nStpPattern( 0), m_pTxrData( nullptr),
|
|
m_pUserObj( nullptr), m_pGDB( nullptr), m_pNext( nullptr), m_pPrev( nullptr), m_pParent( nullptr),
|
|
m_pSelNext( nullptr), m_pSelPrev( nullptr)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
GdbObj::~GdbObj( void)
|
|
{
|
|
// cancello gli attributi
|
|
if ( m_pAttribs != nullptr)
|
|
delete m_pAttribs ;
|
|
m_pAttribs = nullptr ;
|
|
// cancello i dati della texture
|
|
if ( m_pTxrData != nullptr)
|
|
delete m_pTxrData ;
|
|
m_pTxrData = nullptr ;
|
|
// cancello UserObj
|
|
if ( m_pUserObj != nullptr)
|
|
delete m_pUserObj ;
|
|
m_pUserObj = nullptr ;
|
|
// aggiorno managers del Db geometrico di appartenenza
|
|
if ( m_pGDB != nullptr) {
|
|
// elimino da mappa dei nomi
|
|
m_pGDB->m_IdManager.RemoveObj( m_nId) ;
|
|
// eventuale rimozione da lista selezionati
|
|
m_pGDB->m_SelManager.RemoveObj(this) ;
|
|
// sistemazioni in eventuali GdbIterator con quell'oggetto corrente
|
|
m_pGDB->m_IterManager.ResetObjIfSame( this) ;
|
|
}
|
|
m_pGDB = nullptr ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::CopyFrom( const GdbObj* pSou)
|
|
{
|
|
// elimino eventuali attributi pre-esistenti
|
|
if ( m_pAttribs != nullptr)
|
|
delete m_pAttribs ;
|
|
m_pAttribs = nullptr ;
|
|
// reset stipple
|
|
m_nStpFactor = 0 ;
|
|
m_nStpPattern = 0 ;
|
|
// elimino eventuali dati della texture pre-esistenti
|
|
if ( m_pTxrData != nullptr)
|
|
delete m_pTxrData ;
|
|
m_pTxrData = nullptr ;
|
|
// elimino eventuale UserObj pre-esistente
|
|
if ( m_pUserObj != nullptr)
|
|
delete m_pUserObj ;
|
|
m_pUserObj = nullptr ;
|
|
|
|
// se l'oggetto sorgente non esiste
|
|
if ( pSou == nullptr) {
|
|
m_nId = GDB_ID_NULL ;
|
|
return false ;
|
|
}
|
|
|
|
// copio Id
|
|
m_nId = pSou->m_nId ;
|
|
|
|
// copio stipple
|
|
m_nStpFactor = pSou->m_nStpFactor ;
|
|
m_nStpPattern = pSou->m_nStpPattern ;
|
|
|
|
// copio gli attributi, i dati della texture e UserObj
|
|
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)
|
|
{
|
|
// se l'oggetto sorgente non esiste
|
|
if ( pSou == nullptr)
|
|
return false ;
|
|
// cancello gli attributi originali
|
|
if ( m_pAttribs != nullptr)
|
|
delete m_pAttribs ;
|
|
m_pAttribs = nullptr ;
|
|
// copio gli attributi
|
|
if ( pSou->m_pAttribs != nullptr) {
|
|
m_pAttribs = pSou->m_pAttribs->Clone() ;
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
// se selezionato, deve diventare solo visibile
|
|
if ( m_pAttribs->GetStatus() == GDB_ST_SEL)
|
|
m_pAttribs->SetStatus( GDB_ST_ON) ;
|
|
// marcatura sempre disabilitata
|
|
m_pAttribs->ResetMark() ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::CopyTextureDataFrom( const GdbObj* pSou)
|
|
{
|
|
// se l'oggetto sorgente non esiste
|
|
if ( pSou == nullptr)
|
|
return false ;
|
|
// cancello i dati di texture originali
|
|
if ( m_pTxrData != nullptr)
|
|
delete m_pTxrData ;
|
|
m_pTxrData = nullptr ;
|
|
// copio texture data
|
|
if ( pSou->m_pTxrData != nullptr) {
|
|
m_pTxrData = pSou->m_pTxrData->Clone() ;
|
|
if ( m_pTxrData == nullptr)
|
|
return false ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::CopyUserObjFrom( const GdbObj* pSou)
|
|
{
|
|
// se l'oggetto sorgente non esiste
|
|
if ( pSou == nullptr)
|
|
return false ;
|
|
// copio UserObj originale
|
|
if ( m_pUserObj != nullptr)
|
|
delete m_pUserObj ;
|
|
m_pUserObj = nullptr ;
|
|
// copio UserObj
|
|
if ( pSou->m_pUserObj != nullptr) {
|
|
m_pUserObj = pSou->m_pUserObj->Clone() ;
|
|
if ( m_pUserObj == nullptr)
|
|
return false ;
|
|
m_pUserObj->SetOwner( m_nId, m_pGDB) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Node
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
GdbObj::GetParentId( void) const
|
|
{
|
|
if ( m_pParent != nullptr)
|
|
return m_pParent->m_nId ;
|
|
else
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::AddTail( GdbGroup* pParent)
|
|
{
|
|
// se il padre non è definito, errore
|
|
if ( pParent == nullptr)
|
|
return false ;
|
|
|
|
// se non ci sono figli
|
|
if ( pParent->m_pLastObj == nullptr) {
|
|
pParent->m_pLastObj = this ;
|
|
pParent->m_pFirstObj = this ;
|
|
m_pParent = pParent ;
|
|
m_pNext = nullptr ;
|
|
m_pPrev = nullptr ;
|
|
m_pParent->ObjCountInc() ;
|
|
return true ;
|
|
}
|
|
|
|
// caso standard
|
|
return InsertAfter( pParent->m_pLastObj) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::AddHead( GdbGroup* pParent)
|
|
{
|
|
// se il padre non è definito, errore
|
|
if ( pParent == nullptr)
|
|
return false ;
|
|
|
|
// se non ci sono figli
|
|
if ( pParent->m_pFirstObj == nullptr) {
|
|
pParent->m_pFirstObj = this ;
|
|
pParent->m_pLastObj = this ;
|
|
m_pParent = pParent ;
|
|
m_pNext = nullptr ;
|
|
m_pPrev = nullptr ;
|
|
m_pParent->ObjCountInc() ;
|
|
return true ;
|
|
}
|
|
|
|
// caso standard
|
|
return InsertBefore( pParent->m_pFirstObj) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::InsertAfter( GdbObj* pRef)
|
|
{
|
|
// se riferimento non definito, errore
|
|
if ( pRef == nullptr)
|
|
return false ;
|
|
|
|
// sistemazione puntatori di elemento inserito
|
|
m_pNext = pRef->m_pNext ;
|
|
m_pPrev = pRef ;
|
|
m_pParent = pRef->m_pParent ;
|
|
// sistemazione puntatori di elemento di riferimento
|
|
pRef->m_pNext = this ;
|
|
// sistemazione puntatori di eventuale elemento successivo
|
|
if ( m_pNext != nullptr)
|
|
m_pNext->m_pPrev = this ;
|
|
// sistemazione dell'eventuale padre
|
|
if ( m_pParent != nullptr) {
|
|
// se nuovo ultimo nodo
|
|
if ( m_pParent->m_pLastObj == pRef)
|
|
m_pParent->m_pLastObj = this ;
|
|
m_pParent->ObjCountInc() ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::InsertBefore( GdbObj* pRef)
|
|
{
|
|
// se riferimento non definito, errore
|
|
if ( pRef == nullptr)
|
|
return false ;
|
|
|
|
// sistemazione puntatori di elemento inserito
|
|
m_pNext = pRef ;
|
|
m_pPrev = pRef->m_pPrev ;
|
|
m_pParent = pRef->m_pParent ;
|
|
// sistemazione puntatori di elemento corrente
|
|
pRef->m_pPrev = this ;
|
|
// sistemazione puntatori di eventuale elemento precedente
|
|
if ( m_pPrev != nullptr)
|
|
m_pPrev->m_pNext = this ;
|
|
// sistemazione dell'eventuale padre
|
|
if ( m_pParent != nullptr) {
|
|
// se nuovo primo nodo
|
|
if ( m_pParent->m_pFirstObj == pRef)
|
|
m_pParent->m_pFirstObj = this ;
|
|
m_pParent->ObjCountInc() ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
bool
|
|
GdbObj::Swap( GdbObj* pOther)
|
|
{
|
|
// verifico esistenza dell'altro
|
|
if ( pOther == nullptr)
|
|
return false ;
|
|
// sistemazione degli eventuali padri
|
|
if ( m_pParent != nullptr) {
|
|
if ( m_pParent->m_pFirstObj == this)
|
|
m_pParent->m_pFirstObj = pOther ;
|
|
if ( m_pParent->m_pLastObj == this)
|
|
m_pParent->m_pLastObj = pOther ;
|
|
}
|
|
if ( pOther->m_pParent != nullptr) {
|
|
if ( pOther->m_pParent->m_pFirstObj == pOther)
|
|
pOther->m_pParent->m_pFirstObj = this ;
|
|
if ( pOther->m_pParent->m_pLastObj == pOther)
|
|
pOther->m_pParent->m_pLastObj = this ;
|
|
}
|
|
swap( m_pParent, pOther->m_pParent) ;
|
|
// sistemazione dei precedenti
|
|
if ( m_pPrev != nullptr)
|
|
m_pPrev->m_pNext = pOther ;
|
|
if ( pOther->m_pPrev != nullptr)
|
|
pOther->m_pPrev->m_pNext = this ;
|
|
swap( m_pPrev, pOther->m_pPrev) ;
|
|
// sistemazione dei successivi
|
|
if ( m_pNext != nullptr)
|
|
m_pNext->m_pPrev = pOther ;
|
|
if ( pOther->m_pNext != nullptr)
|
|
pOther->m_pNext->m_pPrev = this ;
|
|
swap( m_pNext, pOther->m_pNext) ;
|
|
return true ;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
bool
|
|
GdbObj::Remove( void)
|
|
{
|
|
// sistemazione dell'eventuale padre
|
|
if ( m_pParent != nullptr) {
|
|
if ( m_pParent->m_pFirstObj == this)
|
|
m_pParent->m_pFirstObj = m_pNext ;
|
|
if ( m_pParent->m_pLastObj == this)
|
|
m_pParent->m_pLastObj = m_pPrev ;
|
|
m_pParent->ObjCountDec() ;
|
|
}
|
|
// sistemazione di eventuale precedente
|
|
if ( m_pPrev != nullptr)
|
|
m_pPrev->m_pNext = m_pNext ;
|
|
// sistemazione di eventuale successivo
|
|
if ( m_pNext != nullptr)
|
|
m_pNext->m_pPrev = m_pPrev ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Attribs
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SaveAttribs( NgeWriter& ngeOut) const
|
|
{
|
|
if ( m_pAttribs != nullptr)
|
|
return m_pAttribs->Save( ngeOut) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::LoadAttribs( NgeReader& ngeIn)
|
|
{
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
return m_pAttribs->Load( ngeIn) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
Attribs*
|
|
GdbObj::GetSafeAttribs( void)
|
|
{
|
|
if ( m_pAttribs == nullptr)
|
|
m_pAttribs = new( nothrow) Attribs ;
|
|
|
|
return m_pAttribs ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetLevel( int nLevel)
|
|
{
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
// assegno il livello
|
|
m_pAttribs->SetLevel( nLevel) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::RevertLevel( void)
|
|
{
|
|
// se non ci sono attributi non fa alcunchè
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
|
|
// ripristina il vecchio livello
|
|
m_pAttribs->RevertLevel() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetLevel( int& nLevel) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// il livello è definito
|
|
nLevel = m_pAttribs->GetLevel() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetCalcLevel( int& nLevel) const
|
|
{
|
|
// recupero il livello dell'oggetto
|
|
int nObjLevel = GDB_LV_USER ;
|
|
if ( m_pAttribs != nullptr)
|
|
nObjLevel = m_pAttribs->GetLevel() ;
|
|
|
|
// se il livello è TEMP, non ho bisogno di sapere altro
|
|
if ( nObjLevel == GDB_LV_TEMP) {
|
|
nLevel = GDB_LV_TEMP ;
|
|
return true ;
|
|
}
|
|
|
|
// recupero il livello dell'eventuale padre
|
|
int nParentLevel = GDB_LV_USER ;
|
|
if ( GetParent() != nullptr)
|
|
GetParent()->GetCalcLevel( nParentLevel) ;
|
|
|
|
// calcolo il livello
|
|
nLevel = ::CalcLevel( nObjLevel, nParentLevel) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetMode( int nMode)
|
|
{
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
// assegno il modo
|
|
m_pAttribs->SetMode( nMode) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::RevertMode( void)
|
|
{
|
|
// se non ci sono attributi non fa alcunchè
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
|
|
// ripristina il vecchio modo
|
|
m_pAttribs->RevertMode() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetMode( int& nMode) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// il modo è definito
|
|
nMode = m_pAttribs->GetMode() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetCalcMode( int& nMode) const
|
|
{
|
|
// recupero il modo dell'oggetto
|
|
int nObjMode = GDB_MD_STD ;
|
|
if ( m_pAttribs != nullptr)
|
|
nObjMode = m_pAttribs->GetMode() ;
|
|
|
|
// se il modo è HIDDEN, non ho bisogno di sapere altro
|
|
if ( nObjMode == GDB_MD_HIDDEN) {
|
|
nMode = GDB_MD_HIDDEN ;
|
|
return true ;
|
|
}
|
|
|
|
// recupero il modo dell'eventuale padre
|
|
int nParentMode = GDB_MD_STD ;
|
|
if ( GetParent() != nullptr)
|
|
GetParent()->GetCalcMode( nParentMode) ;
|
|
|
|
// calcolo il modo
|
|
nMode = ::CalcMode( nObjMode, nParentMode) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetStatus( int nStat)
|
|
{
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
// assegno lo stato
|
|
m_pAttribs->SetStatus( nStat) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::RevertStatus( void)
|
|
{
|
|
// se non ci sono attributi non fa alcunchè
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
|
|
// ripristina il vecchio stato
|
|
m_pAttribs->RevertStatus() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::IsOff( void) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// lo stato è definito
|
|
return ( m_pAttribs->GetStatus() == GDB_ST_OFF) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::IsOn( void) const
|
|
{
|
|
// se non ci sono attributi (On di default)
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
|
|
// lo stato è definito
|
|
return ( m_pAttribs->GetStatus() == GDB_ST_ON) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::IsSelected( void) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// lo stato è definito
|
|
return ( m_pAttribs->GetStatus() == GDB_ST_SEL) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetStatus( int& nStat) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// lo stato è definito
|
|
nStat = m_pAttribs->GetStatus() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetCalcStatus( int& nStat, int nLev) const
|
|
{
|
|
// recupero lo stato dell'oggetto
|
|
int nObjStat = GDB_ST_ON ;
|
|
if ( m_pAttribs != nullptr)
|
|
nObjStat = m_pAttribs->GetStatus() ;
|
|
|
|
// se lo stato è OFF, non ho bisogno di sapere altro
|
|
if ( nObjStat == GDB_ST_OFF) {
|
|
nStat = GDB_ST_OFF ;
|
|
return true ;
|
|
}
|
|
|
|
// recupero lo stato dell'eventuale padre
|
|
int nParentStat = GDB_ST_ON ;
|
|
if ( GetParent() != nullptr)
|
|
GetParent()->GetCalcStatus( nParentStat, ( nLev + 1)) ;
|
|
|
|
// calcolo lo stato
|
|
nStat = ::CalcStatus( nObjStat, nParentStat) ;
|
|
|
|
// se sono alla chiamata iniziale, devo aggiustare lo stato con il modo
|
|
if ( nLev == 0) {
|
|
int nMode = GDB_MD_STD ;
|
|
GetCalcMode( nMode) ;
|
|
nStat = ::AdjustStatusWithMode( nStat, nMode) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetMark( int nMark)
|
|
{
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
// assegno la marcatura
|
|
m_pAttribs->SetMark( nMark) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::ResetMark( void)
|
|
{
|
|
// se non ci sono attributi non fa alcunchè
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
|
|
// cancello la marcatura
|
|
m_pAttribs->ResetMark() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetMark( int& nMark) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// la marcatura è definito
|
|
nMark = m_pAttribs->GetMark() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetCalcMark( int& nMark) const
|
|
{
|
|
// recupero la marcatura dell'oggetto
|
|
int nObjMark = GDB_MK_OFF ;
|
|
if ( m_pAttribs != nullptr)
|
|
nObjMark = m_pAttribs->GetMark() ;
|
|
|
|
// se la marcatura è ON, non ho bisogno di sapere altro
|
|
if ( nObjMark == GDB_MK_ON || nObjMark == GDB_MK_ON_2) {
|
|
nMark = nObjMark ;
|
|
return true ;
|
|
}
|
|
|
|
// recupero la marcatura dell'eventuale padre
|
|
int nParentMark = GDB_MK_OFF ;
|
|
if ( GetParent() != nullptr)
|
|
GetParent()->GetCalcMark( nParentMark) ;
|
|
|
|
// calcolo la marcatura
|
|
nMark = ::CalcMark( nObjMark, nParentMark) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetMaterial( int nMat)
|
|
{
|
|
// ammessi da lista materiali o da padre (da colore si imposta con la SetColor)
|
|
if ( nMat < GDB_MT_PARENT)
|
|
return false ;
|
|
|
|
// se materiale da padre e non ci sono attributi è già così
|
|
if ( nMat == GDB_MT_PARENT && GetAttribs() == nullptr)
|
|
return true ;
|
|
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
// assegno il materiale
|
|
m_pAttribs->SetMaterial( nMat) ;
|
|
|
|
// notifico l'oggetto vero
|
|
OnSetMaterial() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetMaterial( Color cCol)
|
|
{
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
|
|
// assegno il colore (e imposto il materiale da colore)
|
|
m_pAttribs->SetColor( cCol) ;
|
|
|
|
// notifico l'oggetto vero
|
|
OnSetMaterial() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetMaterial( int& nMat) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
|
|
// il materiale è definito
|
|
nMat = m_pAttribs->GetMaterial() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetMaterial( Color& cCol) const
|
|
{
|
|
// se non ci sono attributi o ci si deve riferire al padre
|
|
if ( m_pAttribs == nullptr ||
|
|
m_pAttribs->GetMaterial() == GDB_MT_PARENT)
|
|
return false ;
|
|
|
|
// il colore è definito
|
|
cCol = m_pAttribs->GetColor() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetCalcMaterial( int& nMat) const
|
|
{
|
|
// se non ci sono attributi o ci si deve riferire al padre
|
|
if ( m_pAttribs == nullptr ||
|
|
m_pAttribs->GetMaterial() == GDB_MT_PARENT) {
|
|
if ( GetParent() != nullptr)
|
|
GetParent()->GetCalcMaterial( nMat) ;
|
|
else
|
|
nMat = GDB_MT_COLOR ;
|
|
return true ;
|
|
}
|
|
|
|
// il materiale è definito
|
|
nMat = m_pAttribs->GetMaterial() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetCalcMaterial( Color& cCol) const
|
|
{
|
|
// se non ci sono attributi o ci si deve riferire al padre
|
|
if ( m_pAttribs == nullptr ||
|
|
m_pAttribs->GetMaterial() == GDB_MT_PARENT) {
|
|
if ( GetParent() != nullptr)
|
|
GetParent()->GetCalcMaterial( cCol) ;
|
|
else
|
|
cCol.Set() ;
|
|
return true ;
|
|
}
|
|
|
|
// il colore è definito
|
|
cCol = m_pAttribs->GetColor() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetName( const string& sName)
|
|
{
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
// assegno il nome
|
|
return m_pAttribs->SetName( sName) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetName( string& sName) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
// restituisco il nome
|
|
return m_pAttribs->GetName( sName) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::ExistsName( void) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
// restituisco il nome
|
|
return m_pAttribs->ExistsName() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::RemoveName( void)
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
// cancello il nome
|
|
return m_pAttribs->RemoveName() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const string& sInfo)
|
|
{
|
|
// se Info non vuota
|
|
if ( ! IsEmptyOrSpaces( sInfo)) {
|
|
// verifico esistenza (con eventuale creazione) degli attributi
|
|
if ( GetSafeAttribs() == nullptr)
|
|
return false ;
|
|
// eseguo assegnazione
|
|
return m_pAttribs->SetInfo( sKey, sInfo) ;
|
|
}
|
|
// altrimenti
|
|
else {
|
|
// se esiste, la rimuovo
|
|
return ( m_pAttribs == nullptr || m_pAttribs->RemoveInfo( sKey)) ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, bool bInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( bInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, int nInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( nInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, double dInfo)
|
|
{
|
|
int nErr ;
|
|
return ( SetInfo( sKey, ToString( dInfo, 6, &nErr)) && nErr == 0) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const Vector3d& vtInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( vtInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const Point3d& ptInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( ptInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const BBox3d& b3Info)
|
|
{
|
|
return SetInfo( sKey, ToString( b3Info)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const Frame3d& frInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( frInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const INTVECTOR& vnInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( vnInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const DBLVECTOR& vdInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( vdInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetInfo( const string& sKey, const STRVECTOR& vsInfo)
|
|
{
|
|
return SetInfo( sKey, ToString( vsInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, string& sInfo) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
// restituisco l'Info
|
|
return m_pAttribs->GetInfo( sKey, sInfo) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, bool& bInfo) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, bInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, int& nInfo) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, nInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, double& dInfo) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, dInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, Vector3d& vtInfo) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, vtInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, Point3d& ptInfo) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, ptInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, BBox3d& b3Info) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, b3Info)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, Frame3d& frInfo) const
|
|
{
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, frInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, INTVECTOR& vnInfo) const
|
|
{
|
|
vnInfo.clear() ;
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, vnInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, DBLVECTOR& vdInfo) const
|
|
{
|
|
vdInfo.clear() ;
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, vdInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetInfo( const string& sKey, STRVECTOR& vsInfo) const
|
|
{
|
|
vsInfo.clear() ;
|
|
string sInfo ;
|
|
return ( GetInfo( sKey, sInfo) && FromString( sInfo, vsInfo)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::ExistsInfo( const string& sKey) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return false ;
|
|
// verifico l'esistenza dell'Info
|
|
return m_pAttribs->ExistsInfo( sKey) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::RemoveInfo( const string& sKey)
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr)
|
|
return true ;
|
|
// cancello l'Info
|
|
return m_pAttribs->RemoveInfo( sKey) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetAllInfo( STRVECTOR& vsInfo) const
|
|
{
|
|
// se non ci sono attributi
|
|
if ( m_pAttribs == nullptr) {
|
|
vsInfo.clear() ;
|
|
return true ;
|
|
}
|
|
// recupero tutte le Info
|
|
return m_pAttribs->GetAllInfo( vsInfo) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Stipple (significativo solo per curve, per ora non viene salvato)
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetStipple( int nFactor, int nPattern)
|
|
{
|
|
m_nStpFactor = nFactor ;
|
|
m_nStpPattern = nPattern ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetStipple( int& nFactor, int& nPattern) const
|
|
{
|
|
nFactor = m_nStpFactor ;
|
|
nPattern = m_nStpPattern ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// TextureData
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SaveTextureData( NgeWriter& ngeOut) const
|
|
{
|
|
if ( m_pTxrData != nullptr)
|
|
return m_pTxrData->Save( ngeOut) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::LoadTextureData( NgeReader& ngeIn)
|
|
{
|
|
if ( GetSafeTextureData() == nullptr)
|
|
return false ;
|
|
|
|
return m_pTxrData->Load( ngeIn) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
TextureData*
|
|
GdbObj::GetSafeTextureData( void)
|
|
{
|
|
if ( m_pTxrData == nullptr) {
|
|
TextureData* pTxrData = new( nothrow) TextureData ;
|
|
if ( pTxrData == nullptr)
|
|
return nullptr ;
|
|
m_pTxrData = pTxrData ;
|
|
}
|
|
|
|
return m_pTxrData ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetTextureName( const string& sTxrName)
|
|
{
|
|
// se nome vuoto non faccio alcunché
|
|
if ( sTxrName.empty())
|
|
return false ;
|
|
// verifico esistenza (con eventuale creazione) dei dati di texture
|
|
if ( GetSafeTextureData() == nullptr)
|
|
return false ;
|
|
// assegno il nome
|
|
return m_pTxrData->SetName( sTxrName) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SetTextureFrame( const Frame3d& frTxrRef)
|
|
{
|
|
// verifico esistenza dei dati di texture
|
|
if ( m_pTxrData == nullptr)
|
|
return false ;
|
|
// assegno il riferimento
|
|
return m_pTxrData->SetFrame( frTxrRef) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::RemoveTextureData( void)
|
|
{
|
|
if ( m_pTxrData != nullptr)
|
|
delete m_pTxrData ;
|
|
m_pTxrData = nullptr ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetTextureName( string& sTxrName) const
|
|
{
|
|
// se non ci sono dati di texture
|
|
if ( m_pTxrData == nullptr)
|
|
return false ;
|
|
// restituisco il nome
|
|
return m_pTxrData->GetName( sTxrName) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::GetTextureFrame( Frame3d& frTxrRef) const
|
|
{
|
|
// verifico esistenza dei dati di texture
|
|
if ( m_pTxrData == nullptr)
|
|
return false ;
|
|
// restituisco il riferimento
|
|
return m_pTxrData->GetFrame( frTxrRef) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// IUserObj
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::SaveUserObj( int nBaseId, NgeWriter& ngeOut) const
|
|
{
|
|
// se definito UserObj e da salvare
|
|
if ( m_pUserObj != nullptr && m_pUserObj->ToSave()) {
|
|
// recupero il nome della sua classe
|
|
string sName = m_pUserObj->GetClassName() ;
|
|
if ( sName.empty())
|
|
return false ;
|
|
// recupero le stringhe dei dati
|
|
STRVECTOR vString ;
|
|
if ( ! m_pUserObj->Save( nBaseId, vString))
|
|
return false ;
|
|
// eseguo validazione di queste stringhe
|
|
for ( auto iIter = vString.begin() ; iIter != vString.end() ; ++ iIter)
|
|
ValidateVal( *iIter) ;
|
|
// scrivo i dati :
|
|
// flag presenza UserObj
|
|
if ( ! ngeOut.WriteKey( NGE_U))
|
|
return false ;
|
|
// nome della classe dell'oggetto
|
|
if ( ! ngeOut.WriteString( sName, ";", true))
|
|
return false ;
|
|
// numero di stringhe di dati (nelle linee successive)
|
|
if ( ! ngeOut.WriteInt( int( vString.size()), ";", true))
|
|
return false ;
|
|
// stringhe di dati
|
|
for ( auto iIter = vString.cbegin() ; iIter != vString.cend() ; ++ iIter) {
|
|
if ( ! ngeOut.WriteString( *iIter, nullptr, true))
|
|
return false ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbObj::LoadUserObj( NgeReader& ngeIn, int nBaseGdbId)
|
|
{
|
|
// leggo il nome della classe
|
|
string sName ;
|
|
if ( ! ngeIn.ReadString( sName, ";", true))
|
|
return false ;
|
|
// numero di stringhe di dati (nelle linee successive)
|
|
int nNext ;
|
|
if ( ! ngeIn.ReadInt( nNext, ";", true))
|
|
return false ;
|
|
// leggo le eventuali stringhe
|
|
STRVECTOR vString ;
|
|
vString.reserve( nNext) ;
|
|
string sLine ;
|
|
for ( int i = 0 ; i < nNext ; ++i) {
|
|
// preparo la stringa
|
|
vString.emplace_back( "") ;
|
|
// leggo la linea
|
|
if ( ! ngeIn.ReadString( vString.back(), nullptr, true))
|
|
return false ;
|
|
}
|
|
// creo l'oggetto corrispondente
|
|
m_pUserObj = USEROBJ_CREATE( sName) ;
|
|
// se non trovato uso quello di default
|
|
if ( m_pUserObj == nullptr)
|
|
m_pUserObj = new( nothrow) UserObjDefault( sName) ; ;
|
|
if ( m_pUserObj == nullptr)
|
|
return false ;
|
|
// carico i dati nell'oggetto
|
|
if ( ! m_pUserObj->Load( vString, nBaseGdbId))
|
|
return false ;
|
|
// impostazione Id e GeomDB fatte successivamente
|
|
return true ;
|
|
}
|