Files
EgtGraphics/SceExecutor.cpp
T
Dario Sassi 73ee89f9c5 EgtGraphics 1.5b3 :
- aggiunto SceExecutor per eseguire file Tsc
- centralizzata gestiopne del logger
- mogliorie varie
2014-02-19 11:21:12 +00:00

223 lines
6.4 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::Init( IEGrScene* pScene)
{
m_pScene = pScene ;
return ( m_pScene != nullptr) ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::AddExecutor( ICmdExecutor* pOtherExec)
{
m_pOtherExec = pOtherExec ;
return true ;
}
//----------------------------------------------------------------------------
bool
SceExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams)
{
string sOut ;
STRVECTOR::const_iterator theConstIter ;
// output di debug
sOut = " " + sCmd1 ;
if ( ! sCmd2.empty())
sOut += "." + sCmd2 ;
sOut += "( " ;
for ( theConstIter = vsParams.begin() ; theConstIter != vsParams.end() ; ++theConstIter) {
if ( theConstIter != vsParams.begin())
sOut += ", " ;
sOut += *theConstIter ;
}
sOut += ")" ;
LOG_DBG_INFO( GetEGrLogger(), sOut.c_str())
// verifico validita Scene
if ( m_pScene == nullptr) {
LOG_ERROR( GetEGrLogger(), "Error : null Scene.")
return false ;
}
// esecuzione comando
if ( sCmd1 == "PAUSE")
return ExecutePause( sCmd2, vsParams) ;
else 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::ExecutePause( const string& sCmd2, const STRVECTOR& vsParams)
{
const int MIN_TIME = 0 ;
const int MAX_TIME = 10000 ;
// 1 parametro : durata della pausa in ms
if ( vsParams.size() != 1)
return false ;
// tempo di attesa
int nTime ;
if ( ! FromString( vsParams[0], nTime))
return false ;
if ( nTime < MIN_TIME)
nTime = MIN_TIME ;
else if ( nTime > MAX_TIME)
nTime = MAX_TIME ;
// eseguo
Sleep( nTime) ;
return true ;
}
//----------------------------------------------------------------------------
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_PLUS = 0.9 ;
const double COEFF_MINUS = 1 / COEFF_PLUS ;
if ( sCmd2 == "ALL")
m_pScene->ZoomAll() ;
else if ( sCmd2 == "PLUS")
m_pScene->ZoomChange( COEFF_PLUS) ;
else if ( sCmd2 == "MINUS")
m_pScene->ZoomChange( COEFF_MINUS) ;
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 ;
}