From 2cbdfc1db9d89bc19f2505e6b5e0bca628007554 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 15 Apr 2014 06:48:39 +0000 Subject: [PATCH] EgtGeomKernel : - cambiato Load, con uso di NgeReader. --- Attribs.cpp | 49 ++++---- Attribs.h | 4 +- CurveArc.cpp | 26 ++--- CurveArc.h | 8 +- CurveBezier.cpp | 40 +++---- CurveBezier.h | 8 +- CurveComposite.cpp | 30 ++--- CurveComposite.h | 8 +- CurveLine.cpp | 18 +-- CurveLine.h | 8 +- EgtGeomKernel.vcxproj | 2 + EgtGeomKernel.vcxproj.filters | 6 + GdbGeo.cpp | 38 +++---- GdbGeo.h | 2 +- GdbGroup.cpp | 37 +++--- GdbGroup.h | 2 +- GdbObj.cpp | 4 +- GdbObj.h | 6 +- GeoFrame3d.cpp | 11 +- GeoFrame3d.h | 8 +- GeoObjRW.h | 5 +- GeoPoint3d.cpp | 14 +-- GeoPoint3d.h | 8 +- GeoVector3d.cpp | 14 +-- GeoVector3d.h | 8 +- GeomDB.cpp | 111 +++++++----------- GeomDB.h | 4 +- NgeReader.cpp | 206 ++++++++++++++++++++++++++++++++++ NgeReader.h | 53 +++++++++ NgeWriter.cpp | 10 +- NgeWriter.h | 4 +- SurfTriMesh.cpp | 62 ++++------ SurfTriMesh.h | 8 +- 33 files changed, 492 insertions(+), 330 deletions(-) create mode 100644 NgeReader.cpp create mode 100644 NgeReader.h diff --git a/Attribs.cpp b/Attribs.cpp index 2fccf77..d584039 100644 --- a/Attribs.cpp +++ b/Attribs.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "Attribs.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -85,7 +86,7 @@ bool Attribs::Save( NgeWriter& ngeOut) const { // flag presenza attributi - ngeOut.WriteKey( NGE_A, true) ; + ngeOut.WriteKey( NGE_A) ; // livello ngeOut.WriteUchar( m_Data[LEVEL], ",") ; // modo @@ -111,45 +112,47 @@ Attribs::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -Attribs::Load( Scanner& TheScanner) +Attribs::Load( NgeReader& ngeIn) { - // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) + // livello + unsigned char ucLev ; + if ( ! ngeIn.ReadUchar( ucLev, ",")) return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ";", vsParams) ; - // 4 parametri - if ( vsParams.size() != 4) + m_Data[LEVEL] = CLIP( ucLev, GDB_LV_USER, GDB_LV_TEMP) ; + // modo + unsigned char ucMode ; + if ( ! ngeIn.ReadUchar( ucMode, ",")) return false ; - // Data (Level,Mode,Status,Other) - if ( ! DataFromString( vsParams[0])) + m_Data[MODE] = CLIP( ucMode, GDB_MD_STD, GDB_MD_HIDDEN) ; + // stato (se SEL è convertito in ON) + unsigned char ucStat ; + if ( ! ngeIn.ReadUchar( ucStat, ",")) return false ; - // OldData è inizializzato con Data - for ( int i = 0 ; i < DIM ; ++ i) - m_OldData[i] = m_Data[i] ; + m_Data[STATUS] = CLIP( ucStat, GDB_ST_OFF, GDB_ST_ON) ; + // marcatura (sempre OFF) + unsigned char ucMark ; + if ( ! ngeIn.ReadUchar( ucMark, ";")) + return false ; + m_Data[MARK] = CLIP( ucMark, GDB_MK_OFF, GDB_MK_OFF) ; // materiale - int nMat ; - if ( ! FromString( vsParams[1], nMat)) + if ( ! ngeIn.ReadInt( m_Material, ";")) return false ; - m_Material = __max( nMat, GDB_MT_COLOR) ; // colore - if ( ! FromString( vsParams[2], m_Color)) + if ( ! ngeIn.ReadCol( m_Color, ";")) return false ; - // numero di stringhe (nelle linee successive) + // numero di stringhe di info (nelle linee successive) int nNext ; - if ( ! FromString( vsParams[3], nNext)) + if ( ! ngeIn.ReadInt( nNext, ";", true)) return false ; // leggo le eventuali stringhe + string sLine ; for ( int i = 0 ; i < nNext ; ++i) { // leggo la linea - if ( ! TheScanner.GetLine( sLine)) + if ( ! ngeIn.ReadString( sLine, nullptr, true)) return false ; // la carico in lista m_slInfo.push_back( sLine) ; } - return true ; } diff --git a/Attribs.h b/Attribs.h index 0a8a360..28594cd 100644 --- a/Attribs.h +++ b/Attribs.h @@ -15,10 +15,10 @@ #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkColor.h" -#include "/EgtDev/Include/EGnScan.h" #include "/EgtDev/Include/EGnStringBase.h" class NgeWriter ; +class NgeReader ; //---------------------------------------------------------------------------- #define CLIP( nV, nMIN, nMAX) (( nV < nMIN) ? nMIN : (( nV > nMAX) ? nMAX : nV)) @@ -42,7 +42,7 @@ class Attribs return pAttribs ; } bool Dump( std::string& sOut, const char* szNewLine) const ; bool Save( NgeWriter& ngeOut) const ; - bool Load( Scanner& TheScanner) ; + bool Load( NgeReader& ngeIn) ; void SetLevel( int nLev) { m_OldData[LEVEL] = m_Data[LEVEL] ; m_Data[LEVEL] = CLIP( nLev, GDB_LV_USER, GDB_LV_TEMP) ; } diff --git a/CurveArc.cpp b/CurveArc.cpp index f5bc734..4aa77c4 100644 --- a/CurveArc.cpp +++ b/CurveArc.cpp @@ -17,6 +17,7 @@ #include "GeoConst.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include @@ -223,37 +224,28 @@ CurveArc::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -CurveArc::Load( Scanner& TheScanner) +CurveArc::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; - // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ";", vsParams) ; - // 6 parametri : centro, versore normale, raggio, versore iniziale, angolo al centro e delta Z - if ( vsParams.size() != 6) - return false ; + // leggo la prossima linea ( 6 parametri) // recupero il centro - if ( ! FromString( vsParams[0], m_PtCen)) + if ( ! ngeIn.ReadPoint( m_PtCen, ";")) return false ; // recupero il versore normale - if ( ! FromString( vsParams[1], m_VtN)) + if ( ! ngeIn.ReadVector( m_VtN, ";")) return false ; // recupero il raggio - if ( ! FromString( vsParams[2], m_dRad)) + if ( ! ngeIn.ReadDouble( m_dRad, ";")) return false ; // recupero il versore iniziale - if ( ! FromString( vsParams[3], m_VtS)) + if ( ! ngeIn.ReadVector( m_VtS, ";")) return false ; // recupero l'angolo al centro - if ( ! FromString( vsParams[4], m_dAngCenDeg)) + if ( ! ngeIn.ReadDouble( m_dAngCenDeg, ";")) return false ; // recupero il delta N - if ( ! FromString( vsParams[5], m_dDeltaN)) + if ( ! ngeIn.ReadDouble( m_dDeltaN, ";", true)) return false ; // eseguo validazione return Validate() ; diff --git a/CurveArc.h b/CurveArc.h index 17d46ea..a0b0736 100644 --- a/CurveArc.h +++ b/CurveArc.h @@ -30,9 +30,6 @@ class CurveArc : public ICurveArc, public IGeoObjRW { return ( m_nStatus == OK) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool Translate( const Vector3d& vtMove) ; @@ -100,6 +97,11 @@ class CurveArc : public ICurveArc, public IGeoObjRW virtual double GetDeltaN( void) const { return m_dDeltaN ; } + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : CurveArc( void) ; const CurveArc& operator =( const CurveArc& caSrc) diff --git a/CurveBezier.cpp b/CurveBezier.cpp index 7840128..67b2368 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -18,6 +18,7 @@ #include "DistPointLine.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "PolynomialPoint3d.h" #include "/EgtDev/Include/EGkCurveArc.h" #include "/EgtDev/Include/ENkPolynomial.h" @@ -366,27 +367,18 @@ CurveBezier::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -CurveBezier::Load( Scanner& TheScanner) +CurveBezier::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; - // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ";", vsParams) ; - // 2 parametri : flag razionale e grado - if ( vsParams.size() != 2) - return false ; - // recupero il flag + // leggo la prossima linea ( 2 parametri) + // recupero il flag razionale bool bIsRat ; - if ( ! FromString( vsParams[0], bIsRat)) + if ( ! ngeIn.ReadBool( bIsRat, ";")) return false ; // recupero il grado int nDeg ; - if ( ! FromString( vsParams[1], nDeg)) + if ( ! ngeIn.ReadInt( nDeg, ";", true)) return false ; // inizializzo la curva di Bezier if ( ! Init( nDeg, bIsRat)) @@ -397,13 +389,11 @@ CurveBezier::Load( Scanner& TheScanner) string sLine ; Point3d ptP ; for ( int i = 0 ; i <= nDeg ; ++ i) { - // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + // leggo la prossima linea ( un punto) + if ( ! ngeIn.ReadPoint( ptP, ";", true)) return false ; - TrimRight( sLine, ";") ; - // la interpreto - if ( ! FromString( sLine, ptP) || - ! SetControlPoint( i, ptP)) + // lo assegno + if ( ! SetControlPoint( i, ptP)) return false ; } } @@ -414,13 +404,11 @@ CurveBezier::Load( Scanner& TheScanner) Point3d ptP ; double dW ; for ( int i = 0 ; i <= nDeg ; ++ i) { - // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + // leggo la prossima linea ( un punto con peso) + if ( ! ngeIn.ReadPointW( ptP, dW, ";", true)) return false ; - TrimRight( sLine, ";") ; - // la interpreto - if ( ! FromString( sLine, ptP, dW) || - ! SetControlPoint( i, ptP, dW)) + // lo assegno + if ( ! SetControlPoint( i, ptP, dW)) return false ; } } diff --git a/CurveBezier.h b/CurveBezier.h index 4473cf6..6815178 100644 --- a/CurveBezier.h +++ b/CurveBezier.h @@ -32,9 +32,6 @@ class CurveBezier : public ICurveBezier, public IGeoObjRW { return ( m_nStatus == OK) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool Translate( const Vector3d& vtMove) ; @@ -92,6 +89,11 @@ class CurveBezier : public ICurveBezier, public IGeoObjRW virtual bool GetControlPolygonLength( double& dLen) const ; virtual int GetSingularParam( double& dPar) const ; + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : CurveBezier( void) ; const CurveBezier& operator =( const CurveBezier& cbSrc) diff --git a/CurveComposite.cpp b/CurveComposite.cpp index c2eb8eb..75b3195 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -17,6 +17,7 @@ #include "GeoConst.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EgtPointerOwner.h" #include "/EgtDev/Include/EGkCurveArc.h" @@ -290,12 +291,12 @@ CurveComposite::Save( NgeWriter& ngeOut) const int i = 0 ; const ICurve* pCrvSmpl = GetFirstCurve() ; while ( pCrvSmpl != nullptr) { - // recupero il gestore di lettura/scrittura dell'entità + // recupero il gestore di lettura/scrittura delle curve const IGeoObjRW* pCSmplRW = dynamic_cast( pCrvSmpl) ; if ( pCSmplRW == nullptr) return false ; // emetto tipo della curva semplice - ngeOut.WriteKey( pCSmplRW->GetNgeId(), true) ; + ngeOut.WriteKey( pCSmplRW->GetNgeId()) ; // assegno ed emetto nome della curva semplice string sCrvName = "#" + ToString( ++i) ; ngeOut.WriteString( sCrvName, nullptr, true) ; @@ -311,39 +312,32 @@ CurveComposite::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -CurveComposite::Load( Scanner& TheScanner) +CurveComposite::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; - // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ",", vsParams) ; - // 1 parametro : numero di curve componenti - if ( vsParams.size() != 1) - return false ; + // leggo la prossima linea ( 1 parametro) // recupero il numero di curve componenti int nCounter ; - if ( ! FromString( vsParams[0], nCounter)) + if ( ! ngeIn.ReadInt( nCounter, nullptr, true)) return false ; // leggo le curve componenti for ( int i = 0 ; i < nCounter ; ++ i) { // recupero la prossima linea (con il tipo di oggetto) - if ( ! TheScanner.GetLine( sLine)) + int nNgeId ; + if ( ! ngeIn.ReadKey( nNgeId)) return false ; // creo l'oggetto - int nType = GEOOBJ_KEYTOTYPE( sLine) ; + int nType = GEOOBJ_NGEIDTOTYPE( nNgeId) ; IGeoObj* pGeoO = GEOOBJ_CREATE( nType) ; if ( pGeoO == nullptr) return false ; // recupero la linea con il nome - bool bOk = TheScanner.GetLine( sLine) ; + string sName ; + bool bOk = ngeIn.ReadString( sName, nullptr, true) ; // ne leggo i dati IGeoObjRW* pGObjRW = dynamic_cast( pGeoO) ; - bOk = bOk && ( pGObjRW != nullptr && pGObjRW->Load( TheScanner)) ; + bOk = bOk && ( pGObjRW != nullptr && pGObjRW->Load( ngeIn)) ; // verifico sia una curva ICurve* pCrv = ::GetCurve( pGeoO) ; bOk = bOk && ( pCrv != nullptr && pCrv->IsSimple()) ; diff --git a/CurveComposite.h b/CurveComposite.h index 9ab9c96..3931b94 100644 --- a/CurveComposite.h +++ b/CurveComposite.h @@ -32,9 +32,6 @@ class CurveComposite : public ICurveComposite, public IGeoObjRW { return ( m_nStatus == OK) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool Translate( const Vector3d& vtMove) ; @@ -85,6 +82,11 @@ class CurveComposite : public ICurveComposite, public IGeoObjRW virtual bool IsParamAtJoint( double dU) const ; virtual bool ArcsToBezierCurves( void) ; + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : CurveComposite( void) ; const CurveComposite& operator =( const CurveComposite& ccSrc) diff --git a/CurveLine.cpp b/CurveLine.cpp index 5a37042..bd9e0a0 100644 --- a/CurveLine.cpp +++ b/CurveLine.cpp @@ -16,6 +16,7 @@ #include "CurveLine.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include @@ -131,25 +132,14 @@ CurveLine::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -CurveLine::Load( Scanner& TheScanner) +CurveLine::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) + if ( ! ngeIn.ReadPoint( m_PtStart, ";")) return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ";", vsParams) ; - // 2 parametri : punto iniziale e punto finale - if ( vsParams.size() != 2) - return false ; - // recupero il punto iniziale - if ( ! FromString( vsParams[0], m_PtStart)) - return false ; - // recupero il punto finale - if ( ! FromString( vsParams[1], m_PtEnd)) + if ( ! ngeIn.ReadPoint( m_PtEnd, ";", true)) return false ; // eseguo validazione return Validate() ; diff --git a/CurveLine.h b/CurveLine.h index 6159e52..a7dd988 100644 --- a/CurveLine.h +++ b/CurveLine.h @@ -30,9 +30,6 @@ class CurveLine : public ICurveLine, public IGeoObjRW { return ( m_nStatus == OK) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool Translate( const Vector3d& vtMove) ; @@ -82,6 +79,11 @@ class CurveLine : public ICurveLine, public IGeoObjRW virtual const Point3d& GetEnd( void) const { return m_PtEnd ; } + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : CurveLine( void) ; const CurveLine& operator =( const CurveLine& clSrc) diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 2b66eb3..a1807ec 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -252,6 +252,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -336,6 +337,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 559893f..a6088ce 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -144,6 +144,9 @@ File di origine\Gdb + + File di origine\Gdb + @@ -374,6 +377,9 @@ File di intestazione + + File di intestazione + diff --git a/GdbGeo.cpp b/GdbGeo.cpp index ae33e13..b10336c 100644 --- a/GdbGeo.cpp +++ b/GdbGeo.cpp @@ -18,6 +18,7 @@ #include "CurveAux.h" #include "Attribs.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "GeoObjRW.h" #include "/EgtDev/Include/EGkGdbFunct.h" #include "/EgtDev/Include/EGnStringUtils.h" @@ -85,13 +86,13 @@ GdbGeo::GetType( void) const bool GdbGeo::Save( NgeWriter& ngeOut) const { - // recupero il gestore di lettura/scrittura dell'entità + // recupero il gestore di lettura/scrittura dell'oggetto IGeoObjRW* pGObjRW = dynamic_cast( m_pGeoObj) ; if ( pGObjRW == nullptr) return false ; // tipo entità e identificativi - ngeOut.WriteKey( pGObjRW->GetNgeId(), true) ; + ngeOut.WriteKey( pGObjRW->GetNgeId()) ; ngeOut.WriteInt( m_nId, "@") ; ngeOut.WriteInt( GetParentId(), nullptr, true) ; @@ -100,60 +101,51 @@ GdbGeo::Save( NgeWriter& ngeOut) const return false ; // parametri geometrici - ngeOut.WriteKey( NGE_G, true) ; + ngeOut.WriteKey( NGE_G) ; return pGObjRW->Save( ngeOut) ; } //---------------------------------------------------------------------------- bool -GdbGeo::Load( const std::string& sType, Scanner& TheScanner, int& nParentId) +GdbGeo::Load( int nNgeId, NgeReader& ngeIn, int& nParentId) { - int nType ; string sLine ; STRVECTOR vsParams ; // creo l'oggetto geometrico corrispondente - nType = GEOOBJ_KEYTOTYPE( sType) ; + int nType = GEOOBJ_NGEIDTOTYPE( nNgeId) ; m_pGeoObj = GEOOBJ_CREATE( nType) ; if ( m_pGeoObj == nullptr) return false ; // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + if ( ! ngeIn.ReadInt( m_nId, "@")) return false ; - // la divido in parametri - Tokenize( sLine, "@", vsParams) ; - // 2 parametri : Id e ParentId - if ( vsParams.size() != 2) - return false ; - // assegno l'identificativo - if ( ! FromString( vsParams[0], m_nId)) - return false ; - // assegno l'Id del padre - if ( ! FromString( vsParams[1], nParentId)) + if ( ! ngeIn.ReadInt( nParentId, nullptr, true)) return false ; // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + int nKey ; + if ( ! ngeIn.ReadKey( nKey)) return false ; // eventuali attributi - if ( sLine == "A") { - if ( ! GdbObj::LoadAttribs( TheScanner)) + if ( nKey == NGE_A) { + if ( ! GdbObj::LoadAttribs( ngeIn)) return false ; // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + if ( ! ngeIn.ReadKey( nKey)) return false ; } // verifico inizio dati geometrici - if ( sLine != "G") + if ( nKey != NGE_G) return false ; // parametri geometrici IGeoObjRW* pGObjRW = dynamic_cast( m_pGeoObj) ; - return ( pGObjRW != nullptr && pGObjRW->Load( TheScanner)) ; + return ( pGObjRW != nullptr && pGObjRW->Load( ngeIn)) ; } //---------------------------------------------------------------------------- diff --git a/GdbGeo.h b/GdbGeo.h index 644a0e6..6ff6e8b 100644 --- a/GdbGeo.h +++ b/GdbGeo.h @@ -26,7 +26,7 @@ class GdbGeo : public GdbObj virtual ~GdbGeo( void) ; virtual GdbGeo* Clone( int nId, IdManager& IdMgr) const ; virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( const std::string& sType, Scanner& TheScanner, int& nParentId) ; + virtual bool Load( int nNgeId, NgeReader& ngeIn, int& nParentId) ; virtual bool GetLocalBBox( BBox3d& b3Loc, int nFlag, int nLev = 0) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag, int nLev = 0) const ; virtual bool Translate( const Vector3d& vtMove) ; diff --git a/GdbGroup.cpp b/GdbGroup.cpp index 796a023..c0c2108 100644 --- a/GdbGroup.cpp +++ b/GdbGroup.cpp @@ -16,6 +16,7 @@ #include "GdbGroup.h" #include "IdManager.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGkGdbFunct.h" #include "/EgtDev/Include/EGnStringUtils.h" @@ -107,7 +108,7 @@ GdbGroup::Save( NgeWriter& ngeOut) const bool bOk = true ; // tipo entità e identificativi - ngeOut.WriteKey( NGE_A_GRP, true) ; + ngeOut.WriteKey( NGE_A_GRP) ; ngeOut.WriteInt( m_nId, "@") ; ngeOut.WriteInt( GetParentId(), nullptr, true) ; @@ -116,7 +117,7 @@ GdbGroup::Save( NgeWriter& ngeOut) const bOk = false ; // dati del riferimento - ngeOut.WriteKey( NGE_G, true) ; + ngeOut.WriteKey( NGE_G) ; if ( ! m_gfrFrame.Save( ngeOut)) bOk = false ; @@ -133,46 +134,34 @@ GdbGroup::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -GdbGroup::Load( const string& sType, Scanner& TheScanner, int& nParentId) +GdbGroup::Load( int nNgeId, NgeReader& ngeIn, int& nParentId) { - string sLine ; - STRVECTOR vsParams ; - - // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + if ( ! ngeIn.ReadInt( m_nId, "@")) return false ; - // la divido in parametri - Tokenize( sLine, "@", vsParams) ; - // 2 parametri : Id e ParentId - if ( vsParams.size() != 2) - return false ; - // assegno l'identificativo - if ( ! FromString( vsParams[0], m_nId)) - return false ; - // assegno l'Id del padre - if ( ! FromString( vsParams[1], nParentId)) + if ( ! ngeIn.ReadInt( nParentId, nullptr, true)) return false ; // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + int nKey ; + if ( ! ngeIn.ReadKey( nKey)) return false ; // eventuali attributi - if ( sLine == "A") { - if ( ! GdbObj::LoadAttribs( TheScanner)) + if ( nKey == NGE_A) { + if ( ! GdbObj::LoadAttribs( ngeIn)) return false ; // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) + if ( ! ngeIn.ReadKey( nKey)) return false ; } // verifico inizio dati geometrici - if ( sLine != "G") + if ( nKey != NGE_G) return false ; // leggo i dati del riferimento - return m_gfrFrame.Load( TheScanner) ; + return m_gfrFrame.Load( ngeIn) ; } //---------------------------------------------------------------------------- diff --git a/GdbGroup.h b/GdbGroup.h index 11c3071..87364e0 100644 --- a/GdbGroup.h +++ b/GdbGroup.h @@ -27,7 +27,7 @@ class GdbGroup : public GdbObj virtual ~GdbGroup( void) ; virtual GdbGroup* Clone( int nId, IdManager& IdMgr) const ; virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( const std::string& sType, Scanner& TheScanner, int& nParentId) ; + virtual bool Load( int nNgeId, NgeReader& ngeIn, int& nParentId) ; virtual bool GetLocalBBox( BBox3d& b3Loc, int nFlag, int nLev = 0) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag, int nLev = 0) const ; virtual bool Translate( const Vector3d& vtMove) ; diff --git a/GdbObj.cpp b/GdbObj.cpp index c1a589a..b751819 100644 --- a/GdbObj.cpp +++ b/GdbObj.cpp @@ -215,12 +215,12 @@ GdbObj::SaveAttribs( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -GdbObj::LoadAttribs( Scanner& TheScanner) +GdbObj::LoadAttribs( NgeReader& ngeIn) { if ( GetSafeAttribs() == nullptr) return false ; - return m_pAttribs->Load( TheScanner) ; + return m_pAttribs->Load( ngeIn) ; } //---------------------------------------------------------------------------- diff --git a/GdbObj.h b/GdbObj.h index 21049fe..7c6df13 100644 --- a/GdbObj.h +++ b/GdbObj.h @@ -15,7 +15,6 @@ #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkColor.h" -#include "/EgtDev/Include/EGnScan.h" #include "/EgtDev/Include/EGkBBox3d.h" #include @@ -23,6 +22,7 @@ class GdbGroup ; class IdManager ; class Attribs ; class NgeWriter ; +class NgeReader ; //---------------------------------------------------------------------------- class GdbObj @@ -31,7 +31,7 @@ class GdbObj virtual ~GdbObj( void) ; virtual GdbObj* Clone( int nId, IdManager& IdMgr) const = 0 ; virtual bool Save( NgeWriter& ngeOut) const = 0 ; - virtual bool Load( const std::string& sType, Scanner& TheScanner, int& nParentId) = 0 ; + virtual bool Load( int nNgeId, NgeReader& ngeIn, int& nParentId) = 0 ; virtual bool GetLocalBBox( BBox3d& b3Loc, int nFlag, int nLev = 0) const = 0 ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag, int nLev = 0) const = 0 ; virtual bool Translate( const Vector3d& vtMove) = 0 ; @@ -49,7 +49,7 @@ class GdbObj public : bool SaveAttribs( NgeWriter& ngeOut) const ; - bool LoadAttribs( Scanner& TheScanner) ; + bool LoadAttribs( NgeReader& ngeIn) ; Attribs* GetAttribs( void) { return m_pAttribs ; } Attribs* GetSafeAttribs( void) ; diff --git a/GeoFrame3d.cpp b/GeoFrame3d.cpp index 2eaca06..e6e587f 100644 --- a/GeoFrame3d.cpp +++ b/GeoFrame3d.cpp @@ -16,6 +16,7 @@ #include "GeoFrame3d.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGkPolyLine.h" #include @@ -139,18 +140,12 @@ GeoFrame3d::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -GeoFrame3d::Load( Scanner& TheScanner) +GeoFrame3d::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // elimino ; finale - TrimRight( sLine, ";") ; - // eseguo lettura - return FromString( sLine, m_frF) ; + return ngeIn.ReadFrame( m_frF, ";", true) ; } //---------------------------------------------------------------------------- diff --git a/GeoFrame3d.h b/GeoFrame3d.h index 9c191b7..07623a6 100644 --- a/GeoFrame3d.h +++ b/GeoFrame3d.h @@ -30,9 +30,6 @@ class GeoFrame3d : public IGeoFrame3d, public IGeoObjRW { return ( m_frF.GetType() != Frame3d::ERR) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool GetFrame( Frame3d& frF) const @@ -68,6 +65,11 @@ class GeoFrame3d : public IGeoFrame3d, public IGeoObjRW virtual bool GetDrawWithArrowHeads( double dLenA, double dFrazLenAH, PolyLine& plX, PolyLine& plY, PolyLine& plZ) const ; + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : GeoFrame3d( void) ; inline const GeoFrame3d& operator =( const GeoFrame3d& gfSrc) diff --git a/GeoObjRW.h b/GeoObjRW.h index 0f0c269..f9e1f3f 100644 --- a/GeoObjRW.h +++ b/GeoObjRW.h @@ -13,9 +13,8 @@ #pragma once -#include "/EgtDev/Include/EGnScan.h" - class NgeWriter ; +class NgeReader ; //----------------------------------------------------------------------------- class __declspec( novtable) IGeoObjRW @@ -23,5 +22,5 @@ class __declspec( novtable) IGeoObjRW public : virtual int GetNgeId( void) const = 0 ; virtual bool Save( NgeWriter& ngeOut) const = 0 ; - virtual bool Load( Scanner& TheScanner) = 0 ; + virtual bool Load( NgeReader& ngeIn) = 0 ; } ; diff --git a/GeoPoint3d.cpp b/GeoPoint3d.cpp index cc2cc97..121f175 100644 --- a/GeoPoint3d.cpp +++ b/GeoPoint3d.cpp @@ -16,6 +16,7 @@ #include "GeoPoint3d.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "\EgtDev\Include\EGkStringUtils3d.h" #include @@ -127,21 +128,12 @@ GeoPoint3d::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -GeoPoint3d::Load( Scanner& TheScanner) +GeoPoint3d::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // 1 solo parametro : il punto - TrimRight( sLine, ";") ; - // recupero il punto - if ( ! FromString( sLine, m_ptP)) - return false ; - - return true ; + return ngeIn.ReadPoint( m_ptP, ";", true) ; } //---------------------------------------------------------------------------- diff --git a/GeoPoint3d.h b/GeoPoint3d.h index 02f5b7f..eac6837 100644 --- a/GeoPoint3d.h +++ b/GeoPoint3d.h @@ -30,9 +30,6 @@ class GeoPoint3d : public IGeoPoint3d, public IGeoObjRW { return true ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool GetPoint( Point3d& ptP) const @@ -64,6 +61,11 @@ class GeoPoint3d : public IGeoPoint3d, public IGeoObjRW virtual const Point3d& GetPoint( void) const { return m_ptP ; } + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : GeoPoint3d( void) ; const GeoPoint3d& operator =( const GeoPoint3d& gpSrc) diff --git a/GeoVector3d.cpp b/GeoVector3d.cpp index 46282b5..91aa012 100644 --- a/GeoVector3d.cpp +++ b/GeoVector3d.cpp @@ -16,6 +16,7 @@ #include "GeoVector3d.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGkPolyLine.h" #include @@ -128,21 +129,12 @@ GeoVector3d::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -GeoVector3d::Load( Scanner& TheScanner) +GeoVector3d::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // 1 solo parametro : il vettore - TrimRight( sLine, ";") ; - // recupero il vettore - if ( ! FromString( sLine, m_vtV)) - return false ; - - return true ; + return ngeIn.ReadVector( m_vtV, ";", true) ; } //---------------------------------------------------------------------------- diff --git a/GeoVector3d.h b/GeoVector3d.h index 854beff..1575b67 100644 --- a/GeoVector3d.h +++ b/GeoVector3d.h @@ -29,9 +29,6 @@ class GeoVector3d : public IGeoVector3d, public IGeoObjRW { return true ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool GetVector( Vector3d& vtV) const @@ -64,6 +61,11 @@ class GeoVector3d : public IGeoVector3d, public IGeoObjRW { return m_vtV ; } virtual bool GetDrawWithArrowHead( double dFrazLenAH, PolyLine& PL) const ; + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : GeoVector3d( void) ; inline const GeoVector3d& operator =( const GeoVector3d& gvSrc) diff --git a/GeomDB.cpp b/GeomDB.cpp index bac2d97..3f33acf 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -17,6 +17,7 @@ #include "GdbGeo.h" #include "DllMain.h" #include "Attribs.h" +#include "NgeReader.h" #include "NgeWriter.h" #include "/EgtDev/Include/EgnStringUtils.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -80,30 +81,27 @@ GeomDB::Clear( void) bool GeomDB::Load( const std::string& sFileIn) { - bool bOk ; - bool bEnd ; - Scanner TheScanner ; - - - // inizializzo lo scanner - if ( ! TheScanner.Init( sFileIn)) { + // apertura file + NgeReader ngeIn ; + if ( ! ngeIn.Init( sFileIn)) { LOG_ERROR( GetEGkLogger(), "GeomDbLoad : Error on Init ") return false ; } // leggo l'intestazione - if ( ! LoadHeader( TheScanner)) { - string sOut = "GeomDbLoad : Error on line " + ToString( TheScanner.GetCurrLineNbr()) ; + if ( ! LoadHeader( ngeIn)) { + string sOut = "GeomDbLoad : Error on pos " + ToString( ngeIn.GetCurrPos()) ; LOG_ERROR( GetEGkLogger(), sOut.c_str()) return false ; } // ciclo di lettura dei nodi - bOk = true ; + bool bEnd ; + bool bOk = true ; do { - if ( ! LoadOneObj( TheScanner, bEnd)) { + if ( ! LoadOneObj( ngeIn, bEnd)) { bOk = false ; - string sOut = "GeomDbLoad : Error on line " + ToString( TheScanner.GetCurrLineNbr()) ; + string sOut = "GeomDbLoad : Error on pos " + ToString( ngeIn.GetCurrPos()) ; LOG_ERROR( GetEGkLogger(), sOut.c_str()) } } while ( ! bEnd) ; @@ -113,78 +111,52 @@ GeomDB::Load( const std::string& sFileIn) //---------------------------------------------------------------------------- bool -GeomDB::LoadHeader( Scanner& TheScanner) +GeomDB::LoadHeader( NgeReader& ngeIn) { - string sLine ; + // intestazione + int nKey ; + if ( ! ngeIn.ReadKey( nKey) || nKey != NGE_START) + return false ; + string sVal ; + if ( ! ngeIn.ReadString( sVal, ",") || sVal != NGE_GEOMDB) + return false ; + int nVal ; + if ( ! ngeIn.ReadInt( nVal, ".")) + return false ; + if ( ! ngeIn.ReadInt( nVal, ".")) + return false ; + if ( ! ngeIn.ReadInt( nVal, ";", true)) + return false ; - - // recupero la prima linea - if ( ! TheScanner.GetLine( sLine)) + // materiale di default come colore + if ( ! ngeIn.ReadKey( nKey) || nKey != NGE_MAT_DEF) return false ; - // deve essere l'intestazione - if ( sLine != "START") + Color colDef( 0, 0, 0, 0) ; + if ( ! ngeIn.ReadCol( colDef, ";", true)) return false ; - // recupero la riga successiva - if ( ! TheScanner.GetLine( sLine)) - return false ; - // leggo i parametri - // TODO - - // recupero la linea - if ( ! TheScanner.GetLine( sLine)) - return false ; - // deve essere il materiale di default - if ( sLine != "MAT_DEF") - return false ; - // recupero la riga successiva - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ",;", vsParams) ; - // 4 parametri - if ( vsParams.size() != 4) - return false ; - // leggo il materiale come colore - int nRed ; - if ( ! FromString( vsParams[0], nRed)) - return false ; - int nGreen ; - if ( ! FromString( vsParams[1], nGreen)) - return false ; - int nBlue ; - if ( ! FromString( vsParams[2], nBlue)) - return false ; - int nAlpha ; - if ( ! FromString( vsParams[3], nAlpha)) - return false ; - Color colDef( nRed, nGreen, nBlue, nAlpha) ; return SetDefaultMaterial( colDef) ; } //---------------------------------------------------------------------------- bool -GeomDB::LoadOneObj( Scanner& TheScanner, bool& bEnd) +GeomDB::LoadOneObj( NgeReader& ngeIn, bool& bEnd) { - int nParentId ; - string sType ; - GdbObj* pGdbObj ; - - // in generale non è fine file bEnd = false ; // leggo la prossima linea : tipo di nodo - if ( ! TheScanner.GetLine( sType)) + int nKey ; + if ( ! ngeIn.ReadKey( nKey)) return false ; // se fine dati - if ( sType == "END") { + GdbObj* pGdbObj ; + if ( nKey == NGE_END) { bEnd = true ; return true ; } // se gruppo - else if ( sType == "A_GRP") { + else if ( nKey == NGE_A_GRP) { pGdbObj = new( nothrow) GdbGroup ; } // se copia TODO ("X_CPY").. @@ -200,7 +172,8 @@ GeomDB::LoadOneObj( Scanner& TheScanner, bool& bEnd) return false ; // se lettura dati e inserimento nel DB vanno bene - if ( pGdbObj->Load( sType, TheScanner, nParentId) && + int nParentId ; + if ( pGdbObj->Load( nKey, ngeIn, nParentId) && AddToGeomDB( pGdbObj, nParentId)) return true ; // altrimenti errore @@ -216,8 +189,10 @@ GeomDB::Save( const std::string& sFileOut, bool bBinary) const { // apertura file NgeWriter ngeOut ; - if ( ! ngeOut.Init( sFileOut, bBinary)) + if ( ! ngeOut.Init( sFileOut, bBinary)) { + LOG_ERROR( GetEGkLogger(), "GeomDbSave : Error on Init ") return false ; + } // intestazione bool bOk = SaveHeader( ngeOut) ; @@ -254,7 +229,7 @@ bool GeomDB::SaveHeader( NgeWriter& ngeOut) const { // intestazione - ngeOut.WriteKey( NGE_START, true) ; + ngeOut.WriteKey( NGE_START) ; ngeOut.WriteString( NGE_GEOMDB, ",") ; ngeOut.WriteInt( NGE_MAJOR_VER, ".") ; ngeOut.WriteInt( NGE_MINOR_VER, ".") ; @@ -263,7 +238,7 @@ GeomDB::SaveHeader( NgeWriter& ngeOut) const // materiale di default come colore Color colDef( 0, 0, 0, 0) ; GetDefaultMaterial( colDef) ; - ngeOut.WriteKey( NGE_MAT_DEF, true) ; + ngeOut.WriteKey( NGE_MAT_DEF) ; ngeOut.WriteCol( colDef, ";", true) ; return true ; @@ -274,7 +249,7 @@ bool GeomDB::SaveFooter( NgeWriter& ngeOut) const { // terminazione - ngeOut.WriteKey( NGE_END, true) ; + ngeOut.WriteKey( NGE_END) ; return true ; } diff --git a/GeomDB.h b/GeomDB.h index ff409d6..151aaee 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -131,8 +131,8 @@ class GeomDB : public IGeomDB bool AddToGeomDB( GdbObj* pGObj, int nParentId) ; bool Relocate( int nId, int nNewParentId, bool bGlob) ; bool Erase( GdbObj* pGObj) ; - bool LoadHeader( Scanner& TheScanner) ; - bool LoadOneObj( Scanner& TheScanner, bool& bEnd) ; + bool LoadHeader( NgeReader& ngeIn) ; + bool LoadOneObj( NgeReader& ngeIn, bool& bEnd) ; bool SaveHeader( NgeWriter& ngeOut) const ; bool SaveFooter( NgeWriter& ngeOut) const ; bool SetStatus( GdbObj* pGdbObj, int nStat) ; diff --git a/NgeReader.cpp b/NgeReader.cpp new file mode 100644 index 0000000..0c4e5ab --- /dev/null +++ b/NgeReader.cpp @@ -0,0 +1,206 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : NgeReader.cpp Data : 14.04.14 Versione : 1.5d5 +// Contenuto : Implementazione della classe NgeReader. +// +// +// +// Modifiche : 14.04.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "NgeReader.h" +#include "NgeKeyW.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +NgeReader::Init( const std::string& sFileIn) +{ + m_iPosStart = string::npos ; + m_sLine.reserve( 128) ; + m_sToken.reserve( 48) ; + return m_Scan.Init( sFileIn) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::Close( void) +{ + return m_Scan.Terminate() ; +} + +//---------------------------------------------------------------------------- +int +NgeReader::GetCurrPos( void) +{ + return m_Scan.GetCurrLineNbr() ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::GetToken( std::string& sToken, const char* szSep, bool bEndL) +{ + // se necessario, lettura nuova linea + if ( m_iPosStart == string::npos) { + if ( ! m_Scan.GetLine( m_sLine)) + return false ; + m_iPosStart = 0 ; + } + // se richiesta ricerca separatore + if ( szSep != nullptr) { + // cerco il primo separatore nella linea + string::size_type iPosEnd = m_sLine.find_first_of( szSep, m_iPosStart) ; + sToken = m_sLine.substr( m_iPosStart, iPosEnd - m_iPosStart) ; + // passo al prossimo + m_iPosStart = m_sLine.find_first_not_of( szSep, iPosEnd) ; + if ( bEndL) + return ( m_iPosStart == string::npos) ; + else + return ( m_iPosStart != string::npos) ; + } + // altrimenti, deve essere tutto con endl obbligatorio + else { + sToken = m_sLine.substr( m_iPosStart, string::npos) ; + m_iPosStart = string::npos ; + return bEndL ; + } +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadUchar( unsigned char& ucVal, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + int nVal ; + if ( ! FromString( m_sToken, nVal)) + return false ; + ucVal = nVal ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadBool( bool& bVal, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, bVal) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadInt( int& nVal, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, nVal) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadDouble( double& dVal, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, dVal) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadVector( Vector3d& vtV, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, vtV) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadPoint( Point3d& ptP, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadPointW( Point3d& ptP, double& dW, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, ptP, dW) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadFrame( Frame3d& frF, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, frF) ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadString( string& sVal, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // lo copio nella stringa + sVal = m_sToken ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadKey( int& nKey) +{ + // recupero la linea + if ( ! GetToken( m_sToken, nullptr, true)) + return false ; + // ricavo il valore + for ( int i = 0 ; i <= NGE_LAST_ID ; ++ i) { + if ( m_sToken == NgeAscKeyW[i]) { + nKey = i ; + return true ; + } + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +NgeReader::ReadCol( Color& cCol, const char* szSep, bool bEndL) +{ + // recupero il token + if ( ! GetToken( m_sToken, szSep, bEndL)) + return false ; + // ricavo il valore + return FromString( m_sToken, cCol) ; +} diff --git a/NgeReader.h b/NgeReader.h new file mode 100644 index 0000000..0677854 --- /dev/null +++ b/NgeReader.h @@ -0,0 +1,53 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : NgeReader.h Data : 14.04.14 Versione : 1.5d5 +// Contenuto : Dichiarazione della classe NgeReader. +// +// +// +// Modifiche : 14.04.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "NgeConst.h" +#include "/EgtDev/Include/EGkPoint3d.h" +#include "/EgtDev/Include/EGkColor.h" +#include "/EgtDev/Include/EGnScan.h" +#include "/EgtDev/Include/EGnStringBase.h" +#include + +//---------------------------------------------------------------------------- +class NgeReader +{ + public : + NgeReader( void) : m_iPosStart( std::string::npos) {} + ~NgeReader( void) + { Close() ; } + bool Init( const std::string& sFileIn) ; + bool Close( void) ; + int GetCurrPos( void) ; + bool ReadUchar( unsigned char& ucVal, const char* szSep, bool bEndL = false) ; + bool ReadBool( bool& bVal, const char* szSep, bool bEndL = false) ; + bool ReadInt( int& nVal, const char* szSep, bool bEndL = false) ; + bool ReadDouble( double& dVal, const char* szSep, bool bEndL = false) ; + bool ReadVector( Vector3d& vtV, const char* szSep, bool bEndL = false) ; + bool ReadPoint( Point3d& ptP, const char* szSep, bool bEndL = false) ; + bool ReadPointW( Point3d& ptP, double& dW, const char* szSep, bool bEndL = false) ; + bool ReadFrame( Frame3d& frF, const char* szSep, bool bEndL) ; + bool ReadString( std::string& sVal, const char* szSep, bool bEndL = false) ; + bool ReadKey( int& nKey /* bEndL = true*/) ; + bool ReadCol( Color& cCol, const char* szSep, bool bEndL = false) ; + + private : + bool GetToken( std::string& sToken, const char* szSep, bool bEndL) ; + + private : + Scanner m_Scan ; + std::string::size_type m_iPosStart ; + std::string m_sLine ; + std::string m_sToken ; +} ; diff --git a/NgeWriter.cpp b/NgeWriter.cpp index 26ba0b5..8758d67 100644 --- a/NgeWriter.cpp +++ b/NgeWriter.cpp @@ -2,7 +2,7 @@ // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : NgeWriter.cpp Data : 13.04.14 Versione : 1.5d5 -// Contenuto : Implementazione della classe Writer. +// Contenuto : Implementazione della classe NgeWriter. // // // @@ -14,7 +14,6 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "NgeWriter.h" -#include "NgeConst.h" #include "NgeKeyW.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EgnStringConverter.h" @@ -220,7 +219,7 @@ NgeWriter::WriteFrame( const Frame3d& frF, const char* szSep, bool bEndL, int nP //---------------------------------------------------------------------------- void -NgeWriter::WriteKey( int nKey, bool bEndL) +NgeWriter::WriteKey( int nKey) { if ( ! m_OutFile.is_open()) return ; @@ -232,8 +231,7 @@ NgeWriter::WriteKey( int nKey, bool bEndL) m_OutFile.write( (char*) &NgeBinKeyW[nKey], sizeof( int)) ; else { m_OutFile << NgeAscKeyW[nKey] ; - if ( bEndL) - m_OutFile << endl ; + m_OutFile << endl ; } } @@ -259,4 +257,4 @@ NgeWriter::WriteCol( const Color& cCol, const char* szSep, bool bEndL) if ( bEndL) m_OutFile << endl ; } -} \ No newline at end of file +} diff --git a/NgeWriter.h b/NgeWriter.h index fb2f12a..bd617fb 100644 --- a/NgeWriter.h +++ b/NgeWriter.h @@ -37,12 +37,10 @@ class NgeWriter int nPrecP = 6, int nPrecW = 9) ; void WriteFrame( const Frame3d& frF, const char* szSep, bool bEndL, int nPrecP = 6, int nPrecV = 9) ; void WriteString( const std::string& sVal, const char* szSep, bool bEndL = false) ; - void WriteKey( int nKey, bool bEndL) ; + void WriteKey( int nKey /* bEndL = true*/) ; void WriteCol( const Color& cCol, const char* szSep, bool bEndL = false) ; - private : bool m_bBinary ; std::ofstream m_OutFile ; - } ; diff --git a/SurfTriMesh.cpp b/SurfTriMesh.cpp index cd24b42..13e19ce 100644 --- a/SurfTriMesh.cpp +++ b/SurfTriMesh.cpp @@ -16,6 +16,7 @@ #include "SurfTriMesh.h" #include "GeoObjFactory.h" #include "NgeWriter.h" +#include "NgeReader.h" #include "Triangulate.h" #include "\EgtDev\Include\EGkStringUtils3d.h" #include "\EgtDev\Include\EGkPolyLine.h" @@ -370,31 +371,22 @@ SurfTriMesh::Save( NgeWriter& ngeOut) const //---------------------------------------------------------------------------- bool -SurfTriMesh::Load( Scanner& TheScanner) +SurfTriMesh::Load( NgeReader& ngeIn) { // imposto ricalcolo della grafica m_OGrMgr.Reset() ; - // leggo la prossima linea - string sLine ; - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - STRVECTOR vsParams ; - Tokenize( sLine, ";", vsParams) ; - // 3 parametri : flag chiuso num vertici e num tria - if ( vsParams.size() != 3) - return false ; + // leggo la prossima linea ( 3 parametri : flag chiuso num vertici e num tria) // recupero il flag bool bClosed ; - if ( ! FromString( vsParams[0], bClosed)) + if ( ! ngeIn.ReadBool( bClosed, ";")) return false ; // recupero il numero di vertici int nNumVert ; - if ( ! FromString( vsParams[1], nNumVert)) + if ( ! ngeIn.ReadInt( nNumVert, ";")) return false ; // recupero il numero di triangoli int nNumTria ; - if ( ! FromString( vsParams[2], nNumTria)) + if ( ! ngeIn.ReadInt( nNumTria, ";", true)) return false ; // inizializzo la superficie TriMesh if ( ! Init( nNumVert, nNumTria)) @@ -404,40 +396,30 @@ SurfTriMesh::Load( Scanner& TheScanner) int nInd ; StmVert vV ; for ( int i = 0 ; i < nNumVert ; ++ i) { - // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - Tokenize( sLine, ";", vsParams) ; - // 4 parametri : Indice, Punto, IdTria, Flag - if ( vsParams.size() != 4) - return false ; + // leggo la prossima linea ( 4 parametri : Indice, Punto, IdTria, Flag) // la interpreto e imposto il vertice - if ( ! FromString( vsParams[0], nInd) || - ! FromString( vsParams[1], vV.ptP) || - ! FromString( vsParams[2], vV.nIdTria) || - ! FromString( vsParams[3], vV.nFlag) || + if ( ! ngeIn.ReadInt( nInd, ";") || + ! ngeIn.ReadPoint( vV.ptP, ";") || + ! ngeIn.ReadInt( vV.nIdTria, ";") || + ! ngeIn.ReadInt( vV.nFlag, ";", true) || ! SetVertex( nInd, vV)) return false ; } // lettura dei triangoli StmTria tT ; for ( int i = 0 ; i < nNumTria ; ++ i) { - // leggo la prossima linea - if ( ! TheScanner.GetLine( sLine)) - return false ; - // la divido in parametri - Tokenize( sLine, ";", vsParams) ; - // 6 parametri : Indice, IdVertici, IdAdiacenze, Normale, TFlag, EFlag - if ( vsParams.size() != 6) - return false ; + // leggo la prossima linea ( 6 parametri : Indice, IdVertici, IdAdiacenze, Normale, TFlag, EFlag) // la interpreto e imposto il vertice - if ( ! FromString( vsParams[0], nInd) || - ! FromString( vsParams[1], tT.nIdVert) || - ! FromString( vsParams[2], tT.nIdAdjac) || - ! FromString( vsParams[3], tT.vtN) || - ! FromString( vsParams[4], tT.nTFlag) || - ! FromString( vsParams[5], tT.nEFlag) || + if ( ! ngeIn.ReadInt( nInd, ";") || + ! ngeIn.ReadInt( tT.nIdVert[0], ",") || + ! ngeIn.ReadInt( tT.nIdVert[1], ",") || + ! ngeIn.ReadInt( tT.nIdVert[2], ";") || + ! ngeIn.ReadInt( tT.nIdAdjac[0], ",") || + ! ngeIn.ReadInt( tT.nIdAdjac[1], ",") || + ! ngeIn.ReadInt( tT.nIdAdjac[2], ";") || + ! ngeIn.ReadVector( tT.vtN, ";") || + ! ngeIn.ReadInt( tT.nTFlag, ";") || + ! ngeIn.ReadInt( tT.nEFlag, ";", true) || ! SetTriangle( nInd, tT)) return false ; } diff --git a/SurfTriMesh.h b/SurfTriMesh.h index 40cf488..b3af72f 100644 --- a/SurfTriMesh.h +++ b/SurfTriMesh.h @@ -69,9 +69,6 @@ class SurfTriMesh : public ISurfTriMesh, public IGeoObjRW { return ( m_nStatus == OK) ; } virtual const std::string& GetTitle( void) const ; virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const ; - virtual int GetNgeId( void) const ; - virtual bool Save( NgeWriter& ngeOut) const ; - virtual bool Load( Scanner& TheScanner) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const ; virtual bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; virtual bool Translate( const Vector3d& vtMove) ; @@ -114,6 +111,11 @@ class SurfTriMesh : public ISurfTriMesh, public IGeoObjRW virtual int GetNextTriangle( int nId, Triangle3d& Tria) const ; virtual bool GetTriangleSmoothNormals( int nId, TriNormals3d& TNrms) const ; + public : // IGeoObjRW + virtual int GetNgeId( void) const ; + virtual bool Save( NgeWriter& ngeOut) const ; + virtual bool Load( NgeReader& ngeIn) ; + public : SurfTriMesh( void) ; const SurfTriMesh& operator =( const SurfTriMesh& stSrc)