41a38fef3b
- aggiunta entità testo (con font Nfe e di sistema) - in tutte le rotate ora l'angolo è in gradi - aggiunta trasformazione Shear (scorrimento) - aggiunta trsformazione LocToLoc - Set/GetInfo specializzate per i diversi tipi di informazioni - Copy e Relocate con possibilità di indicare l'entità di riferimento rispetto a cui inserire - aggiunte trasformazioni a PolyLine.
335 lines
9.2 KiB
C++
335 lines
9.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 "NgeReader.h"
|
|
#include "GeoObjRW.h"
|
|
#include "/EgtDev/Include/EGkCurveArc.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'oggetto
|
|
IGeoObjRW* pGObjRW = dynamic_cast<IGeoObjRW*>( m_pGeoObj) ;
|
|
if ( pGObjRW == nullptr)
|
|
return false ;
|
|
|
|
// tipo entità e identificativi
|
|
ngeOut.WriteKey( pGObjRW->GetNgeId()) ;
|
|
ngeOut.WriteInt( m_nId, "@") ;
|
|
ngeOut.WriteInt( GetParentId(), nullptr, true) ;
|
|
|
|
// attributi
|
|
if ( ! GdbObj::SaveAttribs( ngeOut))
|
|
return false ;
|
|
|
|
// parametri geometrici
|
|
ngeOut.WriteKey( NGE_G) ;
|
|
return pGObjRW->Save( ngeOut) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbGeo::Load( int nNgeId, NgeReader& ngeIn, int& nParentId)
|
|
{
|
|
string sLine ;
|
|
STRVECTOR vsParams ;
|
|
|
|
|
|
// creo l'oggetto geometrico corrispondente
|
|
int nType = GEOOBJ_NGEIDTOTYPE( nNgeId) ;
|
|
m_pGeoObj = GEOOBJ_CREATE( nType) ;
|
|
if ( m_pGeoObj == nullptr)
|
|
return false ;
|
|
|
|
// leggo la prossima linea
|
|
if ( ! ngeIn.ReadInt( m_nId, "@"))
|
|
return false ;
|
|
if ( ! ngeIn.ReadInt( nParentId, nullptr, true))
|
|
return false ;
|
|
|
|
// leggo la prossima linea
|
|
int nKey ;
|
|
if ( ! ngeIn.ReadKey( nKey))
|
|
return false ;
|
|
|
|
// eventuali attributi
|
|
if ( nKey == NGE_A) {
|
|
if ( ! GdbObj::LoadAttribs( ngeIn))
|
|
return false ;
|
|
// leggo la prossima linea
|
|
if ( ! ngeIn.ReadKey( nKey))
|
|
return false ;
|
|
}
|
|
|
|
// verifico inizio dati geometrici
|
|
if ( nKey != NGE_G)
|
|
return false ;
|
|
|
|
// parametri geometrici
|
|
IGeoObjRW* pGObjRW = dynamic_cast<IGeoObjRW*>( m_pGeoObj) ;
|
|
return ( pGObjRW != nullptr && pGObjRW->Load( ngeIn)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
|
|
{
|
|
if ( m_pGeoObj == nullptr)
|
|
return false ;
|
|
|
|
// verifiche per arco
|
|
if ( m_pGeoObj->GetType() == CRV_ARC) {
|
|
// ricavo puntatore ad arco
|
|
ICurveArc* pArc = GetCurveArc( m_pGeoObj) ;
|
|
// se l'arco non è piatto o il piano di scorrimento non coincide con quello dell'arco
|
|
if ( ! pArc->IsFlat() ||
|
|
! ( AreSameVectorExact( pArc->GetNormVersor(), vtNorm) ||
|
|
AreOppositeVectorExact( pArc->GetNormVersor(), vtNorm))) {
|
|
// 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 scorrimento
|
|
return m_pGeoObj->Shear( ptOn, vtNorm, vtDir, dCoeff) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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::LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
|
|
{
|
|
if ( m_pGeoObj == nullptr)
|
|
return false ;
|
|
|
|
return m_pGeoObj->LocToLoc( frOri, frDest) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbGeo::OnSetMaterial( void)
|
|
{
|
|
if ( m_pGeoObj->GetObjGraphics() != nullptr)
|
|
m_pGeoObj->GetObjGraphics()->Reset() ;
|
|
|
|
return true ;
|
|
}
|