Salome HOME
updated copyright message
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.cxx
index f5d68aa632b64a63cbdb5ceb1fef55896267954e..e6b43772a66c9e1b30c441ead3e5a79a22d9bd04 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  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
@@ -145,8 +145,12 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   // create color scale
   myColorScale = new AIS_ColorScale();
   myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
+#if OCC_VERSION_LARGE < 0x07070000
   myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
-  
+#else
+  myColorScale->SetTransformPersistence( new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER) );
+#endif
+
   /* create trihedron */
   if ( DisplayTrihedron )
   {
@@ -167,6 +171,10 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
     }
   }
 
+  /* create view cube */
+  myViewCube  = new AIS_ViewCube();
+  setViewCubeParamsFromPreferences();
+
   // set interaction style to standard
   myInteractionStyle = 0;
 
@@ -479,9 +487,15 @@ void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
 
 void OCCViewer_Viewer::onViewMapped(OCCViewer_ViewPort3d* viewPort)
 {
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
   setTrihedronShown( true );
+
+  bool showViewCube = true;
+  if ( resMgr ) showViewCube = resMgr->booleanValue( "OCCViewer", "viewcube_show", true );
+  setViewCubeShown( showViewCube );
+
   bool showStaticTrihedron = true;
-  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   if ( resMgr ) showStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
   viewPort->showStaticTrihedron( showStaticTrihedron );
 }
@@ -1284,19 +1298,19 @@ void OCCViewer_Viewer::setColorScaleShown( const bool on )
 }
 
 /*!
-  Changes visibility of trihedron to opposite
+  \return true if trihedron is visible
 */
-void OCCViewer_Viewer::toggleTrihedron()
+bool OCCViewer_Viewer::isTrihedronVisible() const
 {
-  setTrihedronShown( !isTrihedronVisible() );
+  return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
 }
 
 /*!
-  \return true if trihedron is visible
+  \return true if view cube is visible
 */
-bool OCCViewer_Viewer::isTrihedronVisible() const
+bool OCCViewer_Viewer::isViewCubeVisible() const
 {
-  return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
+  return !myViewCube.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myViewCube );
 }
 
 /*!
@@ -1322,6 +1336,70 @@ void OCCViewer_Viewer::setTrihedronShown( const bool on )
   }
 }
 
+/*!
+  Sets visibility state of view cube
+  \param on - new state
+*/
+
+void OCCViewer_Viewer::setViewCubeShown( const bool on )
+{
+  if ( myViewCube.IsNull() )
+    return;
+
+  if ( on ) {
+    myAISContext->Display( myViewCube,
+                           0 /*wireframe*/,
+                           0 /* selection mode */,
+                           Standard_True /* update viewer*/,
+                           AIS_DS_Displayed /* display status */);
+  }
+  else {
+    myAISContext->Erase( myViewCube, Standard_True );
+  }
+}
+
+/*!
+  Set View Cube parameters from preferences
+*/
+void OCCViewer_Viewer::setViewCubeParamsFromPreferences()
+{
+  // Resource manager
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+  if (!resMgr || myViewCube.IsNull())
+    return;
+
+  bool isVisibleVC = isVisible(myViewCube);
+
+  if (resMgr->booleanValue("OCCViewer", "viewcube_custom", false)) {
+    // Use custom settings from preferences
+    QColor aColor;
+
+    // Box color
+    aColor = resMgr->colorValue("OCCViewer", "viewcube_color", QColor(255, 255, 255));
+    myViewCube->SetBoxColor(OCCViewer::color(aColor));
+
+    // Size
+    myViewCube->SetSize(resMgr->doubleValue("OCCViewer", "viewcube_size", 70.0));
+
+    // Text color
+    aColor = resMgr->colorValue("OCCViewer", "viewcube_text_color", QColor(0, 0, 0));
+    myViewCube->SetTextColor(OCCViewer::color(aColor));
+  }
+  else {
+    myViewCube->ResetStyles();
+  }
+
+  // Axes
+  myViewCube->SetDrawAxes(resMgr->booleanValue("OCCViewer", "viewcube_axes", false));
+
+  // Animation duration (sec)
+  myViewCube->SetDuration(resMgr->doubleValue("OCCViewer", "viewcube_duration", 0.5));
+
+  // Update the viewer
+  if (isVisibleVC)
+    myAISContext->Redisplay( myViewCube, Standard_True);
+}
+
 /*!
   \return trihedron size
 */