//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : API_GeomDB.cpp Data : 01.09.14 Versione : 1.5i1 // Contenuto : Funzioni DB geometrico per API. // // // // Modifiche : 01.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "API.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EExImportStl.h" #include "/EgtDev/Include/EExImportDxf.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 EgtInitGeomDB( void) { // inizializzazioni DB geometrico PtrOwner pGeomDB( CreateGeomDB()) ; if ( IsNull( pGeomDB)) return 0 ; // creo e recupero un contesto libero int nGseCtx = CreateGseContext() ; if ( nGseCtx == 0) return 0 ; GseContext* pGseCtx = GetGseContext( nGseCtx) ; // inserisco il GeomDB nel contesto pGseCtx->m_pGeomDB = Release( pGeomDB) ; pGseCtx->m_pGeomDB->Init() ; pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ; // log avvio DB geometrico LOG_INFO( GetLogger(), "GeomDB started") return nGseCtx ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetDefaultMaterial( int nGseCtx, int nRed, int nGreen, int nBlue) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtSetDefaultMaterial)") return FALSE ; } // imposto il materiale di default pGseCtx->m_colDef.Set( nRed, nGreen, nBlue) ; pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtNewFile( int nGseCtx) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtNewFile)") return FALSE ; } // reinizializzazione (con pulizia) del DB geometrico pGseCtx->m_pGeomDB->Init() ; pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtOpenFile( int nGseCtx, const wchar_t* wsFilePath) { // reinizializzazione (con pulizia) del DB geometrico if ( ! EgtNewFile( nGseCtx)) return FALSE ; // carico il file if ( GetGseContext( nGseCtx)->m_pGeomDB->Load( LPSTR( WtoA( wsFilePath)))) return TRUE ; else return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSaveFile( int nGseCtx, const wchar_t* wsFilePath, int nFlag) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtSaveFile)") return FALSE ; } // salvo il file if ( pGseCtx->m_pGeomDB->Save( LPSTR( WtoA( wsFilePath)), nFlag)) return TRUE ; else return FALSE ; } //----------------------------------------------------------------------------- int __stdcall EgtGetFileType( const wchar_t* wsFilePath) { // divido in nome e direttorio string sFileDir, sFileName ; SplitLast( LPSTR( WtoA( wsFilePath)), "\\", 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 { // 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) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtImportDxf)") return FALSE ; } // 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( CreateImportDxf()) ; if ( IsNull( pImpDxf)) { LOG_ERROR( GetLogger(), "Error : CreateImportDxf") return FALSE ; } // eseguo l'importazione if ( pImpDxf->Import( LPSTR( WtoA( wsFilePath)), pGseCtx->m_pGeomDB, nPartId)) return TRUE ; else return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtImportStl( int nGseCtx, const wchar_t* wsFilePath) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtImportStl)") return FALSE ; } // 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( CreateImportStl()) ; if ( IsNull( pImpStl)) { LOG_ERROR( GetLogger(), "Error : CreateImportStl") return FALSE ; } // eseguo l'importazione if ( pImpStl->Import( LPSTR( WtoA( wsFilePath)), pGseCtx->m_pGeomDB, nLayerId)) return TRUE ; else return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExportDxf( int nGseCtx, int nId, const wchar_t* wsFilePath) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtExportDxf)") return FALSE ; } // esporto il file DXF // preparo l'esportatore PtrOwner pExpDxf( CreateExportDxf()) ; if ( IsNull( pExpDxf)) { LOG_ERROR( GetLogger(), "Error : CreateExportDxf") return FALSE ; } // eseguo l'esportazione if ( pExpDxf->Export( pGseCtx->m_pGeomDB, nId, LPSTR( WtoA( wsFilePath)))) return TRUE ; else return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExportStl( int nGseCtx, int nId, const wchar_t* wsFilePath) { // verifico GeomDB GseContext* pGseCtx = GetGseContext( nGseCtx) ; if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { LOG_ERROR( GetLogger(), "GeomDB invalid (EgtExportStl)") return FALSE ; } // esporto il file STL // preparo l'esportatore PtrOwner pExpStl( CreateExportStl()) ; if ( IsNull( pExpStl)) { LOG_ERROR( GetLogger(), "Error : CreateExportStl") return FALSE ; } // eseguo l'esportazione if ( pExpStl->Export( pGseCtx->m_pGeomDB, nId, LPSTR( WtoA( wsFilePath)))) return TRUE ; else return FALSE ; }