Salome HOME
0023450: Fields are not displayed in GEOM
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 64e5585..9de7848
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  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
@@ -21,6 +21,7 @@
 //
 
 #include "OCCViewer_ViewModel.h"
+#include "OCCViewer.h"
 #include "OCCViewer_ViewWindow.h"
 #include "OCCViewer_ViewFrame.h"
 #include "OCCViewer_VService.h"
 #include <QDesktopWidget>
 
 #include <AIS_Axis.hxx>
-#include <AIS_Drawer.hxx>
-#include <AIS_ListOfInteractive.hxx>
+#include <Prs3d_Drawer.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 
 #include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_MaterialAspect.hxx>
 #include <Graphic3d_TextureParams.hxx>
 
 #include <Geom_Axis2Placement.hxx>
@@ -64,7 +65,8 @@
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_TextAspect.hxx>
 
-#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
@@ -83,6 +85,21 @@ QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idLis
   return tr("BG_IMAGE_FILES");
 }
 
+/*!
+  Get data for supported stereo pair modes: stereo types and identifiers
+*/
+void OCCViewer_Viewer::stereoData( QStringList& typeList, QIntList& idList)
+{
+  typeList << tr("ST_QUADBUFFER")    << tr("ST_ANAGLYPH")         <<
+              tr("ST_ROWINTERLACED") << tr("ST_COLUMNINTERLACED") <<
+              tr("ST_CHESSBOARD")    << tr("ST_SIDEBYSIDE")       <<
+              tr("ST_OVERUNDER");
+  idList   << QuadBufferType    << AnaglyphType         <<
+              RowInterlacedType << ColumnInterlacedType <<
+              ChessBoardType    << SideBySideType       <<
+              OverUnderType;
+}
+
 /*!
   Constructor
   \param DisplayTrihedron - is trihedron displayed
@@ -93,19 +110,26 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   myIsRelative(true),
   myTopLayerId( 0 ),
   myTrihedronSize(100),
-  myClippingDlg (NULL)
+  myClippingDlg (NULL),
+  myIsUseLocalSelection(false)
 {
   // 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 );
-  myAISContext->SelectionColor( Quantity_NOC_WHITE );
+  myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
+  myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
   
   // display isoline on planar faces (box for ex.)
   myAISContext->IsoOnPlane( true );
+
+  // create color scale
+  myColorScale = new AIS_ColorScale();
+  myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
+  myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
   
   /* create trihedron */
   if ( DisplayTrihedron )
@@ -118,8 +142,8 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
     //myTrihedron->SetColor( Col );
     myTrihedron->SetArrowColor( Col.Name() );
     myTrihedron->SetSize(100);
-    Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
-    if (drawer->HasDatumAspect()) {
+    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));
@@ -139,6 +163,26 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   // selection
   mySelectionEnabled = true;
   myMultiSelectionEnabled = true;
