Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI.cxx
index d2c810d2b2910a61e24619d92e6b2d252214b2b0..3c2ad86737b9aaf2a87f8df20288fd1f937663c3 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"
 
 #include "CAM_Module.h"
 
-#include "SVTK_RenderWindow.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_Functor.h"
 
 #include "SPlot2d_ViewModel.h"
-#include "SPlot2d_SetupPlot2dDlg.h"
+#include "VisuGUI_SetupPlot2dDlg.h"
 #include "Plot2d_SetupCurveDlg.h"
+#include "Plot2d_ViewManager.h"
 
 #include "OB_Browser.h"
 
 #include "SalomeApp_Application.h"
 #include "SalomeApp_DataModel.h"
 #include "SalomeApp_Study.h"
-#include "SalomeApp_SelectionMgr.h"
-#include "SalomeApp_Selection.h"
-#include "SalomeApp_Preferences.h"
+#include "SalomeApp_CheckFileDlg.h"
+#include "LightApp_SelectionMgr.h"
+#include "LightApp_Selection.h"
+#include "LightApp_Preferences.h"
+
+#include "QtxAction.h"
 
 #include "VISUConfig.hh"
 #include "VISU_Gen_i.hh"
 
 #include "VISU_Actor.h"
 
+#include "VisuGUI_Prs3dTools.h"
 #include "VisuGUI_Tools.h"
+
 #include "VisuGUI_PopupTools.h"
 #include "VisuGUI_NameDlg.h"
-#include "VisuGUI_FileDlg.h"
 #include "VisuGUI_CursorDlg.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"
+
+#include "VVTK_ViewModel.h"
+
 using namespace VISU;
 
 #ifdef _DEBUG_
@@ -143,7 +157,8 @@ static int MYDEBUG = 0;
 //////////////////////////////////////////////////
 
 VisuGUI::VisuGUI():
-  SalomeApp_Module( "VISU" )
+  SalomeApp_Module( "VISU" ),
+  myDisplayer( 0 )
 {
 }
 
@@ -152,98 +167,82 @@ VisuGUI::~VisuGUI()
 {
 }
 
-
 void
 VisuGUI::
 OnImportFromFile()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnImportFromFile()");
-  CheckLock(GetCStudy(GetAppStudy(this)));
-  SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+  if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) )
+    return;
+  
+  SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
 
+  // Get file name
   QStringList aFilter;
-  aFilter.append( tr("FLT_MED_FILES") );
-  aFilter.append( tr("FLT_ALL_FILES") );
+  aFilter.append( tr( "FLT_MED_FILES" ) );
+  aFilter.append( tr( "FLT_ALL_FILES" ) );
+  
+  bool toUseBuildProgress = aResourceMgr->booleanValue("VISU", "use_build_progress", false);
+
+  SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( GetDesktop(this), true, tr("USE_BUILD_PROGRESS") );
+  fd->setCaption( tr( "IMPORT_FROM_FILE" ) );
+  fd->setFilters( aFilter );
+  fd->SetChecked( toUseBuildProgress );
+  fd->exec();
+  QFileInfo aFileInfo( fd->selectedFile() );
+  toUseBuildProgress = fd->IsChecked();
+  delete fd;
+  
+  // Check the file name
+  if ( !aFileInfo.exists() )
+    return;
+  
+  if ( !toUseBuildProgress )
+    {
+      bool toBuildFields = aResourceMgr->booleanValue( "VISU", "build_fields", true );
+      bool toBuildMinMax = aResourceMgr->booleanValue( "VISU", "build_min_max", true );
+      bool toBuildGroups = aResourceMgr->booleanValue( "VISU", "build_groups", true );
+      bool toBuildAll = aResourceMgr->booleanValue( "VISU", "full_med_loading", false );
+      bool toBuildAtOnce = aResourceMgr->booleanValue( "VISU", "build_at_once", false );
+      
+      QString anInfo("Importing From File " + aFileInfo.filePath() + "..." ); 
+      application()->putInfo( anInfo );
 
-  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);
+      QApplication::setOverrideCursor(Qt::waitCursor);
+      VISU::Result_var aResult = GetVisuGen(this)->CreateResult( aFileInfo.filePath() );
+
+      if (CORBA::is_nil(aResult.in())) {
+       SUIT_MessageBox::warn1(GetDesktop(this),
+                              tr("WRN_VISU"),
+                              VisuGUI_BuildProgressDlg::tr("ERR_ERROR_IN_THE_FILE"),
+                              tr("BUT_OK"));
+       QApplication::restoreOverrideCursor();
+      }else{
+       aResult->SetBuildFields( toBuildFields, toBuildMinMax );
+       aResult->SetBuildGroups( toBuildGroups );
+       aResult->Build( toBuildAll, toBuildAtOnce );
+
+       UpdateObjBrowser(this);
+       application()->putInfo( anInfo + tr("INF_DONE"));
+       QApplication::restoreOverrideCursor();
+      }
     }
-
-    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);
+  else
+    {
+      VisuGUI_BuildProgressDlg* aBuildProgressDlg = new VisuGUI_BuildProgressDlg( GetDesktop(this) );
+      aBuildProgressDlg->setFileName( aFileInfo.filePath() );
+      aBuildProgressDlg->setGenerator( GetVisuGen(this) );
+      aBuildProgressDlg->show();
     }
-  }
 }
 
-
-void
-VisuGUI::
-OnExploreMEDFile()
-{
-  if(MYDEBUG) MESSAGE("VisuGUI::OnExploreMEDFile()");
-  _PTR(Study) aStudy = GetCStudy(GetAppStudy(this));
-  CheckLock(aStudy);
-
-  SALOME_MED::MED_Gen_var aGen = GetMEDEngine();
-
-  QStringList aFilter;
-  aFilter.append( tr("FLT_MED_FILES") );
-  aFilter.append( tr("FLT_ALL_FILES") );
-
-  QFileInfo aFileInfo =
-    SUIT_FileDlg::getFileName(GetDesktop(this),
-                              "",
-                              aFilter,
-                              tr("MEN_EXPLORE_MED_FILE"),
-                              true);
-  if(aFileInfo.exists()){
-    application()->putInfo( tr("MEN_EXPLORE_MED_FILE") + " " + aFileInfo.filePath() + "..." );
-    std::string aStudyName = aStudy->Name();
-    aGen->readStructFileWithFieldType(aFileInfo.filePath(),aStudyName.c_str());
-    application()->putInfo(aFileInfo.filePath()+tr("INF_DONE"));
-    getApp()->updateObjectBrowser(true); // as need to update MED tree
-    getApp()->updateActions();
-  }
-}
-
-
 void
 VisuGUI::
 OnImportTableFromFile()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnImportTableFromFile()");
-  CheckLock(GetCStudy(GetAppStudy(this)));
+  if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) )
+    return;
 
   QStringList aFilter;
   aFilter.append( tr("FLT_TABLE_FILES") );
@@ -277,6 +276,102 @@ VisuGUI::
 OnExportTableToFile()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnExportTableToFile()");
