Files
EgtExchange/ExcExecutor.cpp
T
Dario Sassi 8c69460cb1 EgtExchange 1.5h2 :
- aggiunto esportatore STL
- aggiunto esportatore DXF.
2014-08-12 07:43:46 +00:00

206 lines
6.4 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : ExcExecutor.cpp Data : 04.04.14 Versione : 1.5d1
// Contenuto : Implementazione della classe ExcExecutor.
//
//
//
// Modifiche : 04.04.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "ExcExecutor.h"
#include "DllMain.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Include/EgnCmdParser.h"
#include "/EgtDev/Include/EExExportStl.h"
#include "/EgtDev/Include/EExExportDxf.h"
#include "/EgtDev/Include/EExImportStl.h"
#include "/EgtDev/Include/EExImportDxf.h"
using namespace std ;
//----------------------------------------------------------------------------
IExcExecutor*
CreateExcExecutor( void)
{
return static_cast<IExcExecutor*> ( new ExcExecutor) ;
}
//----------------------------------------------------------------------------
ExcExecutor::ExcExecutor( void)
{
// assegno chiavi a funzioni di esecuzione
m_ExecMgr.Init( 8) ;
m_ExecMgr.Insert( "EXPORTSTL", &ExcExecutor::ExecuteExportStl) ;
m_ExecMgr.Insert( "EXPORTDXF", &ExcExecutor::ExecuteExportDxf) ;
m_ExecMgr.Insert( "IMPORTSTL", &ExcExecutor::ExecuteImportStl) ;
m_ExecMgr.Insert( "IMPORTDXF", &ExcExecutor::ExecuteImportDxf) ;
}
//----------------------------------------------------------------------------
ExcExecutor::~ExcExecutor( void)
{
}
//----------------------------------------------------------------------------
bool
ExcExecutor::SetCmdParser( ICmdParser* pParser)
{
m_pParser = pParser ;
return ( m_pParser != nullptr) ;
}
//----------------------------------------------------------------------------
int
ExcExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams)
{
// verifico validita GeomDB
if ( m_pGDB == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : null GeomDb in ExcExecutor.")
return ER_ERR ;
}
// verifico validità CmdParser
if ( m_pParser == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : null CmdParser in ExcExecutor.")
return ER_ERR ;
}
// esecuzione comando
return m_ExecMgr.Execute( *this, sCmd1, sCmd2, vsParams) ;
}
//----------------------------------------------------------------------------
bool
ExcExecutor::SetGeomDB( IGeomDB* pGdb)
{
m_pGDB = pGdb ;
return ( m_pGDB != nullptr) ;
}
//----------------------------------------------------------------------------
bool
ExcExecutor::ExecuteExportStl( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 parametri : Id del gruppo, nome del file
if ( vsParams.size() != 2)
return false ;
// recupero l'Id
int nId = m_pParser->GetIdParam( vsParams[0]) ;
if ( nId == CMD_ID_ERROR)
return false ;
// eventuale conversione di token nel nome file
string sFile = vsParams[1] ;
m_pParser->DirReplace( sFile) ;
// preparo l'esportatore
IExportStl* pExpStl = CreateExportStl() ;
if ( pExpStl == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : CreateExportStl")
return false ;
}
// eseguo l'esportazione
bool bOk = pExpStl->Export( m_pGDB, nId, sFile) ;
// cancello l'esportatore
delete pExpStl ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
ExcExecutor::ExecuteExportDxf( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 parametri : Id del gruppo, nome del file
if ( vsParams.size() != 2)
return false ;
// recupero l'Id
int nId = m_pParser->GetIdParam( vsParams[0]) ;
if ( nId == CMD_ID_ERROR)
return false ;
// eventuale conversione di token nel nome file
string sFile = vsParams[1] ;
m_pParser->DirReplace( sFile) ;
// preparo l'esportatore
IExportDxf* pExpDxf = CreateExportDxf() ;
if ( pExpDxf == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : CreateExportDxf")
return false ;
}
// eseguo l'esportazione
bool bOk = pExpDxf->Export( m_pGDB, nId, sFile) ;
// cancello l'esportatore
delete pExpDxf ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
ExcExecutor::ExecuteImportStl( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 o 3 parametri : nome del file, Id del gruppo[, ScaleFactor]
if ( vsParams.size() != 2 && vsParams.size() != 3)
return false ;
// eventuale conversione di token nel nome file
string sFile = vsParams[0] ;
m_pParser->DirReplace( sFile) ;
// recupero l'Id
int nId = m_pParser->GetIdParam( vsParams[1]) ;
if ( nId == CMD_ID_ERROR)
return false ;
// gestisco ScaleFactor
double dScaleFactor = 1 ;
if ( vsParams.size() >= 3)
FromString( vsParams[2], dScaleFactor) ;
// preparo l'importatore
IImportStl* pImpStl = CreateImportStl() ;
if ( pImpStl == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : CreateImportStl")
return false ;
}
// eseguo l'importazione
bool bOk = pImpStl->Import( sFile, m_pGDB, nId, dScaleFactor) ;
// cancello l'importatore
delete pImpStl ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
ExcExecutor::ExecuteImportDxf( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 o 3 parametri : nome del file, Id del gruppo[, ScaleFactor]
if ( vsParams.size() != 2 && vsParams.size() != 3)
return false ;
// eventuale conversione di token nel nome file
string sFile = vsParams[0] ;
m_pParser->DirReplace( sFile) ;
// recupero l'Id
int nId = m_pParser->GetIdParam( vsParams[1]) ;
if ( nId == CMD_ID_ERROR)
return false ;
// gestisco ScaleFactor
double dScaleFactor = 1 ;
if ( vsParams.size() >= 3)
FromString( vsParams[2], dScaleFactor) ;
// preparo l'importatore
IImportDxf* pImpDxf = CreateImportDxf() ;
if ( pImpDxf == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : CreateImportDxf")
return false ;
}
// eseguo l'importazione
bool bOk = pImpDxf->Import( sFile, m_pGDB, nId, dScaleFactor) ;
// cancello l'importatore
delete pImpDxf ;
return bOk ;
}