Salome HOME
Merge branch 'master' into V9_dev
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
old mode 100644 (file)
new mode 100755 (executable)
index b13c932..5dfc366
@@ -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
@@ -25,7 +25,6 @@
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 
 #include "GEOM_Displayer.h"
-#include "GEOMGUI_DimensionProperty.h"
 #include "GeometryGUI.h"
 
 #include <GEOM_Constants.h>
 #include <GEOM_OCCFilter.h>
 
 #include <GEOM_Actor.h>
-#include <GEOM_AISShape.hxx>
 #include <GEOM_AISDimension.hxx>
+#include <GEOM_Annotation.hxx>
 #include <GEOM_TopWireframeShape.hxx>
 #include <GEOM_AISVector.hxx>
 #include <GEOM_AISTrihedron.hxx>
 #include <GEOM_VTKTrihedron.hxx>
 #include <GEOM_VTKPropertyMaterial.hxx>
 
+#include <GEOMGUI_DimensionProperty.h>
+#include <GEOMGUI_AnnotationAttrs.h>
+#include <GEOMGUI_AnnotationMgr.h>
+
 #include <GEOMUtils.hxx>
 
 #include <Material_Model.h>
 #include <LightApp_DataObject.h>
 #include <SalomeApp_TypeFilter.h>
 #include <SalomeApp_Tools.h>
+#include "utilities.h"
 
 #include <SALOME_ListIO.hxx>
 #include <SALOME_Prs.h>
+#include "utilities.h"
 
 #include <SOCC_Prs.h>
 #include <SOCC_ViewModel.h>
 #include <OCCViewer_Utilities.h>
 
 // OCCT Includes
-#include <AIS_Drawer.hxx>
 #include <AIS_Dimension.hxx>
 #include <AIS_LengthDimension.hxx>
 #include <AIS_DiameterDimension.hxx>
 #include <AIS_AngleDimension.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <Aspect_PolygonOffsetMode.hxx>
-#include <Aspect_ColorScale.hxx>
+#if OCC_VERSION_MAJOR < 7
+  #include <Aspect_ColorScale.hxx>
+#endif
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <StdSelect_TypeOfEdge.hxx>
 #include <Geom_Axis2Placement.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <gp_Pln.hxx>
-#include <TColStd_MapOfInteger.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
 
 // Hard-coded value of shape deflection coefficient for VTK viewer
 const double VTK_MIN_DEFLECTION = 0.001;
+// If the next macro is defined, the deflection coefficient for VTK presentation
+// is limited by VTK_MIN_DEFLECTION
+//#define LIMIT_DEFLECTION_FOR_VTK
 
 // Pixmap caching support
 namespace
@@ -163,7 +171,7 @@ namespace
     if ( aPixmap.IsNull() ) {
       QPixmap px(":images/default_texture.png");
       if ( !px.isNull() )
-       aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
+        aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
     }
     return aPixmap;
   }
@@ -455,15 +463,13 @@ static std::string getName( GEOM::GEOM_BaseObject_ptr object )
  *  Constructor
  */
 //=================================================================
-GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
+GEOM_Displayer::GEOM_Displayer()
+  : myUpdateColorScale(true), myIsRedisplayed( false )
 {
-  if( st )
-    myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
-  else
-    myApp = 0;
+  SUIT_Session* session = SUIT_Session::session();
+  myApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
 
   /* Shading Color */
-  SUIT_Session* session = SUIT_Session::session();
   SUIT_ResourceMgr* resMgr = session->resourceMgr();
 
   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
@@ -492,17 +498,24 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
   // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
   myToActivate = true;
 
-  // Activate parallel vizualisation only for testing purpose
-  // and if the corresponding env variable is set to 1
-  char* parallel_visu = getenv("PARALLEL_VISU");
-  if (parallel_visu && atoi(parallel_visu))
-  {
-    MESSAGE("Parallel visualisation on");
-    BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
-  }
+  // Activate parallel vizualisation by default.
+  // It can be switched OFF via the environment variable:
+  //     export PARALLEL_VISU=0
+  Standard_Boolean parallel_visu = Standard_True;
+  char* parallel_visu_env = getenv("PARALLEL_VISU");
+  if (parallel_visu_env && atoi(parallel_visu_env) == 0)
+    parallel_visu = Standard_False;
+  BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu);
 
   myViewFrame = 0;
 