+
+  _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
+
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  SALOME_ListIO aListIO;
+  aSelectionMgr->selectedObjects(aListIO);
+
+  if (aListIO.Extent() > 0) {
+    const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
+    if (anIO->hasEntry()) {
+      _PTR(SObject) aSObj = aCStudy->FindObjectID(anIO->getEntry());
+      if (!aSObj) return;
+
+      // find table attribute
+      bool isTOR = true;
+      _PTR(GenericAttribute) anAttr;
+
+      if (!aSObj->FindAttribute(anAttr, "AttributeTableOfReal")) {
+        isTOR = false;
+        if (!aSObj->FindAttribute(anAttr, "AttributeTableOfInteger")) {
+          // if the current SObject is a table title
+          // we take a father contaning the table
+          aSObj = aSObj->GetFather();
+
+          if (aSObj->FindAttribute(anAttr, "AttributeTableOfReal")) {
+            isTOR = true;
+          } else {
+            if (!aSObj->FindAttribute(anAttr, "AttributeTableOfInteger")) {
+              return;
+            }
+          }
+        }
+      }
+
+      // get table title in order to have default name of the file
+      QString aTitle;
+      if (isTOR) {
+        _PTR(AttributeTableOfReal) aTabAttr (anAttr);
+        if (!aTabAttr) return;
+        aTitle = aTabAttr->GetTitle().c_str();
+      } else {
+       _PTR(AttributeTableOfInteger) aTabAttr (anAttr);
+       if (!aTabAttr) return;
+        aTitle = aTabAttr->GetTitle().c_str();
+      }
+      aTitle.simplifyWhiteSpace();
+      aTitle = aTitle.replace(QRegExp(" "), "_").replace(QRegExp("\\*"), "" );
+
+      // get default path for the file
+      SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
+      QString aDir = aResourceMgr->stringValue("VISU","OutputDir","");
+      if (aDir.isEmpty()) {
+        aDir = aResourceMgr->stringValue("VISU","InputDir","");
+        if (aDir.isEmpty()) {
+          aDir = getenv("CSF_PATHData");
+        }
+      }
+      QString aPath = Qtx::addSlash(aDir) + aTitle;
+
+      // get name for the file
+      QStringList aFilter;
+      aFilter.append("Table Files (*.xls)");
+
+      QFileInfo aFileInfo =
+        SUIT_FileDlg::getFileName(GetDesktop(this),
+                                  aPath,
+                                  aFilter,
+                                  tr("MEN_EXPORT_TABLE"), // "Export Table To File"
+                                  false);
+
+      // export
+      QString aFile = aFileInfo.filePath();
+      if (!aFile.isEmpty()) {
+        application()->putInfo(tr("MEN_EXPORT_TABLE") + " " + aFile + " ...");
+       aDir = Qtx::dir(aFile, true);
+        aResourceMgr->setValue("VISU", "OutputDir", aDir);
+
+       try {
+         GetVisuGen(this)->ExportTableToFile(GetSObject(aSObj), aFile.latin1());
+          application()->putInfo(aFile + " " + tr("INF_DONE"));
+       } catch(std::exception& exc) {
+         INFOS(exc.what());
+         SUIT_MessageBox::warn1(GetDesktop(this),
+                                 tr("WRN_VISU"),
+                                tr("ERR_ERROR_DURING_EXPORT") + " " + tr(exc.what()),
+                                tr("BUT_OK"));
+       } catch(...) {
+         INFOS(tr("ERR_ERROR_DURING_EXPORT"));
+         SUIT_MessageBox::warn1(GetDesktop(this),
+                                 tr("WRN_VISU"),
+                                tr("ERR_ERROR_DURING_EXPORT"),
+                                tr("BUT_OK") );
+       }
+      }
+    }
+  }
 }
 
 void
@@ -284,11 +379,11 @@ VisuGUI::
 OnImportMedField()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
   SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
 
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -345,7 +440,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;
         }
       }
@@ -376,122 +472,12 @@ CreateCurves( SalomeApp_Module* theModule,
   }
 }
 
-template<class TPrs3d_i>
-TPrs3d_i*
-CreatePrs3d(SalomeApp_Module* theModule,
-            _PTR(SObject) theTimeStamp,
-            const char* theMeshName,
-            VISU::Entity theEntity,
-            const char* theFieldName,
-            int theTimeId)
-{
-  VISU::Result_var aResult;
-  if (CheckResult(theModule,theTimeStamp,aResult)){
-    QApplication::setOverrideCursor(Qt::waitCursor);
-    typedef typename TPrs3d_i::TInterface TPrs3d;
-    typename TPrs3d::_var_type aPrs3d =
-      GetVisuGen(theModule)->template Prs3dOnField<TPrs3d_i>
-      (aResult,theMeshName,theEntity,theFieldName,theTimeId);
-    QApplication::restoreOverrideCursor();
-    if (!CORBA::is_nil(aPrs3d.in()))
-      return dynamic_cast<TPrs3d_i*>(VISU::GetServant(aPrs3d.in()).in());
-  }
-  SUIT_MessageBox::warn1(GetDesktop(theModule),
-                         QObject::tr("WRN_VISU"),
-                         QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
-                         QObject::tr("BUT_OK") );
-  return NULL;
-}
-
-
-template<class TPrs3d_i, class TDlg, int IsDlgModal>
-bool
-CreatePrs3d(SalomeApp_Module* theModule,
-            _PTR(SObject) theTimeStamp,
-            const Handle(SALOME_InteractiveObject)& theIO)
-{
-  using namespace VISU;
-  Storable::TRestoringMap aMap = getMapOfValue(theTimeStamp);
-  bool isExist;
-  QString aType = Storable::FindValue(aMap,"myType",&isExist);
-  if(!isExist || aType.toInt() != TTIMESTAMP )
-    return false;
-  QString aMeshName = Storable::FindValue(aMap,"myMeshName",&isExist).latin1();
-  QString anEntity = Storable::FindValue(aMap,"myEntityId",&isExist).latin1();
-  QString aFieldName = Storable::FindValue(aMap,"myFieldName",&isExist).latin1();
-  QString aTimeStampId = Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1();
-  QApplication::setOverrideCursor(Qt::waitCursor);
-  TPrs3d_i* aPrs3d =
-    CreatePrs3d<TPrs3d_i>(theModule,
-                          theTimeStamp,
-                          aMeshName.latin1(),
-                          (Entity)anEntity.toInt(),
-                          aFieldName.latin1(),
-                          aTimeStampId.toInt());
-  QApplication::restoreOverrideCursor();
-  if(aPrs3d){
-    SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
-    int aValue = aResourceMgr->integerValue("Visu:BuildDefaultPrs3d",0);
-    if(!aValue){
-      if(TDlg* aDlg = new TDlg(theModule)){ // dialog box in creation mode
-        aDlg->initFromPrsObject(aPrs3d);
-        if(IsDlgModal)
-          if(aDlg->exec() && (aDlg->storeToPrsObject(aPrs3d))) {
-            // Optionally, create table and curves for cut lines
-            QApplication::setOverrideCursor(Qt::waitCursor);
-            CreateCurves( theModule,
-                          dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
-                          aDlg,
-                          true ); // in creation mode
-            QApplication::restoreOverrideCursor();
-            delete aDlg;
-          } else {
-            DeletePrs3d(theModule,aPrs3d,theIO);
-            delete aDlg;
-            return false;
-          }
-        else{
-          aDlg->show();
-          return true;
-        }
-      }
-    }
-    PublishInView(theModule,aPrs3d);
-    return true;
-  }
-  return false;
-}
-
-
-template<class TPrs3d_i, class TDlg, int IsDlgModal>
-void
-CreatePrs3d(SalomeApp_Module* theModule)
-{
-  if (CheckLock(GetCStudy(GetAppStudy(theModule))))
-    return;
-
-  _PTR(SObject) aTimeStampSObj;
-  Handle(SALOME_InteractiveObject) anIO;
-  if (!CheckTimeStamp(theModule,aTimeStampSObj,&anIO))
-    return;
-
-  if (!CreatePrs3d<TPrs3d_i,TDlg,IsDlgModal>(theModule,aTimeStampSObj,anIO))
-    return;
-
-  theModule->application()->putInfo(QObject::tr("INF_DONE"));
-  theModule->updateObjBrowser();
-  UpdateObjBrowser(theModule);
-
-  if (SVTK_ViewWindow* aView = GetViewWindow(theModule))
-    aView->onFitAll();
-}
-
 void
 VisuGUI::
 OnCreateMesh()
 {
   _PTR(Study) aStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aStudy))
+  if (CheckLock(aStudy,GetDesktop(this)))
     return;
 
   // Get selected SObject
