From 81a1e3d99463cb36c9c95616ca03892d5d27178d Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 26 Nov 2013 15:00:46 +0000 Subject: [PATCH] EgtGeomKernel : completata gestione DB geometrico di base. Aggiunto esecutore di comandi per script. --- CurveAux.cpp | 24 +- EgtGeomKernel.vcxproj | 10 + EgtGeomKernel.vcxproj.filters | 93 +++- GdbExecutor.cpp | 804 ++++++++++++++++++++++++++++++++++ GdbExecutor.h | 57 +++ GdbObj.cpp | 116 +++++ GdbObj.h | 54 +++ GeomDB.cpp | 395 ++++------------- GeomDB.h | 51 +-- OutScl.cpp | 394 +++++++++++++++++ OutScl.h | 56 +++ 11 files changed, 1676 insertions(+), 378 deletions(-) create mode 100644 GdbExecutor.cpp create mode 100644 GdbExecutor.h create mode 100644 GdbObj.cpp create mode 100644 GdbObj.h create mode 100644 OutScl.cpp create mode 100644 OutScl.h diff --git a/CurveAux.cpp b/CurveAux.cpp index b79dfcb..238f948 100644 --- a/CurveAux.cpp +++ b/CurveAux.cpp @@ -60,15 +60,23 @@ GetPointTangNormCurv( const ICurve& crvC, double dU, Point3d& ptPos, Vector3d& v if ( ! crvC.GetPointD1D2( dU, ptPos, vtT, vtDer2)) return false ; + // se esiste la derivata prima non nulla dLenSqD1 = vtT.LenSq() ; - if ( ! vtT.Normalize()) - return false ; - // del vettore deriv2^ tengo la sola componente perpendicolare al vettore tangente - vtN = vtDer2 - ( vtDer2 * vtT) * vtT ; - if ( ! vtN.Normalize()) - return false ; - // curvatura - dCurv = ( vtT ^ vtDer2).Len() / dLenSqD1 ; + if ( vtT.Normalize()) { + // del vettore deriv2^ tengo la sola componente perpendicolare al vettore tangente + vtN = vtDer2 - ( vtDer2 * vtT) * vtT ; + if ( vtN.Normalize()) + dCurv = ( vtT ^ vtDer2).Len() / dLenSqD1 ; + else + dCurv = 0 ; + } + else { + // se esiste derivata seconda non nulla, definisce la tangente + if ( vtDer2.Normalize()) + vtT = vtDer2 ; + vtN.Set( 0, 0, 0) ; + dCurv = 0 ; + } return true ; } diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 8d9eeaf..1ac6012 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -118,6 +118,7 @@ copy $(TargetPath) \EgtProg\Dll + @@ -125,9 +126,12 @@ copy $(TargetPath) \EgtProg\Dll + + + Create @@ -143,6 +147,7 @@ copy $(TargetPath) \EgtProg\Dll + @@ -151,15 +156,20 @@ copy $(TargetPath) \EgtProg\Dll + + + + + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 81b7be7..02c24c9 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -13,46 +13,73 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {eaf1bdbd-2656-4d33-a9fb-c12762b40031} + + + {38c3a75c-51a7-4771-b1f5-44d3eefcfe3a} + + + {6848770c-64f9-4f0b-91f7-4e54d753ed6d} + + + {17a40885-7164-490b-bc7b-e56811602d12} + + + {a3fbb199-9e77-4b66-8f18-7d48b8d6a8e1} + - - File di origine - - - File di origine - - File di origine + File di origine\Base - File di origine + File di origine\Base - - File di origine - - - File di origine - - - File di origine + + File di origine\Base - File di origine + File di origine\Geo - - File di origine + + File di origine\Geo - - File di origine + + File di origine\Geo - File di origine + File di origine\Geo + + + File di origine\Geo - File di origine + File di origine\Geo - File di origine + File di origine\Geo + + + File di origine\Geo + + + File di origine\General + + + File di origine\General + + + File di origine\Gdb + + + File di origine\Gdb + + + File di origine\Script + + + File di origine\Script @@ -134,6 +161,24 @@ 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 new file mode 100644 index 0000000..71408dc --- /dev/null +++ b/GdbExecutor.cpp @@ -0,0 +1,804 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GdbExecutor.cpp Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Implementazione della classe GdbExecutor. +// +// +// +// Modifiche : 27.03.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include +#include +#include "/EgtDev/Include/EgnStringUtils.h" +#include "/EgtDev/Include/EgnStringConverter.h" +#include "/EgtDev/Include/EgkGeoPoint3d.h" +#include "/EgtDev/Include/EgkGeoVector3d.h" +#include "/EgtDev/Include/EgkCurveLine.h" +#include "/EgtDev/Include/EgkCurveArc.h" +#include "/EgtDev/Include/EgkCurveBezier.h" +#include "/EgtDev/Include/EgkCurveComposite.h" +#include "/EgtDev/Include/EgtReleasePointer.h" +#include "GdbExecutor.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +IGdbExecutor* +CreateGdbExecutor( void) +{ + return static_cast ( new GdbExecutor) ; +} + +//---------------------------------------------------------------------------- +GdbExecutor::GdbExecutor( void) +{ +} + +//---------------------------------------------------------------------------- +GdbExecutor::~GdbExecutor( void) +{ +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::Set( IGeomDB* pGdb) +{ + m_pGDB = pGdb ; + + return ( m_pGDB != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::Load( const wstring& sFile) +{ + bool bOk ; + ifstream ifLoad ; + + + ifLoad.open( sFile) ; + if ( ifLoad.good()) { + bOk = m_pGDB->Load( ifLoad) ; + ifLoad.close() ; + } + else + bOk = false ; + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::Save( const wstring& sFile) +{ + bool bOk ; + ofstream ofSave ; + + + ofSave.open( sFile) ; + if ( ofSave.good()) { + bOk = m_pGDB->Save( ofSave) ; + ofSave.close() ; + } + else + bOk = false ; + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams) +{ + STRVECTOR::const_iterator theConstIter ; + + + // output di debug + cout << "Cmd = [" << sCmd1 << "/" << sCmd2 << "]" ; + cout << " Par = [" ; + for ( theConstIter = vsParams.begin() ; theConstIter != vsParams.end() ; theConstIter ++) { + if ( theConstIter != vsParams.begin()) + cout << "/" ; + cout << *theConstIter ; + } + cout << "]" << endl ; + + // esecuzione comando + if ( sCmd1 == "P" || sCmd1 == "POINT") + return ExecutePoint( sCmd2, vsParams) ; + else if ( sCmd1 == "V" || sCmd1 == "VECTOR") + return ExecuteVector( sCmd2, vsParams) ; + else if ( sCmd1 == "CL" || sCmd1 == "CURVELINE") + return ExecuteCurveLine( sCmd2, vsParams) ; + else if ( sCmd1 == "CA" || sCmd1 == "CURVEARC") + return ExecuteCurveArc( sCmd2, vsParams) ; + else if ( sCmd1 == "CB" || sCmd1 == "CURVEBEZIER") + return ExecuteCurveBez( sCmd2, vsParams) ; + else if ( sCmd1 == "CC" || sCmd1 == "CURVECOMPO") + return ExecuteCurveCompo( sCmd2, vsParams) ; + else if ( sCmd1 == "COPY") + return ExecuteCopy( vsParams) ; + else if ( sCmd1 == "ERASE") + return ExecuteErase( vsParams) ; + else if ( sCmd1 == "MOVE" || sCmd1 == "TRANSLATE") + return ExecuteTranslate( vsParams) ; + else if ( sCmd1 == "ROTATE") + return ExecuteRotate( vsParams) ; + else if ( sCmd1 == "SCALE") + return ExecuteScale( vsParams) ; + else if ( sCmd1 == "MIRROR") + return ExecuteMirror( vsParams) ; + else if ( sCmd1 == "LOAD") + return ExecuteLoad( vsParams) ; + else if ( sCmd1 == "SAVE") + return ExecuteSave( vsParams) ; + else if ( sCmd1 == "OUTSCL") + return ExecuteOutScl( sCmd2, vsParams) ; + + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecutePoint( const string& sCmd2, const STRVECTOR& vsParams) +{ + // analisi ed esecuzione dei comandi + if ( sCmd2 == "MAKE" || sCmd2 == "") { + Point3d Pnt ; + // 4 parametri : un nome e 3 coordinate + if ( vsParams.size() != 4) + return false ; + // recupero le tre coordinate + if ( ! FromString( vsParams[1], Pnt.x) || + ! FromString( vsParams[2], Pnt.y) || + ! FromString( vsParams[3], Pnt.z)) + return false ; + // creo il punto + IGeoPoint3d* pGPnt = CreateGeoPoint3d() ; + if ( pGPnt == nullptr) + return false ; + pGPnt->Set( Pnt) ; + return m_pGDB->AddGeoObj( vsParams[0], pGPnt) ; + } + + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteVector( const string& sCmd2, const STRVECTOR& vsParams) +{ + // analisi ed esecuzione dei comandi + if ( sCmd2 == "MAKE" || sCmd2 == "") { + Vector3d Vect ; + // 4 parametri + if ( vsParams.size() != 4) + return false ; + // recupero i tre componenti + if ( ! FromString( vsParams[1], Vect.x) || + ! FromString( vsParams[2], Vect.y) || + ! FromString( vsParams[3], Vect.z)) + return false ; + // creo il vettore + IGeoVector3d* pGVect = CreateGeoVector3d() ; + if ( pGVect == nullptr) + return false ; + pGVect->Set( Vect) ; + return m_pGDB->AddGeoObj( vsParams[0], pGVect) ; + } + + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteCurveLine( const string& sCmd2, const STRVECTOR& vsParams) +{ + // analisi ed esecuzione dei comandi + if ( sCmd2 == "MAKE" || sCmd2 == "") { + Point3d ptStart ; + Point3d ptEnd ; + // 3 parametri + if ( vsParams.size() != 3) + return false ; + // recupero e setto punti iniziale e finale + if ( ! GetPointParam( vsParams[1], ptStart) || + ! GetPointParam( vsParams[2], ptEnd)) + return false ; + // creo la linea + ReleasePtr pCrvLine( CreateCurveLine()) ; + if ( ! IsValid( pCrvLine) || ! pCrvLine->Set( ptStart, ptEnd)) + return false ; + return m_pGDB->AddGeoObj( vsParams[0], Release( pCrvLine)) ; + } + + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteCurveArc( const string& sCmd2, const STRVECTOR& vsParams) +{ + // creo l'arco + ReleasePtr pCrvArc( CreateCurveArc()) ; + if ( ! IsValid( pCrvArc)) + return false ; + + // arco generico + if ( sCmd2 == "MAKE" || sCmd2 == "") { + Point3d ptCen ; + Vector3d vtN ; + double dRad ; + Vector3d vtS ; + double dAngCenDeg ; + double dDeltaZ ; + // 7 parametri + if ( vsParams.size() != 7) + return false ; + // centro + if ( ! GetPointParam( vsParams[1], ptCen)) + return false ; + // versore ortogonale al piano della circonferenza + if ( ! GetVectorParam( vsParams[2], vtN)) + return false ; + // raggio + if ( ! FromString( vsParams[3], dRad)) + return false ; + // versore iniziale + if ( ! GetVectorParam( vsParams[4], vtS)) + return false ; + // angolo al centro + if ( ! FromString( vsParams[5], dAngCenDeg)) + return false ; + // deltaZ + if ( ! FromString( vsParams[6], dDeltaZ)) + return false ; + // setto l'arco + if ( ! pCrvArc->Set( ptCen, vtN, dRad, vtS, dAngCenDeg, dDeltaZ)) + return false ; + } + // arco nel piano XY + else if ( sCmd2 == "PLANEXY" || sCmd2 == "XY") { + Point3d ptCen ; + double dRad ; + double dAngIniDeg ; + double dAngCenDeg ; + double dDeltaZ ; + // 6 parametri + if ( vsParams.size() != 6) + return false ; + // centro + if ( ! GetPointParam( vsParams[1], ptCen)) + return false ; + // raggio + if ( ! FromString( vsParams[2], dRad)) + return false ; + // angolo iniziale + if ( ! FromString( vsParams[3], dAngIniDeg)) + return false ; + // angolo al centro + if ( ! FromString( vsParams[4], dAngCenDeg)) + return false ; + // deltaZ + if ( ! FromString( vsParams[5], dDeltaZ)) + return false ; + // setto l'arco + if ( ! pCrvArc->Set( ptCen, dRad, dAngIniDeg, dAngCenDeg, dDeltaZ)) + return false ; + } + // altrimenti errore + else + return false ; + + // inserisco l'arco nel DB + return m_pGDB->AddGeoObj( vsParams[0], Release( pCrvArc)) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteCurveBez( const string& sCmd2, const STRVECTOR& vsParams) +{ + // creo la curva di Bezier + ReleasePtr pCrvBez( CreateCurveBezier()) ; + if ( ! IsValid( pCrvBez)) + return false ; + + // curva di Bezier intera (non razionale) + if ( sCmd2 == "INTEG" || sCmd2 == "I") { + int i ; + int nDeg ; + Point3d ptP ; + // almeno 2 parametri + if ( vsParams.size() < 2) + return false ; + // recupero il grado + if ( ! FromString( vsParams[1], nDeg)) + return false ; + // inizializzo la curva di Bezier + if ( ! pCrvBez->Init( nDeg, false)) + return false ; + // recupero e setto punti di controllo + for ( i = 0 ; i <= nDeg ; i ++) { + if ( ! GetPointParam( vsParams[i+2], ptP) || + ! pCrvBez->SetControlPoint( i, ptP)) + return false ; + } + } + // curva di Bezier razionale + else if ( sCmd2 == "RATIO" || sCmd2 == "R") { + int i ; + int nDeg ; + double dW ; + Point3d ptP ; + // almeno 2 parametri + if ( vsParams.size() < 2) + return false ; + // recupero il grado + if ( ! FromString( vsParams[1], nDeg)) + return false ; + // inizializzo la curva di Bezier + if ( ! pCrvBez->Init( nDeg, true)) + return false ; + // recupero e setto punti di controllo + for ( i = 0 ; i <= nDeg ; i ++) { + if ( ! GetPointWeParam( vsParams[i+2], ptP, dW) || + ! pCrvBez->SetControlPoint( i, ptP, dW)) + return false ; + } + } + // altrimenti errore + else + return false ; + + // inserisco la curva di Bezier nel DB + return m_pGDB->AddGeoObj( vsParams[0], Release( pCrvBez)) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteCurveCompo( const string& sCmd2, const STRVECTOR& vsParams) +{ + // curva composita generica + if ( sCmd2 == "MAKE" || sCmd2 == "") { + bool bErase ; + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + const ICurve* pCrv ; + ReleasePtr pCrvCompo( CreateCurveComposite()) ; + if ( ! IsValid( pCrvCompo)) + return false ; + // 2 o 3 parametri + switch ( vsParams.size()) { + case 2 : bErase = false ; break ; + case 3 : bErase = ( vsParams[2] != "0") ; break ; + default : return false ; break ; + } + // recupero lista nomi + if ( ! GetNamesParam( vsParams[1], vsNames)) + return false ; + // esecuzione + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + // recupero la curva + pCrv = GetCurve( m_pGDB->GetGeoObj( *Iter)) ; + if ( pCrv == nullptr) + return false ; + // aggiungo questa curva + if ( ! pCrvCompo->AddCurve( *pCrv)) + return false ; + } + // inserisco la curva composita nel DB + if ( m_pGDB->AddGeoObj( vsParams[0], Release( pCrvCompo))) { + // se richiesto, cancello le curve originali + if ( bErase) { + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + if ( ! m_pGDB->Erase( (*Iter))) + return false ; + } + } + return true ; + } + else + return false ; + } + + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::GetNamesParam( const std::string& sParam, STRVECTOR& vsNames) +{ + STRVECTOR::iterator Iter ; + + + // divido in parti + Tokenize( sParam, ",", vsNames) ; + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) + Trim( (*Iter), " \t\r\n()") ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::GetVectorParam( const std::string& sParam, Vector3d& vtV) +{ + // se insieme di tre componenti + if ( sParam[0] == '(') { + STRVECTOR vsParams ; + STRVECTOR::iterator Iter ; + // divido in parti + Tokenize( sParam, ",", vsParams) ; + for ( Iter = vsParams.begin() ; Iter != vsParams.end() ; Iter++) + Trim( (*Iter), " \t\r\n()") ; + // verifico siano 3 parti e le converto + if ( vsParams.size() != 3) + return false ; + return ( FromString( vsParams[0], vtV.x) && + FromString( vsParams[1], vtV.y) && + FromString( vsParams[2], vtV.z)) ; + } + // altrimenti nome di vettore già nel DB + else { + const IGeoVector3d* pV ; + if ( ( pV = GetGeoVector3d( m_pGDB->GetGeoObj( sParam))) == nullptr) + return false ; + vtV = pV->GetVector() ; + return true ; + } +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::GetPointParam( const std::string& sParam, Point3d& ptP) +{ + // se insieme di tre coordinate + if ( sParam[0] == '(') { + STRVECTOR vsParams ; + STRVECTOR::iterator Iter ; + // divido in parti + Tokenize( sParam, ",", vsParams) ; + for ( Iter = vsParams.begin() ; Iter != vsParams.end() ; Iter++) + Trim( (*Iter), " \t\r\n()") ; + // verifico siano 3 parti e le converto + if ( vsParams.size() != 3) + return false ; + return ( FromString( vsParams[0], ptP.x) && + FromString( vsParams[1], ptP.y) && + FromString( vsParams[2], ptP.z)) ; + } + // altrimenti nome di punto già nel DB + else { + const IGeoPoint3d* pPt ; + if ( ( pPt = GetGeoPoint3d( m_pGDB->GetGeoObj( sParam))) == nullptr) + return false ; + ptP = pPt->GetPoint() ; + return true ; + } +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::GetPointWeParam( const std::string& sParam, Point3d& ptP, double& dW) +{ + STRVECTOR vsParams ; + STRVECTOR::iterator Iter ; + + + // deve essere insieme di dati + if ( sParam[0] != '(') + return false ; + + // divido in parti + Tokenize( sParam, ",", vsParams) ; + for ( Iter = vsParams.begin() ; Iter != vsParams.end() ; Iter++) + Trim( (*Iter), " \t\r\n()") ; + + // se 4 parti, sono 3 coordinate e un peso + if ( vsParams.size() == 4) { + return ( FromString( vsParams[0], ptP.x) && + FromString( vsParams[1], ptP.y) && + FromString( vsParams[2], ptP.z) && + FromString( vsParams[3], dW)) ; + } + // se 2 parti, nome di punto già nel DB e un peso + else if ( vsParams.size() == 2) { + const IGeoPoint3d* pPt ; + // recupero il punto + if ( ( pPt = GetGeoPoint3d( m_pGDB->GetGeoObj( vsParams[0]))) == nullptr) + return false ; + ptP = pPt->GetPoint() ; + // recupero il peso + return FromString( vsParams[1], dW) ; + } + // altrimenti errore + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteCopy( const STRVECTOR& vsParams) +{ + // 2 parametri ( NomeSou, NomeDest) + if ( vsParams.size() != 2) + return false ; + // esecuzione copia + return m_pGDB->Copy( vsParams[0], vsParams[1]) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteErase( const STRVECTOR& vsParams) +{ + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + + + // 1 parametro ( Nome/i) + if ( vsParams.size() != 1) + return false ; + // recupero lista nomi + if ( ! GetNamesParam( vsParams[0], vsNames)) + return false ; + // esecuzione cancellazioni + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + if ( ! m_pGDB->Erase( (*Iter))) + return false ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteTranslate( const STRVECTOR& vsParams) +{ + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + Vector3d vtVN ; + + + // 2 parametri ( Nome/i, Vettore) + if ( vsParams.size() != 2) + return false ; + // recupero lista nomi + if ( ! GetNamesParam( vsParams[0], vsNames)) + return false ; + // recupero il vettore + if ( ! GetVectorParam( vsParams[1], vtVN)) + return false ; + // esecuzione traslazioni + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + if ( ! m_pGDB->Translate( (*Iter), vtVN)) + return false ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteRotate( const STRVECTOR& vsParams) +{ + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + Point3d ptPC ; + Vector3d vtVN ; + double dAngDeg ; + + + // 4 parametri ( Nome, PtoAsse, VtAsse, AngDeg) + if ( vsParams.size() != 4) + return false ; + // recupero lista nomi + if ( ! GetNamesParam( vsParams[0], vsNames)) + return false ; + // recupero il punto + if ( ! GetPointParam( vsParams[1], ptPC)) + return false ; + // recupero il vettore + if ( ! GetVectorParam( vsParams[2], vtVN)) + return false ; + // recupero i coefficienti + if ( ! FromString( vsParams[3], dAngDeg)) + return false ; + // esecuzione rotazioni + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + if ( ! m_pGDB->Rotate( (*Iter), ptPC, vtVN, dAngDeg)) + return false ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteScale( const STRVECTOR& vsParams) +{ + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + Point3d ptPC ; + double dCoeffX ; + double dCoeffY ; + double dCoeffZ ; + + + // 5 parametri ( Nome, Punto, CoeffX, CoeffY, CoeffZ) + if ( vsParams.size() != 5) + return false ; + // recupero lista nomi + if ( ! GetNamesParam( vsParams[0], vsNames)) + return false ; + // recupero il punto + if ( ! GetPointParam( vsParams[1], ptPC)) + return false ; + // recupero i coefficienti + if ( ! FromString( vsParams[2], dCoeffX) || + ! FromString( vsParams[3], dCoeffY) || + ! FromString( vsParams[4], dCoeffZ)) + return false ; + // esecuzione scalature + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + if ( ! m_pGDB->Scale( (*Iter), ptPC, dCoeffX, dCoeffY, dCoeffZ)) + return false ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteMirror( const STRVECTOR& vsParams) +{ + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + Point3d ptPC ; + Vector3d vtVN ; + + + // 3 parametri ( Nome, Punto, Vettore) + if ( vsParams.size() != 3) + return false ; + // recupero lista nomi + if ( ! GetNamesParam( vsParams[0], vsNames)) + return false ; + // recupero il punto + if ( ! GetPointParam( vsParams[1], ptPC)) + return false ; + // recupero il vettore + if ( ! GetVectorParam( vsParams[2], vtVN)) + return false ; + // esecuzione specchiature + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + if ( ! m_pGDB->Mirror( (*Iter), ptPC, vtVN)) + return false ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteLoad( const STRVECTOR& vsParams) +{ + // 1 parametro ( NomeFile) + if ( vsParams.size() != 1) + return false ; + // pulizia e reinizializzazione del DB geometrico + m_pGDB->Clear() ; + m_pGDB->Init() ; + // esecuzione caricamento + return Load( stringtoW( vsParams[0])) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteSave( const STRVECTOR& vsParams) +{ + // 1 parametro ( NomeFile) + if ( vsParams.size() != 1) + return false ; + // esecuzione salvataggio + return Save( stringtoW( vsParams[0])) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteOutScl( const string& sCmd2, const STRVECTOR& vsParams) +{ + // apro il file di uscita Scl + if ( sCmd2 == "OPEN") { + // 1 parametro + if ( vsParams.size() != 1) + return false ; + // apro il file e scrivo intestazione + return m_OutScl.Open( stringtoW( vsParams[0])) ; + } + // chiudo il file di uscita Scl + else if ( sCmd2 == "CLOSE") { + // nessun parametro + if ( vsParams.size() != 0) + return false ; + // scrivo terminazioni e chiudo il file + return m_OutScl.Close() ; + } + // imposto materiale corrente + else if ( sCmd2 == "SETRGB") { + double dRed, dGreen, dBlue ; + // 3 parametri + if ( vsParams.size() != 3) + return false ; + // recupero i 3 colori + if ( ! FromString( vsParams[0], dRed) || + ! FromString( vsParams[1], dGreen) || + ! FromString( vsParams[2], dBlue)) + return false ; + // definisco il materiale opportuno + return m_OutScl.SetMaterial( dRed, dGreen, dBlue) ; + } + // imposto pezzo e layer correnti + else if ( sCmd2 == "SETPL") { + // 2 parametri + if ( vsParams.size() != 2) + return false ; + // eseguo + return m_OutScl.SetPartLay( vsParams[0], vsParams[1]) ; + } + // emetto entità + else if ( sCmd2 == "PUT") { + bool bCrvVsPolyg ; + STRVECTOR vsNames ; + STRVECTOR::iterator Iter ; + // almeno un parametro + if ( vsParams.size() < 1) + return false ; + // se esiste il secondo + if ( vsParams.size() == 2) + bCrvVsPolyg = ( vsParams[1] != "CPS") ; + else + bCrvVsPolyg = TRUE ; + // recupero lista nomi + if ( ! GetNamesParam( vsParams[0], vsNames)) + return false ; + // esecuzione + for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; Iter++) { + // recupero l'oggetto ed eseguo l'output + switch ( m_pGDB->GetObjType( *Iter)) { + case CRV_LINE : + if ( ! m_OutScl.PutCurveLine( *GetCurveLine( m_pGDB->GetGeoObj(*Iter)))) + return false ; + break ; + case CRV_ARC : + if ( ! m_OutScl.PutCurveArc( *GetCurveArc( m_pGDB->GetGeoObj(*Iter)))) + return false ; + break ; + case CRV_BEZ : + if ( bCrvVsPolyg) { + if ( ! m_OutScl.PutCurveBez( *GetCurveBezier( m_pGDB->GetGeoObj(*Iter)))) + return false ; + } + else { + if ( ! m_OutScl.PutPolygBez( *GetCurveBezier( m_pGDB->GetGeoObj(*Iter)))) + return false ; + } + break ; + case CRV_COMPO : + if ( ! m_OutScl.PutCurveCompo( *GetCurveComposite( m_pGDB->GetGeoObj(*Iter)))) + return false ; + break ; + default : + return false ; + } + } + return true ; + } + + return false ; +} \ No newline at end of file diff --git a/GdbExecutor.h b/GdbExecutor.h new file mode 100644 index 0000000..38f876d --- /dev/null +++ b/GdbExecutor.h @@ -0,0 +1,57 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GdbExecutor.h Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe GdbExecutor. +// +// +// +// Modifiche : 27.03.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EgkGdbExecutor.h" +#include "GeomDB.h" +#include "OutScl.h" + +//---------------------------------------------------------------------------- +class GdbExecutor : public IGdbExecutor +{ + public : + virtual bool Execute( const std::string& sCmd1, const std::string& sCmd2, const STRVECTOR& vsParams) ; + virtual bool Set( IGeomDB* pGdb) ; + + public : + GdbExecutor( void) ; + ~GdbExecutor( void) ; + bool Load( const std::wstring& sFile) ; + bool Save( const std::wstring& sFile) ; + + private : + 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 GetPointWeParam( const std::string& sParam, Point3d& ptP, double& dW) ; + bool ExecutePoint( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteVector( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteCurveLine( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteCurveArc( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteCurveBez( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteCurveCompo( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteTranslate( const STRVECTOR& vsParams) ; + bool ExecuteRotate( const STRVECTOR& vsParams) ; + bool ExecuteScale( const STRVECTOR& vsParams) ; + bool ExecuteMirror( const STRVECTOR& vsParams) ; + bool ExecuteCopy( const STRVECTOR& vsParams) ; + bool ExecuteErase( const STRVECTOR& vsParams) ; + bool ExecuteLoad( const STRVECTOR& vsParams) ; + bool ExecuteSave( const STRVECTOR& vsParams) ; + bool ExecuteOutScl( const std::string& sCmd2, const STRVECTOR& vsParams) ; + + private : + IGeomDB* m_pGDB ; + OutScl m_OutScl ; +} ; diff --git a/GdbObj.cpp b/GdbObj.cpp new file mode 100644 index 0000000..056d1e8 --- /dev/null +++ b/GdbObj.cpp @@ -0,0 +1,116 @@ +//---------------------------------------------------------------------------- +// 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( void) const +{ + GdbObj* pGdbObj ; + + + // alloco oggetto Gdb + pGdbObj = new(nothrow) GdbObj ; + if ( pGdbObj != nullptr) { + // copio dati oggetto Gdb + // ... + // copio oggetto Geo + pGdbObj->m_pGeoObj = m_pGeoObj->Clone() ; + } + + 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_sName << endl ; + // parametri geometrici + return m_pGeoObj->Save( osOut) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GdbObj::Load( CScan& TheScanner, string& sErrLine) +{ + string sLine ; + STRVECTOR vsParams ; + + + // reset linea errata + sErrLine.clear() ; + + // leggo la prossima linea : tipo di entità + if ( ! TheScanner.GetLine( sLine)) + return false ; + + // creo l'oggetto geometrico corrispondente + m_pGeoObj = GEOOBJ_CREATE( sLine) ; + if ( m_pGeoObj == nullptr) { + sErrLine = sLine ; + return false ; + } + + // leggo la prossima linea + if ( ! TheScanner.GetLine( sLine)) + return false ; + // la divido in parametri + Tokenize( sLine, ",", vsParams) ; + // 1 parametro : nome + if ( vsParams.size() != 1) + return false ; + // assegno il nome + m_sName = vsParams[0] ; + + // parametri geometrici + return m_pGeoObj->Load( TheScanner) ; +} diff --git a/GdbObj.h b/GdbObj.h new file mode 100644 index 0000000..046c163 --- /dev/null +++ b/GdbObj.h @@ -0,0 +1,54 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GdbObj.h Data : 08.04.13 Versione : 1.1c1 +// Contenuto : Dichiarazione della classe GdbObj. +// +// +// +// Modifiche : 22.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include +#include "/EgtDev/Include/EGkGeoObj.h" + + +//---------------------------------------------------------------------------- +class GdbObj +{ + public : + GdbObj( void); + ~GdbObj( void) ; + GdbObj* Clone( void) const ; + GeoObjType GetType( void) const ; + bool Save( std::ostream& osOut) const ; + bool Load( CScan& TheScanner, std::string& sErrLine) ; + bool Translate( const Vector3d& vtMove) + { if ( m_pGeoObj == nullptr) + return false ; + return m_pGeoObj->Translate( vtMove) ; } + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) + { if ( m_pGeoObj == nullptr) + return false ; + return m_pGeoObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ; } + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) + { if ( m_pGeoObj == nullptr) + return false ; + return m_pGeoObj->Rotate( ptAx, vtAx, dAngRad) ; } + bool Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) + { if ( m_pGeoObj == nullptr) + return false ; + return m_pGeoObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; } + bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) + { if ( m_pGeoObj == nullptr) + return false ; + return m_pGeoObj->Mirror( ptOn, vtNorm) ; } + + public : + std::string m_sName ; + IGeoObj* m_pGeoObj ; +} ; diff --git a/GeomDB.cpp b/GeomDB.cpp index 858e263..a691268 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -15,15 +15,18 @@ #include "stdafx.h" #include #include -#include "GeoConst.h" +#include "GdbObj.h" #include "GeomDB.h" -#include "GdbObjFactory.h" -#include "GeoObjTypeFun.h" -#include "Scan.h" -#include "StringUtils.h" using namespace std ; +//---------------------------------------------------------------------------- +IGeomDB* +CreateGeomDB( void) +{ + return static_cast ( new GeomDB) ; +} + //---------------------------------------------------------------------------- // GeomDB //---------------------------------------------------------------------------- @@ -126,36 +129,42 @@ GeomDB::LoadStart( CScan& TheScanner) bool GeomDB::LoadOneObject( CScan& TheScanner, bool& bEnd) { - string sLine ; - GdbObj* pGObj ; + string sErrLine ; + GdbObj* pGdbObj ; - - // recupero la prossima linea (con il tipo di oggetto) - if ( ! TheScanner.GetLine( sLine)) { - bEnd = true ; + + // in generale non è fine file + bEnd = false ; + + // creo l'oggetto GDB + pGdbObj = new GdbObj ; + if ( pGdbObj == nullptr) return false ; - } - // se fine - if ( sLine == "END") { - bEnd = true ; - } - // altrimenti oggetto - else { - bEnd = false ; - // creo l'oggetto - pGObj = GDBOBJ_CREATE( sLine) ; - if ( pGObj == nullptr) - return false ; - // ne leggo i dati e lo inserisco nel DB - if ( ! pGObj->Load( TheScanner) || - ! AddToGeomDB( pGObj)) { - delete pGObj ; + // se lettura dati va bene + if ( pGdbObj->Load( TheScanner, sErrLine)) { + // se inserimento nel DB va bene + if ( AddToGeomDB( pGdbObj)) + return true ; + // altrimenti errore + else { + delete pGdbObj ; return false ; } } - return true ; + else { + // in ogni caso non serve oggetto GDB + delete pGdbObj ; + // se fine dati + if ( sErrLine == "END") { + bEnd = true ; + return true ; + } + // altrimenti errore + else + return false ; + } } //---------------------------------------------------------------------------- @@ -184,7 +193,7 @@ GeomDB::Save( std::ofstream& osOut) //---------------------------------------------------------------------------- bool -GeomDB::ExistsGdbObj( const std::string& sName) +GeomDB::ExistsObj( const std::string& sName) { STRPGDBO_UMAP::const_iterator Iter ; @@ -209,193 +218,49 @@ GeomDB::GetGdbObj( const std::string& sName) //---------------------------------------------------------------------------- bool -GeomDB::AddToGeomDB( GdbObj* pGObj) +GeomDB::AddToGeomDB( GdbObj* pGdbObj) { // verifico validità oggetto puntato - if ( pGObj == nullptr) + if ( pGdbObj == nullptr) return false ; // verifica validità e unicità del nome - if ( pGObj->m_sName.length() == 0 || ExistsGdbObj( pGObj->m_sName)) + if ( pGdbObj->m_sName.length() == 0 || ExistsObj( pGdbObj->m_sName)) return false ; // inserisco in lista principale - m_GeomDB.push_back( pGObj) ; + m_GeomDB.push_back( pGdbObj) ; // inserisco in mappa nomi - m_GdbNameMap[ pGObj->m_sName] = pGObj ; + m_GdbNameMap[ pGdbObj->m_sName] = pGdbObj ; return true ; } //---------------------------------------------------------------------------- bool -GeomDB::AddVector( const string& sName, const Vector3d& Vect) +GeomDB::AddGeoObj( const std::string& sName, IGeoObj* pGeoObj) { - GdbVector3d* pGVect ; + GdbObj* pGdbObj ; // verifico validità nome if ( sName.length() == 0) return false ; - // alloco oggetto - pGVect = new(nothrow) GdbVector3d ; - if ( pGVect == nullptr) + // verifico validità oggetto Geo + if ( pGeoObj == nullptr || ! pGeoObj->IsValid()) + return false ; + // alloco oggetto Gdb + pGdbObj = new(nothrow) GdbObj ; + if ( pGdbObj == nullptr) return false ; // assegno nome - pGVect->m_sName = sName ; + pGdbObj->m_sName = sName ; // assegno dati - pGVect->m_gvV.Set( Vect) ; + pGdbObj->m_pGeoObj = pGeoObj ; // inserisco nel DB - if ( ! AddToGeomDB( pGVect)) { - delete pGVect ; - return false ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -GeomDB::AddPoint( const string& sName, const Point3d& Pnt) -{ - GdbPoint3d* pGPnt ; - - - // verifico validità nome - if ( sName.length() == 0) - return false ; - // alloco oggetto - pGPnt = new(nothrow) GdbPoint3d ; - if ( pGPnt == nullptr) - return false ; - // assegno nome - pGPnt->m_sName = sName ; - // assegno dati - pGPnt->m_gpP.Set( Pnt) ; - // inserisco nel DB - if ( ! AddToGeomDB( pGPnt)) { - delete pGPnt ; - return false ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -GeomDB::AddCurveLine( const string& sName, const CurveLine& CrvLine) -{ - GdbCurveLine* pGdbCL ; - - - // verifico validità nome - if ( sName.length() == 0) - return false ; - // verifico validità dati geometrici - if ( ! CrvLine.IsValid()) - return false ; - // allocazione oggetto - pGdbCL = new(nothrow) GdbCurveLine ; - if ( pGdbCL == nullptr) - return false ; - // assegnazione nome - pGdbCL->m_sName = sName ; - // assegnazione dati - pGdbCL->m_ln = CrvLine ; - // inserimento nel DB - if ( ! AddToGeomDB( pGdbCL)) { - delete pGdbCL ; - return false ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -GeomDB::AddCurveArc( const string& sName, const CurveArc& CrvArc) -{ - GdbCurveArc* pGdbCA ; - - - // verifico validità nome - if ( sName.length() == 0) - return false ; - // verifico validità dati geometrici - if ( ! CrvArc.IsValid()) - return false ; - // alloco oggetto - pGdbCA = new(nothrow) GdbCurveArc ; - if ( pGdbCA == nullptr) - return false ; - // assegno nome - pGdbCA->m_sName = sName ; - // assegno dati - pGdbCA->m_ar = CrvArc ; - // inserisco nel DB - if ( ! AddToGeomDB( pGdbCA)) { - delete pGdbCA ; - return false ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -GeomDB::AddCurveBez( const string& sName, const CurveBezier& CrvBez) -{ - GdbCurveBezier* pGdbCB ; - - - // verifico validità nome - if ( sName.length() == 0) - return false ; - // verifico validità dati geometrici - if ( ! CrvBez.IsValid()) - return false ; - // allocazione oggetto - pGdbCB = new(nothrow) GdbCurveBezier ; - if ( pGdbCB == nullptr) - return false ; - // assegnazione nome - pGdbCB->m_sName = sName ; - // assegnamento dati - pGdbCB->m_bz = CrvBez ; - // inserimento nel DB - if ( ! AddToGeomDB( pGdbCB)) { - delete pGdbCB ; - return false ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -GeomDB::AddCurveCompo( const string& sName, const CurveComposite& CrvCompo) -{ - GdbCurveComposite* pGdbCC ; - - - // verifico validità nome - if ( sName.length() == 0) - return false ; - // verifico validità dati geometrici - if ( ! CrvCompo.IsValid()) - return false ; - // allocazione oggetto - pGdbCC = new(nothrow) GdbCurveComposite ; - if ( pGdbCC == nullptr) - return false ; - // assegnazione nome - pGdbCC->m_sName = sName ; - // assegnamento dati - pGdbCC->m_cc = CrvCompo ; - // inserimento nel DB - if ( ! AddToGeomDB( pGdbCC)) { - delete pGdbCC ; + if ( ! AddToGeomDB( pGdbObj)) { + delete pGdbObj ; return false ; } @@ -406,133 +271,29 @@ GeomDB::AddCurveCompo( const string& sName, const CurveComposite& CrvCompo) GeoObjType GeomDB::GetObjType( const std::string& sName) { - const GdbObj* pGObj ; + const GdbObj* pGdbObj ; // recupero l'oggetto - if ( ( pGObj = GetGdbObj( sName)) == nullptr) + if ( ( pGdbObj = GetGdbObj( sName)) == nullptr) return GEO_NONE ; // ne identifico il tipo - return pGObj->GetType() ; + return pGdbObj->GetType() ; } //---------------------------------------------------------------------------- -const GeoVector3d* -GeomDB::GetGeoVector3d( const string& sName) +IGeoObj* +GeomDB::GetGeoObj( const string& sName) { - const GdbObj* pGObj ; + const GdbObj* pGdbObj ; - // recupero l'oggetto e ne verifico il tipo - if ( ( pGObj = GetGdbObj( sName)) == nullptr || pGObj->GetType() != GEO_VECT3D) + // recupero l'oggetto Gdb + if ( ( pGdbObj = GetGdbObj( sName)) == nullptr) return nullptr ; - // assegno il vettore per riferimento - return &(static_cast(pGObj))->m_gvV ; -} - -//---------------------------------------------------------------------------- -const Vector3d* -GeomDB::GetVector( const string& sName) -{ - return &( GetGeoVector3d( sName)->m_vtV) ; -} - -//---------------------------------------------------------------------------- -const GeoPoint3d* -GeomDB::GetGeoPoint3d( const string& sName) -{ - const GdbObj* pGObj ; - - - // recupero l'oggetto e ne verifico il tipo - if ( ( pGObj = GetGdbObj( sName)) == nullptr || pGObj->GetType() != GEO_PNT3D) - return nullptr ; - - // assegno il punto per riferimento - return &(static_cast(pGObj))->m_gpP ; -} - -//---------------------------------------------------------------------------- -const Point3d* -GeomDB::GetPoint( const string& sName) -{ - return &( GetGeoPoint3d( sName)->m_ptP) ; -} - -//---------------------------------------------------------------------------- -const CurveLine* -GeomDB::GetCurveLine( const string& sName) -{ - const GdbObj* pGObj ; - - - // recupero l'oggetto e ne verifico il tipo - if ( ( pGObj = GetGdbObj( sName)) == nullptr || pGObj->GetType() != CRV_LINE) - return nullptr ; - - // assegno la linea per riferimento - return &(static_cast(pGObj))->m_ln ; -} - -//---------------------------------------------------------------------------- -const CurveArc* -GeomDB::GetCurveArc( const string& sName) -{ - const GdbObj* pGObj ; - - - // recupero l'oggetto e ne verifico il tipo - if ( ( pGObj = GetGdbObj( sName)) == nullptr || pGObj->GetType() != CRV_ARC) - return nullptr ; - - // assegno l'arco per riferimento - return &(static_cast(pGObj))->m_ar ; -} - -//---------------------------------------------------------------------------- -const CurveBezier* -GeomDB::GetCurveBez( const string& sName) -{ - const GdbObj* pGObj ; - - - // recupero l'oggetto e ne verifico il tipo - if ( ( pGObj = GetGdbObj( sName)) == nullptr || pGObj->GetType() != CRV_BEZ) - return nullptr ; - - // assegno la curva di Bezier per riferimento - return &(static_cast(pGObj))->m_bz ; -} - -//---------------------------------------------------------------------------- -const CurveComposite* -GeomDB::GetCurveCompo( const std::string& sName) -{ - const GdbObj* pGObj ; - - - // recupero l'oggetto e ne verifico il tipo - if ( ( pGObj = GetGdbObj( sName)) == nullptr || pGObj->GetType() != CRV_COMPO) - return nullptr ; - - // assegno la curva di Bezier per riferimento - return &(static_cast(pGObj))->m_cc ; -} - -//---------------------------------------------------------------------------- -const Curve* -GeomDB::GetCurve( const string& sName) -{ - const GdbObj* pGObj ; - - - // recupero l'oggetto - if ( ( pGObj = GetGdbObj( sName)) == nullptr) - return nullptr ; - - // ritorno il puntatore alla curva (oppure nullptr se non è una curva) - return ::GetCurve( pGObj->GetGeoObj()) ; + // restituisco il suo contenuto geometrico + return pGdbObj->m_pGeoObj ; } //---------------------------------------------------------------------------- @@ -593,58 +354,58 @@ GeomDB::Erase( const string& sName) bool GeomDB::Translate( const string& sName, const Vector3d& vtMove) { - GdbObj* pGObj ; + GdbObj* pGdbObj ; // recupero l'oggetto - if ( ( pGObj = GetGdbObj( sName)) == nullptr) + if ( ( pGdbObj = GetGdbObj( sName)) == nullptr) return false ; // eseguo l'operazione - return pGObj->Translate( vtMove) ; + return pGdbObj->Translate( vtMove) ; } //---------------------------------------------------------------------------- bool -GeomDB::Rotate( const string& sName, const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) +GeomDB::Rotate( const string& sName, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) { - GdbObj* pGObj ; + GdbObj* pGdbObj ; // recupero l'oggetto - if ( ( pGObj = GetGdbObj( sName)) == nullptr) + if ( ( pGdbObj = GetGdbObj( sName)) == nullptr) return false ; // eseguo l'operazione - return pGObj->Rotate( ptAx, vtAx, dAngDeg * DEGTORAD) ; + return pGdbObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ; } //---------------------------------------------------------------------------- bool GeomDB::Scale( const string& sName, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) { - GdbObj* pGObj ; + GdbObj* pGdbObj ; // recupero l'oggetto - if ( ( pGObj = GetGdbObj( sName)) == nullptr) + if ( ( pGdbObj = GetGdbObj( sName)) == nullptr) return false ; // eseguo l'operazione - return pGObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; + return pGdbObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; } //---------------------------------------------------------------------------- bool GeomDB::Mirror( const string& sName, const Point3d& ptOn, const Vector3d& vtNorm) { - GdbObj* pGObj ; + GdbObj* pGdbObj ; // recupero l'oggetto - if ( ( pGObj = GetGdbObj( sName)) == nullptr) + if ( ( pGdbObj = GetGdbObj( sName)) == nullptr) return false ; // eseguo l'operazione - return pGObj->Mirror( ptOn, vtNorm) ; + return pGdbObj->Mirror( ptOn, vtNorm) ; } diff --git a/GeomDB.h b/GeomDB.h index 2eb8433..704b025 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -15,6 +15,7 @@ #include #include +#include "/EgtDev/Include/EGkGeomDB.h" #include "GdbObj.h" //---------------------------------------------------------------------------- @@ -25,38 +26,30 @@ typedef std::unordered_map< std::string, GdbObj*> STRPGDBO_UMAP ; class CScan ; //---------------------------------------------------------------------------- -class GeomDB +class GeomDB : public IGeomDB { + public : + virtual ~GeomDB( void) ; + virtual bool Init( void) ; + virtual bool Clear( void) ; + virtual bool Load( std::ifstream& osIn) ; + virtual bool Save( std::ofstream& osOut) ; + virtual bool ExistsObj( const std::string& sName) ; + virtual bool AddGeoObj( const std::string& sName, IGeoObj* pGeoObj) ; + virtual GeoObjType GetObjType( const std::string& sName) ; + virtual IGeoObj* GetGeoObj( const std::string& sName) ; + virtual bool Copy( const std::string& sNameSou, const std::string& sNameDest) ; + virtual bool Erase( const std::string& sName) ; + virtual bool Translate( const std::string& sName, const Vector3d& vtMove) ; + virtual bool Rotate( const std::string& sName, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ; + virtual bool Rotate( const std::string& sName, const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) + { double dAngRad = dAngDeg * DEGTORAD ; + return Rotate( sName, ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + virtual bool Scale( const std::string& sName, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) ; + virtual bool Mirror( const std::string& sName, const Point3d& ptOn, const Vector3d& vtNorm) ; + public : GeomDB( void) ; - ~GeomDB( void) ; - bool Init( void) ; - bool Clear( void) ; - bool Load( std::ifstream& osIn) ; - bool Save( std::ofstream& osOut) ; - bool ExistsGdbObj( const std::string& sName) ; - bool AddVector( const std::string& sName, const Vector3d& Vect) ; - bool AddPoint( const std::string& sName, const Point3d& Pnt) ; - bool AddCurveLine( const std::string& sName, const CurveLine& CrvLine) ; - bool AddCurveArc( const std::string& sName, const CurveArc& CrvArc) ; - bool AddCurveBez( const std::string& sName, const CurveBezier& CrvBez) ; - bool AddCurveCompo( const std::string& sName, const CurveComposite& CrvCompo) ; - GeoObjType GetObjType( const std::string& sName) ; - const GeoVector3d* GetGeoVector3d( const std::string& sName) ; - const Vector3d* GetVector( const std::string& sName) ; - const GeoPoint3d* GetGeoPoint3d( const std::string& sName) ; - const Point3d* GetPoint( const std::string& sName) ; - const CurveLine* GetCurveLine( const std::string& sName) ; - const CurveArc* GetCurveArc( const std::string& sName) ; - const CurveBezier* GetCurveBez( const std::string& sName) ; - const CurveComposite* GetCurveCompo( const std::string& sName) ; - const Curve* GetCurve( const std::string& sName) ; - bool Copy( const std::string& sNameSou, const std::string& sNameDest) ; - bool Erase( const std::string& sName) ; - bool Translate( const std::string& sName, const Vector3d& vtMove) ; - bool Rotate( const std::string& sName, const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) ; - bool Scale( const std::string& sName, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) ; - bool Mirror( const std::string& sName, const Point3d& ptOn, const Vector3d& vtNorm) ; private : GdbObj* GetGdbObj( const std::string& sName) ; diff --git a/OutScl.cpp b/OutScl.cpp new file mode 100644 index 0000000..f8d1d02 --- /dev/null +++ b/OutScl.cpp @@ -0,0 +1,394 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : OutScl.cpp Data : 31.12.12 Versione : 1.1a1 +// Contenuto : Implementazione della classe output SCL. +// +// +// +// Modifiche : 31.12.12 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include +#include +#include +#include +#include "/EgtDev/Include/EgnStringUtils.h" +//#include "GeoObjTypeFun.h" +#include "OutScl.h" + +using namespace std ; + + +//---------------------------------------------------------------------------- +OutScl::OutScl( void) +{ +} + +//---------------------------------------------------------------------------- +OutScl::~OutScl( void) +{ + Close() ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::Open( const wstring& sOutScl) +{ + // apro il file + m_ofFile.open( sOutScl) ; + if ( ! m_ofFile.good()) + return false ; + // scrivo linee iniziali + Start() ; + New() ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::Close( void) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + // scrivo linee finali + End() ; + // chiudo il file + m_ofFile.close() ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::Start( void) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + // emetto stringa + m_ofFile << "{" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::End( void) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + // emetto stringa + m_ofFile << "}" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::New( void) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + // emetto stringa + m_ofFile << "NewFile() ;" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::Remark( string sRemark) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + // emetto stringa + m_ofFile << "// " << sRemark << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::SetMaterial( double dRed, double dGreen, double dBlue) +{ + int nRed ; + int nGreen ; + int nBlue ; + string sMat ; + + + // componenti colore nell'intervallo 0-255 + nRed = max( 0, min( int( 255 * dRed), 255)) ; + nGreen = max( 0, min( int( 255 * dGreen), 255)) ; + nBlue = max( 0, min( int( 255 * dBlue), 255)) ; + // calcolo nome materiale + sMat = "RGB" + ToString( nRed, 3) + ToString( nGreen, 3) + ToString( nBlue, 3) ; + // definizione materiale + return SetMaterial( sMat, ( nRed / 255.), ( nGreen / 255.), ( nBlue / 255.)) ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::SetMaterial( string sMaterial, double dRed, double dGreen, double dBlue) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + + // salvo nome materiale + m_sMaterial = sMaterial ; + + // emetto comando di creazione materiale + m_ofFile << "AddMaterial( \"" << sMaterial << "\", " << + ToString( dRed, 3) << ", " << ToString( dGreen, 3) << ", " << ToString( dBlue, 3) << ") ;" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::SetPartLay( string sPart, string sLay) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + + m_sPartLay = sPart + "\\" + sLay ; + + // emetto comando di creazione pezzo + m_ofFile << "CreatePart( \"" << sPart << "\") ;" << endl ; + // emetto comando di creazione layer + m_ofFile << "CreateLayer( \"" << sLay << "\", \"" << sPart << "\") ;" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::Line2P( Point3d ptP1, Point3d ptP2) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + + // emetto linea + m_ofFile << "Line3D( \"" << m_sPartLay << "\", \"" << m_sMaterial << "\", " ; + m_ofFile << ToString( ptP1) << ", " << ToString( ptP2) ; + m_ofFile << ") ;" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::Arc3P( Point3d ptP1, Point3d ptP2, Point3d ptP3) +{ + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + + // emetto arco + m_ofFile << "Arc3P( \"" << m_sPartLay << "\", \"" << m_sMaterial << "\", " ; + m_ofFile << ToString( ptP1) << ", " << ToString( ptP2) << ", " << ToString( ptP3) ; + m_ofFile << ") ;" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::ArcCPA( Point3d ptCen, Point3d ptMed, double dAngCenDeg) +{ + Point3d ptP1 ; + Point3d ptP3 ; + + + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + + // calcolo i due punti estremi + ptP1 = ptMed ; + ptP1.Rotate( ptCen, Vector3d( 0, 0, 1), - 0.5 * dAngCenDeg * DEGTORAD) ; + ptP3 = ptMed ; + ptP3.Rotate( ptCen, Vector3d( 0, 0, 1), 0.5 * dAngCenDeg * DEGTORAD) ; + + // emetto arco + m_ofFile << "Arc3P( \"" << m_sPartLay << "\", \"" << m_sMaterial << "\", " ; + m_ofFile << ToString( ptP1, 8) << ", " << ToString( ptMed, 8) << ", " << ToString( ptP3, 8) ; + m_ofFile << ") ;" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::PutCurveLine( const ICurveLine& CrvLine) +{ + // scrittura comandi SCL + Remark( "CurveLine") ; + Line2P( CrvLine.GetStart(), CrvLine.GetEnd()) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::PutCurveArc( const ICurveArc& CrvArc) +{ + const double DELTA_ANG = 15 ; + int nNumSeg ; + int i ; + double dU ; + double dCurv ; + Point3d ptIni ; + Point3d ptFin ; + Vector3d vtT ; + Vector3d vtN ; + + + // numero segmenti con cui approssimare + nNumSeg = (int) ( fabs( CrvArc.GetAngCenter()) / DELTA_ANG) + 1 ; + // ciclo sui segmenti + Remark( "CurveArc") ; + for ( i = 0 ; i <= nNumSeg ; i ++) { + // ricavo il punto + dU = i / (double) nNumSeg ; + CrvArc.GetPoint( dU, ptFin) ; + // dopo il primo, disegno + if ( i > 0) + Line2P( ptIni, ptFin) ; + // nuovo iniziale prende i valori del finale + ptIni = ptFin ; + } + // ciclo per disegnare le derivate + Remark( "ArcTangents+Der2") ; + for ( i = 0 ; i <= nNumSeg ; i ++ ) { + // ricavo il punto + dU = i / (double) nNumSeg ; + CrvArc.GetPointTangNormCurv( dU, ptFin, vtT, vtN, dCurv) ; + // tangente + Line2P( ptFin - vtT, ptFin + vtT) ; + // derivata + if ( fabs( dCurv) > EPS_ZERO) + Line2P( ptFin, ptFin + vtN * ( 1 / dCurv)) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::PutCurveBez( const ICurveBezier& CrvBez) +{ + const int NUM_SEG = 20 ; + bool bCCW ; + int i ; + double dU ; + double dCurv ; + double dAngCenDeg ; + Point3d ptIni ; + Point3d ptFin ; + Point3d ptCen ; + Vector3d vtT ; + Vector3d vtN ; + + + // ciclo per disegnare i segmenti + Remark( "BezierCurve") ; + for ( i = 0 ; i <= NUM_SEG ; i ++ ) { + // ricavo il punto + dU = i / (double) NUM_SEG ; + CrvBez.GetPoint( dU, ptFin) ; + // dopo il primo, disegno + if ( i > 0) + Line2P( ptIni, ptFin) ; + // nuovo iniziale prende i valori del finale + ptIni = ptFin ; + } + // ciclo per disegnare le derivate + Remark( "BezierTangents+Der2") ; + for ( i = 0 ; i <= NUM_SEG ; i ++ ) { + // ricavo il punto + dU = i / (double) NUM_SEG ; + CrvBez.GetPointTangNormCurv( dU, ptFin, vtT, vtN, dCurv) ; + // curvatura + if ( fabs( dCurv) > EPS_ZERO) { + // tratto di arco + ptCen = ptFin + vtN * ( 1 / dCurv) ; + bCCW = ( vtT ^ vtN).z > 0 ; + dAngCenDeg = ( bCCW ? 1 : -1) * 4 * dCurv * RADTODEG ; + ArcCPA( ptCen, ptFin, dAngCenDeg) ; + // raggio + Line2P( ptFin, ptCen) ; + } + // altrimenti, tangente + else if ( ! vtT.IsSmall()) + Line2P( ptFin - vtT, ptFin + vtT) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::PutPolygBez( const ICurveBezier& CrvBez) +{ + int i ; + Point3d ptIni ; + Point3d ptFin ; + + + // ciclo per disegnare il poligono di controllo + Remark( "BezierPolygon") ; + for ( i = 0 ; i <= CrvBez.GetDegree() ; i ++) { + ptFin = CrvBez.GetControlPoint( i) ; + // dopo il primo, disegno + if ( i > 0) + Line2P( ptIni, ptFin) ; + // nuovo iniziale prende i valori del finale + ptIni = ptFin ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +OutScl::PutCurveCompo( const ICurveComposite& CrvCompo) +{ + const ICurve* pCrvSmpl ; + + + pCrvSmpl = CrvCompo.GetFirstCurve() ; + while ( pCrvSmpl != nullptr) { + // scrittura comandi SCL + Remark( "CurveComposite") ; + // secondo il tipo + switch ( pCrvSmpl->GetType()) { + case CRV_LINE : + PutCurveLine( *::GetCurveLine( pCrvSmpl)) ; + break ; + case CRV_ARC : + PutCurveArc( *::GetCurveArc( pCrvSmpl)) ; + break ; + case CRV_BEZ : + PutCurveBez( *::GetCurveBezier( pCrvSmpl)) ; + break ; + } + // passo alla successiva + pCrvSmpl = CrvCompo.GetNextCurve() ; + } + + return true ; +} \ No newline at end of file diff --git a/OutScl.h b/OutScl.h new file mode 100644 index 0000000..e4fc558 --- /dev/null +++ b/OutScl.h @@ -0,0 +1,56 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : OutScl.h Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe output SCL. +// +// +// +// Modifiche : 31.12.12 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include +#include +#include "/EgtDev/Include/EgkPoint3d.h" +#include "/EgtDev/Include/EgkCurveLine.h" +#include "/EgtDev/Include/EgkCurveArc.h" +#include "/EgtDev/Include/EgkCurveBezier.h" +#include "/EgtDev/Include/EgkCurveComposite.h" + + +//---------------------------------------------------------------------------- +class OutScl +{ + public : + OutScl( void) ; + ~OutScl( void) ; + bool Open( const std::wstring& sOutScl) ; + bool Close( void) ; + bool Remark( std::string sRemark) ; + bool SetMaterial( double dRed, double dGreen, double dBlue) ; + bool SetPartLay( std::string sPart, std::string sLay) ; + bool PutCurveLine( const ICurveLine& CrvLine) ; + bool PutCurveArc( const ICurveArc& CrvArc) ; + bool PutCurveBez( const ICurveBezier& CrvBez) ; + bool PutPolygBez( const ICurveBezier& CrvBez) ; + bool PutCurveCompo( const ICurveComposite& CrvCompo) ; + + private : + bool Start( void) ; + bool End( void) ; + bool New( void) ; + bool SetMaterial( std::string sMaterial, double dRed, double dGreen, double dBlue) ; + bool Line2P( Point3d ptP1, Point3d ptP2) ; + bool Arc3P( Point3d ptP1, Point3d ptP2, Point3d ptP3) ; + bool ArcCPA( Point3d ptCen, Point3d ptMed, double dAngCenDeg) ; + + private : + std::ofstream m_ofFile ; + std::string m_sMaterial ; + std::string m_sPartLay ; +} ; +