Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI.cxx
index c404df7fe2be89615cdf7dc253196c0c94bfdd1e..3128e69f768cb59652dfe3761370166d33ebc732 100644 (file)
@@ -22,7 +22,7 @@
 //
 //
 //  File   : VisuGUI.cxx
-//  Author : Laurent CORNABE
+//  Author :
 //  Module : VISU
 //  $Header$
 
 #include <qptrlist.h>
 #include <qptrvector.h>
 #include <qcolordialog.h>
+#include <qdatetime.h>
 
 // VTK Includes
 #include <vtkRenderer.h>
 #include <vtkRenderWindow.h>
 #include <vtkActorCollection.h>
+#include <vtkTimerLog.h>
 
 // SALOME Includes
 #include "SALOME_LifeCycleCORBA.hxx"
@@ -54,7 +56,6 @@
 
 #include "CAM_Module.h"
 
-#include "SVTK_RenderWindow.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_Functor.h"
@@ -62,6 +63,7 @@
 #include "SPlot2d_ViewModel.h"
 #include "VisuGUI_SetupPlot2dDlg.h"
 #include "Plot2d_SetupCurveDlg.h"
+#include "Plot2d_ViewManager.h"
 
 #include "OB_Browser.h"
 
 #include "VisuGUI_Selection.h"
 #include "VisuGUI_TimeAnimation.h"
 #include "VisuGUI_EditContainerDlg.h"
-#include "VisuGUI_NonIsometricDlg.h"
 #include "VisuGUI_ClippingDlg.h"
 #include "VisuGUI_Plot3DDlg.h"
-#include "VisuGUI_CubeAxesDlg.h"
 #include "VisuGUI_OffsetDlg.h"
 #include "VisuGUI_Displayer.h"
+#include "VisuGUI_BuildProgressDlg.h"
+#include "VisuGUI_TransparencyDlg.h"
 
 #include "VISU_ScalarMap_i.hh"
 #include "VisuGUI_ScalarBarDlg.h"
 #include "VISU_DeformedShape_i.hh"
 #include "VisuGUI_DeformedShapeDlg.h"
 
+#include "VISU_ScalarMapOnDeformedShape_i.hh"
+#include "VisuGUI_ScalarMapOnDeformedShapeDlg.h"
+
 #include "VISU_IsoSurfaces_i.hh"
 #include "VisuGUI_IsoSurfacesDlg.h"
 
 
 #include "VisuGUI_ActionsDef.h"
 
+#include "VisuGUI_Timer.h"
+
 using namespace VISU;
 
 #ifdef _DEBUG_
@@ -158,59 +165,17 @@ VisuGUI::~VisuGUI()
 {
 }
 
-
 void
 VisuGUI::
 OnImportFromFile()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnImportFromFile()");
-  if ( CheckLock(GetCStudy(GetAppStudy(this))) )
+  if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) )
     return;
-  SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
-
-  QStringList aFilter;
-  aFilter.append( tr("FLT_MED_FILES") );
-  aFilter.append( tr("FLT_ALL_FILES") );
-
-  QFileInfo aFileInfo =
-    SUIT_FileDlg::getFileName(GetDesktop(this),
-                              "",
-                              aFilter,
-                              tr("MEN_IMPORT_FROM_FILE"),
-                              true);
-  if(aFileInfo.exists()) {
-    application()->putInfo( "Importing From File " + aFileInfo.filePath() + "..." );
-
-    VISU::Result_var aResult;
-    bool anIsBuild = aResourceMgr->booleanValue("VISU", "full_med_loading", false);
-    if (VisuGUI_FileDlg::IsBuild) {
-      aResult = GetVisuGen(this)->ImportFile(aFileInfo.filePath());
-      if (!CORBA::is_nil(aResult.in()))
-        if (Result_i* aRes = dynamic_cast<Result_i*>(GetServant(aResult).in())) {
-          if (!aRes->IsPossible())
-            SUIT_MessageBox::warn1(GetDesktop(this),
-                                   tr("WRN_VISU"),
-                                   tr("ERR_CANT_BUILD_PRESENTATION"),
-                                   tr("BUT_OK"));
-          else
-            aRes->BuildAll();
-        }
-    } else {
-      aResourceMgr->setValue("VISU", "full_med_loading", false);
-      aResult = GetVisuGen(this)->ImportFile(aFileInfo.filePath());
-      aResourceMgr->setValue("VISU", "full_med_loading", anIsBuild);
-    }
 
-    if (CORBA::is_nil(aResult.in())) {
-      SUIT_MessageBox::warn1(GetDesktop(this),
-                             tr("WRN_VISU"),
-                             tr("ERR_ERROR_IN_THE_FILE"),
-                             tr("BUT_OK"));
-    }else{
-      application()->putInfo(aFileInfo.filePath() + tr("INF_DONE"));
-      UpdateObjBrowser(this);
-    }
-  }
+  VisuGUI_BuildProgressDlg* aBuildProgressDlg = new VisuGUI_BuildProgressDlg( GetDesktop(this) );
+  aBuildProgressDlg->setGenerator( GetVisuGen(this) );
+  aBuildProgressDlg->show();
 }
 
 
@@ -220,7 +185,7 @@ OnExploreMEDFile()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnExploreMEDFile()");
   _PTR(Study) aStudy = GetCStudy(GetAppStudy(this));
-  if ( CheckLock(aStudy) )
+  if ( CheckLock(aStudy,GetDesktop(this)) )
     return;
 
   SALOME_MED::MED_Gen_var aGen = GetMEDEngine();
@@ -261,7 +226,7 @@ VisuGUI::
 OnImportTableFromFile()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnImportTableFromFile()");
-  if ( CheckLock(GetCStudy(GetAppStudy(this))) )
+  if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) )
     return;
 
   QStringList aFilter;
@@ -376,11 +341,11 @@ OnExportTableToFile()
        try {
          GetVisuGen(this)->ExportTableToFile(GetSObject(aSObj), aFile.latin1());
           application()->putInfo(aFile + " " + tr("INF_DONE"));
-       } catch(std::exception& ex) {
-         INFOS(ex.what());
+       } catch(std::exception& exc) {
+         INFOS(exc.what());
          SUIT_MessageBox::warn1(GetDesktop(this),
                                  tr("WRN_VISU"),
-                                tr("ERR_ERROR_DURING_EXPORT") + " " + tr(ex.what()),
+                                tr("ERR_ERROR_DURING_EXPORT") + " " + tr(exc.what()),
                                 tr("BUT_OK"));
        } catch(...) {
          INFOS(tr("ERR_ERROR_DURING_EXPORT"));
@@ -399,7 +364,7 @@ VisuGUI::
 OnImportMedField()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
   SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
 
@@ -460,7 +425,8 @@ CreateCurves( SalomeApp_Module* theModule,
       if ( aTblObj ) {
         _PTR(GenericAttribute) anAttr;
         if (aTblObj->FindAttribute( anAttr, "AttributeName" ) ) {
-          aBuilder->RemoveObjectWithChildren( aIter->Value() ); // We should have only one child
+          aBuilder->RemoveObjectWithChildren( aTblObj ); // We should have only one child
+         UpdateObjBrowser(theModule,true,aTblObj);
           break;
         }
       }
@@ -496,7 +462,7 @@ VisuGUI::
 OnCreateMesh()
 {
   _PTR(Study) aStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aStudy))
+  if (CheckLock(aStudy,GetDesktop(this)))
     return;
 
   // Get selected SObject
@@ -516,7 +482,7 @@ VisuGUI::
 OnCreateManyMesh()
 {
   _PTR(Study) aStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aStudy))