@@ -500,7 +486,11 @@ OnCreateMesh()
   if (anIO.IsNull() || !anIO->hasEntry())
     return;
 
-  CreateMesh(this, anIO);
+  // create a VTK view window if it does not exist
+  SVTK_ViewWindow* aViewWindow = GetViewWindow<SVTK_Viewer>(this);
+
+  // create mesh presentation and display it in aViewWindow
+  CreateMesh(this, anIO, aViewWindow);
 }
 
 void
@@ -508,11 +498,14 @@ 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
+  SVTK_ViewWindow* aViewWindow = GetViewWindow<SVTK_Viewer>(this);
+
   // Get selected SObject
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
   SALOME_ListIteratorOfListIO anIter (aListIO);
@@ -521,7 +514,8 @@ OnCreateManyMesh()
     if (anIO.IsNull() || !anIO->hasEntry())
       return;
 
-    CreateMesh(this, anIO);
+    // create mesh presentation and display it in aViewWindow
+    CreateMesh(this, anIO, aViewWindow);
   }
 }
 
@@ -540,6 +534,13 @@ OnCreateDeformedShape()
   CreatePrs3d<VISU::DeformedShape_i,VisuGUI_DeformedShapeDlg,1>(this);
 }
 
+void
+VisuGUI::
+OnCreateScalarMapOnDeformedShape()
+{
+  CreatePrs3d<VISU::ScalarMapOnDeformedShape_i,VisuGUI_ScalarMapOnDeformedShapeDlg,1>(this);
+}
+
 void
 VisuGUI::
 OnCreateVectors()
@@ -558,14 +559,14 @@ void
 VisuGUI::
 OnCreateCutPlanes()
 {
-  CreatePrs3d<VISU::CutPlanes_i,VisuGUI_CutPlanesDlg,1>(this);
+  CreatePrs3d<VISU::CutPlanes_i,VisuGUI_CutPlanesDlg,0>(this);
 }
 
 void
 VisuGUI::
 OnCreateCutLines()
 {
-  CreatePrs3d<VISU::CutLines_i,VisuGUI_CutLinesDlg,1>(this);
+  CreatePrs3d<VISU::CutLines_i,VisuGUI_CutLinesDlg,0>(this);
 }
 
 void
@@ -579,14 +580,14 @@ void
 VisuGUI::
 OnCreatePlot3D()
 {
-  CreatePrs3d<VISU::Plot3D_i,VisuGUI_Plot3DDlg,1>(this);
+  CreatePrs3d<VISU::Plot3D_i,VisuGUI_Plot3DDlg,0>(this);
 }
 
 void
 VisuGUI::
 OnCreatePlot2dView()
 {
-  CheckLock(GetCStudy(GetAppStudy(this)));
+  CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this));
   GetVisuGen( this )->CreateContainer();
   UpdateObjBrowser(this);
 }
@@ -597,53 +598,65 @@ OnDisplayPrs()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnDisplayPrs");
 
+  LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
+  if (!mgr) return;
+
   QApplication::setOverrideCursor(Qt::waitCursor);
-  SALOME_ListIO aList;
-  SalomeApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects(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 ) ) {
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
+
+  SALOME_ListIO aSel, aList;
+  mgr->selectedObjects(aSel);
+  extractContainers(aSel, aList);
+
+  for (SALOME_ListIteratorOfListIO it (aList); it.More(); it.Next()) {
+    Handle(SALOME_InteractiveObject) anIO = it.Value();
+    CORBA::Object_var anObject = GetSelectedObj(GetAppStudy(this), anIO->getEntry());
+
+    if (!CORBA::is_nil(anObject)) {
       // is it Prs3d object ?
       VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject).in());
-      if(aPrsObject){
+      if (aPrsObject) {
         if(MYDEBUG) MESSAGE("VisuGUI::OnDisplayPrs : Prs3d object");
-        UpdateViewer( this, aPrsObject );
-        if (SVTK_ViewWindow* vw = GetViewWindow( this )) {
-          vw->highlight(anIO, 1);
+        //UpdateViewer( this, aPrsObject );
+        if (vw) {
+         displayer()->Display(anIO->getEntry());
+         vw->highlight(anIO, 1);
         }
         continue;
       }
       // is it Curve ?
       VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject).in());
-      if(aCurve){
+      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 (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 (aTable) {
         if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Table object");
-        PlotTable( this, aTable, VISU::eDisplay );
+        //PlotTable( this, aTable, VISU::eDisplay );
+       displayer()->Display(anIO->getEntry());
         continue;
       }
     }
   }
-  if (SVTK_ViewWindow* vw = GetViewWindow( this )) {
+
+  if (vw) {
     vw->getRenderer()->ResetCameraClippingRange();
     vw->Repaint();
   }
+
   QApplication::restoreOverrideCursor();
 }
 
@@ -663,129 +676,135 @@ OnErasePrs()
 
   QApplication::setOverrideCursor(Qt::waitCursor);
 
-  SVTK_ViewWindow* vw = GetViewWindow(this);
-  if (vw) vw->unHighlightAll();
+  //SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
+  //if (vw)
+  //  vw->unHighlightAll();
 
-  SALOME_ListIO aList;
-  SalomeApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects(aList);
+  SALOME_ListIO aList, aSel;
+  LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
+  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() );
-    ErasePrs(this, anObject, false);
+  for (SALOME_ListIteratorOfListIO it (aList); it.More(); it.Next()) {
+    Handle(SALOME_InteractiveObject) anIO = it.Value();
+    CORBA::Object_var anObject = GetSelectedObj(GetAppStudy(this), anIO->getEntry());
+    //ErasePrs(this, anObject, /*repaint_view_window = */false);
+    ErasePrs(this, anObject, /*repaint_view_window = */true);
   }
 
-  if (vw) vw->Repaint();
+  //if (vw)
+  //  vw->Repaint();
 
   QApplication::restoreOverrideCursor();
 }
 
-template<class TPrs3d_i, class TDlg>
 void
-EditPrs3d (SalomeApp_Module* theModule, VISU::Prs3d_i* thePrs3d)
+VisuGUI::
+OnEraseAll()
 {
-  TPrs3d_i* aPrsObject = dynamic_cast<TPrs3d_i*>(thePrs3d);
-  if (aPrsObject) {
-    TDlg* aDlg = new TDlg (theModule);
-    aDlg->initFromPrsObject(aPrsObject);
-    if (aDlg->exec()) {
-      if (!(aDlg->storeToPrsObject(aPrsObject))) {
-        delete aDlg;
-        return;
-      }
-      RecreateActor(theModule, aPrsObject);
-      if (SVTK_ViewWindow* vw = GetViewWindow(theModule)) {
-        vw->getRenderer()->ResetCameraClippingRange();
-        vw->Repaint();
+  startOperation( myEraseAll );
+  if (SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(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, vw, anVISUActor->GetPrs3d());
+            anVISUActor->VisibilityOff();
+          }
       }
-      // Optionally, create table and curves for cut lines
-      QApplication::setOverrideCursor(Qt::waitCursor);
-      CreateCurves( theModule,
-                    dynamic_cast<VISU::CutLines_i*>( aPrsObject ),
-                    aDlg,
-                    false ); // in edition mode
-      QApplication::restoreOverrideCursor();
+      vw->Repaint();
     }
-    delete aDlg;
+  } else if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(this, false)) {
+    aPlot2d->EraseAll();
   }
 }
 
+
 void
 VisuGUI::
-OnEditPrs()
+OnEditScalarMap()
 {
-  if (CheckLock(GetCStudy(GetAppStudy(this))))
-    return;
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::ScalarMap_i, VisuGUI_ScalarBarDlg, 1>(this, anIO, aPrs3d);
+}
 
+void
+VisuGUI::
+OnEditDeformedShape()
+{
   Handle(SALOME_InteractiveObject) anIO;
-  CORBA::Object_var anObject = GetSelectedObj(this, &anIO);
-  if (CORBA::is_nil(anObject)) return;
-  PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
-  if (!aServant.in()) return;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg, 1>(this, anIO, aPrs3d);
+}
 
