]> SALOME platform Git repositories - modules/gui.git/blobdiff - src/OCCViewer/OCCViewer_ViewPort3d.cxx
Salome HOME
INT PAL 53422: FitAll does't work in OCC viewer
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewPort3d.cxx
index a60ec0e62b6b08bdb13168552d42cb723fc5b471..4a2cb3a222ceb4af644dd3845a939e90e2b21128 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -28,6 +28,8 @@
 
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewModel.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
 
 #include <QColor>
 #include <QFileInfo>
 #include <QPaintEvent>
 #include <QResizeEvent>
 #include <QApplication>
+#include <QTimer>
 
-#include <Visual3d_View.hxx>
-#include <V3d_Viewer.hxx>
+#if OCC_VERSION_MAJOR < 7
+  #include <Visual3d_View.hxx>
+#endif
 
 #if OCC_VERSION_LARGE > 0x06070100
 #include <V3d_View.hxx>
@@ -88,7 +92,7 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V
   }
 #endif
 
-  setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
+  setDefaultParams();
 
   myCursor = NULL;
 }
@@ -522,7 +526,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();
   }
 }
 
@@ -589,10 +594,17 @@ void OCCViewer_ViewPort3d::paintEvent( QPaintEvent* e )
     mapView( activeView() );
 #endif
   if ( !myWindow.IsNull() ) {
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     QApplication::syncX();
-    QRect rc = e->rect();
-    if ( !myPaintersRedrawing )
+#endif
+    if ( !myPaintersRedrawing ) {
+#if OCC_VERSION_MAJOR < 7
+      QRect rc = e->rect();
       activeView()->Redraw( rc.x(), rc.y(), rc.width(), rc.height() );
+#else
+      activeView()->Redraw();
+#endif
+    }
   }
   OCCViewer_ViewPort::paintEvent( e );
   myBusy = false;
@@ -603,14 +615,25 @@ void OCCViewer_ViewPort3d::paintEvent( QPaintEvent* e )
 */
 void OCCViewer_ViewPort3d::resizeEvent( QResizeEvent* e )
 {
-#ifdef WIN32
+#if defined WIN32 || QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
   /* Win32 : map before first show to avoid flicker */
   if ( !mapped( activeView() ) )
     mapView( activeView() );
 #endif
-  QApplication::syncX();
-  if ( !activeView().IsNull() )
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+    QApplication::syncX();
+#endif
+  QTimer::singleShot( 0, this, SLOT( repaintViewAfterMove() ) );
+}
+
+/*!
+  Moved the viewport
+*/
+void OCCViewer_ViewPort3d::repaintViewAfterMove( )
+{
+  if ( !activeView().IsNull() ){
     activeView()->MustBeResized();
+  }
 }
 
 /*!
@@ -791,3 +814,26 @@ 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();
+}