Salome HOME
bos #32216 [CEA] GUI ergonomic: navigation cube.
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.cxx
index f2c3169ce0d324aa504bd99ecc408d8e43f2d72a..f5711547926e9ccb7ef73daa14b7d4997299e080 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -21,8 +21,6 @@
 //
 
 #include "OCCViewer_ViewModel.h"
-#include "OCCViewer.h"
-#include "OCCViewer_ViewWindow.h"
 #include "OCCViewer_ViewFrame.h"
 #include "OCCViewer_VService.h"
 #include "OCCViewer_ViewPort3d.h"
@@ -37,8 +35,6 @@
 
 #include "ViewerData_AISShape.hxx"
 
-#include <Basics_OCCTVersion.hxx>
-
 #include "QtxActionToolMgr.h"
 #include "QtxBackgroundTool.h"
 
 #include <QDesktopWidget>
 
 #include <AIS_Axis.hxx>
-#if OCC_VERSION_LARGE > 0x06080000
-  #include <Prs3d_Drawer.hxx>
-#else
-  #include <AIS_Drawer.hxx>
-#endif
+#include <Prs3d_Drawer.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <StdSelect_ViewerSelector3d.hxx>
 
 #include <Graphic3d_Texture2Dmanual.hxx>
 #include <Graphic3d_MaterialAspect.hxx>
 #include <V3d_DirectionalLight.hxx>
 #include <V3d_AmbientLight.hxx>
 
-#if OCC_VERSION_MAJOR < 7
-  #include <Visual3d_View.hxx>
+#include <Basics_OCCTVersion.hxx>
+
+namespace
+{
+  void setCappingColor(const Handle(Graphic3d_ClipPlane)& plane, const QColor& color)
+  {
+    Quantity_Color qcolor( color.redF(), color.greenF(), color.blueF(), Quantity_TOC_RGB );
+#if OCC_VERSION_LARGE < 0x07040000
+    Graphic3d_MaterialAspect aspect;
+    aspect.SetColor( qcolor );
+    plane->SetCappingMaterial( aspect );
+#else
+    plane->SetCappingColor( qcolor );
 #endif
+  }
+}
 
 /*!
   Get data for supported background modes: gradient types, identifiers and supported image formats
@@ -116,32 +122,35 @@ void OCCViewer_Viewer::stereoData( QStringList& typeList, QIntList& idList)
 */
 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
 : SUIT_ViewModel(),
-  myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
   myIsRelative(true),
-  myTopLayerId( 0 ),
+  myTopLayerId(0),
   myTrihedronSize(100),