+
+  // set projection type to orthographic
+  myProjectionType = 0;
+  // set stereo parameters
+  myStereoType = 0;
+  myAnaglyphFilter = 0;
+  myToReverseStereo = 0;
+  myVSyncMode = 1;
+  myQuadBufferSupport = 0;
+  myStereographicFocusType = 1;
+  myInterocularDistanceType = 1;
+  myStereographicFocusValue = 1.0;
+  myInterocularDistanceValue = 0.05;
+  //set clipping color and texture to standard
+  myClippingColor = QColor( 50, 50, 50 );
+  myDefaultTextureUsed = true;
+  myClippingTexture = QString();
+  myTextureModulated = true;
+  myClippingTextureScale = 1.0;
+
 }
 
 /*!
@@ -195,14 +239,21 @@ void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
     view->initLayout();
     view->initSketchers();
     view->setInteractionStyle( interactionStyle() );
+    view->setProjectionType( projectionType() );
+    view->setStereoType( stereoType() );
+    view->setAnaglyphFilter( anaglyphFilter() );
+    view->setStereographicFocus( stereographicFocusType(), stereographicFocusValue() );
+    view->setInterocularDistance( interocularDistanceType(), interocularDistanceValue() );
+    view->setReverseStereo( isReverseStereo() );
+    view->setVSync( isVSync() );
+    view->setQuadBufferSupport( isQuadBufferSupport() );
     view->setZoomingStyle( zoomingStyle() );
     view->enablePreselection( isPreselectionEnabled() );
     view->enableSelection( isSelectionEnabled() );
-    
+
     OCCViewer_ViewPort3d* vp3d = view->getViewPort();
     if ( vp3d )
     {
-      vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
       // 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*)));
@@ -279,7 +330,7 @@ void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theE
     }
     Handle(V3d_View) aView3d = aView->getViewPort()->getView();
     if ( !aView3d.IsNull() ) {
-      myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
+      myAISContext->MoveTo( theEvent->x(), theEvent->y(), aView3d, Standard_True );
     }
   }
 }
@@ -301,21 +352,24 @@ 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) emit deselection();
+  if (!aHasShift) {
+    myAISContext->ClearCurrents( false );
+    emit deselection();
+  }
 
   if (myStartPnt == myEndPnt)
   {
     if ( !isPreselectionEnabled() ) {
       Handle(V3d_View) aView3d = aView->getViewPort()->getView();
       if ( !aView3d.IsNull() ) {
-       myAISContext->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
+       myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
       }
     }
 
     if (aHasShift && myMultiSelectionEnabled)
-      myAISContext->ShiftSelect();
-    else
-      myAISContext->Select();
+      myAISContext->ShiftSelect( Standard_True );
+    else 
+      myAISContext->Select( Standard_True );
   }
   else
   {
@@ -351,25 +405,49 @@ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* t
 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
 {
   if (!mySelectionEnabled) return;
-  if (theEvent->key() != Qt::Key_S) return;
-  if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
 
-  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
-  if (!aView || aView->interactionStyle() != SUIT_ViewModel::KEY_FREE)
-    return;
+  OCCViewer_ViewWindow* aView = qobject_cast<OCCViewer_ViewWindow*>( theWindow );
+  if ( !aView ) return;
 
-  emit deselection();
+  bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
 
-  if ( !isPreselectionEnabled() ) {
-    Handle(V3d_View) aView3d = aView->getViewPort()->getView();
-    if ( !aView3d.IsNull() ) {
-      myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d);
+  switch ( theEvent->key() ) {
+  case  Qt::Key_S:
+    if (!aHasShift) {
+      myAISContext->ClearCurrents( false );
+      emit deselection();
+    }
+
+    if ( !isPreselectionEnabled() ) {
+      Handle(V3d_View) aView3d = aView->getViewPort()->getView();
+      if ( !aView3d.IsNull() ) {
+       myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d, Standard_True );
+      }
     }
-  }
 
-  myAISContext->Select();
+    if (aHasShift && myMultiSelectionEnabled)
+      myAISContext->ShiftSelect( Standard_True );
+    else
+      myAISContext->Select( Standard_True );
 
-  emit selectionChanged();
+    emit selectionChanged();
+
+    break;
+  case  Qt::Key_N:
+    if ( isPreselectionEnabled() ) {
+      if ( useLocalSelection() )
+       getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
+    }
+    break;
+  case  Qt::Key_P:
+    if ( isPreselectionEnabled() ) {
+      if ( getAISContext()->HasOpenedContext() )
+       getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
+    }
+    break;
+  default:
+    break;
+  }
 }
 
 void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
@@ -428,6 +506,253 @@ void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
   }
 }
 
+/*!
+  \return projection type
+*/
+int OCCViewer_Viewer::projectionType() const
+{
+  return myProjectionType;
+}
+
+/*!
+  Sets projection type: 0 - orthographic, 1 - perspective
+  \param theType - new projection type
+*/
+void OCCViewer_Viewer::setProjectionType( const int theType )
+{
+  if ( myProjectionType != theType ) {
+    if ( theType != OCCViewer_ViewWindow::Stereo )
+      myProjectionType = theType;
+
+    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->setProjectionType( (OCCViewer_ViewWindow::ProjectionType)theType );
+    }
+  }
+}
+
+/*!
+  \return stereo type
+*/
+int OCCViewer_Viewer::stereoType() const
+{
+  return myStereoType;
+}
+
+/*!
+  Sets stereo type
+  \param theType - new stereo type
+*/
+void OCCViewer_Viewer::setStereoType( const int theType )
+{
+  myStereoType = theType;
+
+  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->setStereoType( (OCCViewer_ViewWindow::StereoType)theType );
+  }
+}
+
+/*!
+  \return stereographic focus type
+*/
+int OCCViewer_Viewer::stereographicFocusType() const
+{
+  return myStereographicFocusType;
+}
+
+/*!
+  \return stereographic focus value
+*/
+double OCCViewer_Viewer::stereographicFocusValue() const
+{
+  return myStereographicFocusValue;
+}
+
+/*!
+  Sets stereographic focus parameters
+  \param theType - new stereographic focus type
+  \param theValue - new stereographic focus value
+*/
+void OCCViewer_Viewer::setStereographicFocus( const int theType, const double theValue )
+{
+  myStereographicFocusType = theType;
+  myStereographicFocusValue = theValue;
+
+  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->setStereographicFocus( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
+  }
+}
+
+/*!
+  \return stereographic focus type
+*/
+int OCCViewer_Viewer::interocularDistanceType() const
+{
+  return myInterocularDistanceType;
+}
+
+/*!
+  \return stereographic focus value
+*/
+double OCCViewer_Viewer::interocularDistanceValue() const
+{
+  return myInterocularDistanceValue;
+}
+
+/*!
+  Sets interocular distance parameters
+  \param theType - new IOD type
+  \param theValue - new IOD value
+*/
+void OCCViewer_Viewer::setInterocularDistance( const int theType, const double theValue )
+{
+  myInterocularDistanceType = theType;
+  myInterocularDistanceValue = theValue;
+
+  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->setInterocularDistance( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
+  }
+}
+
+/*!
+  \return anaglyph filter
+*/
+int OCCViewer_Viewer::anaglyphFilter() const
+{
+  return myAnaglyphFilter;
+}
+
+/*!
+  Sets anaglyph filter
+  \param theType - new anaglyph filter
+*/
+void OCCViewer_Viewer::setAnaglyphFilter( const int theType )
+{
+  myAnaglyphFilter = theType;
+
+  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->setAnaglyphFilter( (OCCViewer_ViewWindow::AnaglyphFilter)theType );
+  }
+}
+
+/*!
+  \return reverse stereo
+*/
+bool OCCViewer_Viewer::isReverseStereo() const
+{
+  return myToReverseStereo;
+}
+
+/*!
+  Sets reverse stereo
+  \param theReverse - enable/disable reverse mode
+*/
+void OCCViewer_Viewer::setReverseStereo( const bool theReverse )
+{
+  myToReverseStereo = theReverse;
+
+  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->setReverseStereo( theReverse );
+  }
+}
+
+/*!
+  \return V-Sync mode
+*/
+bool OCCViewer_Viewer::isVSync() const
+{
+  return myVSyncMode;
+}
+
+/*!
+  Set V-Sync mode
+  \param theEnable - enable/disable V-Sync mode
+*/
+void OCCViewer_Viewer::setVSync( const bool theEnable )
+{
+  myVSyncMode = theEnable;
+
+  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->setVSync( theEnable );
+  }
+}
+
+/*!
+  \return support quad-buffered stereo
+*/
+bool OCCViewer_Viewer::isQuadBufferSupport() const
+{
+  return myQuadBufferSupport;
+}
+
+/*!
+  Set support quad-buffered stereo
+  \param theEnable - enable/disable support quad-buffered stereo
+*/
+void OCCViewer_Viewer::setQuadBufferSupport( const bool theEnable )
+{
+  myQuadBufferSupport = theEnable;
+
+  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->setQuadBufferSupport( theEnable );
+  }
+}
+
 /*!
   \return zooming style
 */