+#if OCC_VERSION_MAJOR >= 7
+  myColorScale = new AIS_ColorScale;
+  myColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
+  myColorScale->SetTransformPersistence (
+    Graphic3d_TransformPers::FromDeprecatedParams(Graphic3d_TMF_2d, gp_Pnt (-1,-1,0)));
+#endif
+
   myFieldDataType = GEOM::FDT_Double;
   myFieldDimension = 0;
   myFieldStepRangeMin = 0;
@@ -626,6 +639,8 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
                                 const bool updateViewer,
                                 const bool checkActiveViewer )
 {
+  bool aRedisplayed = myIsRedisplayed;
+  myIsRedisplayed = true;
   // Remove the object permanently (<forced> == true)
   SUIT_Session* ses = SUIT_Session::session();
   SUIT_Application* app = ses->activeApplication();
@@ -655,6 +670,7 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
       }
     }
   }
+  myIsRedisplayed = aRedisplayed;
 }
 
 //=================================================================
@@ -674,8 +690,23 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
     return;
   }
 
+  bool aRedisplayed = myIsRedisplayed;
+  myIsRedisplayed = true;
   Erase( theIO, true, false, theViewFrame );
   Display( theIO, theUpdateViewer, theViewFrame );
+  myIsRedisplayed = aRedisplayed;
+  // hide annotations for erased presentation
+  SUIT_Session* session = SUIT_Session::session();
+  SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+  GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
+  if ( aModule ) {
+    if ( !theViewFrame->isVisible( theIO ) ) {
+      aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
+    }
+    else {
+      aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
+    }
+  }
 }
 
 //=================================================================
@@ -704,7 +735,7 @@ void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool
     QString entry = p->GetEntry();
     if ( !entry.isEmpty() ) {
       if ( vId != -1 )
-       aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
+        aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
       setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
     }
   }
@@ -769,7 +800,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
 
   // get presentation properties
-  PropMap propMap = getObjectProperties( study, entry, myViewFrame );
+  PropMap propMap = getObjectProperties( entry, myViewFrame );
 
   // Temporary staff: vertex must be infinite for correct visualization
   AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
@@ -828,6 +859,9 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   // - color for edges in shading+edges mode
   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
 
