Files
EgtGraphics/SceExecutor.cpp
T
Dario Sassi 294546102d EgtGraphics 1.5c6 :
- modifiche per materiale
- spostato comando PAUSE di TSC in EgtGeneral.
2014-03-18 08:51:01 +00:00

191 lines
5.5 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : GraExecutor.cpp Data : 18.02.14 Versione : 1.5b3
// Contenuto : Implementazione della classe GraExecutor.
//
//
//
// Modifiche : 18.02.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "SceExecutor.h"
#include "DllMain.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Include/EgrScene.h"
using namespace std ;
//----------------------------------------------------------------------------
ISceExecutor*
CreateSceExecutor( void)
{
return static_cast<ISceExecutor*> ( new SceExecutor) ;
}
//----------------------------------------------------------------------------
SceExecutor::SceExecutor( void)
{
m_pScene = nullptr ;
m_pOtherExec = nullptr ;
}
//----------------------------------------------------------------------------
SceExecutor::~SceExecutor( void)
{
}
//----------------------------------------------------------------------------
bool
SceExecutor::SetScene( IEGrScene* pScene)
{
m_pScene = pScene ;
return ( m_pScene != nullptr) ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::SetCmdParser( ICmdParser* pParser)
{
// imposto eventuale parser dipendente
if ( m_pOtherExec != nullptr)
m_pOtherExec->SetCmdParser( pParser) ;
return true ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::AddExecutor( ICmdExecutor* pOtherExec)
{
m_pOtherExec = pOtherExec ;
return true ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams)
{
// verifico validità Scene
if ( m_pScene == nullptr) {
LOG_ERROR( GetEGrLogger(), "Error : null Scene.")
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) ;
return false ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::ExecuteRedraw( const string& sCmd2, const STRVECTOR& vsParams)
{
m_pScene->RedrawWindow() ;
return true ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::ExecuteZoom( const string& sCmd2, const STRVECTOR& vsParams)
{
const double COEFF_IN = 0.9 ;
const double COEFF_OUT = 1 / COEFF_IN ;
if ( sCmd2 == "ALL")
m_pScene->ZoomAll() ;
else if ( sCmd2 == "IN")
m_pScene->ZoomChange( COEFF_IN) ;
else if ( sCmd2 == "OUT")
m_pScene->ZoomChange( COEFF_OUT) ;
else if ( sCmd2 == "CHANGE") {
// 1 parametro : fattore di zoom
if ( vsParams.size() != 1)
return false ;
// fattore di zoom
double nFactor ;
if ( ! FromString( vsParams[0], nFactor))
return false ;
// eseguo
m_pScene->ZoomChange( nFactor) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::ExecuteCenter( const string& sCmd2, const STRVECTOR& vsParams)
{
// 3 parametri : le 3 coordinate
if ( vsParams.size() != 3)
return false ;
// recupero le tre coordinate
Point3d ptCen ;
if ( ! FromString( vsParams[0], ptCen.x) ||
! FromString( vsParams[1], ptCen.y) ||
! FromString( vsParams[2], ptCen.z))
return false ;
// eseguo
m_pScene->SetCenter( ptCen) ;
return true ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::ExecuteCamera( const string& sCmd2, const STRVECTOR& vsParams)
{
if ( sCmd2 == "TOP")
m_pScene->SetCamera( CT_TOP) ;
else if ( sCmd2 == "FRONT")
m_pScene->SetCamera( CT_FRONT) ;
else if ( sCmd2 == "RIGHT")
m_pScene->SetCamera( CT_RIGHT) ;
else if ( sCmd2 == "BACK")
m_pScene->SetCamera( CT_BACK) ;
else if ( sCmd2 == "LEFT")
m_pScene->SetCamera( CT_LEFT) ;
else if ( sCmd2 == "BOTTOM")
m_pScene->SetCamera( CT_BOTTOM) ;
else if ( sCmd2 == "ISO_SW")
m_pScene->SetCamera( CT_ISO_SW) ;
else if ( sCmd2 == "ISO_SE")
m_pScene->SetCamera( CT_ISO_SE) ;
else if ( sCmd2 == "ISO_NE")
m_pScene->SetCamera( CT_ISO_NE) ;
else if ( sCmd2 == "ISO_NW")
m_pScene->SetCamera( CT_ISO_NW) ;
else if ( sCmd2.empty() || sCmd2 == "GEN") {
// 2 parametri : i 2 angoli
if ( vsParams.size() != 2)
return false ;
// recupero i due angoli
double dAngVertDeg ;
double dAngOrizzDeg ;
if ( ! FromString( vsParams[0], dAngVertDeg) ||
! FromString( vsParams[1], dAngOrizzDeg))
return false ;
// eseguo
m_pScene->SetCamera( dAngVertDeg, dAngOrizzDeg, 0) ;
}
return true ;
}