Files
EgtInterface/API_Scene.cpp
T
Dario Sassi 517a36a009 EgtInterface 1.5l1 :
- aggiornamento a VS2013
- alle curve si assegna in automatico estrusione come Z di griglia
- aggiunta gestione direttorio per librerie Lua
- aggiunta gestione frame di griglia (CPlane) in GeomDB
- aggiunta gestione visualizzazione riferimento globale
- aggiunto comando Lua EgtOffsetCurve
- aggiunti comandi Lua EgtExecTsc, EgtOutLog, EgtEraseFile, EgtEmptyDirectory, EgtTextFileCompare, EgtBinaryFileCompare, EgtGetVersion
- aggiunti comandi Lua EgtSetGridFrame, EgtGetGridFrame, EgtGetGridVersZ.
2014-12-17 15:19:20 +00:00

631 lines
20 KiB
C++

//----------------------------------------------------------------------------
// 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 "API_Macro.h"
#include "/EgtDev/Include/EInAPI.h"
#include "/EgtDev/Include/EGnStringConverter.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtInitScene( HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDepthBits)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX( pGseCtx, FALSE)
// inizializzazione scena OpenGL
PtrOwner<IEGrScene> pScene( CreateEGrScene()) ;
VERIFY_NULL( Get( pScene), "Error in CreateEGrScene", 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 EgtGetSceneInfo( wchar_t*& wsInfo)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// recupero le informazioni sulla scena
string sInfo ;
sInfo += pGseCtx->m_pScene->GetOpenGLInfo() ;
sInfo += "\r\n" ;
sInfo += pGseCtx->m_pScene->GetGLSLInfo() ;
sInfo += "\r\n" ;
sInfo += pGseCtx->m_pScene->GetPixelFormatInfo() ;
wsInfo = _wcsdup( stringtoW( sInfo)) ;
return (( wsInfo == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetBackground( const int TopCol[4], const int BottomCol[4], BOOL bRedraw)
{
return EgtSetBackground( Color( TopCol), Color( BottomCol), bRedraw) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetBackground( Color TopCol, Color BottomCol, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto lo sfondo
pGseCtx->m_pScene->SetBackground( TopCol, BottomCol) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetMarkAttribs( const int MarkCol[4])
{
return EgtSetMarkAttribs( Color( MarkCol)) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetMarkAttribs( Color MarkCol)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto il colore del Mark
return ( pGseCtx->m_pScene->SetMark( MarkCol) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetSelSurfAttribs( const int SelSurfCol[4])
{
return EgtSetSelSurfAttribs( Color( SelSurfCol)) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetSelSurfAttribs( Color SelSurfCol)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto il colore del Mark
return ( pGseCtx->m_pScene->SetSelSurf( SelSurfCol) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGeoLineAttribs( const int GlCol[4])
{
return EgtSetGeoLineAttribs( Color( GlCol)) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGeoLineAttribs( Color GlCol)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto il colore della linea geometrica gestita direttamente dalla scena
return ( pGseCtx->m_pScene->SetGeoLineAttribs( GlCol) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetWinRectAttribs( BOOL bOutline, const int WrCol[4])
{
return EgtSetWinRectAttribs( bOutline, Color( WrCol)) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetWinRectAttribs( BOOL bOutline, Color WrCol)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto il colore della linea geometrica gestita direttamente dalla scena
return ( pGseCtx->m_pScene->SetWinRectAttribs( ( bOutline != FALSE), WrCol) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGlobFrameShow( BOOL bShow)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto stato visualizzazione griglia
return ( pGseCtx->m_pScene->SetGlobFrameShow( ( bShow != FALSE)) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGridShow( BOOL bShowGrid, BOOL bShowFrame)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto stato visualizzazione griglia
return ( pGseCtx->m_pScene->SetGridShow( ( bShowGrid != FALSE), ( bShowFrame != FALSE)) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGridGeo( double dSnapStep, int nMinLineSstep, int nMajLineSstep, int nExtSstep)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto i parametri geometrici di griglia
return ( pGseCtx->m_pScene->SetGridGeo( dSnapStep, nMinLineSstep, nMajLineSstep, nExtSstep) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGridColor( const int nMinCol[4], const int nMajCol[4])
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto i colori di griglia
Color colMin( nMinCol) ;
Color colMaj( nMajCol) ;
return ( pGseCtx->m_pScene->SetGridColor( colMin, colMaj) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtResize( int nW, int nH)
{
IEGrScene* pScene = GetCurrScene() ;
VERIFY_SCENE( pScene, FALSE)
// eseguo resize
pScene->Resize( nW, nH) ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtDraw( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// eseguo disegno
pGseCtx->m_pScene->Draw() ;
// valido la finestra disegnata
ValidateRgn( pGseCtx->m_hWnd, NULL) ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSelect( int nWinX, int nWinY, int nSelW, int nSelH, int* pnSel)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// eseguo la selezione
return ( pGseCtx->m_pScene->Select( Point3d( nWinX, nWinY), nSelW, nSelH, *pnSel) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
int
__stdcall EgtGetFirstObjInSelWin( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// restituisco il primo oggetto selezionato
return pGseCtx->m_pScene->GetFirstSelectedObj() ;
}
//-----------------------------------------------------------------------------
int
__stdcall EgtGetNextObjInSelWin( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// restituisco il successivo oggetto selezionato
return pGseCtx->m_pScene->GetNextSelectedObj() ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtUnselectableRemove( int nId)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// tolgo dai non selezionabili
return pGseCtx->m_pScene->UnselectableRemove( nId) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtUnselectableAdd( int nId)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// aggiungo ai non selezionabili
return pGseCtx->m_pScene->UnselectableAdd( nId) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtUnselectableClearAll( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// cancello tutti i non selezionabili
return pGseCtx->m_pScene->UnselectableClearAll() ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetPointFromSelect( int nSelId, int nWinX, int nWinY, double ptSel[3])
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// trovo il punto usato in selezione
Point3d ptTmp ;
if ( ! pGseCtx->m_pScene->GetPointFromSelect( nSelId, Point3d( nWinX, nWinY), ptTmp))
return FALSE ;
VEC_FROM_3D( ptSel, ptTmp)
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetGraphicSnapPoint( int nSnap, int nWinX, int nWinY, int nSelW, int nSelH,
double ptP[3])
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// trovo il punto snap da selezione
Point3d ptSnap ;
if ( ! pGseCtx->m_pScene->GetGraphicSnapPoint( nSnap, Point3d( nWinX, nWinY), nSelW, nSelH, ptSnap))
return FALSE ;
VEC_FROM_3D( ptP, ptSnap)
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetGridSnapPointZ( BOOL bSketch, int nWinX, int nWinY, const double ptGrid[3],
double ptP[3])
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// trovo il punto snap da selezione
Point3d ptSnap ;
if ( ! pGseCtx->m_pScene->GetGridSnapPointZ( ( bSketch != FALSE), Point3d( nWinX, nWinY), ptGrid, ptSnap))
return FALSE ;
VEC_FROM_3D( ptP, ptSnap)
return TRUE ;
}
//-----------------------------------------------------------------------------
int
__stdcall EgtGetLastSnapId( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// restituisco Id di ultima entità generatrice di punto snap
return pGseCtx->m_pScene->GetLastSnapId() ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetLastSnapDir( double vtV[3])
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// restituisco, se definita, direzione associata ad ultimo punto di snap
Vector3d vtDir ;
if ( pGseCtx->m_pScene->GetLastSnapDir( vtDir)) {
VEC_FROM_3D( vtV, vtDir)
return TRUE ;
}
else
return FALSE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetShowMode( int nShowMode, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto il modo di visualizzazione
if ( nShowMode >= SM_WIREFRAME && nShowMode <= SM_SHADING) {
pGseCtx->m_pScene->SetShowMode( nShowMode) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
else
return FALSE ;
}
//-----------------------------------------------------------------------------
int
__stdcall EgtGetShowMode( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// recupero il modo di visualizzazione
return pGseCtx->m_pScene->GetShowMode() ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetShowCurveDirection( BOOL bShow, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto stato
pGseCtx->m_pScene->SetShowCurveDirection( bShow != FALSE) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetShowCurveDirection( void)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// recupero lo stato
return pGseCtx->m_pScene->GetShowCurveDirection() ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtZoom( int nZoom, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
const double COEFF_IN = 0.9 ;
const double COEFF_OUT = 1 / COEFF_IN ;
switch ( nZoom) {
case 1 :
pGseCtx->m_pScene->ZoomAll() ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
break ;
case 2 :
pGseCtx->m_pScene->ZoomChange( COEFF_IN) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
break ;
case 3 :
pGseCtx->m_pScene->ZoomChange( COEFF_OUT) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
break ;
}
return FALSE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtZoomOnPoint( int nWinX, int nWinY, double dCoeff, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// eseguo zoom
pGseCtx->m_pScene->ZoomOnPoint( Point3d( nWinX, nWinY), dCoeff) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGeoLine( const double ptP1[3], const double ptP2[3], BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// disegno linea per distanza o similari
pGseCtx->m_pScene->SetGeoLine( ptP1, ptP2) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtResetGeoLine( BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// cancello linea per distanza o similari
pGseCtx->m_pScene->ResetGeoLine() ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetWinRect( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// disegno finestra per zoom
pGseCtx->m_pScene->SetWinRect( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtResetWinRect( BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// cancello finestra per zoom
pGseCtx->m_pScene->ResetWinRect() ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtZoomWin( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// eseguo zoom su finestra
pGseCtx->m_pScene->ZoomWin( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetView( int nView, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto vista
if ( nView >= CT_TOP && nView <= CT_CPLANE) {
pGseCtx->m_pScene->SetCamera( nView) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
else
return FALSE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetGenericView( double dAngVertDeg, double dAngHorizDeg, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto vista
pGseCtx->m_pScene->SetCamera( dAngVertDeg, dAngHorizDeg, 0) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetViewCenter( const double ptP[3], BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// imposto vista
pGseCtx->m_pScene->SetCenter( ptP) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtPanCamera( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// eseguo panoramica
pGseCtx->m_pScene->PanCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtRotateCamera( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw)
{
GseContext* pGseCtx = GetCurrGseContext() ;
VERIFY_CTX_SCENE( pGseCtx, FALSE)
// eseguo rotazione camera
pGseCtx->m_pScene->RotateCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ;
if ( bRedraw)
pGseCtx->m_pScene->RedrawWindow() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetCameraDir( int* pnDir)
{
IEGrScene* pScene = GetCurrScene() ;
VERIFY_SCENE( pScene, FALSE)
// recupero direzione di vista
if ( pnDir == nullptr)
return FALSE ;
*pnDir = pScene->GetCameraDir() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtProjectPoint( const double ptP[3], double ptWin[3])
{
IEGrScene* pScene = GetCurrScene() ;
VERIFY_SCENE( pScene, FALSE)
// eseguo la proiezione
Point3d ptView ;
if ( ! pScene->Project( ptP, ptView))
return FALSE ;
VEC_FROM_3D( ptWin, ptView)
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtUnProjectPoint( int nWinX, int nWinY, double ptP[3])
{
IEGrScene* pScene = GetCurrScene() ;
VERIFY_SCENE( pScene, FALSE)
// eseguo l'inverso della proiezione (considero Z punto su centro)
Point3d ptView( nWinX, nWinY, pScene->GetProjectedCenter().z) ;
Point3d ptWorld ;
if ( ! pScene->UnProject( ptView, ptWorld))
return FALSE ;
VEC_FROM_3D( ptP, ptWorld)
return TRUE ;
}