Files
EgtGeomKernel/GdbGeo.cpp
T
Dario Sassi f956fd20cc EgtGeomKernel 1.5d5 :
- aggiunta scrittura binaria
- tolte GetKey, Load e Save da interfaccia IGeoObj.
2014-04-14 15:57:58 +00:00

303 lines
8.2 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : GdbGeo.cpp Data : 24.11.13 Versione : 1.3a1
// Contenuto : Implementazione della classe GdbGeo oggetto del DB geometrico.
//
//
//
// Modifiche : 22.01.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "GdbGeo.h"
#include "GeoObjFactory.h"
#include "CurveAux.h"
#include "Attribs.h"
#include "NgeWriter.h"
#include "GeoObjRW.h"
#include "/EgtDev/Include/EGkGdbFunct.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
GdbGeo::GdbGeo( void)
{
m_pGeoObj = nullptr ;
}
//----------------------------------------------------------------------------
GdbGeo::~GdbGeo( void)
{
if ( m_pGeoObj != nullptr)
delete m_pGeoObj ;
m_pGeoObj = nullptr ;
}
//----------------------------------------------------------------------------
GdbGeo*
GdbGeo::Clone( int nId, IdManager& IdMgr) const
{
GdbGeo* pGdbGeo ;
// alloco oggetto Gdb
pGdbGeo = new(nothrow) GdbGeo ;
if ( pGdbGeo == nullptr)
return nullptr ;
// copio dati oggetto Gdb
pGdbGeo->GdbObj::Copy( this) ;
// assegno nuovo Id
pGdbGeo->m_nId = nId ;
// l'aggiornamento del manager di Id viene fatto all'inserimento nel DB
// copio oggetto Geo
if ( m_pGeoObj != nullptr) {
pGdbGeo->m_pGeoObj = m_pGeoObj->Clone() ;
if ( pGdbGeo->m_pGeoObj == nullptr) {
delete pGdbGeo ;
return nullptr ;
}
}
return pGdbGeo ;
}
//----------------------------------------------------------------------------
GeoObjType
GdbGeo::GetType( void) const
{
// non esiste l'oggetto geometrico
if ( m_pGeoObj == nullptr)
return GEO_NONE ;
return m_pGeoObj->GetType() ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::Save( NgeWriter& ngeOut) const
{
// recupero il gestore di lettura/scrittura dell'entità
IGeoObjRW* pGObjRW = dynamic_cast<IGeoObjRW*>( m_pGeoObj) ;
if ( pGObjRW == nullptr)
return false ;
// tipo entità e identificativi
ngeOut.WriteKey( pGObjRW->GetNgeId(), true) ;
ngeOut.WriteInt( m_nId, "@") ;
ngeOut.WriteInt( GetParentId(), nullptr, true) ;
// attributi
if ( ! GdbObj::SaveAttribs( ngeOut))
return false ;
// parametri geometrici
ngeOut.WriteKey( NGE_G, true) ;
return pGObjRW->Save( ngeOut) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::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 ;
// leggo la prossima linea
if ( ! TheScanner.GetLine( sLine))
return false ;
// eventuali attributi
if ( sLine == "A") {
if ( ! GdbObj::LoadAttribs( TheScanner))
return false ;
// leggo la prossima linea
if ( ! TheScanner.GetLine( sLine))
return false ;
}
// verifico inizio dati geometrici
if ( sLine != "G")
return false ;
// parametri geometrici
IGeoObjRW* pGObjRW = dynamic_cast<IGeoObjRW*>( m_pGeoObj) ;
return ( pGObjRW != nullptr && pGObjRW->Load( TheScanner)) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::GetLocalBBox( BBox3d& b3Loc, int nFlag, int nLev) const
{
if ( m_pGeoObj == nullptr)
return false ;
// se richiesto controllo visibilità oggetto
if ( ( nFlag & BBF_ONLY_VISIBLE) != 0) {
// recupero lo stato dell'oggetto
int nStat = GDB_ST_ON ;
if ( nLev == 0)
// questa funzione già tiene conto del modo
GetCalcStatus( nStat) ;
else {
// devo aggiustare lo stato con il modo
GetStatus( nStat) ;
int nMode = GDB_MD_STD ;
GetMode( nMode) ;
nStat = ::AdjustStatusWithMode( nStat, nMode) ;
}
// se non visibile
if ( nStat == GDB_ST_OFF) {
b3Loc.Reset() ;
return true ;
}
}
return m_pGeoObj->GetLocalBBox( b3Loc) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag, int nLev) const
{
if ( m_pGeoObj == nullptr)
return false ;
// se richiesto controllo visibilità oggetto
if ( ( nFlag & BBF_ONLY_VISIBLE) != 0) {
// recupero lo stato dell'oggetto
int nStat = GDB_ST_ON ;
if ( nLev == 0)
// questa funzione già tiene conto del modo
GetCalcStatus( nStat) ;
else {
// devo aggiustare lo stato con il modo
GetStatus( nStat) ;
int nMode = GDB_MD_STD ;
GetMode( nMode) ;
nStat = ::AdjustStatusWithMode( nStat, nMode) ;
}
// se non visibile
if ( nStat == GDB_ST_OFF) {
b3Ref.Reset() ;
return true ;
}
}
return m_pGeoObj->GetBBox( frRef, b3Ref) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::Translate( const Vector3d& vtMove)
{
if ( m_pGeoObj == nullptr)
return false ;
return m_pGeoObj->Translate( vtMove) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::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
GdbGeo::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))
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) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
{
if ( m_pGeoObj == nullptr)
return false ;
return m_pGeoObj->Mirror( ptOn, vtNorm) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::ToGlob( const Frame3d& frRef)
{
if ( m_pGeoObj == nullptr)
return false ;
return m_pGeoObj->ToGlob( frRef) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::ToLoc( const Frame3d& frRef)
{
if ( m_pGeoObj == nullptr)
return false ;
return m_pGeoObj->ToLoc( frRef) ;
}
//----------------------------------------------------------------------------
bool
GdbGeo::OnSetMaterial( void)
{
if ( m_pGeoObj->GetObjGraphics() != nullptr)
m_pGeoObj->GetObjGraphics()->Reset() ;
return true ;
}