@@ -543,6 +868,111 @@ void OCCViewer_Viewer::enableMultiselection(bool isEnable)
   }
 }
 
+/*!
+  Sets a color of the clipped region
+  \param theColor - a new color of the clipped region
+*/
+void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
+{
+  myClippingColor = 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 );
+
+  update();
+}
+
+/*!
+  \return clipping color
+*/
+QColor OCCViewer_Viewer::clippingColor() const
+{
+  return myClippingColor;
+}
+
+// initialize a texture for clipped region
+Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture,
+                                                       const bool isModulate, const double theScale )
+{
+  QString aTextureFile = isDefault ? ":images/hatch.png" : theTexture;
+  QPixmap px( aTextureFile );
+  const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
+  Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
+  if( aTexture->IsDone() ) {
+    aTexture->EnableRepeat();
+    isModulate ? aTexture->EnableModulate() : aTexture->DisableModulate();
+    aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) );
+  }
+  return aTexture;
+}
+
+/*!
+  Sets default texture parameters
+  \param isDefault - use/non-use default texture
+  \param theTexture - new texture of the clipped region
+  \param isModulate - enable/disable texture modulate mode
+  \param theScale - scale factor.
+*/
+void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QString& theTexture,
+                                                 const bool isModulate, const double theScale )
+{
+  myDefaultTextureUsed = isDefault;
+  myClippingTexture = theTexture;
+  myTextureModulated = isModulate;
+  myClippingTextureScale = theScale;
+
+  if( myInternalClipPlanes.IsEmpty() )
+    return;
+
+  Handle(Graphic3d_Texture2Dmanual) aTexture =
+    initClippingTexture( myDefaultTextureUsed, myClippingTexture,
+                         myTextureModulated, myClippingTextureScale );
+
+  for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
+    myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
+
+  update();
+}
+
+/*!
+  \return true if default texture is used
+*/
+bool OCCViewer_Viewer::isDefaultTextureUsed() const
+{
+  return myDefaultTextureUsed;
+}
+
+/*!
+  \return clipping texture
+*/
+QString OCCViewer_Viewer::clippingTexture() const
+{
+  return myClippingTexture;
+}
+
+/*!
+  \return true if texture is modulated
+*/
+bool OCCViewer_Viewer::isTextureModulated() const
+{
+  return myTextureModulated;
+}
+
+/*!
+  \return scale factor of texture
+*/
+double OCCViewer_Viewer::clippingTextureScale() const
+{
+  return myClippingTextureScale;
+}
+
 /*!
   Builds popup for occ viewer
 */