-  myClippingDlg (NULL)
+  myBackgrounds(4, Qtx::BackgroundData(Qt::black)),
+  myClippingDlg(0),
+  myFitter(0)
 {
   // init CasCade viewers
-  myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
+  myV3dViewer = OCCViewer_VService::CreateViewer();
   //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
   setDefaultLights();
 
   // init selector
   myAISContext = new AIS_InteractiveContext( myV3dViewer );
-#if OCC_VERSION_LARGE > 0x07010000
   myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
   myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
-#elif OCC_VERSION_LARGE > 0x07000000
-  const Handle(Graphic3d_HighlightStyle)& sStyle = myAISContext->SelectionStyle();
-  sStyle->SetColor( Quantity_NOC_WHITE );
-#else
-  myAISContext->SelectionColor( Quantity_NOC_WHITE );
-#endif
-  
+
   // display isoline on planar faces (box for ex.)
   myAISContext->IsoOnPlane( true );
-  
+
+  // 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 )
   {
@@ -153,20 +162,19 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
     //myTrihedron->SetColor( Col );
     myTrihedron->SetArrowColor( Col.Name() );
     myTrihedron->SetSize(100);
-#if OCC_VERSION_LARGE > 0x06080000
-      Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
-      if (drawer->HasOwnDatumAspect()) {
-#else
-      Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
-      if (drawer->HasDatumAspect()) {
-#endif
+    Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
+    if (drawer->HasOwnDatumAspect()) {
       Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
-      daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
-      daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
-      daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
+      daspect->LineAspect(Prs3d_DP_XAxis)->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
+      daspect->LineAspect(Prs3d_DP_YAxis)->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
+      daspect->LineAspect(Prs3d_DP_ZAxis)->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
     }
   }
 
+  /* create view cube */
+  myViewCube  = new AIS_ViewCube();
+  setViewCubeParamsFromPreferences();
+
   // set interaction style to standard
   myInteractionStyle = 0;
 
@@ -182,6 +190,7 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
 
   // set projection type to orthographic
   myProjectionType = 0;
+  mySelectionStyle = OCCViewer_ViewWindow::RectStyle;
   // set stereo parameters
   myStereoType = 0;
   myAnaglyphFilter = 0;
@@ -256,6 +265,7 @@ void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
     view->initSketchers();
     view->setInteractionStyle( interactionStyle() );
     view->setProjectionType( projectionType() );
+    view->setSelectionStyle( selectionStyle() );
     view->setStereoType( stereoType() );
     view->setAnaglyphFilter( anaglyphFilter() );
     view->setStereographicFocus( stereographicFocusType(), stereographicFocusValue() );
@@ -270,9 +280,6 @@ void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
     OCCViewer_ViewPort3d* vp3d = view->getViewPort();
     if ( vp3d )
     {
-#if OCC_VERSION_LARGE <= 0x07000000
-      vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
-#endif
       // connect signal from viewport
       connect(vp3d, SIGNAL(vpClosed(OCCViewer_ViewPort3d*)), this, SLOT(onViewClosed(OCCViewer_ViewPort3d*)));
       connect(vp3d, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewMapped(OCCViewer_ViewPort3d*)));
@@ -323,7 +330,7 @@ void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
 /*!
   SLOT: called on mouse button press, stores current mouse position as start point for transformations
 */
-void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
+void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* /*theWindow*/, QMouseEvent* theEvent)
 {
   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
 }
@@ -371,17 +378,16 @@ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* t
   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
   bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
   
-  if (!aHasShift) {
-    myAISContext->ClearCurrents( false );
-    emit deselection();
-  }
-
   if (myStartPnt == myEndPnt)
   {
+    if (!aHasShift) {
+      myAISContext->ClearCurrents( false ); // todo: ClearCurrents is deprecated
+      emit deselection();
+    }
     if ( !isPreselectionEnabled() ) {
       Handle(V3d_View) aView3d = aView->getViewPort()->getView();
       if ( !aView3d.IsNull() ) {
-       myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
+             myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
       }
     }
 
@@ -389,33 +395,34 @@ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* t
       myAISContext->ShiftSelect( Standard_True );
     else 
       myAISContext->Select( Standard_True );
+    emit selectionChanged();
   }
-  else
-  {
-    if (aHasShift && myMultiSelectionEnabled)
-      myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
-                                myEndPnt.x(), myEndPnt.y(),
-                                aView->getViewPort()->getView(), Standard_False );
-    else
-      myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
-                           myEndPnt.x(), myEndPnt.y(),
-                           aView->getViewPort()->getView(), Standard_False );
 
-    int Nb = myAISContext->NbSelected();
-    if( Nb>1 && !myMultiSelectionEnabled )
-    {
-        myAISContext->InitSelected();
-        Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
-        if( !anOwner.IsNull() )
-        {
-            myAISContext->ClearSelected( Standard_False );
-            myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
-        }
-    }
-
-    myAISContext->UpdateCurrentViewer();
-  }
-  emit selectionChanged();
+  //else
+  //{
+  //  if (aHasShift && myMultiSelectionEnabled)
+  //    myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
+  //                              myEndPnt.x(), myEndPnt.y(),
+  //                              aView->getViewPort()->getView(), Standard_False );
+  //  else
+  //    myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
+  //                         myEndPnt.x(), myEndPnt.y(),
+  //                         aView->getViewPort()->getView(), Standard_False );
+
+  //  int Nb = myAISContext->NbSelected();
+  //  if( Nb>1 && !myMultiSelectionEnabled )
+  //  {
+  //      myAISContext->InitSelected();
+  //      Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
+  //      if( !anOwner.IsNull() )
+  //      {
+  //          myAISContext->ClearSelected( Standard_False );
+  //          myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
+  //      }
+  //  }
+
+  //  myAISContext->UpdateCurrentViewer();
+  //}
 }
 
 /*!
@@ -433,7 +440,7 @@ void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEven
   switch ( theEvent->key() ) {
   case  Qt::Key_S:
     if (!aHasShift) {
-      myAISContext->ClearCurrents( false );
+      myAISContext->ClearCurrents( false ); // todo: ClearCurrents is deprecated
       emit deselection();
     }
 
@@ -454,14 +461,12 @@ void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEven
     break;
   case  Qt::Key_N:
     if ( isPreselectionEnabled() ) {
-      if ( getAISContext()->HasOpenedContext() )
-       getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
+      getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
     }
     break;
   case  Qt::Key_P:
     if ( isPreselectionEnabled() ) {
-      if ( getAISContext()->HasOpenedContext() )
-       getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
+      getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
     }
     break;
   default:
@@ -482,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 );
 }
@@ -556,6 +567,31 @@ void OCCViewer_Viewer::setProjectionType( const int theType )
   }
 }
 
+
+OCCViewer_ViewWindow::SelectionStyle OCCViewer_Viewer::selectionStyle() const
+{
+  return mySelectionStyle;
+}
+
+void OCCViewer_Viewer::setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle theMode)
+{
+  if (mySelectionStyle != theMode) {
+    mySelectionStyle = theMode;
+    if (!myViewManager)
+      return;
+
+    QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
+    for (int i = 0; i < (int)wins.count(); i++)
+    {
+      OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>(wins.at(i));
+      if (win)
+        win->setSelectionStyle(theMode);
+    }
+  }
+}
+
+
+
 /*!
   \return stereo type
 */
