diff --git a/CurveBezier.cpp b/CurveBezier.cpp index 84d01ff..03b998a 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -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 using namespace std ; diff --git a/DistPointArc.cpp b/DistPointArc.cpp index 2d0c3ce..a7d89af 100644 --- a/DistPointArc.cpp +++ b/DistPointArc.cpp @@ -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) diff --git a/DistPointArc.h b/DistPointArc.h new file mode 100644 index 0000000..711da5c --- /dev/null +++ b/DistPointArc.h @@ -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 ; +} ; + diff --git a/DistPointCrvBezier.cpp b/DistPointCrvBezier.cpp new file mode 100644 index 0000000..f0583f4 --- /dev/null +++ b/DistPointCrvBezier.cpp @@ -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 ; +} diff --git a/DistPointCrvBezier.h b/DistPointCrvBezier.h new file mode 100644 index 0000000..3ab812a --- /dev/null +++ b/DistPointCrvBezier.h @@ -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 ; +} ; + diff --git a/DistPointCurve.cpp b/DistPointCurve.cpp new file mode 100644 index 0000000..3af2fe6 --- /dev/null +++ b/DistPointCurve.cpp @@ -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 ; +} diff --git a/DistPointLine.cpp b/DistPointLine.cpp index 5b8d339..1687385 100644 --- a/DistPointLine.cpp +++ b/DistPointLine.cpp @@ -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 ; diff --git a/DistPointLine.h b/DistPointLine.h new file mode 100644 index 0000000..fdf86e6 --- /dev/null +++ b/DistPointLine.h @@ -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 ; +} ; + diff --git a/EGkDllMain.cpp b/EGkDllMain.cpp index e7919df..18ff73b 100644 --- a/EGkDllMain.cpp +++ b/EGkDllMain.cpp @@ -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) diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index d398724..da8bb59 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 5adadb3..e7a722b 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -119,6 +119,8 @@ copy $(TargetPath) \EgtProg\Dll + + @@ -153,8 +155,7 @@ copy $(TargetPath) \EgtProg\Dll - - + @@ -172,8 +173,13 @@ copy $(TargetPath) \EgtProg\Dll + + + + + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 0225203..ccf4fb4 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -28,6 +28,9 @@ {a3fbb199-9e77-4b66-8f18-7d48b8d6a8e1} + + {cc84f71a-b149-4187-af26-736133e92672} + @@ -93,14 +96,20 @@ File di origine\Gdb - - File di origine\Base - File di origine\Base - File di origine\Base + File di origine\Distanze + + + File di origine\Distanze + + + File di origine\Distanze + + + File di origine\Distanze @@ -227,9 +236,6 @@ File di intestazione - - File di intestazione - File di intestazione @@ -242,7 +248,22 @@ File di intestazione - + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + File di intestazione diff --git a/GdbExecutor.cpp b/GdbExecutor.cpp index 7a56eff..e7f2ae0 100644 --- a/GdbExecutor.cpp +++ b/GdbExecutor.cpp @@ -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) ; } diff --git a/GdbExecutor.h b/GdbExecutor.h index 26a8df4..05a0407 100644 --- a/GdbExecutor.h +++ b/GdbExecutor.h @@ -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 AliasMap ; - AliasMap m_AliasMap ; + typedef std::unordered_map NameMap ; + NameMap m_NameMap ; } ; diff --git a/GeomDB.cpp b/GeomDB.cpp index 870c736..100f54c 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -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) ;