EgtGeomKernel 1.5c1 :
- aggiunta prima gestione attributi.
This commit is contained in:
+214
-153
@@ -1,12 +1,12 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2013-2013
|
||||
//----------------------------------------------------------------------------
|
||||
// File : GdbObj.cpp Data : 24.11.13 Versione : 1.3a1
|
||||
// Contenuto : Implementazione della classe CGdbObj oggetto del DB geometrico.
|
||||
// File : GdbObj.cpp Data : 05.03.14 Versione : 1.5c1
|
||||
// Contenuto : Implementazione della classe GdbObj.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 22.01.13 DS Creazione modulo.
|
||||
// Modifiche : 28.11.13 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -14,8 +14,8 @@
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "GdbObj.h"
|
||||
#include "GeoObjFactory.h"
|
||||
#include "CurveAux.h"
|
||||
#include "GdbGroup.h"
|
||||
#include "Attribs.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include <new>
|
||||
|
||||
@@ -23,190 +23,251 @@ using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GdbObj::GdbObj( void)
|
||||
: m_nId( GDB_ID_NULL), m_pAttribs( nullptr),
|
||||
m_pNext( nullptr), m_pPrev( nullptr), m_pParent( nullptr)
|
||||
{
|
||||
m_pGeoObj = nullptr ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GdbObj::~GdbObj( void)
|
||||
{
|
||||
if ( m_pGeoObj != nullptr)
|
||||
delete m_pGeoObj ;
|
||||
m_pGeoObj = nullptr ;
|
||||
if ( m_pAttribs != nullptr)
|
||||
delete m_pAttribs ;
|
||||
m_pAttribs = nullptr ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GdbObj*
|
||||
GdbObj::Clone( int nId, IdManager& IdMgr) const
|
||||
bool
|
||||
GdbObj::Copy( const GdbObj* pSou)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
// elimino eventuali attributi pre-esistenti
|
||||
if ( m_pAttribs != nullptr)
|
||||
delete m_pAttribs ;
|
||||
m_pAttribs = nullptr ;
|
||||
|
||||
|
||||
// alloco oggetto Gdb
|
||||
pGdbObj = new(nothrow) GdbObj ;
|
||||
if ( pGdbObj == nullptr)
|
||||
return nullptr ;
|
||||
|
||||
// copio dati oggetto Gdb
|
||||
pGdbObj->m_nId = nId ;
|
||||
// ...
|
||||
|
||||
// copio oggetto Geo
|
||||
pGdbObj->m_pGeoObj = m_pGeoObj->Clone() ;
|
||||
if ( pGdbObj->m_pGeoObj == nullptr) {
|
||||
delete pGdbObj ;
|
||||
return nullptr ;
|
||||
// se l'oggetto sorgente non esiste
|
||||
if ( pSou == nullptr) {
|
||||
m_nId = GDB_ID_NULL ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
return pGdbObj ;
|
||||
}
|
||||
// copio Id
|
||||
m_nId = pSou->m_nId ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GeoObjType
|
||||
GdbObj::GetType( void) const
|
||||
{
|
||||
// non esiste l'oggetto geometrico
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return GEO_NONE ;
|
||||
|
||||
return m_pGeoObj->GetType() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::Save( std::ostream& osOut) const
|
||||
{
|
||||
// tipo entità
|
||||
osOut << m_pGeoObj->GetKey() << endl ;
|
||||
// nome
|
||||
osOut << m_nId << "@" << GetParentId() << endl ;
|
||||
// parametri geometrici
|
||||
return m_pGeoObj->Save( osOut) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::Load( const std::string& sType, Scanner& TheScanner, int& nParentId)
|
||||
{
|
||||
int nType ;
|
||||
string sLine ;
|
||||
STRVECTOR vsParams ;
|
||||
|
||||
|
||||
// creo l'oggetto geometrico corrispondente
|
||||
nType = GEOOBJ_KEYTOTYPE( sType) ;
|
||||
m_pGeoObj = GEOOBJ_CREATE( nType) ;
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return false ;
|
||||
|
||||
// leggo la prossima linea
|
||||
if ( ! TheScanner.GetLine( sLine))
|
||||
return false ;
|
||||
// la divido in parametri
|
||||
Tokenize( sLine, "@", vsParams) ;
|
||||
// 2 parametri : Id e ParentId
|
||||
if ( vsParams.size() != 2)
|
||||
return false ;
|
||||
// assegno l'identificativo
|
||||
if ( ! FromString( vsParams[0], m_nId))
|
||||
return false ;
|
||||
// assegno l'Id del padre
|
||||
if ( ! FromString( vsParams[1], nParentId))
|
||||
return false ;
|
||||
|
||||
// parametri geometrici
|
||||
return m_pGeoObj->Load( TheScanner) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::GetLocalBBox( BBox3d& b3Loc) const
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->GetLocalBBox( b3Loc) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->GetBBox( frRef, b3Ref) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::Translate( const Vector3d& vtMove)
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->Translate( vtMove) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
return false ;
|
||||
|
||||
// se arco e scalatura non omogenea
|
||||
if ( m_pGeoObj->GetType() == CRV_ARC &&
|
||||
(fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL)) {
|
||||
// trasformo in curva di Bezier (semplice o composta)
|
||||
ICurve* pCrvNew ;
|
||||
if ( ! ArcToBezierCurve( GetCurve( m_pGeoObj), pCrvNew))
|
||||
// copio gli attributi
|
||||
if ( pSou->m_pAttribs != nullptr) {
|
||||
m_pAttribs = pSou->m_pAttribs->Clone() ;
|
||||
if ( m_pAttribs == nullptr)
|
||||
return false ;
|
||||
// elimino l'arco e lo sostituisco con la curva di Bezier
|
||||
delete m_pGeoObj ;
|
||||
m_pGeoObj = pCrvNew ;
|
||||
}
|
||||
|
||||
// eseguo scalatura
|
||||
return m_pGeoObj->Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Node
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
GdbObj::GetParentId( void) const
|
||||
{
|
||||
if ( m_pParent != nullptr)
|
||||
return m_pParent->m_nId ;
|
||||
else
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
|
||||
GdbObj::AddTail( GdbGroup* pParent)
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
// se il padre non è definito, errore
|
||||
if ( pParent == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->Mirror( ptOn, vtNorm) ;
|
||||
// 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::ToGlob( const Frame3d& frRef)
|
||||
GdbObj::AddHead( GdbGroup* pParent)
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
// se il padre non è definito, errore
|
||||
if ( pParent == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->ToGlob( frRef) ;
|
||||
// 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::ToLoc( const Frame3d& frRef)
|
||||
GdbObj::InsertAfter( GdbObj* pRef)
|
||||
{
|
||||
if ( m_pGeoObj == nullptr)
|
||||
// se riferimento non definito, errore
|
||||
if ( pRef == nullptr)
|
||||
return false ;
|
||||
|
||||
return m_pGeoObj->ToLoc( frRef) ;
|
||||
// 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::SetColor( Color cCol)
|
||||
{
|
||||
// recupero gli attributi (se non ci sono, vengono creati)
|
||||
Attribs* pAttribs = GetSafeAttribs() ;
|
||||
if ( pAttribs == nullptr)
|
||||
return false ;
|
||||
|
||||
// assegno il colore
|
||||
pAttribs->SetColor( cCol) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GdbObj::GetColor( Color& cCol) const
|
||||
{
|
||||
// se non ci sono attributi o ci si deve riferire al padre
|
||||
if ( m_pAttribs == nullptr ||
|
||||
m_pAttribs->GetMaterial() == Attribs::MAT_PARENT) {
|
||||
if ( GetParent() != nullptr)
|
||||
return GetParent()->GetColor( cCol) ;
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
// se il colore è definito
|
||||
if ( m_pAttribs->GetMaterial() != Attribs::MAT_NULL) {
|
||||
cCol = m_pAttribs->GetColor() ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user