From 7e7975c622e3608b31fca04f02bd971a192d6861 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Thu, 3 Aug 2023 11:24:02 +0200 Subject: [PATCH] EgtExecutor : - aggiunto l'import dei file 3dm. --- DllExchange.cpp | 16 ++++++++++++++++ DllExchange.h | 2 ++ EXE_Exchange.cpp | 34 ++++++++++++++++++++++++++++++++++ LUA_Exchange.cpp | 18 ++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/DllExchange.cpp b/DllExchange.cpp index c9964a2..6670035 100644 --- a/DllExchange.cpp +++ b/DllExchange.cpp @@ -49,6 +49,7 @@ static const char* EEX_CREATEIMPORTDXF = "CreateImportDxf" ; static const char* EEX_CREATEIMPORTPNT = "CreateImportPnt" ; static const char* EEX_CREATEIMPORTSTL = "CreateImportStl" ; static const char* EEX_CREATEIMPORT3MF = "CreateImport3MF" ; +static const char* EEX_CREATEIMPORT3DM = "CreateImport3dm" ; static const char* EEX_CREATEEXPORTDXF = "CreateExportDxf" ; static const char* EEX_CREATEEXPORTSTL = "CreateExportStl" ; static const char* EEX_CREATEEXPORT3MF = "CreateExport3MF" ; @@ -316,6 +317,21 @@ MyCreateImport3MF( void) return pFun() ; } +//----------------------------------------------------------------------------- +IImport3dm* +MyCreateImport3dm( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IImport3dm* (* PF_CreateImport3dm) ( void) ; + PF_CreateImport3dm pFun = (PF_CreateImport3dm)GetProcAddress( s_hEEx, EEX_CREATEIMPORT3DM) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + //----------------------------------------------------------------------------- IExportDxf* MyCreateExportDxf( void) diff --git a/DllExchange.h b/DllExchange.h index 2c60b89..0a536bc 100644 --- a/DllExchange.h +++ b/DllExchange.h @@ -25,6 +25,7 @@ class IImportDxf ; class IImportPnt ; class IImportStl ; class IImport3MF ; +class IImport3dm ; class IExportDxf ; class IExportStl ; class IExport3MF ; @@ -50,6 +51,7 @@ IImportDxf* MyCreateImportDxf( void) ; IImportPnt* MyCreateImportPnt( void) ; IImportStl* MyCreateImportStl( void) ; IImport3MF* MyCreateImport3MF( void) ; +IImport3dm* MyCreateImport3dm( void) ; IExportDxf* MyCreateExportDxf( void) ; IExportStl* MyCreateExportStl( void) ; IExport3MF* MyCreateExport3MF( void) ; diff --git a/EXE_Exchange.cpp b/EXE_Exchange.cpp index dfba3e4..9fc49fd 100644 --- a/EXE_Exchange.cpp +++ b/EXE_Exchange.cpp @@ -28,6 +28,7 @@ #include "/EgtDev/Include/EExImportPnt.h" #include "/EgtDev/Include/EExImportBtl.h" #include "/EgtDev/Include/EExImportBtlx.h" +#include "/EgtDev/Include/EExImport3dm.h" #include "/EgtDev/Include/EExExportDxf.h" #include "/EgtDev/Include/EExExportStl.h" #include "/EgtDev/Include/EExExport3MF.h" @@ -80,6 +81,8 @@ ExeGetFileType( const string& sFilePath) return FT_BTL ; else if ( sFileExt == "BTLX") return FT_BTLX ; + else if ( sFileExt == "3DM") + return FT_3DM ; else if ( sFileExt == "PNG" || sFileExt == "JPG" || sFileExt == "JPEG" || sFileExt == "BMP") return FT_IMG ; else if ( sFileExt == "PNT" || sFileExt == "XYZ") @@ -355,6 +358,37 @@ ExeImport3MF( const string& sFilePath) return bOk ; } +//----------------------------------------------------------------------------- +bool +ExeImport3dm( const string& sFilePath, double dScaleFactor) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + bool bOk = true ; + // importo il file 3dm + // aggiungo un gruppo pezzo e un gruppo layer + int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; + int nLayerId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, nPartId, Frame3d()) ; + // preparo l'importatore + PtrOwner pImp3dm( MyCreateImport3dm()) ; + bOk = bOk && ! IsNull( pImp3dm) ; + // eseguo l'importazione + bOk = bOk && pImp3dm->Import( sFilePath, pGseCtx->m_pGeomDB, nLayerId, dScaleFactor) ; + // aggiorno stato file corrente + if ( pGseCtx->m_sFilePath.empty()) + pGseCtx->m_sFilePath = sFilePath ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtImport3dm('" + StringToLuaString( sFilePath) + "'," + + ToString( dScaleFactor) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + //----------------------------------------------------------------------------- bool ExeAdvancedImportIsEnabled( void) diff --git a/LUA_Exchange.cpp b/LUA_Exchange.cpp index dc44f12..4981ee2 100644 --- a/LUA_Exchange.cpp +++ b/LUA_Exchange.cpp @@ -169,6 +169,23 @@ LuaImport3MF( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaImport3dm( lua_State* L) +{ + // 1 o 2 parametri : path del file da importare [, Fattore di scala] + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + double dScaleFactor = 1.0 ; + LuaGetParam( L, 2, dScaleFactor) ; + LuaClearStack( L) ; + // apro il file + bool bOk = ExeImport3dm( sFilePath, dScaleFactor) ; + // restituisco il risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaAdvancedImport( lua_State* L) @@ -297,6 +314,7 @@ LuaInstallExchange( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtImportPnt", LuaImportPnt) ; bOk = bOk && luaMgr.RegisterFunction( "EgtImportStl", LuaImportStl) ; bOk = bOk && luaMgr.RegisterFunction( "EgtImport3MF", LuaImport3MF) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtImport3dm", LuaImport3dm) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAdvancedImport", LuaAdvancedImport) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExportDxf", LuaExportDxf) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExportStl", LuaExportStl) ;