From 6e821f3c2b6ef1e29bd597c90a70c2b47472775d Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 13 Oct 2015 14:45:30 +0300 Subject: [PATCH] test OCCT viewer for the snapshots in tests --- src/HYDRO_tests/CMakeLists.txt | 8 +++- src/HYDRO_tests/TestViewer.cxx | 64 +++++++++++++++++++++++++ src/HYDRO_tests/TestViewer.h | 23 +++++++++ src/HYDRO_tests/test_HYDROData_Main.cxx | 9 ++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/HYDRO_tests/TestViewer.cxx create mode 100644 src/HYDRO_tests/TestViewer.h diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 48e7df71..657f9a17 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -12,6 +12,8 @@ set(PROJECT_HEADERS test_HYDROData_Profile.h test_HYDROData_StricklerTable.h test_HYDROGUI_ListModel.h + + TestViewer.h ) set(PROJECT_SOURCES @@ -28,6 +30,8 @@ set(PROJECT_SOURCES test_HYDROGUI_ListModel.cxx ${EXTERNAL_FILES} + + TestViewer.cxx ) add_definitions( @@ -44,7 +48,7 @@ SET( QT_INCLUDES $ENV{QT_ROOT_DIR}/include $ENV{QT_ROOT_DIR}/include/QtCore $ENV SET( GUI_INCLUDES $ENV{GUI_ROOT_DIR}/include/salome ) link_directories( $ENV{CAS_ROOT_DIR}/win32/libd ) #TODO: more correct for release, linux etc -SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO ) +SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO TKV3d ) link_directories( $ENV{QT_ROOT_DIR}/lib ) SET( QT_LIBRARIES QtCored4 QtGuid4 ) @@ -53,7 +57,7 @@ link_directories( $ENV{CPPUNIT_ROOT_DIR}/lib ) SET( CPPUNIT_LIBRARIES cppunitd ) link_directories( $ENV{GUI_ROOT_DIR}/lib/salome ) -SET( GUI_LIBRARIES ImageComposer Qtx SUIT LightApp CAM ) +SET( GUI_LIBRARIES ImageComposer Qtx SUIT LightApp CAM OCCViewer ) include_directories( ${BOOST_INCLUDES} diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx new file mode 100644 index 00000000..4fc29d34 --- /dev/null +++ b/src/HYDRO_tests/TestViewer.cxx @@ -0,0 +1,64 @@ + +#include +#include +#include +#include +#include +#include +#include + +OCCViewer_ViewManager* TestViewer::myViewManager = 0; +OCCViewer_ViewWindow* TestViewer::myViewWindow = 0; + +OCCViewer_ViewManager* TestViewer::viewManager() +{ + if( myViewManager ) + return myViewManager; + + myViewManager = new OCCViewer_ViewManager( 0, 0 ); + OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( true ); + + aViewer->setTrihedronSize( 100, true ); + aViewer->setInteractionStyle( 0 ); + aViewer->setZoomingStyle( 1 ); + + myViewManager->setViewModel( aViewer ); + myViewWindow = dynamic_cast( myViewManager->createViewWindow() ); + + return myViewManager; +} + +OCCViewer_Viewer* TestViewer::viewer() +{ + return dynamic_cast( viewManager()->getViewModel() ); +} + +OCCViewer_ViewWindow* TestViewer::viewWindow() +{ + viewManager(); //to create the view if it was not created earlier + return myViewWindow; +} + +Handle(AIS_InteractiveContext) context() +{ + return TestViewer::viewer()->getAISContext(); +} + +void TestViewer::show( const TopoDS_Shape& theShape, bool isFitAll ) +{ + context()->EraseAll(); + Handle(AIS_Shape) aShape = new AIS_Shape( theShape ); + context()->Display( aShape, AIS_Shaded, 0, Standard_False ); + + viewWindow()->onTopView(); + viewWindow()->onFitAll(); +} + +void TestViewer::dump( const TopoDS_Shape& theShape, const QString& theName ) +{ + show( theShape ); + QImage anImage = viewWindow()->dumpView(); + + QString aPath = QDir::tempPath() + "/" + theName + ".png"; + anImage.save( aPath ); +} diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h new file mode 100644 index 00000000..f184b5da --- /dev/null +++ b/src/HYDRO_tests/TestViewer.h @@ -0,0 +1,23 @@ + +#pragma once + +class OCCViewer_ViewManager; +class OCCViewer_Viewer; +class OCCViewer_ViewWindow; +class TopoDS_Shape; +class QString; + +class TestViewer +{ +public: + static OCCViewer_ViewManager* viewManager(); + static OCCViewer_Viewer* viewer(); + static OCCViewer_ViewWindow* viewWindow(); + + static void show( const TopoDS_Shape& theShape, bool isFitAll = true ); + static void dump( const TopoDS_Shape& theShape, const QString& theName ); + +private: + static OCCViewer_ViewManager* myViewManager; + static OCCViewer_ViewWindow* myViewWindow; +}; diff --git a/src/HYDRO_tests/test_HYDROData_Main.cxx b/src/HYDRO_tests/test_HYDROData_Main.cxx index b9590889..7873bc29 100644 --- a/src/HYDRO_tests/test_HYDROData_Main.cxx +++ b/src/HYDRO_tests/test_HYDROData_Main.cxx @@ -23,6 +23,9 @@ #include #include #include +#include +#include +#include #include #include @@ -41,6 +44,11 @@ std::ostream& operator<<( std::ostream& theStream, const QColor& theColor ) int main( int argc, char* argv[] ) { QApplication anApp( argc, argv ); + SUIT_Session aSession; + + OCCViewer_ViewWindow* aWindow = TestViewer::viewWindow(); + aWindow->setGeometry( 200, 200, 800, 600 ); + aWindow->show(); std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; @@ -79,5 +87,6 @@ int main( int argc, char* argv[] ) return 0; } + //anApp.exec(); return result.wasSuccessful() ? 0 : 1; } -- 2.39.2