00a81d6e04
- aggiunta gestione Stipple per GeoPoint3d, GeoVector3d e GeoCurve.
254 lines
7.5 KiB
C++
254 lines
7.5 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2017-2017
|
|
//----------------------------------------------------------------------------
|
|
// File : ObjMultiGraphics.cpp Data : 02.02.17 Versione : 1.6x3
|
|
// Contenuto : Implementazione classe multi-grafica di un oggetto geometrico.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.02.17 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ObjMultiGraphics.h"
|
|
#include "ObjNewGraphics.h"
|
|
#include "ObjOldGraphics.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
ObjMultiGraphics::~ObjMultiGraphics( void)
|
|
{
|
|
for ( size_t i = 0 ; i < m_vOEGR.size() ; ++ i) {
|
|
delete m_vOEGR[i] ;
|
|
m_vOEGR[i] = nullptr ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjMultiGraphics::Reset( void)
|
|
{
|
|
m_bValid = false ;
|
|
m_nCurr = - 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjMultiGraphics::ResetAll( void)
|
|
{
|
|
Reset() ;
|
|
// reset contatori dei blocchi
|
|
for ( auto& nCnt : m_Counter)
|
|
nCnt = 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjMultiGraphics::SetScene( Scene* pScene)
|
|
{
|
|
m_pScene = pScene ;
|
|
for ( size_t i = 0 ; i < m_vOEGR.size() ; ++ i)
|
|
m_vOEGR[i]->SetScene( pScene) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::SetCurrent( int nCurr)
|
|
{
|
|
if ( nCurr < 0 || nCurr >= int( m_vOEGR.size())) {
|
|
m_nCurr = - 1 ;
|
|
return false ;
|
|
}
|
|
m_nCurr = nCurr ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjMultiGraphics::Clear( void)
|
|
{
|
|
m_bValid = false ;
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return ;
|
|
m_vOEGR[m_nCurr]->Clear() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddColor( const Color& colC)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
return m_vOEGR[m_nCurr]->AddColor( colC) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddMaterial( const Color& colAmb, const Color& colDiff,
|
|
const Color& colSpec, float fShin)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
return m_vOEGR[m_nCurr]->AddMaterial( colAmb, colDiff, colSpec, fShin) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddBackMaterial( const Color& colAmbDiff)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
return m_vOEGR[m_nCurr]->AddBackMaterial( colAmbDiff) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddLineStipple( int nFactor, int nPattern)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
return m_vOEGR[m_nCurr]->AddLineStipple( nFactor, nPattern) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddPoint( const Point3d& ptP, bool bAux)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
m_bValid = true ;
|
|
return m_vOEGR[m_nCurr]->AddPoint( ptP, bAux) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddPoints( const PNTVECTOR& vPnt, bool bAux)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
m_bValid = true ;
|
|
return m_vOEGR[m_nCurr]->AddPoints( vPnt, bAux) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
m_bValid = true ;
|
|
return m_vOEGR[m_nCurr]->AddLines( vPnt, bAux) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
m_bValid = true ;
|
|
return m_vOEGR[m_nCurr]->AddPolyLine( PL, bAux) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::StartTriangles( int nNum, bool bAux)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
return m_vOEGR[m_nCurr]->StartTriangles( nNum, bAux) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
return m_vOEGR[m_nCurr]->AddTriangle( Tria, TFlags, TNrms) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::EndTriangles( void)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
m_bValid = true ;
|
|
return m_vOEGR[m_nCurr]->EndTriangles() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlpha, bool bShowAux)
|
|
{
|
|
bool bOk = true ;
|
|
for ( size_t i = 0 ; i < m_vOEGR.size() ; ++ i) {
|
|
if ( m_vOEGR[i] != nullptr &&
|
|
m_vOEGR[i]->IsValid() &&
|
|
! m_vOEGR[i]->Draw( nStat, nMark, bSurfSha, bSurf, nAlpha, bShowAux))
|
|
bOk = false ;
|
|
}
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::GetLocalBBox( BBox3d& b3Loc) const
|
|
{
|
|
// svuoto BBox
|
|
m_b3Loc.Reset() ;
|
|
// aggiorno il bbox con quello dei componenti
|
|
for ( size_t i = 0 ; i < m_vOEGR.size() ; ++ i) {
|
|
if ( m_vOEGR[i] != nullptr &&
|
|
m_vOEGR[i]->IsValid()) {
|
|
BBox3d b3Temp ;
|
|
if ( m_vOEGR[i]->GetLocalBBox( b3Temp))
|
|
m_b3Loc.Add( b3Temp) ;
|
|
}
|
|
}
|
|
// copio
|
|
b3Loc = m_b3Loc ;
|
|
// verifico non sia vuoto
|
|
return ! m_b3Loc.IsEmpty() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjMultiGraphics::SetCounter( int nCnt)
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return false ;
|
|
m_Counter[m_nCurr] = nCnt ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ObjMultiGraphics::GetCounter( void) const
|
|
{
|
|
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
|
return -1 ;
|
|
return m_Counter[m_nCurr] ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
ObjMultiGraphics::ObjMultiGraphics( int nCount, bool bNewWay)
|
|
{
|
|
m_pScene = nullptr ;
|
|
m_bValid = false ;
|
|
m_vOEGR.reserve( nCount) ;
|
|
for ( int i = 0 ; i < nCount ; ++ i) {
|
|
if ( bNewWay)
|
|
m_vOEGR.emplace_back( new( nothrow) ObjNewGraphics) ;
|
|
else
|
|
m_vOEGR.emplace_back( new( nothrow) ObjOldGraphics) ;
|
|
}
|
|
m_Counter.resize( nCount, 0) ;
|
|
m_nCurr = - 1 ;
|
|
}
|