Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI.cxx
index 3128e69f768cb59652dfe3761370166d33ebc732..3c2ad86737b9aaf2a87f8df20288fd1f937663c3 100644 (file)
@@ -73,6 +73,7 @@
 #include "SalomeApp_Application.h"
 #include "SalomeApp_DataModel.h"
 #include "SalomeApp_Study.h"
+#include "SalomeApp_CheckFileDlg.h"
 #include "LightApp_SelectionMgr.h"
 #include "LightApp_Selection.h"
 #include "LightApp_Preferences.h"
@@ -95,7 +96,6 @@
 
 #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_Timer.h"
 
+#include "VVTK_ViewModel.h"
+
 using namespace VISU;
 
 #ifdef _DEBUG_
@@ -172,55 +174,68 @@ OnImportFromFile()
   if(MYDEBUG) MESSAGE("VisuGUI::OnImportFromFile()");
   if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) )
     return;
+  
+  SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
 
-  VisuGUI_BuildProgressDlg* aBuildProgressDlg = new VisuGUI_BuildProgressDlg( GetDesktop(this) );
-  aBuildProgressDlg->setGenerator( GetVisuGen(this) );
-  aBuildProgressDlg->show();
-}
-
-
-void
-VisuGUI::
-OnExploreMEDFile()
-{
-  if(MYDEBUG) MESSAGE("VisuGUI::OnExploreMEDFile()");
-  _PTR(Study) aStudy = GetCStudy(GetAppStudy(this));
-  if ( CheckLock(aStudy,GetDesktop(this)) )
-    return;
-
-  SALOME_MED::MED_Gen_var aGen = GetMEDEngine();
-
+  // Get file name
   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();
-    try
+  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 )
     {
-      aGen->readStructFileWithFieldType(aFileInfo.filePath(),aStudyName.c_str());
+      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 );
+
+      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();
+      }
     }
-    catch(...)
+  else
     {
-      SUIT_MessageBox::warn1(GetDesktop(this),
-                             tr("WRN_VISU"),
-                             tr("ERR_ERROR_IN_THE_FILE"),
-                             tr("BUT_OK"));
+      VisuGUI_BuildProgressDlg* aBuildProgressDlg = new VisuGUI_BuildProgressDlg( GetDesktop(this) );
+      aBuildProgressDlg->setFileName( aFileInfo.filePath() );
+      aBuildProgressDlg->setGenerator( GetVisuGen(this) );
+      aBuildProgressDlg->show();
     }
-    application()->putInfo(aFileInfo.filePath()+tr("INF_DONE"));
-    getApp()->updateObjectBrowser(true); // as need to update MED tree
-    getApp()->updateActions();
-  }
 }
 
-
 void
 VisuGUI::
 OnImportTableFromFile()
@@ -472,9 +487,10 @@ OnCreateMesh()
     return;
 
   // create a VTK view window if it does not exist
-  GetViewWindow( this, /*create=*/true );
+  SVTK_ViewWindow* aViewWindow = GetViewWindow<SVTK_Viewer>(this);
 
-  CreateMesh(this, anIO);
+  // create mesh presentation and display it in aViewWindow
+  CreateMesh(this, anIO, aViewWindow);
 }
 
 void
@@ -486,7 +502,7 @@ OnCreateManyMesh()
     return;
 
   // create a VTK view window if it does not exist
-  GetViewWindow( this, /*create=*/true );
+  SVTK_ViewWindow* aViewWindow = GetViewWindow<SVTK_Viewer>(this);
 
   // Get selected SObject
   LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
@@ -498,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);
   }
 }
 
@@ -581,62 +598,65 @@ OnDisplayPrs()
 {
   if(MYDEBUG) MESSAGE("VisuGUI::OnDisplayPrs");
 
+  LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
+  if (!mgr) return;
+
   QApplication::setOverrideCursor(Qt::waitCursor);
+
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
+
   SALOME_ListIO aSel, aList;
-  LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects( aSel );
+  mgr->selectedObjects(aSel);
+  extractContainers(aSel, aList);
 
-  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());
 
-  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 ) ) {
+    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 );
-       SVTK_ViewWindow* vw = GetViewWindow( this, /*create=*/true );
-        if ( vw )
-       {
-         displayer()->Display( anIO->getEntry() );
+        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 );
-       displayer()->Display( anIO->getEntry() );
+       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 );
-       displayer()->Display( anIO->getEntry() );
+       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 );
-       displayer()->Display( anIO->getEntry() );
+       displayer()->Display(anIO->getEntry());
         continue;
       }
     }
   }
-  SVTK_ViewWindow* vw = GetViewWindow( this );
-  if ( vw ) {
+
+  if (vw) {
     vw->getRenderer()->ResetCameraClippingRange();
     vw->Repaint();
   }
+
   QApplication::restoreOverrideCursor();
 }
 
@@ -656,27 +676,24 @@ 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, aSel;
   LightApp_SelectionMgr* mgr = GetSelectionMgr(this);
-  mgr->selectedObjects( aSel );
+  mgr->selectedObjects(aSel);
+  extractContainers(aSel, aList);
 
-  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 );
+  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();
 }