+  if (CheckLock(aStudy,GetDesktop(this)))
     return;
 
   // create a VTK view window if it does not exist
@@ -551,6 +517,13 @@ OnCreateDeformedShape()
   CreatePrs3d<VISU::DeformedShape_i,VisuGUI_DeformedShapeDlg,1>(this);
 }
 
+void
+VisuGUI::
+OnCreateScalarMapOnDeformedShape()
+{
+  CreatePrs3d<VISU::ScalarMapOnDeformedShape_i,VisuGUI_ScalarMapOnDeformedShapeDlg,1>(this);
+}
+
 void
 VisuGUI::
 OnCreateVectors()
@@ -597,7 +570,7 @@ void
 VisuGUI::
 OnCreatePlot2dView()
 {
-  CheckLock(GetCStudy(GetAppStudy(this)));
+  CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this));
   GetVisuGen( this )->CreateContainer();
   UpdateObjBrowser(this);
 }
@@ -609,9 +582,11 @@ OnDisplayPrs()
   if(MYDEBUG) MESSAGE("VisuGUI::OnDisplayPrs");
 
   QApplication::setOverrideCursor(Qt::waitCursor);
-  SALOME_ListIO aList;
+  SALOME_ListIO aSel, aList;
   LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects(aList);
+  mgr->selectedObjects( aSel );
+
+  extractContainers( aSel, aList );
 
   Handle(SALOME_InteractiveObject) anIO;
   for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
@@ -622,10 +597,12 @@ OnDisplayPrs()
       VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject).in());
       if(aPrsObject){
         if(MYDEBUG) MESSAGE("VisuGUI::OnDisplayPrs : Prs3d object");
-        UpdateViewer( this, aPrsObject );
+        //UpdateViewer( this, aPrsObject );
        SVTK_ViewWindow* vw = GetViewWindow( this, /*create=*/true );
-        if ( vw ) {
-          vw->highlight(anIO, 1);
+        if ( vw )
+       {
+         displayer()->Display( anIO->getEntry() );
+         vw->highlight(anIO, 1);
         }
         continue;
       }
@@ -633,21 +610,24 @@ OnDisplayPrs()
       VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject).in());
       if(aCurve){
         if(MYDEBUG) MESSAGE("VisuGUI::OnDisplayPrs : Curve object");
-        PlotCurve( this, aCurve, VISU::eDisplay );
+        //PlotCurve( this, aCurve, VISU::eDisplay );
+       displayer()->Display( anIO->getEntry() );
         continue;
       }
       // is it Container ?
       VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject).in());
       if(aContainer){
         if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Container object");
-        PlotContainer( this, aContainer, VISU::eDisplay );
+        //PlotContainer( this, aContainer, VISU::eDisplay );
+       displayer()->Display( anIO->getEntry() );
         continue;
       }
       // is it Table ?
       VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject).in());
       if(aTable){
         if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Table object");
-        PlotTable( this, aTable, VISU::eDisplay );
+        //PlotTable( this, aTable, VISU::eDisplay );
+       displayer()->Display( anIO->getEntry() );
         continue;
       }
     }
@@ -680,14 +660,18 @@ OnErasePrs()
   if (vw)
     vw->unHighlightAll();
 
-  SALOME_ListIO aList;
+  SALOME_ListIO aList, aSel;
   LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects(aList);
+  mgr->selectedObjects( aSel );
+
+  extractContainers( aSel, aList );
 
   Handle(SALOME_InteractiveObject) anIO;
   for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
     anIO = it.Value();
     CORBA::Object_var anObject = GetSelectedObj( GetAppStudy(this), anIO->getEntry() );
+    if (!CORBA::is_nil(anObject))
+      RemoveScalarBarPosition(this,anObject);
     ErasePrs( this, anObject, false );
   }
 
@@ -697,6 +681,30 @@ OnErasePrs()
   QApplication::restoreOverrideCursor();
 }
 
+void
+VisuGUI::
+OnEraseAll()
+{
+  startOperation( myEraseAll );
+  if (SVTK_ViewWindow* vw = GetViewWindow(this)) {
+    vw->unHighlightAll();
+    if (vtkRenderer *aRen = vw->getRenderer()) {
+      vtkActor *anActor;
+      vtkActorCollection *anActColl = aRen->GetActors();
+      for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ) {
+        if (anActor->GetVisibility() > 0)
+          if (VISU_Actor* anVISUActor = VISU_Actor::SafeDownCast(anActor)) {
+           RemoveScalarBarPosition(this,anVISUActor->GetPrs3d());
+            anVISUActor->VisibilityOff();
+          }
+      }
+      vw->Repaint();
+    }
+  } else if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(this, false)) {
+    aPlot2d->EraseAll();
+  }
+}
+
 
 void
 VisuGUI::
@@ -705,7 +713,7 @@ OnEditScalarMap()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::ScalarMap_i, VisuGUI_ScalarBarDlg,1>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
@@ -719,12 +727,24 @@ OnEditDeformedShape()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg,1>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
 }
 
+void
+VisuGUI::
+OnEditScalarMapOnDeformedShape()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
+    EditPrs3d<VISU::ScalarMapOnDeformedShape_i, VisuGUI_ScalarMapOnDeformedShapeDlg,1>(this, aPrs3d);
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+      aViewWindow->highlight(anIO, 1);
+    }
+  }
+}
 
 void
 VisuGUI::
@@ -733,7 +753,7 @@ OnEditCutPlanes()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::CutPlanes_i, VisuGUI_CutPlanesDlg,0>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
@@ -747,7 +767,7 @@ OnEditCutLines()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::CutLines_i, VisuGUI_CutLinesDlg,0>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
@@ -761,7 +781,7 @@ OnEditIsoSurfaces()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg,1>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
@@ -775,7 +795,7 @@ OnEditVectors()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::Vectors_i, VisuGUI_VectorsDlg,1>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
@@ -789,7 +809,7 @@ OnEditStreamLines()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::StreamLines_i, VisuGUI_StreamLinesDlg,1>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
@@ -803,36 +823,13 @@ OnEditPlot3D()
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
     EditPrs3d<VISU::Plot3D_i, VisuGUI_Plot3DDlg,0>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
