//---------------------------------------------------------------------------- // EgalTech 2013-2013 //---------------------------------------------------------------------------- // File : GdbObj.cpp Data : 24.11.13 Versione : 1.3a1 // Contenuto : Implementazione della classe CGdbObj oggetto del DB geometrico. // // // // Modifiche : 22.01.13 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "GdbObj.h" #include "GeoObjFactory.h" #include "CurveAux.h" #include "/EgtDev/Include/EGnStringUtils.h" #include using namespace std ; //---------------------------------------------------------------------------- GdbObj::GdbObj( void) { m_pGeoObj = nullptr ; } //---------------------------------------------------------------------------- GdbObj::~GdbObj( void) { if ( m_pGeoObj != nullptr) delete m_pGeoObj ; m_pGeoObj = nullptr ; } //---------------------------------------------------------------------------- GdbObj* GdbObj::Clone( int nId, IdManager& IdMgr) const { GdbObj* pGdbObj ; // 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 ; } return pGdbObj ; } //---------------------------------------------------------------------------- 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)) 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 GdbObj::Mirror( const Point3d& ptOn, const Vector3d& vtNorm) { if ( m_pGeoObj == nullptr) return false ; return m_pGeoObj->Mirror( ptOn, vtNorm) ; } //---------------------------------------------------------------------------- bool GdbObj::ToGlob( const Frame3d& frRef) { if ( m_pGeoObj == nullptr) return false ; return m_pGeoObj->ToGlob( frRef) ; } //---------------------------------------------------------------------------- bool GdbObj::ToLoc( const Frame3d& frRef) { if ( m_pGeoObj == nullptr) return false ; return m_pGeoObj->ToLoc( frRef) ; }