//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : API_Exchange.cpp Data : 20.09.14 Versione : 1.5i4 // Contenuto : Funzioni import/export per API. // // // // Modifiche : 20.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "API.h" #include "API_Macro.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EExImportStl.h" #include "/EgtDev/Include/EExImportDxf.h" #include "/EgtDev/Include/EExImportCnc.h" #include "/EgtDev/Include/EExExportStl.h" #include "/EgtDev/Include/EExExportDxf.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnStringConverter.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //----------------------------------------------------------------------------- int __stdcall EgtGetFileType( const wchar_t* wsFilePath) { return EgtGetFileType( wstrztoA( wsFilePath)) ; } //----------------------------------------------------------------------------- int __stdcall EgtGetFileType( const string& sFilePath) { // divido in nome e direttorio string sFileDir, sFileName ; SplitLast( sFilePath, "\\", sFileDir, sFileName) ; // recupero l'estensione string sFileTitle, sFileExt ; SplitLast( sFileName, ".", sFileTitle, sFileExt) ; ToUpper( sFileExt) ; if ( sFileExt == "NGE") return 1 ; else if ( sFileExt == "NFE") return 2 ; else if ( sFileExt == "DXF") return 11 ; else if ( sFileExt == "STL") return 12 ; else if ( sFileExt == "CNC") return 13 ; else { // emetto info string sInfo = "File type (" + sFileExt + ") not recognized" ; LOG_INFO( GetLogger(), sInfo.c_str()) return 0 ; } } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportDxf( int nGseCtx, const wchar_t* wsFilePath) { return EgtImportDxf( nGseCtx, wstrztoA( wsFilePath)) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportDxf( int nGseCtx, const string& sFilePath) { IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ; VERIFY_GEOMDB( pGeomDB, FALSE) // importo il file DXF // aggiungo un gruppo pezzo int nPartId = pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; // preparo l'importatore PtrOwner pImpDxf( CreateImportDxf()) ; VERIFY_NULL( Get( pImpDxf), "Error in CreateImportDxf", FALSE) // eseguo l'importazione return ( pImpDxf->Import( sFilePath, pGeomDB, nPartId) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportStl( int nGseCtx, const wchar_t* wsFilePath) { return EgtImportStl( nGseCtx, wstrztoA( wsFilePath)) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportStl( int nGseCtx, const string& sFilePath) { IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ; VERIFY_GEOMDB( pGeomDB, FALSE) // importo il file STL // aggiungo un gruppo pezzo e un gruppo layer int nPartId = pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; int nLayerId = pGeomDB->AddGroup( GDB_ID_NULL, nPartId, Frame3d()) ; // preparo l'importatore PtrOwner pImpStl( CreateImportStl()) ; VERIFY_NULL( Get( pImpStl), "Error in CreateImportStl", FALSE) // eseguo l'importazione return ( pImpStl->Import( sFilePath, pGeomDB, nLayerId) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportCnc( int nGseCtx, const wchar_t* wsFilePath) { return EgtImportCnc( nGseCtx, wstrztoA( wsFilePath)) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportCnc( int nGseCtx, const string& sFilePath) { IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ; VERIFY_GEOMDB( pGeomDB, FALSE) // importo il file CNC // aggiungo un gruppo pezzo int nPartId = pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; // preparo l'importatore PtrOwner pImpCnc( CreateImportCnc()) ; VERIFY_NULL( Get( pImpCnc), "Error in CreateImportCnc", FALSE) // eseguo l'importazione return ( pImpCnc->Import( sFilePath, pGeomDB, nPartId) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExportDxf( int nGseCtx, int nId, const wchar_t* wsFilePath) { return EgtExportDxf( nGseCtx, nId, wstrztoA( wsFilePath)) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExportDxf( int nGseCtx, int nId, const string& sFilePath) { IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ; VERIFY_GEOMDB( pGeomDB, FALSE) // esporto il file DXF // preparo l'esportatore PtrOwner pExpDxf( CreateExportDxf()) ; VERIFY_NULL( Get( pExpDxf), "Error in CreateExportDxf", FALSE) // eseguo l'esportazione return ( pExpDxf->Export( pGeomDB, nId, sFilePath) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExportStl( int nGseCtx, int nId, const wchar_t* wsFilePath) { return EgtExportStl( nGseCtx, nId, wstrztoA( wsFilePath)) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExportStl( int nGseCtx, int nId, const string& sFilePath) { IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ; VERIFY_GEOMDB( pGeomDB, FALSE) // esporto il file STL // preparo l'esportatore PtrOwner pExpStl( CreateExportStl()) ; VERIFY_NULL( Get( pExpStl), "Error in CreateExportStl", FALSE) // eseguo l'esportazione return ( pExpStl->Export( pGeomDB, nId, sFilePath) ? TRUE : FALSE) ; }