+    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
       aViewWindow->highlight(anIO, 1);
     }
   }
 }
 
 
-void
-VisuGUI::
-OnEraseAll()
-{
-  if (SVTK_ViewWindow* vw = GetViewWindow()) {
-    vw->unHighlightAll();
-    if (vtkRenderer *aRen = vw->getRenderer()) {
-      vtkActor *anActor;
-      vtkActorCollection *anActColl = aRen->GetActors();
-      for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ) {
-        if (anActor->GetVisibility() > 0)
-          if (VISU_Actor* anVISUActor = VISU_Actor::SafeDownCast(anActor)) {
-            anVISUActor = anVISUActor->GetParent();
-            anVISUActor->VisibilityOff();
-          }
-      }
-      vw->Repaint();
-    }
-  } else if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(this, false)) {
-    aPlot2d->EraseAll();
-  }
-}
-
 void
 VisuGUI::
 OnMakeSurfaceframe()
@@ -902,7 +899,7 @@ OnChangeColor()
   VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrs3d) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetViewWindow(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrs3d, vw);
@@ -974,7 +971,7 @@ OnChangeWireframeColor()
   VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrs3d) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetViewWindow(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrs3d, vw);
@@ -1009,31 +1006,14 @@ OnChangeOpacity()
   VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetViewWindow(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrsObject, vw);
   if (!anActor) return;
 
-  VisuGUI_CursorDlg* CursorDlg =
-    new VisuGUI_CursorDlg (GetDesktop(this), tr("DLG_OPACITY_TITLE"), TRUE);
-
-  CursorDlg->Comment1->setText(tr("DLG_OPACITY_CMT1"));
-  CursorDlg->Comment2->setText(tr("DLG_OPACITY_CMT2"));
-  CursorDlg->SpinBox1->setMinValue(0);
-  CursorDlg->SpinBox1->setMaxValue(100);
-
-  float oldopac = anActor->GetOpacity();
-  int intopac = int(oldopac*100. + 0.5);
-  CursorDlg->SpinBox1->setValue(intopac);
-
-  int ret = CursorDlg->exec();
-  if (ret == 1) {
-    intopac = CursorDlg->SpinBox1->value();
-    float newopac = intopac/100.;
-    anActor->SetOpacity(newopac);
-  }
-  delete CursorDlg;
+  VisuGUI_TransparencyDlg* aTransparencyDlg = new VisuGUI_TransparencyDlg( this );
+  aTransparencyDlg->show();
 }
 
 void
@@ -1049,7 +1029,7 @@ OnChangeLines()
   VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetViewWindow(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrsObject, vw);
@@ -1131,7 +1111,7 @@ VisuGUI::
 OnDeleteObjects()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   SALOME_ListIO aList;
@@ -1158,14 +1138,12 @@ OnDeleteObjects()
     _PTR(SObject) aSObject = aCStudy->FindObjectID(entries[i]);
     if (aSObject) {
       DeleteSObject(this, aCStudy, aSObject);
+      UpdateObjBrowser(this, true, aSObject);
     }
   }
 
   // Finish transaction
   aStudyBuilder->CommitCommand();
-
-  //GetActiveStudy()->unHighlightAll();
-  UpdateObjBrowser(this, true);
 }
 
 void
@@ -1371,7 +1349,7 @@ VisuGUI::
 OnClearContainer()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
   Handle(SALOME_InteractiveObject) anIO;
   CORBA::Object_var anObject = GetSelectedObj(this, &anIO);
@@ -1419,7 +1397,7 @@ VisuGUI::
 OnSaveViewParams()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   SUIT_ViewManager* aViewMgr = getApp()->activeViewManager();
@@ -1467,7 +1445,7 @@ VisuGUI::
 OnRename()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   Handle(SALOME_InteractiveObject) anIO;
@@ -1533,6 +1511,20 @@ OnRename()
       // rename the study object
       aName->SetValue(Name.latin1()); // rename the SObject
       anIO->setName(Name.latin1()); // rename the InteractiveObject
+      
+      ViewManagerList pvm_list;
+      getApp()->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
+      for( SUIT_ViewManager* mgr = pvm_list.first(); mgr; mgr = pvm_list.next() )
+      {
+       Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( mgr );
+       if( pvm )
+       {
+         SPlot2d_Viewer* pv = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
+         if( pv )
+           pv->renameAll( anIO, Name.latin1() );
+       }
+      }
+
       UpdateObjBrowser(this, false);
 
       QApplication::restoreOverrideCursor();
@@ -1561,7 +1553,7 @@ OnSweep()
   VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetViewWindow(this);
   if (!vw) return;
 
   VISU_Actor* aActor = GetActor(aPrsObject, vw);
@@ -1588,7 +1580,7 @@ OnSweep()
         float aPercents = float(i)/aSteps;
         aPrsObject->SetMapScale(aPercents);
         aPrsObject->UpdateActor(aActor);
