EgtGeomKernel 1.4a3 : Migliorata gestione gruppi, aggiunti GdbIterator, GeoFrame3d e IdManager.
This commit is contained in:
+117
-62
@@ -16,7 +16,7 @@
|
||||
#include <iostream>
|
||||
#include <new>
|
||||
#include "/EgtDev/Include/EgnStringUtils.h"
|
||||
#include "/EgtDev/Include/EgtReleasePointer.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include "GdbObj.h"
|
||||
#include "GeomDB.h"
|
||||
|
||||
@@ -34,7 +34,7 @@ CreateGeomDB( void)
|
||||
//----------------------------------------------------------------------------
|
||||
GeomDB::GeomDB( void)
|
||||
{
|
||||
m_GrpRadix.m_nId = 0 ;
|
||||
m_GrpRadix.m_nId = GDB_ID_ROOT ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -233,7 +233,7 @@ GeomDB::AddToGeomDB( GdbNode* pGNode, int nParentId)
|
||||
return false ;
|
||||
|
||||
// verifica validità e unicità del nome
|
||||
if ( pGNode->m_nId <= 0 || ExistsNode( pGNode->m_nId))
|
||||
if ( pGNode->m_nId <= GDB_ID_ROOT || ExistsNode( pGNode->m_nId))
|
||||
return false ;
|
||||
|
||||
// cerco il padre
|
||||
@@ -244,82 +244,99 @@ GeomDB::AddToGeomDB( GdbNode* pGNode, int nParentId)
|
||||
if ( ! pGNode->AddTail( pGroup))
|
||||
return false ;
|
||||
|
||||
// aggiorno gestore Id
|
||||
m_IdManager.UpdateMaxId( pGNode->m_nId) ;
|
||||
|
||||
// inserisco in mappa nomi
|
||||
return m_GdbIdMap.insert( pair< int, GdbNode*>( pGNode->m_nId, pGNode)).second ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::AddGroup( int nId, int nParentId)
|
||||
int
|
||||
GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame)
|
||||
{
|
||||
GdbGroup* pGdbGroup ;
|
||||
|
||||
|
||||
// verifico validità Id e ParentId
|
||||
if ( nId <= 0 || nParentId < 0)
|
||||
return false ;
|
||||
// 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 ( ExistsNode( nId))
|
||||
return GDB_ID_NULL ;
|
||||
// alloco gruppo Gdb
|
||||
pGdbGroup = new(nothrow) GdbGroup ;
|
||||
if ( pGdbGroup == nullptr)
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
// assegno identificativo
|
||||
pGdbGroup->m_nId = nId ;
|
||||
// assegno dati
|
||||
// TODO ...
|
||||
// assegno riferimento
|
||||
pGdbGroup->m_gfrFrame.m_frF = frFrame ;
|
||||
// inserisco nel DB
|
||||
if ( ! AddToGeomDB( pGdbGroup, nParentId)) {
|
||||
delete pGdbGroup ;
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return nId ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
int
|
||||
GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// assegno GeoObj a gestore puntatore con rilascio automatico
|
||||
ReleasePtr<IGeoObj> pRPGeoObj( pGeoObj) ;
|
||||
PtrOwner<IGeoObj> pRPGeoObj( pGeoObj) ;
|
||||
// verifico validità identificativo
|
||||
if ( nId <= 0)
|
||||
return false ;
|
||||
if ( nId <= GDB_ID_ROOT)
|
||||
nId = m_IdManager.GetNewId() ;
|
||||
if ( ExistsNode( nId))
|
||||
return GDB_ID_NULL ;
|
||||
// verifico validità oggetto Geo
|
||||
if ( ! IsValid( pRPGeoObj) || ! pRPGeoObj->IsValid())
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
// alloco oggetto Gdb
|
||||
pGdbObj = new(nothrow) GdbObj ;
|
||||
if ( pGdbObj == nullptr)
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
// assegno identificativo
|
||||
pGdbObj->m_nId = nId ;
|
||||
// assegno dati ( ma non ne trasferisco il possesso)
|
||||
pGdbObj->m_pGeoObj = Get( pRPGeoObj) ;
|
||||
// assegno dati
|
||||
pGdbObj->m_pGeoObj = Release( pRPGeoObj) ;
|
||||
// inserisco nel DB
|
||||
if ( ! AddToGeomDB( pGdbObj, nParentId)) {
|
||||
delete pGdbObj ;
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
// rilascio il possesso di GeoObj
|
||||
Release( pRPGeoObj) ;
|
||||
return true ;
|
||||
|
||||
return nId ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GeoObjType
|
||||
GeomDB::GetObjType( int nId) const
|
||||
GdbType
|
||||
GeomDB::GetGdbType( int nId) const
|
||||
{
|
||||
const GdbObj* pGdbObj ;
|
||||
const GdbNode* pGdbNode ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = (const_cast<GeomDB*>(this))->GetGdbObj( nId)) == nullptr)
|
||||
return GEO_NONE ;
|
||||
// ne identifico il tipo
|
||||
return pGdbObj->GetType() ;
|
||||
// recupero il nodo
|
||||
if ( ( pGdbNode = (const_cast<GeomDB*> (this))->GetGdbNode( nId)) == nullptr)
|
||||
return GDB_NONE ;
|
||||
|
||||
// se oggetto geometrico
|
||||
if ( ::GetGdbObj( pGdbNode) != nullptr)
|
||||
return GDB_GEO ;
|
||||
// se gruppo
|
||||
else if ( ::GetGdbGroup( pGdbNode) != nullptr)
|
||||
return GDB_GROUP ;
|
||||
// altro
|
||||
else
|
||||
return GDB_NONE ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -337,33 +354,80 @@ GeomDB::GetGeoObj( int nId)
|
||||
return pGdbObj->m_pGeoObj ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Frame3d*
|
||||
GeomDB::GetGroupFrame( int nId)
|
||||
{
|
||||
GdbGroup* pGdbGroup ;
|
||||
|
||||
|
||||
// recupero il gruppo Gdb
|
||||
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
|
||||
return nullptr ;
|
||||
|
||||
// restituisco il suo riferimento
|
||||
return &(pGdbGroup->m_gfrFrame.m_frF) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::GetGroupGlobFrame( int nId, Frame3d& frGlob)
|
||||
{
|
||||
GdbGroup* pGdbGroup ;
|
||||
|
||||
|
||||
// recupero il gruppo Gdb
|
||||
if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// ne faccio calcolare il riferimento globale
|
||||
return pGdbGroup->GetGlobFrame( frGlob) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
GeomDB::GetParentId( int nId)
|
||||
{
|
||||
GdbNode* pGdbNode ;
|
||||
|
||||
|
||||
// recupero il nodo Gdb
|
||||
if ( ( pGdbNode = GetGdbNode( nId)) == nullptr)
|
||||
return GDB_ID_NULL ;
|
||||
|
||||
// restituisco l'Id del padre
|
||||
return pGdbNode->GetParentId() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
GeomDB::Copy( int nIdSou, int nIdDest, int nParentIdDest)
|
||||
{
|
||||
GdbNode* pGdNSou ;
|
||||
GdbNode* pGdNDest ;
|
||||
|
||||
|
||||
// verifico validità Id destinazione
|
||||
if ( nIdDest <= 0 || ExistsNode( nIdDest))
|
||||
return false ;
|
||||
// verifico Id destinazione
|
||||
if ( nIdDest <= GDB_ID_ROOT)
|
||||
nIdDest = m_IdManager.GetNewId() ;
|
||||
if ( ExistsNode( nIdDest))
|
||||
return GDB_ID_NULL ;
|
||||
|
||||
// verifico esistenza del sorgente
|
||||
if ( ( pGdNSou = GetGdbNode( nIdSou)) == nullptr)
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
|
||||
// eseguo la copia
|
||||
if ( ( pGdNDest = pGdNSou->Clone( nIdDest)) == nullptr)
|
||||
return false ;
|
||||
if ( ( pGdNDest = pGdNSou->Clone( nIdDest, m_IdManager)) == nullptr)
|
||||
return GDB_ID_NULL ;
|
||||
|
||||
// inserisco nel DB
|
||||
if ( ! AddToGeomDB( pGdNDest, nParentIdDest)) {
|
||||
delete pGdNDest ;
|
||||
return false ;
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return nIdDest ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -396,54 +460,45 @@ GeomDB::Erase( int nId)
|
||||
bool
|
||||
GeomDB::Translate( int nId, const Vector3d& vtMove)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
GdbNode* pGdbNode ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
if ( ( pGdbNode = GetGdbNode( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
if ( pGdbObj->m_pGeoObj != nullptr)
|
||||
return pGdbObj->m_pGeoObj->Translate( vtMove) ;
|
||||
else
|
||||
return false ;
|
||||
// eseguo la traslazione
|
||||
return pGdbNode->Translate( vtMove) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Rotate( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
GdbNode* pGdbNode ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
if ( ( pGdbNode = GetGdbNode( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
if ( pGdbObj->m_pGeoObj != nullptr)
|
||||
return pGdbObj->m_pGeoObj->Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
|
||||
else
|
||||
return false ;
|
||||
// eseguo la rotazione
|
||||
return pGdbNode->Rotate( ptAx, vtAx, dCosAng, dSinAng) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Scale( int nId, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
GdbNode* pGdbNode ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
if ( ( pGdbNode = GetGdbNode( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
if ( pGdbObj->m_pGeoObj != nullptr)
|
||||
return pGdbObj->m_pGeoObj->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ;
|
||||
else
|
||||
return false ;
|
||||
// eseguo la scalatura
|
||||
return pGdbNode->Scale( ptCen, dCoeffX, dCoeffY, dCoeffZ) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user