Files
EgtGeomKernel/GdbObj.cpp
T

217 lines
5.9 KiB
C++

//----------------------------------------------------------------------------
// 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 "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
#include "/EgtDev/Include/EgkCurveBezier.h"
#include "/EgtDev/Include/EgkCurveArc.h"
#include <new>
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 m_pGeoObj->GetLocalBBox( b3Loc) ;
else
return false ;
}
//----------------------------------------------------------------------------
bool
GdbObj::GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const
{
if ( m_pGeoObj != nullptr)
return m_pGeoObj->GetBBox( frRef, b3Ref) ;
else
return false ;
}
//----------------------------------------------------------------------------
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 Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
{
if ( m_pGeoObj != nullptr) {
// se scalatura non omogenea e arco, devo trasformare in curva di Bezier
if ( m_pGeoObj->GetType() == CRV_ARC &&
(fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL)) {
// creo la curva di Bezier
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
if ( ! IsValid( pCrvBez))
return false ;
if ( ! pCrvBez->FromArc( *GetCurveArc( m_pGeoObj)))
return false ;
// elimino l'arco e lo sostituisco con la curva di Bezier
delete m_pGeoObj ;
m_pGeoObj = Release( pCrvBez) ;
}
// eseguo scalatura
return m_pGeoObj->Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ;
}
else
return false ;
}
//----------------------------------------------------------------------------
bool
GdbObj::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
{
if ( m_pGeoObj != nullptr)
return m_pGeoObj->Mirror( ptOn, vtNorm) ;
else
return false ;
}
//----------------------------------------------------------------------------
bool
GdbObj::ToGlob( const Frame3d& frRef)
{
if ( m_pGeoObj != nullptr)
return m_pGeoObj->ToGlob( frRef) ;
else
return false ;
}
//----------------------------------------------------------------------------
bool
GdbObj::ToLoc( const Frame3d& frRef)
{
if ( m_pGeoObj != nullptr)
return m_pGeoObj->ToLoc( frRef) ;
else
return false ;
}