-        vw->getRenderWindow()->getRenderWindow()->Render();
+        vw->getRenderWindow()->Render();
         usleep(aTemp);
       } catch (std::exception& exc) {
         INFOS("Follow exception was occured :\n" << exc.what());
@@ -1604,9 +1596,11 @@ void
 VisuGUI::
 OnTimeAnimation()
 {
+  if(!VISU::GetViewWindow(this))
+    return;
+
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
   VisuGUI_TimeAnimationDlg* aAnimationDlg =
-//    new VisuGUI_TimeAnimationDlg(GetDesktop(this), aCStudy);
     new VisuGUI_TimeAnimationDlg (this, aCStudy);
 
   LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
@@ -1641,6 +1635,9 @@ void
 VisuGUI::
 OnShowAnimation()
 {
+  if(!VISU::GetViewWindow(this))
+    return;
+
   LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
@@ -1678,7 +1675,7 @@ VisuGUI::
 OnCopyPresentation()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   Handle(SALOME_InteractiveObject) anIO;
@@ -1715,6 +1712,14 @@ OnCopyPresentation()
       UpdateViewer(this, aSameDeformed);
     }
     break;
+  case VISU::TSCALARMAPONDEFORMEDSHAPE:
+    {
+      VISU::ScalarMapOnDeformedShape_i* aDefPrs = dynamic_cast<VISU::ScalarMapOnDeformedShape_i*>(aPrsObject);
+      VISU::ScalarMapOnDeformedShape_i* aSameScalarMapOnDeformed = new VISU::ScalarMapOnDeformedShape_i(aDefPrs->GetResult(),true);
+      aSameScalarMapOnDeformed->SameAs(aDefPrs);
+      UpdateViewer(this, aSameScalarMapOnDeformed);
+    }
+    break;
   case VISU::TCUTPLANES:
     {
       VISU::CutPlanes_i* aCutPrs = dynamic_cast<VISU::CutPlanes_i*>(aPrsObject);
@@ -1771,8 +1776,8 @@ void
 VisuGUI::
 OnSelectionInfo()
 {
-  if (GetViewWindow())
-    (new VisuGUI_SelectionDlg(GetDesktop(this)))->show();
+  if (GetViewWindow(this))
+    (new VisuGUI_SelectionDlg(this))->show();
   else
     SUIT_MessageBox::warn1(GetDesktop(this),
                            tr("WRN_VISU"),
@@ -1780,25 +1785,6 @@ OnSelectionInfo()
                            tr("BUT_OK") );
 }
 
-void
-VisuGUI::
-OnScaling()
-{
-  VisuGUI_NonIsometricDlg* m_NonIsoDlg =
-    new VisuGUI_NonIsometricDlg (GetDesktop(this), "m_NonIsoDlg",
-                                 false, Qt::WDestructiveClose);
-  m_NonIsoDlg->show();
-}
-
-void
-VisuGUI::
-OnCubeAxes()
-{
-  //Show dialog that allows to select scale function and corresponding scale factor
-  VisuGUI_CubeAxesDlg* aDlg = new VisuGUI_CubeAxesDlg (GetDesktop(this));
-  aDlg->show();
-}
-
 void
 VisuGUI::
 OnMergeScalarBars()
@@ -1940,7 +1926,7 @@ void
 VisuGUI::
 OnArrangeActors()
 {
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetViewWindow(this);
   if (vw) {
     ArrangeDlg* aDlg = new ArrangeDlg (GetDesktop(this), vw);
     aDlg->exec();
@@ -1992,6 +1978,11 @@ createActions()
                 tr("MEN_DEFORMED_SHAPE"), "", 0, aParent, false,
                 this, SLOT(OnCreateDeformedShape()));
 
+  aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_SCALAR_MAP_ON_DEFORMED_SHAPE"));
+  createAction( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE, tr("MEN_SCALAR_MAP_ON_DEFORMED_SHAPE"), QIconSet(aPixmap),
+                tr("MEN_SCALAR_MAP_ON_DEFORMED_SHAPE"), "", 0, aParent, false,
+                this, SLOT(OnCreateScalarMapOnDeformedShape()));
+
   aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_VECTORS"));
   createAction( VISU_VECTORS, tr("MEN_VECTORS"), QIconSet(aPixmap),
                 tr("MEN_VECTORS"), "", 0, aParent, false,
@@ -2217,6 +2208,10 @@ createActions()
                 tr("MEN_EDIT_PRS"), "", 0, aParent, false,
                 this, SLOT(OnEditPlot3D()));
 
+  createAction( VISU_EDIT_SCALARMAPONDEFORMEDSHAPE, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditScalarMapOnDeformedShape()));
+
 
   createAction( VISU_CREATE_TABLE, tr("MEN_CREATE_TABLE"), QIconSet(),
                 tr("MEN_CREATE_TABLE"), "", 0, aParent, false,
@@ -2257,16 +2252,6 @@ createActions()
                 //this, SLOT(OnEraseAll()));
                 this);
 
-  aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_SCALING"));
-  createAction( VISU_SCALING, tr("MEN_SCALING"), QIconSet(aPixmap),
-                tr("MEN_SCALING"), "", 0, aParent, false,
-                this, SLOT(OnScaling()));
-
-  aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_CUBE_AXES"));
-  createAction( VISU_CUBE_AXES, tr("MEN_CUBE_AXES"), QIconSet(aPixmap),
-                tr("MEN_CUBE_AXES"), "", 0, aParent, false,
-                this, SLOT(OnCubeAxes()));
-
   createAction( VISU_SHOW_ANIMATION, tr("MEN_SHOW_ANIMATION"), QIconSet(),
                 tr("MEN_SHOW_ANIMATION"), "", 0, aParent, false,
                 this, SLOT(OnShowAnimation()));
@@ -2293,6 +2278,7 @@ createMenus()
   createMenu( VISU_CUT_LINES, aMenuId, 10 ); // cut lines
   createMenu( VISU_STREAM_LINES, aMenuId, 10 ); // stream lines
   createMenu( VISU_PLOT_3D, aMenuId, 10 ); // Plot3d
+  createMenu( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE, aMenuId, 10 ); // scalar map on deformed shape
 
   aMenuId = createMenu( tr( "MEN_SELECTION" ), -1, -1, 30 );
   createMenu( VISU_SELECTION_INFO, aMenuId, 10 ); // selection info
@@ -2306,8 +2292,6 @@ createMenus()
   createMenu( VISU_ERASE_ALL, aMenuId, 10 ); // erase all
   createMenu( VISU_GLOBAL_SELECTION, aMenuId, 10 ); // global selection
   createMenu( VISU_PARTIAL_SELECTION, aMenuId, 10 ); // partial selection
-  createMenu( VISU_SCALING, aMenuId, 10 ); // scaling
-  createMenu( VISU_CUBE_AXES, aMenuId, 10 ); // scaling
 }
 
 void
@@ -2323,6 +2307,7 @@ createToolBars()
   createTool( VISU_CUT_LINES, aToolId );
   createTool( VISU_STREAM_LINES, aToolId );
   createTool( VISU_PLOT_3D, aToolId );
+  createTool( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE, aToolId );
 
   aToolId = createTool(tr("TOOL_REPRESENTATION"));
   createTool( VISU_POINTS, aToolId );
@@ -2331,8 +2316,6 @@ createToolBars()
   createTool( VISU_ERASE_ALL, aToolId );
   createTool( VISU_GLOBAL_SELECTION, aToolId );
   createTool( VISU_PARTIAL_SELECTION, aToolId );
-  createTool( VISU_SCALING, aToolId );
-  createTool( VISU_CUBE_AXES, aToolId );
 }
 
 void
@@ -2358,6 +2341,7 @@ createPopupMenus()
   mgr->insert( action( VISU_VECTORS ), -1, -1, -1 ); // vectors
   mgr->insert( action( VISU_STREAM_LINES ), -1, -1, -1 ); // stream lines
   mgr->insert( action( VISU_PLOT_3D ), -1, -1, -1 ); // Plot3d
+  mgr->insert( action( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE ), -1, -1, -1 ); // scalar map on deformed shape
 
   mgr->insert( action( VISU_CREATE_PRS ), -1, -1, -1 ); // create presentation
   mgr->insert( action( VISU_CREATE_MANY_PRS ), -1, -1, -1 ); // create presentations
@@ -2373,6 +2357,7 @@ createPopupMenus()
   mgr->insert( action( VISU_EDIT_VECTORS ), -1, -1, -1 );
   mgr->insert( action( VISU_EDIT_STREAMLINES ), -1, -1, -1 );
   mgr->insert( action( VISU_EDIT_PLOT3D ), -1, -1, -1 );
+  mgr->insert( action( VISU_EDIT_SCALARMAPONDEFORMEDSHAPE ), -1, -1, -1 );
   mgr->insert( action( VISU_EDIT_CONTAINER ), -1, -1, -1 );
 
   // rename
@@ -2445,7 +2430,7 @@ createPopupMenus()
   // Rules
 
   QString aPrsAll ("'VISU::TSCALARMAP' 'VISU::TISOSURFACE' 'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' "
-                   "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D'");
+                   "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE'");
 
   // VISU root commands
   QString aRule = "client='ObjectBrowser' and selcount=1 and type='VISU::TVISUGEN'";
