EgtGeomKernel 1.4a1 : gli oggetti non hanno più un nome ma un Id.
This commit is contained in:
+47
-38
@@ -15,6 +15,8 @@
|
||||
#include "stdafx.h"
|
||||
#include <iostream>
|
||||
#include <new>
|
||||
#include "/EgtDev/Include/EgnStringUtils.h"
|
||||
#include "/EgtDev/Include/EgtReleasePointer.h"
|
||||
#include "GdbObj.h"
|
||||
#include "GeomDB.h"
|
||||
|
||||
@@ -44,8 +46,8 @@ GeomDB::~GeomDB( void)
|
||||
bool
|
||||
GeomDB::Init( void)
|
||||
{
|
||||
// imposto numero minimo buckets di m_GdbNameMap
|
||||
m_GdbNameMap.rehash( 128) ;
|
||||
// imposto numero minimo buckets di m_GdbIdMap
|
||||
m_GdbIdMap.rehash( 1024) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -62,7 +64,7 @@ GeomDB::Clear( void)
|
||||
delete (*Iter) ;
|
||||
|
||||
m_GeomDB.clear() ;
|
||||
m_GdbNameMap.clear() ;
|
||||
m_GdbIdMap.clear() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -193,24 +195,24 @@ GeomDB::Save( std::ofstream& osOut)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::ExistsObj( const std::string& sName)
|
||||
GeomDB::ExistsObj( int nId)
|
||||
{
|
||||
STRPGDBO_UMAP::const_iterator Iter ;
|
||||
INTPGDBO_UMAP::const_iterator Iter ;
|
||||
|
||||
|
||||
Iter = m_GdbNameMap.find( sName) ;
|
||||
return ( Iter != m_GdbNameMap.end()) ;
|
||||
Iter = m_GdbIdMap.find( nId) ;
|
||||
return ( Iter != m_GdbIdMap.end()) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GdbObj*
|
||||
GeomDB::GetGdbObj( const std::string& sName)
|
||||
GeomDB::GetGdbObj( int nId)
|
||||
{
|
||||
STRPGDBO_UMAP::const_iterator Iter ;
|
||||
INTPGDBO_UMAP::const_iterator Iter ;
|
||||
|
||||
|
||||
Iter = m_GdbNameMap.find( sName) ;
|
||||
if ( Iter != m_GdbNameMap.end())
|
||||
Iter = m_GdbIdMap.find( nId) ;
|
||||
if ( Iter != m_GdbIdMap.end())
|
||||
return Iter->second ;
|
||||
else
|
||||
return nullptr ;
|
||||
@@ -225,57 +227,60 @@ GeomDB::AddToGeomDB( GdbObj* pGdbObj)
|
||||
return false ;
|
||||
|
||||
// verifica validità e unicità del nome
|
||||
if ( pGdbObj->m_sName.length() == 0 || ExistsObj( pGdbObj->m_sName))
|
||||
if ( pGdbObj->m_nId <= 0 || ExistsObj( pGdbObj->m_nId))
|
||||
return false ;
|
||||
|
||||
// inserisco in lista principale
|
||||
m_GeomDB.push_back( pGdbObj) ;
|
||||
|
||||
// inserisco in mappa nomi
|
||||
m_GdbNameMap[ pGdbObj->m_sName] = pGdbObj ;
|
||||
m_GdbIdMap[ pGdbObj->m_nId] = pGdbObj ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::AddGeoObj( const std::string& sName, IGeoObj* pGeoObj)
|
||||
GeomDB::AddGeoObj( int nId, IGeoObj* pGeoObj)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// assegno GeoObj a gestore puntatore con rilascio automatico
|
||||
ReleasePtr<IGeoObj> pRPGeoObj( pGeoObj) ;
|
||||
// verifico validità nome
|
||||
if ( sName.length() == 0)
|
||||
if ( nId <= 0)
|
||||
return false ;
|
||||
// verifico validità oggetto Geo
|
||||
if ( pGeoObj == nullptr || ! pGeoObj->IsValid())
|
||||
if ( ! IsValid( pRPGeoObj) || ! pRPGeoObj->IsValid())
|
||||
return false ;
|
||||
// alloco oggetto Gdb
|
||||
pGdbObj = new(nothrow) GdbObj ;
|
||||
if ( pGdbObj == nullptr)
|
||||
return false ;
|
||||
// assegno nome
|
||||
pGdbObj->m_sName = sName ;
|
||||
// assegno dati
|
||||
pGdbObj->m_pGeoObj = pGeoObj ;
|
||||
pGdbObj->m_nId = nId ;
|
||||
// assegno dati ( ma non ne trasferisco il possesso)
|
||||
pGdbObj->m_pGeoObj = Get( pRPGeoObj) ;
|
||||
// inserisco nel DB
|
||||
if ( ! AddToGeomDB( pGdbObj)) {
|
||||
delete pGdbObj ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// rilascio il possesso di GeoObj
|
||||
Release( pRPGeoObj) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
GeoObjType
|
||||
GeomDB::GetObjType( const std::string& sName)
|
||||
GeomDB::GetObjType( int nId)
|
||||
{
|
||||
const GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( sName)) == nullptr)
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
return GEO_NONE ;
|
||||
// ne identifico il tipo
|
||||
return pGdbObj->GetType() ;
|
||||
@@ -283,13 +288,13 @@ GeomDB::GetObjType( const std::string& sName)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
IGeoObj*
|
||||
GeomDB::GetGeoObj( const string& sName)
|
||||
GeomDB::GetGeoObj( int nId)
|
||||
{
|
||||
const GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// recupero l'oggetto Gdb
|
||||
if ( ( pGdbObj = GetGdbObj( sName)) == nullptr)
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
return nullptr ;
|
||||
|
||||
// restituisco il suo contenuto geometrico
|
||||
@@ -298,14 +303,18 @@ GeomDB::GetGeoObj( const string& sName)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Copy( const string& sNameSou, const string& sNameDest)
|
||||
GeomDB::Copy( int nIdSou, int nIdDest)
|
||||
{
|
||||
GdbObj* pGdoSou ;
|
||||
GdbObj* pGdoDest ;
|
||||
|
||||
|
||||
// verifico validità Id destinazione
|
||||
if ( nIdDest <= 0)
|
||||
return false ;
|
||||
|
||||
// verifico esistenza del sorgente
|
||||
if ( ( pGdoSou = GetGdbObj( sNameSou)) == nullptr)
|
||||
if ( ( pGdoSou = GetGdbObj( nIdSou)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo la copia
|
||||
@@ -313,7 +322,7 @@ GeomDB::Copy( const string& sNameSou, const string& sNameDest)
|
||||
return false ;
|
||||
|
||||
// assegno il nuovo nome
|
||||
pGdoDest->m_sName = sNameDest ;
|
||||
pGdoDest->m_nId = nIdDest ;
|
||||
|
||||
// inserisco nel DB
|
||||
if ( ! AddToGeomDB( pGdoDest)) {
|
||||
@@ -326,18 +335,18 @@ GeomDB::Copy( const string& sNameSou, const string& sNameDest)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Erase( const string& sName)
|
||||
GeomDB::Erase( int nId)
|
||||
{
|
||||
PGDBO_LIST::iterator Iter ;
|
||||
|
||||
|
||||
// elimino da mappa dei nomi
|
||||
m_GdbNameMap.erase( sName) ;
|
||||
m_GdbIdMap.erase( nId) ;
|
||||
|
||||
// elimino da lista principale
|
||||
for ( Iter = m_GeomDB.begin() ; Iter != m_GeomDB.end() ; Iter++) {
|
||||
// se oggetto cercato
|
||||
if ( (*Iter)->m_sName == sName) {
|
||||
if ( (*Iter)->m_nId == nId) {
|
||||
// lo disalloco (distruttore virtuale)
|
||||
delete( (*Iter)) ;
|
||||
// lo tolgo dalla lista
|
||||
@@ -352,13 +361,13 @@ GeomDB::Erase( const string& sName)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Translate( const string& sName, const Vector3d& vtMove)
|
||||
GeomDB::Translate( int nId, const Vector3d& vtMove)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( sName)) == nullptr)
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
@@ -367,13 +376,13 @@ GeomDB::Translate( const string& sName, const Vector3d& vtMove)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Rotate( const string& sName, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
||||
GeomDB::Rotate( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( sName)) == nullptr)
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
@@ -382,13 +391,13 @@ GeomDB::Rotate( const string& sName, const Point3d& ptAx, const Vector3d& vtAx,
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Scale( const string& sName, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ)
|
||||
GeomDB::Scale( int nId, const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( sName)) == nullptr)
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
@@ -397,13 +406,13 @@ GeomDB::Scale( const string& sName, const Point3d& ptCen, double dCoeffX, double
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
GeomDB::Mirror( const string& sName, const Point3d& ptOn, const Vector3d& vtNorm)
|
||||
GeomDB::Mirror( int nId, const Point3d& ptOn, const Vector3d& vtNorm)
|
||||
{
|
||||
GdbObj* pGdbObj ;
|
||||
|
||||
|
||||
// recupero l'oggetto
|
||||
if ( ( pGdbObj = GetGdbObj( sName)) == nullptr)
|
||||
if ( ( pGdbObj = GetGdbObj( nId)) == nullptr)
|
||||
return false ;
|
||||
|
||||
// eseguo l'operazione
|
||||
|
||||
Reference in New Issue
Block a user