-  VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
-  if (!aPrs3d) return;
+void
+VisuGUI::
+OnEditScalarMapOnDeformedShape()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::ScalarMapOnDeformedShape_i, VisuGUI_ScalarMapOnDeformedShapeDlg, 1>(this, anIO, aPrs3d);
+}
 
-  switch (aPrs3d->GetType()) {
-  case VISU::TMESH:
-    break;
-  case VISU::TSCALARMAP:
-    EditPrs3d<VISU::ScalarMap_i, VisuGUI_ScalarBarDlg>(this, aPrs3d);
-    break;
-  case VISU::TDEFORMEDSHAPE:
-    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg>(this, aPrs3d);
-    break;
-  case VISU::TCUTPLANES:
-    EditPrs3d<VISU::CutPlanes_i, VisuGUI_CutPlanesDlg>(this, aPrs3d);
-    break;
-  case VISU::TCUTLINES:
-    EditPrs3d<VISU::CutLines_i, VisuGUI_CutLinesDlg>(this, aPrs3d);
-    break;
-  case VISU::TISOSURFACE:
-    EditPrs3d<VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg>(this, aPrs3d);
-    break;
-  case VISU::TVECTORS:
-    EditPrs3d<VISU::Vectors_i, VisuGUI_VectorsDlg>(this, aPrs3d);
-    break;
-  case VISU::TSTREAMLINES:
-    EditPrs3d<VISU::StreamLines_i, VisuGUI_StreamLinesDlg>(this, aPrs3d);
-    break;
-  case VISU::TPLOT3D:
-    EditPrs3d<VISU::Plot3D_i, VisuGUI_Plot3DDlg>(this, aPrs3d);
-    break;
-  default:
-    return;
-  }
+void
+VisuGUI::
+OnEditCutPlanes()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::CutPlanes_i, VisuGUI_CutPlanesDlg, 0>(this, anIO, aPrs3d);
+}
 
-  if (SVTK_ViewWindow* vw = GetViewWindow())
-    vw->highlight(anIO, 1);
+void
+VisuGUI::
+OnEditCutLines()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::CutLines_i, VisuGUI_CutLinesDlg, 0>(this, anIO, aPrs3d);
 }
 
 void
 VisuGUI::
-OnEraseAll()
+OnEditIsoSurfaces()
 {
-  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();
-  }
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg, 1>(this, anIO, aPrs3d);
+}
+
+void
+VisuGUI::
+OnEditVectors()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::Vectors_i, VisuGUI_VectorsDlg, 1>(this, anIO, aPrs3d);
+}
+
+void
+VisuGUI::
+OnEditStreamLines()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::StreamLines_i, VisuGUI_StreamLinesDlg, 1>(this, anIO, aPrs3d);
 }
 
+void
+VisuGUI::
+OnEditPlot3D()
+{
+  Handle(SALOME_InteractiveObject) anIO;
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::Plot3D_i, VisuGUI_Plot3DDlg, 0>(this, anIO, aPrs3d);
+}
+
+
 void
 VisuGUI::
 OnMakeSurfaceframe()
@@ -828,6 +847,20 @@ OnMakeShrink()
   ChangeRepresentation(this, VISU::SHRINK);
 }
 
+void
+VisuGUI::
+OnSetShadingOn()
+{
+  SetShading(this, true);
+}
+
+void
+VisuGUI::
+OnSetShadingOff()
+{
+  SetShading(this, false);
+}
+
 void
 VisuGUI::
 OnChangeColor()
@@ -841,7 +874,7 @@ OnChangeColor()
   VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrs3d) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrs3d, vw);
@@ -913,7 +946,7 @@ OnChangeWireframeColor()
   VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrs3d) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrs3d, vw);
@@ -948,31 +981,14 @@ OnChangeOpacity()
   VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(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
@@ -988,7 +1004,7 @@ OnChangeLines()
   VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrsObject, vw);
@@ -1070,12 +1086,12 @@ VisuGUI::
 OnDeleteObjects()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   SALOME_ListIO aList;
-  SalomeApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects(aList);
+  LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
+  mgr->selectedObjects(aList,QString::null,false);
   int i = 0, nbSelected = aList.Extent();
   if (nbSelected < 1) return;
 
@@ -1097,14 +1113,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
@@ -1134,7 +1148,7 @@ OnPlotData()
               aName = anAttr;
               SOName = QString( aName->Value().c_str() );
             }
-            SPlot2d_SetupPlot2dDlg* dlg = new SPlot2d_SetupPlot2dDlg( SO, GetDesktop( this ) );
+            VisuGUI_SetupPlot2dDlg* dlg = new VisuGUI_SetupPlot2dDlg( SO, GetDesktop( this ) );
             if ( dlg->exec() == QDialog::Accepted ) {
               if ( !IsStudyLocked( aStudy ) ) {
                 // if study is not locked - create new container, create curves and insert them
@@ -1204,7 +1218,7 @@ OnPlotData()
         aName = anAttr;
         SOName = QString( aName->Value().c_str() );
       }
-      SPlot2d_SetupPlot2dDlg* dlg = new SPlot2d_SetupPlot2dDlg( SO, GetDesktop( this ) );
+      VisuGUI_SetupPlot2dDlg* dlg = new VisuGUI_SetupPlot2dDlg( SO, GetDesktop( this ) );
       if ( dlg->exec() == QDialog::Accepted ) {
         if ( !IsStudyLocked( aStudy ) ) {
           // if study is not locked - create new table and container objects, create curves
@@ -1267,7 +1281,7 @@ void
 VisuGUI::
 OnCurveProperties()
 {
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
   if (aListIO.Extent() != 1) return;
@@ -1310,7 +1324,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);
@@ -1358,14 +1372,14 @@ VisuGUI::
 OnSaveViewParams()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   SUIT_ViewManager* aViewMgr = getApp()->activeViewManager();
   if (aViewMgr->getType() != SVTK_Viewer::Type())
     return;
 
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
   if (aListIO.Extent() > 1)
@@ -1388,7 +1402,7 @@ OnRestoreViewParams()
   if (aViewMgr->getType() != SVTK_Viewer::Type())
     return;
 
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
   if (aListIO.Extent() != 1)
@@ -1398,7 +1412,8 @@ OnRestoreViewParams()
   //jfa tmp:VISU::View3D_i::RestoreViewParams(aViewMgr, anIO->getName());
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));//jfa tmp
   _PTR(SObject) aSObj = aCStudy->FindObjectID(anIO->getEntry());//jfa tmp
-  VISU::View3D_i::RestoreViewParams(aViewMgr, aSObj->GetName().c_str());//jfa tmp
+  if ( aSObj )
+    VISU::View3D_i::RestoreViewParams(aViewMgr, aSObj->GetName().c_str());//jfa tmp
 }
 
 void
@@ -1406,7 +1421,7 @@ VisuGUI::
 OnRename()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   Handle(SALOME_InteractiveObject) anIO;
@@ -1416,8 +1431,9 @@ OnRename()
   if (!aSObj) return;
 
   //TEST DU PARENT == VISU
