diff --git a/API.h b/API.h new file mode 100644 index 0000000..be34a96 --- /dev/null +++ b/API.h @@ -0,0 +1,20 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API.h Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Dichiarazioni locali per moduli API. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "GseContext.h" +#include "/EgtDev/Include/EgtILogger.h" + +//---------------------------------------------------------------------------- +ILogger* GetLogger( void) ; diff --git a/API_General.cpp b/API_General.cpp new file mode 100644 index 0000000..2e79cbe --- /dev/null +++ b/API_General.cpp @@ -0,0 +1,103 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_General.cpp Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Funzioni generali per API. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "API.h" +#include "/EgtDev/Include/EInAPI.h" +#include "/EgtDev/Include/EInDllMain.h" +#include "/EgtDev/Include/EGkDllMain.h" +#include "/EgtDev/Include/ENkDllMain.h" +#include "/EgtDev/Include/EGnDllMain.h" +#include "/EgtDev/Include/EExDllMain.h" +#include "/EgtDev/Include/EGrDllMain.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtLogger.h" +#include + +using namespace std ; +using namespace egtlogger ; + +//---------------------------------------------------------------------------- +static Logger* s_pLogGen = nullptr ; + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtInit( int nDebug, const wchar_t* sLogFile) +{ + // cancello eventuali vecchi contesti + ClearAllGseContexts() ; + // cancello eventuale vecchio logger + if ( s_pLogGen != nullptr) + delete s_pLogGen ; + // creo il logger generale + s_pLogGen = new Logger( ( nDebug > 0 ? LL_DEBUG : LL_INFO), "EgtInterface") ; + if ( s_pLogGen == nullptr) + return FALSE ; + // assegno il file + s_pLogGen->AddOutputStream( new ofstream( sLogFile), true) ; + // lo passo alle DLL + SetEGnLogger( s_pLogGen) ; + SetENkLogger( s_pLogGen) ; + SetEGkLogger( s_pLogGen) ; + SetEExLogger( s_pLogGen) ; + SetEGrLogger( s_pLogGen) ; + + // dichiaro inizio programma + LOG_DATETIME( s_pLogGen, " Init") + // versione dell'interfaccia + LOG_INFO( s_pLogGen, GetEInVersion()) + // versione delle librerie + LOG_INFO( s_pLogGen, GetEGnVersion()) + LOG_INFO( s_pLogGen, GetENkVersion()) + LOG_INFO( s_pLogGen, GetEGkVersion()) + LOG_INFO( s_pLogGen, GetEExVersion()) + LOG_INFO( s_pLogGen, GetEGrVersion()) + + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtExit( void) +{ + // fine programma + LOG_DATETIME( s_pLogGen, " Exit") + + // cancello tutti i contesti + ClearAllGseContexts() ; + // cancello il logger + if ( s_pLogGen != nullptr) { + delete s_pLogGen ; + s_pLogGen = nullptr ; + } + + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtSetFont( const wchar_t* sNfeFontDir, const wchar_t* sDefaultFont) +{ + // inizializzazioni gestore font Nfe + InitFontManager( LPSTR( WtoA( sNfeFontDir)), LPSTR( WtoA( sDefaultFont))) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +ILogger* +GetLogger( void) +{ + return s_pLogGen ; +} + diff --git a/API_GeomDB.cpp b/API_GeomDB.cpp new file mode 100644 index 0000000..a174f68 --- /dev/null +++ b/API_GeomDB.cpp @@ -0,0 +1,243 @@ +//---------------------------------------------------------------------------- +// 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 ; +} diff --git a/API_Scene.cpp b/API_Scene.cpp new file mode 100644 index 0000000..4cf66f0 --- /dev/null +++ b/API_Scene.cpp @@ -0,0 +1,345 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_Scene.cpp Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Funzioni Scene per API. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "API.h" +#include "/EgtDev/Include/EInAPI.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtInitScene( int nGseCtx, HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDepthBits) +{ + // recupero il contesto + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + // verifico GeomDB + if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { + LOG_ERROR( GetLogger(), "GeomDB invalid (EgtInitScene)") + return FALSE ; + } + // inizializzazione scena OpenGL + PtrOwner pScene( CreateEGrScene()) ; + if ( IsNull( pScene)) + return FALSE ; + HDC hdc = GetDC( hWnd) ; + if ( ! pScene->CreateContext( hdc, nDriver, ( b2Buff != 0), nColorBits, nDepthBits)) + return FALSE ; + pScene->SetBackground( WHITE, WHITE) ; + pScene->SetShowMode( SM_SHADING) ; + pScene->SetShowCurveDirection( false) ; + pScene->SetCamera( CT_TOP) ; + pScene->ZoomAll() ; + pScene->SetWinRectAttribs( true, BLACK) ; + pScene->SetMark( YELLOW) ; + pScene->Init( pGseCtx->m_pGeomDB) ; + // assegno la scena al contesto + pGseCtx->m_hWnd = hWnd ; + pGseCtx->m_pScene = Release( pScene) ; + // log con info sulla scena + string sSceneInfo = pGseCtx->m_pScene->GetOpenGLInfo() + '\n' + + pGseCtx->m_pScene->GetGLSLInfo() + '\n' + + pGseCtx->m_pScene->GetPixelFormatInfo() ; + LOG_INFO( GetLogger(), sSceneInfo.c_str()) + + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtSetBackground( int nGseCtx, int nTopRed, int nTopGreen, int nTopBlue, + int nBottomRed, int nBottomGreen, int nBottomBlue) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtSetBackground)") + return FALSE ; + } + // imposto lo sfondo + pGseCtx->m_pScene->SetBackground( Color( nTopRed, nTopGreen, nTopBlue), + Color( nBottomRed, nBottomGreen, nBottomBlue)) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtDraw( int nGseCtx) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtDraw)") + return FALSE ; + } + // eseguo disegno + pGseCtx->m_pScene->Draw() ; + // valido la finestra disegnata + ValidateRgn( pGseCtx->m_hWnd, NULL) ; + + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtResize( int nGseCtx, int nW, int nH) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtResize)") + return FALSE ; + } + // eseguo resize + pGseCtx->m_pScene->Resize( nW, nH) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtSetShowMode( int nGseCtx, int nShowMode, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtSetShowMode)") + return FALSE ; + } + // imposto il modo di visualizzazione + if ( nShowMode >= SM_WIREFRAME && nShowMode <= SM_SHADING) { + pGseCtx->m_pScene->SetShowMode( nShowMode) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; + } + else + return FALSE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtSetShowCurveDirection( int nGseCtx, int nShow, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtSetShowCurveDirection)") + return FALSE ; + } + // imposto stato + pGseCtx->m_pScene->SetShowCurveDirection( nShow != 0) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtZoom( int nGseCtx, int nZoom, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtZoom)") + return FALSE ; + } + + const double COEFF_IN = 0.9 ; + const double COEFF_OUT = 1 / COEFF_IN ; + + switch ( nZoom) { + case 1 : + pGseCtx->m_pScene->ZoomAll() ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; + break ; + case 2 : + pGseCtx->m_pScene->ZoomChange( COEFF_IN) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; + break ; + case 3 : + pGseCtx->m_pScene->ZoomChange( COEFF_OUT) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; + break ; + } + + return FALSE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtZoomOnPoint( int nGseCtx, int nWinX, int nWinY, double dCoeff, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtZoomOnPoint)") + return FALSE ; + } + // eseguo zoom + pGseCtx->m_pScene->ZoomOnPoint( Point3d( nWinX, nWinY), dCoeff) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtSetWinRect( int nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtSetWinRect)") + return FALSE ; + } + // disegno finestra per zoom + pGseCtx->m_pScene->SetWinRect( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtResetWinRect( int nGseCtx, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtResetWinRect)") + return FALSE ; + } + // cancello finestra per zoom + pGseCtx->m_pScene->ResetWinRect() ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtZoomWin( int nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtZoomWin)") + return FALSE ; + } + // eseguo zoom su finestra + pGseCtx->m_pScene->ZoomWin( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtSetView( int nGseCtx, int nView, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtSetView)") + return FALSE ; + } + // imposto vista + if ( nView >= CT_TOP && nView <= CT_ISO_NW) { + pGseCtx->m_pScene->SetCamera( nView) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; + } + else + return FALSE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtPanCamera( int nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtPanCamera)") + return FALSE ; + } + // eseguo panoramica + pGseCtx->m_pScene->PanCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtRotateCamera( int nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtRotateCamera)") + return FALSE ; + } + // eseguo rotazione camera + pGseCtx->m_pScene->RotateCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + RedrawWindow( pGseCtx->m_hWnd, nullptr, nullptr, RDW_INVALIDATE) ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtGetCameraDir( int nGseCtx, int* pnDir) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtGetCameraDir)") + return FALSE ; + } + // recupero direzione di vista + if ( pnDir != nullptr) + *pnDir = pGseCtx->m_pScene->GetCameraDir() ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtUnProjectPoint( int nGseCtx, int nWinX, int nWinY, double ptP[3]) +{ + // verifico Scena + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pScene == nullptr) { + LOG_ERROR( GetLogger(), "Scene invalid (EgtUnProjectPoint)") + return FALSE ; + } + // eseguo l'inverso della proiezione (considero Z punto su centro) + Point3d ptView( nWinX, nWinY, pGseCtx->m_pScene->GetProjectedCenter().z) ; + Point3d ptWorld ; + if ( ! pGseCtx->m_pScene->UnProject( ptView, ptWorld)) + return 0 ; + ptP[0] = ptWorld.x ; + ptP[1] = ptWorld.y ; + ptP[2] = ptWorld.z ; + return TRUE ; +} diff --git a/API_TscExec.cpp b/API_TscExec.cpp new file mode 100644 index 0000000..557ad57 --- /dev/null +++ b/API_TscExec.cpp @@ -0,0 +1,133 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_TscExec.cpp Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Funzioni esecuzione TSC per API. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "API.h" +#include "/EgtDev/Include/EInAPI.h" +#include "/EgtDev/Include/EGkGdbExecutor.h" +#include "/EgtDev/Include/EExExcExecutor.h" +#include "/EgtDev/Include/EGrSceExecutor.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" +#include + +using namespace std ; + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtInitTscExec( int nGseCtx) +{ + // recupero il contesto + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + // verifico GeomDB + if ( pGseCtx == nullptr || pGseCtx->m_pGeomDB == nullptr) { + LOG_ERROR( GetLogger(), "GeomDB invalid (EgtInitTscExec)") + return FALSE ; + } + + // eventuale pulizia esecutore e suoi oggetti + if ( pGseCtx->m_pTscExec != nullptr) { + delete pGseCtx->m_pTscExec ; + pGseCtx->m_pTscExec = nullptr ; + } + + // creo esecutore + PtrOwner pCmdParser( CreateCmdParser()) ; + if ( IsNull( pCmdParser)) { + LOG_ERROR( GetLogger(), "Error in CreateCmdParser") + return FALSE ; + } + + // creo oggetto per esecuzione funzioni di GeomKernel + PtrOwner pGdbExec( CreateGdbExecutor()) ; + if ( IsNull( pGdbExec)) { + LOG_ERROR( GetLogger(), "Error in CreateGdbExecutor") + return FALSE ; + } + pGdbExec->SetGeomDB( pGseCtx->m_pGeomDB) ; + pCmdParser->SetExecutor( Release( pGdbExec)) ; + + // creazione oggetto per esecuzione funzioni di Exchange + PtrOwner pExcExec( CreateExcExecutor()) ; + if ( IsNull( pExcExec)) { + LOG_ERROR( GetLogger(), "Error in CreateExcExecutor") + return FALSE ; + } + pExcExec->SetGeomDB( pGseCtx->m_pGeomDB) ; + pCmdParser->AddExecutor( Release( pExcExec)) ; + + // eventuale creazione oggetto per esecuzione funzioni di Scene + if ( pGseCtx->m_pScene != nullptr) { + PtrOwner pSceExec( CreateSceExecutor()) ; + if ( IsNull( pSceExec)) { + LOG_ERROR( GetLogger(), "Error in CreateSceExecutor") + return FALSE ; + } + pSceExec->SetScene( pGseCtx->m_pScene) ; + pCmdParser->AddExecutor( Release( pSceExec)) ; + } + + // completo inizializzazioni + pCmdParser->Init() ; + pGseCtx->m_pTscExec = Release( pCmdParser) ; + + return TRUE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtTscFileExec( int nGseCtx, const wchar_t* wsFilePath) +{ + // verifico TscExecutor + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pTscExec == nullptr) { + LOG_ERROR( GetLogger(), "TscExecutor invalid (EgtFileExec)") + return FALSE ; + } + // converto nome file + string sFilePath = LPSTR( WtoA( wsFilePath)) ; + // emetto info + string sInfo = "Exec File = " + sFilePath ; + LOG_INFO( GetLogger(), sInfo.c_str()) + + // imposto il direttorio dello script + string sFileDir, sFileName ; + SplitLast( sFilePath, "\\", sFileDir, sFileName) ; + pGseCtx->m_pTscExec->SetDirReplace( "", sFileDir) ; + + // esecuzione script + if ( pGseCtx->m_pTscExec->Run( sFilePath)) + return TRUE ; + else + return FALSE ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtTscLineExec( int nGseCtx, const wchar_t* wsLine) +{ + // verifico TscExecutor + GseContext* pGseCtx = GetGseContext( nGseCtx) ; + if ( pGseCtx == nullptr || pGseCtx->m_pTscExec == nullptr) { + LOG_ERROR( GetLogger(), "TscExecutor invalid (EgtLineExec)") + return FALSE ; + } + + // eseguo il comando + if ( pGseCtx->m_pTscExec->ExecLine( LPSTR( WtoA( wsLine)))) + return TRUE ; + else + return FALSE ; +} diff --git a/EgtInterface.rc b/EgtInterface.rc index 02f1ae5..ccb786e 100644 Binary files a/EgtInterface.rc and b/EgtInterface.rc differ diff --git a/EgtInterface.vcxproj b/EgtInterface.vcxproj index 6bacb77..d66d686 100644 --- a/EgtInterface.vcxproj +++ b/EgtInterface.vcxproj @@ -181,14 +181,21 @@ copy $(TargetPath) \EgtProg\Dll64 + + + + - + + + + - + Create Create diff --git a/EgtInterface.vcxproj.filters b/EgtInterface.vcxproj.filters index 5f06da0..9949630 100644 --- a/EgtInterface.vcxproj.filters +++ b/EgtInterface.vcxproj.filters @@ -18,10 +18,19 @@ File di intestazione - + File di intestazione - + + File di intestazione + + + File di intestazione + + + File di intestazione + + File di intestazione @@ -35,7 +44,19 @@ File di origine - + + File di origine + + + File di origine + + + File di origine + + + File di origine + + File di origine diff --git a/GseContext.cpp b/GseContext.cpp new file mode 100644 index 0000000..87473d6 --- /dev/null +++ b/GseContext.cpp @@ -0,0 +1,65 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : GseContext.cpp Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Gestione contesti GSE ( Geometria, Scena, Esecuzione). +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "stdafx.h" +#include "GseContext.h" + +//---------------------------------------------------------------------------- +static const int MAX_CTX = 10 ; +static bool s_GseOn[MAX_CTX] = { false, false, false, false, false, false, false, false, false, false} ; +static GseContext s_GseCtx[MAX_CTX] ; + +//---------------------------------------------------------------------------- +int +CreateGseContext( void) +{ + for ( int i = 0 ; i < MAX_CTX ; ++ i) { + if ( ! s_GseOn[i]) { + s_GseCtx[i].Clear() ; + s_GseOn[i] = true ; + return ( i + 1) ; + } + } + return 0 ; +} + +//---------------------------------------------------------------------------- +bool +DeleteGseContext( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX) + return false ; + s_GseOn[nInd-1] = false ; + s_GseCtx[nInd-1].Clear() ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ClearAllGseContexts( void) +{ + for ( int i = 0 ; i < MAX_CTX ; ++ i) { + s_GseOn[i] = false ; + s_GseCtx[i].Clear() ; + } + return true ; +} + +//---------------------------------------------------------------------------- +GseContext* +GetGseContext( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX || ! s_GseOn[nInd-1]) + return nullptr ; + return &(s_GseCtx[nInd-1]) ; +} diff --git a/GseContext.h b/GseContext.h new file mode 100644 index 0000000..73cd661 --- /dev/null +++ b/GseContext.h @@ -0,0 +1,59 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : GseContext.h Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Dichiarazioni per contesti GSE ( Geometria, Scena, Esecuzione). +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EGrScene.h" +#include "/EgtDev/Include/EGnCmdParser.h" +#include + +//---------------------------------------------------------------------------- +class GseContext +{ + public : + IGeomDB* m_pGeomDB ; + Color m_colDef ; + HWND m_hWnd ; + IEGrScene* m_pScene ; + ICmdParser* m_pTscExec ; + + public : + GseContext( void) + : m_pGeomDB( nullptr), m_colDef( GRAY), m_hWnd( nullptr), m_pScene( nullptr), m_pTscExec( nullptr) {} + ~GseContext( void) + { Clear() ; } + void Clear( void) + { + if ( m_pTscExec != nullptr) { + delete m_pTscExec ; + m_pTscExec = nullptr ; + } + if ( m_pScene != nullptr) { + m_pScene->Destroy() ; + delete m_pScene ; + m_pScene = nullptr ; + } + m_hWnd = nullptr ; + if ( m_pGeomDB != nullptr) { + delete m_pGeomDB ; + m_pGeomDB = nullptr ; + } + } +} ; + +//---------------------------------------------------------------------------- +int CreateGseContext( void) ; +bool DeleteGseContext( int nInd) ; +bool ClearAllGseContexts( void) ; +GseContext* GetGseContext( int nInd) ; diff --git a/Interface.cpp b/Interface.cpp index 319e672..846d215 100644 --- a/Interface.cpp +++ b/Interface.cpp @@ -34,20 +34,17 @@ static Color s_colDef = BLACK ; //----------------------------------------------------------------------------- int -__stdcall EgtSetLog( int nDebug, const wchar_t* sLogFile) +__stdcall EgtInitGeomDB( void) { - // creo il logger generale - s_pLogGen = new Logger( ( nDebug > 0 ? LL_DEBUG : LL_INFO), "EgtInterface") ; - if ( s_pLogGen == nullptr) + // inizializzazioni DB geometrico + s_pGeomDB = CreateGeomDB() ; + if ( s_pGeomDB == nullptr) return 0 ; - // assegno il file - s_pLogGen->AddOutputStream( new ofstream( sLogFile), true) ; - // lo passo alle DLL - SetEGnLogger( s_pLogGen) ; - SetENkLogger( s_pLogGen) ; - SetEGkLogger( s_pLogGen) ; - SetEExLogger( s_pLogGen) ; - SetEGrLogger( s_pLogGen) ; + s_pGeomDB->Init() ; + s_pGeomDB->SetDefaultMaterial( s_colDef) ; + + // log avvio DB geometrico + LOG_INFO( s_pLogGen, "GeomDB started") return 1 ; } @@ -63,26 +60,13 @@ __stdcall EgtSetFont( const wchar_t* sNfeFontDir, const wchar_t* sDefaultFont) //----------------------------------------------------------------------------- int -__stdcall EgtInit( HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDepthBits) +__stdcall EgtInitScene( HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDepthBits) { - // inizio programma - LOG_DATETIME( s_pLogGen, " Init") - // versione dell'interfaccia - LOG_INFO( s_pLogGen, GetEInVersion()) - // versione delle librerie - LOG_INFO( s_pLogGen, GetEGnVersion()) - LOG_INFO( s_pLogGen, GetENkVersion()) - LOG_INFO( s_pLogGen, GetEGkVersion()) - LOG_INFO( s_pLogGen, GetEExVersion()) - LOG_INFO( s_pLogGen, GetEGrVersion()) - - // inizializzazioni DB geometrico - s_pGeomDB = CreateGeomDB() ; - if ( s_pGeomDB == nullptr) + // verifico GeomDB + if ( s_pGeomDB == nullptr) { + LOG_ERROR( s_pLogGen, "GeomDB invalid (EgtInitScene)") return 0 ; - s_pGeomDB->Init() ; - s_pGeomDB->SetDefaultMaterial( s_colDef) ; - + } // inizializzazione scena OpenGL s_pScene = CreateEGrScene() ; if ( s_pScene == nullptr) @@ -108,6 +92,13 @@ __stdcall EgtInit( HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDept return 1 ; } +//----------------------------------------------------------------------------- +int +__stdcall EgtInitTscExec( void) +{ + return 0 ; +} + //----------------------------------------------------------------------------- int __stdcall EgtExit( void) @@ -197,7 +188,23 @@ __stdcall EgtOpenFile( const wchar_t* sFilePath) //----------------------------------------------------------------------------- int -__stdcall EgtTestImportExt( const wchar_t* sFilePath) +__stdcall EgtSaveFile( const wchar_t* sFilePath, int nFlag) +{ + // verifico GeomDB + if ( s_pGeomDB == nullptr) { + LOG_ERROR( s_pLogGen, "GeomDB invalid (EgtSaveFile)") + return 0 ; + } + // salvo il file + if ( s_pGeomDB->Save( LPSTR( WtoA( sFilePath)), nFlag)) + return 1 ; + else + return 0 ; +} + +//----------------------------------------------------------------------------- +int +__stdcall EgtGetFileType( const wchar_t* sFilePath) { // divido in nome e direttorio string sFileDir, sFileName ; @@ -208,10 +215,14 @@ __stdcall EgtTestImportExt( const wchar_t* sFilePath) SplitLast( sFileName, ".", sFileTitle, sFileExt) ; ToUpper( sFileExt) ; - if ( sFileExt == "DXF") + if ( sFileExt == "NGE") return 1 ; - else if ( sFileExt == "STL") + 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" ; @@ -271,6 +282,52 @@ __stdcall EgtImportStl( const wchar_t* sFilePath) return 0 ; } +//----------------------------------------------------------------------------- +int +__stdcall EgtExportDxf( int nId, const wchar_t* sFilePath) +{ + // verifico GeomDB + if ( s_pGeomDB == nullptr) { + LOG_ERROR( s_pLogGen, "GeomDB invalid (ImportFile)") + return 0 ; + } + // esporto il file DXF + // preparo l'esportatore + PtrOwner pExpDxf( CreateExportDxf()) ; + if ( IsNull( pExpDxf)) { + LOG_ERROR( s_pLogGen, "Error : CreateExportDxf") + return 0 ; + } + // eseguo l'esportazione + if ( pExpDxf->Export( s_pGeomDB, nId, LPSTR( WtoA( sFilePath)))) + return 1 ; + else + return 0 ; +} + +//----------------------------------------------------------------------------- +int +__stdcall EgtExportStl( int nId, const wchar_t* sFilePath) +{ + // verifico GeomDB + if ( s_pGeomDB == nullptr) { + LOG_ERROR( s_pLogGen, "GeomDB invalid (ImportFile)") + return 0 ; + } + // esporto il file STL + // preparo l'esportatore + PtrOwner pExpStl( CreateExportStl()) ; + if ( IsNull( pExpStl)) { + LOG_ERROR( s_pLogGen, "Error : CreateExportStl") + return 0 ; + } + // eseguo l'esportazione + if ( pExpStl->Export( s_pGeomDB, nId, LPSTR( WtoA( sFilePath)))) + return 1 ; + else + return 0 ; +} + //----------------------------------------------------------------------------- int __stdcall EgtDraw( void) @@ -500,4 +557,4 @@ __stdcall EgtUnProject( int nWinX, int nWinY, double ptP[3]) ptP[1] = ptWorld.y ; ptP[2] = ptWorld.z ; return 1 ; -} \ No newline at end of file +}