From fbe1fa475740a0f300b2c0cd2431f23ed7146136 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 1 Sep 2015 07:29:08 +0000 Subject: [PATCH] EgtExecutor 1.6h5 : - corretta trasformazioni stringhe in stringhe Lua con ' - aggiunta gestione import BTL. --- AuxTools.cpp | 10 ++++++ AuxTools.h | 2 ++ DllExchange.cpp | 26 ++++++++++++--- DllExchange.h | 4 ++- EXE_Exchange.cpp | 73 ++++++++++++++++++++++++++---------------- EXE_GdbCreate.cpp | 20 +++--------- EXE_GdbObjAttribs.cpp | 16 +++------ EXE_GeomDB.cpp | 16 +++------ EXE_Lua.cpp | 6 ++-- EgtExecutor.rc | Bin 11686 -> 11686 bytes LUA_Exchange.cpp | 16 +++++++++ 11 files changed, 113 insertions(+), 76 deletions(-) diff --git a/AuxTools.cpp b/AuxTools.cpp index bd9e6c2..34dd9ed 100644 --- a/AuxTools.cpp +++ b/AuxTools.cpp @@ -22,6 +22,16 @@ using namespace std ; +//---------------------------------------------------------------------------- +string +StringToLuaString( const string& sText) +{ + string sLuaText = sText ; + ReplaceString( sLuaText, "\\", "\\\\") ; + ReplaceString( sLuaText, "'", "\\'") ; + return sLuaText ; +} + //---------------------------------------------------------------------------- const string IdToString( int nId) diff --git a/AuxTools.h b/AuxTools.h index cc6326c..6e7034b 100644 --- a/AuxTools.h +++ b/AuxTools.h @@ -17,6 +17,8 @@ class IGeomDB ; //---------------------------------------------------------------------------- +// Sistemazione caratteri speciali per stringhe da scrivere in programmi Lua +std::string StringToLuaString( const std::string& sText) ; // Id con gestione delle relative costanti const std::string IdToString( int nId) ; // Lista di Id completa (parametro per lua) diff --git a/DllExchange.cpp b/DllExchange.cpp index d7454a2..e8241c6 100644 --- a/DllExchange.cpp +++ b/DllExchange.cpp @@ -36,8 +36,9 @@ using namespace std ; static const char* EEX_SETEEXLOGGER = "SetEExLogger" ; static const char* EEX_GETEEXVERSION = "GetEExVersion" ; static const char* EEX_SETEEXKEY = "SetEExKey" ; -static const char* EEX_CREATEIMPORTCSF = "CreateImportCsf" ; +static const char* EEX_CREATEIMPORTBTL = "CreateImportBtl" ; static const char* EEX_CREATEIMPORTCNC = "CreateImportCnc" ; +static const char* EEX_CREATEIMPORTCSF = "CreateImportCsf" ; static const char* EEX_CREATEIMPORTDXF = "CreateImportDxf" ; static const char* EEX_CREATEIMPORTSTL = "CreateImportStl" ; static const char* EEX_CREATEEXPORTDXF = "CreateExportDxf" ; @@ -137,15 +138,15 @@ MySetEExKey( const string& sKey) } //----------------------------------------------------------------------------- -IImportCsf* -MyCreateImportCsf( void) +IImportBtl* +MyCreateImportBtl( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto - typedef IImportCsf* (* PF_CreateImportCsf) ( void) ; - PF_CreateImportCsf pFun = (PF_CreateImportCsf)GetProcAddress( s_hEEx, EEX_CREATEIMPORTCSF) ; + typedef IImportBtl* (* PF_CreateImportBtl) ( void) ; + PF_CreateImportBtl pFun = (PF_CreateImportBtl)GetProcAddress( s_hEEx, EEX_CREATEIMPORTBTL) ; if ( pFun == nullptr) return nullptr ; return pFun() ; @@ -166,6 +167,21 @@ MyCreateImportCnc( void) return pFun() ; } +//----------------------------------------------------------------------------- +IImportCsf* +MyCreateImportCsf( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IImportCsf* (* PF_CreateImportCsf) ( void) ; + PF_CreateImportCsf pFun = (PF_CreateImportCsf)GetProcAddress( s_hEEx, EEX_CREATEIMPORTCSF) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + //----------------------------------------------------------------------------- IImportDxf* MyCreateImportDxf( void) diff --git a/DllExchange.h b/DllExchange.h index d615fc3..630374a 100644 --- a/DllExchange.h +++ b/DllExchange.h @@ -16,8 +16,9 @@ #include class ILogger ; -class IImportCsf ; +class IImportBtl ; class IImportCnc ; +class IImportCsf ; class IImportDxf ; class IImportStl ; class IExportDxf ; @@ -31,6 +32,7 @@ bool IsLoadedExchangeDll( void) ; void MySetEExLogger( ILogger* pLogger) ; void MySetEExKey( const std::string& sKey) ; const char* MyGetEExVersion( void) ; +IImportBtl* MyCreateImportBtl( void) ; IImportCnc* MyCreateImportCnc( void) ; IImportCsf* MyCreateImportCsf( void) ; IImportDxf* MyCreateImportDxf( void) ; diff --git a/EXE_Exchange.cpp b/EXE_Exchange.cpp index 9df3dad..3e0be41 100644 --- a/EXE_Exchange.cpp +++ b/EXE_Exchange.cpp @@ -15,12 +15,15 @@ #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" +#include "AuxTools.h" #include "DllExchange.h" #include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EExImportStl.h" #include "/EgtDev/Include/EExImportDxf.h" #include "/EgtDev/Include/EExImportCnc.h" #include "/EgtDev/Include/EExImportCsf.h" +#include "/EgtDev/Include/EExImportBtl.h" #include "/EgtDev/Include/EExExportStl.h" #include "/EgtDev/Include/EExExportDxf.h" #include "/EgtDev/Include/EGnStringUtils.h" @@ -43,26 +46,28 @@ ExeGetFileType( const string& sFilePath) ToUpper( sFileExt) ; if ( sFileExt == "NGE") - return 1 ; + return FT_NGE ; else if ( sFileExt == "NFE") - return 2 ; + return FT_NFE ; else if ( sFileExt == "DXF") - return 11 ; + return FT_DXF ; else if ( sFileExt == "STL") - return 12 ; + return FT_STL ; else if ( sFileExt == "CNC") - return 13 ; + return FT_CNC ; else if ( sFileExt == "HED" || sFileExt == "ENT" || sFileExt == "ENS") - return 14 ; + return FT_CSF ; + else if ( sFileExt == "BTL") + return FT_BTL ; else if ( sFileExt == "TSC") - return 101 ; + return FT_TSC ; else if ( sFileExt == "LUA") - return 102 ; + return FT_LUA ; else { // emetto info string sInfo = "File type (" + sFileExt + ") not recognized" ; LOG_INFO( GetLogger(), sInfo.c_str()) - return 0 ; + return FT_NULL ; } } @@ -86,9 +91,7 @@ ExeImportDxf( const string& sFilePath, double dScaleFactor) pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtImportDxf('" + sLuaPath + "'," + + string sLua = "EgtImportDxf('" + StringToLuaString( sFilePath) + "'," + ToString( dScaleFactor) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -118,9 +121,7 @@ ExeImportStl( const string& sFilePath, double dScaleFactor) pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtImportStl('" + sLuaPath + "'," + + string sLua = "EgtImportStl('" + StringToLuaString( sFilePath) + "'," + ToString( dScaleFactor) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -149,9 +150,7 @@ ExeImportCnc( const string& sFilePath) pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtImportCnc('" + sLuaPath + "')" + + string sLua = "EgtImportCnc('" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -177,9 +176,33 @@ ExeImportCsf( const string& sFilePath) pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtImportCsf('" + sLuaPath + "')" + + string sLua = "EgtImportCsf('" + StringToLuaString( sFilePath) + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeImportBtl( const string& sFilePath) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + bool bOk = true ; + // importo il file BTL + // preparo l'importatore + PtrOwner pImpBtl( MyCreateImportBtl()) ; + bOk = bOk && ! IsNull( pImpBtl) ; + // eseguo l'importazione (direttamente nella radice) + bOk = bOk && pImpBtl->Import( sFilePath, pGseCtx->m_pGeomDB) ; + // aggiorno stato file corrente + pGseCtx->m_sFilePath = sFilePath ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtImportBtl('" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -202,10 +225,8 @@ ExeExportDxf( int nId, const string& sFilePath) bOk = bOk && pExpDxf->Export( pGeomDB, nId, sFilePath) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; string sLua = "EgtExportDxf(" + ToString( nId) + ",'" + - sLuaPath + "')" + + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -228,10 +249,8 @@ ExeExportStl( int nId, const string& sFilePath) bOk = bOk && pExpStl->Export( pGeomDB, nId, sFilePath) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; string sLua = "EgtExportStl(" + ToString( nId) + ",'" + - sLuaPath + "')" + + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } diff --git a/EXE_GdbCreate.cpp b/EXE_GdbCreate.cpp index af3b949..2380cfd 100644 --- a/EXE_GdbCreate.cpp +++ b/EXE_GdbCreate.cpp @@ -214,11 +214,9 @@ ExeCreateText( int nParentId, const Point3d& ptP, ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaText = sText ; - ReplaceString( sLuaText, "'", "\\'") ; string sLua = "EgtText(" + IdToString( nParentId) + ",{" + ToString( ptP) + "},'" + - sLuaText + "'," + + StringToLuaString( sText) + "'," + ToString( dH) + "," + RefTypeToString( nRefType) + ")" + " -- Id=" + ToString( nId) ; @@ -253,15 +251,11 @@ ExeCreateTextEx( int nParentId, const Point3d& ptP, double dAngRotDeg, ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaText = sText ; - ReplaceString( sLuaText, "'", "\\'") ; - string sLuaFont = sFont ; - ReplaceString( sLuaFont, "'", "\\'") ; string sLua = "EgtTextEx(" + IdToString( nParentId) + ",{" + ToString( ptP) + "}," + ToString( dAngRotDeg) + ",'" + - sLuaText + "','" + - sLuaFont + "'," + + StringToLuaString( sText) + "','" + + StringToLuaString( sFont) + "'," + ( bItalic ? "'I'" : "'S'") + "," + ToString( dH) + "," + RefTypeToString( nRefType) + ")" + @@ -298,15 +292,11 @@ ExeCreateTextAdv( int nParentId, const Point3d& ptP, double dAngRotDeg, ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaText = sText ; - ReplaceString( sLuaText, "'", "\\'") ; - string sLuaFont = sFont ; - ReplaceString( sLuaFont, "'", "\\'") ; string sLua = "EgtTextAdv(" + IdToString( nParentId) + ",{" + ToString( ptP) + "}," + ToString( dAngRotDeg) + ",'" + - sLuaText + "','" + - sLuaFont + "'," + + StringToLuaString( sText) + "','" + + StringToLuaString( sFont) + "'," + ToString( nW) + "," + ( bItalic ? "'I'" : "'S'") + "," + ToString( dH) + "," + diff --git a/EXE_GdbObjAttribs.cpp b/EXE_GdbObjAttribs.cpp index 244a9ef..610c0cb 100644 --- a/EXE_GdbObjAttribs.cpp +++ b/EXE_GdbObjAttribs.cpp @@ -402,10 +402,8 @@ ExeSetName( int nId, const string& sName) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaName = sName ; - ReplaceString( sLuaName, "'", "\\'") ; string sLua = "EgtSetName(" + ToString( nId) + ",'" + - sLuaName + "')" + + StringToLuaString( sName) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -463,13 +461,9 @@ ExeSetInfo( int nId, const string& sKey, const string& sInfo) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaKey = sKey ; - ReplaceString( sLuaKey, "'", "\\'") ; - string sLuaInfo = sInfo ; - ReplaceString( sLuaInfo, "'", "\\'") ; string sLua = "EgtSetInfo(" + ToString( nId) + ",'" + - sLuaKey + "','" + - sLuaInfo + "')" + + StringToLuaString( sKey) + "','" + + StringToLuaString( sInfo) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -530,10 +524,8 @@ ExeRemoveInfo( int nId, const string& sKey) ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaKey = sKey ; - ReplaceString( sLuaKey, "'", "\\'") ; string sLua = "EgtRemoveInfo(" + ToString( nId) + ",'" + - sLuaKey + "')" + + StringToLuaString( sKey) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } diff --git a/EXE_GeomDB.cpp b/EXE_GeomDB.cpp index 0a75bb4..d37f5be 100644 --- a/EXE_GeomDB.cpp +++ b/EXE_GeomDB.cpp @@ -281,9 +281,7 @@ ExeOpenFile( const string& sFilePath) ExeUpdateMachMgr() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtOpenFile('" + sLuaPath + "')" + + string sLua = "EgtOpenFile('" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -324,9 +322,7 @@ ExeInsertFile( const string& sFilePath) pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtInsertFile('" + sLuaPath + "')" + + string sLua = "EgtInsertFile('" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } @@ -354,9 +350,7 @@ ExeSaveFile( const string& sFilePath, int nFlag) pGseCtx->m_bModified = false ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtSaveFile('" + sLuaPath + "'," + + string sLua = "EgtSaveFile('" + StringToLuaString( sFilePath) + "'," + NgeTypeToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -381,9 +375,7 @@ ExeSaveObjToFile( int nId, const string& sFilePath, int nFlag) ExeSetCurrMachGroup( nCurrMachGroup) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - string sLua = "EgtSaveObjToFile('" + sLuaPath + "'," + + string sLua = "EgtSaveObjToFile('" + StringToLuaString( sFilePath) + "'," + ToString( nId) + "," + NgeTypeToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; diff --git a/EXE_Lua.cpp b/EXE_Lua.cpp index 5a08ffb..1ed1c34 100644 --- a/EXE_Lua.cpp +++ b/EXE_Lua.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "EXE.h" #include "LUA_Base.h" +#include "AuxTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EgtStringConverter.h" @@ -204,10 +205,7 @@ ExeLuaExecFile( const string& sFilePath) ExeEnableCommandLogger() ; // se richiesto, salvo il comando Lua if ( IsCmdLog()) { - string sLuaPath = sFilePath ; - ReplaceString( sLuaPath, "\\", "\\\\") ; - ReplaceString( sLuaPath, "'", "\\'") ; - string sLua = "dofile('" + sLuaPath + "')" + + string sLua = "dofile('" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 36a19333666f086de36818d09a1acdd035d17d6a..746d2f4588de6fbfa7f0a0d1a0a99da79e2b503e 100644 GIT binary patch delta 79 zcmZ1$y)1geFE&Qg&A-`PnSqoe*K!sx?>N)s4T4pSrjs4Hk~jAW*?>e(i-FY$N+HxV MD8kglDS2=M0AR!#egFUf delta 79 zcmZ1$y)1geFE&P#&A-`PnSqoe*K!sx?>N)s4T4pSCX*exk~jAW*?>e(i-FY$N+HxV MD8kglDS2=M0AF|-b^rhX diff --git a/LUA_Exchange.cpp b/LUA_Exchange.cpp index 5fdda35..fd57dfe 100644 --- a/LUA_Exchange.cpp +++ b/LUA_Exchange.cpp @@ -85,6 +85,21 @@ LuaImportCsf( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaImportBtl( lua_State* L) +{ + // 1 parametro : path del file da importare + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + LuaClearStack( L) ; + // apro il file + bool bOk = ExeImportBtl( sFilePath) ; + // restituisco il risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaExportDxf( lua_State* L) @@ -128,6 +143,7 @@ LuaInstallExchange( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtImportStl", LuaImportStl) ; bOk = bOk && luaMgr.RegisterFunction( "EgtImportCnc", LuaImportCnc) ; bOk = bOk && luaMgr.RegisterFunction( "EgtImportCsf", LuaImportCsf) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtImportBtl", LuaImportBtl) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExportDxf", LuaExportDxf) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExportStl", LuaExportStl) ; return bOk ;