5fe590f627
- aggiunti materiali e loro gestione - aggiunta gestione libreria materiali.
1740 lines
48 KiB
C++
1740 lines
48 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) &&
|
|
AddToGeomDB( pGdbObj, nParentId))
|
|
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::AddToGeomDB( GdbObj* pGObj, int nParentId)
|
|
{
|
|
// verifico validità oggetto puntato
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
|
|
// verifica validità e unicità del nome
|
|
if ( pGObj->m_nId <= GDB_ID_ROOT || ExistsObj( pGObj->m_nId))
|
|
return false ;
|
|
|
|
// cerco il padre
|
|
GdbGroup* pGroup = GetGdbGroup( nParentId) ;
|
|
if ( pGroup == nullptr)
|
|
return false ;
|
|
// inserisco in coda alla lista del padre
|
|
if ( ! pGObj->AddTail( pGroup))
|
|
return false ;
|
|
|
|
// inserisco in mappa Id
|
|
return m_IdManager.AddObj( pGObj->m_nId, pGObj) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame)
|
|
{
|
|
GdbGroup* pGdbGroup ;
|
|
|
|
|
|
// verifico validità ParentId
|
|
if ( nParentId < 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
|
|
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 ( ! AddToGeomDB( pGdbGroup, nParentId)) {
|
|
delete pGdbGroup ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj)
|
|
{
|
|
GdbGeo* pGdbGeo ;
|
|
|
|
|
|
// 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
|
|
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 ( ! AddToGeomDB( pGdbGeo, nParentId)) {
|
|
delete pGdbGeo ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
GeomDB::GetGdbType( int nId) const
|
|
{
|
|
const GdbObj* pGdbObj ;
|
|
|
|
|
|
// recupero l'oggetto
|
|
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 nParentIdDest)
|
|
{
|
|
// 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 ;
|
|
if ( ( pGdOSou = GetGdbObj( nIdSou)) == nullptr)
|
|
return GDB_ID_NULL ;
|
|
|
|
// eseguo la copia
|
|
GdbObj* pGdODest ;
|
|
if ( ( pGdODest = pGdOSou->Clone( nIdDest, m_IdManager)) == nullptr)
|
|
return GDB_ID_NULL ;
|
|
|
|
// inserisco nel DB
|
|
if ( ! AddToGeomDB( pGdODest, nParentIdDest)) {
|
|
delete pGdODest ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
return nIdDest ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
GeomDB::CopyGlob( int nIdSou, int nIdDest, int nParentIdDest)
|
|
{
|
|
// 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 ;
|
|
|
|
// recupero il riferimento del sorgente
|
|
Frame3d frSou ;
|
|
if ( ! GetGlobFrame( nIdSou, frSou))
|
|
return false ;
|
|
|
|
// recupero il riferimento del gruppo destinazione
|
|
Frame3d frDest ;
|
|
if ( ! GetGroupGlobFrame( nParentIdDest, frDest))
|
|
return false ;
|
|
|
|
// eseguo la copia
|
|
GdbObj* pGdODest ;
|
|
if ( ( pGdODest = pGdOSou->Clone( nIdDest, m_IdManager)) == nullptr)
|
|
return GDB_ID_NULL ;
|
|
|
|
// porto la copia da riferimento sorgente a quello destinazione
|
|
if ( ! AreSameFrame( frSou, frDest)) {
|
|
pGdODest->ToGlob( frSou) ;
|
|
pGdODest->ToLoc( frDest) ;
|
|
}
|
|
|
|
// inserisco nel DB
|
|
if ( ! AddToGeomDB( pGdODest, nParentIdDest)) {
|
|
delete pGdODest ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
return nIdDest ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GeomDB::Relocate( int nId, int nNewParentId, bool bGlob)
|
|
{
|
|
// 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
|
|
GdbGroup* pNewGroup = GetGdbGroup( nNewParentId) ;
|
|
if ( pNewGroup == nullptr)
|
|
return false ;
|
|
|
|
// se vecchio e nuovo padre coincidono, non devo fare alcunché
|
|
if ( 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
|
|
if ( ! AreSameFrame( frCurr, frNew)) {
|
|
pGdbObj->ToGlob( frCurr) ;
|
|
pGdbObj->ToLoc( 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 in coda alla lista del padre
|
|
if ( ! pGdbObj->AddTail( pNewGroup)) {
|
|
// 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) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// 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 ;
|
|
|
|
// assegno lo stato
|
|
if ( ! pGdbObj->SetStatus( nStat))
|
|
return false ;
|
|
|
|
// se il nuovo stato è 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 ;
|
|
|
|
// ripristino lo stato precedente
|
|
if ( ! pGdbObj->RevertStatus())
|
|
return false ;
|
|
|
|
// se il nuovo stato è selezionato, inserisco oggetto in lista selezionati
|
|
int nStat = GDB_ST_ON ;
|
|
if ( pGdbObj->GetStatus( nStat) && 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 ;
|
|
GetMaterial( 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::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::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::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::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.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) ;
|
|
}
|