EgtGeomKernel :

- gestione cancellazione oggetti puntati da GdbIterator
- aggiunte a GdbIterator EraseAndGoToNext e EraseAndGoToPrev
- possibilità di passare IGeomDB* al costruttore di GdbIterator.
This commit is contained in:
Dario Sassi
2014-03-23 21:38:09 +00:00
parent 155c722466
commit 033236491d
10 changed files with 176 additions and 19 deletions
+2
View File
@@ -251,6 +251,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClCompile Include="GeoObj.cpp" />
<ClCompile Include="GeoPoint3d.cpp" />
<ClCompile Include="GeoVector3d.cpp" />
<ClCompile Include="IterManager.cpp" />
<ClCompile Include="OutScl.cpp" />
<ClCompile Include="Point3d.cpp" />
<ClCompile Include="PolyLine.cpp" />
@@ -326,6 +327,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClInclude Include="GeoPoint3d.h" />
<ClInclude Include="GeoVector3d.h" />
<ClInclude Include="IdManager.h" />
<ClInclude Include="IterManager.h" />
<ClInclude Include="ObjGraphicsMgr.h" />
<ClInclude Include="OutScl.h" />
<ClInclude Include="PolynomialPoint3d.h" />
+6
View File
@@ -132,6 +132,9 @@
<ClCompile Include="Color.cpp">
<Filter>File di origine\Base</Filter>
</ClCompile>
<ClCompile Include="IterManager.cpp">
<Filter>File di origine\Gdb</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@@ -335,6 +338,9 @@
<ClInclude Include="SelManager.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="IterManager.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EgtGeomKernel.rc">
+1 -2
View File
@@ -1685,7 +1685,6 @@ GdbExecutor::OutGroupScl( int nId, int nFlag)
int nParentId ;
int nGdbType ;
Frame3d frFrame ;
GdbIterator Iter ;
m_OutScl.Remark( "Start Group ---") ;
@@ -1708,7 +1707,7 @@ GdbExecutor::OutGroupScl( int nId, int nFlag)
}
// emetto entità gruppo
m_OutScl.Remark( "Entities :") ;
Iter.SetGDB( m_pGDB) ;
GdbIterator Iter( m_pGDB) ;
bNext = Iter.GoToFirstInGroup( nId) ;
while ( bNext) {
nGdbType = Iter.GetGdbType() ;
+43 -6
View File
@@ -21,24 +21,29 @@ using namespace std ;
//----------------------------------------------------------------------------
IGdbIterator*
CreateGdbIterator( void)
CreateGdbIterator( IGeomDB* pGDB)
{
return static_cast<IGdbIterator*> ( new GdbIterator) ;
return static_cast<IGdbIterator*> ( new GdbIterator( pGDB) ) ;
}
//----------------------------------------------------------------------------
// GdbIterator
//----------------------------------------------------------------------------
GdbIterator::GdbIterator( void)
GdbIterator::GdbIterator( IGeomDB* pGDB)
{
m_pGDB = nullptr ;
if ( pGDB != nullptr)
SetGDB( pGDB) ;
else
m_pGDB = nullptr ;
m_pCurrObj = nullptr ;
}
//----------------------------------------------------------------------------
GdbIterator::~GdbIterator( void)
{
// TODO : togliere link da GdbGeom per essere notificato della cancellazione di nodi
if ( m_pGDB != nullptr)
m_pGDB->RemoveGdbIteratorFromList( this) ;
}
//----------------------------------------------------------------------------
@@ -46,8 +51,10 @@ bool
GdbIterator::SetGDB( IGeomDB* pGDB)
{
m_pGDB = dynamic_cast<GeomDB*>( pGDB) ;
if ( m_pGDB == nullptr)
return false ;
return ( m_pGDB != nullptr) ;
return m_pGDB->AddGdbIteratorToList( this) ;
}
//----------------------------------------------------------------------------
@@ -188,6 +195,36 @@ GdbIterator::GoToPrev( void)
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
+6 -2
View File
@@ -31,6 +31,8 @@ class GdbIterator : public IGdbIterator
virtual bool GoToLastInGroup( int nIdGroup) ;
virtual bool GoToLastInGroup( const IGdbIterator& iIter) ;
virtual bool GoToPrev( void) ;
virtual bool EraseAndGoToNext( void) ;
virtual bool EraseAndGoToPrev( void) ;
virtual int GetGdbType( void) const ;
virtual IGeoObj* GetGeoObj( void) ;
@@ -73,8 +75,10 @@ class GdbIterator : public IGdbIterator
virtual bool RemoveInfo( const std::string& sKey) ;
public :
GdbIterator( void) ;
GdbIterator( IGeomDB* pGDB = nullptr) ;
void ResetCurrObjIfSame( GdbObj* pObj)
{ if ( m_pCurrObj == pObj)
m_pCurrObj = nullptr ; }
private :
GeomDB* m_pGDB ;
GdbObj* m_pCurrObj ;
+19 -1
View File
@@ -620,12 +620,30 @@ GeomDB::Erase( int nId)
if ( pGdbObj == nullptr)
return false ;
return Erase( pGdbObj) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Erase( GdbObj* pGdbObj)
{
// deve essere valido
if ( pGdbObj == nullptr)
return false ;
// non si può cancellare il gruppo radice
if ( pGdbObj == &m_GrpRadix)
return false ;
// elimino da mappa dei nomi
m_IdManager.RemoveObj( nId) ;
m_IdManager.RemoveObj( pGdbObj->m_nId) ;
// eliminazione eventuale da lista dei selezionati
m_SelManager.RemoveObj( pGdbObj) ;
// sistemazioni in eventuali GdbIterator con quell'oggetto corrente
m_IterManager.ResetObjIfSame( pGdbObj) ;
// lo tolgo dalla lista
pGdbObj->Remove() ;
+10 -7
View File
@@ -16,14 +16,11 @@
#include "GdbGeo.h"
#include "GdbGroup.h"
#include "IdManager.h"
#include "IterManager.h"
#include "SelManager.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include <string>
//----------------------------------------------------------------------------
class CScan ;
//----------------------------------------------------------------------------
class GeomDB : public IGeomDB
{
@@ -120,14 +117,20 @@ class GeomDB : public IGeomDB
GdbGroup* GetGdbGroup( int nId)
{ return dynamic_cast<GdbGroup*>( GetGdbObj( nId)) ; }
bool AddToGeomDB( GdbObj* pGObj, int nParentId) ;
bool Erase( GdbObj* pGObj) ;
bool LoadHeader( Scanner& TheScanner) ;
bool LoadOneObj( Scanner& TheScanner, bool& bEnd) ;
bool SaveHeader( std::ostream& osOut) const ;
bool SetStatus( GdbObj* pGdbObj, int nStat) ;
bool RevertStatus( GdbObj* pGdbObj) ;
bool AddGdbIteratorToList( GdbIterator* pIter)
{ return m_IterManager.AddGdbIterator( pIter) ; }
bool RemoveGdbIteratorFromList( GdbIterator* pIter)
{ return m_IterManager.RemoveGdbIterator( pIter) ; }
private :
GdbGroup m_GrpRadix ; // gruppo radice di tutto il DB
IdManager m_IdManager ; // gestore del nuovo Id
SelManager m_SelManager ; // gestore lista oggetti selezionati
GdbGroup m_GrpRadix ; // gruppo radice di tutto il DB
IdManager m_IdManager ; // gestore del nuovo Id
IterManager m_IterManager ; // gestore lista iteratori attivi
SelManager m_SelManager ; // gestore lista oggetti selezionati
} ;
+32
View File
@@ -0,0 +1,32 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : IterManager.cpp Data : 23.03.14 Versione : 1.5c9
// Contenuto : Implementazione di alcuni metodi della classe IterManager
// (non possono stare nell'header per problemi di richiami ricursivi)
//
//
// Modifiche : 20.03.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "IterManager.h"
#include "GdbIterator.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
IterManager::ResetObjIfSame( GdbObj* pGdbObj)
{
PGDBI_LIST::const_iterator Iter ;
for ( Iter = m_IterList.begin() ; Iter != m_IterList.end() ; ++ Iter) {
if ( *Iter != nullptr) {
(*Iter)->ResetCurrObjIfSame( pGdbObj) ;
}
}
return true ;
}
+56
View File
@@ -0,0 +1,56 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : IterManager.h Data : 23.03.14 Versione : 1.5c9
// Contenuto : Dichiarazione e implementazione della classe IterManager.
//
//
//
// Modifiche : 23.03.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include <list>
class GdbIterator ;
class GdbObj ;
//----------------------------------------------------------------------------
typedef std::list<GdbIterator*> PGDBI_LIST ;
//----------------------------------------------------------------------------
class IterManager
{
public :
bool IsGdbIteratorInList( GdbIterator* pIter)
{ PGDBI_LIST::const_iterator Iter ;
for ( Iter = m_IterList.begin() ; Iter != m_IterList.end() ; ++ Iter) {
if ( *Iter == pIter)
return true ;
}
return false ; }
bool AddGdbIterator( GdbIterator* pIter)
{ if ( pIter == nullptr)
return false ;
if ( IsGdbIteratorInList( pIter))
return true ;
try { m_IterList.push_back( pIter) ; }
catch (...) { return false ;}
return true ; }
bool RemoveGdbIterator( GdbIterator* pIter)
{ PGDBI_LIST::iterator Iter ;
for ( Iter = m_IterList.begin() ; Iter != m_IterList.end() ; ++ Iter) {
if ( *Iter == pIter) {
m_IterList.erase( Iter) ;
return true ;
}
}
return true ; }
bool ResetObjIfSame( GdbObj* pGdbObj) ;
private :
PGDBI_LIST m_IterList ;
} ;
+1 -1
View File
@@ -13,9 +13,9 @@
#pragma once
#include "GdbObj.h"
#include <list>
class GdbObj ;
//----------------------------------------------------------------------------
typedef std::list<GdbObj*> PGDBO_LIST ;