EgtGeomKernel 1.5a1 : Aggiunta prima versione distanza punto Curva di Bezier.

Ora si esporta la generica classe distanza punto curva.
This commit is contained in:
Dario Sassi
2014-01-05 09:47:43 +00:00
parent b4f2770eb8
commit 2216a87ab4
15 changed files with 580 additions and 91 deletions
+1 -1
View File
@@ -15,10 +15,10 @@
#include "stdafx.h"
#include "DllMain.h"
#include "CurveBezier.h"
#include "DistPointLine.h"
#include "GeoObjFactory.h"
#include "\EgtDev\Include\EGnStringUtils.h"
#include "\EgtDev\Include\EGkCurveArc.h"
#include "\EgtDev\Include\EGkDistPointLine.h"
#include <new>
using namespace std ;
+14 -6
View File
@@ -13,14 +13,17 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "\EgtDev\Include\EGkDistPointArc.h"
#include "DistPointArc.h"
//----------------------------------------------------------------------------
DistPointArc::DistPointArc( const Point3d& ptP, const ICurveArc& arArc)
{
// distanza non calcolata
m_dDist = - 1 ;
if ( ! arArc.IsValid())
m_dDist = - 1 ;
return ;
// se circonferenza
if ( arArc.IsACircle())
@@ -31,10 +34,8 @@ DistPointArc::DistPointArc( const Point3d& ptP, const ICurveArc& arArc)
DistPointFlatArc( ptP, arArc) ;
// altrimenti caso generico
else {
}
else
DistPointHelix( ptP, arArc) ;
}
//----------------------------------------------------------------------------
@@ -104,6 +105,13 @@ DistPointArc::DistPointFlatArc( const Point3d& ptP, const ICurveArc& arArc)
}
}
//----------------------------------------------------------------------------
void
DistPointArc::DistPointHelix( const Point3d& ptP, const ICurveArc& arArc)
{
}
//----------------------------------------------------------------------------
bool
DistPointArc::GetSqDist( double& dSqDist)
+54
View File
@@ -0,0 +1,54 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : DistPointArc.h Data : 28.12.13 Versione : 1.4l5
// Contenuto : Dichiarazione della classe distanza punto da circonferenza/arco.
//
//
//
// Modifiche : 28.12.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGkPoint3d.h"
#include "/EgtDev/Include/EGkCurveArc.h"
//----------------------- Macro per import/export ----------------------------
#undef EGK_EXPORT
#if defined( I_AM_EGK) // da definirsi solo nella DLL
#define EGK_EXPORT __declspec( dllexport)
#else
#define EGK_EXPORT __declspec( dllimport)
#endif
//-----------------------------------------------------------------------------
class DistPointArc
{
friend class DistPointCurve ;
public :
EGK_EXPORT DistPointArc( const Point3d& ptP, const ICurveArc& arArc) ;
public :
EGK_EXPORT bool GetSqDist( double& dSqDist) ;
EGK_EXPORT bool GetDist( double& dDist) ;
EGK_EXPORT bool GetPointMinDist( Point3d& ptMinDist, bool* pbDet = nullptr) ;
EGK_EXPORT bool GetParamAtPointMinDist( double& dParam, bool* pbDet = nullptr) ;
private :
DistPointArc( void) ;
void DistPointCircle( const Point3d& ptP, const ICurveArc& arArc) ;
void DistPointFlatArc( const Point3d& ptP, const ICurveArc& arArc) ;
void DistPointHelix( const Point3d& ptP, const ICurveArc& arArc) ;
private :
bool m_bDet ;
double m_dDist ;
double m_dParam ;
Point3d m_ptMinDist ;
} ;
+177
View File
@@ -0,0 +1,177 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : DistPointCrvBezier.cpp Data : 02.01.14 Versione : 1.5a1
// Contenuto : Implementazione della classe distanza punto da curva di Bezier.
//
//
//
// Modifiche : 02.01.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DistPointCrvBezier.h"
#include "DistPointLine.h"
#include "\EgtDev\Include\EgtTrace.h"
//----------------------------------------------------------------------------
DistPointCrvBezier::DistPointCrvBezier( const Point3d& ptP, const ICurveBezier& CrvBez)
{
const double LIN_TOL_APPROX = 1 ;
const double ANG_TOL_APPROX_DEG = 45 ;
// distanza non calcolata
m_dDist = - 1 ;
if ( ! CrvBez.IsValid())
return ;
// creo una polilinea di approssimazione
PolyLine PL ;
if ( ! CrvBez.ApproxWithLines( LIN_TOL_APPROX, ANG_TOL_APPROX_DEG, PL))
return ;
// cerco la minima distanza per la polilinea
double dSqDist ;
double dMinPar ;
double dMinParIni ;
double dMinParFin ;
double dPar ;
double dUIni ;
double dUFin ;
Point3d ptMinDist ;
Point3d ptIni ;
Point3d ptFin ;
bool bFound = false ;
bool bOnEnd = false ;
double dSqMinDist = INFINITO * INFINITO ;
for ( bool bLine = PL.GetFirstULine( &dUIni, &ptIni, &dUFin, &ptFin) ;
bLine ;
bLine = PL.GetNextULine( &dUIni, &ptIni, &dUFin, &ptFin)) {
// calcolo la distanza del punto dal segmento
DistPointLine dstPtLn( ptP, ptIni, ptFin) ;
if ( dstPtLn.GetSqDist( dSqDist) && dSqDist < dSqMinDist) {
bFound = true ;
dSqMinDist = dSqDist ;
dstPtLn.GetPointMinDist( ptMinDist) ;
dstPtLn.GetParamAtPointMinDist( dPar) ;
dMinPar = ( 1 - dPar) * dUIni + dPar * dUFin ;
dMinParIni = dUIni ;
dMinParFin = dUFin ;
bOnEnd = ( AreSamePointNear( ptMinDist, ptFin)) ;
}
else if ( bOnEnd) {
bOnEnd = false ;
dMinParFin = dUFin ;
}
}
if ( ! bFound)
return ;
// raffino i punti trovati (con algoritmo tipo Newton da TheNurbsBook pag 230)
const int MAX_COUNT = 10 ;
double dMinDist = sqrt( dSqMinDist) ;
double dPrevPar ;
double dTemp ;
double dSqCosA ;
Point3d ptQ ;
Vector3d vtDer1 ;
Vector3d vtDer2 ;
Vector3d vtDiff ;
int nCount = 0 ;
dPar = dMinPar ;
do {
// contatore iterazioni
nCount ++ ;
// calcolo P, D1 e D2
CrvBez.GetPointD1D2( dPar, ICurve::FROM_MINUS, ptQ, &vtDer1, &vtDer2) ;
// se D1 nulla e distanza sicuramente non minima, riprovo sul centro dell'intervallo
if ( vtDer1.IsZero() && Dist( ptQ, ptP) > __min( 1.2 * dMinDist, dMinDist + LIN_TOL_APPROX)) {
dPar = 0.5 * ( dMinParIni + dMinParFin) ;
CrvBez.GetPointD1D2( dPar, ICurve::FROM_MINUS, ptQ, &vtDer1, &vtDer2) ;
}
// vettore dal punto al piede sulla curva
vtDiff = ptQ - ptP ;
// angolo tra vettore e tangente
dTemp = vtDer1 * vtDiff ;
if ( fabs( dTemp) > EPS_ZERO)
dSqCosA = dTemp * dTemp / ( vtDer1.SqLen() * vtDiff.SqLen()) ;
else
dSqCosA = 0 ;
// stima prossimo valore del parametro (Newton : Unext = U - F(U) / F'(U))
dPrevPar = dPar ;
dTemp = vtDer2 * vtDiff + vtDer1.SqLen() ;
if ( fabs( dTemp) > EPS_ZERO)
dPar = dPrevPar - ( vtDer1 * vtDiff) / dTemp ;
// clipping parametro in 0-1
if ( dPar < dMinParIni)
dPar = dMinParIni ;
else if ( dPar > dMinParFin)
dPar = dMinParFin ;
} while ( nCount < MAX_COUNT && fabs( dPar - dPrevPar) > EPS_ZERO &&
fabs( dSqCosA) > COS_ORTO_ANG_ZERO * COS_ORTO_ANG_ZERO) ;
#if defined( _DEBUG)
if ( nCount == MAX_COUNT)
EGT_TRACE( "Exceeded MAX_COUNT in PolishingDistPointCrv.") ;
#endif
// assegno i dati
m_bDet = true ;
m_dDist = Dist( ptP, ptQ) ;
m_dParam = dPrevPar ;
m_ptMinDist = ptQ ;
}
//----------------------------------------------------------------------------
bool
DistPointCrvBezier::GetSqDist( double& dSqDist)
{
if ( m_dDist < 0)
return false ;
dSqDist = m_dDist * m_dDist ;
return true ;
}
//----------------------------------------------------------------------------
bool
DistPointCrvBezier::GetDist( double& dDist)
{
if ( m_dDist < 0)
return false ;
dDist = m_dDist ;
return true ;
}
//----------------------------------------------------------------------------
bool
DistPointCrvBezier::GetPointMinDist( Point3d& ptMinDist, bool* pbDet)
{
if ( m_dDist < 0)
return false ;
ptMinDist = m_ptMinDist ;
if ( pbDet != nullptr)
*pbDet = m_bDet ;
return true ;
}
//----------------------------------------------------------------------------
bool
DistPointCrvBezier::GetParamAtPointMinDist( double& dParam, bool* pbDet)
{
if ( m_dDist < 0)
return false ;
dParam = m_dParam ;
if ( pbDet != nullptr)
*pbDet = m_bDet ;
return true ;
}
+51
View File
@@ -0,0 +1,51 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : DistPointCrvBezier.h Data : 02.01.14 Versione : 1.5a1
// Contenuto : Dichiarazione della classe distanza punto da curva di Bezier.
//
//
//
// Modifiche : 02.01.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGkPoint3d.h"
#include "/EgtDev/Include/EGkCurveBezier.h"
//----------------------- Macro per import/export ----------------------------
#undef EGK_EXPORT
#if defined( I_AM_EGK) // da definirsi solo nella DLL
#define EGK_EXPORT __declspec( dllexport)
#else
#define EGK_EXPORT __declspec( dllimport)
#endif
//-----------------------------------------------------------------------------
class DistPointCrvBezier
{
friend class DistPointCurve ;
public :
EGK_EXPORT DistPointCrvBezier( const Point3d& ptP, const ICurveBezier& CrvBez) ;
public :
EGK_EXPORT bool GetSqDist( double& dSqDist) ;
EGK_EXPORT bool GetDist( double& dDist) ;
EGK_EXPORT bool GetPointMinDist( Point3d& ptMinDist, bool* pbDet = nullptr) ;
EGK_EXPORT bool GetParamAtPointMinDist( double& dParam, bool* pbDet = nullptr) ;
private :
DistPointCrvBezier( void) ;
private :
bool m_bDet ;
double m_dDist ;
double m_dParam ;
Point3d m_ptMinDist ;
} ;
+138
View File
@@ -0,0 +1,138 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : DistPointCurve.cpp Data : 02.01.14 Versione : 1.5a1
// Contenuto : Implementazione della classe distanza punto da Curva.
//
//
//
// Modifiche : 02.01.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DistPointLine.h"
#include "DistPointArc.h"
#include "DistPointCrvBezier.h"
#include "/EgtDev/Include/EGkDistPointCurve.h"
//----------------------------------------------------------------------------
DistPointCurve::DistPointCurve( const Point3d& ptP, const ICurve& Curve)
{
// distanza non calcolata
m_dDist = - 1 ;
// curva non valida
if ( ! Curve.IsValid())
return ;
// chiamo calcolatore opportuno
switch ( Curve.GetType()) {
case CRV_LINE :
LineCalculate( ptP, Curve) ;
break ;
case CRV_ARC :
ArcCalculate( ptP, Curve) ;
break ;
case CRV_BEZ :
CrvBezierCalculate( ptP, Curve) ;
break ;
case CRV_COMPO :
CrvCompositeCalculate( ptP, Curve) ;
break ;
}
}
//----------------------------------------------------------------------------
void
DistPointCurve::LineCalculate( const Point3d& ptP, const ICurve& Curve)
{
DistPointLine dstPtLn( ptP, *GetCurveLine( &Curve)) ;
m_bDet = true ;
m_dDist = (( dstPtLn.m_dSqDist > 0) ? sqrt( dstPtLn.m_dSqDist) : dstPtLn.m_dSqDist) ;
m_dParam = dstPtLn.m_dParam ;
m_ptMinDist = dstPtLn.m_ptMinDist ;
}
//----------------------------------------------------------------------------
void
DistPointCurve::ArcCalculate( const Point3d& ptP, const ICurve& Curve)
{
DistPointArc dstPtArc( ptP, *GetCurveArc( &Curve)) ;
m_bDet = dstPtArc.m_bDet ;
m_dDist = dstPtArc.m_dDist ;
m_dParam = dstPtArc.m_dParam ;
m_ptMinDist = dstPtArc.m_ptMinDist ;
}
//----------------------------------------------------------------------------
void
DistPointCurve::CrvBezierCalculate( const Point3d& ptP, const ICurve& Curve)
{
DistPointCrvBezier dstPtCBez( ptP, *GetCurveBezier( &Curve)) ;
m_bDet = dstPtCBez.m_bDet ;
m_dDist = dstPtCBez.m_dDist ;
m_dParam = dstPtCBez.m_dParam ;
m_ptMinDist = dstPtCBez.m_ptMinDist ;
}
//----------------------------------------------------------------------------
void
DistPointCurve::CrvCompositeCalculate( const Point3d& ptP, const ICurve& Curve)
{
//DistPointCrvComposite dstPtLn( ptP, *GetCurveComposite( &Curve)) ;
}
//----------------------------------------------------------------------------
bool
DistPointCurve::GetSqDist( double& dSqDist)
{
if ( m_dDist < 0)
return false ;
dSqDist = m_dDist * m_dDist ;
return true ;
}
//----------------------------------------------------------------------------
bool
DistPointCurve::GetDist( double& dDist)
{
if ( m_dDist < 0)
return false ;
dDist = m_dDist ;
return true ;
}
//----------------------------------------------------------------------------
bool
DistPointCurve::GetPointMinDist( Point3d& ptMinDist, bool* pbDet)
{
if ( m_dDist < 0)
return false ;
ptMinDist = m_ptMinDist ;
if ( pbDet != nullptr)
*pbDet = m_bDet ;
return true ;
}
//----------------------------------------------------------------------------
bool
DistPointCurve::GetParamAtPointMinDist( double& dParam, bool* pbDet)
{
if ( m_dDist < 0)
return false ;
dParam = m_dParam ;
if ( pbDet != nullptr)
*pbDet = m_bDet ;
return true ;
}
+5 -4
View File
@@ -13,17 +13,18 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "\EgtDev\Include\EGkDistPointLine.h"
#include "DistPointLine.h"
//----------------------------------------------------------------------------
DistPointLine::DistPointLine( const Point3d& ptP,
const ICurveLine& crvLine, bool bIsSegment)
{
if ( ! crvLine.IsValid()) {
m_dSqDist = -1 ;
// distanza non calcolata
m_dDist = - 1 ;
if ( ! crvLine.IsValid())
return ;
}
double dLen ;
Vector3d vtDir ;
+59
View File
@@ -0,0 +1,59 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : DistPointLine.h Data : 02.01.14 Versione : 1.5a1
// Contenuto : Dichiarazione dell'oggetto distanza punto da linea/segmento.
//
//
//
// Modifiche : 30.12.12 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGkPoint3d.h"
#include "/EgtDev/Include/EGkCurveLine.h"
//----------------------- Macro per import/export ----------------------------
#undef EGK_EXPORT
#if defined( I_AM_EGK) // da definirsi solo nella DLL
#define EGK_EXPORT __declspec( dllexport)
#else
#define EGK_EXPORT __declspec( dllimport)
#endif
//-----------------------------------------------------------------------------
class DistPointLine
{
friend class DistPointCurve ;
public :
EGK_EXPORT DistPointLine( const Point3d& ptP,
const ICurveLine& crvLine, bool bIsSegment = true) ;
EGK_EXPORT DistPointLine( const Point3d& ptP,
const Point3d& ptIni, const Point3d& ptFin, bool bIsSegment = true) ;
EGK_EXPORT DistPointLine( const Point3d& ptP,
const Point3d& ptIni, const Vector3d& vtDir, double dLen, bool bIsSegment = true)
{ Calculate( ptP, ptIni, vtDir, dLen, bIsSegment) ; }
public :
EGK_EXPORT bool GetSqDist( double& dSqDist) ;
EGK_EXPORT bool GetDist( double& dDist) ;
EGK_EXPORT bool GetPointMinDist( Point3d& ptMinDist) ;
EGK_EXPORT bool GetParamAtPointMinDist( double& dParam) ;
private :
DistPointLine( void) ;
void Calculate( const Point3d& ptP,
const Point3d& ptIni, const Vector3d& vtDir, double dLen, bool bIsSegment) ;
private :
double m_dSqDist ;
double m_dDist ;
double m_dParam ;
Point3d m_ptMinDist ;
} ;
+3 -3
View File
@@ -13,9 +13,9 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include <\EgtDev\Include\EGkDllMain.h>
#include <\EgtDev\Include\EgnGetModuleVer.h>
#include <\EgtDev\Include\EgtTrace.h>
#include "\EgtDev\Include\EGkDllMain.h"
#include "\EgtDev\Include\EgnGetModuleVer.h"
#include "\EgtDev\Include\EgtTrace.h"
//--------------------------- Costanti ----------------------------------------
#if defined( _DEBUG)
BIN
View File
Binary file not shown.
+8 -2
View File
@@ -119,6 +119,8 @@ copy $(TargetPath) \EgtProg\Dll</Command>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DistPointArc.cpp" />
<ClCompile Include="DistPointCrvBezier.cpp" />
<ClCompile Include="DistPointCurve.cpp" />
<ClCompile Include="DistPointLine.cpp" />
<ClCompile Include="GdbExecutor.cpp" />
<ClCompile Include="CurveArc.cpp" />
@@ -153,8 +155,7 @@ copy $(TargetPath) \EgtProg\Dll</Command>
<ClInclude Include="..\Include\EgkCurveComposite.h" />
<ClInclude Include="..\Include\EgkCurveLine.h" />
<ClInclude Include="..\Include\EGkCurvePointDiffGeom.h" />
<ClInclude Include="..\Include\EGkDistPointArc.h" />
<ClInclude Include="..\Include\EGkDistPointLine.h" />
<ClInclude Include="..\Include\EGkDistPointCurve.h" />
<ClInclude Include="..\Include\EGkDllMain.h" />
<ClInclude Include="..\Include\EGkFrame3d.h" />
<ClInclude Include="..\Include\EGkGdbConst.h" />
@@ -172,8 +173,13 @@ copy $(TargetPath) \EgtProg\Dll</Command>
<ClInclude Include="..\Include\EGkVector3d.h" />
<ClInclude Include="..\Include\EgnGetModuleVer.h" />
<ClInclude Include="..\Include\EGnStringUtils.h" />
<ClInclude Include="..\Include\EgtILogger.h" />
<ClInclude Include="..\Include\EgtLogger.h" />
<ClInclude Include="..\Include\EgtPointerOwner.h" />
<ClInclude Include="..\Include\EgtTrace.h" />
<ClInclude Include="DistPointArc.h" />
<ClInclude Include="DistPointCrvBezier.h" />
<ClInclude Include="DistPointLine.h" />
<ClInclude Include="DllMain.h" />
<ClInclude Include="GdbExecutor.h" />
<ClInclude Include="CurveArc.h" />
+29 -8
View File
@@ -28,6 +28,9 @@
<Filter Include="File di origine\Script">
<UniqueIdentifier>{a3fbb199-9e77-4b66-8f18-7d48b8d6a8e1}</UniqueIdentifier>
</Filter>
<Filter Include="File di origine\Distanze">
<UniqueIdentifier>{cc84f71a-b149-4187-af26-736133e92672}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Vector3d.cpp">
@@ -93,14 +96,20 @@
<ClCompile Include="GdbIterator.cpp">
<Filter>File di origine\Gdb</Filter>
</ClCompile>
<ClCompile Include="DistPointLine.cpp">
<Filter>File di origine\Base</Filter>
</ClCompile>
<ClCompile Include="PolyLine.cpp">
<Filter>File di origine\Base</Filter>
</ClCompile>
<ClCompile Include="DistPointArc.cpp">
<Filter>File di origine\Base</Filter>
<Filter>File di origine\Distanze</Filter>
</ClCompile>
<ClCompile Include="DistPointLine.cpp">
<Filter>File di origine\Distanze</Filter>
</ClCompile>
<ClCompile Include="DistPointCurve.cpp">
<Filter>File di origine\Distanze</Filter>
</ClCompile>
<ClCompile Include="DistPointCrvBezier.cpp">
<Filter>File di origine\Distanze</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@@ -227,9 +236,6 @@
<ClInclude Include="..\Include\EGkDllMain.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EGkDistPointLine.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="DllMain.h">
<Filter>File di intestazione</Filter>
</ClInclude>
@@ -242,7 +248,22 @@
<ClInclude Include="..\Include\EGkGeoCollection.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EGkDistPointArc.h">
<ClInclude Include="DistPointArc.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="DistPointLine.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EGkDistPointCurve.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="DistPointCrvBezier.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EgtILogger.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EgtLogger.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
+35 -60
View File
@@ -25,13 +25,13 @@
#include "/EgtDev/Include/EgkCurveArc.h"
#include "/EgtDev/Include/EgkCurveBezier.h"
#include "/EgtDev/Include/EgkCurveComposite.h"
#include "/EgtDev/Include/EgkDistPointLine.h"
#include "/EgtDev/Include/EgkDistPointArc.h"
#include "/EgtDev/Include/EgkDistPointCurve.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//----------------------------------------------------------------------------
static const int ID_NO = -2 ;
static const int ID_ERROR = -3 ;
//----------------------------------------------------------------------------
@@ -45,6 +45,9 @@ CreateGdbExecutor( void)
GdbExecutor::GdbExecutor( void)
{
m_pGDB = nullptr ;
// alias predefiniti
m_NameMap.insert( pair< string, int>( "$ROOT", GDB_ID_ROOT)) ;
m_NameMap.insert( pair< string, int>( "$NN", ID_NO)) ;
}
//----------------------------------------------------------------------------
@@ -77,12 +80,10 @@ GdbExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR&
sOut += *theConstIter ;
}
sOut += "]" ;
LOG_DBG_INFO( GetEGkLogger(), sOut.c_str()) ;
LOG_DBG_INFO( GetEGkLogger(), sOut.c_str())
// esecuzione comando
if ( sCmd1 == "ALIAS")
return ExecuteAlias( sCmd2, vsParams) ;
else if ( sCmd1 == "GR" || sCmd1 == "GROUP")
if ( sCmd1 == "GR" || sCmd1 == "GROUP")
return ExecuteGroup( sCmd2, vsParams) ;
else if ( sCmd1 == "P" || sCmd1 == "POINT")
return ExecutePoint( sCmd2, vsParams) ;
@@ -124,26 +125,6 @@ GdbExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR&
return false ;
}
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteAlias( const string& sCmd2, const STRVECTOR& vsParams)
{
// analisi ed esecuzione dei comandi
if ( sCmd2 == "") {
int nId ;
// 2 parametri : stringa alias e Id
if ( vsParams.size() != 2)
return false ;
// recupero Id
if ( ! FromString( vsParams[1], nId))
return false ;
// inserisco le stringhe in coda alla lista
return m_AliasMap.insert( pair< string, int>( vsParams[0], nId)).second ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteGroup( const string& sCmd2, const STRVECTOR& vsParams)
@@ -187,11 +168,11 @@ GdbExecutor::ExecuteGroup( const string& sCmd2, const STRVECTOR& vsParams)
return false ;
// creo il gruppo
int nIdDest = GetIdParam( vsParams[0]) ;
int nIdDest = GetIdParam( vsParams[0], true) ;
int nIdNew = m_pGDB->AddGroup( nIdDest, GetIdParam( vsParams[1]), frFrame) ;
// se IdDest da calcolare e indicato da Alias, ne cambio il valore
if ( nIdDest == GDB_ID_NULL && m_AliasMap.find( vsParams[0]) != m_AliasMap.end())
m_AliasMap[vsParams[0]] = nIdNew ;
if ( nIdDest == GDB_ID_NULL && m_NameMap.find( vsParams[0]) != m_NameMap.end())
m_NameMap[vsParams[0]] = nIdNew ;
return ( nIdNew != GDB_ID_NULL) ;
}
@@ -338,25 +319,9 @@ GdbExecutor::ExecuteCurveLine( const string& sCmd2, const STRVECTOR& vsParams)
ptSloc.LocToLoc( frPoint, frCurve) ;
// calcolo il punto a minima distanza
Point3d ptEnd ;
switch ( pCurve->GetType()) {
case CRV_LINE :
{ DistPointLine dstPtLn( ptSloc, *GetCurveLine( pCurve)) ;
if ( ! dstPtLn.GetPointMinDist( ptEnd))
return false ;
} break ;
case CRV_ARC :
{ DistPointArc dstPtArc( ptSloc, *GetCurveArc( pCurve)) ;
if ( ! dstPtArc.GetPointMinDist( ptEnd))
return false ;
} break ;
//case CRV_BEZ :
// return PutCurveBez( *GetCurveBezier( pCurve), nFlag) ;
//case CRV_COMPO :
// return PutCurveCompo( *GetCurveComposite( pCurve), nFlag) ;
default :
DistPointCurve dstPtCurve( ptSloc, *pCurve) ;
if ( ! dstPtCurve.GetPointMinDist( ptEnd))
return false ;
break ;
}
// porto il punto finale nel riferimento di creazione
ptEnd.LocToLoc( frCurve, frPoint) ;
// setto la linea
@@ -623,28 +588,38 @@ bool
GdbExecutor::AddGeoObj( const string& sId, const string& sIdParent, IGeoObj* pGeoObj)
{
// creo il gruppo
int nId = GetIdParam( sId) ;
int nId = GetIdParam( sId, true) ;
int nIdNew = m_pGDB->AddGeoObj( nId, GetIdParam( sIdParent), pGeoObj) ;
// se IdDest da calcolare e indicato da Alias, ne cambio il valore
if ( nId == GDB_ID_NULL && m_AliasMap.find( sId) != m_AliasMap.end())
m_AliasMap[sId] = nIdNew ;
if ( nId == GDB_ID_NULL && m_NameMap.find( sId) != m_NameMap.end())
m_NameMap[sId] = nIdNew ;
return ( nIdNew != GDB_ID_NULL) ;
}
//----------------------------------------------------------------------------
int
GdbExecutor::GetIdParam( const std::string& sParam)
GdbExecutor::GetIdParam( const std::string& sParam, bool bNewAllowed)
{
int nVal ;
AliasMap::iterator Iter ;
NameMap::iterator Iter ;
// sostituisco eventuali Alias
Iter = m_AliasMap.find( sParam) ;
if ( Iter != m_AliasMap.end())
return Iter->second ;
// converto in identificatore numerico
// se nome di identificatore numerico
if ( sParam[0] == '$') {
// se già presente nella lista dei nomi, ne restituisco il valore
Iter = m_NameMap.find( sParam) ;
if ( Iter != m_NameMap.end())
return Iter->second ;
// se ammessa nuova definizione, provo ad inserirlo
else if ( bNewAllowed &&
m_NameMap.insert( pair< string, int>( sParam, GDB_ID_NULL)).second)
return GDB_ID_NULL ;
// altrimenti errore
else
return ID_ERROR ;
}
// se identificatore numerico
else if ( FromString( sParam, nVal))
return nVal ;
// altrimenti errore
@@ -772,11 +747,11 @@ GdbExecutor::ExecuteCopy( const STRVECTOR& vsParams)
if ( vsParams.size() != 3)
return false ;
// esecuzione copia
int nIdDest = GetIdParam( vsParams[1]) ;
int nIdDest = GetIdParam( vsParams[1], true) ;
int nIdNew = m_pGDB->Copy( GetIdParam( vsParams[0]), nIdDest, GetIdParam( vsParams[2])) ;
// se IdDest da calcolare e indicato da Alias, ne cambio il valore
if ( nIdDest == GDB_ID_NULL && m_AliasMap.find( vsParams[1]) != m_AliasMap.end())
m_AliasMap[vsParams[1]] = nIdNew ;
if ( nIdDest == GDB_ID_NULL && m_NameMap.find( vsParams[1]) != m_NameMap.end())
m_NameMap[vsParams[1]] = nIdNew ;
return ( nIdNew != GDB_ID_NULL) ;
}
+3 -4
View File
@@ -30,12 +30,11 @@ class GdbExecutor : public IGdbExecutor
private :
bool AddGeoObj( const std::string& sId, const std::string& sIdParent, IGeoObj* pGeoObj) ;
int GetIdParam( const std::string& sParam) ;
int GetIdParam( const std::string& sParam, bool bNewAllowed = false) ;
bool GetNamesParam( const std::string& sParam, STRVECTOR& vsNames) ;
bool GetVectorParam( const std::string& sParam, Vector3d& vtV) ;
bool GetPointParam( const std::string& sParam, Point3d& ptP) ;
bool GetPointWParam( const std::string& sParam, Point3d& ptP, double& dW) ;
bool ExecuteAlias( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteGroup( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecutePoint( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteVector( const std::string& sCmd2, const STRVECTOR& vsParams) ;
@@ -60,6 +59,6 @@ class GdbExecutor : public IGdbExecutor
private :
IGeomDB* m_pGDB ;
OutScl m_OutScl ;
typedef std::unordered_map<std::string, int> AliasMap ;
AliasMap m_AliasMap ;
typedef std::unordered_map<std::string, int> NameMap ;
NameMap m_NameMap ;
} ;
+3 -3
View File
@@ -79,14 +79,14 @@ GeomDB::Load( const std::string& sFileIn)
// inizializzo lo scanner
if ( ! TheScanner.Init( sFileIn)) {
LOG_ERROR( GetEGkLogger(), "GeomDbLoad : Error on Init ") ;
LOG_ERROR( GetEGkLogger(), "GeomDbLoad : Error on Init ")
return false ;
}
// leggo l'intestazione
if ( ! LoadStart( TheScanner)) {
string sOut = "GeomDbLoad : Error on line " + ToString( TheScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str())
return false ;
}
@@ -96,7 +96,7 @@ GeomDB::Load( const std::string& sFileIn)
if ( ! LoadOneNode( TheScanner, bEnd)) {
bOk = false ;
string sOut = "GeomDbLoad : Error on line " + ToString( TheScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str())
}
} while ( ! bEnd) ;