-  _PTR(GenericAttribute) anAttr;
-  if (aSObj->FindAttribute(anAttr, "AttributeName")) {
+  _PTR(StudyBuilder) aBuilder = aCStudy->NewBuilder();
+  _PTR(GenericAttribute) anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
+  if (anAttr) {
     _PTR(AttributeName) aName (anAttr);
     QString Name = VisuGUI_NameDlg::getName( GetDesktop( this ), aName->Value().c_str() );
     if (!Name.isEmpty()) {
@@ -1471,6 +1487,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();
@@ -1499,7 +1529,7 @@ OnSweep()
   VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* aActor = GetActor(aPrsObject, vw);
@@ -1520,20 +1550,20 @@ OnSweep()
 
   // Sweep
   QApplication::setOverrideCursor(Qt::waitCursor);
-  try {
-    for (int j = 0; j < aCycles; j++) {
-      for (int i = 0; i <= aSteps; i++) {
+  for (int j = 0; j < aCycles; j++) {
+    for (int i = 0; i <= aSteps; i++) {
+      try {
         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());
+      } catch (...) {
+        INFOS("Unknown exception was occured!");
       }
     }
-  } catch (std::exception& exc) {
-    INFOS("Follow exception was occured :\n" << exc.what());
-  } catch (...) {
-    INFOS("Unknown exception was occured!");
   }
   QApplication::restoreOverrideCursor();
 }
@@ -1542,12 +1572,14 @@ void
 VisuGUI::
 OnTimeAnimation()
 {
+  if (!VISU::GetActiveViewWindow<SVTK_ViewWindow>(this))
+    return;
+
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
   VisuGUI_TimeAnimationDlg* aAnimationDlg =
-//    new VisuGUI_TimeAnimationDlg(GetDesktop(this), aCStudy);
     new VisuGUI_TimeAnimationDlg (this, aCStudy);
 
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -1579,7 +1611,10 @@ void
 VisuGUI::
 OnShowAnimation()
 {
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  if (!VISU::GetActiveViewWindow<SVTK_ViewWindow>(this))
+    return;
+
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -1616,7 +1651,7 @@ VisuGUI::
 OnCopyPresentation()
 {
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
-  if (CheckLock(aCStudy))
+  if (CheckLock(aCStudy,GetDesktop(this)))
     return;
 
   Handle(SALOME_InteractiveObject) anIO;
@@ -1634,7 +1669,6 @@ OnCopyPresentation()
       VISU::Mesh_i* aMeshPrs = dynamic_cast<VISU::Mesh_i*>(aPrsObject);
       VISU::Mesh_i* aSameMesh = new VISU::Mesh_i(aMeshPrs->GetResult());
       aSameMesh->SameAs(aMeshPrs);
-      UpdateViewer(this, aSameMesh);
     }
     break;
   case VISU::TSCALARMAP:
@@ -1642,7 +1676,6 @@ OnCopyPresentation()
       VISU::ScalarMap_i* aScalarPrs = dynamic_cast<VISU::ScalarMap_i*>(aPrsObject);
       VISU::ScalarMap_i* aSameScalar = new VISU::ScalarMap_i(aScalarPrs->GetResult(),true);
       aSameScalar->SameAs(aScalarPrs);
-      UpdateViewer(this, aSameScalar);
     }
     break;
   case VISU::TDEFORMEDSHAPE:
@@ -1650,7 +1683,15 @@ OnCopyPresentation()
       VISU::DeformedShape_i* aDefPrs = dynamic_cast<VISU::DeformedShape_i*>(aPrsObject);
       VISU::DeformedShape_i* aSameDeformed = new VISU::DeformedShape_i(aDefPrs->GetResult(),true);
       aSameDeformed->SameAs(aDefPrs);
-      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);
     }
     break;
   case VISU::TCUTPLANES:
@@ -1658,7 +1699,6 @@ OnCopyPresentation()
       VISU::CutPlanes_i* aCutPrs = dynamic_cast<VISU::CutPlanes_i*>(aPrsObject);
       VISU::CutPlanes_i* aSameCut = new VISU::CutPlanes_i(aCutPrs->GetResult(),true);
       aSameCut->SameAs(aCutPrs);
-      UpdateViewer(this, aSameCut);
     }
     break;
   case VISU::TCUTLINES:
@@ -1666,7 +1706,6 @@ OnCopyPresentation()
       VISU::CutLines_i* aCutPrs = dynamic_cast<VISU::CutLines_i*>(aPrsObject);
       VISU::CutLines_i* aSameCut = new VISU::CutLines_i(aCutPrs->GetResult(),true);
       aSameCut->SameAs(aCutPrs);
-      UpdateViewer(this, aSameCut);
     }
     break;
   case VISU::TISOSURFACE:
@@ -1674,7 +1713,6 @@ OnCopyPresentation()
       VISU::IsoSurfaces_i* aIsoPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aPrsObject);
       VISU::IsoSurfaces_i* aSameIso = new VISU::IsoSurfaces_i(aIsoPrs->GetResult(),true);
       aSameIso->SameAs(aIsoPrs);
-      UpdateViewer(this, aSameIso);
     }
     break;
   case VISU::TSTREAMLINES:
@@ -1682,7 +1720,6 @@ OnCopyPresentation()
       VISU::StreamLines_i* aLinesPrs = dynamic_cast<VISU::StreamLines_i*>(aPrsObject);
       VISU::StreamLines_i* aSameLines = new VISU::StreamLines_i(aLinesPrs->GetResult(),true);
       aSameLines->SameAs(aLinesPrs);
-      UpdateViewer(this, aSameLines);
     }
     break;
   case VISU::TVECTORS:
@@ -1690,7 +1727,6 @@ OnCopyPresentation()
       VISU::Vectors_i* aVectorsPrs = dynamic_cast<VISU::Vectors_i*>(aPrsObject);
       VISU::Vectors_i* aSameVectors = new VISU::Vectors_i(aVectorsPrs->GetResult(),true);
       aSameVectors->SameAs(aVectorsPrs);
-      UpdateViewer(this, aSameVectors);
     }
     break;
   case VISU::TPLOT3D:
@@ -1698,7 +1734,6 @@ OnCopyPresentation()
       VISU::Plot3D_i* aPlot3DPrs = dynamic_cast<VISU::Plot3D_i*>(aPrsObject);
       VISU::Plot3D_i* aSamePlot3D = new VISU::Plot3D_i(aPlot3DPrs->GetResult());
       aSamePlot3D->SameAs(aPlot3DPrs);
-      UpdateViewer(this, aSamePlot3D);
     }
     break;
   }
@@ -1709,8 +1744,8 @@ void
 VisuGUI::
 OnSelectionInfo()
 {
-  if (GetViewWindow())
-    (new VisuGUI_SelectionDlg(GetDesktop(this)))->show();
+  if (GetActiveViewWindow<SVTK_ViewWindow>(this))
+    (new VisuGUI_SelectionDlg(this))->show();
   else
     SUIT_MessageBox::warn1(GetDesktop(this),
                            tr("WRN_VISU"),
@@ -1718,30 +1753,11 @@ 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()
 {
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -1791,11 +1807,9 @@ OnMergeScalarBars()
     }
   }
   if (update) {
-    if (SVTK_ViewWindow* vw = GetViewWindow(this)) {
-//if (vw->getRenderer()->GetActors()->GetNumberOfItems() > 0) {
-        vw->getRenderer()->ResetCameraClippingRange();
-        vw->Repaint();
-//}
+    if (SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this)) {
+      vw->getRenderer()->ResetCameraClippingRange();
+      vw->Repaint();
     }
   }
 }
@@ -1804,7 +1818,7 @@ void
 VisuGUI::
 OnFreeScalarBars()
 {
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -1830,11 +1844,9 @@ OnFreeScalarBars()
     }
   }
   if (update) {
-    if (SVTK_ViewWindow* vw = GetViewWindow(this)) {
-//if (vw->getRenderer()->GetActors()->GetNumberOfItems() > 0) {
-        vw->getRenderer()->ResetCameraClippingRange();
-        vw->Repaint();
-//}
+    if (SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this)) {
+      vw->getRenderer()->ResetCameraClippingRange();
+      vw->Repaint();
     }
   }
 }
