Salome HOME
Typo-fix by Kunda
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
old mode 100644 (file)
new mode 100755 (executable)
index 3166ac2..6925d8d
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  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>
@@ -56,8 +59,6 @@
 #include <SUIT_ViewManager.h>
 #include <SUIT_ResourceMgr.h>
 
-#include <Basics_OCCTVersion.hxx>
-
 #include <SalomeApp_Study.h>
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -87,7 +88,6 @@
 #include <AIS_AngleDimension.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <Aspect_PolygonOffsetMode.hxx>
-#include <Aspect_ColorScale.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <StdSelect_TypeOfEdge.hxx>
@@ -99,7 +99,6 @@
 #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>
 #include <TopoDS.hxx>
 #include <NCollection_DataMap.hxx>
 #include <NCollection_Map.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
 
 #include <Prs3d_ShadingAspect.hxx>
 
@@ -167,7 +167,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;
   }
@@ -238,8 +238,11 @@ namespace
       if ( aAISShape.IsNull() )
         continue;
 
-#ifdef USE_TEXTURED_SHAPE
-      const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
+      const Handle(Graphic3d_TextureMap)& aTexture = aAISShape->Attributes()->ShadingAspect()->Aspect()->TextureMap();
+      if ( aTexture.IsNull() )
+        continue;
+
+      const Handle(Image_PixMap)& aPixmap = aTexture->GetImage();
       if ( aPixmap.IsNull() )
         continue;
 
@@ -254,7 +257,6 @@ namespace
         aPixmapUsersMap.UnBind( aPixmap );
         aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
       }
-#endif
     }
   }
 
@@ -460,6 +462,7 @@ static std::string getName( GEOM::GEOM_BaseObject_ptr object )
  */
 //=================================================================
 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
+  : myUpdateColorScale( true ), myIsRedisplayed( false )
 {
   if( st )
     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
@@ -496,14 +499,14 @@ 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;
 
@@ -630,6 +633,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();
@@ -659,6 +664,7 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
       }
     }
   }
+  myIsRedisplayed = aRedisplayed;
 }
 
 //=================================================================
@@ -678,8 +684,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 ));
+    }
+  }
 }
 
 //=================================================================
@@ -708,7 +729,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 );
     }
   }
@@ -836,11 +857,12 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   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 
-                            GetDisplayMode() :
-                            // display mode from properties
-                            propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
+  int displayMode = HasDisplayMode() ? 
+    // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
+    GetDisplayMode() :
+    // display mode from properties
+    propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
+  AISShape->SetDisplayMode( displayMode );
 
   // - face boundaries color and line width
   anAspect = AISShape->Attributes()->FaceBoundaryAspect();
@@ -921,7 +943,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
         
-        // Update propeties map
+        // Update properties map
         propMap = getObjectProperties( study, entry, myViewFrame );
       }
     }
@@ -930,7 +952,6 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
     aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
   }
 
-#ifdef USE_TEXTURED_SHAPE
   Handle(Image_PixMap) aPixmap;
   if ( !aImagePath.isEmpty() )
     aPixmap = cacheTextureFor( aImagePath, AISShape );
@@ -939,14 +960,12 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
 
   // apply image to shape
   if ( !aPixmap.IsNull() ) {
-    AISShape->SetTexturePixMap( aPixmap );
-    AISShape->SetTextureMapOn();
-    AISShape->DisableTextureModulate();
-  }
-  else {
-    AISShape->SetTextureMapOff();
+    AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) );
   }
-#endif
+  if ( displayMode == GEOM_AISShape::TexturedShape )
+    AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
+  else
+    AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
 
   // set line width
   AISShape->SetWidth( HasWidth() ?
@@ -984,9 +1003,9 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
       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 );
@@ -1653,7 +1672,7 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
 //=================================================================
 /*!
  *  GEOM_Displayer::BuildPrs
- *  Build presentation accordint to the current viewer type
+ *  Build presentation according to the current viewer type
  */
 //=================================================================
 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
@@ -1682,7 +1701,7 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
 //=================================================================
 /*!
  *  GEOM_Displayer::BuildPrs
- *  Build presentation accordint to the current viewer type
+ *  Build presentation according to the current viewer type
  */
 //=================================================================
 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
@@ -1771,7 +1790,8 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
 
                   if ( !GeomObject->_is_nil() )
                   {
-                    theIO->setName( GeomObject->GetName() );
+                    CORBA::String_var name = GeomObject->GetName();
+                    theIO->setName( name );
                     // finally set shape
                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
                   }
@@ -2038,14 +2058,26 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
     if ( !ic.IsNull() )
     {
       if ( ic->HasOpenedContext() )
-      ic->CloseAllContexts();
+      ic->CloseAllContexts(Standard_True);
     }
   }
 }
 
 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
 {
-  UpdateColorScale(false,false);
+  UpdateColorScale();
+
+  // 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 )
@@ -2057,7 +2089,16 @@ void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
 {
   LightApp_Displayer::AfterErase( v, p );
-  UpdateColorScale(false,false);
+  UpdateColorScale();
+
+  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 ));
+  }
 }
 
 //=================================================================
@@ -2555,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 ),
@@ -2914,7 +2955,7 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
     {
       QColor aQColor;
       Quantity_Color aColor;
-      if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
+      if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
       aResultList << aQColor;
     }
@@ -2922,187 +2963,91 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
   return aResultList;
 }
 