@@ -686,7 +703,7 @@ VisuGUI::
 OnEraseAll()
 {
   startOperation( myEraseAll );
-  if (SVTK_ViewWindow* vw = GetViewWindow(this)) {
+  if (SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this)) {
     vw->unHighlightAll();
     if (vtkRenderer *aRen = vw->getRenderer()) {
       vtkActor *anActor;
@@ -694,7 +711,7 @@ OnEraseAll()
       for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ) {
         if (anActor->GetVisibility() > 0)
           if (VISU_Actor* anVISUActor = VISU_Actor::SafeDownCast(anActor)) {
-           RemoveScalarBarPosition(this,anVISUActor->GetPrs3d());
+           RemoveScalarBarPosition(this, vw, anVISUActor->GetPrs3d());
             anVISUActor->VisibilityOff();
           }
       }
@@ -711,26 +728,17 @@ VisuGUI::
 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(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  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;
-  if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg,1>(this, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg, 1>(this, anIO, aPrs3d);
 }
 
 void
@@ -738,12 +746,8 @@ 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);
-    }
-  }
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::ScalarMapOnDeformedShape_i, VisuGUI_ScalarMapOnDeformedShapeDlg, 1>(this, anIO, aPrs3d);
 }
 
 void
@@ -751,82 +755,53 @@ VisuGUI::
 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(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::CutPlanes_i, VisuGUI_CutPlanesDlg, 0>(this, anIO, aPrs3d);
 }
 
-
 void
 VisuGUI::
 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(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::CutLines_i, VisuGUI_CutLinesDlg, 0>(this, anIO, aPrs3d);
 }
 
-
 void
 VisuGUI::
 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(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  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, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  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, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  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, aPrs3d);
-    if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){
-      aViewWindow->highlight(anIO, 1);
-    }
-  }
+  if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO))
+    EditPrs3d<VISU::Plot3D_i, VisuGUI_Plot3DDlg, 0>(this, anIO, aPrs3d);
 }
 
 
@@ -899,7 +874,7 @@ OnChangeColor()
   VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrs3d) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow(this);
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrs3d, vw);
@@ -971,7 +946,7 @@ OnChangeWireframeColor()
   VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrs3d) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow(this);
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrs3d, vw);
@@ -1006,7 +981,7 @@ OnChangeOpacity()
   VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow(this);
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrsObject, vw);
@@ -1029,7 +1004,7 @@ OnChangeLines()
   VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow(this);
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* anActor = GetActor(aPrsObject, vw);
@@ -1437,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
@@ -1553,7 +1529,7 @@ OnSweep()
   VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(aServant.in());
   if (!aPrsObject) return;
 
-  SVTK_ViewWindow* vw = GetViewWindow(this);
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (!vw) return;
 
   VISU_Actor* aActor = GetActor(aPrsObject, vw);
@@ -1596,7 +1572,7 @@ void
 VisuGUI::
 OnTimeAnimation()
 {
-  if(!VISU::GetViewWindow(this))
+  if (!VISU::GetActiveViewWindow<SVTK_ViewWindow>(this))
     return;
 
   _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
@@ -1635,7 +1611,7 @@ void
 VisuGUI::
 OnShowAnimation()
 {
-  if(!VISU::GetViewWindow(this))
+  if (!VISU::GetActiveViewWindow<SVTK_ViewWindow>(this))
     return;
 
   LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
@@ -1693,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:
@@ -1701,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:
@@ -1709,15 +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);
+      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:
@@ -1725,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:
@@ -1733,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:
@@ -1741,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:
@@ -1749,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:
@@ -1757,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:
@@ -1765,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;
   }
@@ -1776,7 +1744,7 @@ void
 VisuGUI::
 OnSelectionInfo()
 {
-  if (GetViewWindow(this))
+  if (GetActiveViewWindow<SVTK_ViewWindow>(this))
     (new VisuGUI_SelectionDlg(this))->show();
   else
     SUIT_MessageBox::warn1(GetDesktop(this),
@@ -1839,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();
     }
   }
 }
@@ -1878,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();
     }
   }
 }
@@ -1926,7 +1890,7 @@ void
 VisuGUI::
 OnArrangeActors()
 {
-  SVTK_ViewWindow* vw = GetViewWindow(this);
+  SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(this);
   if (vw) {
     ArrangeDlg* aDlg = new ArrangeDlg (GetDesktop(this), vw);
     aDlg->exec();
@@ -1960,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()));
@@ -2243,13 +2203,11 @@ 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);
 
   createAction( VISU_SHOW_ANIMATION, tr("MEN_SHOW_ANIMATION"), QIconSet(),
@@ -2265,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
@@ -2616,6 +2575,8 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
 
     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;
@@ -2663,6 +2624,8 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
 
     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);
@@ -2693,6 +2656,8 @@ 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();
 
@@ -2751,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() );
+  }
 }
 
 
@@ -2974,6 +2947,7 @@ void VisuGUI::createPreferences()
   // group: "MED files import"
   int importGr = addPreference( tr( "MED files import" ), srangeTab );
   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" );
@@ -2993,11 +2967,12 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b)
   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 > 1.0){
+    if(sbX1+sbW > aTol){
       aWarning = "Origin and Size Vertical: X+Width > 1\n";
       sbX1=0.01;
       sbW=0.05;
@@ -3008,7 +2983,7 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b)
   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){
+    if(sbY1+sbH > aTol){
       aWarning = "Origin and Size Vertical: Y+Height > 1\n";
       sbY1=0.01;
       sbH=0.5;
@@ -3019,7 +2994,7 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b)
   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){
+    if(sbX1+sbW > aTol){
       aWarning = "Origin and Size Horizontal: X+Width > 1\n";
       sbX1=0.2;
       sbW=0.6;
@@ -3030,7 +3005,7 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b)
   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){
+    if(sbY1+sbH > aTol){
       aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
       sbY1=0.01;
       sbH=0.12;