Salome HOME
0023124: EDF 11219 GEOM: Ray tracing in the OCC viewer
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewPort3d.cxx
index 06029fb30c09cf042bc534d694c289be73e27bb0..5e927fbb3eda784eef72f747ab9e65b2e29dd368 100755 (executable)
@@ -28,6 +28,8 @@
 
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewModel.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
 
 #include <QColor>
 #include <QFileInfo>
@@ -52,7 +54,7 @@
 #if defined WIN32
 #include <WNT_Window.hxx>
 #else
-#include <Xw_Window.hxx>
+//#include <Xw_Window.hxx>
 #endif
 
 static double rx = 0.;
@@ -88,7 +90,9 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V
   }
 #endif
 
-  setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
+  setDefaultParams();
+
+  myCursor = NULL;
 }
 
 /*!
@@ -96,6 +100,12 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V
 */
 OCCViewer_ViewPort3d::~OCCViewer_ViewPort3d()
 {
+  if ( myCursor )
+  {
+    delete myCursor;
+    myCursor = NULL;
+  }
+
   emit vpClosed(this);
   Handle(V3d_View) aView = activeView();
   if (!aView.IsNull())
@@ -514,7 +524,8 @@ void OCCViewer_ViewPort3d::startRotation( int x, int y,
     default:
       break;
     }
-    activeView()->DepthFitAll();
+    // VSR: 10.06.2015: next line commented out - causes ugly blinking on starting rotation with Perspective projection mode
+    //activeView()->DepthFitAll();
   }
 }
 
@@ -605,6 +616,17 @@ void OCCViewer_ViewPort3d::resizeEvent( QResizeEvent* e )
     activeView()->MustBeResized();
 }
 
+/*!
+  Moved the viewport
+*/
+/*
+void OCCViewer_ViewPort3d::repaintViewAfterMove( )
+{
+  if ( !activeView().IsNull() ){
+    activeView()->MustBeResized();
+  }
+}
+*/
 /*!
   Fits all objects in view. [ virtual protected ]
 */
@@ -764,3 +786,45 @@ void OCCViewer_ViewPort3d::showStaticTrihedron( bool on )
   }
   aView->Update();
 }
+
+/*
+ * Create default cursor with a specific shape
+ */
+void OCCViewer_ViewPort3d::setDefaultCursor( Qt::CursorShape theCursorShape )
+{
+  if ( !myCursor )
+    myCursor = new QCursor();
+
+  myCursor->setShape( theCursorShape );
+}
+
+/*
+ * Get default cursor with a specific shape
+ */
+QCursor* OCCViewer_ViewPort3d::getDefaultCursor() const
+{
+  return myCursor;
+}
+
+/*
+ * Set default parameters from preferences
+ */
+void OCCViewer_ViewPort3d::setDefaultParams()
+{
+  setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
+
+  // get ray tracing parameters from preferences
+  int aDepth = SUIT_Session::session()->resourceMgr()->integerValue( "OCCViewer", "rt_depth", 3 );
+  bool aReflection = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_reflection", true );
+  bool anAntialiasing = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_antialiasing", false );
+  bool aShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_shadow", true );
+  bool aTransparentShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_trans_shadow", true );
+
+  Graphic3d_RenderingParams& aParams = myActiveView->ChangeRenderingParams();
+  aParams.RaytracingDepth = aDepth;
+  aParams.IsReflectionEnabled = aReflection;
+  aParams.IsAntialiasingEnabled = anAntialiasing;
+  aParams.IsShadowEnabled = aShadow;
+  aParams.IsTransparentShadowEnabled = aTransparentShadow;
+  myActiveView->Redraw();
+}