+  // - color of labels (textual fields and shape name)
+  AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
+
   // set display mode
   AISShape->SetDisplayMode( HasDisplayMode() ? 
                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
@@ -835,11 +869,10 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
                             // display mode from properties
                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
 
-  // - face boundaries color
-  if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
-    AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
+  // - face boundaries color and line width
   anAspect = AISShape->Attributes()->FaceBoundaryAspect();
   anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
+  anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
   AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
 
   // set display vectors flag
@@ -849,6 +882,10 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
   AISShape->SetDisplayVertices( isVerticesMode );
 
+  // set display name flag
+  bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
+  AISShape->SetDisplayName( isNameMode );
+
   // set transparency
   if( HasTransparency() ) {
     AISShape->SetTransparency( GetTransparency() );
@@ -905,14 +942,14 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
     aImagePath = GetTexture().c_str();
     if ( ! entry.isEmpty() ) {
       // check that study is active
-      SalomeApp_Study* study = getActiveStudy();
+      SalomeApp_Study* study = getStudy();
       if ( study ) {
         // Store the texture in object properties for next displays
         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
         
         // Update propeties map
-        propMap = getObjectProperties( study, entry, myViewFrame );
+        propMap = getObjectProperties( entry, myViewFrame );
       }
     }
   }
@@ -970,13 +1007,13 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
       int textureId = aList[0].toInt();
       Standard_Integer aWidth, aHeight;
       Handle(TColStd_HArray1OfByte) aTexture =
-        GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
+        GeometryGUI::getTexture( textureId, aWidth, aHeight );
       if ( !aTexture.IsNull() ) {
         Handle(Prs3d_PointAspect) aTextureAspect =
           new Prs3d_PointAspect( HasColor() ? 
-                                // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
-                                (Quantity_NameOfColor)GetColor() : 
-                                // color from properties 
+                                 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
+                                 (Quantity_NameOfColor)GetColor() : 
+                                 // color from properties 
                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
                                  aWidth, aHeight,
                                  aTexture );
@@ -1033,7 +1070,7 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
 
   // get presentation properties
-  PropMap propMap = getObjectProperties( study, entry, myViewFrame );
+  PropMap propMap = getObjectProperties( entry, myViewFrame );
   QColor c;
 
   /////////////////////////////////////////////////////////////////////////
@@ -1042,7 +1079,11 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
   /////////////////////////////////////////////////////////////////////////
   if ( !actor->getTopo().IsSame( myShape ) )
+#ifdef LIMIT_DEFLECTION_FOR_VTK
     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
+#else
+    actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
+#endif
 
   // set material
   Material_Model material;
@@ -1113,6 +1154,10 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
 
+  // - color of labels (shape name)
+  c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
+  actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
+
   // set opacity
   if( HasTransparency() ) {
     actor->SetOpacity( 1.0 - GetTransparency() );
@@ -1133,6 +1178,9 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   // set display vertices flag
   actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
 
+  // set display name flag
+  actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
+
   // set display mode
   int displayMode = HasDisplayMode() ? 
     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
@@ -1213,11 +1261,12 @@ void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& t
 
   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
-  double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
+  QFont   aFont         = aResMgr->fontValue   ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
+  bool    aUseText3d    = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
 
   // restore dimension presentation from saved attribute or property data
   AIS_ListOfInteractive aRestoredDimensions;
@@ -1235,7 +1284,7 @@ void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& t
   }
   else
   {
-    aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
+    aRecords.LoadFromAttribute( theIO->getEntry() );
   }
   
   // create up-to-date dimension presentations
@@ -1283,10 +1332,12 @@ void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& t
 
     aStyle->SetCommonColor( aColor );
     aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
-    aStyle->MakeText3d( Standard_True );
+    aStyle->MakeText3d( aUseText3d );
     aStyle->MakeTextShaded( Standard_True );
-    aStyle->SetExtensionSize( aFontHeight * 0.5 );
-    aStyle->TextAspect()->SetHeight( aFontHeight );
+    int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
+    aStyle->SetExtensionSize( fsize * 0.5 );
+    aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
+    aStyle->TextAspect()->SetHeight( fsize );
     aStyle->ArrowAspect()->SetLength( anArrowLength );
     aStyle->LineAspect()->SetWidth( aLineWidth );
     aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
@@ -1708,48 +1759,43 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
         // set interactive object
         setIO( theIO );
         //  Find SOBject (because shape should be published previously)
-        SUIT_Session* session = SUIT_Session::session();
-        SUIT_Application* app = session->activeApplication();
-        if ( app )
+        if ( getStudy() )
         {
-          SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-          if ( study )
+          _PTR(SObject) SO ( getStudy()->studyDS()->FindObjectID( theIO->getEntry() ) );
+          if ( SO )
           {
-            _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
-            if ( SO )
+            // get CORBA reference to data object
+            CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
+            if ( !CORBA::is_nil( object ) )
             {
-              // get CORBA reference to data object
-              CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
-              if ( !CORBA::is_nil( object ) )
+              // downcast to GEOM base object
+              GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
+              if ( !GeomBaseObject->_is_nil() )
               {
-                // downcast to GEOM base object
-                GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
-                if ( !GeomBaseObject->_is_nil() )
-                {
-                  myType = GeomBaseObject->GetType();
+                myType = GeomBaseObject->GetType();
 
-                  // downcast to GEOM object
-                  GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
-                  if ( myType == GEOM_FIELD_STEP )
+                // downcast to GEOM object
+                GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
+                if ( myType == GEOM_FIELD_STEP )
+                {
+                  // get the GEOM object from the field's shape
+                  GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
+                  if ( !GeomFieldStep->_is_nil() )
                   {
-                    // get the GEOM object from the field's shape
-                    GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
-                    if ( !GeomFieldStep->_is_nil() )
-                    {
-                      GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
-                      if ( !GeomField->_is_nil() )
-                        GeomObject = GeomField->GetShape();
-                    }
-
-                    // read the field step information
-                    readFieldStepInfo( GeomFieldStep );
+                    GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
+                    if ( !GeomField->_is_nil() )
+                      GeomObject = GeomField->GetShape();
                   }
 
-                  if ( !GeomObject->_is_nil() )
-                  {
-                    // finally set shape
-                    setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
-                  }
+                  // read the field step information
+                  readFieldStepInfo( GeomFieldStep );
+                }
+
+                if ( !GeomObject->_is_nil() )
+                {
+                  theIO->setName( GeomObject->GetName() );
+                  // finally set shape
+                  setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
                 }
               }
             }
@@ -1827,7 +1873,7 @@ void GEOM_Displayer::internalReset()
  *  of their sub-shapes (with opened local context for OCC viewer)
  */
 //=================================================================
-void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
+void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
 {
   SUIT_Session* session = SUIT_Session::session();
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
@@ -1844,11 +1890,25 @@ void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& the
     if (!theIO.IsNull() && !vf->isVisible(theIO))
       Display(theIO);
     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
-    vf->LocalSelection( prs, theMode );
+    vf->LocalSelection( prs, modes );
     delete prs;  // delete presentation because displayer is its owner
   }
 }
 
+//=================================================================
+/*!
+ *  GEOM_Displayer::LocalSelection
+ *  Activate selection of CAD shapes with activisation of selection
+ *  of their sub-shapes (with opened local context for OCC viewer)
+ */
+//=================================================================
+void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
+{
+  std::list<int> modes;
+  modes.push_back( theMode );
+  LocalSelection( theIO, modes );
+}
+
 //=================================================================
 /*!
  *  GEOM_Displayer::globalSelection
@@ -1962,11 +2022,25 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
  *  of their sub-shapes (with opened local context for OCC viewer)
  */
 //=================================================================
-void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
+void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
 {
   SALOME_ListIteratorOfListIO Iter( theIOList );
   for ( ; Iter.More(); Iter.Next() )
-    LocalSelection( Iter.Value(), theMode );
+    LocalSelection( Iter.Value(), modes );
+}
+
+//=================================================================
+/*!
+ *  GEOM_Displayer::LocalSelection
+ *  Activate selection of CAD shapes with activisation of selection
+ *  of their sub-shapes (with opened local context for OCC viewer)
+ */
+//=================================================================
+void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
+{
+  std::list<int> modes;
+  modes.push_back( theMode );
+  LocalSelection( theIOList, modes );
 }
 
 //=================================================================
@@ -1985,7 +2059,7 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
     if ( !ic.IsNull() )
     {
       if ( ic->HasOpenedContext() )
-      ic->CloseAllContexts();
+      ic->CloseAllContexts(Standard_True);
     }
   }
 }
@@ -1993,6 +2067,18 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
 {
   UpdateColorScale(false,false);
+
+  // visualize annotations for displayed presentation
+  SUIT_Session* session = SUIT_Session::session();
+  SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+  GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
+  if ( aModule ) {
+    if ( !myIsRedisplayed ) {
+      aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
+    } else {
+      aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
+    }
+  }
 }
 
 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
@@ -2005,6 +2091,15 @@ void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
 {
   LightApp_Displayer::AfterErase( v, p );
   UpdateColorScale(false,false);
+
+  if ( !myIsRedisplayed ) {
+    // hide annotations for erased presentation
+    SUIT_Session* session = SUIT_Session::session();
+    SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+    GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
+    if ( aModule )
+      aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
+  }
 }
 
 //=================================================================
@@ -2400,21 +2495,20 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& th
   return aSColor;
 }
 
-PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
-                                             const QString& entry,
+PropMap GEOM_Displayer::getObjectProperties( const QString& entry,
                                              SALOME_View* view )
 {
   // get default properties for the explicitly specified default view type
   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
 
-  if ( study && view ) {
+  if ( getStudy() && view ) {
     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
   
     if ( viewModel && viewId != -1 ) {
       // get properties from the study
-      PropMap storedMap = study->getObjectProperties( viewId, entry );
+      PropMap storedMap = getStudy()->getObjectProperties( viewId, entry );
       // overwrite default properties from stored ones (that are specified)
       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
@@ -2434,7 +2528,7 @@ PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
 
       if ( !entry.isEmpty() ) {
         // get CORBA reference to geom object
-        _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
+        _PTR(SObject) SO( getStudy()->studyDS()->FindObjectID( entry.toStdString() ) );
         if ( SO ) {
           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
           if ( !CORBA::is_nil( object ) ) {
@@ -2502,7 +2596,7 @@ PropMap GEOM_Displayer::getDefaultPropertyMap()
 
   // - transparency (opacity = 1-transparency)
   propMap.insert( GEOM::propertyName( GEOM::Transparency ),
-                 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
+                  resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
 
   // - display mode (take default value from preferences)
   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
@@ -2514,6 +2608,9 @@ PropMap GEOM_Displayer::getDefaultPropertyMap()
   // - show vertices flag (false by default)
   propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
 
+  // - show name flag (false by default)
+  propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
+
   // - shading color (take default value from preferences)
   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
@@ -2629,16 +2726,9 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo
 
 
 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
-                                       const bool eraseOnlyChildren) {
-  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( !app )
-    return;
-
-  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-  if ( !appStudy )
-    return;
-
-  LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
+                                       const bool eraseOnlyChildren)
+{
+  LightApp_DataObject* parent = getStudy()->findObjectByEntry(theIO->getEntry());
 
   if( !parent)
     return;
@@ -2646,7 +2736,7 @@ void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& t
   // Erase from all views
   QList<SALOME_View*> views;
   SALOME_View* view;
-  ViewManagerList vmans = app->viewManagers();
+  ViewManagerList vmans = myApp->viewManagers();
   SUIT_ViewManager* vman;
   foreach ( vman, vmans ) {
     SUIT_ViewModel* vmod = vman->getViewModel();
@@ -2858,7 +2948,11 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
     {
       QColor aQColor;
       Quantity_Color aColor;
+#if OCC_VERSION_MAJOR < 7
       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
+#else
+      if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
+#endif
         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
       aResultList << aQColor;
     }
@@ -2866,6 +2960,7 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
   return aResultList;
 }
 
+#if OCC_VERSION_MAJOR < 7
 // Note: the method is copied from Aspect_ColorScale class
 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
                                                const Standard_Integer aMin,
@@ -2909,13 +3004,10 @@ Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
     return Standard_True;
   } 
 }
+#endif
 
 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
 {
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
-  if( !aStudy )
-    return;
-
   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
   if( !aViewModel )
     return;
@@ -2937,43 +3029,41 @@ void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, cons
   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
   Standard_Boolean anIsBoolean = Standard_False;
 
-  SALOME_ListIO aSelectedObjects;
-  myApp->selectionMgr()->selectedObjects( aSelectedObjects );
-  if( aSelectedObjects.Extent() == 1 )
+  Handle(SALOME_InteractiveObject) anIO;
+  if ( myUpdateColorScale )
+    anIO = myApp->selectionMgr()->soleSelectedObject();
+
+  if( !anIO.IsNull() )
   {
-    Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
-    if( !anIO.IsNull() )
+    SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
+    if( aPrs )
     {
-      SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
-      if( aPrs )
+      AIS_ListOfInteractive aList;
+      aPrs->GetObjects( aList );
+      AIS_ListIteratorOfListOfInteractive anIter( aList );
+      for( ; anIter.More(); anIter.Next() )
       {
-        AIS_ListOfInteractive aList;
-        aPrs->GetObjects( aList );
-        AIS_ListIteratorOfListOfInteractive anIter( aList );
-        for( ; anIter.More(); anIter.Next() )
+        Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
+        if( !aShape.IsNull() )
         {
-          Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
-          if( !aShape.IsNull() )
+          GEOM::field_data_type aFieldDataType;
+          int aFieldDimension;
+          QList<QVariant> aFieldStepData;
+          TCollection_AsciiString aFieldStepName;
+          double aFieldStepRangeMin, aFieldStepRangeMax;
+          aShape->getFieldStepInfo( aFieldDataType,
+                                    aFieldDimension,
+                                    aFieldStepData,
+                                    aFieldStepName,
+                                    aFieldStepRangeMin,
+                                    aFieldStepRangeMax );
+          if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
           {
-            GEOM::field_data_type aFieldDataType;
-            int aFieldDimension;
-            QList<QVariant> aFieldStepData;
-            TCollection_AsciiString aFieldStepName;
-            double aFieldStepRangeMin, aFieldStepRangeMax;
-            aShape->getFieldStepInfo( aFieldDataType,
-                                      aFieldDimension,
-                                      aFieldStepData,
-                                      aFieldStepName,
-                                      aFieldStepRangeMin,
-                                      aFieldStepRangeMax );
-            if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
-            {
-              anIsDisplayColorScale = Standard_True;
-              aColorScaleTitle = aFieldStepName;
-              aColorScaleMin = aFieldStepRangeMin;
-              aColorScaleMax = aFieldStepRangeMax;
-              anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
-            }
+            anIsDisplayColorScale = Standard_True;
+            aColorScaleTitle = aFieldStepName;
+            aColorScaleMin = aFieldStepRangeMin;
+            aColorScaleMax = aFieldStepRangeMax;
+            anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
           }
         }
       }
@@ -2982,49 +3072,67 @@ void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, cons
 
   if( anIsDisplayColorScale )
   {
-    Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
-    if( !aColorScale.IsNull() )
+    SUIT_Session* session = SUIT_Session::session();
+    SUIT_ResourceMgr* resMgr = session->resourceMgr();
+
+    Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
+    Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
+    Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
+    Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
+    Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
+    Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
+
+#if OCC_VERSION_MAJOR < 7
+    Handle(Aspect_ColorScale) myColorScale = aView->ColorScale();
+    if( !myColorScale.IsNull() )
     {
-      SUIT_Session* session = SUIT_Session::session();
-      SUIT_ResourceMgr* resMgr = session->resourceMgr();
-
-      Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
-      Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
-      Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
-      Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
-      Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
-      Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
-      aColorScale->SetXPosition( anXPos );
-      aColorScale->SetYPosition( anYPos );
-      aColorScale->SetWidth( aWidth );
-      aColorScale->SetHeight( aHeight );
-
-      aColorScale->SetTextHeight( aTextHeight );
-      aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
-
-      aColorScale->SetTitle( aColorScaleTitle );
-      aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
+      myColorScale->SetXPosition( anXPos );
+      myColorScale->SetYPosition( anYPos );
+      myColorScale->SetWidth( aWidth );
+      myColorScale->SetHeight( aHeight );
+#else
+      Standard_Integer aWinWidth = 0, aWinHeight = 0;
+      aView->Window()->Size (aWinWidth, aWinHeight);
+
+      myColorScale->SetPosition (aWinWidth*anXPos, aWinHeight*anYPos);
+      //myColorScale->SetBreadth (aWinWidth); // ???
+      myColorScale->SetBreadth (aWinWidth*aWidth); // ???
+      myColorScale->SetHeight  (aWinHeight*aHeight);
+#endif
+
+      myColorScale->SetRange( aColorScaleMin, aColorScaleMax );
+      myColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
+
+      myColorScale->SetTextHeight( aTextHeight );
+      myColorScale->SetTitle( aColorScaleTitle );
+
+#if OCC_VERSION_MAJOR < 7
     }
     if( !aView->ColorScaleIsDisplayed() )
       aView->ColorScaleDisplay();
   }
   else
-  {
     if( aView->ColorScaleIsDisplayed() )
       aView->ColorScaleErase();
+#else
+    if( !aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
+      aViewModel->getAISContext()->Display( myColorScale, Standard_True);
   }
+  else
+    if( aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
+      aViewModel->getAISContext()->Erase( myColorScale, Standard_True );
+#endif
 
   if( theIsRedisplayFieldSteps )
   {
-    _PTR(Study) aStudyDS = aStudy->studyDS();
+    _PTR(Study) aStudyDS = getStudy()->studyDS();
     QList<SUIT_ViewManager*> vmList;
     myApp->viewManagers( vmList );
     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
     {
       if( SUIT_ViewManager* aViewManager = *vmIt )
       {
-        const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
+        const ObjMap& anObjects = getStudy()->getObjectProperties( aViewManager->getGlobalId() );
         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
         {
           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );