From 51052ede7cceb11e7a045fee34c82374f848ac76 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Sun, 23 Mar 2014 12:37:45 +0000 Subject: [PATCH] EgtGraphics 1.5c8 : - gestione stato Mark con disegno alone attorno ad oggetto - modifiche ad esecutore. --- EgtGraphics.rc | Bin 11390 -> 11390 bytes ObjEGrGraphics.h | 2 +- ObjNewGraphics.cpp | 36 +++++++++++++++++++++++++++++++++-- ObjNewGraphics.h | 2 +- ObjOldGraphics.cpp | 37 +++++++++++++++++++++++++++++++++--- ObjOldGraphics.h | 2 +- SceExecutor.cpp | 46 +++++++++++++++++++-------------------------- SceExecutor.h | 9 +++++---- Scene.h | 17 +++++++++++------ SceneBasic.cpp | 25 ++++++++++++------------ SceneGeom.cpp | 27 +++++++++++++++++++------- 11 files changed, 139 insertions(+), 64 deletions(-) diff --git a/EgtGraphics.rc b/EgtGraphics.rc index 847b99800eb0a769d7d3e2abc4c6d58e4fda7c3b..9d4c3a13632961cd0ece2558b2d5371fa4423ebb 100644 GIT binary patch delta 81 zcmewt@h@V-H#SC#&G%&mnSs F+yKOf8~*?R delta 81 zcmewt@h@V-H#SD|&G%&mnSs F+yKK>8}|SJ diff --git a/ObjEGrGraphics.h b/ObjEGrGraphics.h index e402c24..1333c65 100644 --- a/ObjEGrGraphics.h +++ b/ObjEGrGraphics.h @@ -31,7 +31,7 @@ class ObjEGrGraphics : public IObjGraphics virtual bool AddColor( const Color& colC) = 0 ; virtual bool AddPoint( const Point3d& ptP) = 0 ; virtual bool AddPolyLine( const PolyLine& PL) = 0 ; - virtual bool Draw( int nStat) = 0 ; + virtual bool Draw( int nStat, int nMark) = 0 ; } ; //---------------------------------------------------------------------------- diff --git a/ObjNewGraphics.cpp b/ObjNewGraphics.cpp index 61afa7f..0e4cd68 100644 --- a/ObjNewGraphics.cpp +++ b/ObjNewGraphics.cpp @@ -133,11 +133,15 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL) //---------------------------------------------------------------------------- bool -ObjNewGraphics::Draw( int nStat) +ObjNewGraphics::Draw( int nStat, int nMark) { if ( m_pScene == nullptr || ! m_pScene->MakeCurrent()) return false ; + // se vuoto non faccio alcunché + if ( m_ngaList.size() == 0) + return true ; + // gestione stato di visualizzazione if ( nStat == GDB_ST_OFF) return true ; @@ -163,8 +167,36 @@ ObjNewGraphics::Draw( int nStat) } } + // se marcato, disegno halo + if ( nMark == GDB_MK_ON) { + // dimensioni per halo + glPointSize( 7) ; + glLineWidth( 5) ; + + // colore di marcatura + Color colMark = ( ( GetScene() != nullptr) ? GetScene()->GetMark() : Color( 192, 192, 0)) ; + glColor4f( colMark.GetRed(), colMark.GetGreen(), colMark.GetBlue(), colMark.GetAlpha()) ; + + // ciclo di disegno + NGALIST::iterator iIter ; + for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) { + switch ( iIter->m_nType) { + case NewGrAtom::VERTS : + if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) { + glBindVertexArray( iIter->m_nVaoId) ; + glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ; + glBindVertexArray( 0) ; + } + break ; + case NewGrAtom::COLOR : + // si usa il colore di marcatura + break ; + } + } + } + // se necessario, ripristino la normale visualizzazione - if ( nStat == GDB_ST_SEL) { + if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON) { glPointSize( 3) ; glLineWidth( 1) ; } diff --git a/ObjNewGraphics.h b/ObjNewGraphics.h index c7a2ca2..caa96dd 100644 --- a/ObjNewGraphics.h +++ b/ObjNewGraphics.h @@ -69,7 +69,7 @@ class ObjNewGraphics : public ObjEGrGraphics virtual bool AddColor( const Color& colC) ; virtual bool AddPoint( const Point3d& ptP) ; virtual bool AddPolyLine( const PolyLine& PL) ; - virtual bool Draw( int nStat) ; + virtual bool Draw( int nStat, int nMark) ; public : ObjNewGraphics( void) : m_pScene( nullptr), m_bValid( false) {} diff --git a/ObjOldGraphics.cpp b/ObjOldGraphics.cpp index 83037aa..788dd55 100644 --- a/ObjOldGraphics.cpp +++ b/ObjOldGraphics.cpp @@ -14,7 +14,7 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "ObjOldGraphics.h" -#include "OpenGL.h" +#include "Scene.h" #include "/EgtDev/Include/EGkColor.h" #include "/EgtDev/Include/EGkPolyLine.h" #include "/EgtDev/Include/EGkGdbConst.h" @@ -83,12 +83,13 @@ ObjOldGraphics::AddPolyLine( const PolyLine& PL) //---------------------------------------------------------------------------- bool -ObjOldGraphics::Draw( int nStat) +ObjOldGraphics::Draw( int nStat, int nMark) { // se vuoto non faccio alcunché if ( m_ogaList.size() == 0) return true ; + // gestione stato di visualizzazione if ( nStat == GDB_ST_OFF) return true ; if ( nStat == GDB_ST_SEL) { @@ -115,8 +116,38 @@ ObjOldGraphics::Draw( int nStat) } } + // se marcato, disegno halo + if ( nMark == GDB_MK_ON) { + // dimensioni per halo + glPointSize( 7) ; + glLineWidth( 5) ; + + // colore di marcatura + Color colMark = ( ( GetScene() != nullptr) ? GetScene()->GetMark() : Color( 192, 192, 0)) ; + glColor4f( colMark.GetRed(), colMark.GetGreen(), colMark.GetBlue(), colMark.GetAlpha()) ; + + // ciclo di disegno + OGALIST::iterator iIter ; + for ( iIter = m_ogaList.begin() ; iIter != m_ogaList.end() ; ++ iIter) { + switch ( iIter->m_nType) { + case OldGrAtom::START : + glBegin( iIter->m_nMode) ; + break ; + case OldGrAtom::VERT : + glVertex3f( iIter->m_fX, iIter->m_fY, iIter->m_fZ) ; + break ; + case OldGrAtom::COLOR : + // si usa il colore di marcatura + break ; + case OldGrAtom::END : + glEnd() ; + break ; + } + } + } + // se necessario, ripristino la normale visualizzazione - if ( nStat == GDB_ST_SEL) { + if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON) { glPointSize( 3) ; glLineWidth( 1) ; } diff --git a/ObjOldGraphics.h b/ObjOldGraphics.h index 07a1b2c..7bfc374 100644 --- a/ObjOldGraphics.h +++ b/ObjOldGraphics.h @@ -70,7 +70,7 @@ class ObjOldGraphics : public ObjEGrGraphics virtual bool AddColor( const Color& colC) ; virtual bool AddPoint( const Point3d& ptP) ; virtual bool AddPolyLine( const PolyLine& PL) ; - virtual bool Draw( int nStat) ; + virtual bool Draw( int nStat, int nMark) ; public : ObjOldGraphics( void) : m_pScene( nullptr), m_bValid( false) {} diff --git a/SceExecutor.cpp b/SceExecutor.cpp index 8d6cc1d..17f1cb9 100644 --- a/SceExecutor.cpp +++ b/SceExecutor.cpp @@ -32,7 +32,15 @@ CreateSceExecutor( void) SceExecutor::SceExecutor( void) { m_pScene = nullptr ; - m_pOtherExec = nullptr ; + m_pParser = nullptr ; + // assegno chiavi a funzioni di esecuzione + m_ExecMgr.Init( 16) ; + m_ExecMgr.Insert( "RD", &SceExecutor::ExecuteRedraw) ; + m_ExecMgr.Insert( "REDRAW", &SceExecutor::ExecuteRedraw) ; + m_ExecMgr.Insert( "ZM", &SceExecutor::ExecuteZoom) ; + m_ExecMgr.Insert( "ZOOM", &SceExecutor::ExecuteZoom) ; + m_ExecMgr.Insert( "CENTER", &SceExecutor::ExecuteCenter) ; + m_ExecMgr.Insert( "CAMERA", &SceExecutor::ExecuteCamera) ; } //---------------------------------------------------------------------------- @@ -53,23 +61,12 @@ SceExecutor::SetScene( IEGrScene* pScene) bool SceExecutor::SetCmdParser( ICmdParser* pParser) { - // imposto eventuale parser dipendente - if ( m_pOtherExec != nullptr) - m_pOtherExec->SetCmdParser( pParser) ; - - return true ; + m_pParser = pParser ; + return ( m_pParser != nullptr) ; } //---------------------------------------------------------------------------- -bool -SceExecutor::AddExecutor( ICmdExecutor* pOtherExec) -{ - m_pOtherExec = pOtherExec ; - return true ; -} - -//---------------------------------------------------------------------------- -bool +int SceExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams) { // verifico validità Scene @@ -78,19 +75,14 @@ SceExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& return false ; } - // esecuzione comando - if ( sCmd1 == "RD" || sCmd1 == "REDRAW") - return ExecuteRedraw( sCmd2, vsParams) ; - else if ( sCmd1 == "ZM" || sCmd1 == "ZOOM") - return ExecuteZoom( sCmd2, vsParams) ; - else if ( sCmd1 == "CENTER") - return ExecuteCenter( sCmd2, vsParams) ; - else if ( sCmd1 == "CAMERA") - return ExecuteCamera( sCmd2, vsParams) ; - else if ( m_pOtherExec != nullptr) - return m_pOtherExec->Execute( sCmd1, sCmd2, vsParams) ; + // verifico validità CmdParser + if ( m_pParser == nullptr) { + LOG_ERROR( GetEGrLogger(), "Error : null CmdParser.") + return ER_ERR ; + } - return false ; + // esecuzione comando + return m_ExecMgr.Execute( *this, sCmd1, sCmd2, vsParams) ; } //---------------------------------------------------------------------------- diff --git a/SceExecutor.h b/SceExecutor.h index eda5c0b..9bffc05 100644 --- a/SceExecutor.h +++ b/SceExecutor.h @@ -15,6 +15,7 @@ #include "/EgtDev/Include/EGrSceExecutor.h" +#include "/EgtDev/Include/EgtExecMgr.h" //---------------------------------------------------------------------------- @@ -22,10 +23,9 @@ class SceExecutor : public ISceExecutor { public : // ICmdExecutor virtual bool SetCmdParser( ICmdParser* pParser) ; - virtual bool AddExecutor( ICmdExecutor* pOtherExec) ; virtual bool AddStandardVariables( void) { return true ; } - virtual bool Execute( const std::string& sCmd1, const std::string& sCmd2, const STRVECTOR& vsParams) ; + virtual int Execute( const std::string& sCmd1, const std::string& sCmd2, const STRVECTOR& vsParams) ; public : // ISceExecutor ~SceExecutor( void) ; @@ -41,6 +41,7 @@ class SceExecutor : public ISceExecutor bool ExecuteCamera( const std::string& sCmd2, const STRVECTOR& vsParams) ; private : - IEGrScene* m_pScene ; - ICmdExecutor* m_pOtherExec ; + IEGrScene* m_pScene ; + ICmdParser* m_pParser ; + ExecManager m_ExecMgr ; } ; diff --git a/Scene.h b/Scene.h index ddde264..4184563 100644 --- a/Scene.h +++ b/Scene.h @@ -34,7 +34,7 @@ class Scene : public IEGrScene virtual std::string GetPixelFormatInfo( void) ; virtual bool RedrawWindow( void) ; virtual bool Reshape( int nW, int nH) ; - virtual bool SetBackground( Color BackTop, Color BackBottom) ; + virtual bool SetBackground( Color colBackTop, Color colBackBottom) ; virtual bool Prepare( void) ; virtual bool Draw( void) ; virtual bool Project( const Point3d& ptWorld, Point3d& ptView) ; @@ -58,6 +58,7 @@ class Scene : public IEGrScene // Geometry virtual bool SetExtension( const BBox3d& b3Ext) ; virtual bool UpdateExtension( void) ; + virtual bool SetMark( Color colMark) ; // Aux virtual bool SetWinRectAttribs( bool bOutline, Color WRcol) ; virtual bool SetWinRect( const Point3d& ptWinRectP1, const Point3d& ptWinRectP2) ; @@ -69,6 +70,9 @@ class Scene : public IEGrScene bool MakeCurrent( void) ; GLEWContext* glewGetContext( void) { return &m_glewc ; } + // Geometry + Color GetMark( void) + { return m_colMark ; } private : // Basic @@ -85,9 +89,9 @@ class Scene : public IEGrScene bool CalcDirUp( void) ; bool CalcCameraFrame( Frame3d& frView) ; // Geometry - bool DrawGroup( int nId, int nParentMode, int nParentStat) ; - bool DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat) ; - bool DrawGeoObj( const IGdbIterator& iIter, int nObjStat) ; + bool DrawGroup( int nId, int nParentMode, int nParentStat, int nParentMark) ; + bool DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, int nParentMark) ; + bool DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) ; bool DeleteObjGraphicsGroup( int nId) ; // Aux bool DrawWinRect( void) ; @@ -107,11 +111,12 @@ class Scene : public IEGrScene int m_nViewportW ; // larghezza della finestra int m_nViewportH ; // altezza della finestra - Color m_BackTop ; // colore di sfondo in alto - Color m_BackBottom ; // colore di sfondo in basso + Color m_colBackTop ; // colore di sfondo in alto + Color m_colBackBottom ; // colore di sfondo in basso IGeomDB* m_pGeomDB ; // puntatore al DB geometrico Color m_colDef ; // colore di default + Color m_colMark ; // colore per marcatura BBox3d m_b3ExtWorld ; // estensione della geometria nel riferimento globale (mondo) BBox3d m_b3ExtView ; // estensione nel riferimento di vista diff --git a/SceneBasic.cpp b/SceneBasic.cpp index dacb8b1..1a61788 100644 --- a/SceneBasic.cpp +++ b/SceneBasic.cpp @@ -51,11 +51,12 @@ Scene::Scene( void) m_nViewportW = 0 ; m_nViewportH = 0 ; // Sfondo - m_BackTop.Set( 128, 128, 128) ; - m_BackBottom.Set( 128, 128, 128) ; + m_colBackTop.Set( 128, 128, 128) ; + m_colBackBottom.Set( 128, 128, 128) ; // GeomData m_pGeomDB = nullptr ; m_colDef.Set( 0, 0, 0) ; + m_colMark.Set( 192, 192, 0) ; // Extension SetExtension( BBox3d( -MIN_EXTENSION, -MIN_EXTENSION, -MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION)) ; @@ -474,10 +475,10 @@ Scene::Reshape( int nW, int nH) //---------------------------------------------------------------------------- bool -Scene::SetBackground( Color BackTop, Color BackBottom) +Scene::SetBackground( Color colBackTop, Color colBackBottom) { - m_BackTop = BackTop ; - m_BackBottom = BackBottom ; + m_colBackTop = colBackTop ; + m_colBackBottom = colBackBottom ; return true ; } @@ -495,9 +496,9 @@ Scene::Background( void) glClear( GL_DEPTH_BUFFER_BIT) ; // se lo sfondo ha un colore uniforme - if ( m_BackTop == m_BackBottom) { + if ( m_colBackTop == m_colBackBottom) { // imposto il colore dello sfondo e lo cancello - glClearColor( m_BackTop.GetRed(), m_BackTop.GetGreen(), m_BackTop.GetBlue(), m_BackTop.GetAlpha()) ; + glClearColor( m_colBackTop.GetRed(), m_colBackTop.GetGreen(), m_colBackTop.GetBlue(), 1) ; glClear( GL_COLOR_BUFFER_BIT) ; return true ; } @@ -514,10 +515,10 @@ Scene::Background( void) // disegno lo sfondo con due colori if ( ! m_bNewWay) { glBegin( GL_TRIANGLE_STRIP) ; - glColor3f( m_BackBottom.GetRed(), m_BackBottom.GetGreen(), m_BackBottom.GetBlue()) ; + glColor3f( m_colBackBottom.GetRed(), m_colBackBottom.GetGreen(), m_colBackBottom.GetBlue()) ; glVertex3f( -1, -1, 0.5) ; glVertex3f( 1, -1, 0.5) ; - glColor3f( m_BackTop.GetRed(), m_BackTop.GetGreen(), m_BackTop.GetBlue()) ; + glColor3f( m_colBackTop.GetRed(), m_colBackTop.GetGreen(), m_colBackTop.GetBlue()) ; glVertex3f( -1, 1, 0.5) ; glVertex3f( 1, 1, 0.5) ; glEnd() ; @@ -542,7 +543,7 @@ Scene::Background( void) // bottom left v3V.Set( -1, -1, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &v3V) ; - v3C.Set( m_BackBottom.GetRed(), m_BackBottom.GetGreen(), m_BackBottom.GetBlue()) ; + v3C.Set( m_colBackBottom.GetRed(), m_colBackBottom.GetGreen(), m_colBackBottom.GetBlue()) ; glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &v3C) ; // bottom right v3V.Set( 1, -1, 0.5) ; @@ -552,7 +553,7 @@ Scene::Background( void) // top left v3V.Set( -1, 1, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 4 * SIZEV3F, SIZEV3F, &v3V) ; - v3C.Set( m_BackTop.GetRed(), m_BackTop.GetGreen(), m_BackTop.GetBlue()) ; + v3C.Set( m_colBackTop.GetRed(), m_colBackTop.GetGreen(), m_colBackTop.GetBlue()) ; glBufferSubData( GL_ARRAY_BUFFER, 5 * SIZEV3F, SIZEV3F, &v3C) ; // top right v3V.Set( 1, 1, 0.5) ; @@ -629,7 +630,7 @@ Scene::Draw( void) glPointSize( 3) ; // disegno le geometrie del DB - DrawGroup( GDB_ID_ROOT, GDB_MD_STD, GDB_ST_ON) ; + DrawGroup( GDB_ID_ROOT, GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF) ; // aggiungo disegni diretti (senza test Zbuffer) glDisable( GL_DEPTH_TEST) ; diff --git a/SceneGeom.cpp b/SceneGeom.cpp index da5df7f..aee736b 100644 --- a/SceneGeom.cpp +++ b/SceneGeom.cpp @@ -81,7 +81,16 @@ Scene::UpdateExtension( void) //---------------------------------------------------------------------------- bool -Scene::DrawGroup( int nId, int nParentMode, int nParentStat) +Scene::SetMark( Color colMark) +{ + m_colMark = colMark ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Scene::DrawGroup( int nId, int nParentMode, int nParentStat, int nParentMark) { // creo un iteratore PtrOwner pIter( CreateGdbIterator()) ; @@ -94,12 +103,12 @@ Scene::DrawGroup( int nId, int nParentMode, int nParentStat) return false ; // eseguo il disegno - return DrawGroup( *pIter, nParentMode, nParentStat) ; + return DrawGroup( *pIter, nParentMode, nParentStat, nParentMark) ; } //---------------------------------------------------------------------------- bool -Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat) +Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, int nParentMark) { // recupero il riferimento del gruppo Frame3d frFrame ; @@ -132,11 +141,15 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat) pIter->GetStatus( nStat) ; nStat = ::CalcStatus( nStat, nParentStat) ; nStat = ::AdjustStatusWithMode( nStat, nMode) ; + // recupero e aggiorno la marcatura dell'oggetto + int nMark = GDB_MK_OFF ; + pIter->GetMark( nMark) ; + nMark = ::CalcMark( nMark, nParentMark) ; // se oggetto geometrico if ( nGdbType == GDB_TY_GEO) { // se non nascosto, lo disegno if ( nStat != GDB_ST_OFF) { - if ( ! DrawGeoObj( *pIter, nStat)) + if ( ! DrawGeoObj( *pIter, nStat, nMark)) return false ; } } @@ -144,7 +157,7 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat) else if ( nGdbType == GDB_TY_GROUP) { // se non nascosto, lo disegno if ( nStat != GDB_ST_OFF) { - if ( ! DrawGroup( *pIter, nMode, nStat)) + if ( ! DrawGroup( *pIter, nMode, nStat, nMark)) return false ; } } @@ -160,7 +173,7 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat) //---------------------------------------------------------------------------- bool -Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat) +Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) { // recupero l'oggetto geometrico IGeoObj* pGeoObj = (const_cast(&iIter))->GetGeoObj() ; @@ -242,7 +255,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat) } // visualizzo la grafica associata - return pGraphics->Draw( nObjStat) ; + return pGraphics->Draw( nObjStat, nObjMark) ; } //----------------------------------------------------------------------------