//---------------------------------------------------------------------------- // 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 "/EgtDev/Include/EGkGdbFunct.h" #include "/EgtDev/Include/EGnStringUtils.h" #include using namespace std ; //---------------------------------------------------------------------------- GdbObj::GdbObj( void) : m_nId( GDB_ID_NULL), m_pAttribs( nullptr), m_pGDB( nullptr), m_pNext( nullptr), m_pPrev( nullptr), m_pParent( nullptr) { } //---------------------------------------------------------------------------- GdbObj::~GdbObj( void) { // cancello gli attributi if ( m_pAttribs != nullptr) delete m_pAttribs ; m_pAttribs = nullptr ; // aggiorno managers del Db geometrico di appartenenza if ( m_pGDB != nullptr) { // elimino da mappa dei nomi m_pGDB->m_IdManager.RemoveObj( m_nId) ; // eliminazione eventuale da lista dei 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 ; // se l'oggetto sorgente non esiste if ( pSou == nullptr) { m_nId = GDB_ID_NULL ; return false ; } // copio Id m_nId = pSou->m_nId ; // copio gli attributi return CopyAttribsFrom( pSou) ; } //---------------------------------------------------------------------------- bool GdbObj::CopyAttribsFrom( const GdbObj* pSou) { // se l'oggetto sorgente non esiste if ( pSou == nullptr) return false ; // 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() ; } // altrimenti li cancello else { if ( m_pAttribs != nullptr) delete m_pAttribs ; m_pAttribs = nullptr ; } 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::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) { Attribs* pAttribs = new (nothrow) Attribs ; if ( pAttribs == nullptr) return nullptr ; m_pAttribs = pAttribs ; } 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( void) { // verifico esistenza (con eventuale creazione) degli attributi if ( GetSafeAttribs() == nullptr) return false ; // assegno la marcatura m_pAttribs->SetMark() ; 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) { nMark = GDB_MK_ON ; 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 ; // 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 false ; // cancello il nome return m_pAttribs->RemoveName() ; } //---------------------------------------------------------------------------- bool GdbObj::SetInfo( const string& sKey, const string& sInfo) { // verifico esistenza (con eventuale creazione) degli attributi if ( GetSafeAttribs() == nullptr) return false ; // assegno l'Info return m_pAttribs->SetInfo( sKey, sInfo) ; } //---------------------------------------------------------------------------- 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::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 false ; // cancello l'Info return m_pAttribs->RemoveInfo( sKey) ; }