//---------------------------------------------------------------------------- // 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 "/EgtDev/Include/EGkStringUtils3d.h" #include using namespace std ; //---------------------------------------------------------------------------- IGdbIterator* CreateGdbIterator( IGeomDB* pGDB) { return static_cast ( 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( 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 (&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 (&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 ; } //---------------------------------------------------------------------------- int GdbIterator::GetGeoType( void) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return GEO_NONE ; if ( GetGdbGeo( m_pCurrObj) != nullptr) return GetGdbGeo( m_pCurrObj)->GetType() ; else return GEO_NONE ; } //---------------------------------------------------------------------------- IGeoObj* GdbIterator::GetGeoObj( void) { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // recupero l'oggetto Gdb GdbGeo* pGdbGeo = GetGdbGeo( m_pCurrObj) ; if ( pGdbGeo == nullptr) return nullptr ; // restituisco il suo contenuto geometrico return pGdbGeo->m_pGeoObj ; } //---------------------------------------------------------------------------- const IGeoObj* GdbIterator::GetGeoObj( void) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // recupero l'oggetto Gdb const GdbGeo* pGdbGeo = GetGdbGeo( m_pCurrObj) ; if ( pGdbGeo == nullptr) return nullptr ; // restituisco il suo contenuto geometrico return pGdbGeo->m_pGeoObj ; } //---------------------------------------------------------------------------- Frame3d* GdbIterator::GetGroupFrame( void) { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return nullptr ; GdbGroup* pGdbGroup = GetGdbGroup( m_pCurrObj) ; if ( pGdbGroup == nullptr) return nullptr ; return &( pGdbGroup->GetFrame()) ; } //---------------------------------------------------------------------------- const Frame3d* GdbIterator::GetGroupFrame( void) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return nullptr ; const GdbGroup* pGdbGroup = GetGdbGroup( m_pCurrObj) ; if ( pGdbGroup == nullptr) return nullptr ; return &( pGdbGroup->GetFrame()) ; } //---------------------------------------------------------------------------- bool GdbIterator::GetGroupFrame( Frame3d& frGlob) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; const GdbGroup* pGdbGroup = GetGdbGroup( m_pCurrObj) ; if ( pGdbGroup == nullptr) return false ; // copio il riferimento frGlob = pGdbGroup->GetFrame() ; return true ; } //---------------------------------------------------------------------------- bool GdbIterator::GetGroupGlobFrame( Frame3d& frGlob) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; const GdbGroup* pGdbGroup = GetGdbGroup( m_pCurrObj) ; if ( pGdbGroup == nullptr) return false ; return pGdbGroup->GetGlobFrame( frGlob) ; } //---------------------------------------------------------------------------- int GdbIterator::GetGroupObjs( void) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return 0 ; const GdbGroup* pGdbGroup = GetGdbGroup( m_pCurrObj) ; if ( pGdbGroup == nullptr) return 0 ; // restituisco il numero di nodi (figli) return pGdbGroup->GetObjCount() ; } //---------------------------------------------------------------------------- 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 const 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_pGDB->SetMaterial( m_pCurrObj, nMat) ; } //---------------------------------------------------------------------------- bool GdbIterator::SetMaterial( int nMat, const string& sMatName) { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // assegno il materiale tramite nome return m_pGDB->SetMaterial( m_pCurrObj, sMatName) ; } //---------------------------------------------------------------------------- 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( Material& mMat) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // recupero il materiale return m_pGDB->GetMaterial( m_pCurrObj, mMat) ; } //---------------------------------------------------------------------------- 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( Material& mMat) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // recupero il materiale return m_pGDB->GetCalcMaterial( m_pCurrObj, mMat) ; } //---------------------------------------------------------------------------- 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::ExistsName( void) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // verifico esistenza del nome return m_pCurrObj->ExistsName() ; } //---------------------------------------------------------------------------- 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::SetInfo( const string& sKey, bool bInfo) { return SetInfo( sKey, ToString( bInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::SetInfo( const string& sKey, int nInfo) { return SetInfo( sKey, ToString( nInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::SetInfo( const string& sKey, double dInfo) { return SetInfo( sKey, ToString( dInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::SetInfo( const string& sKey, const Point3d& ptInfo) { return SetInfo( sKey, ToString( ptInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::SetInfo( const string& sKey, const Vector3d& vtInfo) { return SetInfo( sKey, ToString( vtInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::SetInfo( const string& sKey, const Frame3d& frInfo) { return SetInfo( sKey, ToString( frInfo)) ; } //---------------------------------------------------------------------------- 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::GetInfo( const string& sKey, bool& bInfo) const { string sInfo ; return ( GetInfo( sKey, sInfo) && FromString( sInfo, bInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::GetInfo( const string& sKey, int& nInfo) const { string sInfo ; return ( GetInfo( sKey, sInfo) && FromString( sInfo, nInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::GetInfo( const string& sKey, double& dInfo) const { string sInfo ; return ( GetInfo( sKey, sInfo) && FromString( sInfo, dInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::GetInfo( const string& sKey, Point3d& ptInfo) const { string sInfo ; return ( GetInfo( sKey, sInfo) && FromString( sInfo, ptInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::GetInfo( const string& sKey, Vector3d& vtInfo) const { string sInfo ; return ( GetInfo( sKey, sInfo) && FromString( sInfo, vtInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::GetInfo( const string& sKey, Frame3d& frInfo) const { string sInfo ; return ( GetInfo( sKey, sInfo) && FromString( sInfo, frInfo)) ; } //---------------------------------------------------------------------------- bool GdbIterator::ExistsInfo( const string& sKey) const { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // verifico l'esistenza dell'Info return m_pCurrObj->ExistsInfo( sKey) ; } //---------------------------------------------------------------------------- bool GdbIterator::RemoveInfo( const string& sKey) { if ( m_pGDB == nullptr || m_pCurrObj == nullptr) return false ; // rimuovo l'Info return m_pCurrObj->RemoveInfo( sKey) ; }