@@ -556,7 +986,7 @@ void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
 
   //Support of several toolbars in the popup menu
-  QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
+  QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
   QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
   for ( ; it!=last; it++ ) {
     if ( (*it)->parentWidget()->isVisible() )
@@ -649,6 +1079,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, OCCViewer::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
@@ -777,6 +1234,28 @@ void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj
     myV3dViewer->Update();
 }
 
+bool OCCViewer_Viewer::isColorScaleVisible() const
+{
+  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 );
+  }
+}
+
 /*!
   Changes visibility of trihedron to opposite
 */
@@ -804,11 +1283,16 @@ void OCCViewer_Viewer::setTrihedronShown( const bool on )
     return;
 
   if ( on ) {
-    myAISContext->Display( myTrihedron );
-    myAISContext->Deactivate(myTrihedron);
+    myAISContext->Display( myTrihedron,
+                           0 /*wireframe*/,
+                           -1 /* selection mode */,
+                           Standard_True /* update viewer*/,
+                           Standard_False /* allow decomposition */,
+                           AIS_DS_Displayed /* display status */);
+    myAISContext->Deactivate( myTrihedron );
   }
   else {
-    myAISContext->Erase( myTrihedron );
+    myAISContext->Erase( myTrihedron , Standard_True );
   }
 }
 
@@ -874,6 +1358,27 @@ OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
   return new OCCViewer_ViewWindow(0,  this);
 }
 
+/*!
+  Sets using local selection state
+  \param theIsUseLocalSelection - state
+*/
+void OCCViewer_Viewer::setUseLocalSelection(bool theIsUseLocalSelection)
+{
+  myIsUseLocalSelection = theIsUseLocalSelection;
+}
+
+/* 
+ * Returns true if local context is opened or view model local state is set
+ */
+bool OCCViewer_Viewer::useLocalSelection() const
+{
+  if (myIsUseLocalSelection)
+    return true;
+
+  Handle(AIS_InteractiveContext) ic = getAISContext();
+  return !ic.IsNull() && ic->HasOpenedContext();
+}
+
 // obsolete  
 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
 {
@@ -956,7 +1461,13 @@ 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;
 
-  view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
+  Bnd_Box aBox = view3d->View()->MinMaxValues();
+  Xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
+  Ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
+  Zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
+  Xmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().X();
+  Ymax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Y();
+  Zmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Z();
 
   if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
        Xmax != RealLast()  && Ymax != RealLast()  && Zmax != RealLast() )
@@ -1012,18 +1523,16 @@ Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& theP
   aGraphic3dPlane->SetOn( theIsOn );
   aGraphic3dPlane->SetCapping( Standard_True );
 
-  // load capping texture
-  QPixmap px( ":images/hatch.png" );
-  if( !px.isNull() ) {
-    const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
-    Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
-    if( aTexture->IsDone() ) {
-      aTexture->EnableModulate();
-      aTexture->EnableRepeat();
-      aTexture->GetParams()->SetScale( Graphic3d_Vec2( 0.01, 0.01 ) );
-      aGraphic3dPlane->SetCappingTexture( aTexture );
-    }
-  }
+  // set capping color
+  Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
+  aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
+                                            myClippingColor.blueF(), Quantity_TOC_RGB ) );
+  aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
+
+  // set capping texture
+  aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture,
+                                                           myTextureModulated, myClippingTextureScale ) );
+
   return aGraphic3dPlane;
 }
 /*!
@@ -1097,3 +1606,22 @@ void OCCViewer_Viewer::setClippingDlg(OCCViewer_ClippingDlg* theDlg) {
     myClippingDlg = theDlg;
   }
 }
+
+
+bool OCCViewer_Viewer::enableDrawMode( bool on )
+{
+  //!! To be done for view windows
+  if ( !myViewManager )
+    return false;
+
+  bool prev = false;
+  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 ) {
+      prev = prev || win->enableDrawMode( on ); 
+    }
+  }
+  return prev;
+}