@@ -2464,6 +2449,7 @@ createPopupMenus()
   mgr->setRule( action( VISU_DEFORMED_SHAPE ), aRule, true );
   mgr->setRule( action( VISU_VECTORS ), aRule, true );
   mgr->setRule( action( VISU_STREAM_LINES ), aRule, true );
+  mgr->setRule( action( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE ), aRule, true );
 
   // display/erase commands
   QString andInvisible = " and (((not isVisible) and isActiveView) or (not isActiveView))";
@@ -2472,16 +2458,17 @@ createPopupMenus()
   QString orCurveInvisible = "or (type='VISU::TCURVE'" + andInvisible + ")";
   QString aPrsVisible   = "(($type in {'VISU::TMESH' " + aPrsAll + "}) and isVisible)";
   QString aPrsInvisible = "(($type in {'VISU::TMESH' " + aPrsAll + "})" + andInvisible + ")";
+  QString aComponent = "( selcount=1 and canBeDisplayed and isComponent )";
 
-  QString anEraseRule = "selcount>0 and (" + aPrsVisible +
-    " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveVisible + ")))";
+  QString anEraseRule = "( selcount>0 and ({true} in $canBeDisplayed) and (" + aPrsVisible +
+    " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveVisible + "))) ) or " + aComponent;
 
-  QString aDisplayRule = "selcount>0 and (" + aPrsInvisible +
-    " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveInvisible + ")))";
+  QString aDisplayRule = "( selcount>0 and ({true} in $canBeDisplayed) and (" + aPrsInvisible +
+    " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveInvisible + "))) ) or" + aComponent;
 
-  QString aDOnlyRule = "selcount>0 and (($type in {'VISU::TMESH' " + aPrsAll + "})"
+  QString aDOnlyRule = "( selcount>0 and ({true} in $canBeDisplayed) and (($type in {'VISU::TMESH' " + aPrsAll + "})"
     " or (client='ObjectBrowser' and ((type='VISU::TTABLE' and nbChildren>0) or"
-    " ($type in {'VISU::TCURVE' 'VISU::TCONTAINER'}))))";
+    " ($type in {'VISU::TCURVE' 'VISU::TCONTAINER'})))) ) or" + aComponent;
 
   mgr->setRule( action( VISU_ERASE ), anEraseRule, true );
   mgr->setRule( action( VISU_DISPLAY ), aDisplayRule, true );
@@ -2495,10 +2482,10 @@ createPopupMenus()
   mgr->setRule( action( VISU_FREE_SCALAR_BARS ), aRule, true );
 
   // view parameters
-  aRule = "selcount=1 and type='VISU::TVIEW3D'";
+  aRule = "selcount=1 and type='VISU::TVIEW3D' and activeView='VTKViewer'";
   mgr->setRule( action( VISU_SAVE_VIEW_PARAMS_1 ), aRule, true );
-  mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "client='VTKViewer' and selcount=0", true );
-  mgr->setRule( action( VISU_RESTORE_VIEW_PARAMS ), "selcount=1 and type='VISU::TVIEW3D'", true );
+  mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "client='VTKViewer' and selcount=0 and activeView='VTKViewer'", true );
+  mgr->setRule( action( VISU_RESTORE_VIEW_PARAMS ), "selcount=1 and type='VISU::TVIEW3D' and activeView='VTKViewer'", true );
   //mgr->setRule( action( VISU_DELETE_VIEW_PARAMS ), "selcount=1 and type='VISU::TVIEW3D'", true );
 
   mgr->setRule( action( VISU_ARRANGE_ACTORS ), "client='VTKViewer' and selcount=0", true );
@@ -2508,9 +2495,9 @@ createPopupMenus()
   QString aInsideType = " and $type in {'VISU::TMESH' 'VISU::TSCALARMAP' 'VISU::TDEFORMEDSHAPE'}";
   QString aSurfType   = " and $type in {'VISU::TMESH'}";
   QString aShrinkType = " and $type in {'VISU::TMESH' 'VISU::TSCALARMAP' 'VISU::TISOSURFACE' "
-                        "'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TPLOT3D'}";
+                        "'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE'}";
   QString aLineType   = " and $type in {'VISU::TMESH' 'VISU::TSCALARMAP' 'VISU::TISOSURFACE' 'VISU::TDEFORMEDSHAPE' "
-                        "'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D'}";
+                        "'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE' }";
 
   aRule = "selcount=1";
   mgr->setRule( action( VISU_CLIPPING ), aRule + aPrsType, true );
@@ -2566,6 +2553,8 @@ createPopupMenus()
                "selcount=1 and type='VISU::TSCALARMAP'", true );
   mgr->setRule( action( VISU_EDIT_DEFORMEDSHAPE ),
                "selcount=1 and type='VISU::TDEFORMEDSHAPE'", true );
+  mgr->setRule( action( VISU_EDIT_SCALARMAPONDEFORMEDSHAPE ),
+               "selcount=1 and type='VISU::TSCALARMAPONDEFORMEDSHAPE'", true );
   mgr->setRule( action( VISU_EDIT_CUTPLANES ),
                "selcount=1 and type='VISU::TCUTPLANES'", true );
   mgr->setRule( action( VISU_EDIT_CUTLINES ),
@@ -2589,7 +2578,10 @@ createPopupMenus()
   aRule = "client='VTKViewer' and selcount=1" + aInsideType;
   mgr->setRule( action( VISU_SELECTION_INFO ), aRule, true );
 
-  aRule = "client='ObjectBrowser' and selcount>0 and $type in {'VISU::TFIELD'} and nbTimeStamps>1";
+  aRule = "client='ObjectBrowser' and selcount>0";
+  aRule += " and $type in {'VISU::TFIELD'}";
+  aRule += " and nbTimeStamps>1";
+  aRule += " and activeView in {'VTKViewer' 'VVTK'}";
   mgr->setRule( action( VISU_ANIMATION ), aRule, true );
 
   aRule = "client='ObjectBrowser' and $type in {'VISU::TENTITY' 'VISU::TFAMILY' 'VISU::TGROUP'}";
@@ -2663,6 +2655,36 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
     action( VISU_DELETE_OBJS )->addTo(theMenu);
   }
 
