Files
EgtGeomKernel/GdbIterator.cpp
T
Dario Sassi 033236491d EgtGeomKernel :
- gestione cancellazione oggetti puntati da GdbIterator
- aggiunte a GdbIterator EraseAndGoToNext e EraseAndGoToPrev
- possibilità di passare IGeomDB* al costruttore di GdbIterator.
2014-03-23 21:38:09 +00:00

696 lines
18 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : GdbIterator.cpp Data : 04.12.13 Versione : 1.4a3
// Contenuto : Implementazione della classe GdbIterator.
//
//
//
// Modifiche : 04.12.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "GdbIterator.h"
#include "Attribs.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
IGdbIterator*
CreateGdbIterator( IGeomDB* pGDB)
{
return static_cast<IGdbIterator*> ( new GdbIterator( pGDB) ) ;
}
//----------------------------------------------------------------------------
// GdbIterator
//----------------------------------------------------------------------------
GdbIterator::GdbIterator( IGeomDB* pGDB)
{
if ( pGDB != nullptr)
SetGDB( pGDB) ;
else
m_pGDB = nullptr ;
m_pCurrObj = nullptr ;
}
//----------------------------------------------------------------------------
GdbIterator::~GdbIterator( void)
{
if ( m_pGDB != nullptr)
m_pGDB->RemoveGdbIteratorFromList( this) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetGDB( IGeomDB* pGDB)
{
m_pGDB = dynamic_cast<GeomDB*>( pGDB) ;
if ( m_pGDB == nullptr)
return false ;
return m_pGDB->AddGdbIteratorToList( this) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoTo( int nId)
{
if ( m_pGDB == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
m_pCurrObj = m_pGDB->GetGdbObj( nId) ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoToFirstInGroup( int nIdGroup)
{
if ( m_pGDB == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero il gruppo
GdbGroup* pGdbGroup = m_pGDB->GetGdbGroup( nIdGroup) ;
if ( pGdbGroup == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero l'oggetto
m_pCurrObj = pGdbGroup->GetFirstObj() ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoToFirstInGroup( const IGdbIterator& iIter)
{
if ( m_pGDB == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
const GdbIterator* pIter = dynamic_cast<const GdbIterator*> (&iIter) ;
if ( pIter == nullptr || pIter->m_pGDB != m_pGDB) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero il gruppo
GdbGroup* pGdbGroup = GetGdbGroup( pIter->m_pCurrObj) ;
if ( pGdbGroup == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero l'oggetto
m_pCurrObj = pGdbGroup->GetFirstObj() ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoToNext( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
m_pCurrObj = m_pCurrObj->GetNext() ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoToLastInGroup( int nIdGroup)
{
if ( m_pGDB == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero il gruppo
GdbGroup* pGdbGroup = m_pGDB->GetGdbGroup( nIdGroup) ;
if ( pGdbGroup == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero l'oggetto
m_pCurrObj = pGdbGroup->GetLastObj() ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoToLastInGroup( const IGdbIterator& iIter)
{
if ( m_pGDB == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
const GdbIterator* pIter = dynamic_cast<const GdbIterator*> (&iIter) ;
if ( pIter == nullptr || pIter->m_pGDB != m_pGDB) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero il gruppo
GdbGroup* pGdbGroup = GetGdbGroup( pIter->m_pCurrObj) ;
if ( pGdbGroup == nullptr) {
m_pCurrObj = nullptr ;
return false ;
}
// recupero l'oggetto
m_pCurrObj = pGdbGroup->GetLastObj() ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GoToPrev( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
m_pCurrObj = m_pCurrObj->GetPrev() ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::EraseAndGoToNext( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// passo al successivo
GdbObj* pObjToErase = m_pCurrObj ;
m_pCurrObj = m_pCurrObj->GetNext() ;
// eseguo cancellazione
m_pGDB->Erase( pObjToErase) ;
return ( m_pCurrObj != nullptr) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::EraseAndGoToPrev( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// passo al precedente
GdbObj* pObjToErase = m_pCurrObj ;
m_pCurrObj = m_pCurrObj->GetPrev() ;
// eseguo cancellazione
m_pGDB->Erase( pObjToErase) ;
return true ;
}
//----------------------------------------------------------------------------
int
GdbIterator::GetGdbType( void) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return GDB_TY_NONE ;
// se oggetto geometrico
if ( GetGdbGeo( m_pCurrObj) != nullptr)
return GDB_TY_GEO ;
// se gruppo
else if ( GetGdbGroup( m_pCurrObj) != nullptr)
return GDB_TY_GROUP ;
// altro
else
return GDB_TY_NONE ;
}
//----------------------------------------------------------------------------
IGeoObj*
GdbIterator::GetGeoObj( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero l'oggetto Gdb
const GdbGeo* pGdbGeo ;
if ( ( pGdbGeo = GetGdbGeo( m_pCurrObj)) == nullptr)
return nullptr ;
// restituisco il suo contenuto geometrico
return pGdbGeo->m_pGeoObj ;
}
//----------------------------------------------------------------------------
IGeoFrame3d*
GdbIterator::GetGeoFrame( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return nullptr ;
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( m_pCurrObj)) == nullptr)
return nullptr ;
return &( pGdbGroup->m_gfrFrame) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetGroupFrame( Frame3d& frGlob) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( m_pCurrObj)) == nullptr)
return false ;
// copio il riferimento
frGlob = pGdbGroup->m_gfrFrame.m_frF ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetGroupGlobFrame( Frame3d& frGlob) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( m_pCurrObj)) == nullptr)
return false ;
return pGdbGroup->GetGlobFrame( frGlob) ;
}
//----------------------------------------------------------------------------
int
GdbIterator::GetId( void) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return GDB_ID_NULL ;
return m_pCurrObj->m_nId ;
}
//----------------------------------------------------------------------------
int
GdbIterator::GetParentId( void) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return GDB_ID_NULL ;
return m_pCurrObj->GetParentId() ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetGlobFrame( Frame3d& frGlob) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// eseguo l'operazione
GdbGroup* pGdbGroup = m_pCurrObj->GetParent() ;
if ( pGdbGroup == nullptr)
return false ;
return pGdbGroup->GetGlobFrame( frGlob) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetLocalBBox( BBox3d& b3Loc, int nFlag) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// eseguo l'operazione
return m_pCurrObj->GetLocalBBox( b3Loc, nFlag) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetGlobalBBox( BBox3d& b3Glob, int nFlag) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il riferimento globale del gruppo cui appartiene
Frame3d frGlob ;
if ( ! GetGlobFrame( frGlob))
return false ;
// eseguo l'operazione
return m_pCurrObj->GetBBox( frGlob, b3Glob, nFlag) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetRefBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il riferimento globale del gruppo cui appartiene
Frame3d frGlob ;
if ( ! GetGlobFrame( frGlob))
return false ;
// lo porto nel riferimento passato
frGlob.ToLoc( frRef) ;
// eseguo l'operazione
return m_pCurrObj->GetBBox( frGlob, b3Ref, nFlag) ;
}
//----------------------------------------------------------------------------
// Attributes
//----------------------------------------------------------------------------
bool
GdbIterator::SetLevel( int nLevel)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno il livello
return m_pCurrObj->SetLevel( nLevel) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::RevertLevel( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// ripristino il livello precedente
return m_pCurrObj->RevertLevel() ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetLevel( int& nLevel) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il livello
return m_pCurrObj->GetLevel( nLevel) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcLevel( int& nLevel) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il livello calcolato
return m_pCurrObj->GetCalcLevel( nLevel) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetMode( int nMode)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno il modo
return m_pCurrObj->SetMode( nMode) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::RevertMode( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// ripristino il modo precedente
return m_pCurrObj->RevertMode() ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetMode( int& nMode) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il modo
return m_pCurrObj->GetMode( nMode) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcMode( int& nMode) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il modo calcolato
return m_pCurrObj->GetCalcMode( nMode) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetStatus( int nStat)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// la funzione chiamata gestisce l'aggiornamento della lista dei selezionati
return m_pGDB->SetStatus( m_pCurrObj, nStat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::RevertStatus( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// la funzione chiamata gestisce l'aggiornamento della lista dei selezionati
return m_pGDB->RevertStatus( m_pCurrObj) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetStatus( int& nStat) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero lo stato
return m_pCurrObj->GetStatus( nStat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcStatus( int& nStat) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero lo stato calcolato
return m_pCurrObj->GetCalcStatus( nStat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetMark( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// imposto la marcatura
return m_pCurrObj->SetMark() ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::ResetMark( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// cancello la marcatura
return m_pCurrObj->ResetMark() ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetMark( int& nMark) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero la marcatura
return m_pCurrObj->GetMark( nMark) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcMark( int& nMark) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero la marcatura calcolata
return m_pCurrObj->GetCalcMark( nMark) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetMaterial( int nMat)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno il materiale tramite indice
return m_pCurrObj->SetMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetMaterial( Color cCol)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno il materiale tramite colore
return m_pCurrObj->SetMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetMaterial( int& nMat) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero l'indice del materiale
return m_pCurrObj->GetMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetMaterial( Color& cCol) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il colore del materiale
return m_pCurrObj->GetMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcMaterial( int& nMat) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero l'indice del materiale calcolato
return m_pCurrObj->GetCalcMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcMaterial( Color& cCol) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il colore del materiale calcolato
return m_pCurrObj->GetCalcMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetName( const string& sName)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno il nome
return m_pCurrObj->SetName( sName) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetName( string& sName) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il nome
return m_pCurrObj->GetName( sName) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::RemoveName( void)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// rimuovo il nome
return m_pCurrObj->RemoveName() ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetInfo( const string& sKey, const string& sInfo)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno l'Info
return m_pCurrObj->SetInfo( sKey, sInfo) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetInfo( const string& sKey, string& sInfo) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero l'Info
return m_pCurrObj->GetInfo( sKey, sInfo) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::RemoveInfo( const string& sKey)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// rimuovo l'Info
return m_pCurrObj->RemoveInfo( sKey) ;
}