@@ -1848,7 +1860,7 @@ OnTranslatePrs()
 
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
 
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -1878,7 +1890,7 @@ void
 VisuGUI::
 OnArrangeActors()
 {
-  SVTK_ViewWindow* vw = GetViewWindow();
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (vw) {
     ArrangeDlg* aDlg = new ArrangeDlg (GetDesktop(this), vw);
     aDlg->exec();
@@ -1912,10 +1924,6 @@ createActions()
                 tr("MEN_IMPORT_FROM_FILE"), "", (CTRL + Key_I), aParent, false,
                 this, SLOT(OnImportFromFile()));
 
-  createAction( VISU_EXPLORE_MED, "", QIconSet(),
-                tr("MEN_EXPLORE_MED_FILE"), "", (CTRL + Key_M), aParent, false,
-                this, SLOT(OnExploreMEDFile()));
-
   createAction( VISU_IMPORT_TABLE, "", QIconSet(),
                 tr("MEN_IMPORT_TABLE"), "", 0, aParent, false,
                 this, SLOT(OnImportTableFromFile()));
@@ -1930,6 +1938,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,
@@ -2093,6 +2106,14 @@ createActions()
   createAction( VISU_UNSHRINK, tr("MEN_UNSHRINK"), QIconSet(),
                 tr("MEN_UNSHRINK"), "", 0, aParent, false,
                 this, SLOT(OnMakeShrink()));
+  
+  createAction( VISU_SHADING, tr("MEN_SHADING"), QIconSet(),
+                tr("MEN_SHADING"), "", 0, aParent, false,
+                this, SLOT(OnSetShadingOn()));
+  
+  createAction( VISU_NOSHADING, tr("MEN_NOSHADING"), QIconSet(),
+                tr("MEN_NOSHADING"), "", 0, aParent, false,
+                this, SLOT(OnSetShadingOff()));
 
   createAction( VISU_CELL_COLOR, tr("MEN_CELL_COLOR"), QIconSet(),
                 tr("MEN_CELL_COLOR"), "", 0, aParent, false,
@@ -2114,9 +2135,43 @@ createActions()
                 tr("MEN_LINE_WIDTH"), "", 0, aParent, false,
                 this, SLOT(OnChangeLines()));
 
-  createAction( VISU_EDIT_PRS, tr("MEN_EDIT_PRS"), QIconSet(),
+
+  createAction( VISU_EDIT_SCALARMAP, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditScalarMap()));
+
+  createAction( VISU_EDIT_DEFORMEDSHAPE, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditDeformedShape()));
+
+  createAction( VISU_EDIT_CUTPLANES, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditCutPlanes()));
+
+  createAction( VISU_EDIT_CUTLINES, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditCutLines()));
+
+  createAction( VISU_EDIT_ISOSURFACE, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditIsoSurfaces()));
+
+  createAction( VISU_EDIT_VECTORS, tr("MEN_EDIT_PRS"), QIconSet(),
                 tr("MEN_EDIT_PRS"), "", 0, aParent, false,
-                this, SLOT(OnEditPrs()));
+                this, SLOT(OnEditVectors()));
+
+  createAction( VISU_EDIT_STREAMLINES, tr("MEN_EDIT_PRS"), QIconSet(),
+                tr("MEN_EDIT_PRS"), "", 0, aParent, false,
+                this, SLOT(OnEditStreamLines()));
+
+  createAction( VISU_EDIT_PLOT3D, tr("MEN_EDIT_PRS"), QIconSet(),
+                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,
@@ -2148,25 +2203,13 @@ createActions()
   aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_GLOBAL_SELECTION"));
   createAction( VISU_GLOBAL_SELECTION, tr("MEN_GLOBAL_SELECTION"), QIconSet(aPixmap),
                 tr("MEN_GLOBAL_SELECTION"), "", 0, aParent, false,
-                //this, SLOT(OnEraseAll()));
                 this);
 
   aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_PARTIAL_SELECTION"));
   createAction( VISU_PARTIAL_SELECTION, tr("MEN_PARTIAL_SELECTION"), QIconSet(aPixmap),
                 tr("MEN_PARTIAL_SELECTION"), "", 0, aParent, false,
-                //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()));
@@ -2180,9 +2223,10 @@ createMenus()
   int aMenuId;
   aMenuId = createMenu( tr( "MEN_DESK_FILE" ), -1 );
   createMenu( separator(), aMenuId, -1, 10 );
-  createMenu( VISU_IMPORT_FROM_FILE, aMenuId, 10 ); // import from file
-  createMenu( VISU_EXPLORE_MED, aMenuId, 10 ); // explore MED file
-  createMenu( VISU_IMPORT_TABLE, aMenuId, 10 ); // import table
+  
+  int anImportId = createMenu( tr( "MEN_IMPORT" ), aMenuId, -1, 10 );
+  createMenu( VISU_IMPORT_FROM_FILE, anImportId ); // import from file
+  createMenu( VISU_IMPORT_TABLE, anImportId ); // import table
 
   aMenuId = createMenu( tr( "MEN_VISUALIZATION" ), -1, -1, 30 );
   createMenu( VISU_SCALAR_MAP, aMenuId, 10 ); // scalar map
@@ -2193,6 +2237,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
@@ -2206,8 +2251,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
@@ -2223,6 +2266,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 );
@@ -2231,8 +2275,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
@@ -2258,6 +2300,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
@@ -2265,7 +2308,15 @@ createPopupMenus()
   mgr->insert( action( VISU_CREATE_TABLE ), -1, -1, -1 ); // create table
 
   // edit
-  mgr->insert( action( VISU_EDIT_PRS ), -1, -1, -1 );
+  mgr->insert( action( VISU_EDIT_SCALARMAP ), -1, -1, -1 );
+  mgr->insert( action( VISU_EDIT_DEFORMEDSHAPE ), -1, -1, -1 );
+  mgr->insert( action( VISU_EDIT_CUTPLANES ), -1, -1, -1 );
+  mgr->insert( action( VISU_EDIT_CUTLINES ), -1, -1, -1 );
+  mgr->insert( action( VISU_EDIT_ISOSURFACE ), -1, -1, -1 );
+  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
@@ -2297,6 +2348,9 @@ createPopupMenus()
   mgr->insert( action( VISU_SURFACEFRAME ), parentId, -1, -1 ); // surfaceframe
   mgr->insert( action( VISU_SHRINK )      , parentId, -1, -1 ); // shrink
   mgr->insert( action( VISU_UNSHRINK )    , parentId, -1, -1 ); // unshrink
+  mgr->insert( separator(), parentId, -1, -1 );
+  mgr->insert( action( VISU_SHADING )     , parentId, -1, -1 ); // shading
+  mgr->insert( action( VISU_NOSHADING )   , parentId, -1, -1 ); // noshading
 
   // "Properties" submenu
   parentId = mgr->insert( tr( "MEN_PROPERTIES" ), -1, -1 );
@@ -2334,23 +2388,17 @@ createPopupMenus()
 
   // Rules
 
-  QString aSel_One_ObjBr  ("client='ObjectBrowser' and selcount=1");
-  QString aSel_Some_ObjBr ("client='ObjectBrowser' and selcount>0");
-  QString aSel_Many_ObjBr ("client='ObjectBrowser' and selcount>1");
-
   QString aPrsAll ("'VISU::TSCALARMAP' 'VISU::TISOSURFACE' 'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' "
-                   "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D'");
-
-  QString aCurveAll = "'VISU::TTABLE' 'VISU::TCURVE' 'VISU::TCONTAINER'";
+                   "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE'");
 
   // VISU root commands
-  QString aRule = aSel_One_ObjBr + " and type='VISU::TVISUGEN'";
+  QString aRule = "client='ObjectBrowser' and selcount=1 and type='VISU::TVISUGEN'";
   mgr->setRule( action( VISU_IMPORT_FROM_FILE ), aRule, true );
   mgr->setRule( action( VISU_IMPORT_TABLE ), aRule, true );
   mgr->setRule( action( VISU_PLOT2D ), aRule, true );
 
   // timestamp commands