+  // Check if some curves selected (for bug PAL10611)
+  bool isCurves = false;
+  SALOME_ListIteratorOfListIO It1 (aListIO);
+  for (; It1.More() && !isCurves; It1.Next()) {
+    Handle(SALOME_InteractiveObject)& anIO = It1.Value();
+
+    if (!anIO.IsNull() && anIO->hasEntry()) {
+      _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
+      _PTR(GenericAttribute) anAttr;
+      if (aSObject->FindAttribute(anAttr, "AttributeComment")) {
+        _PTR(AttributeComment) aComment (anAttr);
+        string aComm = aComment->Value();
+        QString strIn (aComm.c_str());
+        VISU::Storable::TRestoringMap pMap;
+        VISU::Storable::StrToMap(strIn, pMap);
+        bool isExist;
+        VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
+        if (isExist && aType == VISU::TCURVE) {
+          isCurves = true;
+        }
+      }
+    }
+  }
+  if (isCurves) {
+    action( myDisplay     )->removeFrom(theMenu);
+    action( myErase       )->removeFrom(theMenu);
+    action( myDisplayOnly )->removeFrom(theMenu);
+    action( myEraseAll    )->removeFrom(theMenu);
+  }
+
   // Check single selection
   if (aListIO.Extent() != 1) return;
 
@@ -2787,21 +2809,66 @@ extern "C" {
   }
 }
 */
