//---------------------------------------------------------------------------- // 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 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) const { // alloco oggetto Gdb GdbGeo* pGdbGeo = new(nothrow) GdbGeo ; if ( pGdbGeo == nullptr) return nullptr ; // copio dati oggetto Gdb pGdbGeo->GdbObj::CopyFrom( this) ; // assegno nuovo Id pGdbGeo->m_nId = nId ; // l'aggiornamento del manager di Id viene fatto all'inserimento nel DB // assegno il riferimento al DB geometrico pGdbGeo->SetGeomDB( m_pGDB) ; // 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( m_pGeoObj) ; if ( pGObjRW == nullptr) return false ; // tipo entità e identificativi if ( ! ngeOut.WriteKey( pGObjRW->GetNgeId())) return false ; if ( ! ngeOut.WriteInt( m_nId, "@")) return false ; if ( ! ngeOut.WriteInt( GetParentId(), nullptr, true)) return false ; // attributi if ( ! GdbObj::SaveAttribs( ngeOut)) return false ; // parametri geometrici if ( ! ngeOut.WriteKey( NGE_G)) return false ; 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( 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 ; } } // se richiesto controllo non sia un testo if ( ( nFlag & BBF_IGNORE_TEXT) != 0) { // recupero il tipo di oggetto if ( m_pGeoObj->GetType() == EXT_TEXT) { b3Loc.Reset() ; return true ; } } return m_pGeoObj->GetLocalBBox( b3Loc, nFlag) ; } //---------------------------------------------------------------------------- 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 ; } } // se richiesto controllo non sia un testo if ( ( nFlag & BBF_IGNORE_TEXT) != 0) { // recupero il tipo di oggetto if ( m_pGeoObj->GetType() == EXT_TEXT) { b3Ref.Reset() ; return true ; } } return m_pGeoObj->GetBBox( frRef, b3Ref, nFlag) ; } //---------------------------------------------------------------------------- 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)) { // curva originale ICurve* pCrv = GetCurve( m_pGeoObj) ; // trasformo in curva di Bezier (semplice o composta) ICurve* pCrvNew = ArcToBezierCurve( pCrv) ; if ( pCrvNew == nullptr) return false ; // assegno alla nuova curva estrusione e spessore di quella originale Vector3d vtExtr ; if ( pCrv->GetExtrusion( vtExtr)) pCrvNew->SetExtrusion( vtExtr) ; double dThick ; if ( pCrv->GetThickness( dThick)) pCrvNew->SetThickness( dThick) ; // 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() || ! AreSameOrOppositeVectorExact( pArc->GetNormVersor(), vtNorm)) { // trasformo in curva di Bezier (semplice o composta) ICurve* pCrvNew = ArcToBezierCurve( GetCurve( m_pGeoObj)) ; if ( pCrvNew == nullptr) return false ; // assegno alla nuova curva estrusione e spessore di quella originale Vector3d vtExtr ; if ( pArc->GetExtrusion( vtExtr)) pCrvNew->SetExtrusion( vtExtr) ; double dThick ; if ( pArc->GetThickness( dThick)) pCrvNew->SetThickness( dThick) ; // 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 ; }