]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
test OCCT viewer for the snapshots in tests
authorasl <asl@opencascade.com>
Tue, 13 Oct 2015 11:45:30 +0000 (14:45 +0300)
committerasl <asl@opencascade.com>
Tue, 13 Oct 2015 11:45:30 +0000 (14:45 +0300)
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/TestViewer.cxx [new file with mode: 0644]
src/HYDRO_tests/TestViewer.h [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_Main.cxx

index 48e7df71f76612559011d0b741976fe96d0167e5..657f9a173b2fc15740640b88cdd26aff3a01e985 100644 (file)
@@ -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 (file)
index 0000000..4fc29d3
--- /dev/null
@@ -0,0 +1,64 @@
+
+#include <TestViewer.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewWindow.h>
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_Shape.hxx>
+#include <QDir>
+
+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<OCCViewer_ViewWindow*>( myViewManager->createViewWindow() );
+
+  return myViewManager;
+}
+
+OCCViewer_Viewer* TestViewer::viewer()
+{
+  return dynamic_cast<OCCViewer_Viewer*>( 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 (file)
index 0000000..f184b5d
--- /dev/null
@@ -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;
+};
index b9590889429c7191810386ceceb066718a128617..7873bc293c88c40f3fcfa1beff6236dde7d1ddc2 100644 (file)
@@ -23,6 +23,9 @@
 #include <cppunit/TestRunner.h>
 #include <cppunit/TextTestProgressListener.h>
 #include <stdexcept>
+#include <TestViewer.h>
+#include <OCCViewer_ViewWindow.h>
+#include <SUIT_Session.h>
 #include <QApplication>
 #include <QColor>
 
@@ -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;
 }