+
 void VisuGUI::createPreferences()
 {
+  // TAB: "Scalar Bar"
   int sbarTab = addPreference( tr( "VISU_SCALAR_BAR" ) );
 
+  int rangeGr = addPreference( tr( "VISU_SCALAR_RANGE" ), sbarTab );
+  setPreferenceProperty( rangeGr, "columns", 1 );
+
+  int mode = addPreference( tr( "VISU_SCALAR_MODE" ), rangeGr, LightApp_Preferences::Selector, "VISU", "scalar_bar_mode" );
+  QStringList modes;
+  modes.append( tr( "VISU_MODULUS" ) );
+  modes.append( tr( "VISU_COMPONENT" ) + tr("1") );
+  modes.append( tr( "VISU_COMPONENT" ) + tr("2") );
+  modes.append( tr( "VISU_COMPONENT" ) + tr("3") );
+  QValueList<QVariant> indices;
+  indices.append( 0 );
+  indices.append( 1 );
+  indices.append( 2 );
+  indices.append( 3 );
+  setPreferenceProperty( mode, "strings", modes );
+  setPreferenceProperty( mode, "indexes", indices );
+
+  addPreference( tr( "VISU_LOGARITHMIC_SCALING" ), rangeGr, LightApp_Preferences::Bool, "VISU", "scalar_bar_logarithmic" );
+
+  int rangetype = addPreference( tr( "VISU_RANGE_TO_USE" ), rangeGr, LightApp_Preferences::Selector, "VISU", "scalar_range_type" );
+  QStringList types;
+  types.append( tr( "VISU_FIELD_RANGE" ) );
+  types.append( tr( "VISU_IMPOSED_RANGE" ) );
+  indices.clear();
+  indices.append( 0 );
+  indices.append( 1 );
+  setPreferenceProperty( rangetype, "strings", types );
+  setPreferenceProperty( rangetype, "indexes", indices );
+
+  int imposedGr = addPreference( tr( "VISU_MINMAX_IMPOSED_RANGE" ), sbarTab );
+
+  int min = addPreference( tr( "VISU_MIN" ), imposedGr, LightApp_Preferences::DblSpin, "VISU", "scalar_range_min" );
+  int max = addPreference( tr( "VISU_MAX" ), imposedGr, LightApp_Preferences::DblSpin, "VISU", "scalar_range_max" );
+  setPreferenceProperty( min, "step", 0.1 );
+  setPreferenceProperty( max, "step", 0.1 );
+
+  // group: "Font"
   int fontGr = addPreference( tr( "VISU_FONT" ), sbarTab );
-  int tfont = addPreference( tr( "VISU_TITLE" ), fontGr, LightApp_Preferences::Font, "VISU", "scalar_bar_title_font" );
-  addPreference( tr( "VISU_TITLE" ), fontGr, LightApp_Preferences::Color, "VISU", "scalar_bar_title_color" );
-  int lfont = addPreference( tr( "VISU_LABELS" ), fontGr, LightApp_Preferences::Font, "VISU", "scalar_bar_label_font" );
-  addPreference( tr( "VISU_LABELS" ), fontGr, LightApp_Preferences::Color, "VISU", "scalar_bar_label_color" );
+  int tfont = addPreference( tr( "VISU_TITLE" ), fontGr,
+                             LightApp_Preferences::Font, "VISU", "scalar_bar_title_font" );
+  addPreference( tr( "VISU_TITLE" ), fontGr,
+                 LightApp_Preferences::Color, "VISU", "scalar_bar_title_color" );
+  int lfont = addPreference( tr( "VISU_LABELS" ), fontGr,
+                             LightApp_Preferences::Font, "VISU", "scalar_bar_label_font" );
+  addPreference( tr( "VISU_LABELS" ), fontGr,
+                 LightApp_Preferences::Color, "VISU", "scalar_bar_label_color" );
 
   QStringList fam;
   fam.append( tr( "VISU_FONT_ARIAL" ) );
   fam.append( tr( "VISU_FONT_COURIER" ) );
   fam.append( tr( "VISU_FONT_TIMES" ) );
-  int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
+  int wflag = ( QtxListResourceEdit::FontItem::All &
+                ( ~( QtxListResourceEdit::FontItem::Size |
+                     QtxListResourceEdit::FontItem::UserSize ) ) );
 
   setPreferenceProperty( tfont, "families", fam );
   setPreferenceProperty( tfont, "system", false );
@@ -2810,32 +2877,42 @@ void VisuGUI::createPreferences()
   setPreferenceProperty( lfont, "system", false );
   setPreferenceProperty( lfont, "widget_flags", wflag );
 
+  // group: "Colors & Labels"
   int colorsLabelsGr = addPreference( tr( "VISU_COLORS_AND_LABELS" ), sbarTab );
 
-  int numcol = addPreference( tr( "VISU_NB_COLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "VISU", "scalar_bar_num_colors" );
+  int numcol = addPreference( tr( "VISU_NB_COLORS" ), colorsLabelsGr,
+                              LightApp_Preferences::IntSpin, "VISU", "scalar_bar_num_colors" );
   setPreferenceProperty( numcol, "min", 2 );
-  setPreferenceProperty( numcol, "max", 64 );
+  setPreferenceProperty( numcol, "max", 256 );
 
-  int numlab = addPreference( tr( "VISU_NB_LABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "VISU", "scalar_bar_num_labels" );
+  int numlab = addPreference( tr( "VISU_NB_LABELS" ), colorsLabelsGr,
+                              LightApp_Preferences::IntSpin, "VISU", "scalar_bar_num_labels" );
   setPreferenceProperty( numlab, "min", 2 );
   setPreferenceProperty( numlab, "max", 65 );
 
+  // group: "Orientation"
   int orientGr = addPreference( tr( "VISU_ORIENTATION" ), sbarTab );
-  int orient = addPreference( tr( "VISU_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "VISU", "scalar_bar_orientation" );
+  int orient = addPreference( tr( "VISU_ORIENTATION" ), orientGr,
+                              LightApp_Preferences::Selector, "VISU", "scalar_bar_orientation" );
   QStringList orients;
   orients.append( tr( "VISU_VERTICAL" ) );
   orients.append( tr( "VISU_HORIZONTAL" ) );
-  QValueList<QVariant> indices;
+  indices.clear();
   indices.append( 0 );
   indices.append( 1 );
   setPreferenceProperty( orient, "strings", orients );
   setPreferenceProperty( orient, "indexes", indices );
 
+  // group: "Origin & Size Vertical"
   int posVSizeGr = addPreference( tr( "VISU_ORIGIN_AND_SIZE" ) + " " + tr( "VISU_VERTICAL" ), sbarTab );
-  int xv = addPreference( tr( "VISU_X" ), posVSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_x" );
-  int yv = addPreference( tr( "VISU_Y" ), posVSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_y" );
-  int wv = addPreference( tr( "VISU_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_width" );
-  int hv = addPreference( tr( "VISU_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_height" );
+  int xv = addPreference( tr( "VISU_X" ), posVSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_x" );
+  int yv = addPreference( tr( "VISU_Y" ), posVSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_y" );
+  int wv = addPreference( tr( "VISU_WIDTH" ), posVSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_width" );
+  int hv = addPreference( tr( "VISU_HEIGHT" ), posVSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_height" );
   setPreferenceProperty( xv, "step", 0.1 );
   setPreferenceProperty( yv, "step", 0.1 );
   setPreferenceProperty( wv, "step", 0.1 );
@@ -2849,11 +2926,16 @@ void VisuGUI::createPreferences()
   setPreferenceProperty( wv, "max", 1.0 );
   setPreferenceProperty( hv, "max", 1.0 );
 
+  // group: "Origin & Size Horizontal"
   int posHSizeGr = addPreference( tr( "VISU_ORIGIN_AND_SIZE" ) + " " + tr( "VISU_HORIZONTAL" ), sbarTab );
-  int xh = addPreference( tr( "VISU_X" ), posHSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_x" );
-  int yh = addPreference( tr( "VISU_Y" ), posHSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_y" );
-  int wh = addPreference( tr( "VISU_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_width" );
-  int hh = addPreference( tr( "VISU_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_height" );
+  int xh = addPreference( tr( "VISU_X" ), posHSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_x" );
+  int yh = addPreference( tr( "VISU_Y" ), posHSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_y" );
+  int wh = addPreference( tr( "VISU_WIDTH" ), posHSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_width" );
+  int hh = addPreference( tr( "VISU_HEIGHT" ), posHSizeGr,
+                          LightApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_height" );
   setPreferenceProperty( xh, "step", 0.1 );
   setPreferenceProperty( yh, "step", 0.1 );
   setPreferenceProperty( wh, "step", 0.1 );
@@ -2867,62 +2949,102 @@ void VisuGUI::createPreferences()
   setPreferenceProperty( wh, "max", 1.0 );
   setPreferenceProperty( hh, "max", 1.0 );
 
-  int srangeTab = addPreference( tr( "Scalar range, Sweep, MED import" ) );
-
-  int rangeGr = addPreference( tr( "VISU_SCALAR_RANGE" ), srangeTab );
-  setPreferenceProperty( rangeGr, "columns", 1 );
-
-  int mode = addPreference( tr( "VISU_SCALAR_MODE" ), rangeGr, LightApp_Preferences::Selector, "VISU", "scalar_bar_mode" );
-  QStringList modes;
-  modes.append( tr( "VISU_MODULUS" ) );
-  modes.append( tr( "VISU_COMPONENT" ) + tr("1") );
-  modes.append( tr( "VISU_COMPONENT" ) + tr("2") );
-  modes.append( tr( "VISU_COMPONENT" ) + tr("3") );
-  indices.clear();
-  indices.append( 0 );
-  indices.append( 1 );
-  indices.append( 2 );
-  indices.append( 3 );
-  setPreferenceProperty( mode, "strings", modes );
-  setPreferenceProperty( mode, "indexes", indices );
+  // group: "Scalar bars default position"
+  int scalarBarGr = addPreference( tr( "Scalar bars default position" ), sbarTab );
+  addPreference( tr( "Arrange Scalar Bars" ), scalarBarGr, LightApp_Preferences::Bool, "VISU", "scalar_bars_default_position" );
 
-  addPreference( tr( "VISU_LOGARITHMIC_SCALING" ), rangeGr, LightApp_Preferences::Bool, "VISU", "scalar_bar_logarithmic" );
-
-  int rangetype = addPreference( tr( "VISU_RANGE_TO_USE" ), rangeGr, LightApp_Preferences::Selector, "VISU", "scalar_range_type" );
-  QStringList types;
-  types.append( tr( "VISU_FIELD_RANGE" ) );
-  types.append( tr( "VISU_IMPOSED_RANGE" ) );
-  indices.clear();
-  indices.append( 0 );
-  indices.append( 1 );
-  setPreferenceProperty( rangetype, "strings", types );
-  setPreferenceProperty( rangetype, "indexes", indices );
-
-  int imposedGr = addPreference( tr( "VISU_MINMAX_IMPOSED_RANGE" ), srangeTab );
-
-  int min = addPreference( tr( "VISU_MIN" ), imposedGr, LightApp_Preferences::DblSpin, "VISU", "scalar_range_min" );
-  int max = addPreference( tr( "VISU_MAX" ), imposedGr, LightApp_Preferences::DblSpin, "VISU", "scalar_range_max" );
-  setPreferenceProperty( min, "step", 0.1 );
-  setPreferenceProperty( max, "step", 0.1 );
+  int srangeTab = addPreference( tr( "Sweep, MED import" ) );
 
+  // group: "Sweeping preferences"
   int sweepGr = addPreference( tr( "VISU_SWEEPING_PREF" ), srangeTab );
   setPreferenceProperty( sweepGr, "columns", 1 );
 
-  int timestep   = addPreference( tr( "VISU_TIME_STEP" ), sweepGr, LightApp_Preferences::DblSpin, "VISU", "sweeping_time_step" );
-  int nbcycles   = addPreference( tr( "VISU_NB_CYCLES" ), sweepGr, LightApp_Preferences::IntSpin, "VISU", "sweeping_number_cycles" );
-  int nbsteps    = addPreference( tr( "VISU_NB_STEPS" ),  sweepGr, LightApp_Preferences::IntSpin, "VISU", "sweeping_number_steps" );
+  int timestep   = addPreference( tr( "VISU_TIME_STEP" ), sweepGr,
+                                  LightApp_Preferences::DblSpin, "VISU", "sweeping_time_step" );
+  int nbcycles   = addPreference( tr( "VISU_NB_CYCLES" ), sweepGr,
+                                  LightApp_Preferences::IntSpin, "VISU", "sweeping_number_cycles" );
+  int nbsteps    = addPreference( tr( "VISU_NB_STEPS" ),  sweepGr,
+                                  LightApp_Preferences::IntSpin, "VISU", "sweeping_number_steps" );
   setPreferenceProperty( timestep, "min",  0.1 );
   setPreferenceProperty( timestep, "step", 0.1 );
   setPreferenceProperty( timestep, "max",  1000 );
   setPreferenceProperty( nbcycles, "max",  100  );
   setPreferenceProperty( nbsteps,  "max",  200  );
 
+  // group: "MED files import"
   int importGr = addPreference( tr( "MED files import" ), srangeTab );
+  setPreferenceProperty( importGr, "columns", 1 );
   addPreference( tr( "Full MED loading" ), importGr, LightApp_Preferences::Bool, "VISU", "full_med_loading" );
+  addPreference( tr( "Build at once" ), importGr, LightApp_Preferences::Bool, "VISU", "build_at_once" );
+  addPreference( tr( "Build fields" ), importGr, LightApp_Preferences::Bool, "VISU", "build_fields" );
+  addPreference( tr( "Build min/max" ), importGr, LightApp_Preferences::Bool, "VISU", "build_min_max" );
+  addPreference( tr( "Build groups" ), importGr, LightApp_Preferences::Bool, "VISU", "build_groups" );
+  addPreference( tr( "Close dialog at finish" ), importGr, LightApp_Preferences::Bool, "VISU", "close_at_finish" );
+
+  // group: "Representation properties"
+  int representGr = addPreference( tr( "VISU_PREF_REPRESENT_PROPS" ), srangeTab );
+  addPreference( tr( "VISU_PREF_SHADING" ), representGr,
+                 LightApp_Preferences::Bool, "VISU", "represent_shading" );
 }
 
-void VisuGUI::preferencesChanged( const QString&, const QString& )
+void VisuGUI::preferencesChanged( const QString& a, const QString& b)
 {
+  if (a != QString("VISU")) return;
+  if (b == QString("scalar_bar_orientation")) return;
+  SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+  float sbX1,sbY1,sbW,sbH;
+  std::string aWarning;
+  if(b == QString("scalar_bar_vertical_x") || b == QString("scalar_bar_vertical_width")){
+    sbX1 = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_x", sbX1);
+    sbW = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_width", sbW);
+    if(sbX1+sbW > 1.0){
+      aWarning = "Origin and Size Vertical: X+Width > 1\n";
+      sbX1=0.01;
+      sbW=0.05;
+      aResourceMgr->setValue("VISU", "scalar_bar_vertical_x", sbX1);
+      aResourceMgr->setValue("VISU", "scalar_bar_vertical_width", sbW);
+    }
+  }
+  else if(b == QString("scalar_bar_vertical_y") || b == QString("scalar_bar_vertical_height")){
+    sbY1 = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_y", sbY1);
+    sbH = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_height",sbH);
+    if(sbY1+sbH > 1.0){
+      aWarning = "Origin and Size Vertical: Y+Height > 1\n";
+      sbY1=0.01;
+      sbH=0.5;
+      aResourceMgr->setValue("VISU", "scalar_bar_vertical_y", sbY1);
+      aResourceMgr->setValue("VISU", "scalar_bar_vertical_height",sbH);
+    }
+  }
+  else if(b ==  QString("scalar_bar_horizontal_x") || b ==  QString("scalar_bar_horizontal_width")){
+    sbX1 = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_x", sbX1);
+    sbW = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_width", sbW);
+    if(sbX1+sbW > 1.0){
+      aWarning = "Origin and Size Horizontal: X+Width > 1\n";
+      sbX1=0.2;
+      sbW=0.6;
+      aResourceMgr->setValue("VISU", "scalar_bar_horizontal_x", sbX1);
+      aResourceMgr->setValue("VISU", "scalar_bar_horizontal_width", sbW);
+    }
+  }
+  else if(b ==  QString("scalar_bar_horizontal_y") || b ==  QString("scalar_bar_horizontal_height")){
+    sbY1 = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_y", sbY1);
+    sbH = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_height",sbH);
+    if(sbY1+sbH > 1.0){
+      aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
+      sbY1=0.01;
+      sbH=0.12;
+      aResourceMgr->setValue("VISU", "scalar_bar_horizontal_y", sbY1);
+      aResourceMgr->setValue("VISU", "scalar_bar_horizontal_height",sbH);
+    }
+  }
+  if (aWarning.size() != 0){
+    aWarning += "The default values are applied instead.";
+    SUIT_MessageBox::warn1(GetDesktop(this),
+                          tr("ERR_SCALARBAR_PARAMS"),
+                          tr(aWarning.c_str()),
+                          tr("BUT_OK") );
+  }
 }
 
 SUIT_ViewManager*
@@ -2933,10 +3055,16 @@ VisuGUI
   return getApp()->getViewManager(theType,theIsCreate);
 }
 
+TViewToPrs3d 
+VisuGUI
+::getScalarBarsMap()
+{
+  return myScalarBarsMap;
+}
 LightApp_Displayer* VisuGUI::displayer()
 {
   if( !myDisplayer )
-    myDisplayer = new VisuGUI_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
+    myDisplayer = new VisuGUI_Displayer( getApp() );
     
   return myDisplayer;
 }