From 8e9bc9169c84e4e43966ceae7a527e8fcdadc8e8 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 5 Dec 2013 07:33:42 +0000 Subject: [PATCH] EgtGeomKernel 1.4a3 : Migliorata gestione gruppi, aggiunti GdbIterator, GeoFrame3d e IdManager. --- EgtGeomKernel.rc | Bin 7630 -> 7630 bytes EgtGeomKernel.vcxproj | 10 +- EgtGeomKernel.vcxproj.filters | 30 ++++- Frame3d.cpp | 49 ++++++-- GdbExecutor.cpp | 200 +++++++++++++++++++++++-------- GdbExecutor.h | 4 +- GdbGroup.cpp | 84 ++++++++++++- GdbGroup.h | 15 ++- GdbIterator.cpp | 220 ++++++++++++++++++++++++++++++++++ GdbIterator.h | 42 +++++++ GdbNode.cpp | 2 +- GdbNode.h | 10 +- GdbObj.cpp | 32 ++++- GdbObj.h | 10 +- GeoFrame3d.cpp | 126 +++++++++++++++++++ GeoFrame3d.h | 63 ++++++++++ GeoObj.cpp | 2 +- GeoPoint3d.cpp | 2 +- GeoVector3d.cpp | 2 +- GeomDB.cpp | 179 +++++++++++++++++---------- GeomDB.h | 27 ++++- IdManager.h | 28 +++++ OutScl.cpp | 54 +++++++++ OutScl.h | 2 + Vector3d.cpp | 46 +++++++ 25 files changed, 1095 insertions(+), 144 deletions(-) create mode 100644 GdbIterator.cpp create mode 100644 GdbIterator.h create mode 100644 GeoFrame3d.cpp create mode 100644 GeoFrame3d.h create mode 100644 IdManager.h diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index a62766f82845d711bd35a2e9b8c51c6bb230ea21..b3aff211a3780b19ecfa4b2743e35cc51cbb9f7a 100644 GIT binary patch delta 60 zcmX?Sea?ErH#SD&&1d<}Gfn;{tTVZRlVkE5K{-a_$&JFgn=OQF7&kX@dohER*a9i2 H@HB1!y5baT delta 60 zcmX?Sea?ErH#SD2&1d<}Gfn;{tTVZRlVkE5K{-aF$&JFgn=OQF7&kX@dohER*a9i2 H@HB1!x^fg} diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 3c7c20b..a06ad4c 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -127,8 +127,10 @@ copy $(TargetPath) \EgtProg\Dll + + @@ -148,7 +150,10 @@ copy $(TargetPath) \EgtProg\Dll + + + @@ -158,7 +163,7 @@ copy $(TargetPath) \EgtProg\Dll - + @@ -167,12 +172,15 @@ copy $(TargetPath) \EgtProg\Dll + + + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index aeefdf3..7396a04 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -87,6 +87,12 @@ File di origine\Gdb + + File di origine\Geo + + + File di origine\Gdb + @@ -182,15 +188,33 @@ File di intestazione - - File di intestazione - File di intestazione File di intestazione + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + diff --git a/Frame3d.cpp b/Frame3d.cpp index c459f01..54ad265 100644 --- a/Frame3d.cpp +++ b/Frame3d.cpp @@ -176,17 +176,16 @@ Frame3d::Translate( const Vector3d& vtMove) bool Frame3d::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) { - double dCosAng ; - double dSinAng ; - + return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; +} +//---------------------------------------------------------------------------- +bool +Frame3d::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) +{ // verifico validità riferimento if ( m_nType == ERR) return false ; - - // calcolo seno e coseno dell'angolo di rotazione - dCosAng = cos( dAngRad) ; - dSinAng = sin( dAngRad) ; // controllo solo la prima rotazione, per le altre è lo stesso if ( ! m_ptOrig.Rotate( ptAx, vtAx, dCosAng, dSinAng)) { @@ -208,7 +207,7 @@ Frame3d::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) bool Frame3d::ToGlob( const Frame3d& frRef) { - // verifico validità deu frame + // verifico validità del frame if ( GetType() == ERR || frRef.GetType() == ERR) return false ; @@ -303,3 +302,37 @@ Frame3d::CalculateType( void) m_nType = GEN ; } } + +//---------------------------------------------------------------------------- +bool +Frame3d::GetRotationsCAC1( double& dAngCDeg, double& dAngADeg, double& dAngC1Deg) const +{ + bool bDet ; + double dAngVertDeg ; + double dAngOrizzDeg ; + Vector3d vtXnoC1 ; + + + // verifico validità riferimento + if ( m_nType == ERR) + return false ; + + // calcolo angoli sferici del versore Z + m_vtVersZ.ToSpherical( nullptr, &dAngVertDeg, &dAngOrizzDeg) ; + dAngADeg = dAngVertDeg ; + + // ricavo la prima rotazione attorno a Z + if ( dAngADeg > EPS_ANG_SMALL) + dAngCDeg = dAngOrizzDeg + 90 ; + else + m_vtVersX.ToSpherical( nullptr, nullptr, &dAngCDeg) ; + + // calcolo l'asse X senza la rotazione attorno a C' + vtXnoC1.FromPolar( 1, dAngCDeg) ; + + // calcolo la rotazione attorno a C' + if ( ! vtXnoC1.GetRotation( m_vtVersX, m_vtVersZ, dAngC1Deg, bDet) || ! bDet) + dAngC1Deg = 0 ; + + return true ; +} \ No newline at end of file diff --git a/GdbExecutor.cpp b/GdbExecutor.cpp index 3861143..e6c3342 100644 --- a/GdbExecutor.cpp +++ b/GdbExecutor.cpp @@ -19,11 +19,13 @@ #include "/EgtDev/Include/EgnStringConverter.h" #include "/EgtDev/Include/EgkGeoPoint3d.h" #include "/EgtDev/Include/EgkGeoVector3d.h" +#include "/EgtDev/Include/EgkGeoFrame3d.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 "/EgtDev/Include/EgtPointerOwner.h" +#include "GdbIterator.h" #include "GdbExecutor.h" using namespace std ; @@ -118,6 +120,8 @@ GdbExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& return ExecutePoint( sCmd2, vsParams) ; else if ( sCmd1 == "V" || sCmd1 == "VECTOR") return ExecuteVector( sCmd2, vsParams) ; + else if ( sCmd1 == "FR" || sCmd1 == "FRAME") + return ExecuteFrame( sCmd2, vsParams) ; else if ( sCmd1 == "CL" || sCmd1 == "CURVELINE") return ExecuteCurveLine( sCmd2, vsParams) ; else if ( sCmd1 == "CA" || sCmd1 == "CURVEARC") @@ -172,16 +176,52 @@ GdbExecutor::ExecuteAlias( const string& sCmd2, const STRVECTOR& vsParams) bool GdbExecutor::ExecuteGroup( const string& sCmd2, const STRVECTOR& vsParams) { - // analisi ed esecuzione dei comandi - if ( sCmd2 == "MAKE" || sCmd2 == "") { - // 2 parametri : Id e Id del padre - if ( vsParams.size() != 2) - return false ; - // creo il gruppo - return m_pGDB->AddGroup( GetIdParam( vsParams[0]), GetIdParam( vsParams[1])) ; - } + Frame3d frFrame ; - return false ; + + // gruppo generico + if ( sCmd2 == "MAKE" || sCmd2 == "") { + Point3d ptOrig ; + Vector3d vtDirX ; + Vector3d vtDirY ; + Vector3d vtDirZ ; + // 6 parametri : Id, Id del padre, Orig, VersX, VersY, VersZ + if ( vsParams.size() != 6) + return false ; + // recupero i componenti + if ( ! GetPointParam( vsParams[2], ptOrig) || + ! GetVectorParam( vsParams[3], vtDirX) || + ! GetVectorParam( vsParams[4], vtDirY) || + ! GetVectorParam( vsParams[5], vtDirZ)) + return false ; + // costruisco il riferimento + if ( ! frFrame.Set( ptOrig, vtDirX, vtDirY, vtDirZ)) + return false ; + } + // gruppo orientato come il padre + else if ( sCmd2 == "PLANEXY" || sCmd2 == "XY") { + Point3d ptOrig ; + // 3 parametri : Id, Id del padre, Orig + if ( vsParams.size() != 3) + return false ; + // recupero i componenti + if ( ! GetPointParam( vsParams[2], ptOrig)) + return false ; + // costruisco il riferimento + if ( ! frFrame.Set( ptOrig, Frame3d::TOP)) + return false ; + } + else + return false ; + + // creo il gruppo + int nIdDest = GetIdParam( vsParams[0]) ; + 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 ; + + return ( nIdNew != GDB_ID_NULL) ; } //---------------------------------------------------------------------------- @@ -204,7 +244,7 @@ GdbExecutor::ExecutePoint( const string& sCmd2, const STRVECTOR& vsParams) if ( pGPnt == nullptr) return false ; pGPnt->Set( Pnt) ; - return m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]),pGPnt) ; + return ( m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]),pGPnt) != GDB_ID_NULL) ; } return false ; @@ -230,7 +270,37 @@ GdbExecutor::ExecuteVector( const string& sCmd2, const STRVECTOR& vsParams) if ( pGVect == nullptr) return false ; pGVect->Set( Vect) ; - return m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), pGVect) ; + return ( m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), pGVect) != GDB_ID_NULL) ; + } + + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::ExecuteFrame( const string& sCmd2, const STRVECTOR& vsParams) +{ + // analisi ed esecuzione dei comandi + if ( sCmd2 == "MAKE" || sCmd2 == "") { + Point3d ptOrig ; + Vector3d vtDirX ; + Vector3d vtDirY ; + Vector3d vtDirZ ; + // 6 parametri + if ( vsParams.size() != 6) + return false ; + // recupero i componenti + if ( ! GetPointParam( vsParams[2], ptOrig) || + ! GetVectorParam( vsParams[3], vtDirX) || + ! GetVectorParam( vsParams[4], vtDirY) || + ! GetVectorParam( vsParams[5], vtDirZ)) + return false ; + // creo il riferimento + IGeoFrame3d* pGFrame = CreateGeoFrame3d() ; + if ( pGFrame == nullptr) + return false ; + pGFrame->Set( ptOrig, vtDirX, vtDirY, vtDirZ) ; + return ( m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), pGFrame) != GDB_ID_NULL) ; } return false ; @@ -252,10 +322,10 @@ GdbExecutor::ExecuteCurveLine( const string& sCmd2, const STRVECTOR& vsParams) ! GetPointParam( vsParams[3], ptEnd)) return false ; // creo la linea - ReleasePtr pCrvLine( CreateCurveLine()) ; + PtrOwner pCrvLine( CreateCurveLine()) ; if ( ! IsValid( pCrvLine) || ! pCrvLine->Set( ptStart, ptEnd)) return false ; - return m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), Release( pCrvLine)) ; + return ( m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), Release( pCrvLine)) != GDB_ID_NULL) ; } return false ; @@ -266,7 +336,7 @@ bool GdbExecutor::ExecuteCurveArc( const string& sCmd2, const STRVECTOR& vsParams) { // creo l'arco - ReleasePtr pCrvArc( CreateCurveArc()) ; + PtrOwner pCrvArc( CreateCurveArc()) ; if ( ! IsValid( pCrvArc)) return false ; @@ -337,7 +407,7 @@ GdbExecutor::ExecuteCurveArc( const string& sCmd2, const STRVECTOR& vsParams) return false ; // inserisco l'arco nel DB - return m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), Release( pCrvArc)) ; + return ( m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), Release( pCrvArc)) != GDB_ID_NULL) ; } //---------------------------------------------------------------------------- @@ -345,7 +415,7 @@ bool GdbExecutor::ExecuteCurveBez( const string& sCmd2, const STRVECTOR& vsParams) { // creo la curva di Bezier - ReleasePtr pCrvBez( CreateCurveBezier()) ; + PtrOwner pCrvBez( CreateCurveBezier()) ; if ( ! IsValid( pCrvBez)) return false ; @@ -387,7 +457,7 @@ GdbExecutor::ExecuteCurveBez( const string& sCmd2, const STRVECTOR& vsParams) return false ; // recupero e setto punti di controllo for ( i = 0 ; i <= nDeg ; ++ i) { - if ( ! GetPointWeParam( vsParams[i+3], ptP, dW) || + if ( ! GetPointWParam( vsParams[i+3], ptP, dW) || ! pCrvBez->SetControlPoint( i, ptP, dW)) return false ; } @@ -397,7 +467,7 @@ GdbExecutor::ExecuteCurveBez( const string& sCmd2, const STRVECTOR& vsParams) return false ; // inserisco la curva di Bezier nel DB - return m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), Release( pCrvBez)) ; + return ( m_pGDB->AddGeoObj( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), Release( pCrvBez)) != GDB_ID_NULL) ; } //---------------------------------------------------------------------------- @@ -410,7 +480,7 @@ GdbExecutor::ExecuteCurveCompo( const string& sCmd2, const STRVECTOR& vsParams) STRVECTOR vsNames ; STRVECTOR::iterator Iter ; const ICurve* pCrv ; - ReleasePtr pCrvCompo( CreateCurveComposite()) ; + PtrOwner pCrvCompo( CreateCurveComposite()) ; if ( ! IsValid( pCrvCompo)) return false ; // 3 o 4 parametri @@ -467,7 +537,7 @@ GdbExecutor::GetIdParam( const std::string& sParam) return nVal ; // altrimenti errore else - return 0 ; + return - 1 ; } //---------------------------------------------------------------------------- @@ -545,7 +615,7 @@ GdbExecutor::GetPointParam( const std::string& sParam, Point3d& ptP) //---------------------------------------------------------------------------- bool -GdbExecutor::GetPointWeParam( const std::string& sParam, Point3d& ptP, double& dW) +GdbExecutor::GetPointWParam( const std::string& sParam, Point3d& ptP, double& dW) { STRVECTOR vsParams ; STRVECTOR::iterator Iter ; @@ -590,7 +660,13 @@ GdbExecutor::ExecuteCopy( const STRVECTOR& vsParams) if ( vsParams.size() != 3) return false ; // esecuzione copia - return m_pGDB->Copy( GetIdParam( vsParams[0]), GetIdParam( vsParams[1]), GetIdParam( vsParams[2])) ; + int nIdDest = GetIdParam( vsParams[1]) ; + 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 ; + + return ( nIdNew != GDB_ID_NULL) ; } //---------------------------------------------------------------------------- @@ -811,7 +887,17 @@ GdbExecutor::ExecuteOutScl( const string& sCmd2, const STRVECTOR& vsParams) // eseguo return m_OutScl.SetPartLay( vsParams[0], vsParams[1]) ; } - // emetto entità + // emetto gruppo + else if ( sCmd2 == "PUTGR") { + int nId ; + // un parametro + if ( vsParams.size() != 1) + return false ; + nId = GetIdParam( vsParams[0]) ; + // emetto gruppo e suoi sottoposti + return OutGroupScl( nId) ; + } + // emetto oggetto geometrico else if ( sCmd2 == "PUT") { bool bCrvVsPolyg ; int nId ; @@ -832,35 +918,49 @@ GdbExecutor::ExecuteOutScl( const string& sCmd2, const STRVECTOR& vsParams) for ( Iter = vsNames.begin() ; Iter != vsNames.end() ; ++Iter) { // recupero l'oggetto ed eseguo l'output nId = GetIdParam( *Iter) ; - switch ( m_pGDB->GetObjType( nId)) { - case CRV_LINE : - if ( ! m_OutScl.PutCurveLine( *GetCurveLine( m_pGDB->GetGeoObj( nId)))) - return false ; - break ; - case CRV_ARC : - if ( ! m_OutScl.PutCurveArc( *GetCurveArc( m_pGDB->GetGeoObj( nId)))) - return false ; - break ; - case CRV_BEZ : - if ( bCrvVsPolyg) { - if ( ! m_OutScl.PutCurveBez( *GetCurveBezier( m_pGDB->GetGeoObj( nId)))) - return false ; - } - else { - if ( ! m_OutScl.PutPolygBez( *GetCurveBezier( m_pGDB->GetGeoObj( nId)))) - return false ; - } - break ; - case CRV_COMPO : - if ( ! m_OutScl.PutCurveCompo( *GetCurveComposite( m_pGDB->GetGeoObj( nId)))) - return false ; - break ; - default : + if ( ! m_OutScl.PutCurve( m_pGDB->GetGeoObj( nId), bCrvVsPolyg)) return false ; - } } return true ; } return false ; -} \ No newline at end of file +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::OutGroupScl( int nId) +{ + bool bNext ; + int nParentId ; + int nGdbType ; + Frame3d frFrame ; + GdbIterator Iter ; + + + // emetto dati gruppo + if ( m_pGDB->GetGroupGlobFrame( nId, frFrame)) { + nParentId = m_pGDB->GetParentId( nId) ; + if ( nParentId > GDB_ID_ROOT) { + if ( ! m_OutScl.SetPartLayRef( ToString( nParentId), ToString( nId), frFrame)) + return false ; + } + } + // emetto entità gruppo + Iter.SetGDB( m_pGDB) ; + bNext = Iter.GoToFirstInGroup( nId) ; + while ( bNext) { + nGdbType = Iter.GetGdbType() ; + if ( nGdbType == GDB_GEO) { + if ( ! m_OutScl.PutCurve( Iter.GetGeoObj(), true)) + return false ; + } + else if ( nGdbType == GDB_GROUP) { + if ( ! OutGroupScl( Iter.GetId())) + return false ; + } + bNext = Iter.GoToNext() ; + } + + return true ; +} diff --git a/GdbExecutor.h b/GdbExecutor.h index a9c8490..e8092c4 100644 --- a/GdbExecutor.h +++ b/GdbExecutor.h @@ -35,11 +35,12 @@ class GdbExecutor : public IGdbExecutor 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 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) ; + bool ExecuteFrame( 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) ; @@ -53,6 +54,7 @@ class GdbExecutor : public IGdbExecutor bool ExecuteLoad( const STRVECTOR& vsParams) ; bool ExecuteSave( const STRVECTOR& vsParams) ; bool ExecuteOutScl( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool OutGroupScl( int nId) ; private : IGeomDB* m_pGDB ; diff --git a/GdbGroup.cpp b/GdbGroup.cpp index cafeb17..c682b19 100644 --- a/GdbGroup.cpp +++ b/GdbGroup.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "\EgtDev\Include\EGnStringUtils.h" #include "GdbGroup.h" +#include "IdManager.h" using namespace std ; @@ -56,7 +57,7 @@ GdbGroup::Clear( void) //---------------------------------------------------------------------------- GdbGroup* -GdbGroup::Clone( int nId) const +GdbGroup::Clone( int nId, IdManager& IdMgr) const { GdbGroup* pGdbGroup ; const GdbNode* pNode ; @@ -70,13 +71,14 @@ GdbGroup::Clone( int nId) const // copio dati oggetto Gdb pGdbGroup->m_nId = nId ; + IdMgr.UpdateMaxId( nId) ; // ... // clono i nodi figli pNode = GetFirstNode() ; while ( pNode != nullptr) { // eseguo copia - pNewNode = pNode->Clone( ++ nId) ; + pNewNode = pNode->Clone( IdMgr.GetNewId(), IdMgr) ; if ( pNewNode == nullptr) { delete pGdbGroup ; return nullptr ; @@ -104,13 +106,12 @@ GdbGroup::Save( std::ostream& osOut) const osOut << GetKey() << endl ; // identificativi osOut << m_nId << "@" << GetParentId() << endl ; - // altri parametri - // TODO ... + // dati del riferimento + m_gfrFrame.Save( osOut) ; // lancio il salvataggio dei figli const GdbNode* pGdbNode = GetFirstNode() ; while ( pGdbNode != nullptr) { - // oggetto geometrico if ( ! pGdbNode->Save( osOut)) bOk = false ; pGdbNode = pGdbNode->GetNext() ; @@ -141,8 +142,81 @@ GdbGroup::Load( const string& sType, CScan& TheScanner, int& nParentId) // assegno l'Id del padre if ( ! FromString( vsParams[1], nParentId)) return false ; + // leggo i dati del riferimento + m_gfrFrame.Load( TheScanner) ; return true ; } +//---------------------------------------------------------------------------- +bool +GdbGroup::Translate( const Vector3d& vtMove) +{ + return m_gfrFrame.Translate( vtMove) ; +} + +//---------------------------------------------------------------------------- +bool +GdbGroup::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) +{ + return m_gfrFrame.Rotate( ptAx, vtAx, dCosAng, dSinAng) ; +} + +//---------------------------------------------------------------------------- +bool +GdbGroup::Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) +{ + bool bOk ; + bool bUniform ; + Point3d ptCenLoc ; + GdbNode* pGdbNode ; + + + // non è possibile scalare il riferimento, devo agire sui nodi sottostanti + + // determino se la scalatura è uniforme + bUniform = fabs( dCoeffX - dCoeffY) < EPS_SMALL && fabs( dCoeffX - dCoeffZ) < EPS_SMALL ; + + // se la scalatura è uniforme, basta portare il centro nel riferimento del gruppo + if ( bUniform) { + ptCenLoc = ptCen ; + ptCenLoc.ToLoc( m_gfrFrame.m_frF) ; + } + // altrimenti si deve propagare il riferimento rispetto al centro + else + return false ; // !!!!! TODO !!!!! + + // ciclo sui nodi + bOk = true ; + pGdbNode = GetFirstNode() ; + while ( pGdbNode != nullptr) { + if ( ! pGdbNode->Scale( ptCenLoc, dCoeffX, dCoeffY, dCoeffZ)) + bOk = false ; + pGdbNode = pGdbNode->GetNext() ; + } + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +GdbGroup::GetGlobFrame( Frame3d& frGlob) +{ + GdbGroup* pParent ; + + + // assegno il proprio frame + frGlob = m_gfrFrame.m_frF ; + + // mentre ci sono padri + pParent = GetParent() ; + while ( pParent != nullptr) { + // porto il riferimento corrente sopra il padre + frGlob.ToGlob( pParent->m_gfrFrame.m_frF) ; + // passo al successivo + pParent = pParent->GetParent() ; + } + + return true ; +} diff --git a/GdbGroup.h b/GdbGroup.h index 41068f7..f35ddb0 100644 --- a/GdbGroup.h +++ b/GdbGroup.h @@ -15,6 +15,7 @@ #include #include "/EgtDev/Include/EGkGeoObj.h" +#include "GeoFrame3d.h" #include "GdbNode.h" @@ -25,9 +26,15 @@ class GdbGroup : public GdbNode public : virtual ~GdbGroup( void) ; - virtual GdbGroup* Clone( int nId) const ; + virtual GdbGroup* Clone( int nId, IdManager& IdMgr) const ; virtual bool Save( std::ostream& osOut) const ; virtual bool Load( const std::string& sType, CScan& TheScanner, int& nParentId) ; + virtual bool Translate( const Vector3d& vtMove) ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) + { double dAngRad = dAngDeg * DEGTORAD ; + return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + virtual bool Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) ; public : GdbGroup( void) ; @@ -43,6 +50,12 @@ class GdbGroup : public GdbNode public : static const std::string& GetKey( void) { static std::string s_sKey = "A_GRP" ; return s_sKey ; } + public : + bool GetGlobFrame( Frame3d& frGlob) ; + + public : + GeoFrame3d m_gfrFrame ; + private : int m_nNodeCount ; GdbNode* m_pFirstNode ; diff --git a/GdbIterator.cpp b/GdbIterator.cpp new file mode 100644 index 0000000..75bfb89 --- /dev/null +++ b/GdbIterator.cpp @@ -0,0 +1,220 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GdbIterator.cpp Data : 04.12.13 Versione : 1.4a3 +// Contenuto : Implementazione della classe GdbIterator. +// +// +// +// Modifiche : 04.12.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include +#include "GdbIterator.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +IGdbIterator* +CreateGdbIterator( void) +{ + return static_cast ( new GdbIterator) ; +} + +//---------------------------------------------------------------------------- +// GdbIterator +//---------------------------------------------------------------------------- +GdbIterator::GdbIterator( void) +{ + m_pGDB = nullptr ; + m_pCurrNode = nullptr ; +} + +//---------------------------------------------------------------------------- +GdbIterator::~GdbIterator( void) +{ + // TODO : togliere link da GdbGeom per essere notificato della cancellazione di nodi +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::SetGDB( IGeomDB* pGDB) +{ + m_pGDB = dynamic_cast( pGDB) ; + + return ( m_pGDB != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::GoTo( int nId) +{ + if ( m_pGDB == nullptr) + return false ; + + m_pCurrNode = m_pGDB->GetGdbNode( nId) ; + + return ( m_pCurrNode != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::GoToFirstInGroup( int nIdGroup) +{ + GdbGroup* pGdbGroup ; + + + if ( m_pGDB == nullptr) + return false ; + + // recupero il gruppo + pGdbGroup = m_pGDB->GetGdbGroup( nIdGroup) ; + if ( pGdbGroup == nullptr) { + m_pCurrNode = nullptr ; + return false ; + } + + // recupero il nodo + m_pCurrNode = pGdbGroup->GetFirstNode() ; + + return ( m_pCurrNode != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::GoToNext( void) +{ + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return false ; + + m_pCurrNode = m_pCurrNode->GetNext() ; + + return ( m_pCurrNode != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::GoToLastInGroup( int nIdGroup) +{ + GdbGroup* pGdbGroup ; + + + if ( m_pGDB == nullptr) + return false ; + + // recupero il gruppo + pGdbGroup = m_pGDB->GetGdbGroup( nIdGroup) ; + if ( pGdbGroup == nullptr) { + m_pCurrNode = nullptr ; + return false ; + } + + // recupero il nodo + m_pCurrNode = pGdbGroup->GetLastNode() ; + + return ( m_pCurrNode != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::GoToPrev( void) +{ + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return false ; + + m_pCurrNode = m_pCurrNode->GetPrev() ; + + return ( m_pCurrNode != nullptr) ; +} + +//---------------------------------------------------------------------------- +GdbType +GdbIterator::GetGdbType( void) const +{ + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return GDB_NONE ; + + // se oggetto geometrico + if ( GetGdbObj( m_pCurrNode) != nullptr) + return GDB_GEO ; + // se gruppo + else if ( GetGdbGroup( m_pCurrNode) != nullptr) + return GDB_GROUP ; + // altro + else + return GDB_NONE ; +} + +//---------------------------------------------------------------------------- +IGeoObj* +GdbIterator::GetGeoObj( void) +{ + const GdbObj* pGdbObj ; + + + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return false ; + + // recupero l'oggetto Gdb + if ( ( pGdbObj = GetGdbObj( m_pCurrNode)) == nullptr) + return nullptr ; + + // restituisco il suo contenuto geometrico + return pGdbObj->m_pGeoObj ; +} + +//---------------------------------------------------------------------------- +Frame3d* +GdbIterator::GetGroupFrame( void) +{ + GdbGroup* pGdbGroup ; + + + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return nullptr ; + + if ( ( pGdbGroup = GetGdbGroup( m_pCurrNode)) == nullptr) + return nullptr ; + + return &( pGdbGroup->m_gfrFrame.m_frF) ; +} + +//---------------------------------------------------------------------------- +bool +GdbIterator::GetGroupGlobFrame( Frame3d& frGlob) +{ + GdbGroup* pGdbGroup ; + + + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return false ; + + if ( ( pGdbGroup = GetGdbGroup( m_pCurrNode)) == nullptr) + return false ; + + return pGdbGroup->GetGlobFrame( frGlob) ; +} + +//---------------------------------------------------------------------------- +int +GdbIterator::GetId( void) +{ + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return - 1 ; + + return m_pCurrNode->m_nId ; +} + +//---------------------------------------------------------------------------- +int +GdbIterator::GetParentId( void) +{ + if ( m_pGDB == nullptr || m_pCurrNode == nullptr) + return - 1 ; + + return m_pCurrNode->GetParentId() ; +} diff --git a/GdbIterator.h b/GdbIterator.h new file mode 100644 index 0000000..d110d34 --- /dev/null +++ b/GdbIterator.h @@ -0,0 +1,42 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GdbIterator.h Data : 04.12.13 Versione : 1.4a3 +// Contenuto : Dichiarazione della classe GdbIterator. +// +// +// +// Modifiche : 04.12.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGdbIterator.h" +#include "GeomDB.h" + +//----------------------------------------------------------------------------- +class GdbIterator : public IGdbIterator +{ + public : + GdbIterator( void) ; + virtual ~GdbIterator( void) ; + virtual bool SetGDB( IGeomDB* pGDB) ; + virtual bool GoTo( int nId) ; + virtual bool GoToFirstInGroup( int nIdGroup) ; + virtual bool GoToNext( void) ; + virtual bool GoToLastInGroup( int nIdGroup) ; + virtual bool GoToPrev( void) ; + + virtual GdbType GetGdbType( void) const ; + virtual IGeoObj* GetGeoObj( void) ; + virtual Frame3d* GetGroupFrame( void) ; + virtual bool GetGroupGlobFrame( Frame3d& frGlob) ; + virtual int GetId( void) ; + virtual int GetParentId( void) ; + + private : + GeomDB* m_pGDB ; + GdbNode* m_pCurrNode ; +} ; diff --git a/GdbNode.cpp b/GdbNode.cpp index 5ab4a5b..85b81d0 100644 --- a/GdbNode.cpp +++ b/GdbNode.cpp @@ -19,7 +19,7 @@ //---------------------------------------------------------------------------- GdbNode::GdbNode( void) { - m_nId = - 1 ; + m_nId = GDB_ID_NULL ; m_pNext = nullptr ; m_pPrev = nullptr ; m_pParent = nullptr ; diff --git a/GdbNode.h b/GdbNode.h index b8d4750..88d5eff 100644 --- a/GdbNode.h +++ b/GdbNode.h @@ -14,19 +14,27 @@ #pragma once #include +#include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGnScan.h" +#include "/EgtDev/Include/EGkPoint3d.h" class GdbGroup ; +class IdManager ; //---------------------------------------------------------------------------- class GdbNode { public : virtual ~GdbNode( void) {} - virtual GdbNode* Clone( int nId) const = 0 ; + virtual GdbNode* Clone( int nId, IdManager& IdMgr) const = 0 ; virtual bool Save( std::ostream& osOut) const = 0 ; virtual bool Load( const std::string& sType, CScan& TheScanner, int& nParentId) = 0 ; + virtual bool Translate( const Vector3d& vtMove) = 0 ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) = 0 ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) = 0 ; + virtual bool Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) = 0 ; + //virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) = 0 ; public : GdbNode( void) ; diff --git a/GdbObj.cpp b/GdbObj.cpp index 38943ad..dfc962f 100644 --- a/GdbObj.cpp +++ b/GdbObj.cpp @@ -36,7 +36,7 @@ GdbObj::~GdbObj( void) //---------------------------------------------------------------------------- GdbObj* -GdbObj::Clone( int nId) const +GdbObj::Clone( int nId, IdManager& IdMgr) const { GdbObj* pGdbObj ; @@ -118,3 +118,33 @@ GdbObj::Load( const std::string& sType, CScan& TheScanner, int& nParentId) // parametri geometrici return m_pGeoObj->Load( TheScanner) ; } + +//---------------------------------------------------------------------------- +bool +GdbObj::Translate( const Vector3d& vtMove) +{ + if ( m_pGeoObj != nullptr) + return m_pGeoObj->Translate( vtMove) ; + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbObj::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) +{ + if ( m_pGeoObj != nullptr) + return m_pGeoObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ; + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +GdbObj::Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) +{ + if ( m_pGeoObj != nullptr) + return m_pGeoObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; + else + return false ; +} diff --git a/GdbObj.h b/GdbObj.h index 95866c5..d086157 100644 --- a/GdbObj.h +++ b/GdbObj.h @@ -23,12 +23,18 @@ class GdbObj : public GdbNode { public : virtual ~GdbObj( void) ; - virtual GdbObj* Clone( int nId) const ; + virtual GdbObj* Clone( int nId, IdManager& IdMgr) const ; virtual bool Save( std::ostream& osOut) const ; virtual bool Load( const std::string& sType, CScan& TheScanner, int& nParentId) ; + virtual bool Translate( const Vector3d& vtMove) ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) + { double dAngRad = dAngDeg * DEGTORAD ; + return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + virtual bool Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) ; public : - GdbObj( void); + GdbObj( void) ; GeoObjType GetType( void) const ; public : diff --git a/GeoFrame3d.cpp b/GeoFrame3d.cpp new file mode 100644 index 0000000..a588902 --- /dev/null +++ b/GeoFrame3d.cpp @@ -0,0 +1,126 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GeoFrame3d.cpp Data : 02.12.13 Versione : 1.4a3 +// Contenuto : Implementazione della classe Riferimento geometrico. +// +// +// +// Modifiche : 10.10.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include +#include "\EgtDev\Include\EGnStringUtils.h" +#include "GeoFrame3d.h" +#include "GeoObjFactory.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +GEOOBJ_REGISTER( GEO_FRAME3D, "G_FRM", GeoFrame3d) ; + +//---------------------------------------------------------------------------- +GeoFrame3d::GeoFrame3d( void) +{ + m_frF.Set( ORIG, Frame3d::TOP) ; +} + +//---------------------------------------------------------------------------- +GeoFrame3d::~GeoFrame3d( void) +{ +} + +//---------------------------------------------------------------------------- +bool +GeoFrame3d::Set( const Point3d& ptOrig, const Vector3d& vtDirX, + const Vector3d& vtDirY, const Vector3d& vtDirZ) +{ + return m_frF.Set( ptOrig, vtDirX, vtDirY, vtDirZ) ; +} + +//---------------------------------------------------------------------------- +bool +GeoFrame3d::Set( const Frame3d& frF) +{ + m_frF = frF ; + + return true ; +} + +//---------------------------------------------------------------------------- +GeoFrame3d* +GeoFrame3d::Clone( void) const +{ + GeoFrame3d* pGFr ; + + + // alloco oggetto + pGFr = new(nothrow) GeoFrame3d ; + if ( pGFr != nullptr) + *pGFr = *(const_cast(this)) ; + + return pGFr ; +} + +//---------------------------------------------------------------------------- +const string& +GeoFrame3d::GetKey( void) const +{ + return GEOOBJ_GETKEY( GeoFrame3d) ; +} + +//---------------------------------------------------------------------------- +bool +GeoFrame3d::Save( ostream& osOut) const +{ + // Origine + osOut << ToString( m_frF.Orig()) << ";" ; + // VersoreX + osOut << ToString( m_frF.VersX()) << ";" ; + // VersoreY + osOut << ToString( m_frF.VersY()) << ";" ; + // VersoreZ + osOut << ToString( m_frF.VersZ()) << ";" << endl ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +GeoFrame3d::Load( CScan& TheScanner) +{ + Point3d ptOrig ; + Vector3d vtDirX ; + Vector3d vtDirY ; + Vector3d vtDirZ ; + string sLine ; + STRVECTOR vsParams ; + + + // leggo la prossima linea + if ( ! TheScanner.GetLine( sLine)) + return false ; + // la divido in parametri + Tokenize( sLine, ";", vsParams) ; + // 4 parametri : origine, versore X, versore Y, versore Z + if ( vsParams.size() != 4) + return false ; + // recupero l'origine + if ( ! FromString( vsParams[0], ptOrig)) + return false ; + // recupero il versore X + if ( ! FromString( vsParams[1], vtDirX)) + return false ; + // recupero il versore Y + if ( ! FromString( vsParams[2], vtDirY)) + return false ; + // recupero il versore Z + if ( ! FromString( vsParams[3], vtDirZ)) + return false ; + // imposto il riferimento + return m_frF.Set( ptOrig, vtDirX, vtDirY, vtDirZ) ; +} diff --git a/GeoFrame3d.h b/GeoFrame3d.h new file mode 100644 index 0000000..d336cc0 --- /dev/null +++ b/GeoFrame3d.h @@ -0,0 +1,63 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GeoFrame3d.h Data : 02.12.13 Versione : 1.4a3 +// Contenuto : Dichiarazione della classe Riferimento Geometrico 3d. +// +// +// +// Modifiche : 02.12.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGeoFrame3d.h" + + +//---------------------------------------------------------------------------- +class GeoFrame3d : public IGeoFrame3d +{ + public : + virtual ~GeoFrame3d( void) ; + virtual GeoFrame3d* Clone( void) const ; + virtual GeoObjType GetType( void) const { return GEO_FRAME3D ; } + virtual const std::string& GetKey( void) const ; + virtual bool IsValid( void) const { return ( m_frF.GetType() != Frame3d::ERR) ; } + virtual bool Save( std::ostream& osOut) const ; + virtual bool Load( CScan& TheScanner) ; + virtual bool GetFrame( Frame3d& frF) const + { frF = m_frF ; return true ;} + virtual bool Translate( const Vector3d& vtMove) + { m_frF.Translate( vtMove) ; return true ; } + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) + { return m_frF.Rotate( ptAx, vtAx, dCosAng, dSinAng) ; } + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) + { return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + virtual bool Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) + { return false ; } + virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) + { return false ; } + virtual bool ToGlob( const Frame3d& frRef) + { return m_frF.ToGlob( frRef) ;} + virtual bool ToLoc( const Frame3d& frRef) + { return m_frF.ToLoc( frRef) ;} + + public : + virtual bool Set( const Point3d& ptOrig, const Vector3d& vtDirX, + const Vector3d& vtDirY, const Vector3d& vtDirZ) ; + virtual bool Set( const Frame3d& frF) ; + virtual const Frame3d& GetFrame( void) const + { return m_frF ; } + + public : + GeoFrame3d( void) ; + inline const GeoFrame3d& operator =( const GeoFrame3d& gvSrc) + { if ( &gvSrc != this) + m_frF = gvSrc.m_frF ; + return *this ; } + + public : + Frame3d m_frF ; +} ; diff --git a/GeoObj.cpp b/GeoObj.cpp index d63c7f0..dd24955 100644 --- a/GeoObj.cpp +++ b/GeoObj.cpp @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------- -// EgalS +// EgalTech 2013-2013 //---------------------------------------------------------------------------- // File : GeoObj.cpp Data : 21.11.13 Versione : 1.3a1 // Contenuto : Implementazione della classe Punto geometrico. diff --git a/GeoPoint3d.cpp b/GeoPoint3d.cpp index a4fd837..b72d424 100644 --- a/GeoPoint3d.cpp +++ b/GeoPoint3d.cpp @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------- -// EgalS +// EgalTech 2013-2013 //---------------------------------------------------------------------------- // File : GeoPoint3d.cpp Data : 10.10.13 Versione : 1.2a3 // Contenuto : Implementazione della classe Punto geometrico. diff --git a/GeoVector3d.cpp b/GeoVector3d.cpp index 70747f9..2a5fa5a 100644 --- a/GeoVector3d.cpp +++ b/GeoVector3d.cpp @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------- -// EgalS +// EgalTech 2013-2013 //---------------------------------------------------------------------------- // File : GeoVector3d.cpp Data : 10.10.13 Versione : 1.2a3 // Contenuto : Implementazione della classe Vettore geometrico. diff --git a/GeomDB.cpp b/GeomDB.cpp index 424f1fa..d68a21d 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -16,7 +16,7 @@ #include #include #include "/EgtDev/Include/EgnStringUtils.h" -#include "/EgtDev/Include/EgtReleasePointer.h" +#include "/EgtDev/Include/EgtPointerOwner.h" #include "GdbObj.h" #include "GeomDB.h" @@ -34,7 +34,7 @@ CreateGeomDB( void) //---------------------------------------------------------------------------- GeomDB::GeomDB( void) { - m_GrpRadix.m_nId = 0 ; + m_GrpRadix.m_nId = GDB_ID_ROOT ; } //---------------------------------------------------------------------------- @@ -233,7 +233,7 @@ GeomDB::AddToGeomDB( GdbNode* pGNode, int nParentId) return false ; // verifica validità e unicità del nome - if ( pGNode->m_nId <= 0 || ExistsNode( pGNode->m_nId)) + if ( pGNode->m_nId <= GDB_ID_ROOT || ExistsNode( pGNode->m_nId)) return false ; // cerco il padre @@ -244,82 +244,99 @@ GeomDB::AddToGeomDB( GdbNode* pGNode, int nParentId) if ( ! pGNode->AddTail( pGroup)) return false ; + // aggiorno gestore Id + m_IdManager.UpdateMaxId( pGNode->m_nId) ; + // inserisco in mappa nomi return m_GdbIdMap.insert( pair< int, GdbNode*>( pGNode->m_nId, pGNode)).second ; } //---------------------------------------------------------------------------- -bool -GeomDB::AddGroup( int nId, int nParentId) +int +GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame) { GdbGroup* pGdbGroup ; - // verifico validità Id e ParentId - if ( nId <= 0 || nParentId < 0) - return false ; + // verifico validità ParentId + if ( nParentId < GDB_ID_ROOT) + return GDB_ID_NULL ; + // verifico validità Id + if ( nId <= GDB_ID_ROOT) + nId = m_IdManager.GetNewId() ; + if ( ExistsNode( nId)) + return GDB_ID_NULL ; // alloco gruppo Gdb pGdbGroup = new(nothrow) GdbGroup ; if ( pGdbGroup == nullptr) - return false ; + return GDB_ID_NULL ; // assegno identificativo pGdbGroup->m_nId = nId ; - // assegno dati - // TODO ... + // assegno riferimento + pGdbGroup->m_gfrFrame.m_frF = frFrame ; // inserisco nel DB if ( ! AddToGeomDB( pGdbGroup, nParentId)) { delete pGdbGroup ; - return false ; + return GDB_ID_NULL ; } - return true ; + return nId ; } //---------------------------------------------------------------------------- -bool +int GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) { GdbObj* pGdbObj ; // assegno GeoObj a gestore puntatore con rilascio automatico - ReleasePtr pRPGeoObj( pGeoObj) ; + PtrOwner pRPGeoObj( pGeoObj) ; // verifico validità identificativo - if ( nId <= 0) - return false ; + if ( nId <= GDB_ID_ROOT) + nId = m_IdManager.GetNewId() ; + if ( ExistsNode( nId)) + return GDB_ID_NULL ; // verifico validità oggetto Geo if ( ! IsValid( pRPGeoObj) || ! pRPGeoObj->IsValid()) - return false ; + return GDB_ID_NULL ; // alloco oggetto Gdb pGdbObj = new(nothrow) GdbObj ; if ( pGdbObj == nullptr) - return false ; + return GDB_ID_NULL ; // assegno identificativo pGdbObj->m_nId = nId ; - // assegno dati ( ma non ne trasferisco il possesso) - pGdbObj->m_pGeoObj = Get( pRPGeoObj) ; + // assegno dati + pGdbObj->m_pGeoObj = Release( pRPGeoObj) ; // inserisco nel DB if ( ! AddToGeomDB( pGdbObj, nParentId)) { delete pGdbObj ; - return false ; + return GDB_ID_NULL ; } - // rilascio il possesso di GeoObj - Release( pRPGeoObj) ; - return true ; + + return nId ; } //---------------------------------------------------------------------------- -GeoObjType -GeomDB::GetObjType( int nId) const +GdbType +GeomDB::GetGdbType( int nId) const { - const GdbObj* pGdbObj ; + const GdbNode* pGdbNode ; - // recupero l'oggetto - if ( ( pGdbObj = (const_cast(this))->GetGdbObj( nId)) == nullptr) - return GEO_NONE ; - // ne identifico il tipo - return pGdbObj->GetType() ; + // recupero il nodo + if ( ( pGdbNode = (const_cast (this))->GetGdbNode( nId)) == nullptr) + return GDB_NONE ; + + // se oggetto geometrico + if ( ::GetGdbObj( pGdbNode) != nullptr) + return GDB_GEO ; + // se gruppo + else if ( ::GetGdbGroup( pGdbNode) != nullptr) + return GDB_GROUP ; + // altro + else + return GDB_NONE ; } //---------------------------------------------------------------------------- @@ -337,33 +354,80 @@ GeomDB::GetGeoObj( int nId) return pGdbObj->m_pGeoObj ; } +//---------------------------------------------------------------------------- +Frame3d* +GeomDB::GetGroupFrame( int nId) +{ + GdbGroup* pGdbGroup ; + + + // recupero il gruppo Gdb + if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr) + return nullptr ; + + // restituisco il suo riferimento + return &(pGdbGroup->m_gfrFrame.m_frF) ; +} + //---------------------------------------------------------------------------- bool +GeomDB::GetGroupGlobFrame( int nId, Frame3d& frGlob) +{ + GdbGroup* pGdbGroup ; + + + // recupero il gruppo Gdb + if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr) + return false ; + + // ne faccio calcolare il riferimento globale + return pGdbGroup->GetGlobFrame( frGlob) ; +} + +//---------------------------------------------------------------------------- +int +GeomDB::GetParentId( int nId) +{ + GdbNode* pGdbNode ; + + + // recupero il nodo Gdb + if ( ( pGdbNode = GetGdbNode( nId)) == nullptr) + return GDB_ID_NULL ; + + // restituisco l'Id del padre + return pGdbNode->GetParentId() ; +} + +//---------------------------------------------------------------------------- +int GeomDB::Copy( int nIdSou, int nIdDest, int nParentIdDest) { GdbNode* pGdNSou ; GdbNode* pGdNDest ; - // verifico validità Id destinazione - if ( nIdDest <= 0 || ExistsNode( nIdDest)) - return false ; + // verifico Id destinazione + if ( nIdDest <= GDB_ID_ROOT) + nIdDest = m_IdManager.GetNewId() ; + if ( ExistsNode( nIdDest)) + return GDB_ID_NULL ; // verifico esistenza del sorgente if ( ( pGdNSou = GetGdbNode( nIdSou)) == nullptr) - return false ; + return GDB_ID_NULL ; // eseguo la copia - if ( ( pGdNDest = pGdNSou->Clone( nIdDest)) == nullptr) - return false ; + if ( ( pGdNDest = pGdNSou->Clone( nIdDest, m_IdManager)) == nullptr) + return GDB_ID_NULL ; // inserisco nel DB if ( ! AddToGeomDB( pGdNDest, nParentIdDest)) { delete pGdNDest ; - return false ; + return GDB_ID_NULL ; } - return true ; + return nIdDest ; } //---------------------------------------------------------------------------- @@ -396,54 +460,45 @@ GeomDB::Erase( int nId) bool GeomDB::Translate( int nId, const Vector3d& vtMove) { - GdbObj* pGdbObj ; + GdbNode* pGdbNode ; // recupero l'oggetto - if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) + if ( ( pGdbNode = GetGdbNode( nId)) == nullptr) return false ; - // eseguo l'operazione - if ( pGdbObj->m_pGeoObj != nullptr) - return pGdbObj->m_pGeoObj->Translate( vtMove) ; - else - return false ; + // eseguo la traslazione + return pGdbNode->Translate( vtMove) ; } //---------------------------------------------------------------------------- bool GeomDB::Rotate( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) { - GdbObj* pGdbObj ; + GdbNode* pGdbNode ; // recupero l'oggetto - if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) + if ( ( pGdbNode = GetGdbNode( nId)) == nullptr) return false ; - // eseguo l'operazione - if ( pGdbObj->m_pGeoObj != nullptr) - return pGdbObj->m_pGeoObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ; - else - return false ; + // eseguo la rotazione + return pGdbNode->Rotate( ptAx, vtAx, dCosAng, dSinAng) ; } //---------------------------------------------------------------------------- bool GeomDB::Scale( int nId, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) { - GdbObj* pGdbObj ; + GdbNode* pGdbNode ; // recupero l'oggetto - if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) + if ( ( pGdbNode = GetGdbNode( nId)) == nullptr) return false ; - // eseguo l'operazione - if ( pGdbObj->m_pGeoObj != nullptr) - return pGdbObj->m_pGeoObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; - else - return false ; + // eseguo la scalatura + return pGdbNode->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ; } //---------------------------------------------------------------------------- diff --git a/GeomDB.h b/GeomDB.h index 7592a1f..e02b494 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------- -// EgalS +// EgalTech 2013-2013 //---------------------------------------------------------------------------- // File : GeomDB.h Data : 08.04.13 Versione : 1.1c1 // Contenuto : Dichiarazione della classe GeomDB. @@ -18,6 +18,7 @@ #include "/EgtDev/Include/EGkGeomDB.h" #include "GdbObj.h" #include "GdbGroup.h" +#include "IdManager.h" //---------------------------------------------------------------------------- typedef std::unordered_map< int, GdbNode*> INTPGDBN_UMAP ; @@ -28,6 +29,8 @@ class CScan ; //---------------------------------------------------------------------------- class GeomDB : public IGeomDB { + friend class GdbIterator ; + public : virtual ~GeomDB( void) ; virtual bool Init( void) ; @@ -35,11 +38,14 @@ class GeomDB : public IGeomDB virtual bool Load( std::ifstream& osIn) ; virtual bool Save( std::ofstream& osOut) const ; virtual bool ExistsNode( int nId) const ; - virtual bool AddGroup( int nId, int nParentId) ; - virtual bool AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) ; - virtual GeoObjType GetObjType( int nId) const ; + virtual int AddGroup( int nId, int nParentId, const Frame3d& frFrame) ; + virtual int AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) ; + virtual GdbType GetGdbType( int nId) const ; virtual IGeoObj* GetGeoObj( int nId) ; - virtual bool Copy( int nIdSou, int nIdDest, int nParentIdDest) ; + virtual Frame3d* GetGroupFrame( int nId) ; + virtual bool GetGroupGlobFrame( int nId, Frame3d& frGlob) ; + virtual int GetParentId( int nId) ; + virtual int Copy( int nIdSou, int nIdDest, int nParentIdDest) ; virtual bool Erase( int nId) ; virtual bool Translate( int nId, const Vector3d& vtMove) ; virtual bool Rotate( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ; @@ -63,4 +69,15 @@ class GeomDB : public IGeomDB private : GdbGroup m_GrpRadix ; // gruppo radice di tutto il DB INTPGDBN_UMAP m_GdbIdMap ; // map basato sugli identificatori + IdManager m_IdManager ; // gestore del nuovo Id } ; + +//---------------------------------------------------------------------------- +inline const GdbObj* GetGdbObj( const GdbNode* pGNode) + { return dynamic_cast(pGNode) ; } +inline GdbObj* GetGdbObj( GdbNode* pGNode) + { return dynamic_cast(pGNode) ; } +inline const GdbGroup* GetGdbGroup( const GdbNode* pGNode) + { return dynamic_cast(pGNode) ; } +inline GdbGroup* GetGdbGroup( GdbNode* pGNode) + { return dynamic_cast(pGNode) ; } diff --git a/IdManager.h b/IdManager.h new file mode 100644 index 0000000..d99d978 --- /dev/null +++ b/IdManager.h @@ -0,0 +1,28 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : IdManager.h Data : 02.12.13 Versione : 1.4a3 +// Contenuto : Dichiarazione e implementazione della classe IdManager. +// +// +// +// Modifiche : 02.12.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +//---------------------------------------------------------------------------- +class IdManager +{ + public : + IdManager( void) { m_nMaxId = 0 ; } + int GetNewId( void) { return ++ m_nMaxId ; } + int GetMaxId( void) const { return m_nMaxId ; } + void UpdateMaxId( int nId) { if ( nId > m_nMaxId) m_nMaxId = nId ; } + + private : + int m_nMaxId ; +} ; diff --git a/OutScl.cpp b/OutScl.cpp index e65da0d..6b280b1 100644 --- a/OutScl.cpp +++ b/OutScl.cpp @@ -173,6 +173,36 @@ OutScl::SetPartLay( string sPart, string sLay) return true ; } +//---------------------------------------------------------------------------- +bool +OutScl::SetPartLayRef( string sPart, string sLay, const Frame3d& frFrame) +{ + double dAngC ; + double dAngA ; + double dAngC1 ; + + + // verifico sia aperto + if ( ! m_ofFile.is_open()) + return false ; + + m_sPartLay = sPart + "\\" + sLay ; + + // calcolo angoli di rotazione del frame + frFrame.GetRotationsCAC1( dAngC, dAngA, dAngC1) ; + + // emetto comando di creazione pezzo + m_ofFile << "CreatePart( \"" << sPart << "\") ;" << endl ; + // emetto comando di creazione layer + m_ofFile << "CreateLayer( \"" << sLay << "\", \"" << sPart << "\") ;" << endl ; + // emetto comando di modifica riferimento + m_ofFile << "ModifyLayerRef( \"" << sLay << "\", \"" << sPart << "\"," ; + m_ofFile << "30,0," << ToString( frFrame.Orig()) << "," ; + m_ofFile << ToString( dAngC) << "," << ToString( dAngA) << "," << ToString( dAngC1) << ") ;" << endl ; + + return true ; +} + //---------------------------------------------------------------------------- bool OutScl::Line2P( Point3d ptP1, Point3d ptP2) @@ -231,6 +261,30 @@ OutScl::ArcCPA( Point3d ptCen, Point3d ptMed, double dAngCenDeg) return true ; } +//---------------------------------------------------------------------------- +bool +OutScl::PutCurve( const IGeoObj* pCurve, bool bCrvVsPoly) +{ + if ( pCurve == nullptr) + return false ; + + switch ( pCurve->GetType()) { + case CRV_LINE : + return PutCurveLine( *GetCurveLine( pCurve)) ; + case CRV_ARC : + return PutCurveArc( *GetCurveArc( pCurve)) ; + case CRV_BEZ : + if ( bCrvVsPoly) + return PutCurveBez( *GetCurveBezier( pCurve)) ; + else + return PutPolygBez( *GetCurveBezier( pCurve)) ; + case CRV_COMPO : + return PutCurveCompo( *GetCurveComposite( pCurve)) ; + } + + return false ; +} + //---------------------------------------------------------------------------- bool OutScl::PutCurveLine( const ICurveLine& CrvLine) diff --git a/OutScl.h b/OutScl.h index e4fc558..fe15fbf 100644 --- a/OutScl.h +++ b/OutScl.h @@ -33,6 +33,8 @@ class OutScl bool Remark( std::string sRemark) ; bool SetMaterial( double dRed, double dGreen, double dBlue) ; bool SetPartLay( std::string sPart, std::string sLay) ; + bool SetPartLayRef( std::string sPart, std::string sLay, const Frame3d& frFrame) ; + bool PutCurve( const IGeoObj* pCurve, bool bCrvVsPoly) ; bool PutCurveLine( const ICurveLine& CrvLine) ; bool PutCurveArc( const ICurveArc& CrvArc) ; bool PutCurveBez( const ICurveBezier& CrvBez) ; diff --git a/Vector3d.cpp b/Vector3d.cpp index 4b3fc3d..6fd5661 100644 --- a/Vector3d.cpp +++ b/Vector3d.cpp @@ -266,3 +266,49 @@ Vector3d::ToLoc( const Frame3d& frRef) return true ; } + +//---------------------------------------------------------------------------- +// Calcolo angolo di rotazione per portare la componente perpendicolare del +// vettore sulla stessa direzione della componente perpendicolare di vtEnd +//---------------------------------------------------------------------------- +bool +Vector3d::GetRotation( const Vector3d& vtEnd, const Vector3d& vtAx, double& dAngDeg, bool& bDet) +{ + double dKcosA ; + double dKsinA ; + Vector3d vtDirAx ; + Vector3d vtPerp ; + Vector3d vtPerpE ; + Vector3d vtPerp2 ; + + + // ricavo versore asse di rotazione + vtDirAx = vtAx ; + if ( ! vtDirAx.Normalize()) + return false ; + + // ricavo le componenti perpendicolari all'asse di rotazione + vtPerp = *this - vtDirAx * ( *this * vtDirAx) ; + vtPerpE = vtEnd - vtDirAx * ( vtEnd * vtDirAx) ; + // se sono entrambe non nulle : angolo determinato + if ( ! vtPerp.IsZero() && ! vtPerpE.IsZero()) { + // secondo vettore perpendicolare ad asse e a componente perpendicolare + vtPerp2 = vtDirAx ^ vtPerp ; + // proporzionali a seno e coseno del perpendicolare E + dKcosA = vtPerpE * vtPerp ; + dKsinA = vtPerpE * vtPerp2 ; + // angolo di rotazione + dAngDeg = atan2( dKsinA, dKcosA) * RADTODEG ; + bDet = true ; + return true ; + } + // se comunque sono entrambe molto piccole : angolo indeterminato + else if ( vtPerp.IsSmall() && vtPerpE.IsSmall()) { + dAngDeg = 0 ; + bDet = false ; + return true ; + } + // altrimenti angolo impossibile + else + return false ; +}