Files
EgtGeomKernel/GeoVector3d.cpp
T
Dario Sassi 3e8e7e2e2a EgtGeomKernel 1.5l1 :
- aggiornamento a VS2013
- migliorato SimpleOffset e implementato anche per CurveComposite
- il lato di offset ora viene dal segno dello spostamento ( + a destra, - a sinistra)
- il vettore estrusione ora è la normale al piano di offset (se non c'è uso Z+)
- aggiunto a tutte le entità geometriche membro m_nTempProp intero temporaneo
- migliorata DistPointCrvBezier e DistPointArc
- corretta IntersLineArc con linee che non giacciono nel piano XY
- corretta ModifyStart di CurveArc
- a PolyArc aggiunto metodo ParamLinearTransform
- aggiunta gestione riferimento di griglia (CPlane).
2014-12-17 15:03:29 +00:00

246 lines
6.6 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : GeoVector3d.cpp Data : 10.10.13 Versione : 1.2a3
// Contenuto : Implementazione della classe Vettore geometrico.
//
//
//
// Modifiche : 10.10.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "GeoVector3d.h"
#include "GeoObjFactory.h"
#include "NgeWriter.h"
#include "NgeReader.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGkPolyLine.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( GEO_VECT3D, NGE_G_VEC, GeoVector3d) ;
//----------------------------------------------------------------------------
GeoVector3d::GeoVector3d( void)
: m_vtV(), m_nTempProp()
{
}
//----------------------------------------------------------------------------
GeoVector3d::~GeoVector3d( void)
{
}
//----------------------------------------------------------------------------
bool
GeoVector3d::Set( const Vector3d& vtV)
{
// assegno i dati
m_vtV = vtV ;
m_ptBase = ORIG ;
// imposto ricalcolo della grafica
m_OGrMgr.Reset() ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::Set( const Vector3d& vtV, const Point3d& ptBase)
{
// assegno i dati
m_vtV = vtV ;
m_ptBase = ptBase ;
// imposto ricalcolo della grafica
m_OGrMgr.Reset() ;
return true ;
}
//----------------------------------------------------------------------------
GeoVector3d*
GeoVector3d::Clone( void) const
{
// alloco oggetto
GeoVector3d* pGVt = new(nothrow) GeoVector3d ;
if ( pGVt != nullptr) {
if ( ! pGVt->CopyFrom( *this)) {
delete pGVt ;
return nullptr ;
}
}
return pGVt ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::CopyFrom( const IGeoObj* pGObjSrc)
{
const GeoVector3d* pGV = dynamic_cast<const GeoVector3d*>( pGObjSrc) ;
if ( pGV == nullptr)
return false ;
return CopyFrom( *pGV) ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::CopyFrom( const GeoVector3d& clSrc)
{
if ( &clSrc == this)
return true ;
m_nTempProp = clSrc.m_nTempProp ;
return Set( clSrc.m_vtV, clSrc.m_ptBase) ;
}
//----------------------------------------------------------------------------
GeoObjType
GeoVector3d::GetType( void) const
{
return static_cast<GeoObjType>( GEOOBJ_GETTYPE( GeoVector3d)) ;
}
//----------------------------------------------------------------------------
const string&
GeoVector3d::GetTitle( void) const
{
static const string sTitle = "Vector" ;
return sTitle ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::Dump( string& sOut, const char* szNewLine) const
{
// parametri : vettore
sOut += "V(" + ToString( m_vtV) + ")" + szNewLine ;
sOut += "base(" + ToString( m_ptBase) + ")" + szNewLine ;
return true ;
}
//----------------------------------------------------------------------------
int
GeoVector3d::GetNgeId( void) const
{
return GEOOBJ_GETNGEID( GeoVector3d) ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::Save( NgeWriter& ngeOut) const
{
// parametri : vettore
if ( ! ngeOut.WriteVector( m_vtV, ";"))
return false ;
if ( ! ngeOut.WritePoint( m_ptBase, ";", true))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::Load( NgeReader& ngeIn)
{
// imposto ricalcolo della grafica
m_OGrMgr.Reset() ;
// leggo la prossima linea
if ( ! ngeIn.ReadVector( m_vtV, ";"))
return false ;
if ( ! ngeIn.ReadPoint( m_ptBase, ";", true))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::GetLocalBBox( BBox3d& b3Loc, int nFlag) const
{
// il box tiene conto della posizione della base e del tip
b3Loc.Set( m_ptBase, m_ptBase + m_vtV) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const
{
// verifico validità del frame
if ( frRef.GetType() == Frame3d::ERR)
return false ;
// porto la base e il tip nel riferimento passato
Point3d ptFrBase = m_ptBase ;
ptFrBase.ToGlob( frRef) ;
Point3d ptFrTip = m_ptBase + m_vtV ;
ptFrTip.ToGlob( frRef) ;
// assegno il box nel riferimento
b3Ref.Set( ptFrBase, ptFrTip) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::ChangeVector( const Vector3d& vtV)
{
// assegno i dati
m_vtV = vtV ;
// imposto ricalcolo della grafica
m_OGrMgr.Reset() ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::ChangeBase( const Point3d& ptBase)
{
// assegno i dati
m_ptBase = ptBase ;
// imposto ricalcolo della grafica
m_OGrMgr.Reset() ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::GetDrawWithArrowHead( double dFrazLenAH, double dMaxDimA, PolyLine& PL) const
{
// vettore
PL.AddUPoint( 0, m_ptBase) ;
Point3d ptTip = m_ptBase + m_vtV ;
PL.AddUPoint( 1, ptTip) ;
// doppia freccia
const double A_WIDTH_COEFF = 0.3 ;
double dLenAH = min( dMaxDimA, dFrazLenAH * m_vtV.Len()) ;
Frame3d frF ;
frF.Set( ptTip, m_vtV) ;
Point3d ptP1 = ORIG + Vector3d( A_WIDTH_COEFF, 0, -1) * dLenAH ;
ptP1.ToGlob( frF) ;
PL.AddUPoint( 2, ptP1) ;
Point3d ptP2 = ORIG + Vector3d( -A_WIDTH_COEFF, 0, -1) * dLenAH ;
ptP2.ToGlob( frF) ;
PL.AddUPoint( 3, ptP2) ;
PL.AddUPoint( 4, ptTip) ;
Point3d ptP3 = ORIG + Vector3d( 0, A_WIDTH_COEFF, -1) * dLenAH ;
ptP3.ToGlob( frF) ;
PL.AddUPoint( 5, ptP3) ;
Point3d ptP4 = ORIG + Vector3d( 0, -A_WIDTH_COEFF, -1) * dLenAH ;
ptP4.ToGlob( frF) ;
PL.AddUPoint( 6, ptP4) ;
PL.AddUPoint( 7, ptTip) ;
return true ;
}