Files
EgtGeomKernel/GdbObj.cpp
T
Dario Sassi dedb4f23cf EgtGeomKernel 1.5c7 :
- migliorata gestione materiale (colore ora caso speciale)
- si invalida rappresentazione grafica alla modifica del materiale
- spostato comando COUNTER di TSC in EgtGeneral.
2014-03-18 08:49:25 +00:00

614 lines
16 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 "GdbObj.h"
#include "GdbGroup.h"
#include "Attribs.h"
#include "/EgtDev/Include/EGkGdbFunct.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
GdbObj::GdbObj( void)
: m_nId( GDB_ID_NULL), m_pAttribs( nullptr),
m_pNext( nullptr), m_pPrev( nullptr), m_pParent( nullptr)
{
}
//----------------------------------------------------------------------------
GdbObj::~GdbObj( void)
{
if ( m_pAttribs != nullptr)
delete m_pAttribs ;
m_pAttribs = nullptr ;
}
//----------------------------------------------------------------------------
bool
GdbObj::Copy( 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
if ( pSou->m_pAttribs != nullptr) {
m_pAttribs = pSou->m_pAttribs->Clone() ;
if ( m_pAttribs == nullptr)
return false ;
}
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( std::ostream& osOut) const
{
if ( m_pAttribs != nullptr)
return m_pAttribs->Save( osOut) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbObj::LoadAttribs( Scanner& TheScanner)
{
if ( GetSafeAttribs() == nullptr)
return false ;
return m_pAttribs->Load( TheScanner) ;
}
//----------------------------------------------------------------------------
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::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::SetMaterial( int nMat)
{
// per ora ammesso solo 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::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 il nome
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 il nome
return m_pAttribs->GetInfo( sKey, sInfo) ;
}
//----------------------------------------------------------------------------
bool
GdbObj::RemoveInfo( const string& sKey)
{
// se non ci sono attributi
if ( m_pAttribs == nullptr)
return false ;
// cancello il nome
return m_pAttribs->RemoveInfo( sKey) ;
}