EgtGeomKernel 1.5d7 :

- aggiunti materiali e loro gestione
- aggiunta gestione libreria materiali.
This commit is contained in:
Dario Sassi
2014-04-27 20:09:56 +00:00
parent 7e680c311f
commit 5fe590f627
21 changed files with 1020 additions and 181 deletions
+17 -8
View File
@@ -16,6 +16,7 @@
#include "Attribs.h"
#include "NgeWriter.h"
#include "NgeReader.h"
#include "GeomDB.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
@@ -28,7 +29,7 @@ static const char EQUAL = '=' ;
//----------------------------------------------------------------------------
bool
Attribs::Dump( string& sOut, const char* szNewLine) const
Attribs::Dump( const GeomDB& GDB, string& sOut, const char* szNewLine) const
{
// livello
sOut += "Lev=" ;
@@ -57,7 +58,6 @@ Attribs::Dump( string& sOut, const char* szNewLine) const
switch ( m_Material) {
case GDB_MT_COLOR : sOut += "color" ; break ;
case GDB_MT_PARENT : sOut += "by parent" ; break ;
default : sOut += ToString( m_Material) ; break ;
}
// eventuale colore
if ( m_Material == GDB_MT_COLOR) {
@@ -72,6 +72,15 @@ Attribs::Dump( string& sOut, const char* szNewLine) const
sOut += "," + ToString( m_Color.GetIntAlpha()) ;
sOut += ")" ;
}
// eventuale materiale
else if ( m_Material > GDB_MT_PARENT) {
string sMatName ;
if ( GDB.GetMaterialName( m_Material, sMatName))
sOut += " " + sMatName ;
else
sOut += " ??" ;
sOut += " (" + ToString( m_Material) + ")" ;
}
sOut += szNewLine ;
// eventuali nome e stringhe informative
STRLIST::const_iterator iIter ;
@@ -195,7 +204,7 @@ bool
Attribs::SetName( const string& sName)
{
// se nome non valido, esco con errore
if ( ! ValidString( sName))
if ( ! IsValidString( sName) || ! IsValidName( sName))
return false ;
// può essere solo la prima stringa
@@ -252,7 +261,7 @@ bool
Attribs::SetInfo( const string& sKey, const string& sVal)
{
// se chiave o valore non validi, esco con errore
if ( ! ValidString( sKey) || ! ValidString( sVal))
if ( ! IsValidString( sKey) || ! IsValidString( sVal))
return false ;
// se è il nome
@@ -282,7 +291,7 @@ bool
Attribs::GetInfo( const string& sKey, string& sVal) const
{
// se chiave non valida, esco con errore
if ( ! ValidString( sKey))
if ( ! IsValidString( sKey))
return false ;
// cerco una stringa con la chiave
@@ -302,7 +311,7 @@ bool
Attribs::RemoveInfo( const string& sKey)
{
// se chiave non valida, esco con errore
if ( ! ValidString( sKey))
if ( ! IsValidString( sKey))
return false ;
// cerco una stringa con la chiave
@@ -329,9 +338,9 @@ Attribs::FindKey( const string& sString, const string& sKey) const
//----------------------------------------------------------------------------
bool
Attribs::ValidString( const string& sString) const
Attribs::IsValidString( const string& sString) const
{
return ( sString.length() > 0 &&
return ( ! sString.empty() &&
sString.find( '\n') == string::npos &&
sString.find_first_not_of( " \t\r\n") != string::npos) ;
}
+3 -2
View File
@@ -19,6 +19,7 @@
class NgeWriter ;
class NgeReader ;
class GeomDB ;
//----------------------------------------------------------------------------
#define CLIP( nV, nMIN, nMAX) (( nV < nMIN) ? nMIN : (( nV > nMAX) ? nMAX : nV))
@@ -40,7 +41,7 @@ class Attribs
if ( pAttribs != nullptr)
*pAttribs = *(const_cast<Attribs*>(this)) ;
return pAttribs ; }
bool Dump( std::string& sOut, const char* szNewLine) const ;
bool Dump( const GeomDB& GDB, std::string& sOut, const char* szNewLine) const ;
bool Save( NgeWriter& ngeOut) const ;
bool Load( NgeReader& ngeIn) ;
void SetLevel( int nLev)
@@ -92,7 +93,7 @@ class Attribs
private :
bool DataFromString( const std::string& sParam) ;
bool FindKey( const std::string& sString, const std::string& sKey) const ;
bool ValidString( const std::string& sString) const ;
bool IsValidString( const std::string& sString) const ;
private :
unsigned char m_Data[DIM] ;
+52 -98
View File
@@ -7,7 +7,7 @@
//
//
// Modifiche : 12.03.14 DS Creazione modulo.
//
// 24.04.14 DS Agg. GetSurfBackColor.
//
//----------------------------------------------------------------------------
@@ -19,24 +19,31 @@
using namespace std ;
//------------------------- Constants ----------------------------------------
static const char* SZ_WHITE = "WHITE" ;
static const char* SZ_LGRAY = "LGRAY" ;
static const char* SZ_GRAY = "GRAY" ;
static const char* SZ_BLACK = "BLACK" ;
static const char* SZ_RED = "RED" ;
static const char* SZ_MAROON = "MAROON" ;
static const char* SZ_YELLOW = "YELLOW" ;
static const char* SZ_OLIVE = "OLIVE" ;
static const char* SZ_LIME = "LIME" ;
static const char* SZ_GREEN = "GREEN" ;
static const char* SZ_AQUA = "AQUA" ;
static const char* SZ_TEAL = "TEAL" ;
static const char* SZ_BLUE = "BLUE" ;
static const char* SZ_NAVY = "NAVY" ;
static const char* SZ_FUCHSIA = "FUCHSIA" ;
static const char* SZ_PURPLE = "PURPLE" ;
static const char* SZ_ORANGE = "ORANGE" ;
static const char* SZ_BROWN = "BROWN" ;
struct NamedColor {
const char* szName ;
Color colC ;
} ;
static const NamedColor StdColor[] = {
{ "WHITE", WHITE},
{ "LGRAY", LGRAY},
{ "GRAY", GRAY},
{ "BLACK", BLACK},
{ "RED", RED},
{ "MAROON", MAROON},
{ "YELLOW", YELLOW},
{ "OLIVE", OLIVE},
{ "LIME", LIME},
{ "GREEN", GREEN},
{ "AQUA", AQUA},
{ "TEAL", TEAL},
{ "BLUE", BLUE},
{ "NAVY", NAVY},
{ "FUCHSIA", FUCHSIA},
{ "PURPLE", PURPLE},
{ "ORANGE", ORANGE},
{ "BROWN", BROWN}
} ;
static const int NUM_STDCOLOR = ( sizeof(StdColor) / sizeof(StdColor[0]) ) ;
//----------------------------------------------------------------------------
bool
@@ -44,92 +51,28 @@ GetStdColor( const string& sName, Color& cCol)
{
string sCol = sName ;
ToUpper( sCol) ;
if ( sCol == SZ_WHITE)
cCol = WHITE ;
else if ( sCol == SZ_LGRAY)
cCol = LGRAY ;
else if ( sCol == SZ_GRAY)
cCol = GRAY ;
else if ( sCol == SZ_BLACK)
cCol = BLACK ;
else if ( sCol == SZ_RED)
cCol = RED ;
else if ( sCol == SZ_MAROON)
cCol = MAROON ;
else if ( sCol == SZ_YELLOW)
cCol = YELLOW ;
else if ( sCol == SZ_OLIVE)
cCol = OLIVE ;
else if ( sCol == SZ_LIME)
cCol = LIME ;
else if ( sCol == SZ_GREEN)
cCol = GREEN ;
else if ( sCol == SZ_AQUA)
cCol = AQUA ;
else if ( sCol == SZ_TEAL)
cCol = TEAL ;
else if ( sCol == SZ_BLUE)
cCol = BLUE ;
else if ( sCol == SZ_NAVY)
cCol = NAVY ;
else if ( sCol == SZ_FUCHSIA)
cCol = FUCHSIA ;
else if ( sCol == SZ_PURPLE)
cCol = PURPLE ;
else if ( sCol == SZ_ORANGE)
cCol = ORANGE ;
else if ( sCol == SZ_BROWN)
cCol = BROWN ;
else
return false ;
for ( int i = 0 ; i < NUM_STDCOLOR ; ++ i) {
if ( sCol == StdColor[i].szName) {
cCol = StdColor[i].colC ;
return true ;
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
GetNameOfStdColor( Color cCol, string& sName)
{
if ( cCol == WHITE)
sName = SZ_WHITE ;
else if ( cCol == LGRAY)
sName = SZ_LGRAY ;
else if ( cCol == GRAY)
sName = SZ_GRAY ;
else if ( cCol == BLACK)
sName = SZ_BLACK ;
else if ( cCol == RED)
sName = SZ_RED ;
else if ( cCol == MAROON)
sName = SZ_MAROON ;
else if ( cCol == YELLOW)
sName = SZ_YELLOW ;
else if ( cCol == OLIVE)
sName = SZ_OLIVE ;
else if ( cCol == LIME)
sName = SZ_LIME ;
else if ( cCol == GREEN)
sName = SZ_GREEN ;
else if ( cCol == AQUA)
sName = SZ_AQUA ;
else if ( cCol == TEAL)
sName = SZ_TEAL ;
else if ( cCol == BLUE)
sName = SZ_BLUE ;
else if ( cCol == NAVY)
sName = SZ_NAVY ;
else if ( cCol == FUCHSIA)
sName = SZ_FUCHSIA ;
else if ( cCol == PURPLE)
sName = SZ_PURPLE ;
else if ( cCol == ORANGE)
sName = SZ_ORANGE ;
else if ( cCol == BROWN)
sName = SZ_BROWN ;
else
return false ;
for ( int i = 0 ; i < NUM_STDCOLOR ; ++ i) {
if ( cCol == StdColor[i].colC) {
sName = StdColor[i].szName ;
return true ;
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
@@ -140,4 +83,15 @@ GetOppositeColor( Color cCol)
MAX_RGB - cCol.GetIntGreen(),
MAX_RGB - cCol.GetIntBlue(),
cCol.GetIntAlpha()) ;
}
}
//----------------------------------------------------------------------------
Color
GetSurfBackColor( Color cCol)
{
float fLum = ( cCol.GetRed() + cCol.GetGreen() + cCol.GetBlue()) / 3 ;
return Color( 0.4 * fLum + 0.2 * cCol.GetRed(),
0.4 * fLum + 0.2 * cCol.GetGreen(),
0.4 * fLum + 0.2 * cCol.GetBlue(),
cCol.GetAlpha()) ;
}
BIN
View File
Binary file not shown.
+5
View File
@@ -244,6 +244,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClCompile Include="Frame3d.cpp" />
<ClCompile Include="GdbGroup.cpp" />
<ClCompile Include="GdbIterator.cpp" />
<ClCompile Include="GdbMaterialMgr.cpp" />
<ClCompile Include="GdbObj.cpp" />
<ClCompile Include="GdbGeo.cpp" />
<ClCompile Include="GeoFrame3d.cpp" />
@@ -252,6 +253,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClCompile Include="GeoPoint3d.cpp" />
<ClCompile Include="GeoVector3d.cpp" />
<ClCompile Include="IterManager.cpp" />
<ClCompile Include="Material.cpp" />
<ClCompile Include="NgeReader.cpp" />
<ClCompile Include="OutTsc.cpp" />
<ClCompile Include="Point3d.cpp" />
@@ -292,6 +294,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClInclude Include="..\Include\EGkGeoPoint3d.h" />
<ClInclude Include="..\Include\EGkGeoCollection.h" />
<ClInclude Include="..\Include\EGkGeoVector3d.h" />
<ClInclude Include="..\Include\EGkMaterial.h" />
<ClInclude Include="..\Include\EgkObjGraphics.h" />
<ClInclude Include="..\Include\EGkPlane3d.h" />
<ClInclude Include="..\Include\EGkPoint3d.h" />
@@ -324,6 +327,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClInclude Include="GdbGroup.h" />
<ClInclude Include="GdbIterator.h" />
<ClInclude Include="GdbGeo.h" />
<ClInclude Include="GdbMaterialMgr.h" />
<ClInclude Include="GdbObj.h" />
<ClInclude Include="Attribs.h" />
<ClInclude Include="GeoConst.h" />
@@ -335,6 +339,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClInclude Include="GeoVector3d.h" />
<ClInclude Include="IdManager.h" />
<ClInclude Include="IterManager.h" />
<ClInclude Include="Material.h" />
<ClInclude Include="NgeConst.h" />
<ClInclude Include="NgeKeyW.h" />
<ClInclude Include="NgeReader.h" />
+15
View File
@@ -147,6 +147,12 @@
<ClCompile Include="NgeReader.cpp">
<Filter>File di origine\Gdb</Filter>
</ClCompile>
<ClCompile Include="Material.cpp">
<Filter>File di origine\Base</Filter>
</ClCompile>
<ClCompile Include="GdbMaterialMgr.cpp">
<Filter>File di origine\Gdb</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@@ -380,6 +386,15 @@
<ClInclude Include="NgeReader.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EGkMaterial.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="GdbMaterialMgr.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="Material.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EgtGeomKernel.rc">
+125 -23
View File
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : GdbExecutor.cpp Data : 19.01.14 Versione : 1.5a6
// File : GdbExecutor.cpp Data : 24.04.14 Versione : 1.5a6
// Contenuto : Implementazione della classe GdbExecutor.
//
//
@@ -87,6 +87,8 @@ GdbExecutor::GdbExecutor( void)
m_ExecMgr.Insert( "NAME", &GdbExecutor::ExecuteName) ;
m_ExecMgr.Insert( "INF", &GdbExecutor::ExecuteInfo) ;
m_ExecMgr.Insert( "INFO", &GdbExecutor::ExecuteInfo) ;
m_ExecMgr.Insert( "MATLIBRARY", &GdbExecutor::ExecuteMatLibrary) ;
m_ExecMgr.Insert( "MATLIB", &GdbExecutor::ExecuteMatLibrary) ;
m_ExecMgr.Insert( "COPY", &GdbExecutor::ExecuteCopy) ;
m_ExecMgr.Insert( "REL", &GdbExecutor::ExecuteRelocate) ;
m_ExecMgr.Insert( "RELOCATE", &GdbExecutor::ExecuteRelocate) ;
@@ -898,14 +900,14 @@ GdbExecutor::AddGeoObj( const string& sId, const string& sIdParent, IGeoObj* pGe
//----------------------------------------------------------------------------
int
GdbExecutor::GetIdParam( const std::string& sParam, bool bNewAllowed)
GdbExecutor::GetIdParam( const string& sParam, bool bNewAllowed)
{
return m_pParser->GetIdParam( sParam, bNewAllowed) ;
}
//----------------------------------------------------------------------------
bool
GdbExecutor::GetNamesParam( const std::string& sParam, INTVECTOR& vnNames)
GdbExecutor::GetNamesParam( const string& sParam, INTVECTOR& vnNames)
{
// divido in parti
STRVECTOR vsNames ;
@@ -934,7 +936,7 @@ GdbExecutor::GetNamesParam( const std::string& sParam, INTVECTOR& vnNames)
//----------------------------------------------------------------------------
bool
GdbExecutor::GetVectorParam( const std::string& sParam, Vector3d& vtV)
GdbExecutor::GetVectorParam( const string& sParam, Vector3d& vtV)
{
// se insieme di tre componenti
if ( sParam[0] == '(') {
@@ -993,7 +995,7 @@ GdbExecutor::GetVectorParam( const std::string& sParam, Vector3d& vtV)
//----------------------------------------------------------------------------
bool
GdbExecutor::GetPointParam( const std::string& sParam, Point3d& ptP)
GdbExecutor::GetPointParam( const string& sParam, Point3d& ptP)
{
// se insieme di tre coordinate
if ( sParam[0] == '(') {
@@ -1027,7 +1029,7 @@ GdbExecutor::GetPointParam( const std::string& sParam, Point3d& ptP)
//----------------------------------------------------------------------------
bool
GdbExecutor::GetPointWParam( const std::string& sParam, Point3d& ptP, double& dW)
GdbExecutor::GetPointWParam( const string& sParam, Point3d& ptP, double& dW)
{
// deve essere insieme di dati
if ( sParam[0] != '(')
@@ -1069,7 +1071,7 @@ GdbExecutor::GetPointWParam( const std::string& sParam, Point3d& ptP, double& dW
//----------------------------------------------------------------------------
bool
GdbExecutor::GetFrameParam( const std::string& sParam, Frame3d& frF)
GdbExecutor::GetFrameParam( const string& sParam, Frame3d& frF)
{
// se insieme di punto origine e tre versori
if ( sParam[0] == '(') {
@@ -1112,7 +1114,7 @@ GdbExecutor::GetFrameParam( const std::string& sParam, Frame3d& frF)
//----------------------------------------------------------------------------
bool
GdbExecutor::GetColorParam( const std::string& sParam, bool& bByParent, Color& cCol)
GdbExecutor::GetColorParam( const string& sParam, bool& bByParent, Color& cCol)
{
// se insieme di tre o quattro valori
if ( sParam[0] == '(') {
@@ -1352,8 +1354,8 @@ GdbExecutor::ExecuteDeselect( const string& sCmd2, const STRVECTOR& vsParams)
bool
GdbExecutor::ExecuteMaterial( const string& sCmd2, const STRVECTOR& vsParams)
{
// assegnazione colore di oggetto
if ( sCmd2.empty()) {
// assegnazione materiale di oggetto tramite colore
if ( sCmd2.empty() || sCmd2 == "COLOR") {
// devono essere 2 parametri ( Id, Colore)
if ( vsParams.size() != 2)
return false ;
@@ -1380,6 +1382,32 @@ GdbExecutor::ExecuteMaterial( const string& sCmd2, const STRVECTOR& vsParams)
}
return true ;
}
// assegnazione materiale di oggetto
else if ( sCmd2 == "MAT" || sCmd2 == "MATERIAL") {
// devono essere 2 parametri ( Id, Materiale)
if ( vsParams.size() != 2)
return false ;
// recupero lista Id
INTVECTOR vnNames ;
if ( ! GetNamesParam( vsParams[0], vnNames))
return false ;
// verifico se da padre
string sMat = vsParams[1] ;
bool bByParent = ( sMat == "BYPARENT") ;
// esecuzione impostazione colore
INTVECTOR::iterator Iter ;
for ( Iter = vnNames.begin() ; Iter != vnNames.end() ; ++Iter) {
if ( bByParent) {
if ( ! m_pGDB->SetMaterial( *Iter, GDB_MT_PARENT))
return false ;
}
else {
if ( ! m_pGDB->SetMaterial( *Iter, vsParams[1]))
return false ;
}
}
return true ;
}
// impostazione colore di default
else if ( sCmd2 == "DEF" || sCmd2 == "DEFAULT") {
// 1 parametro ( Colore)
@@ -1483,7 +1511,81 @@ GdbExecutor::ExecuteInfo( const string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteCopy( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteMatLibrary( const string& sCmd2, const STRVECTOR& vsParams)
{
if ( sCmd2 == "ADD") {
// 5 parametri ( Nome, colAmb, colDiff, colSpec, Shininess)
if ( vsParams.size() != 5)
return false ;
// colore ambiente
bool bByParent ;
Color colAmb ;
if ( ! GetColorParam( vsParams[1], bByParent, colAmb) || bByParent)
return false ;
// colore diffuso
Color colDiff ;
if ( ! GetColorParam( vsParams[2], bByParent, colDiff) || bByParent)
return false ;
// colore speculare
Color colSpec ;
if ( ! GetColorParam( vsParams[3], bByParent, colSpec) || bByParent)
return false ;
// lucentezza
double dShin ;
if ( ! FromString( vsParams[4], dShin))
return false ;
// creo il materiale
Material matM( colAmb, colDiff, colSpec, dShin) ;
// inserisco il materiale in libreria
return ( m_pGDB->AddMaterial( vsParams[0], matM) != GDB_MT_NULL) ;
}
else if ( sCmd2 == "REMOVE") {
// 1 parametro ( Nome)
if ( vsParams.size() != 1)
return false ;
// elimino il materiale
int nMat ;
if ( ( nMat = m_pGDB->FindMaterial( vsParams[0])) == GDB_MT_NULL)
return false ;
bool bInUse ;
return m_pGDB->EraseMaterial( nMat, bInUse) ;
}
else if ( sCmd2 == "MODIFY") {
// 5 parametri ( Nome, colAmb, colDiff, colSpec, Shininess)
if ( vsParams.size() != 5)
return false ;
// colore ambiente
bool bByParent ;
Color colAmb ;
if ( ! GetColorParam( vsParams[1], bByParent, colAmb) || bByParent)
return false ;
// colore diffuso
Color colDiff ;
if ( ! GetColorParam( vsParams[2], bByParent, colDiff) || bByParent)
return false ;
// colore speculare
Color colSpec ;
if ( ! GetColorParam( vsParams[3], bByParent, colSpec) || bByParent)
return false ;
// lucentezza
double dShin ;
if ( ! FromString( vsParams[4], dShin))
return false ;
// creo il materiale
Material matM( colAmb, colDiff, colSpec, dShin) ;
// modifico i dati del materiale in libreria
int nMat ;
if ( ( nMat = m_pGDB->FindMaterial( vsParams[0])) == GDB_MT_NULL)
return false ;
return m_pGDB->ModifyMaterialData( nMat, matM) ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteCopy( const string& sCmd2, const STRVECTOR& vsParams)
{
// 3 parametri ( IdSou, IdDest, ParentIdDest)
if ( vsParams.size() != 3)
@@ -1506,7 +1608,7 @@ GdbExecutor::ExecuteCopy( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteRelocate( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteRelocate( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 parametri ( Id, NewParentId)
if ( vsParams.size() != 2)
@@ -1534,7 +1636,7 @@ GdbExecutor::ExecuteRelocate( const std::string& sCmd2, const STRVECTOR& vsParam
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteErase( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteErase( const string& sCmd2, const STRVECTOR& vsParams)
{
// 1 parametro ( Nome/i)
if ( vsParams.size() != 1)
@@ -1555,7 +1657,7 @@ GdbExecutor::ExecuteErase( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteTranslate( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteTranslate( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 parametri ( Nome/i, Vettore)
if ( vsParams.size() != 2)
@@ -1599,7 +1701,7 @@ GdbExecutor::ExecuteTranslate( const std::string& sCmd2, const STRVECTOR& vsPara
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteRotate( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteRotate( const string& sCmd2, const STRVECTOR& vsParams)
{
// 4 parametri ( Nome, PtoAsse, VtAsse, AngDeg)
if ( vsParams.size() != 4)
@@ -1651,7 +1753,7 @@ GdbExecutor::ExecuteRotate( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteScale( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteScale( const string& sCmd2, const STRVECTOR& vsParams)
{
// 5 parametri ( Nome, Punto o Frame, CoeffX, CoeffY, CoeffZ)
if ( vsParams.size() != 5)
@@ -1708,7 +1810,7 @@ GdbExecutor::ExecuteScale( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteMirror( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteMirror( const string& sCmd2, const STRVECTOR& vsParams)
{
// 3 parametri ( Nome, Punto, Vettore)
if ( vsParams.size() != 3)
@@ -1756,7 +1858,7 @@ GdbExecutor::ExecuteMirror( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteInvertCurve( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteInvertCurve( const string& sCmd2, const STRVECTOR& vsParams)
{
// 1 parametro ( Nome/i)
if ( vsParams.size() != 1)
@@ -1778,7 +1880,7 @@ GdbExecutor::ExecuteInvertCurve( const std::string& sCmd2, const STRVECTOR& vsPa
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteInvertSurf( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteInvertSurf( const string& sCmd2, const STRVECTOR& vsParams)
{
// 1 parametro ( Nome/i)
if ( vsParams.size() != 1)
@@ -1800,7 +1902,7 @@ GdbExecutor::ExecuteInvertSurf( const std::string& sCmd2, const STRVECTOR& vsPar
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteTrimCurve( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteTrimCurve( const string& sCmd2, const STRVECTOR& vsParams)
{
enum SeLp { SL, EL, SP, EP} ;
@@ -1861,7 +1963,7 @@ GdbExecutor::ExecuteTrimCurve( const std::string& sCmd2, const STRVECTOR& vsPara
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteNew( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteNew( const string& sCmd2, const STRVECTOR& vsParams)
{
// nessun parametro
if ( vsParams.size() != 0)
@@ -1874,7 +1976,7 @@ GdbExecutor::ExecuteNew( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteLoad( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteLoad( const string& sCmd2, const STRVECTOR& vsParams)
{
// 1 parametro ( NomeFile)
if ( vsParams.size() != 1)
@@ -1888,7 +1990,7 @@ GdbExecutor::ExecuteLoad( const std::string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
GdbExecutor::ExecuteSave( const std::string& sCmd2, const STRVECTOR& vsParams)
GdbExecutor::ExecuteSave( const string& sCmd2, const STRVECTOR& vsParams)
{
// almeno 1 parametro ( NomeFile)
if ( vsParams.size() < 1)
+1
View File
@@ -60,6 +60,7 @@ class GdbExecutor : public IGdbExecutor
bool ExecuteMaterial( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteName( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteInfo( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteMatLibrary( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteCopy( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteRelocate( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteErase( const std::string& sCmd2, const STRVECTOR& vsParams) ;
+33
View File
@@ -573,6 +573,17 @@ GdbIterator::SetMaterial( int nMat)
return m_pCurrObj->SetMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetMaterial( int nMat, const string& sMatName)
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// assegno il materiale
return m_pGDB->SetMaterial( m_pCurrObj, sMatName) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::SetMaterial( Color cCol)
@@ -595,6 +606,17 @@ GdbIterator::GetMaterial( int& nMat) const
return m_pCurrObj->GetMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetMaterial( Material& mMat) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il materiale
return m_pGDB->GetMaterial( m_pCurrObj, mMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetMaterial( Color& cCol) const
@@ -617,6 +639,17 @@ GdbIterator::GetCalcMaterial( int& nMat) const
return m_pCurrObj->GetCalcMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcMaterial( Material& mMat) const
{
if ( m_pGDB == nullptr || m_pCurrObj == nullptr)
return false ;
// recupero il materiale
return m_pGDB->GetCalcMaterial( m_pCurrObj, mMat) ;
}
//----------------------------------------------------------------------------
bool
GdbIterator::GetCalcMaterial( Color& cCol) const
+3
View File
@@ -62,10 +62,13 @@ class GdbIterator : public IGdbIterator
virtual bool GetMark( int& nMark) const ;
virtual bool GetCalcMark( int& nMark) const ;
virtual bool SetMaterial( int nMat) ;
virtual bool SetMaterial( int nMat, const std::string& sMatName) ;
virtual bool SetMaterial( Color cCol) ;
virtual bool GetMaterial( int& nMat) const ;
virtual bool GetMaterial( Material& mMat) const ;
virtual bool GetMaterial( Color& cCol) const ;
virtual bool GetCalcMaterial( int& nMat) const ;
virtual bool GetCalcMaterial( Material& mMat) const ;
virtual bool GetCalcMaterial( Color& cCol) const ;
virtual bool SetName( const std::string& sName) ;
virtual bool GetName( std::string& sName) const ;
+265
View File
@@ -0,0 +1,265 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : GdbMaterialMgr.cpp Data : 24.04.14 Versione : 1.5d7
// Contenuto : Implementazione classe gestore materiali in GeomDB.
//
//
//
// Modifiche : 24.04.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "GdbMaterialMgr.h"
#include "NgeWriter.h"
#include "NgeReader.h"
#include "/EgtDev/Include/EGnStringUtils.h"
using namespace std ;
//----------------------------------------------------------------------------
GdbMaterialMgr::GdbMaterialMgr( void)
{
// riservo spazio per 48 materiali
m_GdbMats.reserve( 48) ;
// inserisco i materiali standard
string sName ;
Material matM ;
for ( int i = 0 ; GetStdMaterial( i, sName, matM) ; ++ i)
AddMaterial( sName, matM) ;
// salvo il numero dei materiali standard
m_nStdNum = int( m_GdbMats.size()) ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::Clear( void)
{
// cancello i materiali custom
if ( int( m_GdbMats.size()) > m_nStdNum)
m_GdbMats.resize( m_nStdNum) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::Save( NgeWriter& ngeOut) const
{
// intestazione libreria
ngeOut.WriteKey( NGE_MAT_LIB) ;
// numero di materiali custom
int nCustNum = int( m_GdbMats.size()) - m_nStdNum ;
ngeOut.WriteInt( nCustNum, ";", true) ;
// 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) ;
// 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) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::Load( NgeReader& ngeIn)
{
// lettura eventuale intestazione libreria
int nKey ;
if ( ! ngeIn.ReadKey( nKey))
return false ;
if ( nKey != NGE_MAT_LIB) {
ngeIn.UngetKey() ;
return true ;
}
// lettura numero di materiali custom
int nCustNum ;
if ( ! ngeIn.ReadInt( nCustNum, ";", true))
return false ;
// lettura dei materiali custom
for ( int i = 0 ; i < nCustNum ; ++ i) {
// Nome, Id, Tipo (1=materiale senza texture)
string sMatName ;
if ( ! ngeIn.ReadString( sMatName, ","))
return false ;
int nInd ;
if ( ! ngeIn.ReadInt( nInd, ","))
return false ;
int nType ;
if ( ! ngeIn.ReadInt( nType, ";", true))
return false ;
// dati del materiale
Color colAmb ;
if ( ! ngeIn.ReadCol( colAmb, ";"))
return false ;
Color colDiff ;
if ( ! ngeIn.ReadCol( colDiff, ";"))
return false ;
Color colSpec ;
if ( ! ngeIn.ReadCol( colSpec, ";"))
return false ;
double dShin ;
if ( ! ngeIn.ReadDouble( dShin, ";", true))
return false ;
// inserisco il materiale
int nNew = AddMaterial( sMatName, Material( colAmb, colDiff, colSpec, dShin)) ;
if ( nNew == GDB_MT_NULL || nNew != nInd)
return false ;
}
// sistemazione dei materiali cancellati
for ( int i = m_nStdNum ; i < int( m_GdbMats.size()) ; ++ i) {
if ( m_GdbMats[i].sName == "$$")
EraseMaterial( i + 1) ;
}
return true ;
}
//----------------------------------------------------------------------------
int
GdbMaterialMgr::AddMaterial( const string& sName, const Material& matM)
{
// verifico validità nome
if ( ! IsValidName( sName))
return GDB_MT_NULL ;
// se il materiale già esiste ritorno errore
if ( FindMaterial( sName) > 0)
return GDB_MT_NULL ;
// provo ad inserire al posto del primo cancellato
int nId = FindFirstErased() ;
if ( nId > GDB_MT_NULL) {
m_GdbMats[nId-1].sName = sName ;
m_GdbMats[nId-1].matM = matM ;
return nId ;
}
// aggiungo il materiale nella collezione
GdbMaterial gdbmatM ;
gdbmatM.sName = sName ;
gdbmatM.matM = matM ;
try { m_GdbMats.push_back( gdbmatM) ; }
catch (...) { return GDB_MT_NULL ; }
return int( m_GdbMats.size()) ;
}
//----------------------------------------------------------------------------
int
GdbMaterialMgr::FindFirstErased( void) const
{
for ( int i = 0 ; i < int( m_GdbMats.size()) ; ++ i) {
if ( m_GdbMats[i].sName.empty())
return ( i + 1) ;
}
return GDB_MT_NULL ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::EraseMaterial( int nId)
{
// controllo indice ( 1 based)
if ( nId <= GDB_MT_NULL || nId > int( m_GdbMats.size()))
return false ;
// se standard, non posso cancellarlo
if ( nId <= m_nStdNum)
return false ;
// se già cancellato, non devo fare alcunchè
if ( m_GdbMats[nId-1].sName.empty())
return true ;
// lo cancello
m_GdbMats[nId-1].sName.clear() ;
return true ;
}
//----------------------------------------------------------------------------
int
GdbMaterialMgr::FindMaterial( const string& sName) const
{
// verifico validità nome
if ( ! IsValidName( sName))
return GDB_MT_NULL ;
// cerco nella collezione (confronto tra nomi in maiuscolo)
string sToFind = sName ;
ToUpper( sToFind) ;
string sUpName ;
for ( int i = 0 ; i < int( m_GdbMats.size()) ; ++ i) {
sUpName = m_GdbMats[i].sName ;
ToUpper( sUpName) ;
if ( sToFind == sUpName)
return ( i + 1) ;
}
return GDB_MT_NULL ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::GetMaterial( int nId, Material& matM) const
{
if ( ! ExistsMaterial( nId))
return false ;
// recupero i dati del materiale
matM = m_GdbMats[nId-1].matM ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::GetMaterialName( int nId, string& sName) const
{
if ( ! ExistsMaterial( nId))
return false ;
// recupero il nome del materiale
sName = m_GdbMats[nId-1].sName ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::IsCustomMaterial( int nId, bool& bCustom) const
{
if ( ! ExistsMaterial( nId))
return false ;
// recupero il tipo del materiale
bCustom = ( nId > m_nStdNum) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::ModifyMaterial( int nId, const Material& matM)
{
if ( ! ExistsMaterial( nId))
return false ;
// se standard, non è modificabile
if ( nId <= m_nStdNum)
return false ;
// modifico i dati del materiale nella collezione
m_GdbMats[nId-1].matM = matM ;
return true ;
}
//----------------------------------------------------------------------------
bool
GdbMaterialMgr::ModifyMaterialName( int nId, const string& sName)
{
if ( ! ExistsMaterial( nId))
return false ;
// se standard, non è modificabile
if ( nId <= m_nStdNum)
return false ;
// verifico validità nome
if ( ! IsValidName( sName))
return false ;
// modifico il nome del materiale nella collezione
m_GdbMats[nId-1].sName = sName ;
return true ;
}
+59
View File
@@ -0,0 +1,59 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : GdbMaterialMgr.h Data : 24.04.14 Versione : 1.5d7
// Contenuto : Dichiarazione della classe gestore materiali in GeomDB.
//
//
//
// Modifiche : 24.04.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "Material.h"
#include "/EgtDev/Include/EGkGdbConst.h"
#include <vector>
class NgeWriter ;
class NgeReader ;
//----------------------------------------------------------------------------
class GdbMaterialMgr
{
public :
GdbMaterialMgr( void) ;
bool Clear( void) ;
bool Save( NgeWriter& ngeOut) const ;
bool Load( NgeReader& ngeIn) ;
int AddMaterial( const std::string& sName, const Material& matM) ;
bool EraseMaterial( int nId) ;
int FindMaterial( const std::string& sName) const ;
int GetMaxMaterialId( void) const
{ return int( m_GdbMats.size()) ; }
bool ExistsMaterial( int nId) const
{ return ( nId > GDB_MT_NULL && nId <= int( m_GdbMats.size()) && ! m_GdbMats[nId-1].sName.empty()) ; }
bool GetMaterial( int nId, Material& matM) const ;
bool GetMaterialName( int nId, std::string& sName) const ;
bool IsCustomMaterial( int nId, bool& bCustom) const ;
bool ModifyMaterial( int nId, const Material& matM) ;
bool ModifyMaterialName( int nId, const std::string& sName) ;
private :
int FindFirstErased( void) const ;
private :
class GdbMaterial
{
public :
std::string sName ;
Material matM ;
} ;
typedef std::vector< GdbMaterial> GDBMAT_VECTOR ;
private :
int m_nStdNum ;
GDBMAT_VECTOR m_GdbMats ;
} ;
+2 -2
View File
@@ -541,8 +541,8 @@ GdbObj::GetCalcMark( int& nMark) const
bool
GdbObj::SetMaterial( int nMat)
{
// per ora ammesso solo da padre (da colore si imposta con la SetColor)
if ( nMat != GDB_MT_PARENT)
// ammessi da lista materiali o da padre (da colore si imposta con la SetColor)
if ( nMat < GDB_MT_PARENT)
return false ;
// verifico esistenza (con eventuale creazione) degli attributi
+274 -27
View File
@@ -71,6 +71,8 @@ GeomDB::Clear( void)
m_IdManager.Clear() ;
// pulisco lista dei selezionati
m_SelManager.Clear() ;
// cancello i materiali custom
m_MatManager.Clear() ;
// disalloco i gruppi e gli oggetti
m_GrpRadix.Clear() ;
@@ -95,6 +97,13 @@ GeomDB::Load( const std::string& sFileIn)
return false ;
}
// leggo i materiali custom
if ( ! m_MatManager.Load( ngeIn)) {
string sOut = "GeomDbLoad : Error on pos " + ToString( ngeIn.GetCurrPos()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str())
return false ;
}
// ciclo di lettura dei nodi
bool bEnd ;
bool bOk = true ;
@@ -197,6 +206,10 @@ GeomDB::Save( const std::string& sFileOut, bool bBinary) const
// intestazione
bool bOk = SaveHeader( ngeOut) ;
// materiali custom
if ( ! m_MatManager.Save( ngeOut))
bOk = false ;
// ciclo di scrittura degli oggetti
const GdbObj* pGdbObj = m_GrpRadix.GetFirstObj() ;
while ( pGdbObj != nullptr) {
@@ -258,7 +271,7 @@ GeomDB::SaveFooter( NgeWriter& ngeOut) const
bool
GeomDB::ExistsObj( int nId) const
{
return ( (const_cast<GeomDB*>(this))->GetGdbObj( nId) != nullptr) ;
return ( GetGdbObj( nId) != nullptr) ;
}
//----------------------------------------------------------------------------
@@ -276,6 +289,21 @@ GeomDB::GetGdbObj( int nId)
return m_IdManager.FindObj( nId) ;
}
//----------------------------------------------------------------------------
const GdbObj*
GeomDB::GetGdbObj( int nId) const
{
// impossibile
if ( nId < GDB_ID_ROOT)
return nullptr ;
// radice
else if ( nId == GDB_ID_ROOT)
return &m_GrpRadix ;
// un nodo qualubque
else
return ( const_cast<IdManager&>(m_IdManager)).FindObj( nId) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::AddToGeomDB( GdbObj* pGObj, int nParentId)
@@ -374,7 +402,7 @@ GeomDB::GetGdbType( int nId) const
// recupero l'oggetto
if ( ( pGdbObj = (const_cast<GeomDB*> (this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return GDB_TY_NONE ;
// se oggetto geometrico
@@ -460,7 +488,7 @@ GeomDB::GetParentId( int nId) const
{
// recupero l'oggetto Gdb
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*> (this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return GDB_ID_NULL ;
// restituisco l'Id del padre
@@ -473,7 +501,7 @@ GeomDB::GetLocalBBox( int nId, BBox3d& b3Loc, int nFlag) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*> (this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo l'operazione
@@ -486,7 +514,7 @@ GeomDB::GetGlobalBBox( int nId, BBox3d& b3Glob, int nFlag) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*> (this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento globale del gruppo cui appartiene
@@ -504,7 +532,7 @@ GeomDB::GetRefBBox( int nId, const Frame3d& frRef, BBox3d& b3Ref, int nFlag) con
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*> (this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento globale del gruppo cui appartiene
@@ -992,7 +1020,7 @@ GeomDB::IsSelectedObj( int nId) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero lo stato
@@ -1046,15 +1074,15 @@ GeomDB::DumpAttributes( int nId, string& sOut, const char* szNewLine) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo il dump
if ( pGdbObj->m_pAttribs != nullptr)
return pGdbObj->m_pAttribs->Dump( sOut, szNewLine) ;
return pGdbObj->m_pAttribs->Dump( *this, sOut, szNewLine) ;
else {
Attribs attr ;
return attr.Dump( sOut, szNewLine) ;
return attr.Dump( *this, sOut, szNewLine) ;
}
}
@@ -1090,7 +1118,7 @@ GeomDB::GetLevel( int nId, int& nLevel) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il livello
@@ -1103,7 +1131,7 @@ GeomDB::GetCalcLevel( int nId, int& nLevel) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il livello calcolato
@@ -1142,7 +1170,7 @@ GeomDB::GetMode( int nId, int& nMode) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il modo
@@ -1155,7 +1183,7 @@ GeomDB::GetCalcMode( int nId, int& nMode) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il modo calcolato
@@ -1237,7 +1265,7 @@ GeomDB::GetStatus( int nId, int& nStat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero lo stato
@@ -1250,7 +1278,7 @@ GeomDB::GetCalcStatus( int nId, int& nStat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero lo stato calcolato
@@ -1289,7 +1317,7 @@ GeomDB::GetMark( int nId, int& nMark) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero la marcatura
@@ -1302,7 +1330,7 @@ GeomDB::GetCalcMark( int nId, int& nMark) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero la marcatura calcolata
@@ -1313,7 +1341,7 @@ GeomDB::GetCalcMark( int nId, int& nMark) const
bool
GeomDB::SetDefaultMaterial( Color cCol)
{
// recupero l'oggetto
// recupero l'oggetto radice
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( GDB_ID_ROOT)) == nullptr)
return false ;
@@ -1326,9 +1354,9 @@ GeomDB::SetDefaultMaterial( Color cCol)
bool
GeomDB::GetDefaultMaterial( Color& cCol) const
{
// recupero l'oggetto
// recupero l'oggetto radice
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( GDB_ID_ROOT)) == nullptr)
if ( ( pGdbObj = GetGdbObj( GDB_ID_ROOT)) == nullptr)
return false ;
// recupero il colore
@@ -1344,10 +1372,49 @@ GeomDB::SetMaterial( int nId, int nMat)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// verifico che il materiale esista o sia da padre
if ( ! ExistsMaterial( nMat) && nMat != GDB_MT_PARENT)
return false ;
// assegno il materiale tramite indice
return pGdbObj->SetMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMaterial( int nId, const string& sMatName)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// assegno il materiale
return SetMaterial( pGdbObj, sMatName) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMaterial( GdbObj* pGdbObj, const string& sMatName)
{
// verifico validità oggetto
if ( pGdbObj == nullptr)
return false ;
// cerco il materiale nella libreria (indice materiali 1 based)
int nIdMat = FindMaterial( sMatName) ;
if ( nIdMat <= GDB_MT_NULL)
return false ;
// recupero il materiale per assegnare anche il colore
Material mMat ;
GetMaterial( nIdMat, mMat) ;
// assegno il materiale tramite indice
return ( pGdbObj->SetMaterial( mMat.GetDiffuse()) &&
pGdbObj->SetMaterial( nIdMat)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMaterial( int nId, Color cCol)
@@ -1367,20 +1434,51 @@ GeomDB::GetMaterial( int nId, int& nMat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero l'indice del materiale
return pGdbObj->GetMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterial( int nId, Material& mMat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il materiale
return GetMaterial( pGdbObj, mMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterial( const GdbObj* pGdbObj, Material& mMat) const
{
// verifico validità oggetto
if ( pGdbObj == nullptr)
return false ;
// recupero l'indice del materiale
int nIdMat ;
if ( ! pGdbObj->GetMaterial( nIdMat) ||
nIdMat == GDB_MT_PARENT || nIdMat == GDB_MT_COLOR)
return false ;
// recupero il materiale
return GetMaterialData( nIdMat, mMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterial( int nId, Color& cCol) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il colore del materiale
@@ -1393,26 +1491,93 @@ GeomDB::GetCalcMaterial( int nId, int& nMat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero l'indice del materiale calcolato
return pGdbObj->GetCalcMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcMaterial( int nId, Material& mMat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il materiale
return GetCalcMaterial( pGdbObj, mMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcMaterial( const GdbObj* pGdbObj, Material& mMat) const
{
// verifico validità oggetto
if ( pGdbObj == nullptr)
return false ;
// recupero il materiale tramite l'indice
int nIdMat ;
if ( pGdbObj->GetCalcMaterial( nIdMat)) {
if ( nIdMat == GDB_MT_COLOR) {
Color cCol ;
if ( pGdbObj->GetCalcMaterial( cCol)) {
mMat.Set( cCol) ;
return true ;
}
}
else if ( GetMaterialData( nIdMat, mMat))
return true ;
}
// qualcosa è andato male, recupero il colore di default
Color cDef ;
GetDefaultMaterial( cDef) ;
mMat.Set( cDef) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcMaterial( int nId, Color& cCol) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il colore del materiale calcolato
return pGdbObj->GetCalcMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::UsedMaterialInGroup( int nMat, const GdbGroup* pGdbGroup) const
{
// verifico se il gruppo utilizza direttamente il materiale
int nObjMat ;
if ( pGdbGroup->GetMaterial( nObjMat) && nObjMat == nMat)
return true ;
// scandisco il gruppo
for ( const GdbObj* pGdbObj = pGdbGroup->GetFirstObj() ;
pGdbObj != nullptr ;
pGdbObj = pGdbObj->GetNext()) {
// verifico utilizzo del materiale da parte dell'oggetto
if ( pGdbObj->GetMaterial( nObjMat) && nObjMat == nMat)
return true ;
// se l'oggetto è un gruppo, devo cercare nei suoi figli
const GdbGroup* pGdbSubGrp ;
if ( ( pGdbSubGrp = ::GetGdbGroup( pGdbObj)) != nullptr) {
if ( UsedMaterialInGroup( nMat, pGdbSubGrp))
return true ;
}
}
return false ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetName( int nId, const string& sName)
@@ -1432,7 +1597,7 @@ GeomDB::GetName( int nId, string& sName) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il nome
@@ -1471,7 +1636,7 @@ GeomDB::GetInfo( int nId, const string& sKey, string& sInfo) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero l'Info
@@ -1490,3 +1655,85 @@ GeomDB::RemoveInfo( int nId, const string& sKey)
// rimuovo l'Info
return pGdbObj->RemoveInfo( sKey) ;
}
//----------------------------------------------------------------------------
// Material Library
//----------------------------------------------------------------------------
int
GeomDB::AddMaterial( const string& sName, const Material& matM)
{
return m_MatManager.AddMaterial( sName, matM) ;
}
//----------------------------------------------------------------------------
int
GeomDB::FindMaterial( const std::string& sName) const
{
return m_MatManager.FindMaterial( sName) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::EraseMaterial( int nMat, bool& bInUse)
{
// verifico validità Id
if ( nMat <= GDB_MT_NULL) {
bInUse = false ;
return false ;
}
// verifico esistenza materiale
if ( ! m_MatManager.ExistsMaterial( nMat)) {
bInUse = false ;
return true ;
}
// verifico se usato da qualche oggetto
if ( UsedMaterialInGroup( nMat, &m_GrpRadix)) {
bInUse = true ;
return false ;
}
// elimino il materiale
bInUse = false ;
return m_MatManager.EraseMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterialData( int nMat, Material& matM) const
{
return m_MatManager.GetMaterial( nMat, matM) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterialName( int nMat, std::string& sName) const
{
return m_MatManager.GetMaterialName( nMat, sName) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ExistsMaterial( int nMat) const
{
return m_MatManager.ExistsMaterial( nMat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::IsCustomMaterial( int nMat, bool& bCustom) const
{
return m_MatManager.IsCustomMaterial( nMat, bCustom) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ModifyMaterialData( int nMat, const Material& matM)
{
return m_MatManager.ModifyMaterial( nMat, matM) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ModifyMaterialName( int nMat, const std::string& sName)
{
return m_MatManager.ModifyMaterialName( nMat, sName) ;
}
+28 -5
View File
@@ -18,9 +18,9 @@
#include "IdManager.h"
#include "IterManager.h"
#include "SelManager.h"
#include "GdbMaterialMgr.h"
#include "/EgtDev/Include/EGkGeomDB.h"
class NgeWriter ;
//----------------------------------------------------------------------------
class GeomDB : public IGeomDB
@@ -107,10 +107,13 @@ class GeomDB : public IGeomDB
virtual bool SetDefaultMaterial( Color cCol) ;
virtual bool GetDefaultMaterial( Color& cCol) const ;
virtual bool SetMaterial( int nId, int nMat) ;
virtual bool SetMaterial( int nId, const std::string& sMatName) ;
virtual bool SetMaterial( int nId, Color cCol) ;
virtual bool GetMaterial( int nId, int& nMat) const ;
virtual bool GetMaterial( int nId, Material& mMat) const ;
virtual bool GetMaterial( int nId, Color& cCol) const ;
virtual bool GetCalcMaterial( int nId, int& nMat) const ;
virtual bool GetCalcMaterial( int nId, Material& mMat) const ;
virtual bool GetCalcMaterial( int nId, Color& cCol) const ;
virtual bool SetName( int nId, const std::string& sName) ;
virtual bool GetName( int nId, std::string& sName) const ;
@@ -118,16 +121,31 @@ class GeomDB : public IGeomDB
virtual bool SetInfo( int nId, const std::string& sKey, const std::string& sInfo) ;
virtual bool GetInfo( int nId, const std::string& sKey, std::string& sInfo) const ;
virtual bool RemoveInfo( int nId, const std::string& sKey) ;
// material library
virtual int AddMaterial( const std::string& sName, const Material& matM) ;
virtual int FindMaterial( const std::string& sName) const ;
virtual bool EraseMaterial( int nMat, bool& bInUse) ;
virtual bool GetMaterialData( int nMat, Material& matM) const ;
virtual bool GetMaterialName( int nMat, std::string& sName) const ;
virtual bool ExistsMaterial( int nMat) const ;
virtual bool IsCustomMaterial( int nMat, bool& bCustom) const ;
virtual bool ModifyMaterialData( int nMat, const Material& matM) ;
virtual bool ModifyMaterialName( int nMat, const std::string& sName) ;
public :
GeomDB( void) ;
private :
GdbObj* GetGdbObj( int nId) ;
const GdbObj* GetGdbObj( int nId) const ;
GdbGeo* GetGdbGeo( int nId)
{ return dynamic_cast<GdbGeo*>( GetGdbObj( nId)) ; }
const GdbGeo* GetGdbGeo( int nId) const
{ return dynamic_cast<const GdbGeo*>( GetGdbObj( nId)) ; }
GdbGroup* GetGdbGroup( int nId)
{ return dynamic_cast<GdbGroup*>( GetGdbObj( nId)) ; }
const GdbGroup* GetGdbGroup( int nId) const
{ return dynamic_cast<const GdbGroup*>( GetGdbObj( nId)) ; }
bool AddToGeomDB( GdbObj* pGObj, int nParentId) ;
bool Relocate( int nId, int nNewParentId, bool bGlob) ;
bool Erase( GdbObj* pGObj) ;
@@ -137,14 +155,19 @@ class GeomDB : public IGeomDB
bool SaveFooter( NgeWriter& ngeOut) const ;
bool SetStatus( GdbObj* pGdbObj, int nStat) ;
bool RevertStatus( GdbObj* pGdbObj) ;
bool SetMaterial( GdbObj* pGdbObj, const std::string& sMatName) ;
bool GetMaterial( const GdbObj* pGdbObj, Material& mMat) const ;
bool GetCalcMaterial( const GdbObj* pGdbObj, Material& mMat) const ;
bool UsedMaterialInGroup( int nMat, const GdbGroup* pGdbGroup) const ;
bool AddGdbIteratorToList( GdbIterator* pIter)
{ return m_IterManager.AddGdbIterator( pIter) ; }
bool RemoveGdbIteratorFromList( GdbIterator* pIter)
{ return m_IterManager.RemoveGdbIterator( pIter) ; }
private :
GdbGroup m_GrpRadix ; // gruppo radice di tutto il DB
IdManager m_IdManager ; // gestore del nuovo Id
IterManager m_IterManager ; // gestore lista iteratori attivi
SelManager m_SelManager ; // gestore lista oggetti selezionati
GdbGroup m_GrpRadix ; // gruppo radice di tutto il DB
IdManager m_IdManager ; // gestore del nuovo Id
IterManager m_IterManager ; // gestore lista iteratori attivi
SelManager m_SelManager ; // gestore lista oggetti selezionati
GdbMaterialMgr m_MatManager ; // gestore lista materiali
} ;
+88
View File
@@ -0,0 +1,88 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : Material.cpp Data : 23.04.14 Versione : 1.5d7
// Contenuto : Implementazione funzioni per gestione materiali.
//
//
//
// Modifiche : 23.04.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "Material.h"
using namespace std ;
//------------------------- Constants ----------------------------------------
const Material EMERALD( Color( 0.022, 0.175, 0.022), Color( 0.076, 0.614,0.076), Color( 0.633, 0.728, 0.633), 76.8) ;
const Material JADE( Color( 0.135, 0.223, 0.158), Color( 0.54, 0.89,0.63), Color( 0.316, 0.316, 0.316), 12.8) ;
const Material OBSIDIAN( Color( 0.054, 0.05, 0.066), Color( 0.183, 0.17,0.225), Color( 0.333, 0.329, 0.346), 38.4) ;
const Material PEARL( Color( 0.25, 0.207, 0.207), Color( 1.0, 0.829,0.829), Color( 0.297, 0.297, 0.297), 11.3) ;
const Material RUBY( Color( 0.175, 0.012, 0.012), Color( 0.614, 0.041,0.041), Color( 0.728, 0.627, 0.627), 76.8) ;
const Material TURQUOISE( Color( 0.1, 0.187, 0.175), Color( 0.396, 0.742,0.691), Color( 0.297, 0.308, 0.307), 12.8) ;
const Material BRASS( Color( 0.329, 0.224, 0.027), Color( 0.780, 0.569,0.114), Color( 0.992, 0.941, 0.808), 27.9) ;
const Material BRONZE( Color( 0.213, 0.128, 0.054), Color( 0.714, 0.429,0.181), Color( 0.394, 0.272, 0.167), 25.6) ;
const Material CHROME( Color( 0.25, 0.25, 0.25), Color( 0.4, 0.4,0.4), Color( 0.775, 0.775, 0.775), 76.8) ;
const Material COPPER( Color( 0.191, 0.074, 0.023), Color( 0.704, 0.270,0.083), Color( 0.257, 0.138, 0.086), 12.8) ;
const Material GOLD( Color( 0.247, 0.199, 0.075), Color( 0.751, 0.606, 0.226), Color( 0.797, 0.724, 0.208), 51.2) ;
const Material SILVER( Color( 0.192, 0.192, 0.192), Color( 0.508, 0.508, 0.508), Color( 0.774, 0.774, 0.774), 51.2) ;
const Material BLACKPLASTIC( Color( 0.0, 0.0, 0.0), Color( 0.01, 0.01, 0.01), Color( 0.5, 0.5, 0.5), 32) ;
const Material CYANPLASTIC( Color( 0.0, 0.1, 0.06), Color( 0.0, 0.51, 0.51), Color( 0.502, 0.502, 0.502), 32) ;
const Material GREENPLASTIC( Color( 0.0, 0.0, 0.0), Color( 0.1, 0.35, 0.1), Color( 0.45, 0.55, 0.45), 32) ;
const Material REDPLASTIC( Color( 0.0, 0.0, 0.0), Color( 0.5, 0.0, 0.0), Color( 0.7, 0.6, 0.6), 32) ;
const Material WHITEPLASTIC( Color( 0.0, 0.0, 0.0), Color( 0.55, 0.55, 0.55), Color( 0.7, 0.7, 0.7), 32) ;
const Material YELLOWPLASTIC( Color( 0.0, 0.0, 0.0), Color( 0.5, 0.5, 0.0), Color( 0.6, 0.6, 0.5), 32) ;
const Material BLACKRUBBER( Color( 0.02, 0.02, 0.02), Color( 0.01, 0.01, 0.01), Color( 0.4, 0.4, 0.4), 10) ;
const Material CYANRUBBER( Color( 0.0, 0.05, 0.05), Color( 0.4, 0.5, 0.5), Color( 0.04, 0.7, 0.7), 10) ;
const Material GREENRUBBER( Color( 0.0, 0.05, 0.0), Color( 0.4, 0.5, 0.4), Color( 0.04, 0.7, 0.04), 10) ;
const Material REDRUBBER( Color( 0.05, 0.0, 0.0), Color( 0.5, 0.4, 0.4), Color( 0.7, 0.04, 0.04), 10) ;
const Material WHITERUBBER( Color( 0.05, 0.05, 0.05), Color( 0.5, 0.5, 0.5), Color( 0.7, 0.7, 0.7), 10) ;
const Material YELLOWRUBBER( Color( 0.05, 0.05, 0.0), Color( 0.5, 0.5, 0.4), Color( 0.7, 0.7, 0.04), 10) ;
struct NamedMaterial {
const char* szName ;
Material matM ;
} ;
static const NamedMaterial StdMaterial[] = {
{ "EMERALD", EMERALD},
{ "JADE", JADE},
{ "OBSIDIAN", OBSIDIAN},
{ "PEARL", PEARL},
{ "RUBY", RUBY},
{ "TURQUOISE", TURQUOISE},
{ "BRASS", BRASS},
{ "BRONZE", BRONZE},
{ "CHROME", CHROME},
{ "COPPER", COPPER},
{ "GOLD", GOLD},
{ "SILVER", SILVER},
{ "BLACKPLASTIC", BLACKPLASTIC},
{ "CYANPLASTIC", CYANPLASTIC},
{ "GREENPLASTIC", GREENPLASTIC},
{ "REDPLASTIC", REDPLASTIC},
{ "WHITEPLASTIC", WHITEPLASTIC},
{ "YELLOWPLASTIC", YELLOWPLASTIC},
{ "BLACKRUBBER", BLACKRUBBER},
{ "CYANRUBBER", CYANRUBBER},
{ "GREENRUBBER", GREENRUBBER},
{ "REDRUBBER", REDRUBBER},
{ "WHITERUBBER", WHITERUBBER},
{ "YELLOWRUBBER", YELLOWRUBBER}
} ;
static const int NUM_STDMATERIAL = ( sizeof(StdMaterial) / sizeof(StdMaterial[0]) ) ;
//----------------------------------------------------------------------------
bool
GetStdMaterial( int nInd, string& sName, Material& mMat)
{
// verifico indice
if ( nInd < 0 || nInd >= NUM_STDMATERIAL)
return false ;
// assegno i dati
sName = StdMaterial[nInd].szName ;
mMat = StdMaterial[nInd].matM ;
return true ;
}
+19
View File
@@ -0,0 +1,19 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : EGkMaterial.h Data : 23.04.14 Versione : 1.5d7
// Contenuto : Implementazione della classe Material.
//
//
//
// Modifiche : 23.04.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGkMaterial.h"
//----------------------------------------------------------------------------
bool GetStdMaterial( int nInd, std::string& sName, Material& mMat) ;
+16 -15
View File
@@ -21,24 +21,25 @@
// versione
const int NGE_MAJOR_VER = 1 ;
const int NGE_MINOR_VER = 5 ;
const int NGE_PATCH_VER = 4 ;
const int NGE_PATCH_VER = 5 ;
// nome GDB
const std::string NGE_GEOMDB = "GeomDB" ;
// indici KeyWord
const int NGE_START = 0 ;
const int NGE_END = 1 ;
const int NGE_MAT_DEF = 2 ;
const int NGE_A = 3 ;
const int NGE_G = 4 ;
const int NGE_P = 5 ;
const int NGE_A_GRP = 6 ;
const int NGE_X_CPY = 7 ;
const int NGE_G_VEC = 8 ;
const int NGE_G_PNT = 9 ;
const int NGE_G_FRM = 10 ;
const int NGE_C_LIN = 11 ;
const int NGE_C_ARC = 12 ;
const int NGE_C_BEZ = 13 ;
const int NGE_C_CMP = 14 ;
const int NGE_S_TRM = 15 ;
const int NGE_LAST_ID = 15 ; // ultimo valore
const int NGE_MAT_LIB = 3 ;
const int NGE_A = 4 ;
const int NGE_G = 5 ;
const int NGE_P = 6 ;
const int NGE_A_GRP = 7 ;
const int NGE_X_CPY = 8 ;
const int NGE_G_VEC = 9 ;
const int NGE_G_PNT = 10 ;
const int NGE_G_FRM = 11 ;
const int NGE_C_LIN = 12 ;
const int NGE_C_ARC = 13 ;
const int NGE_C_BEZ = 14 ;
const int NGE_C_CMP = 15 ;
const int NGE_S_TRM = 16 ;
const int NGE_LAST_ID = 16 ; // ultimo valore
+2
View File
@@ -23,6 +23,7 @@
const std::string NgeAscKeyW[] = { "START", // NGE_START
"END", // NGE_END
"MAT_DEF", // NGE_MAT_DEF
"MAT_LIB", // NGE_MAT_LIB
"A", // NGE_A
"G", // NGE_G
"P", // NGE_P
@@ -48,6 +49,7 @@ const int NGEB_GEO_BASE = 0x2000 ;
const int NgeBinKeyW[] = { NGEB_GEN_BASE + 0x0F0F, // NGE_START
NGEB_GEN_BASE + 0x0FFF, // NGE_END
NGEB_GEN_BASE + 0x0100, // NGE_MAT_DEF
NGEB_GEN_BASE + 0x0101, // NGE_MAT_LIB
NGEB_GEN_BASE + 0x0200, // NGE_A
NGEB_GEN_BASE + 0x0201, // NGE_G
NGEB_GEN_BASE + 0x0202, // NGE_P
+7
View File
@@ -327,6 +327,11 @@ NgeReader::ReadString( string& sVal, const char* szSep, bool bEndL)
bool
NgeReader::ReadKey( int& nKey)
{
if ( m_bUngetKey) {
m_bUngetKey = false ;
nKey = m_nLastKey ;
return true ;
}
if ( m_bBinary) {
if ( ! m_InFile.is_open())
return false ;
@@ -339,6 +344,7 @@ NgeReader::ReadKey( int& nKey)
for ( int i = 0 ; i <= NGE_LAST_ID ; ++ i) {
if ( nVal == NgeBinKeyW[i]) {
nKey = i ;
m_nLastKey = nKey ;
return true ;
}
}
@@ -352,6 +358,7 @@ NgeReader::ReadKey( int& nKey)
for ( int i = 0 ; i <= NGE_LAST_ID ; ++ i) {
if ( m_sToken == NgeAscKeyW[i]) {
nKey = i ;
m_nLastKey = nKey ;
return true ;
}
}
+6 -1
View File
@@ -24,7 +24,7 @@
class NgeReader
{
public :
NgeReader( void) : m_iPosStart( std::string::npos) {}
NgeReader( void) : m_iPosStart( std::string::npos), m_bUngetKey( false) {}
~NgeReader( void)
{ Close() ; }
bool Init( const std::string& sFileIn) ;
@@ -40,6 +40,8 @@ class NgeReader
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*/) ;
void UngetKey( void)
{ m_bUngetKey = true ; }
bool ReadCol( Color& cCol, const char* szSep, bool bEndL = false) ;
private :
@@ -58,4 +60,7 @@ class NgeReader
std::string::size_type m_iPosStart ;
std::string m_sLine ;
std::string m_sToken ;
// unget Key
bool m_bUngetKey ;
int m_nLastKey ;
} ;