EgtGraphics 1.5b2 :
- aggiunta gestione ObjNewGraphics e ObjOldGraphics.
This commit is contained in:
+107
-14
@@ -14,6 +14,8 @@
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "ObjOldGraphics.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "/EgtDev/Include/EgtILogger.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EGkFrame3d.h"
|
||||
@@ -54,6 +56,26 @@ FrameToOpenGlMatrix( const Frame3d& frFrame, double Matrix[OGLMAT_DIM])
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ObjEGrGraphics*
|
||||
CreateObjEGrGraphics( bool bNewWay)
|
||||
{
|
||||
if ( bNewWay)
|
||||
return ( new ObjNewGraphics) ;
|
||||
else
|
||||
return ( new ObjOldGraphics) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::UpdateExtension( void)
|
||||
{
|
||||
BBox3d b3Ext ;
|
||||
if ( ! m_pGeomDB->GetLocalBBox( GDB_ID_ROOT, b3Ext))
|
||||
return false ;
|
||||
return SetExtension( b3Ext) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawGroup( int nId)
|
||||
@@ -62,7 +84,7 @@ Scene::DrawGroup( int nId)
|
||||
Frame3d frFrame ;
|
||||
if ( ! m_pGeomDB->GetGroupFrame( nId, frFrame))
|
||||
return false ;
|
||||
// se non è identità, lo imposto nello stack delle matrici MODELVIEW di OpenGL
|
||||
// se non è identità, lo aggiungo sullo stack delle matrici MODELVIEW di OpenGL
|
||||
bool bMatrix = ( frFrame.GetType() != Frame3d::TOP || ! frFrame.Orig().IsSmall()) ;
|
||||
if ( bMatrix) {
|
||||
glPushMatrix() ;
|
||||
@@ -78,26 +100,25 @@ Scene::DrawGroup( int nId)
|
||||
pIter->SetGDB( m_pGeomDB) ;
|
||||
bool bNext = pIter->GoToFirstInGroup( nId) ;
|
||||
while ( bNext) {
|
||||
// leggo il tipo di nodo
|
||||
int nGdbType = pIter->GetGdbType() ;
|
||||
// se oggetto geometrico
|
||||
if ( nGdbType == GDB_GEO) {
|
||||
const ICurve* pCurve ;
|
||||
// se curva, la emetto
|
||||
if ( ( pCurve = GetCurve( pIter->GetGeoObj())) != nullptr) {
|
||||
bool bFound ;
|
||||
PolyLine PL ;
|
||||
Point3d ptP ;
|
||||
pCurve->ApproxWithLines( 0.1, 5, PL) ;
|
||||
glBegin( GL_LINE_STRIP) ;
|
||||
for ( bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) {
|
||||
glVertex3f( (GLfloat)ptP.x, (GLfloat)ptP.y, (GLfloat)ptP.z) ;
|
||||
}
|
||||
glEnd() ;
|
||||
}
|
||||
// lo recupero
|
||||
IGeoObj* pGeoObj = pIter->GetGeoObj() ;
|
||||
if ( pGeoObj == nullptr)
|
||||
return false ;
|
||||
// lo disegno
|
||||
if ( ! DrawGeoObj( pGeoObj))
|
||||
return false ;
|
||||
}
|
||||
// se gruppo
|
||||
else if ( nGdbType == GDB_GROUP) {
|
||||
// lo disegno
|
||||
if ( ! DrawGroup( pIter->GetId()))
|
||||
return false ;
|
||||
}
|
||||
// passo al successivo
|
||||
bNext = pIter->GoToNext() ;
|
||||
}
|
||||
// se necessario, ripristino lo stack delle matrici
|
||||
@@ -106,3 +127,75 @@ Scene::DrawGroup( int nId)
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawGeoObj( IGeoObj* pGeoObj)
|
||||
{
|
||||
// se non esiste grafica associata, la creo
|
||||
if ( pGeoObj->GetObjGraphics() == nullptr) {
|
||||
ObjEGrGraphics* pGraphics = CreateObjEGrGraphics( m_bNewWay) ;
|
||||
if ( pGraphics == nullptr)
|
||||
return false ;
|
||||
pGraphics->SetScene( this) ;
|
||||
pGeoObj->SetObjGraphics( pGraphics) ;
|
||||
}
|
||||
// leggo il tipo di oggetto geometrico
|
||||
int nGeoType = pGeoObj->GetType() ;
|
||||
// se curva
|
||||
if ( ( nGeoType & GEO_CURVE) != 0) {
|
||||
// recupero la curva
|
||||
const ICurve* pCurve = GetCurve( pGeoObj) ;
|
||||
if ( pCurve == nullptr)
|
||||
return false ;
|
||||
// se la grafica associata non è valida la ricalcolo
|
||||
ObjEGrGraphics* pGraphics = GetObjEGrGraphics( pGeoObj) ;
|
||||
if ( ! pGraphics->IsValid()) {
|
||||
PolyLine PL ;
|
||||
pCurve->ApproxWithLines( 0.1, 5, PL) ;
|
||||
pGraphics->AddPolyLine( PL) ;
|
||||
}
|
||||
// visualizzo la grafica associata
|
||||
pGraphics->Draw() ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DeleteObjGraphicsGroup( int nId)
|
||||
{
|
||||
// creo un iteratore
|
||||
PtrOwner<IGdbIterator> pIter( CreateGdbIterator()) ;
|
||||
if ( ! ::IsValid( pIter))
|
||||
return false ;
|
||||
// scandisco il gruppo
|
||||
pIter->SetGDB( m_pGeomDB) ;
|
||||
bool bNext = pIter->GoToFirstInGroup( nId) ;
|
||||
while ( bNext) {
|
||||
// leggo il tipo di nodo
|
||||
int nGdbType = pIter->GetGdbType() ;
|
||||
// se oggetto geometrico
|
||||
if ( nGdbType == GDB_GEO) {
|
||||
// lo recupero
|
||||
IGeoObj* pGeoObj = pIter->GetGeoObj() ;
|
||||
if ( pGeoObj == nullptr)
|
||||
return false ;
|
||||
// ne cancello l'eventuale parte grafica
|
||||
ObjEGrGraphics* pGraph = GetObjEGrGraphics( pGeoObj) ;
|
||||
if ( pGraph != nullptr && pGraph->GetScene() == this)
|
||||
pGeoObj->SetObjGraphics( nullptr) ;
|
||||
}
|
||||
// se gruppo
|
||||
else if ( nGdbType == GDB_GROUP) {
|
||||
// ripeto sugli oggetti dello stesso
|
||||
if ( ! DeleteObjGraphicsGroup( pIter->GetId()))
|
||||
return false ;
|
||||
}
|
||||
// passo al successivo
|
||||
bNext = pIter->GoToNext() ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user