EgtGeomKernel 1.5f5 :

- gestione salvataggio in modalità testo compresso
- aggiunto controlli in scritture per salvataggio.
This commit is contained in:
Dario Sassi
2014-06-18 07:27:03 +00:00
parent 26c2ad702a
commit 4097bcd178
23 changed files with 359 additions and 261 deletions
+20 -10
View File
@@ -95,26 +95,36 @@ bool
Attribs::Save( NgeWriter& ngeOut) const
{
// flag presenza attributi
ngeOut.WriteKey( NGE_A) ;
if ( ! ngeOut.WriteKey( NGE_A))
return false ;
// livello
ngeOut.WriteUchar( m_Data[LEVEL], ",") ;
if ( ! ngeOut.WriteUchar( m_Data[LEVEL], ","))
return false ;
// modo
ngeOut.WriteUchar( m_Data[MODE], ",") ;
if ( ! ngeOut.WriteUchar( m_Data[MODE], ","))
return false ;
// stato (se SEL è convertito in ON)
int nStat = (( m_Data[STATUS] > GDB_ST_ON) ? GDB_ST_ON : m_Data[STATUS]) ;
ngeOut.WriteUchar( nStat, ",") ;
if ( ! ngeOut.WriteUchar( nStat, ","))
return false ;
// marcatura (sempre OFF)
ngeOut.WriteUchar( GDB_MK_OFF, ";") ;
if ( ! ngeOut.WriteUchar( GDB_MK_OFF, ";"))
return false ;
// materiale
ngeOut.WriteInt( m_Material, ";") ;
if ( ! ngeOut.WriteInt( m_Material, ";"))
return false ;
// colore
ngeOut.WriteCol( m_Color, ";") ;
if ( ! ngeOut.WriteCol( m_Color, ";"))
return false ;
// numero di stringhe di info (nelle linee successive)
ngeOut.WriteInt( int( m_slInfo.size()), ";", true) ;
if ( ! ngeOut.WriteInt( int( m_slInfo.size()), ";", true))
return false ;
// stringhe di info
STRLIST::const_iterator iIter ;
for ( iIter = m_slInfo.begin() ; iIter != m_slInfo.end() ; ++ iIter)
ngeOut.WriteString( *iIter, nullptr, true) ;
for ( iIter = m_slInfo.begin() ; iIter != m_slInfo.end() ; ++ iIter) {
if ( ! ngeOut.WriteString( *iIter, nullptr, true))
return false ;
}
return true ;
}
+12 -6
View File
@@ -487,17 +487,23 @@ bool
CurveArc::Save( NgeWriter& ngeOut) const
{
// centro
ngeOut.WritePoint( m_PtCen, ";") ;
if ( ! ngeOut.WritePoint( m_PtCen, ";"))
return false ;
// versore Normale
ngeOut.WriteVector( m_VtN, ";") ;
if ( ! ngeOut.WriteVector( m_VtN, ";"))
return false ;
// raggio
ngeOut.WriteDouble( m_dRad, ";") ;
if ( ! ngeOut.WriteDouble( m_dRad, ";"))
return false ;
// versore Iniziale
ngeOut.WriteVector( m_VtS, ";") ;
if ( ! ngeOut.WriteVector( m_VtS, ";"))
return false ;
// angolo al centro
ngeOut.WriteDouble( m_dAngCenDeg, ";") ;
if ( ! ngeOut.WriteDouble( m_dAngCenDeg, ";"))
return false ;
// deltaN
ngeOut.WriteDouble( m_dDeltaN, ";", true) ;
if ( ! ngeOut.WriteDouble( m_dDeltaN, ";", true))
return false ;
return true ;
}
+12 -6
View File
@@ -352,15 +352,21 @@ bool
CurveBezier::Save( NgeWriter& ngeOut) const
{
// flag razionale
ngeOut.WriteBool( m_bRat, ";") ;
if ( ! ngeOut.WriteBool( m_bRat, ";"))
return false ;
// grado
ngeOut.WriteInt( m_nDeg, ";", true) ;
if ( ! ngeOut.WriteInt( m_nDeg, ";", true))
return false ;
// ciclo sui punti di controllo ( con pesi se razionale)
for ( int i = 0 ; i <= m_nDeg ; ++ i) {
if ( ! m_bRat)
ngeOut.WritePoint( m_aPtCtrl[i], ";", true) ;
else
ngeOut.WritePointW( m_aPtCtrl[i], m_aWeCtrl[i], ";", true) ;
if ( ! m_bRat) {
if ( ! ngeOut.WritePoint( m_aPtCtrl[i], ";", true))
return false ;
}
else {
if ( ! ngeOut.WritePointW( m_aPtCtrl[i], m_aWeCtrl[i], ";", true))
return false ;
}
}
return true ;
+6 -3
View File
@@ -411,7 +411,8 @@ bool
CurveComposite::Save( NgeWriter& ngeOut) const
{
// numero di curve
ngeOut.WriteInt( m_nCounter, nullptr, true) ;
if ( ! ngeOut.WriteInt( m_nCounter, nullptr, true))
return false ;
// ciclo sulle curve componenti
int i = 0 ;
const ICurve* pCrvSmpl = GetFirstCurve() ;
@@ -421,10 +422,12 @@ CurveComposite::Save( NgeWriter& ngeOut) const
if ( pCSmplRW == nullptr)
return false ;
// emetto tipo della curva semplice
ngeOut.WriteKey( pCSmplRW->GetNgeId()) ;
if ( ! ngeOut.WriteKey( pCSmplRW->GetNgeId()))
return false ;
// assegno ed emetto nome della curva semplice
string sCrvName = "#" + ToString( ++i) ;
ngeOut.WriteString( sCrvName, nullptr, true) ;
if ( ! ngeOut.WriteString( sCrvName, nullptr, true))
return false ;
// salvataggio della curva semplice
if ( ! pCSmplRW->Save( ngeOut))
return false ;
+4 -2
View File
@@ -165,8 +165,10 @@ bool
CurveLine::Save( NgeWriter& ngeOut) const
{
// parametri : punti iniziale e finale
ngeOut.WritePoint( m_PtStart, ";") ;
ngeOut.WritePoint( m_PtEnd, ";", true) ;
if ( ! ngeOut.WritePoint( m_PtStart, ";"))
return false ;
if ( ! ngeOut.WritePoint( m_PtEnd, ";", true))
return false ;
return true ;
}
BIN
View File
Binary file not shown.
+2
View File
@@ -165,6 +165,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<OpenMPSupport>true</OpenMPSupport>
<CompileAs>CompileAsCpp</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -200,6 +201,7 @@ copy $(TargetPath) \EgtProg\Dll32</Command>
<OpenMPSupport>true</OpenMPSupport>
<CompileAs>CompileAsCpp</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
+3
View File
@@ -34,6 +34,9 @@
<Filter Include="File di origine\GeoDist">
<UniqueIdentifier>{cc84f71a-b149-4187-af26-736133e92672}</UniqueIdentifier>
</Filter>
<Filter Include="File di origine\GeoInters">
<UniqueIdentifier>{7284f71c-3fd5-4bb9-bfe6-2c8c312985cc}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Vector3d.cpp">
+22 -11
View File
@@ -220,27 +220,38 @@ bool
ExtText::Save( NgeWriter& ngeOut) const
{
// punto di inserimento
ngeOut.WritePoint( m_ptP, ";") ;
if ( ! ngeOut.WritePoint( m_ptP, ";"))
return false ;
// flag posizione inserimento
ngeOut.WriteInt( m_nInsPos, ";") ;
if ( ! ngeOut.WriteInt( m_nInsPos, ";"))
return false ;
// versore normale
ngeOut.WriteVector( m_vtN, ";") ;
if ( ! ngeOut.WriteVector( m_vtN, ";"))
return false ;
// versore di direzione
ngeOut.WriteVector( m_vtD, ";", true) ;
if ( ! ngeOut.WriteVector( m_vtD, ";", true))
return false ;
// testo
ngeOut.WriteString( m_sText, nullptr, true) ;
if ( ! ngeOut.WriteString( m_sText, nullptr, true))
return false ;
// font
ngeOut.WriteString( m_sFont, ";") ;
if ( ! ngeOut.WriteString( m_sFont, ";"))
return false ;
// spessore del font
ngeOut.WriteInt( m_nWeight, ",") ;
if ( ! ngeOut.WriteInt( m_nWeight, ","))
return false ;
// flag di italico
ngeOut.WriteBool( m_bItalic, ",") ;
if ( ! ngeOut.WriteBool( m_bItalic, ","))
return false ;
// altezza del font
ngeOut.WriteDouble( m_dHeight, ",") ;
if ( ! ngeOut.WriteDouble( m_dHeight, ","))
return false ;
// rapporto larghezza su altezza del font
ngeOut.WriteDouble( m_dRatio, ",") ;
if ( ! ngeOut.WriteDouble( m_dRatio, ","))
return false ;
// avanzamento addizionale tra caratteri
ngeOut.WriteDouble( m_dAddAdvance, ";", true) ;
if ( ! ngeOut.WriteDouble( m_dAddAdvance, ";", true))
return false ;
return true ;
}
+8 -5
View File
@@ -4313,14 +4313,17 @@ GdbExecutor::ExecuteSave( const string& sCmd2, const STRVECTOR& vsParams)
string sFile = vsParams[0] ;
m_pParser->DirReplace( sFile) ;
// il secondo parametro, opzionale, indica il formato del file
bool bBinary = false ;
int nFlag = GDB_SV_CMPTXT ;
if ( vsParams.size() == 2) {
string sBinary = vsParams[1] ;
ToUpper( sBinary) ;
bBinary = ( sBinary == "B" || sBinary == "BINARY") ;
string sFlag = vsParams[1] ;
ToUpper( sFlag) ;
if ( sFlag == "T" || sFlag == "TEXT")
nFlag = GDB_SV_TXT ;
else if ( sFlag == "B" || sFlag == "BINARY")
nFlag = GDB_SV_BIN ;
}
// esecuzione salvataggio
return m_pGDB->Save( sFile, bBinary) ;
return m_pGDB->Save( sFile, nFlag) ;
}
//----------------------------------------------------------------------------
+8 -4
View File
@@ -93,16 +93,20 @@ GdbGeo::Save( NgeWriter& ngeOut) const
return false ;
// tipo entità e identificativi
ngeOut.WriteKey( pGObjRW->GetNgeId()) ;
ngeOut.WriteInt( m_nId, "@") ;
ngeOut.WriteInt( GetParentId(), nullptr, true) ;
if ( ! ngeOut.WriteKey( pGObjRW->GetNgeId()))
return false ;
if ( ! ngeOut.WriteInt( m_nId, "@"))
return false ;
if ( ! ngeOut.WriteInt( GetParentId(), nullptr, true))
return false ;
// attributi
if ( ! GdbObj::SaveAttribs( ngeOut))
return false ;
// parametri geometrici
ngeOut.WriteKey( NGE_G) ;
if ( ! ngeOut.WriteKey( NGE_G))
return false ;
return pGObjRW->Save( ngeOut) ;
}
+14 -11
View File
@@ -105,34 +105,37 @@ GdbGroup::Clone( int nId, IdManager& IdMgr) const
bool
GdbGroup::Save( NgeWriter& ngeOut) const
{
bool bOk = true ;
// tipo entità e identificativi
ngeOut.WriteKey( NGE_A_GRP) ;
ngeOut.WriteInt( m_nId, "@") ;
ngeOut.WriteInt( GetParentId(), nullptr, true) ;
if ( ! ngeOut.WriteKey( NGE_A_GRP))
return false ;
if ( ! ngeOut.WriteInt( m_nId, "@"))
return false ;
if ( ! ngeOut.WriteInt( GetParentId(), nullptr, true))
return false ;
// attributi
if ( ! GdbObj::SaveAttribs( ngeOut))
bOk = false ;
return false ;
// dati geometrici
ngeOut.WriteKey( NGE_G) ;
if ( ! ngeOut.WriteKey( NGE_G))
return false ;
// puntatore alla prima copia (per ora NULL)
ngeOut.WriteInt( GDB_ID_NULL, nullptr, true) ;
if ( ! ngeOut.WriteInt( GDB_ID_NULL, nullptr, true))
return false ;
// frame
if ( ! m_gfrFrame.Save( ngeOut))
bOk = false ;
return false ;
// salvataggio dei figli
const GdbObj* pGdbObj = GetFirstObj() ;
while ( pGdbObj != nullptr) {
if ( ! pGdbObj->Save( ngeOut))
bOk = false ;
return false ;
pGdbObj = pGdbObj->GetNext() ;
}
return bOk ;
return true ;
}
//----------------------------------------------------------------------------
+18 -9
View File
@@ -49,22 +49,31 @@ bool
GdbMaterialMgr::Save( NgeWriter& ngeOut) const
{
// intestazione libreria
ngeOut.WriteKey( NGE_MAT_LIB) ;
if ( ! ngeOut.WriteKey( NGE_MAT_LIB))
return false ;
// numero di materiali custom
int nCustNum = int( m_GdbMats.size()) - m_nStdNum ;
ngeOut.WriteInt( nCustNum, ";", true) ;
if ( ! ngeOut.WriteInt( nCustNum, ";", true))
return false ;
// scrittura dei materiali custom
for ( int i = m_nStdNum ; i < int( m_GdbMats.size()) ; ++ i) {
// Nome, Id, Tipo (1=materiale senza texture)
string sMatName = ( m_GdbMats[i].sName.empty() ? "$$" : m_GdbMats[i].sName) ;
ngeOut.WriteString( sMatName, ",") ;
ngeOut.WriteInt( i + 1, ",") ;
ngeOut.WriteInt( 1, ";", true) ;
if ( ! ngeOut.WriteString( sMatName, ","))
return false ;
if ( ! ngeOut.WriteInt( i + 1, ","))
return false ;
if ( ! ngeOut.WriteInt( 1, ";", true))
return false ;
// dati del materiale
ngeOut.WriteCol( m_GdbMats[i].matM.GetAmbient(), ";") ;
ngeOut.WriteCol( m_GdbMats[i].matM.GetDiffuse(), ";") ;
ngeOut.WriteCol( m_GdbMats[i].matM.GetSpecular(), ";") ;
ngeOut.WriteDouble( m_GdbMats[i].matM.GetShininess(), ";", true, 1) ;
if ( ! ngeOut.WriteCol( m_GdbMats[i].matM.GetAmbient(), ";"))
return false ;
if ( ! ngeOut.WriteCol( m_GdbMats[i].matM.GetDiffuse(), ";"))
return false ;
if ( ! ngeOut.WriteCol( m_GdbMats[i].matM.GetSpecular(), ";"))
return false ;
if ( ! ngeOut.WriteDouble( m_GdbMats[i].matM.GetShininess(), ";", true, 1))
return false ;
}
return true ;
+1 -3
View File
@@ -153,9 +153,7 @@ GeoFrame3d::GetNgeId( void) const
bool
GeoFrame3d::Save( NgeWriter& ngeOut) const
{
ngeOut.WriteFrame( m_frF, ";", true) ;
return true ;
return ngeOut.WriteFrame( m_frF, ";", true) ;
}
//----------------------------------------------------------------------------
+1 -3
View File
@@ -121,9 +121,7 @@ bool
GeoPoint3d::Save( NgeWriter& ngeOut) const
{
// parametri : punto
ngeOut.WritePoint( m_ptP, ";", true) ;
return true ;
return ngeOut.WritePoint( m_ptP, ";", true) ;
}
//----------------------------------------------------------------------------
+4 -2
View File
@@ -138,8 +138,10 @@ bool
GeoVector3d::Save( NgeWriter& ngeOut) const
{
// parametri : vettore
ngeOut.WriteVector( m_vtV, ";") ;
ngeOut.WritePoint( m_ptBase, ";", true) ;
if ( ! ngeOut.WriteVector( m_vtV, ";"))
return false ;
if ( ! ngeOut.WritePoint( m_ptBase, ";", true))
return false ;
return true ;
}
+17 -12
View File
@@ -194,11 +194,11 @@ GeomDB::LoadOneObj( NgeReader& ngeIn, bool& bEnd)
//----------------------------------------------------------------------------
bool
GeomDB::Save( const std::string& sFileOut, bool bBinary) const
GeomDB::Save( const std::string& sFileOut, int nFlag) const
{
// apertura file
NgeWriter ngeOut ;
if ( ! ngeOut.Init( sFileOut, bBinary)) {
if ( ! ngeOut.Init( sFileOut, nFlag)) {
LOG_ERROR( GetEGkLogger(), "GeomDbSave : Error on Init ")
return false ;
}
@@ -242,17 +242,24 @@ bool
GeomDB::SaveHeader( NgeWriter& ngeOut) const
{
// intestazione
ngeOut.WriteKey( NGE_START) ;
ngeOut.WriteString( NGE_GEOMDB, ",") ;
ngeOut.WriteInt( NGE_MAJOR_VER, ".") ;
ngeOut.WriteInt( NGE_MINOR_VER, ".") ;
ngeOut.WriteInt( NGE_PATCH_VER, ";", true) ;
if ( ! ngeOut.WriteKey( NGE_START))
return false ;
if ( ! ngeOut.WriteString( NGE_GEOMDB, ","))
return false ;
if ( ! ngeOut.WriteInt( NGE_MAJOR_VER, "."))
return false ;
if ( ! ngeOut.WriteInt( NGE_MINOR_VER, "."))
return false ;
if ( ! ngeOut.WriteInt( NGE_PATCH_VER, ";", true))
return false ;
// materiale di default come colore
Color colDef( 0, 0, 0, 0) ;
GetDefaultMaterial( colDef) ;
ngeOut.WriteKey( NGE_MAT_DEF) ;
ngeOut.WriteCol( colDef, ";", true) ;
if ( ! ngeOut.WriteKey( NGE_MAT_DEF))
return false ;
if ( ! ngeOut.WriteCol( colDef, ";", true))
return false ;
return true ;
}
@@ -262,9 +269,7 @@ bool
GeomDB::SaveFooter( NgeWriter& ngeOut) const
{
// terminazione
ngeOut.WriteKey( NGE_END) ;
return true ;
return ngeOut.WriteKey( NGE_END) ;
}
//----------------------------------------------------------------------------
+1 -1
View File
@@ -32,7 +32,7 @@ class GeomDB : public IGeomDB
virtual bool Init( void) ;
virtual bool Clear( void) ;
virtual bool Load( const std::string& sFileIn) ;
virtual bool Save( const std::string& sFileOut, bool bBinary = true) const ;
virtual bool Save( const std::string& sFileOut, int nFlag = GDB_SV_BIN) const ;
virtual bool ExistsObj( int nId) const ;
virtual int AddGroup( int nId, int nParentId, const Frame3d& frFrame) ;
virtual int InsertGroup( int nId, int nRefId, int nSonBeforeAfter, const Frame3d& frFrame) ;
+4
View File
@@ -73,6 +73,10 @@ NgeReader::NgeType( const std::string& sFile)
// chiusura del file
InFile.close() ;
// verifico se file compresso (gz)
if ( cBuff[0] == '\x1F' && cBuff[1] == '\x8B')
return NGE_ASCII ;
// verifico se iniziano con "START"
string sBuff = cBuff ;
size_t nPos = sBuff.find( "START") ;
+156 -140
View File
@@ -15,246 +15,262 @@
#include "stdafx.h"
#include "NgeWriter.h"
#include "NgeKeyW.h"
#include "/EgtDev/Include/EGkGdbConst.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgnStringConverter.h"
#include "/EgtDev/Extern/Zlib/Include/zlib.h"
using namespace std ;
//----------------------------------------------------------------------------
inline bool
WriteStringOutTxt( gzFile OutTxtFile, const char* szVal, const char* szSep, bool bEndL)
{
// verifico apertura file
if ( OutTxtFile == nullptr)
return false ;
// scrivo stringa
if ( gzputs( OutTxtFile, szVal) == Z_ERRNO)
return false ;
// se fornito, scrivo separatore
if ( szSep != nullptr && szSep[0] != '\0') {
if ( gzputs( OutTxtFile, szSep) == Z_ERRNO)
return false ;
}
// se richiesto, scrivo fine linea
if ( bEndL) {
if ( gzputs( OutTxtFile, "\r\n") == Z_ERRNO)
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
NgeWriter::Init( const std::string& sFileOut, bool bBinary)
NgeWriter::Init( const string& sFileOut, int nFlag)
{
// salvo tipo file
m_bBinary = bBinary ;
m_bBinary = ( nFlag == GDB_SV_BIN) ;
// apertura del file di uscita
ios_base::openmode nMode = ios::out | ( m_bBinary ? ios::binary : 0) ;
int nProt = _SH_DENYWR ;
m_OutFile.open( stringtoW( sFileOut), nMode, nProt) ;
return m_OutFile.good() ;
if ( m_bBinary) {
ios_base::openmode nMode = ios::out | ( m_bBinary ? ios::binary : 0) ;
int nProt = _SH_DENYWR ;
m_OutBinFile.open( stringtoW( sFileOut), nMode, nProt) ;
return m_OutBinFile.good() ;
}
else {
if ( nFlag == GDB_SV_TXT)
m_OutTxtFile = gzopen_w( stringtoW( sFileOut), "wbT") ;
else // GDB_SV_CMPTXT
m_OutTxtFile = gzopen_w( stringtoW( sFileOut), "wb") ;
if ( m_OutTxtFile == nullptr)
return false ;
const int DIM_BUFFER = 65536 ;
if ( gzbuffer( m_OutTxtFile, DIM_BUFFER) != Z_OK)
return false ;
const int COMPR_LEVEL = 3 ; // 0 = no compression ... 9 = max compression
if ( gzsetparams( m_OutTxtFile, COMPR_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK)
return false ;
return true ;
}
}
//----------------------------------------------------------------------------
bool
NgeWriter::Close( void)
{
bool bOk = ( m_OutFile.good() && m_OutFile.is_open()) ;
if ( m_OutFile.is_open())
m_OutFile.close() ;
return bOk ;
if ( m_bBinary) {
bool bOk = ( m_OutBinFile.good() && m_OutBinFile.is_open()) ;
if ( m_OutBinFile.is_open())
m_OutBinFile.close() ;
return bOk ;
}
else {
if ( m_OutTxtFile != nullptr) {
bool bOk = ( gzclose( m_OutTxtFile) == Z_OK) ;
m_OutTxtFile = nullptr ;
return bOk ;
}
return true ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteUchar( unsigned char ucVal, const char* szSep, bool bEndL)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary)
m_OutFile.write( (char*) &ucVal, sizeof( ucVal)) ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &ucVal, sizeof( ucVal)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( ucVal) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( ucVal).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteBool( bool bVal, const char* szSep, bool bEndL)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary)
m_OutFile.write( (char*) &bVal, sizeof( bVal)) ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &bVal, sizeof( bVal)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( bVal) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( bVal).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteInt( int nVal, const char* szSep, bool bEndL)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary)
m_OutFile.write( (char*) &nVal, sizeof( nVal)) ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &nVal, sizeof( nVal)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( nVal) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( nVal).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteDouble( double dVal, const char* szSep, bool bEndL, int nPrec)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary)
m_OutFile.write( (char*) &dVal, sizeof( dVal)) ;
else {
m_OutFile << ToString( dVal, nPrec) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
}
}
//----------------------------------------------------------------------------
void
NgeWriter::WriteString( const std::string& sVal, const char* szSep, bool bEndL)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary) {
int nDim = int( sVal.size()) ;
m_OutFile.write( (char*) &nDim, sizeof( nDim)) ;
m_OutFile.write( sVal.c_str(), sVal.size()) ;
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &dVal, sizeof( dVal)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << sVal ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( dVal, nPrec).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteString( const string& sVal, const char* szSep, bool bEndL)
{
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
int nDim = int( sVal.size()) ;
m_OutBinFile.write( (char*) &nDim, sizeof( nDim)) ;
m_OutBinFile.write( sVal.c_str(), sVal.size()) ;
return m_OutBinFile.good() ;
}
else {
return WriteStringOutTxt( m_OutTxtFile, sVal.c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
bool
NgeWriter::WriteVector( const Vector3d& vtV, const char* szSep, bool bEndL, int nPrec)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary)
m_OutFile.write( (char*) &vtV.v, sizeof( vtV.v)) ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &vtV.v, sizeof( vtV.v)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( vtV, nPrec) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( vtV, nPrec).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WritePoint( const Point3d& ptP, const char* szSep, bool bEndL, int nPrec)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary)
m_OutFile.write( (char*) &ptP.v, sizeof( ptP.v)) ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &ptP.v, sizeof( ptP.v)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( ptP, nPrec) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( ptP, nPrec).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WritePointW( const Point3d& ptP, double dW, const char* szSep, bool bEndL, int nPrecP, int nPrecW)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary) {
m_OutFile.write( (char*) &ptP.v, sizeof( ptP.v)) ;
m_OutFile.write( (char*) &dW, sizeof( dW)) ;
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &ptP.v, sizeof( ptP.v)) ;
m_OutBinFile.write( (char*) &dW, sizeof( dW)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( ptP, dW, nPrecP, nPrecW) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( ptP, dW, nPrecP, nPrecW).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteFrame( const Frame3d& frF, const char* szSep, bool bEndL, int nPrecP, int nPrecV)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary) {
m_OutFile.write( (char*) &frF.Orig().v, sizeof( frF.Orig().v)) ;
m_OutFile.write( (char*) &frF.VersX().v, sizeof( frF.VersX().v)) ;
m_OutFile.write( (char*) &frF.VersY().v, sizeof( frF.VersY().v)) ;
m_OutFile.write( (char*) &frF.VersZ().v, sizeof( frF.VersZ().v)) ;
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &frF.Orig().v, sizeof( frF.Orig().v)) ;
m_OutBinFile.write( (char*) &frF.VersX().v, sizeof( frF.VersX().v)) ;
m_OutBinFile.write( (char*) &frF.VersY().v, sizeof( frF.VersY().v)) ;
m_OutBinFile.write( (char*) &frF.VersZ().v, sizeof( frF.VersZ().v)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( frF, nPrecP, nPrecV) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( frF, nPrecP, nPrecV).c_str(), szSep, bEndL) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteKey( int nKey)
{
if ( ! m_OutFile.is_open())
return ;
if ( nKey < 0 || nKey > NGE_LAST_ID)
return ;
return false ;
if ( m_bBinary)
m_OutFile.write( (char*) &NgeBinKeyW[nKey], sizeof( int)) ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
m_OutBinFile.write( (char*) &NgeBinKeyW[nKey], sizeof( int)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << NgeAscKeyW[nKey] ;
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, NgeAscKeyW[nKey].c_str(), nullptr, true) ;
}
}
//----------------------------------------------------------------------------
void
bool
NgeWriter::WriteCol( const Color& cCol, const char* szSep, bool bEndL)
{
if ( ! m_OutFile.is_open())
return ;
if ( m_bBinary) {
if ( ! m_OutBinFile.is_open())
return false ;
unsigned char ucCol[4] ;
ucCol[0] = cCol.GetIntRed() ;
ucCol[1] = cCol.GetIntGreen() ;
ucCol[2] = cCol.GetIntBlue() ;
ucCol[3] = cCol.GetIntAlpha() ;
m_OutFile.write( (char*) ucCol, sizeof( ucCol)) ;
m_OutBinFile.write( (char*) ucCol, sizeof( ucCol)) ;
return m_OutBinFile.good() ;
}
else {
m_OutFile << ToString( cCol) ;
if ( szSep != nullptr)
m_OutFile << szSep ;
if ( bEndL)
m_OutFile << endl ;
return WriteStringOutTxt( m_OutTxtFile, ToString( cCol).c_str(), szSep, bEndL) ;
}
}
+19 -14
View File
@@ -18,29 +18,34 @@
#include "/EgtDev/Include/EGkColor.h"
#include <fstream>
struct gzFile_s ;
//----------------------------------------------------------------------------
class NgeWriter
{
public :
NgeWriter( void) : m_bBinary( false) {}
NgeWriter( void) : m_bBinary( false), m_OutTxtFile( nullptr) {}
~NgeWriter( void)
{ Close() ; }
bool Init( const std::string& sFileOut, bool bBinary) ;
bool Init( const std::string& sFileOut, int nFlag) ;
bool Close( void) ;
void WriteUchar( unsigned char ucVal, const char* szSep, bool bEndL = false) ;
void WriteBool( bool bVal, const char* szSep, bool bEndL = false) ;
void WriteInt( int nVal, const char* szSep, bool bEndL = false) ;
void WriteDouble( double dVal, const char* szSep, bool bEndL = false, int nPrec = 6) ;
void WriteVector( const Vector3d& vtV, const char* szSep, bool bEndL = false, int nPrec = 9) ;
void WritePoint( const Point3d& ptP, const char* szSep, bool bEndL = false, int nPrec = 6) ;
void WritePointW( const Point3d& ptP, double dW, const char* szSep, bool bEndL = false,
bool WriteUchar( unsigned char ucVal, const char* szSep, bool bEndL = false) ;
bool WriteBool( bool bVal, const char* szSep, bool bEndL = false) ;
bool WriteInt( int nVal, const char* szSep, bool bEndL = false) ;
bool WriteDouble( double dVal, const char* szSep, bool bEndL = false, int nPrec = 6) ;
bool WriteVector( const Vector3d& vtV, const char* szSep, bool bEndL = false, int nPrec = 9) ;
bool WritePoint( const Point3d& ptP, const char* szSep, bool bEndL = false, int nPrec = 6) ;
bool WritePointW( const Point3d& ptP, double dW, const char* szSep, bool bEndL = false,
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 /* bEndL = true*/) ;
void WriteCol( const Color& cCol, const char* szSep, bool bEndL = false) ;
bool WriteFrame( const Frame3d& frF, const char* szSep, bool bEndL, int nPrecP = 6, int nPrecV = 9) ;
bool WriteString( const std::string& sVal, const char* szSep, bool bEndL = false) ;
bool WriteKey( int nKey /* bEndL = true*/) ;
bool WriteCol( const Color& cCol, const char* szSep, bool bEndL = false) ;
private :
bool m_bBinary ;
std::ofstream m_OutFile ;
// per file binari
std::ofstream m_OutBinFile ;
// per file ASCII
gzFile_s* m_OutTxtFile ;
} ;
+26 -19
View File
@@ -404,34 +404,41 @@ bool
SurfTriMesh::Save( NgeWriter& ngeOut) const
{
// tolleranza lineare di costruzione
ngeOut.WriteDouble( m_dLinTol, ";") ;
if ( ! ngeOut.WriteDouble( m_dLinTol, ";"))
return false ;
// angolo limite per mediare le normali
ngeOut.WriteDouble( m_dSmoothAng, ";", true) ;
if ( ! ngeOut.WriteDouble( m_dSmoothAng, ";", true))
return false ;
// flag aperta/chiusa
ngeOut.WriteBool( m_bClosed, ";") ;
if ( ! ngeOut.WriteBool( m_bClosed, ";"))
return false ;
// numero di vertici
ngeOut.WriteInt( GetVertexSize(), ";") ;
if ( ! ngeOut.WriteInt( GetVertexSize(), ";"))
return false ;
// numero di triangoli
ngeOut.WriteInt( GetTriangleSize(), ";", true) ;
if ( ! ngeOut.WriteInt( GetTriangleSize(), ";", true))
return false ;
// ciclo sui vertici
for ( int i = 0 ; i < int( m_vVert.size()) ; ++ i) {
ngeOut.WriteInt( i, ";") ;
ngeOut.WritePoint( m_vVert[i].ptP, ";") ;
ngeOut.WriteInt( m_vVert[i].nIdTria, ";") ;
ngeOut.WriteInt( m_vVert[i].nFlag, ";", true) ;
if ( ! ngeOut.WriteInt( i, ";") ||
! ngeOut.WritePoint( m_vVert[i].ptP, ";") ||
! ngeOut.WriteInt( m_vVert[i].nIdTria, ";") ||
! ngeOut.WriteInt( m_vVert[i].nFlag, ";", true))
return false ;
}
// ciclo sui triangoli
for ( int i = 0 ; i < int( m_vTria.size()) ; ++ i) {
ngeOut.WriteInt( i, ";") ;
ngeOut.WriteInt( m_vTria[i].nIdVert[0], ",") ;
ngeOut.WriteInt( m_vTria[i].nIdVert[1], ",") ;
ngeOut.WriteInt( m_vTria[i].nIdVert[2], ";") ;
ngeOut.WriteInt( m_vTria[i].nIdAdjac[0], ",") ;
ngeOut.WriteInt( m_vTria[i].nIdAdjac[1], ",") ;
ngeOut.WriteInt( m_vTria[i].nIdAdjac[2], ";") ;
ngeOut.WriteVector( m_vTria[i].vtN, ";") ;
ngeOut.WriteInt( m_vTria[i].nTFlag, ";") ;
ngeOut.WriteInt( m_vTria[i].nEFlag, ";", true) ;
if ( ! ngeOut.WriteInt( i, ";") ||
! ngeOut.WriteInt( m_vTria[i].nIdVert[0], ",") ||
! ngeOut.WriteInt( m_vTria[i].nIdVert[1], ",") ||
! ngeOut.WriteInt( m_vTria[i].nIdVert[2], ";") ||
! ngeOut.WriteInt( m_vTria[i].nIdAdjac[0], ",") ||
! ngeOut.WriteInt( m_vTria[i].nIdAdjac[1], ",") ||
! ngeOut.WriteInt( m_vTria[i].nIdAdjac[2], ";") ||
! ngeOut.WriteVector( m_vTria[i].vtN, ";") ||
! ngeOut.WriteInt( m_vTria[i].nTFlag, ";") ||
! ngeOut.WriteInt( m_vTria[i].nEFlag, ";", true))
return false ;
}
return true ;
+1
View File
@@ -28,5 +28,6 @@
#include "/EgtDev/Include/EgtLibVer.h"
#pragma comment(lib, EGTEXTDIR "zlib/lib/zlib" EGTLIBVER ".lib")
#pragma comment(lib, EGTLIBDIR "EgtGeneral" EGTLIBVER ".lib")
#pragma comment(lib, EGTLIBDIR "EgtNumKernel" EGTLIBVER ".lib")