EgtGeomKernel :
- cambiato Load, con uso di NgeReader.
This commit is contained in:
+43
-68
@@ -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 ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user