@@ -898,12 +934,8 @@ void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
   if( myInternalClipPlanes.IsEmpty() )
     return;
 
-  Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
-  aMaterialAspect.SetColor( Quantity_Color( theColor.redF(), theColor.greenF(),
-                                            theColor.blueF(), Quantity_TOC_RGB ) );
-
-  for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
-    myInternalClipPlanes.Value(i)->SetCappingMaterial( aMaterialAspect );
+  for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
+    setCappingColor( aPlaneIt.Value(), theColor );
 
   update();
 }
@@ -953,9 +985,8 @@ void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QSt
   Handle(Graphic3d_Texture2Dmanual) aTexture =
     initClippingTexture( myDefaultTextureUsed, myClippingTexture,
                          myTextureModulated, myClippingTextureScale );
-
-  for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
-    myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
+  for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
+    aPlaneIt.Value()->SetCappingTexture( aTexture );
 
   update();
 }
@@ -1118,11 +1149,14 @@ void OCCViewer_Viewer::setDefaultLights()
   double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 );
 
   Handle(V3d_DirectionalLight) aLight =
-    new V3d_DirectionalLight( myV3dViewer, V3d_Zneg, OCCViewer::color( aColor ).Name(), Standard_True );
+    new V3d_DirectionalLight( V3d_Zneg, OCCViewer::color( aColor ).Name(), Standard_True );
+  myV3dViewer->AddLight( aLight );
   if( !( aDx == 0 && aDy == 0 && aDz == 0 ) )
     aLight->SetDirection( aDx, aDy, aDz );
   myV3dViewer->SetLightOn( aLight );
-  myV3dViewer->SetLightOn( new V3d_AmbientLight( myV3dViewer ) );
+  Handle(V3d_AmbientLight) ambLight = new V3d_AmbientLight();
+  myV3dViewer->AddLight( ambLight );
+  myV3dViewer->SetLightOn( ambLight );
 }
 
 /*!
@@ -1134,19 +1168,16 @@ void OCCViewer_Viewer::setDefaultLights()
 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
                                   bool hilight, bool update )
 {
-  bool isInLocal = myAISContext->HasOpenedContext();
-  if( !obj.IsNull() )
-    if( !isInLocal )
-    {
-      if ( hilight && !myAISContext->IsSelected( obj ) )
-        myAISContext->AddOrRemoveCurrentObject( obj, false );
-      else if ( !hilight && myAISContext->IsSelected( obj ) )
-        myAISContext->AddOrRemoveCurrentObject( obj, false );
-    }
+  if( !obj.IsNull() ) {
+    if ( hilight && !myAISContext->IsSelected( obj ) )
+      myAISContext->AddOrRemoveSelected( obj, false );
+    else if ( !hilight && myAISContext->IsSelected( obj ) )
+      myAISContext->AddOrRemoveSelected( obj, false );
+  }
 
   if ( update )
     myV3dViewer->Redraw();
-    
+  
   return false;
 }
 
@@ -1156,20 +1187,11 @@ bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
 */
 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
 {
-  if ( myAISContext->HasOpenedContext() ) {
-    if ( unselect ) {
-      myAISContext->ClearSelected( updateviewer );
-    } else {
-      myAISContext->UnhilightSelected( updateviewer );
-    }
+  if ( unselect ) {
+    myAISContext->ClearSelected( updateviewer );
   } else {
-    if ( unselect ) {
-      myAISContext->ClearCurrents( updateviewer );
-    } else {
-      myAISContext->UnhilightCurrents( updateviewer );
-    }
+    myAISContext->UnhilightSelected( updateviewer );
   }
-
   return false;
 }
 
@@ -1179,7 +1201,7 @@ bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
   \param onlyInViewer - search object only in viewer (so object must be displayed)
 */
 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
-                                   bool onlyInViewer )
+                                   bool /*onlyInViewer*/ )
 {
   AIS_ListOfInteractive List;
   myAISContext->DisplayedObjects(List);
@@ -1253,12 +1275,26 @@ void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj
     myV3dViewer->Update();
 }
 