-  aRule = aSel_One_ObjBr + " and type='VISU::TTIMESTAMP'";
+  aRule = "client='ObjectBrowser' and selcount=1 and type='VISU::TTIMESTAMP'";
   mgr->setRule( action( VISU_SCALAR_MAP ), aRule, true );
   mgr->setRule( action( VISU_ISO_SURFACES ), aRule, true );
   mgr->setRule( action( VISU_CUT_PLANES ), aRule, true );
@@ -2360,20 +2408,30 @@ 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 );
 
-  // table commands
-  //aRule = aSel_One_ObjBr + " and type='VISU::TTABLE'";
-  //mgr->setRule( action( VISU_SHOW_TABLE ), aRule, true );
-  //mgr->setRule( action( VISU_CREATE_CURVES ), aRule, true );
-  //mgr->setRule( action( VISU_EXPORT_TABLE ), aRule, true );
+  // display/erase commands
+  QString andInvisible = " and (((not isVisible) and isActiveView) or (not isActiveView))";
+  QString aTableOrCont = "(type='VISU::TTABLE' and nbChildren>0) or type='VISU::TCONTAINER'";
+  QString orCurveVisible   = "or (type='VISU::TCURVE' and isVisible)";
+  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 )";
 
-  aRule = "(" + aSel_Some_ObjBr + " and ((type='VISU::TTABLE' and nbChildren>0) or"
-          " ($type in {'VISU::TCURVE' 'VISU::TCONTAINER'}))"
-          ") or (selcount>0 and $type in {'VISU::TMESH' " + aPrsAll + "})";
+  QString anEraseRule = "( selcount>0 and ({true} in $canBeDisplayed) and (" + aPrsVisible +
+    " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveVisible + "))) ) or " + aComponent;
 
-  mgr->setRule( action( VISU_ERASE ), aRule + "and (isVisible=true)", true );// TODO: aRule.arg(" and isVisible=1"), true );
-  mgr->setRule( action( VISU_DISPLAY ), aRule + "and (isVisible=false)", true );// TODO: aRule.arg(" and isVisible=0"), true );
-  mgr->setRule( action( VISU_DISPLAY_ONLY ), aRule, true );
+  QString aDisplayRule = "( selcount>0 and ({true} in $canBeDisplayed) and (" + aPrsInvisible +
+    " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveInvisible + "))) ) or" + aComponent;
+
+  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'})))) ) or" + aComponent;
+
+  mgr->setRule( action( VISU_ERASE ), anEraseRule, true );
+  mgr->setRule( action( VISU_DISPLAY ), aDisplayRule, true );
+  mgr->setRule( action( VISU_DISPLAY_ONLY ), aDOnlyRule, true );
 
   aRule = "selcount>0 and $type in {'VISU::TMESH' " + aPrsAll + "}";
   mgr->setRule( action( VISU_TRANSLATE_PRS ), aRule, true );
@@ -2382,11 +2440,11 @@ createPopupMenus()
   mgr->setRule( action( VISU_MERGE_SCALAR_BARS ), aRule, true );
   mgr->setRule( action( VISU_FREE_SCALAR_BARS ), aRule, true );
 
-  // View parameters
-  aRule = "selcount=1 and type='VISU::TVIEW3D'";
+  // view parameters
+  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 );
@@ -2396,9 +2454,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 );
@@ -2419,6 +2477,9 @@ createPopupMenus()
   mgr->setRule( action( VISU_SHRINK )  , aRule + aShrinkType + " and isShrunk=0", true );
   mgr->setRule( action( VISU_UNSHRINK ), aRule + aShrinkType + " and isShrunk=1", true );
 
+  mgr->setRule( action( VISU_SHADING )  , aRule + " and isScalarMapAct=1 and isShading=0", true );
+  mgr->setRule( action( VISU_NOSHADING ), aRule + " and isScalarMapAct=1 and isShading=1", true );
+
   // "Properties" submenu
   mgr->setRule( action( VISU_CELL_COLOR ), aRule + " and type='VISU::TMESH' and representation='VISU::SURFACEFRAME'", true );
   mgr->setRule( action( VISU_EDGE_COLOR ), aRule + " and type='VISU::TMESH' and representation='VISU::SURFACEFRAME'", true );
@@ -2429,6 +2490,8 @@ createPopupMenus()
   mgr->setRule( action( VISU_LINE_WIDTH ), aRule + aLineType + " and hasActor=1", true );
 
   // rename command
+  QString aCurveAll = "'VISU::TTABLE' 'VISU::TCURVE' 'VISU::TCONTAINER'";
+
   aRule = "selcount=1 and ($type in {'VISU::TVIEW3D' 'VISU::TMESH' " + aCurveAll + " " + aPrsAll + "})";
   mgr->setRule( action( VISU_RENAME ), aRule, true );
 
@@ -2441,12 +2504,28 @@ createPopupMenus()
   mgr->setRule( action( VISU_CURVE_PROPS ), aRule, true );
 
   // curve container commands
-  aRule = aSel_One_ObjBr + " and type='VISU::TCONTAINER'";
+  aRule = "client='ObjectBrowser' and selcount=1 and type='VISU::TCONTAINER'";
   mgr->setRule( action( VISU_EDIT_CONTAINER ), aRule, true );
   mgr->setRule( action( VISU_CLEAR_CONTAINER ), aRule, true );
 
-  aRule = "selcount=1 and $type in {" + aPrsAll + "}";
-  mgr->setRule( action( VISU_EDIT_PRS ), aRule, true );
+  mgr->setRule( action( VISU_EDIT_SCALARMAP ),
+               "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 ),
+               "selcount=1 and type='VISU::TCUTLINES'", true );
+  mgr->setRule( action( VISU_EDIT_ISOSURFACE ),
+               "selcount=1 and type='VISU::TISOSURFACE'", true );
+  mgr->setRule( action( VISU_EDIT_VECTORS ),
+               "selcount=1 and type='VISU::TVECTORS'", true );
+  mgr->setRule( action( VISU_EDIT_STREAMLINES ),
+               "selcount=1 and type='VISU::TSTREAMLINES'", true );
+  mgr->setRule( action( VISU_EDIT_PLOT3D ),
+               "selcount=1 and type='VISU::TPLOT3D'", true );
 
   aRule = "selcount=1 and type='VISU::TCUTLINES' and nbNamedChildren=0";
   mgr->setRule( action( VISU_CREATE_TABLE ), aRule, true );
@@ -2454,11 +2533,14 @@ createPopupMenus()
   aRule = "selcount=1 and ($type in {" + aPrsAll + "})";
   mgr->setRule( action( VISU_SWEEP ), aRule, true );
 
-  // Selection info popup item
+  // "Selection info" popup item
   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'}";
