Files
EgtGeomKernel/GeomDB.cpp
T
Dario Sassi 41a38fef3b EgtGeomKernel 1.5f1 :
- aggiunta entità testo (con font Nfe e di sistema)
- in tutte le rotate ora l'angolo è in gradi
- aggiunta trasformazione Shear (scorrimento)
- aggiunta trsformazione LocToLoc
- Set/GetInfo specializzate per i diversi tipi di informazioni
- Copy e Relocate con possibilità di indicare l'entità di riferimento rispetto a cui inserire
- aggiunte trasformazioni a PolyLine.
2014-06-03 13:19:54 +00:00

2074 lines
58 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : GeomDB.cpp Data : 08.04.13 Versione : 1.3a5
// Contenuto : Implementazione della classe GeomDB.
//
//
//
// Modifiche : 22.01.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "GeomDB.h"
#include "GdbGeo.h"
#include "DllMain.h"
#include "Attribs.h"
#include "NgeReader.h"
#include "NgeWriter.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgnStringConverter.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
IGeomDB*
CreateGeomDB( void)
{
return static_cast<IGeomDB*> ( new(nothrow) GeomDB) ;
}
//----------------------------------------------------------------------------
// GeomDB
//----------------------------------------------------------------------------
GeomDB::GeomDB( void)
{
m_GrpRadix.m_nId = GDB_ID_ROOT ;
m_GrpRadix.SetMaterial( Color()) ;
}
//----------------------------------------------------------------------------
GeomDB::~GeomDB( void)
{
Clear() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Init( void)
{
// pulizia
Clear() ;
// imposto numero minimo buckets del map degli Id
m_IdManager.Init( 1024) ;
// imposto materiale di default
m_GrpRadix.SetMaterial( Color()) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Clear( void)
{
// pulisco mappa degli identificatori
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() ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Load( const std::string& sFileIn)
{
// apertura file
NgeReader ngeIn ;
if ( ! ngeIn.Init( sFileIn)) {
LOG_ERROR( GetEGkLogger(), "GeomDbLoad : Error on Init ")
return false ;
}
// leggo l'intestazione
if ( ! LoadHeader( ngeIn)) {
string sOut = "GeomDbLoad : Error on pos " + ToString( ngeIn.GetCurrPos()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str())
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 ;
do {
if ( ! LoadOneObj( ngeIn, bEnd)) {
bOk = false ;
string sOut = "GeomDbLoad : Error on pos " + ToString( ngeIn.GetCurrPos()) ;
LOG_ERROR( GetEGkLogger(), sOut.c_str())
}
} while ( ! bEnd) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
GeomDB::LoadHeader( NgeReader& ngeIn)
{
// intestazione
int nKey ;
if ( ! ngeIn.ReadKey( nKey) || nKey != NGE_START)
return false ;
string sVal ;
if ( ! ngeIn.ReadString( sVal, ",") || sVal != NGE_GEOMDB)
return false ;
int nVal ;
if ( ! ngeIn.ReadInt( nVal, "."))
return false ;
if ( ! ngeIn.ReadInt( nVal, "."))
return false ;
if ( ! ngeIn.ReadInt( nVal, ";", true))
return false ;
// materiale di default come colore
if ( ! ngeIn.ReadKey( nKey) || nKey != NGE_MAT_DEF)
return false ;
Color colDef( 0, 0, 0, 0) ;
if ( ! ngeIn.ReadCol( colDef, ";", true))
return false ;
return SetDefaultMaterial( colDef) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::LoadOneObj( NgeReader& ngeIn, bool& bEnd)
{
// in generale non è fine file
bEnd = false ;
// leggo la prossima linea : tipo di nodo
int nKey ;
if ( ! ngeIn.ReadKey( nKey))
return false ;
// se fine dati
GdbObj* pGdbObj ;
if ( nKey == NGE_END) {
bEnd = true ;
return true ;
}
// se gruppo
else if ( nKey == NGE_A_GRP) {
pGdbObj = new( nothrow) GdbGroup ;
}
// se copia TODO ("X_CPY")..
//else if ( sType == GdbCopy::GetKey) {
// pGdbObj = new( nothrow) GdbCopy ;
//}
// altrimenti oggetto geometrico
else
pGdbObj = new( nothrow) GdbGeo ;
// verifico l'oggetto GDB
if ( pGdbObj == nullptr)
return false ;
// se lettura dati e inserimento nel DB vanno bene
int nParentId ;
if ( pGdbObj->Load( nKey, ngeIn, nParentId) &&
InsertInGeomDB( pGdbObj, nParentId, GDB_SON))
return true ;
// altrimenti errore
else {
delete pGdbObj ;
return false ;
}
}
//----------------------------------------------------------------------------
bool
GeomDB::Save( const std::string& sFileOut, bool bBinary) const
{
// apertura file
NgeWriter ngeOut ;
if ( ! ngeOut.Init( sFileOut, bBinary)) {
LOG_ERROR( GetEGkLogger(), "GeomDbSave : Error on Init ")
return false ;
}
// 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) {
// recupero il livello dell'oggetto
int nLevel = GDB_LV_USER ;
pGdbObj->GetLevel( nLevel) ;
// se non temporaneo
if ( nLevel != GDB_LV_TEMP) {
// salvo l'oggetto
if ( ! pGdbObj->Save( ngeOut))
bOk = false ;
}
// passo al successivo
pGdbObj = pGdbObj->GetNext() ;
}
// terminazione
if ( ! SaveFooter( ngeOut))
bOk = false ;
// chiusura file
if ( ! ngeOut.Close())
bOk = false ;
return bOk ;
}
//----------------------------------------------------------------------------
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) ;
// materiale di default come colore
Color colDef( 0, 0, 0, 0) ;
GetDefaultMaterial( colDef) ;
ngeOut.WriteKey( NGE_MAT_DEF) ;
ngeOut.WriteCol( colDef, ";", true) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SaveFooter( NgeWriter& ngeOut) const
{
// terminazione
ngeOut.WriteKey( NGE_END) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ExistsObj( int nId) const
{
return ( GetGdbObj( nId) != nullptr) ;
}
//----------------------------------------------------------------------------
GdbObj*
GeomDB::GetGdbObj( int nId)
{
// impossibile
if ( nId < GDB_ID_ROOT)
return nullptr ;
// radice
else if ( nId == GDB_ID_ROOT)
return &m_GrpRadix ;
// un nodo qualubque
else
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::InsertInGeomDB( GdbObj* pGObj, int nRefId, int nSonBeforeAfter, bool bTestId)
{
// verifico validità oggetto puntato
if ( pGObj == nullptr)
return false ;
// se richista, verifica validità e unicità del nome
if ( bTestId && ( pGObj->m_nId <= GDB_ID_ROOT || ExistsObj( pGObj->m_nId)))
return false ;
// oggetto e riferimento non possono essere la stessa cosa
if ( pGObj->m_nId == nRefId)
return ( nSonBeforeAfter != GDB_SON) ;
// cerco il riferimento
GdbObj* pGRef = GetGdbObj( nRefId) ;
if ( pGRef == nullptr)
return false ;
// inserisco prima del riferimento
if ( nSonBeforeAfter <= GDB_BEFORE) {
if ( ! pGObj->InsertBefore( pGRef))
return false ;
}
// inserisco dopo il riferimento
else if ( nSonBeforeAfter >= GDB_AFTER) {
if ( ! pGObj->InsertAfter( pGRef))
return false ;
}
// inserisco come figlio, in coda alla lista del padre
else {
GdbGroup* pGroup = dynamic_cast<GdbGroup*> ( pGRef) ;
if ( pGroup == nullptr)
return false ;
// inserisco in coda alla lista del padre
if ( ! pGObj->AddTail( pGroup))
return false ;
}
// se richiesto, inserisco in mappa Id
if ( bTestId)
return m_IdManager.AddObj( pGObj->m_nId, pGObj) ;
else
return true ;
}
//----------------------------------------------------------------------------
int
GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame)
{
return InsertGroup( nId, nParentId, GDB_SON, frFrame) ;
}
//----------------------------------------------------------------------------
int
GeomDB::InsertGroup( int nId, int nRefId, int nSonBeforeAfter, const Frame3d& frFrame)
{
// verifico validità apparente RefId
if ( nRefId < GDB_ID_ROOT)
return GDB_ID_NULL ;
// verifico validità Id
if ( nId <= GDB_ID_ROOT)
nId = m_IdManager.GetNewId() ;
if ( ExistsObj( nId))
return GDB_ID_NULL ;
// alloco gruppo Gdb
GdbGroup* pGdbGroup = new(nothrow) GdbGroup ;
if ( pGdbGroup == nullptr)
return GDB_ID_NULL ;
// assegno identificativo
pGdbGroup->m_nId = nId ;
// assegno riferimento
pGdbGroup->m_gfrFrame.Set( frFrame) ;
// inserisco nel DB
if ( ! InsertInGeomDB( pGdbGroup, nRefId, nSonBeforeAfter)) {
delete pGdbGroup ;
return GDB_ID_NULL ;
}
return nId ;
}
//----------------------------------------------------------------------------
int
GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj)
{
return InsertGeoObj( nId, nParentId, GDB_SON, pGeoObj) ;
}
//----------------------------------------------------------------------------
int
GeomDB::InsertGeoObj( int nId, int nRefId, int nSonBeforeAfter, IGeoObj* pGeoObj)
{
// assegno GeoObj a gestore puntatore con rilascio automatico
PtrOwner<IGeoObj> pRPGeoObj( pGeoObj) ;
// verifico validità identificativo
if ( nId <= GDB_ID_ROOT)
nId = m_IdManager.GetNewId() ;
if ( ExistsObj( nId))
return GDB_ID_NULL ;
// verifico validità oggetto Geo
if ( ! IsValid( pRPGeoObj) || ! pRPGeoObj->IsValid())
return GDB_ID_NULL ;
// alloco oggetto Gdb
GdbGeo* pGdbGeo = new(nothrow) GdbGeo ;
if ( pGdbGeo == nullptr)
return GDB_ID_NULL ;
// assegno identificativo
pGdbGeo->m_nId = nId ;
// assegno dati
pGdbGeo->m_pGeoObj = Release( pRPGeoObj) ;
// inserisco nel DB
if ( ! InsertInGeomDB( pGdbGeo, nRefId, nSonBeforeAfter)) {
delete pGdbGeo ;
return GDB_ID_NULL ;
}
return nId ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetFirstInGroup( int nIdGroup) const
{
// recupero il gruppo
const GdbGroup* pGdbGroup = GetGdbGroup( nIdGroup) ;
if ( pGdbGroup == nullptr)
return GDB_ID_NULL ;
// recupero il primo oggetto del gruppo
const GdbObj* pGdbO = pGdbGroup->GetFirstObj() ;
if ( pGdbO == nullptr)
return GDB_ID_NULL ;
return ( pGdbO->m_nId) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetNext( int nId) const
{
// recupero l'oggetto
const GdbObj* pGdbObj = GetGdbObj( nId) ;
if ( pGdbObj == nullptr)
return GDB_ID_NULL ;
// recupero il successivo
const GdbObj* pGdbNext = pGdbObj->GetNext() ;
if ( pGdbNext == nullptr)
return GDB_ID_NULL ;
return ( pGdbNext->m_nId) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetLastInGroup( int nIdGroup) const
{
// recupero il gruppo
const GdbGroup* pGdbGroup = GetGdbGroup( nIdGroup) ;
if ( pGdbGroup == nullptr)
return GDB_ID_NULL ;
// recupero l'ultimo oggetto del gruppo
const GdbObj* pGdbO = pGdbGroup->GetLastObj() ;
if ( pGdbO == nullptr)
return GDB_ID_NULL ;
return ( pGdbO->m_nId) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetPrev( int nId) const
{
// recupero l'oggetto
const GdbObj* pGdbObj = GetGdbObj( nId) ;
if ( pGdbObj == nullptr)
return GDB_ID_NULL ;
// recupero il precedente
const GdbObj* pGdbPrev = pGdbObj->GetPrev() ;
if ( pGdbPrev == nullptr)
return GDB_ID_NULL ;
return ( pGdbPrev->m_nId) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetGdbType( int nId) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return GDB_TY_NONE ;
// se oggetto geometrico
if ( ::GetGdbGeo( pGdbObj) != nullptr)
return GDB_TY_GEO ;
// se gruppo
else if ( ::GetGdbGroup( pGdbObj) != nullptr)
return GDB_TY_GROUP ;
// altro
else
return GDB_TY_NONE ;
}
//----------------------------------------------------------------------------
IGeoObj*
GeomDB::GetGeoObj( int nId)
{
// recupero l'oggetto Gdb
const GdbGeo* pGdbGeo ;
if ( ( pGdbGeo = GetGdbGeo( nId)) == nullptr)
return nullptr ;
// restituisco il suo contenuto geometrico
return pGdbGeo->m_pGeoObj ;
}
//----------------------------------------------------------------------------
IGeoFrame3d*
GeomDB::GetGeoFrame( int nId)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return nullptr ;
// restituisco il suo riferimento
return &(pGdbGroup->m_gfrFrame) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetGroupFrame( int nId, Frame3d& frGrp) const
{
// recupero il gruppo Gdb
const GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = (const_cast<GeomDB*> (this))->GetGdbGroup( nId)) == nullptr)
return false ;
// copio il riferimento
frGrp = pGdbGroup->m_gfrFrame.GetFrame() ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetGroupGlobFrame( int nId, Frame3d& frGlob) const
{
// recupero il gruppo Gdb
const GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = (const_cast<GeomDB*> (this))->GetGdbGroup( nId)) == nullptr)
return false ;
// ne faccio calcolare il riferimento globale
return pGdbGroup->GetGlobFrame( frGlob) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetGroupObjs( int nId) const
{
// recupero il gruppo Gdb
const GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = (const_cast<GeomDB*> (this))->GetGdbGroup( nId)) == nullptr)
return 0 ;
// restituisco il numero di nodi (figli)
return pGdbGroup->GetObjCount() ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetParentId( int nId) const
{
// recupero l'oggetto Gdb
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return GDB_ID_NULL ;
// restituisco l'Id del padre
return pGdbObj->GetParentId() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetLocalBBox( int nId, BBox3d& b3Loc, int nFlag) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo l'operazione
return pGdbObj->GetLocalBBox( b3Loc, nFlag) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetGlobalBBox( int nId, BBox3d& b3Glob, int nFlag) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento globale del gruppo cui appartiene
Frame3d frGlob ;
if ( ! GetGroupGlobFrame( pGdbObj->GetParentId(), frGlob))
return false ;
// eseguo l'operazione
return pGdbObj->GetBBox( frGlob, b3Glob, nFlag) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetRefBBox( int nId, const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento globale del gruppo cui appartiene
Frame3d frGlob ;
if ( ! GetGroupGlobFrame( pGdbObj->GetParentId(), frGlob))
return false ;
// lo porto nel riferimento passato
frGlob.ToLoc( frRef) ;
// eseguo l'operazione
return pGdbObj->GetBBox( frGlob, b3Ref, nFlag) ;
}
//----------------------------------------------------------------------------
int
GeomDB::Copy( int nIdSou, int nIdDest, int nRefId, int nSonBeforeAfter, bool bGlob)
{
// verifico Id destinazione
if ( nIdDest <= GDB_ID_ROOT)
nIdDest = m_IdManager.GetNewId() ;
if ( ExistsObj( nIdDest))
return GDB_ID_NULL ;
// verifico esistenza del sorgente
GdbObj* pGdOSou = GetGdbObj( nIdSou) ;
if ( pGdOSou == nullptr)
return GDB_ID_NULL ;
// verifico esistenza del padre
GdbGroup* pGroupSou = pGdOSou->GetParent() ;
if ( pGroupSou == nullptr)
return false ;
// cerco il padre di destinazione
int nParentIdDest = (( nSonBeforeAfter == GDB_SON) ? nRefId : GetParentId( nRefId)) ;
GdbGroup* pGroupDest = GetGdbGroup( nParentIdDest) ;
if ( pGroupDest == nullptr)
return false ;
// eseguo la copia
PtrOwner<GdbObj> pGdODest( pGdOSou->Clone( nIdDest, m_IdManager)) ;
if ( ! ::IsValid( pGdODest))
return GDB_ID_NULL ;
// se in globale
if ( bGlob) {
// recupero il riferimento del sorgente
Frame3d frSou ;
if ( ! pGroupSou->GetGlobFrame( frSou))
return GDB_ID_NULL ;
// recupero il riferimento del gruppo destinazione
Frame3d frDest ;
if ( ! pGroupDest->GetGlobFrame( frDest))
return GDB_ID_NULL ;
// porto la copia da riferimento sorgente a quello destinazione
pGdODest->LocToLoc( frSou, frDest) ;
}
// inserisco nel DB (non rilascio il puntatore)
if ( ! InsertInGeomDB( ::Get( pGdODest), nRefId, nSonBeforeAfter))
return GDB_ID_NULL ;
// rilascio il puntatore
::Release( pGdODest) ;
return nIdDest ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Relocate( int nId, int nRefId, int nSonBeforeAfter, bool bGlob)
{
// l'oggetto e il riferimento non possono coincidere
if ( nId == nRefId)
return ( nSonBeforeAfter != GDB_SON) ;
// verifico esistenza dell'oggetto
GdbObj* pGdbObj = GetGdbObj( nId) ;
if ( pGdbObj == nullptr)
return false ;
// verifico esistenza del padre
GdbGroup* pGroup = pGdbObj->GetParent() ;
if ( pGroup == nullptr)
return false ;
// cerco il nuovo padre
int nNewParentId = (( nSonBeforeAfter == GDB_SON) ? nRefId : GetParentId( nRefId)) ;
GdbGroup* pNewGroup = GetGdbGroup( nNewParentId) ;
if ( pNewGroup == nullptr)
return false ;
// se riferimento al padre e vecchio e nuovo padre coincidono, non devo fare alcunché
if ( nSonBeforeAfter == GDB_SON && pGroup->m_nId == pNewGroup->m_nId)
return true ;
// se rilocazione in globale
if ( bGlob) {
// recupero il riferimento del sorgente
Frame3d frCurr ;
if ( ! pGroup->GetGlobFrame( frCurr))
return false ;
// recupero il riferimento del nuovo padre
Frame3d frNew ;
if ( ! pNewGroup->GetGlobFrame( frNew))
return false ;
// porto l'oggetto dal riferimento originale a quello nuovo
pGdbObj->LocToLoc( frCurr, frNew) ;
}
// sistemazioni in eventuali GdbIterator con quell'oggetto corrente
m_IterManager.ResetObjIfSame( pGdbObj) ;
// lo estraggo dalla posizione corrente del DB geometrico
pGdbObj->Remove() ;
// lo inserisco nella posizione opportuna
if ( ! InsertInGeomDB( pGdbObj, nRefId, nSonBeforeAfter, false)) {
// in caso di errore (condizione assai remota qui) cancello tutto
m_IdManager.RemoveObj( pGdbObj->m_nId) ;
m_SelManager.RemoveObj( pGdbObj) ;
delete pGdbObj ;
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Erase( int nId)
{
// non si può cancellare il gruppo radice (escludo anche Id non validi)
if ( nId <= GDB_ID_ROOT)
return false ;
// recupero l'oggetto
GdbObj* pGdbObj ;
pGdbObj = m_IdManager.FindObj( nId) ;
if ( pGdbObj == nullptr)
return false ;
return Erase( pGdbObj) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Erase( GdbObj* pGdbObj)
{
// deve essere valido
if ( pGdbObj == nullptr)
return false ;
// non si può cancellare il gruppo radice
if ( pGdbObj == &m_GrpRadix)
return false ;
// elimino da mappa dei nomi
m_IdManager.RemoveObj( pGdbObj->m_nId) ;
// eliminazione eventuale da lista dei selezionati
m_SelManager.RemoveObj( pGdbObj) ;
// sistemazioni in eventuali GdbIterator con quell'oggetto corrente
m_IterManager.ResetObjIfSame( pGdbObj) ;
// lo tolgo dalla lista
pGdbObj->Remove() ;
// lo disalloco (distruttore virtuale)
delete pGdbObj ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Translate( int nId, const Vector3d& vtMove)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo la traslazione
return pGdbObj->Translate( vtMove) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::TranslateGlob( int nId, const Vector3d& vtMove)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento in cui è immerso
Frame3d frObj ;
if ( ! GetGlobFrame( nId, frObj))
return false ;
// porto il movimento in locale
Vector3d vtMoveLoc = vtMove ;
if ( ! vtMoveLoc.ToLoc( frObj))
return false ;
// eseguo la traslazione
return pGdbObj->Translate( vtMoveLoc) ;
}
//----------------------------------------------------------------------------
// La traslazione è espressa nel riferimento del gruppo (ovvero il proprio).
//----------------------------------------------------------------------------
bool
GeomDB::TranslateGroup( int nId, const Vector3d& vtMove)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// utilizzo il riferimento proprio
// porto il movimento nel riferimento in cui è immerso
Vector3d vtMoveLoc = vtMove ;
if ( ! vtMoveLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
// eseguo la traslazione
return pGdbGroup->Translate( vtMoveLoc) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Rotate( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo la rotazione
return pGdbObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RotateGlob( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento in cui è immerso
Frame3d frObj ;
if ( ! GetGlobFrame( nId, frObj))
return false ;
// porto i parametri di rotazione in locale
Point3d ptAxLoc = ptAx ;
if ( ! ptAxLoc.ToLoc( frObj))
return false ;
Vector3d vtAxLoc = vtAx ;
if ( ! vtAxLoc.ToLoc( frObj))
return false ;
// eseguo la rotazione
return pGdbObj->Rotate( ptAxLoc, vtAxLoc, dCosAng, dSinAng) ;
}
//----------------------------------------------------------------------------
// La rotazione è espressa nel riferimento del gruppo (ovvero il proprio).
//----------------------------------------------------------------------------
bool
GeomDB::RotateGroup( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// utilizzo il riferimento proprio
// porto i parametri di rotazione nel riferimento in cui è immerso
Point3d ptAxLoc = ptAx ;
if ( ! ptAxLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
Vector3d vtAxLoc = vtAx ;
if ( ! vtAxLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
// eseguo la rotazione
return pGdbGroup->Rotate( ptAxLoc, vtAxLoc, dCosAng, dSinAng) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Scale( int nId, const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo la scalatura
return pGdbObj->Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ScaleGlob( int nId, const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento in cui è immerso
Frame3d frObj ;
if ( ! GetGlobFrame( nId, frObj))
return false ;
// porto il riferimento di scalatura in locale
Frame3d frRefLoc = frRef ;
if ( ! frRefLoc.ToLoc( frObj))
return false ;
// eseguo la scalatura
return pGdbObj->Scale( frRefLoc, dCoeffX, dCoeffY, dCoeffZ) ;
}
//----------------------------------------------------------------------------
// La scalatura è espressa nel riferimento del gruppo (ovvero il proprio).
//----------------------------------------------------------------------------
bool
GeomDB::ScaleGroup( int nId, const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// utilizzo il riferimento proprio
// porto il riferimento di scalatura nel riferimento in cui è immerso
Frame3d frRefLoc = frRef ;
if ( ! frRefLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
// eseguo la scalatura
return pGdbGroup->Scale( frRefLoc, dCoeffX, dCoeffY, dCoeffZ) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Mirror( int nId, const Point3d& ptOn, const Vector3d& vtNorm)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo l'operazione
return pGdbObj->Mirror( ptOn, vtNorm) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::MirrorGlob( int nId, const Point3d& ptOn, const Vector3d& vtNorm)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento in cui è immerso
Frame3d frObj ;
if ( ! GetGlobFrame( nId, frObj))
return false ;
// porto i parametri di mirror in locale
Point3d ptOnLoc = ptOn ;
if ( ! ptOnLoc.ToLoc( frObj))
return false ;
Vector3d vtNormLoc = vtNorm ;
if ( ! vtNormLoc.ToLoc( frObj))
return false ;
// eseguo l'operazione
return pGdbObj->Mirror( ptOnLoc, vtNormLoc) ;
}
//----------------------------------------------------------------------------
// La specchiatura è espressa nel riferimento del gruppo (ovvero il proprio).
//----------------------------------------------------------------------------
bool
GeomDB::MirrorGroup( int nId, const Point3d& ptOn, const Vector3d& vtNorm)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// utilizzo il riferimento proprio
// porto i parametri di mirror nel riferimento in cui è immerso
Point3d ptOnLoc = ptOn ;
if ( ! ptOnLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
Vector3d vtNormLoc = vtNorm ;
if ( ! vtNormLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
// eseguo l'operazione
return pGdbGroup->Mirror( ptOnLoc, vtNormLoc) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::Shear( int nId, const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo l'operazione
return pGdbObj->Shear( ptOn, vtNorm, vtDir, dCoeff) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ShearGlob( int nId, const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il riferimento in cui è immerso
Frame3d frObj ;
if ( ! GetGlobFrame( nId, frObj))
return false ;
// porto i parametri di shear in locale
Point3d ptOnLoc = ptOn ;
if ( ! ptOnLoc.ToLoc( frObj))
return false ;
Vector3d vtNormLoc = vtNorm ;
if ( ! vtNormLoc.ToLoc( frObj))
return false ;
Vector3d vtDirLoc = vtDir ;
if ( ! vtDirLoc.ToLoc( frObj))
return false ;
// eseguo l'operazione
return pGdbObj->Shear( ptOnLoc, vtNormLoc, vtDirLoc, dCoeff) ;
}
//----------------------------------------------------------------------------
// La specchiatura è espressa nel riferimento del gruppo (ovvero il proprio).
//----------------------------------------------------------------------------
bool
GeomDB::ShearGroup( int nId, const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// utilizzo il riferimento proprio
// porto i parametri di mirror nel riferimento in cui è immerso
Point3d ptOnLoc = ptOn ;
if ( ! ptOnLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
Vector3d vtNormLoc = vtNorm ;
if ( ! vtNormLoc.ToGlob( pGdbGroup->GetFrame()))
return false ;
Vector3d vtDirLoc = vtDir ;
if ( ! vtDirLoc.ToLoc( pGdbGroup->GetFrame()))
return false ;
// eseguo l'operazione
return pGdbGroup->Shear( ptOnLoc, vtNormLoc, vtDirLoc, dCoeff) ;
}
//----------------------------------------------------------------------------
// Selection
//----------------------------------------------------------------------------
bool
GeomDB::SelectObj( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
return SetStatus( pGdbObj, GDB_ST_SEL) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::DeselectObj( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// se selezionato, lo deseleziono
if ( pGdbObj->IsSelected())
return SetStatus( pGdbObj, GDB_ST_ON) ;
// altrimenti, va già bene
else
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SelectGroupObjs( int nId)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// ciclo sugli oggetti del gruppo e li seleziono
GdbObj* pGdbObj = pGdbGroup->GetFirstObj() ;
while ( pGdbObj != nullptr) {
if ( ! SetStatus( pGdbObj, GDB_ST_SEL))
return false ;
pGdbObj = pGdbObj->GetNext() ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::DeselectGroupObjs( int nId)
{
// recupero il gruppo Gdb
GdbGroup* pGdbGroup ;
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
return false ;
// ciclo sugli oggetti del gruppo e li seleziono
GdbObj* pGdbObj = pGdbGroup->GetFirstObj() ;
while ( pGdbObj != nullptr) {
// se selezionato, lo deseleziono
if ( pGdbObj->IsSelected()) {
if ( ! SetStatus( pGdbObj, GDB_ST_ON))
return false ;
}
pGdbObj = pGdbObj->GetNext() ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::IsSelectedObj( int nId) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero lo stato
return pGdbObj->IsSelected() ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetSelectedObjNbr( void) const
{
return m_SelManager.GetSize() ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetFirstSelectedObj( void) const
{
GdbObj* pGObj = m_SelManager.GetFirstObj() ;
return (( pGObj == nullptr) ? GDB_ID_NULL : pGObj->m_nId) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetNextSelectedObj( void) const
{
GdbObj* pGObj = m_SelManager.GetNextObj() ;
return (( pGObj == nullptr) ? GDB_ID_NULL : pGObj->m_nId) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ClearSelection( void)
{
GdbObj* pGObj = m_SelManager.GetFirstObj() ;
while ( pGObj != nullptr) {
m_SelManager.RemoveObj( pGObj) ;
pGObj->SetStatus( GDB_ST_ON) ;
pGObj = m_SelManager.GetFirstObj() ;
}
return true ;
}
//----------------------------------------------------------------------------
// Attributes
//----------------------------------------------------------------------------
bool
GeomDB::DumpAttributes( int nId, string& sOut, const char* szNewLine) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// eseguo il dump
if ( pGdbObj->m_pAttribs != nullptr)
return pGdbObj->m_pAttribs->Dump( *this, sOut, szNewLine) ;
else {
Attribs attr ;
return attr.Dump( *this, sOut, szNewLine) ;
}
}
//----------------------------------------------------------------------------
bool
GeomDB::SetLevel( int nId, int nLevel)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// assegno il livello
return pGdbObj->SetLevel( nLevel) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RevertLevel( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// ripristino il livello precedente
return pGdbObj->RevertLevel() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetLevel( int nId, int& nLevel) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il livello
return pGdbObj->GetLevel( nLevel) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcLevel( int nId, int& nLevel) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il livello calcolato
return pGdbObj->GetCalcLevel( nLevel) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMode( int nId, int nMode)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// assegno il modo
return pGdbObj->SetMode( nMode) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RevertMode( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// ripristino il modo precedente
return pGdbObj->RevertMode() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMode( int nId, int& nMode) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il modo
return pGdbObj->GetMode( nMode) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcMode( int nId, int& nMode) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il modo calcolato
return pGdbObj->GetCalcMode( nMode) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetStatus( int nId, int nStat)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
return SetStatus( pGdbObj, nStat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetStatus( GdbObj* pGdbObj, int nStat)
{
// verifico validità oggetto
if ( pGdbObj == nullptr)
return false ;
// recupero lo stato precedente
int nOldStat = GDB_ST_ON ;
pGdbObj->GetStatus( nOldStat) ;
// assegno lo stato
if ( ! pGdbObj->SetStatus( nStat))
return false ;
// se lo stato è cambiato
if ( nStat != nOldStat) {
// se il nuovo stato è di selezionato, inserisco oggetto in lista selezionati
if ( nStat == GDB_ST_SEL)
m_SelManager.AddObj( pGdbObj) ;
// altrimenti provo a toglierlo
else
m_SelManager.RemoveObj( pGdbObj) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RevertStatus( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
return RevertStatus( pGdbObj) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RevertStatus( GdbObj* pGdbObj)
{
// verifico validità oggetto
if ( pGdbObj == nullptr)
return false ;
// recupero lo stato precedente
int nOldStat = GDB_ST_ON ;
pGdbObj->GetStatus( nOldStat) ;
// ripristino lo stato precedente
if ( ! pGdbObj->RevertStatus())
return false ;
// recupero il nuovo stato
int nStat = GDB_ST_ON ;
pGdbObj->GetStatus( nStat) ;
// se lo stato è cambiato
if ( nStat != nOldStat) {
// se il nuovo stato è di selezionato, inserisco oggetto in lista selezionati
if ( nStat == GDB_ST_SEL)
m_SelManager.AddObj( pGdbObj) ;
// altrimenti provo a toglierlo
else
m_SelManager.RemoveObj( pGdbObj) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetStatus( int nId, int& nStat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero lo stato
return pGdbObj->GetStatus( nStat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcStatus( int nId, int& nStat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero lo stato calcolato
return pGdbObj->GetCalcStatus( nStat) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMark( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// imposto la marcatura
return pGdbObj->SetMark() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ResetMark( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// cancello la marcatura
return pGdbObj->ResetMark() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMark( int nId, int& nMark) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero la marcatura
return pGdbObj->GetMark( nMark) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcMark( int nId, int& nMark) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero la marcatura calcolata
return pGdbObj->GetCalcMark( nMark) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetDefaultMaterial( Color cCol)
{
// recupero l'oggetto radice
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( GDB_ID_ROOT)) == nullptr)
return false ;
// assegno il colore
return pGdbObj->SetMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetDefaultMaterial( Color& cCol) const
{
// recupero l'oggetto radice
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( GDB_ID_ROOT)) == nullptr)
return false ;
// recupero il colore
return pGdbObj->GetMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMaterial( int nId, int nMat)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
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 ;
GetMaterialData( nIdMat, mMat) ;
// assegno il materiale tramite indice
return ( pGdbObj->SetMaterial( mMat.GetDiffuse()) &&
pGdbObj->SetMaterial( nIdMat)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetMaterial( int nId, Color cCol)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// assegno il materiale tramite colore
return pGdbObj->SetMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterial( int nId, int& nMat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
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 = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il colore del materiale
return pGdbObj->GetMaterial( cCol) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetCalcMaterial( int nId, int& nMat) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
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 = 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::NotifyObjectsWithMaterialInGroup( int nMat, Color cCol, bool bByParent, GdbGroup* pGdbGroup)
{
// verifico se il gruppo utilizza direttamente il materiale
int nObjMat ;
// recupero il materiale
if ( ! pGdbGroup->GetMaterial( nObjMat))
nObjMat = GDB_MT_PARENT ;
// se il materiale è usato dal gruppo
bByParent = ( nObjMat == nMat || ( nObjMat == GDB_MT_PARENT && bByParent)) ;
// eventuale aggiornamento del colore
if ( nObjMat == nMat) {
pGdbGroup->SetMaterial( cCol) ;
pGdbGroup->SetMaterial( nMat) ;
}
// scandisco il gruppo
bool bOk = true ;
for ( GdbObj* pGdbObj = pGdbGroup->GetFirstObj() ;
pGdbObj != nullptr ;
pGdbObj = pGdbObj->GetNext()) {
// se sottogruppo, devo cercare nei suoi figli
GdbGroup* pGdbSubGrp ;
if ( ( pGdbSubGrp = ::GetGdbGroup( pGdbObj)) != nullptr) {
if ( ! NotifyObjectsWithMaterialInGroup( nMat, cCol, bByParent, pGdbSubGrp))
bOk = false ;
}
// altrimenti oggetto
else {
// recupero il materiale
if ( ! pGdbObj->GetMaterial( nObjMat))
nObjMat = GDB_MT_PARENT ;
// se il materiale è usato dall'oggetto
if ( nObjMat == nMat ||
( nObjMat == GDB_MT_PARENT && bByParent)) {
if ( ! pGdbObj->OnSetMaterial())
bOk = false ;
}
// eventuale aggiornamento del colore
if ( nObjMat == nMat) {
pGdbObj->SetMaterial( cCol) ;
pGdbObj->SetMaterial( nMat) ;
}
}
}
return bOk ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetName( int nId, const string& sName)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// assegno il nome
return pGdbObj->SetName( sName) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetName( int nId, string& sName) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il nome
return pGdbObj->GetName( sName) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ExistsName( int nId) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero il nome
return pGdbObj->ExistsName() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RemoveName( int nId)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// rimuovo il nome
return pGdbObj->RemoveName() ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, const string& sInfo)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// assegno l'Info
return pGdbObj->SetInfo( sKey, sInfo) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, bool bInfo)
{
return SetInfo( nId, sKey, ToString( bInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, int nInfo)
{
return SetInfo( nId, sKey, ToString( nInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, double dInfo)
{
return SetInfo( nId, sKey, ToString( dInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, const Point3d& ptInfo)
{
return SetInfo( nId, sKey, ToString( ptInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, const Vector3d& vtInfo)
{
return SetInfo( nId, sKey, ToString( vtInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::SetInfo( int nId, const string& sKey, const Frame3d& frInfo)
{
return SetInfo( nId, sKey, ToString( frInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, string& sInfo) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// recupero l'Info
return pGdbObj->GetInfo( sKey, sInfo) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, bool& bInfo) const
{
string sInfo ;
return ( GetInfo( nId, sKey, sInfo) && FromString( sInfo, bInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, int& nInfo) const
{
string sInfo ;
return ( GetInfo( nId, sKey, sInfo) && FromString( sInfo, nInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, double& dInfo) const
{
string sInfo ;
return ( GetInfo( nId, sKey, sInfo) && FromString( sInfo, dInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, Point3d& ptInfo) const
{
string sInfo ;
return ( GetInfo( nId, sKey, sInfo) && FromString( sInfo, ptInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, Vector3d& vtInfo) const
{
string sInfo ;
return ( GetInfo( nId, sKey, sInfo) && FromString( sInfo, vtInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetInfo( int nId, const string& sKey, Frame3d& frInfo) const
{
string sInfo ;
return ( GetInfo( nId, sKey, sInfo) && FromString( sInfo, frInfo)) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ExistsInfo( int nId, const string& sKey) const
{
// recupero l'oggetto
const GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// verifico l'esistenza dell'Info
return pGdbObj->ExistsInfo( sKey) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::RemoveInfo( int nId, const string& sKey)
{
// recupero l'oggetto
GdbObj* pGdbObj ;
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
return false ;
// 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.GetMaterialData( nMat, matM) ;
}
//----------------------------------------------------------------------------
bool
GeomDB::GetMaterialName( int nMat, std::string& sName) const
{
return m_MatManager.GetMaterialName( nMat, sName) ;
}
//----------------------------------------------------------------------------
int
GeomDB::GetMaxMaterialId( void) const
{
return m_MatManager.GetMaxMaterialId() ;
}
//----------------------------------------------------------------------------
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)
{
if ( ! m_MatManager.ModifyMaterialData( nMat, matM))
return false ;
// notifico gli oggetti che usano questo materiale (e gli aggiorno il colore)
NotifyObjectsWithMaterialInGroup( nMat, matM.GetDiffuse(), false, &m_GrpRadix) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GeomDB::ModifyMaterialName( int nMat, const std::string& sName)
{
return m_MatManager.ModifyMaterialName( nMat, sName) ;
}