]> SALOME platform Git repositories - modules/gui.git/blobdiff - src/OCCViewer/OCCViewer_ViewModel.cxx
Salome HOME
0023124: EDF 11219 GEOM: Ray tracing in the OCC viewer
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.cxx
index 282cc5721933e52ccead81b2d65fc2e56e55b4e9..fe2546853b34f478998ed0d9bc92dc90c2f2e64d 100755 (executable)
@@ -36,6 +36,8 @@
 
 #include "ViewerData_AISShape.hxx"
 
+#include "CAF_Tools.h"
+
 #include <Basics_OCCTVersion.hxx>
 
 #include "QtxActionToolMgr.h"
@@ -73,6 +75,9 @@
 
 #include <Visual3d_View.hxx>
 
+#include <V3d_DirectionalLight.hxx>
+#include <V3d_AmbientLight.hxx>
+
 /*!
   Get data for supported background modes: gradient types, identifiers and supported image formats
 */
@@ -120,7 +125,7 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   // init CasCade viewers
   myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
   //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
-  myV3dViewer->SetDefaultLights();
+  setDefaultLights();
 
   // init selector
   myAISContext = new AIS_InteractiveContext( myV3dViewer );
@@ -1083,6 +1088,33 @@ void OCCViewer_Viewer::performSelectionChanged()
     emit selectionChanged();
 }
 
+/*
+ * Defines default lights
+ */
+void OCCViewer_Viewer::setDefaultLights()
+{
+  // clear all light sources
+  myV3dViewer->InitDefinedLights();
+  while ( myV3dViewer->MoreDefinedLights() )
+  {
+    myV3dViewer->DelLight( myV3dViewer->DefinedLight() );
+    myV3dViewer->InitDefinedLights();
+  }
+
+  // get light source parameters from preferences
+  QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "OCCViewer", "light_color", QColor( 0, 0, 0 ) );
+  double aDx = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dx", 0.0 );
+  double aDy = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dy", 0.0 );
+  double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 );
+
+  Handle(V3d_DirectionalLight) aLight =
+    new V3d_DirectionalLight( myV3dViewer, V3d_Zneg, CAF_Tools::color( aColor ).Name(), Standard_True );
+  if( !( aDx == 0 && aDy == 0 && aDz == 0 ) )
+    aLight->SetDirection( aDx, aDy, aDz );
+  myV3dViewer->SetLightOn( aLight );
+  myV3dViewer->SetLightOn( new V3d_AmbientLight( myV3dViewer ) );
+}
+
 /*!
   Hilights/unhilights object in viewer
   \param obj - object to be updated