//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : EXE_Exchange.cpp Data : 20.09.14 Versione : 1.6e1 // Contenuto : Funzioni import/export per EXE. // // // // Modifiche : 20.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #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/EExExportSvg.h" #include "/EgtDev/Include/EExExportDxf.h" #include "/EgtDev/Include/EExImportPnt.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EgtStringConverter.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //----------------------------------------------------------------------------- int ExeGetFileType( const string& sFilePath) { // divido in nome e direttorio string sFileDir, sFileName ; if ( sFilePath.find( "\\") != string::npos) SplitLast( sFilePath, "\\", sFileDir, sFileName) ; else sFileName = sFilePath ; // recupero l'estensione string sFileTitle, sFileExt ; SplitLast( sFileName, ".", sFileTitle, sFileExt) ; ToUpper( sFileExt) ; if ( sFileExt == "NGE" || sFileExt == "VME" || sFileExt == "NHE") return FT_NGE ; else if ( sFileExt == "NFE") return FT_NFE ; else if ( sFileExt == "DXF") return FT_DXF ; else if ( sFileExt == "STL") return FT_STL ; else if ( sFileExt == "CNC" || sFileExt == "XPI" || sFileExt == "MPF") return FT_CNC ; else if ( sFileExt == "HED" || sFileExt == "ENT" || sFileExt == "ENS") return FT_CSF ; else if ( sFileExt == "BTL") return FT_BTL ; else if ( sFileExt == "PNG" || sFileExt == "JPG" || sFileExt == "JPEG" || sFileExt == "BMP") return FT_IMG ; else if ( sFileExt == "PNT" || sFileExt == "XYZ") return FT_PNT ; else if ( sFileExt == "SVG") return FT_SVG ; else if ( sFileExt == "TSC") return FT_TSC ; else if ( sFileExt == "LUA") return FT_LUA ; else { // emetto info string sInfo = "File type (" + sFileExt + ") not recognized" ; LOG_INFO( GetLogger(), sInfo.c_str()) return FT_NULL ; } } //----------------------------------------------------------------------------- bool ExeImportBtl( const string& sFilePath, int nFlag) { 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, nFlag) ; // 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 = "EgtImportBtl('" + StringToLuaString( sFilePath) + "'," + ToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeImportCnc( const string& sFilePath, int nFlag) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) bool bOk = true ; // importo il file CNC // aggiungo un gruppo pezzo int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; // preparo l'importatore PtrOwner pImpCnc( MyCreateImportCnc()) ; bOk = bOk && ! IsNull( pImpCnc) ; // eseguo l'importazione bOk = bOk && pImpCnc->Import( sFilePath, pGseCtx->m_pGeomDB, nPartId, nFlag) ; // 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 = "EgtImportCnc('" + StringToLuaString( sFilePath) + "'," + ToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeImportCsf( const string& sFilePath) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) bool bOk = true ; // importo il file CSF // preparo l'importatore PtrOwner pImpCsf( MyCreateImportCsf()) ; bOk = bOk && ! IsNull( pImpCsf) ; // eseguo l'importazione (direttamente nella radice) bOk = bOk && pImpCsf->Import( sFilePath, pGseCtx->m_pGeomDB) ; // 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 = "EgtImportCsf('" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeImportDxf( const string& sFilePath, double dScaleFactor) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) bool bOk = true ; // importo il file DXF // aggiungo un gruppo pezzo int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; // preparo l'importatore PtrOwner pImpDxf( MyCreateImportDxf()) ; bOk = bOk && ! IsNull( pImpDxf) ; // eseguo l'importazione bOk = bOk && pImpDxf->Import( sFilePath, pGseCtx->m_pGeomDB, nPartId, 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 = "EgtImportDxf('" + StringToLuaString( sFilePath) + "'," + ToString( dScaleFactor) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeImportPnt( const string& sFilePath, int nFlag) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) bool bOk = true ; // importo il file PNT // aggiungo un gruppo pezzo int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; // preparo l'importatore PtrOwner pImpPnt( MyCreateImportPnt()) ; bOk = bOk && ! IsNull( pImpPnt) ; // eseguo l'importazione bOk = bOk && pImpPnt->Import( sFilePath, pGseCtx->m_pGeomDB, nPartId, nFlag) ; // 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 = "EgtImportPnt('" + StringToLuaString( sFilePath) + "'," + ToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeImportStl( const string& sFilePath, double dScaleFactor) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) bool bOk = true ; // importo il file STL // 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 pImpStl( MyCreateImportStl()) ; bOk = bOk && ! IsNull( pImpStl) ; // eseguo l'importazione bOk = bOk && pImpStl->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 = "EgtImportStl('" + StringToLuaString( sFilePath) + "'," + ToString( dScaleFactor) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeExportDxf( int nId, const string& sFilePath) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // esporto il file DXF // preparo l'esportatore PtrOwner pExpDxf( MyCreateExportDxf()) ; bOk = bOk && ! IsNull( pExpDxf) ; // eseguo l'esportazione bOk = bOk && pExpDxf->Export( pGeomDB, nId, sFilePath) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtExportDxf(" + ToString( nId) + ",'" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeExportStl( int nId, const string& sFilePath) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // esporto il file STL // preparo l'esportatore PtrOwner pExpStl( MyCreateExportStl()) ; bOk = bOk && ! IsNull( pExpStl) ; // eseguo l'esportazione bOk = bOk && pExpStl->Export( pGeomDB, nId, sFilePath) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtExportStl(" + ToString( nId) + ",'" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeExportSvg( int nId, const string& sFilePath) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) bool bOk = true ; // esporto il file SVG // preparo l'esportatore PtrOwner pExpSvg( MyCreateExportSvg()) ; bOk = bOk && ! IsNull( pExpSvg) ; // eseguo l'esportazione bOk = bOk && pExpSvg->Export( pGeomDB, nId, sFilePath) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtExportSvg(" + ToString( nId) + ",'" + StringToLuaString( sFilePath) + "')" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; }