@@ -2474,7 +2556,10 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
 {
   SalomeApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
 
-  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  OB_Browser* ob = getApp()->objectBrowser();
+  bool isOBClient = (ob && theClient == ob->popupClientType());
+
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
   SALOME_ListIO aListIO;
   aSelectionMgr->selectedObjects(aListIO);
 
@@ -2487,11 +2572,11 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
   SALOME_ListIteratorOfListIO It (aListIO);
   for (; It.More(); It.Next()) {
     Handle(SALOME_InteractiveObject)& anIO = It.Value();
-    /*std::vector<VISU::Prs3d_i*> aPrsList = GetPrs3dList(this, anIO);
-    nbPrs += aPrsList.size();*/
 
     if (!anIO.IsNull() && anIO->hasEntry()) {
       _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
+      if ( !aSObject )
+       continue;
       CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
       if (CORBA::is_nil(aCORBAObject)) {
         _PTR(GenericAttribute) anAttr;
@@ -2527,10 +2612,42 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
   theMenu->insertSeparator();
 
   // Check if some (nb > 0) removable objects selected
-  if (IsRemovableSelected(this)) {
+  if (isOBClient && IsRemovableSelected(this)) {
     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());
+      if ( !aSObject )
+       continue;
+      _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;
 
@@ -2539,39 +2656,42 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
   CORBA::Object_var anObject = GetSelectedObj( this, &anIO, &aMap);
 
   _PTR(SObject) SO = aCStudy->FindObjectID(anIO->getEntry());
+  if ( !SO )
+    return;
   bool isExist;
   VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
 
   if (aType == VISU::TANIMATION) {
     action( VISU_SHOW_ANIMATION )->addTo(theMenu);
 
-  } else if (IsSObjectTable(SO)) {
-    action( VISU_SHOW_TABLE )->addTo(theMenu);
-    action( VISU_CREATE_CURVES )->addTo(theMenu);
-    action( VISU_EXPORT_TABLE )->addTo(theMenu);
-    theMenu->insertSeparator();
-
-  } else {
-    if (!CORBA::is_nil(anObject)) {
-      SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(anObject);
-      if (!CORBA::is_nil(aMED.in())) {
-        action( VISU_IMPORT_MED_STRUCTURE )->addTo(theMenu);
-      }
-
-      SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(anObject); // "Import Structure"
-      if (!CORBA::is_nil(aField)) {
-        action( VISU_IMPORT_MED_TIMESTAMP )->addTo(theMenu); // "Import TimeStamp"
-      }
+  } else if (isOBClient) {
+    if (IsSObjectTable(SO)) {
+      action( VISU_SHOW_TABLE )->addTo(theMenu);
+      action( VISU_CREATE_CURVES )->addTo(theMenu);
+      action( VISU_EXPORT_TABLE )->addTo(theMenu);
+      theMenu->insertSeparator();
     } else {
-      _PTR(SObject) aSFather = SO->GetFather();
-      if (aSFather) {
-        _PTR(GenericAttribute) anAttr;
-        aSFather->FindAttribute(anAttr, "AttributeName");
-        if (anAttr) {
-          _PTR(AttributeName) aName (anAttr);
-          std::string aValue = aName->Value();
-          if (strcmp(aValue.c_str(), "MEDFIELD") == 0) {
-            action( VISU_IMPORT_MED_FIELD )->addTo(theMenu); // "Import Field"
+      if (!CORBA::is_nil(anObject)) {
+        SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(anObject);
+        if (!CORBA::is_nil(aMED.in())) {
+          action( VISU_IMPORT_MED_STRUCTURE )->addTo(theMenu);
+        }
+
+        SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(anObject); // "Import Structure"
+        if (!CORBA::is_nil(aField)) {
+          action( VISU_IMPORT_MED_TIMESTAMP )->addTo(theMenu); // "Import TimeStamp"
+        }
+      } else {
+        _PTR(SObject) aSFather = SO->GetFather();
+        if (aSFather) {
+          _PTR(GenericAttribute) anAttr;
+          aSFather->FindAttribute(anAttr, "AttributeName");
+          if (anAttr) {
+            _PTR(AttributeName) aName (anAttr);
+            std::string aValue = aName->Value();
+            if (strcmp(aValue.c_str(), "MEDFIELD") == 0) {
+              action( VISU_IMPORT_MED_FIELD )->addTo(theMenu); // "Import Field"
+            }
           }
         }
       }
@@ -2596,7 +2716,15 @@ VisuGUI::
 viewManagers( QStringList& theList ) const
 {
   theList.clear();
-  theList.append( SVTK_Viewer::Type() );
+  // append SVTK viewer only if there is neither SVTK nor VVTK is open
+  QPtrList<SUIT_ViewManager> lst;
+  getApp()->viewManagers( SVTK_Viewer::Type(), lst );
+  if ( !lst.count() ) {
+    lst.clear();
+    getApp()->viewManagers( VVTK_Viewer::Type(), lst );
+    if ( !lst.count() )
+      theList.append( SVTK_Viewer::Type() );
+  }
 }
 
 
@@ -2632,7 +2760,7 @@ deactivateModule( SUIT_Study* theStudy )
   return true;
 }
 
-SalomeApp_Selection*
+LightApp_Selection*
 VisuGUI::
 createSelection() const
 {
@@ -2645,7 +2773,7 @@ void VisuGUI::studyActivated()
   GetVisuGen(this)->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(this))));
 }
 
-
+/*
 extern "C" {
   CAM_Module*
   createModule()
@@ -2653,22 +2781,67 @@ extern "C" {
     return new VisuGUI();
   }
 }
+*/
 
 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, SalomeApp_Preferences::Font, "VISU", "scalar_bar_title_font" );
-  addPreference( tr( "VISU_TITLE" ), fontGr, SalomeApp_Preferences::Color, "VISU", "scalar_bar_title_color" );
-  int lfont = addPreference( tr( "VISU_LABELS" ), fontGr, SalomeApp_Preferences::Font, "VISU", "scalar_bar_label_font" );
-  addPreference( tr( "VISU_LABELS" ), fontGr, SalomeApp_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 );
@@ -2677,32 +2850,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, SalomeApp_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, SalomeApp_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, SalomeApp_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, SalomeApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_x" );
-  int yv = addPreference( tr( "VISU_Y" ), posVSizeGr, SalomeApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_y" );
-  int wv = addPreference( tr( "VISU_WIDTH" ), posVSizeGr, SalomeApp_Preferences::DblSpin, "VISU", "scalar_bar_vertical_width" );
-  int hv = addPreference( tr( "VISU_HEIGHT" ), posVSizeGr, SalomeApp_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 );
@@ -2716,11 +2899,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, SalomeApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_x" );
-  int yh = addPreference( tr( "VISU_Y" ), posHSizeGr, SalomeApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_y" );
-  int wh = addPreference( tr( "VISU_WIDTH" ), posHSizeGr, SalomeApp_Preferences::DblSpin, "VISU", "scalar_bar_horizontal_width" );
-  int hh = addPreference( tr( "VISU_HEIGHT" ), posHSizeGr, SalomeApp_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 );
@@ -2734,60 +2922,124 @@ 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, SalomeApp_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 );
-
-  addPreference( tr( "VISU_LOGARITHMIC_SCALING" ), rangeGr, SalomeApp_Preferences::Bool, "VISU", "scalar_bar_logarithmic" );
-
-  int rangetype = addPreference( tr( "VISU_RANGE_TO_USE" ), rangeGr, SalomeApp_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 );
+  // 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" );
 
-  int min = addPreference( tr( "VISU_MIN" ), imposedGr, SalomeApp_Preferences::DblSpin, "VISU", "scalar_range_min" );
-  int max = addPreference( tr( "VISU_MAX" ), imposedGr, SalomeApp_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, SalomeApp_Preferences::DblSpin, "VISU", "sweeping_time_step" );
-  int nbcycles   = addPreference( tr( "VISU_NB_CYCLES" ), sweepGr, SalomeApp_Preferences::IntSpin, "VISU", "sweeping_number_cycles" );
-  int nbsteps    = addPreference( tr( "VISU_NB_STEPS" ),  sweepGr, SalomeApp_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 );
-  addPreference( tr( "Full MED loading" ), importGr, SalomeApp_Preferences::Bool, "VISU", "full_med_loading" );
+  setPreferenceProperty( importGr, "columns", 1 );
+  addPreference( tr( "Use build progress" ), importGr, LightApp_Preferences::Bool, "VISU", "use_build_progress" );
+  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;
+  float aTol = 1.00000009999999;
+  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 > aTol){
+      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 > aTol){
+      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 > aTol){
+      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 > aTol){
+      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*
+VisuGUI
+::getViewManager(const QString& theType,
+                const bool theIsCreate)
+{
+  return getApp()->getViewManager(theType,theIsCreate);
+}
+
+TViewToPrs3d 
+VisuGUI
+::getScalarBarsMap()
+{
+  return myScalarBarsMap;
+}
+LightApp_Displayer* VisuGUI::displayer()
 {
+  if( !myDisplayer )
+    myDisplayer = new VisuGUI_Displayer( getApp() );
+    
+  return myDisplayer;
 }