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
+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) ;
}