//---------------------------------------------------------------------------- // EgalTech 2014-2015 //---------------------------------------------------------------------------- // File : EXE_Scene.cpp Data : 05.05.15 Versione : 1.6e1 // Contenuto : Funzioni Scene per EXE. // // // // Modifiche : 01.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" #include "DllGraphics.h" #include "DllMain.h" #include "resource.h" #include "/EgtDev/Include/EGkSurfBezier.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EgtStringConverter.h" #include "/EgtDev/Include/EgtPointerOwner.h" #include using namespace std ; //----------------------------------------------------------------------------- bool ExeInitScene( HWND hWnd, int nDriver, bool b2Buff, int nColorBits, int nDepthBits) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) // inizializzazione scena OpenGL PtrOwner pScene( MyCreateEGrScene()) ; VERIFY_NULL( Get( pScene), "Error in CreateEGrScene", false) HDC hdc = GetDC( hWnd) ; if ( ! pScene->CreateContext( hdc, nDriver, b2Buff, 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 ExeGetSceneInfo( string& sInfo) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // verifico parametro di ritorno if ( &sInfo == nullptr) return false ; // recupero le informazioni sulla scena sInfo += pScene->GetOpenGLInfo() ; sInfo += "\r\n" ; sInfo += pScene->GetGLSLInfo() ; sInfo += "\r\n" ; sInfo += pScene->GetPixelFormatInfo() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetBackground( Color TopCol, Color BottomCol, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto lo sfondo pScene->SetBackground( TopCol, BottomCol) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetBackground( Color& TopCol, Color& BottomCol) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero lo sfondo pScene->GetBackground( TopCol, BottomCol) ; return true ; } //----------------------------------------------------------------------------- bool ExeSetLineAttribs( int nWidth) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto lo spessore delle linee return pScene->SetLineWidth( nWidth) ; } //----------------------------------------------------------------------------- bool ExeSetMarkAttribs( Color MarkCol, Color Mark2Col) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il colore del Mark return ( pScene->SetMark( MarkCol) && pScene->SetMark2( Mark2Col)) ; } //----------------------------------------------------------------------------- bool ExeSetSelSurfAttribs( Color SelSurfCol) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il colore del Mark return pScene->SetSelSurf( SelSurfCol) ; } //----------------------------------------------------------------------------- bool ExeSetGeoLineAttribs( Color GlCol) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il colore della linea geometrica gestita direttamente dalla scena return pScene->SetGeoLineAttribs( GlCol) ; } //----------------------------------------------------------------------------- bool ExeSetGeoTriaAttribs( Color GtCol) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il colore del triangolo immediato return pScene->SetGeoTriaAttribs( GtCol) ; } //----------------------------------------------------------------------------- bool ExeSetWinRectAttribs( bool bOutline, Color WrCol) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il colore della linea geometrica gestita direttamente dalla scena return pScene->SetWinRectAttribs( bOutline, WrCol) ; } //----------------------------------------------------------------------------- bool ExeSetGlobFrameShow( bool bShow) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto stato visualizzazione griglia return pScene->SetGlobFrameShow( bShow) ; } //----------------------------------------------------------------------------- bool ExeSetGridShow( bool bShowGrid, bool bShowFrame) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto stato visualizzazione griglia return pScene->SetGridShow( bShowGrid, bShowFrame) ; } //----------------------------------------------------------------------------- bool ExeSetGridGeo( double dSnapStep, int nMinLineSstep, int nMajLineSstep, int nExtSstep) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto i parametri geometrici di griglia return pScene->SetGridGeo( dSnapStep, nMinLineSstep, nMajLineSstep, nExtSstep) ; } //----------------------------------------------------------------------------- bool ExeSetGridGeoAdv( double dSnapStep, int nMinLineSstep, int nMajLineSstep, double dXmin, double dXmax, double dYmin, double dYmax) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto i parametri geometrici di griglia return pScene->SetGridGeoAdv( dSnapStep, nMinLineSstep, nMajLineSstep, dXmin, dXmax, dYmin, dYmax) ; } //----------------------------------------------------------------------------- bool ExeSetGridColor( Color colMin, Color colMaj) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto i colori di griglia return pScene->SetGridColor( colMin, colMaj) ; } //----------------------------------------------------------------------------- bool ExeSetCameraType( bool bOrthoOrPersp, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) pScene->SetCameraType( bOrthoOrPersp) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetZoomType( int nMode, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) if ( ! pScene->SetZoomType( nMode)) return false ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeResize( int nW, int nH) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo resize pScene->Resize( nW, nH) ; return true ; } //----------------------------------------------------------------------------- bool ExeDraw( void) { // se interfaccia disabilitata, esco subito if ( ! ExeGetEnableUI()) return true ; 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 ExeRedraw( void) { // se interfaccia disabilitata, esco subito if ( ! ExeGetEnableUI()) return true ; IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // forzo ridisegno pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSelect( int nWinX, int nWinY, int nSelW, int nSelH, int* pnSel) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // verifico parametro di ritorno if ( pnSel == nullptr) return false ; // eseguo la selezione return pScene->Select( Point3d( nWinX, nWinY), nSelW, nSelH, *pnSel) ; } //----------------------------------------------------------------------------- bool ExeSetObjFilterForSelWin( bool bZerodim, bool bCurve, bool bSurf, bool bVolume, bool bExtra) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il filtro return pScene->SetObjFilterForSelect( bZerodim, bCurve, bSurf, bVolume, bExtra) ; } //----------------------------------------------------------------------------- bool ExeUnselectableRemove( int nId) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // tolgo dai non selezionabili return pScene->UnselectableRemove( nId) ; } //----------------------------------------------------------------------------- bool ExeUnselectableAdd( int nId) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // aggiungo ai non selezionabili return pScene->UnselectableAdd( nId) ; } //----------------------------------------------------------------------------- bool ExeUnselectableClearAll( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // cancello tutti i non selezionabili return pScene->UnselectableClearAll() ; } //----------------------------------------------------------------------------- int ExeGetFirstObjInSelWin( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, GDB_ID_NULL) // restituisco il primo oggetto selezionato return pScene->GetFirstSelectedObj() ; } //----------------------------------------------------------------------------- int ExeGetNextObjInSelWin( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, GDB_ID_NULL) // restituisco il successivo oggetto selezionato return pScene->GetNextSelectedObj() ; } //----------------------------------------------------------------------------- bool ExeGetPointFromSelect( int nSelId, int nWinX, int nWinY, Point3d& ptSel, int* pnAux) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // trovo il punto usato in selezione if ( &ptSel == nullptr || pnAux == nullptr) return false ; return pScene->GetPointFromSelect( nSelId, Point3d( nWinX, nWinY), ptSel, *pnAux) ; } //----------------------------------------------------------------------------- bool ExeGetGraphicSnapPoint( int nSnap, int nWinX, int nWinY, int nSelW, int nSelH, Point3d& ptP) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // trovo il punto snap da selezione if ( &ptP == nullptr) return false ; return pScene->GetGraphicSnapPoint( nSnap, Point3d( nWinX, nWinY), nSelW, nSelH, ptP) ; } //----------------------------------------------------------------------------- bool ExeGetGridSnapPointZ( bool bSketch, int nWinX, int nWinY, const Point3d& ptGrid, Point3d& ptP) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // trovo il punto snap da griglia con elevazione in Z if ( &ptP == nullptr) return false ; return pScene->GetGridSnapPointZ( bSketch, Point3d( nWinX, nWinY), ptGrid, ptP) ; } //----------------------------------------------------------------------------- int ExeGetLastSnapId( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, GDB_ID_NULL) // restituisco Id di ultima entità generatrice di punto snap return pScene->GetLastSnapId() ; } //----------------------------------------------------------------------------- bool ExeGetLastSnapDir( Vector3d& vtV) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // restituisco, se definita, direzione associata ad ultimo punto di snap if ( &vtV == nullptr) return false ; return pScene->GetLastSnapDir( vtV) ; } //----------------------------------------------------------------------------- bool ExeGetPlaneSnapPoint( int nWinX, int nWinY, const Plane3d& Plane, Point3d& ptP) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // trovo il punto snap da piano indicato if ( &ptP == nullptr) return false ; return pScene->GetPlaneSnapPoint( Point3d( nWinX, nWinY), Plane, ptP) ; } //----------------------------------------------------------------------------- bool ExeSetShowMode( int nShowMode, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto il modo di visualizzazione if ( nShowMode >= SM_WIREFRAME && nShowMode <= SM_SHADING) { pScene->SetShowMode( nShowMode) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } else return false ; } //----------------------------------------------------------------------------- int ExeGetShowMode( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, SM_WIREFRAME) // recupero il modo di visualizzazione return pScene->GetShowMode() ; } //----------------------------------------------------------------------------- bool ExeSetShowCurveDirection( bool bShow, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto stato pScene->SetShowCurveDirection( bShow) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetShowCurveDirection( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero lo stato return pScene->GetShowCurveDirection() ; } //----------------------------------------------------------------------------- static bool MyResetGroupObjGraphics( IGeomDB* pGDB, int nGroupId) { if ( pGDB == nullptr) return false ; int nEntId = pGDB->GetFirstInGroup( nGroupId) ; while ( nEntId != GDB_ID_NULL) { if ( pGDB->GetGdbType( nEntId) == GDB_TY_GROUP) { MyResetGroupObjGraphics( pGDB, nEntId) ; } else { IGeoObj* pGeoObj = pGDB->GetGeoObj( nEntId) ; if ( pGeoObj != nullptr) pGeoObj->SetObjGraphics( nullptr) ; } nEntId = pGDB->GetNext( nEntId) ; } return true ; } //----------------------------------------------------------------------------- bool ExeSetShowTriaAdv( bool bAdvanced, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // se cambiato, imposto stato if ( pScene->GetShowTriaAdvanced() != bAdvanced) { // imposto il nuovo stato pScene->SetShowTriaAdvanced( bAdvanced) ; // forzo ricalcolo della grafica di tutti gli oggetti if ( ! MyResetGroupObjGraphics( pScene->GetGeomDB(), GDB_ID_ROOT)) return false ; } if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetShowTriaAdv( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero lo stato return pScene->GetShowTriaAdvanced() ; } //------------------------------------------------------------------------------- bool ExeSetShowSurfBezierTol( double dLinTol, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // se diverso, imposto il nuovo valore if ( abs( GetSurfBezierAuxSurfTol() - dLinTol) > 10 * EPS_SMALL) { // imposto il nuovo valore di approssimazione SetSurfBezierAuxSurfTol( dLinTol) ; // forzo ricalcolo della grafica di tutti gli oggetti if ( ! MyResetGroupObjGraphics( pScene->GetGeomDB(), GDB_ID_ROOT)) return false ; } if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- double ExeGetShowSurfBezierTol( void) { // recupero il valore return GetSurfBezierAuxSurfTol() ; } //----------------------------------------------------------------------------- bool ExeSetShowZmap( int nMode, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // se cambiato, imposto il nuovo stato if ( pScene->GetShowZmap() != nMode) { // imposto il nuovo stato pScene->SetShowZmap( nMode) ; // forzo ricalcolo della grafica di tutti gli oggetti if ( ! MyResetGroupObjGraphics( pScene->GetGeomDB(), GDB_ID_ROOT)) return false ; } if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- int ExeGetShowZmap( void) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, -1) // recupero lo stato return pScene->GetShowZmap() ; } //----------------------------------------------------------------------------- bool ExeZoomRadius( double dRadius, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo lo zoom pScene->ZoomRadius( dRadius) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeZoom( int nZoom, bool bRedraw) { // se interfaccia disabilitata, esco subito if ( ! ExeGetEnableUI()) return true ; IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) const double COEFF_IN = 0.5 ; const double COEFF_OUT = 1 / COEFF_IN ; switch ( nZoom) { case ZM_ALL : pScene->ZoomAll() ; if ( bRedraw) pScene->RedrawWindow() ; return true ; break ; case ZM_IN : pScene->ZoomChange( COEFF_IN) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; break ; case ZM_OUT : pScene->ZoomChange( COEFF_OUT) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; break ; } return false ; } //----------------------------------------------------------------------------- bool ExeZoomObject( int nId, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo zoom bool bOk = pScene->ZoomObject( nId) ; if ( bRedraw) pScene->RedrawWindow() ; return bOk ; } //----------------------------------------------------------------------------- bool ExeZoomOnPoint( int nWinX, int nWinY, double dCoeff, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo zoom pScene->ZoomOnPoint( Point3d( nWinX, nWinY), dCoeff) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetGeoLine( const Point3d& ptP1, const Point3d& ptP2, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // disegno linea per distanza o similari pScene->SetGeoLine( ptP1, ptP2) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeResetGeoLine( bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // cancello linea per distanza o similari pScene->ResetGeoLine() ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetGeoTria( const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // disegno triangolo immediato pScene->SetGeoTria( ptP1, ptP2, ptP3) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeResetGeoTria( bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // cancello triangolo immediato pScene->ResetGeoTria() ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetWinRect( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // disegno finestra per zoom pScene->SetWinRect( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeResetWinRect( bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // cancello finestra per zoom pScene->ResetWinRect() ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeZoomWin( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo zoom su finestra pScene->ZoomWin( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetViewOrizzOffsStep( int nDirOffsStep) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) return pScene->SetCameraDirOrizzOffset( nDirOffsStep) ; } //----------------------------------------------------------------------------- bool ExeSetView( int nDir, bool bRedraw) { // se interfaccia disabilitata, esco subito if ( ! ExeGetEnableUI()) return true ; IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto vista if ( nDir >= CT_TOP && nDir <= CT_CPLANE) { pScene->SetCamera( nDir) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } else return false ; } //----------------------------------------------------------------------------- bool ExeSetGenericView( double dAngVertDeg, double dAngHorizDeg, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto vista pScene->SetCamera( dAngVertDeg, dAngHorizDeg, 0) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetViewCenter( const Point3d& ptP, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // imposto vista pScene->SetCenter( ptP) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExePanView( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo panoramica pScene->PanCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeRotateView( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo rotazione camera pScene->RotateCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pScene->RedrawWindow() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetViewOrizzOffsStep( int* pnDirOffsStep) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero offset direzione di vista if ( pnDirOffsStep == nullptr) return false ; *pnDirOffsStep = pScene->GetCameraDirOrizzOffset() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetView( int* pnDir) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero direzione di vista if ( pnDir == nullptr) return false ; *pnDir = pScene->GetCameraDir() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetGenericView( double* pdAngVertDeg, double* pdAngHorizDeg) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero direzione di vista if ( pdAngVertDeg == nullptr || pdAngHorizDeg == nullptr) return false ; pScene->GetCamera( pdAngVertDeg, pdAngHorizDeg) ; return true ; } //----------------------------------------------------------------------------- bool ExeGetViewUp( Vector3d& vtUp) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero direzione in alto di vista if ( &vtUp == nullptr) return false ; vtUp = pScene->GetCameraUp() ; return true ; } //----------------------------------------------------------------------------- bool ExeProjectPoint( const Point3d& ptP, Point3d& ptWin) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo la proiezione if ( &ptWin == nullptr) return false ; Point3d ptView ; return pScene->Project( ptP, ptView) ; } //----------------------------------------------------------------------------- bool ExeUnProjectPoint( int nWinX, int nWinY, Point3d& ptP) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // eseguo l'inverso della proiezione (considero Z punto su centro) if ( &ptP == nullptr) return false ; Point3d ptView( nWinX, nWinY, pScene->GetProjectedCenter().z) ; return pScene->UnProject( ptView, ptP) ; } //----------------------------------------------------------------------------- bool ExeSetTextureMaxLinPixels( int nMaxLinPix) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // lancio il caricamento della texture return pScene->SetTextureMaxLinPixels( nMaxLinPix) ; } //----------------------------------------------------------------------------- bool ExeLoadTexture( const string& sName, const string& sFile, double dMMxPix, double dDimX, double dDimY, int nRepeat) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // lancio il caricamento della texture return pScene->LoadTexture( sName, sFile, dMMxPix, dDimX, dDimY, nRepeat) ; } //----------------------------------------------------------------------------- bool ExeUnloadTexture( const string& sName) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // lancio lo scaricamento della texture return pScene->UnloadTexture( sName) ; } //----------------------------------------------------------------------------- bool ExeExistsTexture( const string& sName) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // verifico esistenza della texture return pScene->ExistsTexture( sName) ; } //----------------------------------------------------------------------------- bool ExeGetTexturePixels( const string& sName, int& nWidth, int& nHeight) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero la dimensione in pixels della texture return pScene->GetTexturePixels( sName, nWidth, nHeight) ; } //----------------------------------------------------------------------------- bool ExeGetTextureImagePixels( const string& sName, int& nWidth, int& nHeight) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero la dimensione in pixels della immagine da cui è derivata la texture return pScene->GetTextureImagePixels( sName, nWidth, nHeight) ; } //----------------------------------------------------------------------------- bool ExeGetTextureDimensions( const string& sName, double& dDimX, double& dDimY) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // recupero la dimensione fisica della texture return pScene->GetTextureDimensions( sName, dDimX, dDimY) ; } //----------------------------------------------------------------------------- bool ExeChangeTextureDimensions( const string& sName, double dDimX, double dDimY) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // modifico le dimensioni della texture return pScene->ChangeTextureDimensions( sName, dDimX, dDimY) ; } //----------------------------------------------------------------------------- bool ExeGetImage( int nShowMode, Color colBackTop, Color colBackBottom, int nWidth, int nHeight, const string& sFile) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, false) // creo e salvo una immagine della scena return pScene->GetImage( nShowMode, colBackTop, colBackBottom, nWidth, nHeight, sFile) ; } //------------------------------------------------------------------------------- static int s_nContext = 0 ; static int s_nDriver = 3 ; static bool s_b2Buff = true ; static int s_nColorBits = 32 ; static int s_nDepthBits = 24 ; static int s_nShowMode = SM_SHADING ; static Color s_colBackTop = WHITE ; static Color s_colBackBottom = WHITE ; static int s_nCameraDir = CT_TOP ; static int s_nWidth = 1024 ; static int s_nHeight = 1024 ; static string s_sImageFile ; //------------------------------------------------------------------------------- BOOL CALLBACK SceneBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch ( message) { case WM_INITDIALOG : { // imposto dimensione box e picture const int WIN_MAX_DIM = ( s_nDriver == 1 ? 512 : 1024) ; int nWinW = ( s_nWidth >= s_nHeight ? WIN_MAX_DIM : ( WIN_MAX_DIM * s_nWidth) / s_nHeight) ; int nWinH = ( s_nHeight >= s_nWidth ? WIN_MAX_DIM : ( WIN_MAX_DIM * s_nHeight) / s_nWidth) ; HWND hPic = GetDlgItem( hwndDlg, IDC_PICTURE1) ; SetWindowPos( hwndDlg, HWND_TOP, 0, 0, nWinW, nWinH, SWP_NOMOVE | SWP_NOREPOSITION) ; SetWindowPos( hPic, HWND_TOP, 0, 0, nWinW, nWinH, SWP_NOMOVE | SWP_NOREPOSITION) ; // imposto scena int nContext = GetIndCurrGseContext() ; GseContext* pGseCtx = GetGseContext( nContext) ; if ( pGseCtx != nullptr && pGseCtx->m_pScene == nullptr) { ExeInitScene( hPic, s_nDriver, s_b2Buff, s_nColorBits, s_nDepthBits) ; if ( pGseCtx->m_pGeomDB != nullptr && pGseCtx->m_pScene != nullptr) { s_nContext = nContext ; pGseCtx->m_pScene->SetCamera( s_nCameraDir) ; pGseCtx->m_pScene->ZoomAll() ; if ( ! pGseCtx->m_pScene->GetImage( s_nShowMode, s_colBackTop, s_colBackBottom, s_nWidth, s_nHeight, s_sImageFile)) s_nContext = -s_nContext ; MyResetGroupObjGraphics( pGseCtx->m_pGeomDB, GDB_ID_ROOT) ; EndDialog( hwndDlg, wParam) ; } else { s_nContext = 0 ; EndDialog( hwndDlg, wParam) ; } } else s_nContext = 0 ; } break ; } return FALSE ; } //------------------------------------------------------------------------------- bool ExeGetImageEx( int nDriver, bool b2Buff, int nColorBits, int nDepthBits, int nShowMode, Color colBackTop, Color colBackBottom, int nCameraDir, int nWidth, int nHeight, const string& sFile) { // Se il contesto corrente possiede già una scena if ( GetCurrScene() != nullptr) { return ExeGetImage( nShowMode, colBackTop, colBackBottom, nWidth, nHeight, sFile) ; } // altrimenti ne creo una temporanea else { // salvo i parametri s_nDriver = nDriver ; s_b2Buff = b2Buff ; s_nColorBits = nColorBits ; s_nDepthBits = nDepthBits ; s_nShowMode = nShowMode ; s_colBackTop = colBackTop ; s_colBackBottom = colBackBottom ; s_nCameraDir = nCameraDir ; s_nWidth = nWidth ; s_nHeight = nHeight ; s_sImageFile = sFile ; // lancio dialogo HWND hTopWnd = ExeGetMainWindowHandle() ; DialogBox( GetModuleIstance(), MAKEINTRESOURCE( IDD_LUASCENE), hTopWnd, (DLGPROC)SceneBoxProc) ; bool bOk = ( s_nContext > 0) ; // elimino la scena dal contesto GseContext* pGseCtx = GetGseContext( abs( s_nContext)) ; if ( pGseCtx != nullptr) { delete pGseCtx->m_pScene ; pGseCtx->m_pScene = nullptr ; } s_nContext = 0 ; return bOk ; } }