-/*!
-  Changes visibility of trihedron to opposite
-*/
-void OCCViewer_Viewer::toggleTrihedron()
+bool OCCViewer_Viewer::isColorScaleVisible() const
 {
-  setTrihedronShown( !isTrihedronVisible() );
+  return !myColorScale.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myColorScale );
+}
+
+void OCCViewer_Viewer::setColorScaleShown( const bool on )
+{
+  if ( myColorScale.IsNull() )
+    return;
+  if ( on )
+  {
+    if ( !myAISContext->IsDisplayed( myColorScale ) )
+      myAISContext->Display( myColorScale, Standard_True );
+    myAISContext->Redisplay( myColorScale, Standard_True, Standard_True );
+  }
+  else
+  {
+    if ( myAISContext->IsDisplayed( myColorScale ) )
+      myAISContext->Erase( myColorScale, Standard_True );
+  }
 }
 
 /*!
@@ -1269,6 +1305,14 @@ bool OCCViewer_Viewer::isTrihedronVisible() const
   return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
 }
 
+/*!
+  \return true if view cube is visible
+*/
+bool OCCViewer_Viewer::isViewCubeVisible() const
+{
+  return !myViewCube.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myViewCube );
+}
+
 /*!
   Sets visibility state of trihedron
   \param on - new state
@@ -1284,7 +1328,6 @@ void OCCViewer_Viewer::setTrihedronShown( const bool on )
                            0 /*wireframe*/,
                            -1 /* selection mode */,
                            Standard_True /* update viewer*/,
-                           Standard_False /* allow decomposition */,
                            AIS_DS_Displayed /* display status */);
     myAISContext->Deactivate( myTrihedron );
   }
@@ -1293,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
 */
@@ -1421,7 +1528,7 @@ bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize
 
   float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
 
-  static float EPS = 5.0E-3;
+  static float EPS = 5.0E-3f;
   theSize = getTrihedron()->Size();
   theNewSize = aMaxSide*aSizeInPercents / 100.0;
 
@@ -1437,7 +1544,6 @@ double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
   double aMaxSide = 0;
   double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
 
-#if OCC_VERSION_LARGE > 0x06070100
   Bnd_Box aBox = view3d->View()->MinMaxValues();
   Xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
   Ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
@@ -1445,9 +1551,6 @@ double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
   Xmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().X();
   Ymax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Y();
   Zmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Z();
-#else
-  view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
-#endif
 
   if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
        Xmax != RealLast()  && Ymax != RealLast()  && Zmax != RealLast() )
@@ -1504,10 +1607,7 @@ Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& theP
   aGraphic3dPlane->SetCapping( Standard_True );
 
   // set capping color
-  Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
-  aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
-                                            myClippingColor.blueF(), Quantity_TOC_RGB ) );
-  aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
+  setCappingColor( aGraphic3dPlane, myClippingColor );
 
   // set capping texture
   aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture,
@@ -1547,7 +1647,7 @@ void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList)
     Handle(AIS_InteractiveObject) anObj = anIter.Value();
     Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj);
     if (!aShape.IsNull() && aShape->IsClippable()) {
-      aShape->SetClipPlanes(myInternalClipPlanes);
+      aShape->SetClipPlanes(new Graphic3d_SequenceOfHClipPlane(myInternalClipPlanes)); // todo: store clipping planes in a handle?
     }
   }
 }
@@ -1566,7 +1666,7 @@ void OCCViewer_Viewer::applyExistingClipPlanesToObject (const Handle(AIS_Interac
   Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (theObject);
   if (!aShape.IsNull() && aShape->IsClippable())
   {
-    aShape->SetClipPlanes (myInternalClipPlanes);
+    aShape->SetClipPlanes (new Graphic3d_SequenceOfHClipPlane(myInternalClipPlanes)); // todo: store clipping planes in a handle?
   }
 }