-// Note: the method is copied from Aspect_ColorScale class
-Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
-                                               const Standard_Integer aMin,
-                                               const Standard_Integer aMax )
-{
-  Standard_Integer minLimit( 0 ), maxLimit( 230 );
-
-  Standard_Integer aHue = maxLimit;
-  if ( aMin != aMax )
-    aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
-
-  aHue = Min( Max( minLimit, aHue ), maxLimit );
-
-  return aHue;
-}
-
-// Note: the method is copied from Aspect_ColorScale class
-Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
-                                            const Standard_Real aMin,
-                                            const Standard_Real aMax,
-                                            const Standard_Integer ColorsCount,
-                                            Quantity_Color& aColor )
-{
-  if( aValue<aMin || aValue>aMax || aMax<aMin )
-    return Standard_False;
-
-  else
-  {
-    Standard_Real IntervNumber = 0;
-    if( aValue<aMin )
-      IntervNumber = 0;
-    else if( aValue>aMax )
-      IntervNumber = ColorsCount-1;
-    else if( Abs( aMax-aMin ) > Precision::Approximation() )
-      IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
-
-    Standard_Integer Interv = Standard_Integer( IntervNumber );
-
-    aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
-
-    return Standard_True;
-  } 
-}
-
-void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
+void GEOM_Displayer::UpdateColorScale() 
 {
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
-  if( !aStudy )
-    return;
-
-  SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
-  if( !aViewModel )
+  if ( !myUpdateColorScale )
     return;
 
-  Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
-  if( aViewer.IsNull() )
-    return;
-
-  aViewer->InitActiveViews();
-  if( !aViewer->MoreActiveViews() )
-    return;
-
-  Handle(V3d_View) aView = aViewer->ActiveView();
-  if( aView.IsNull() )
-    return;
+  SUIT_Session* session = SUIT_Session::session();
+  SUIT_Application* app = session->activeApplication();
+  if ( !app ) return;
 
-  Standard_Boolean anIsDisplayColorScale = Standard_False;
-  TCollection_AsciiString aColorScaleTitle;
-  Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
-  Standard_Boolean anIsBoolean = Standard_False;
+  Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
 
-  SALOME_ListIO aSelectedObjects;
-  myApp->selectionMgr()->selectedObjects( aSelectedObjects );
-  if( aSelectedObjects.Extent() == 1 )
+  QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
+  foreach( SUIT_ViewWindow* window, windows )
   {
-    Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
-    if( !anIO.IsNull() )
+    OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
+    if ( !occWindow ) continue;
+    if ( !occWindow->getViewManager() ) continue;
+    if ( !window->getViewManager() ) continue;
+    if ( !window->getViewManager()->getViewModel() ) continue;
+    SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
+    if ( !view ) continue;
+    Handle(V3d_Viewer) viewer = view->getViewer3d();
+    if ( !io.IsNull() && view->isVisible( io ) )
     {
-      SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
-      if( aPrs )
+      bool visible = false;
+      SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
+      if ( prs )
       {
-        AIS_ListOfInteractive aList;
-        aPrs->GetObjects( aList );
-        AIS_ListIteratorOfListOfInteractive anIter( aList );
-        for( ; anIter.More(); anIter.Next() )
+        AIS_ListOfInteractive presentations;
+        prs->GetObjects( presentations );
+        AIS_ListIteratorOfListOfInteractive iter( presentations );
+        for ( ; iter.More(); iter.Next() )
         {
-          Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
-          if( !aShape.IsNull() )
+          Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
+          if ( shape.IsNull() ) continue;
+          GEOM::field_data_type fieldDataType;
+          int fieldDimension;
+          QList<QVariant> fieldStepData;
+          TCollection_AsciiString fieldStepName;
+          Standard_Real fieldStepRangeMin, fieldStepRangeMax;
+          shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
+                                   fieldStepName, fieldStepRangeMin,  fieldStepRangeMax );
+          visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
+          if ( visible )
           {
-            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;
-            }
-          }
+            SUIT_Session* session = SUIT_Session::session();
+            SUIT_ResourceMgr* resMgr = session->resourceMgr();
+            
+            Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
+            Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
+            Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
+            Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
+            Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
+            Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
+            
+            Standard_Integer viewWidth = 0, viewHeight = 0;
+            occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
+            
+            Handle(AIS_ColorScale) colorScale = view->getColorScale();
+            
+            colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
+            colorScale->SetBreadth( viewWidth * width );
+            colorScale->SetHeight( viewHeight * height );
+            colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
+            colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
+            colorScale->SetTextHeight( textHeight );
+            colorScale->SetTitle( fieldStepName );
+          } // if ( visible )
         }
       }
-    }
-  }
-
-  if( anIsDisplayColorScale )
-  {
-    Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
-    if( !aColorScale.IsNull() )
+      view->setColorScaleShown( visible );
+    } // if ( view->isVisible( io ) )
+    else
     {
-      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 );
+      view->setColorScaleShown( false );
     }
-    if( !aView->ColorScaleIsDisplayed() )
-      aView->ColorScaleDisplay();
-  }
-  else
-  {
-    if( aView->ColorScaleIsDisplayed() )
-      aView->ColorScaleErase();
-  }
+  } // foreach( SUIT_ViewWindow* window, windows )
+}
 
-  if( theIsRedisplayFieldSteps )
-  {
-    _PTR(Study) aStudyDS = aStudy->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() );
-        for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
-        {
-          _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
-          if( aSObj )
-          {
-            CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
-            if( !CORBA::is_nil( anObject ) )
-            {
-              GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
-              if( !aFieldStep->_is_nil() )
-              {
-                CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
-                Handle(SALOME_InteractiveObject) aStepIO =
-                  new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
-                Redisplay( aStepIO, false, false );
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-  if(updateViewer)
-    UpdateViewer();
+bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
+{
+  bool previous = myUpdateColorScale;
+  myUpdateColorScale = toUpdate;
+  if ( myUpdateColorScale && !previous )
+    UpdateColorScale();
+  return previous;
 }
+