Files
EgtExchange/ExcExecutor.cpp
T
Daniele Bariletti c5503427cb EgtExchange :
- aggiunti oggetti all'import3dm e corretti alcuni bug.
2023-09-01 17:22:03 +02:00

274 lines
8.6 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/EExExportDxf.h"
#include "/EgtDev/Include/EExExportStl.h"
#include "/EgtDev/Include/EExImportCnc.h"
#include "/EgtDev/Include/EExImportDxf.h"
#include "/EgtDev/Include/EExImportStl.h"
#include "/EgtDev/Include/EExImport3dm.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( "EXPORTDXF", &ExcExecutor::ExecuteExportDxf) ;
m_ExecMgr.Insert( "EXPORTSTL", &ExcExecutor::ExecuteExportStl) ;
m_ExecMgr.Insert( "IMPORTCNC", &ExcExecutor::ExecuteImportCnc) ;
m_ExecMgr.Insert( "IMPORTDXF", &ExcExecutor::ExecuteImportDxf) ;
m_ExecMgr.Insert( "IMPORTSTL", &ExcExecutor::ExecuteImportStl) ;
//m_ExecMgr.Insert( "IMPORT3DM", &ExcExecutor::ExecuteImport3dm) ;
}
//----------------------------------------------------------------------------
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::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::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::ExecuteImportCnc( const string& sCmd2, const STRVECTOR& vsParams)
{
// 2 : nome del file, Id del gruppo
if ( vsParams.size() != 2)
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 ;
// preparo l'importatore
IImportCnc* pImpCnc = CreateImportCnc() ;
if ( pImpCnc == nullptr) {
LOG_ERROR( GetEExLogger(), "Error : CreateImportCnc")
return false ;
}
// eseguo l'importazione
bool bOk = pImpCnc->Import( sFile, m_pGDB, nId, EICFLAG_NONE) ;
// cancello l'importatore
delete pImpCnc ;
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 ;
}
//----------------------------------------------------------------------------
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::ExecuteImport3dm( 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
// IImport3dm* pImp3dm = CreateImport3dm() ;
// if ( pImp3dm == nullptr) {
// LOG_ERROR( GetEExLogger(), "Error : CreateImportStl")
// return false ;
// }
// // eseguo l'importazione
// //bool bOk = pImp3dm->Import( sFile, m_pGDB, nId, dScaleFactor) ;
// // cancello l'importatore
// delete pImp3dm ;
//
// //return bOk ;
//
// //return true ;
//}