//---------------------------------------------------------------------------- // 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 #include "\EgtDev\Include\EGnStringUtils.h" #include "GdbObj.h" #include "GeoObjFactory.h" 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) ; return true ; } //---------------------------------------------------------------------------- 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::Translate( const Vector3d& vtMove) { if ( m_pGeoObj != nullptr) return m_pGeoObj->Translate( vtMove) ; else return false ; } //---------------------------------------------------------------------------- bool GdbObj::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) { if ( m_pGeoObj != nullptr) return m_pGeoObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ; else return false ; } //---------------------------------------------------------------------------- bool GdbObj::Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) { if ( m_pGeoObj != nullptr) return m_pGeoObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; else return false ; }