Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/visu.git] / src / VISUGUI / VisuGUI.cxx
index 104eb6f32f4bc2162108b26965b843565690fbca..eb81af8ac08ee601a6babe536dcaf8384cad09bc 100644 (file)
 //  Module : VISU
 //  $Header$
 
-using namespace std;
 #include "VisuGUI.h"
-#include "VisuGUI_PhaseDlg.h"
+
+#include "VISU_Gen_i.hh"
+#include "VISU_Result_i.hh"
+#include "VISU_PrsObject_i.hh"
+#include "VISU_ViewManager_i.hh"
+
+#include "VISU_PipeLine.hxx"
+
+#include "VISU_Prs3d_i.hh"
+#include "VISU_Mesh_i.hh"
+#include "VISU_ScalarMap_i.hh"
+#include "VISU_IsoSurfaces_i.hh"
+#include "VISU_DeformedShape_i.hh"
+#include "VISU_CutPlanes_i.hh"
+#include "VISU_CutLines_i.hh"
+#include "VISU_Vectors_i.hh"
+#include "VISU_StreamLines_i.hh"
+#include "VISU_Table_i.hh"
+
+#include "VISU_Actor.h"
+#include "VISU_MeshAct.h"
+
 #include "VisuGUI_MagnitudeDlg.h"
-#include "VisuGUI_PhaseMagnitudeDlg.h"
-#include "VisuGUI_PartialScaDlg.h"
 #include "VisuGUI_CursorDlg.h"
 #include "VisuGUI_ScalarBarDlg.h"
 #include "VisuGUI_SweepPrefDlg.h"
@@ -40,21 +58,12 @@ using namespace std;
 #include "VisuGUI_VectorsDlg.h"
 #include "VisuGUI_IsoSurfacesDlg.h"
 #include "VisuGUI_StreamLinesDlg.h"
+#include "VisuGUI_EditContainerDlg.h"
 #include "VisuGUI_TimeAnimation.h"
 
 #include "VisuGUI_Selection.h"
-#include "VisuGUI_VisuAsDlg.h"
-#include "VisuGUI_SelVectCompDlg.h"
 #include "VisuGUI_NonIsometricDlg.h"
 
-#include "VISU_Gen_i.hh"
-#include "VISU_Result_i.hh"
-#include "VISU_Extractor.hxx"
-#include "VISU_Table_i.hh"
-#include "VISU_ViewManager_i.hh"
-#include "VISU_LookupTable.hxx"
-#include "VISU_ScalarBarActor.hxx"
-
 #include "SALOMEGUI_ImportOperation.h"
 #include "SALOMEGUI_QtCatchCorbaException.hxx"
 #include "utilities.h"
@@ -78,9 +87,14 @@ using namespace std;
 #include "SALOMEGUI_TableDlg.h"
 #include "SALOMEGUI_SetupCurveDlg.h"
 #include "SALOMEGUI_SetValueDlg.h"
+#include "SALOMEGUI_Desktop.h"
 #include "Plot2d_SetupPlot2dDlg.h"
 #include "Plot2d_ViewFrame.h"
 #include "VTKViewer_ViewFrame.h"
+#include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_InteractorStyleSALOME.h"
+#include "VTKViewer_RenderWindowInteractor.h"
+#include "VisuGUI_FileDlg.h"
 
 // QT Includes
 #define  INCLUDE_MENUITEM_DEF
@@ -97,6 +111,7 @@ using namespace std;
 #include <qthread.h>
 #include <qlistbox.h>
 #include <qcombobox.h>
+#include <qregexp.h> 
 
 //VRV: porting on Qt 3.0.5
 #if QT_VERSION >= 0x030005
@@ -106,10 +121,12 @@ using namespace std;
 #include <qmessagebox.h>
 
 #include <med.h>
-#include CORBA_CLIENT_HEADER(Med_Gen)
+#include CORBA_CLIENT_HEADER(MED_Gen)
 
 #include <vtkActor.h>
+#include <vtkRenderer.h>
 #include <vtkDataSetMapper.h>
+#include <vtkActorCollection.h>
 
 // Open CASCADE Include
 #include <TCollection_AsciiString.hxx>
@@ -122,7 +139,9 @@ static int MYCHECKTIME = 0;
 #endif
 #include <Utils_Timer.hxx>
 
-#ifdef DEBUG
+using namespace std;
+
+#ifdef _DEBUG_
 static int MYDEBUG = 0;
 static int MYDEBUGWITHFILES = 0;
 #else
@@ -151,14 +170,97 @@ private:
   QFont font;
 };
 
+
+inline bool IsSObjectTable(SALOMEDS::SObject_ptr theSObject){
+  if(!theSObject->_is_nil()) {
+    SALOMEDS::GenericAttribute_var anAttr;
+    if(theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
+      return true;
+    if(theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
+      return true;
+  }  
+  return false;
+}
+
+
 static VisuGUI MYVISUGUI;
-static VisuGUI *visuGUI = &MYVISUGUI;
+VisuGUI *visuGUI = &MYVISUGUI;
 
 VISU::VISU_Gen_i* VisuGUI::GetVisuGen(){
   VISU::VISU_Gen_i::GetVisuGenImpl()->SetCurrentStudy(GetStudyDocument());
   return VISU::VISU_Gen_i::GetVisuGenImpl();
 }
 
+static int ComputeVisiblePropBounds(VTKViewer_ViewFrame* theViewFrame, float allBounds[6], 
+                                   const char* theActorClassName = "VISU_Actor")
+{
+  vtkRenderer *aRen = theViewFrame->getRenderer();
+  vtkActorCollection *anActColl = aRen->GetActors(); 
+  vtkProp    *prop;
+  float      *bounds;
+  int        nothingVisible=1;
+
+  allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
+  allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
+  // loop through all props
+  for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ){
+    // if it's invisible, or has no geometry, we can skip the rest 
+    if ( prop->GetVisibility() && prop->IsA(theActorClassName)){
+      bounds = prop->GetBounds();
+      // make sure we haven't got bogus bounds
+      if ( bounds != NULL &&
+           bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
+           bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
+           bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT )
+        {
+         nothingVisible = 0;
+         if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
+         if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
+         if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
+         if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
+         if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
+         if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
+        }//not bogus
+      }
+    }  
+  return nothingVisible;
+}
+
+VisuGUI::CameraOrient VisuGUI::SetFitAll(VTKViewer_ViewFrame* theViewFrame){ 
+  static float PRECISION = 0.000001;
+  static float DEVIATION = 600;
+  float XYZ_Bnd[6];
+  if(ComputeVisiblePropBounds(theViewFrame,XYZ_Bnd)) return e3D;
+
+  float absX = XYZ_Bnd[1]-XYZ_Bnd[0];
+  float absY = XYZ_Bnd[3]-XYZ_Bnd[2];
+  
+  float absZ = XYZ_Bnd[5]-XYZ_Bnd[4];
+  
+  CameraOrient aCameraOrient = e3D;
+  if(absX <= PRECISION) aCameraOrient = eFront;
+  else {if(absY <= PRECISION) aCameraOrient = eLeft;
+  else {if(absZ <= PRECISION) aCameraOrient = eTop;}}
+  
+    float dev_abs_XY = absX / absY;
+    float dev_abs_YZ = absY / absZ;
+    float dev_abs_XZ = absX / absZ;
+    if(dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION) aCameraOrient = eLeft;
+    else{if(1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION) aCameraOrient = eFront; 
+    else {if(dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION) aCameraOrient = eTop;}}  
+  switch(aCameraOrient){
+  case eFront: theViewFrame->onViewFront();  break;
+  case eLeft:  theViewFrame->onViewLeft();   break;
+  case eTop:   theViewFrame->onViewTop();    break;
+  case e3D:    theViewFrame->onViewReset();  break; 
+  }
+  theViewFrame->getRenderer()->ResetCameraClippingRange();
+  theViewFrame->onViewFitAll();
+  return aCameraOrient;
+}
 QAD_Desktop* VisuGUI::GetDesktop(){
   return QAD_Application::getDesktop() ;
 }
@@ -178,6 +280,27 @@ VTKViewer_ViewFrame* VisuGUI::GetVtkViewFrame(){
   return dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
 }
 
+static void UpdateViewFrame() {
+  QList<QAD_StudyFrame> aFrameList = VisuGUI::GetActiveStudy()->getStudyFrames();
+
+  for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
+    if (aStudyFrame->getTypeView() == VIEW_VTK) {
+      QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
+      VTKViewer_ViewFrame* aVtkViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
+      if (!aVtkViewFrame) continue;
+      VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
+      if (anInteractor) {
+       anInteractor->SetSelectionProp();
+       anInteractor->SetSelectionTolerance();
+       VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
+       if (aStyle) {
+         aStyle->setPreselectionProp();
+       }
+      }
+    }
+  }
+}
+
 SALOMEDS::Study_var VisuGUI::GetStudyDocument(){
   return GetActiveStudy()->getStudyDocument();
 }
@@ -252,42 +375,11 @@ void RepaintCurrentView(){
   if(VTKViewer_ViewFrame* vf = VisuGUI::GetVtkViewFrame()) vf->Repaint();
 }
 
-/**
- * Returns selected sclalar mode or -1 if it was cancelled
- */
-int GetScalarMode(VISU::Result_i* theResult, const char* theFieldName){
-  int aScalarMode = 0;
-//  const VISU::TField* aField = theResult->GetInput()->GetField(theFieldName);
-//  if(aField->myNbComp > 1){
-//    VisuGUI_SelVectCompDlg* SelCompDlg = new VisuGUI_SelVectCompDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
-//    if(SelCompDlg->exec()){
-//     aScalarMode = SelCompDlg->whatIsChecked();
-//    } else {
-//     aScalarMode = -1;
-//    }
-//    delete SelCompDlg;
-//  }
-  return aScalarMode;
-}  
-
-
-VisuGUI::VisuGUI(){}
-
-
-VisuGUI* VisuGUI::GetOrCreateVisuGUI( QAD_Desktop* desktop ){
-  if(!visuGUI){
-    static VisuGUI VISUGUI;
-    visuGUI = &VISUGUI;
-  }
-  return visuGUI;
-}
 
-/* ********************************************************************************* */
-/* Function to return VisuGUI object                                                */
-/* ********************************************************************************* */
-VisuGUI* VisuGUI::GetVisuGUI( )
-{
-       return VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
+VisuGUI::VisuGUI( const QString& theName, QObject* theParent ): 
+  SALOMEGUI( theName, theParent ) 
+{    
+  mySelectionDlg = 0;
 }
 
 /* ==================================================================================== */
@@ -303,7 +395,7 @@ static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
 static int checkLock(const SALOMEDS::Study_var& theStudy) {
   if (isStudyLocked(theStudy)) {
     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
-                          QObject::tr("WARNING"), 
+                          QObject::tr("WRN_WARNING"), 
                           QObject::tr("WRN_STUDY_LOCKED"),
                           QObject::tr("BUT_OK") );
     return true;
@@ -316,38 +408,20 @@ static int checkLock(const SALOMEDS::Study_var& theStudy) {
 bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
 {
   try{
-  VisuGUI::GetOrCreateVisuGUI(parent);
-  QString VisuInputDir = getVisuInputDir();
-  QString VisuOutputDir = getVisuOutputDir();
-  vtkRenderer *theRenderer = GetRenderer();
-
-  SALOMEDS::Study_var aStudy = GetActiveStudy()->getStudyDocument(); //Document OCAF de l'etude active
-  SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
-  SALOMEDS::GenericAttribute_var anAttr;
-  SALOMEDS::AttributeName_var    aName;
-  SALOMEDS::AttributeIOR_var     anIOR;
-
-  switch (theCommandID)
-    {
-       /* ======================================================================================== */
-       /* Define Selection Mode                                                                  */
-       /* ======================================================================================== */
-    case 101:
-    case 102:
-    case 103:
-    case 104:
-      {
-       QApplication::setOverrideCursor( Qt::waitCursor );
-       int mode  = theCommandID - 100; // Point, Edge, Cell, Actor     
-       parent->SetSelectionMode( mode );
-       QApplication::restoreOverrideCursor();
-      }
-      break;
-      
+    QString VisuInputDir = getVisuInputDir();
+    QString VisuOutputDir = getVisuOutputDir();
+    vtkRenderer *theRenderer = GetRenderer();
+    
+    SALOMEDS::Study_var aStudy = GetActiveStudy()->getStudyDocument(); //Document OCAF de l'etude active
+    SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+    SALOMEDS::GenericAttribute_var anAttr;
+    SALOMEDS::AttributeName_var    aName;
+    SALOMEDS::AttributeIOR_var     anIOR;
+    
+    switch (theCommandID){
       /* ======================================================================================== */
       /* Import Table from file                                                                  */
       /* ======================================================================================== */
-
     case 199:
       {
        if(checkLock(aStudy)) break;
@@ -359,9 +433,14 @@ bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
       /* Import Mesh from MED, DAT file                                                                  */
       /* ======================================================================================== */
 
+    case 111:
+      {
+       visuGUI->CopyAndImportFile();
+       break;
+      }
     case 112:
       {
-       visuGUI->ImportFromFile();
+       visuGUI->ImportFile();
        break;
       }
 
@@ -407,53 +486,10 @@ bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
       visuGUI->CreateStreamLines();
       break;
 
-      /* ======================================================================================================================= */
-      /* View Scalar Animation (Animation/scalar)                                                                               */
-      /* With Phase                                                                                                             */
-      /* ======================================================================================================================= */
-
-      //case 4021 :
-      //case 4022 :
-      //case 4023 :
-
-      /* ========================================================================================================================= */
-      /* Selection - Cell  by number                                                                                              */
-      /* ========================================================================================================================= */
-
     case 4111 :
-      visuGUI->SelectCell();
-      break;
-
-      /* ========================================================================================================================= */
-      /* Selection - Cell - information attribute                                                                                 */
-      /* ========================================================================================================================= */
-
-    case 4112 :
-      visuGUI->InfoOnCell();
-      break;
-
-      /* ========================================================================================================================= */
-      /* Selection - Point - information number                                                                                           */
-      /* ========================================================================================================================= */
-
-    case 4121 :
-      visuGUI->SelectPoint();
-      break;
-
-      /* ========================================================================================================================= */
-      /* Selection - Point - information attribute                                                                                */
-      /* ========================================================================================================================= */
-
-    case 4122 :
-      visuGUI->InfoOnPoint();
+      visuGUI->SelectionInfo();
       break;
 
-      /* ========================================================================================================================= */
-      /* Selection - Shape                                                                                                        */
-      /* ========================================================================================================================= */
-
-      //case 413 :
-
       /* ========================================================================================================================= */
       /* Visualization - Wireframe                                                                                                */
       /* ========================================================================================================================= */
@@ -532,22 +568,22 @@ bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
 
     case 8041 : // Object representation : Wireframe
     case 9041 : // Object representation : Wireframe
-      visuGUI->ChangeRepresentation(WIREFRAME);
+      visuGUI->ChangeRepresentation(VISU::WIREFRAME);
       break;
 
     case 8042 : // Object representation : Surface
     case 9042 : // Object representation : Surface
-      visuGUI->ChangeRepresentation(SURFACE);
+      visuGUI->ChangeRepresentation(VISU::SHADED);
       break;
 
     case 8043 : // Object representation : Points
     case 9043 : // Object representation : Points
-      visuGUI->ChangeRepresentation(POINTS);
+      visuGUI->ChangeRepresentation(VISU::POINT);
       break;
 
     case 8044 : // Object representation : Shrink/Unshrink
     case 9044 : // Object representation : Shrink/Unshrink
-      visuGUI->ChangeRepresentation(SHRINK);
+      visuGUI->ChangeRepresentation(VISU::SHRINK);
       break;
 
     case 8051 : // Change object color
@@ -587,15 +623,35 @@ bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
        SetSweepingPreferences();
       }
       break;
-      
+
+/* ======================================================================================== */
+/* Preferences for Full loading                                                             */
+/* ======================================================================================== */
+    case 53:
+    case 54:
+      {
+       QMenuData* pp;
+       QMenuItem* item = parent->menuBar()->findItem(theCommandID,&pp);
+       bool check = !pp->isItemChecked(theCommandID);
+       pp->setItemChecked(theCommandID,check);
+       switch(theCommandID){
+       case 53:
+         QAD_CONFIG->addSetting( "Visu:BuildResult", check );
+         break;
+       case 54:
+         QAD_CONFIG->addSetting( "Visu:BuildDefaultPrs3d", check );
+         break;
+       }
+      }
+      break;
 
     case 113: // Load MED using MED component
       {
        if (checkLock(GetStudyDocument())) break;
 
-       Engines::Component_var aMedComp = GetDesktop()->getEngine("FactoryServer", "Med");
+       Engines::Component_var aMedComp = GetDesktop()->getEngine("FactoryServer", "MED");
        if (CORBA::is_nil(aMedComp)) return false;
-       Engines::Med_Gen_var aMedGen = Engines::Med_Gen::_narrow(aMedComp);
+       SALOME_MED::MED_Gen_var aMedGen = SALOME_MED::MED_Gen::_narrow(aMedComp);
        if (CORBA::is_nil(aMedGen)) return false;
 
        QStringList filtersList ;       
@@ -622,11 +678,25 @@ bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
                              tr ("VISU_BUT_OK") );
       break;
     } 
+  } catch (const std::bad_alloc& e ) { 
+    INFOS("bad_alloc exception is caught "<<e.what());
+    QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                         tr("ERR_NO_MEMORY") + " " + tr(e.what()),
+                         tr("VISU_BUT_OK") );
+    return false;
+    }
+  catch (std::exception& e){
+    INFOS(e.what());
+    QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                         tr(e.what()),
+                         tr("VISU_BUT_OK") );
   }catch (const SALOME::SALOME_Exception& S_ex) {
+    INFOS("const SALOME::SALOME_Exception& S_ex");
     QtCatchCorbaException(S_ex);
     return false;
   }
   catch(...) {
+    INFOS(tr("ERR_UNKNOWN_EXCEPTION").latin1());
     QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
                          tr("ERR_UNKNOWN_EXCEPTION"),
                          tr("VISU_BUT_OK") );
@@ -635,27 +705,13 @@ bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
   return true;
 }
 
+void VisuGUI::SelectionInfo() {
+  mySelectionDlg = new VisuGUI_SelectionDlg();
+  mySelectionDlg->show();
+}
 
-/* ********************************************************************************* */
-/* Function to find Actor in Viewer                                                 */
-/* ********************************************************************************* */
-
-
-VISU_Actor *VisuGUI::GetActor(int* theSelectionType){
-  VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d();
-  if (!aPrs3d) return NULL;
-
-  VTKViewer_ViewFrame* vf = VisuGUI::GetVtkViewFrame();
-  if(!vf) return NULL;
 
-  if(theSelectionType){
-    QAD_Study *aStudy = QAD_Application::getDesktop()->getActiveStudy();
-    SALOME_Selection *aSel = SALOME_Selection::Selection(aStudy->getSelection());
-    *theSelectionType = aSel->SelectionMode();
-  }
 
-  return GetActor(aPrs3d,vf);
-}
 
 /* ********************************************************************************** */
 /* Function ShowTrihedron                                                             */
@@ -675,7 +731,7 @@ void VisuGUI::ShowTrihedron(bool ShowThd){
 /* ********************************************************************************** */
 
 VisuGUI::~VisuGUI(){
-  MESSAGE("VisuGUI::~VisuGUI");
+  if(MYDEBUG) MESSAGE("VisuGUI::~VisuGUI");
 }
                        
 /* ********************************************************************************** */
@@ -684,34 +740,31 @@ VisuGUI::~VisuGUI(){
 /* ********************************************************************************** */
 
 void VisuGUI::ChangeViewer(int theType){
-  VTKViewer_ViewFrame* vf = GetVtkViewFrame();
-  if (!vf) return;
-
-  vtkActor *anActor;
-  vtkRenderer *aRen = vf->getRenderer();
-  vtkActorCollection *anActColl = aRen->GetActors();
-  for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
-    if(anActor->IsA("VISU_Actor")){ 
-      VISU_Actor* anVISUActor = VISU_Actor::SafeDownCast(anActor);
-      if(anVISUActor->GetVisibility() > 0)
-       if(theType > 0)
-         anVISUActor->SetRepresentation(theType); 
-       else if(theType == -1)
-         anVISUActor->VisibilityOff();
-       else
-         anVISUActor->VisibilityOn();
+  if(theType < 0 ) 
+    GetActiveStudy()->unHighlightAll();
+  if(vtkRenderer *aRen = 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();
+         if(theType >= 0)
+           anVISUActor->SetRepresentation(theType); 
+         else
+           anVISUActor->VisibilityOff();
+       }
     }
+    RepaintCurrentView();
   }
 }
 
-
 // -----------------------------------------------------------------------------------------
 // EVENTS
 // -----------------------------------------------------------------------------------------
 
 bool VisuGUI::OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
 {
-  VisuGUI::GetOrCreateVisuGUI(parent);
   return true;
 }
 
@@ -719,7 +772,6 @@ bool VisuGUI::OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame
 
 bool VisuGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
 {
-  VisuGUI::GetOrCreateVisuGUI(parent);
   return true;
 }
 
@@ -727,17 +779,16 @@ bool VisuGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame*
 
 bool VisuGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
 {
-  VisuGUI::GetOrCreateVisuGUI(parent);
   if (GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK) // true = Viewer OCC
     return false;
 
-  MESSAGE ( "VisuGUI::onKeyPress : " << pe->key() )
+  if(MYDEBUG) MESSAGE( "VisuGUI::onKeyPress : " << pe->key() )
 
   switch ( pe->key() )
     {
     case Key_Escape :
       {
-         MESSAGE("--> Key : Escape")
+         if(MYDEBUG) MESSAGE("--> Key : Escape")
          return true;    
       }
     default :
@@ -753,7 +804,6 @@ bool VisuGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* st
 // Slot-functions for presentations creation
 //=====================================================================================
 
-
 #define CREATEPRESENTATION(FunctionName)  \
  void FunctionName() { \
    if (checkLock(GetStudyDocument())) return; \
@@ -780,14 +830,32 @@ CREATEPRESENTATION(VisuGUI::CreateStreamLines);
 
 
 
-
 //=====================================================================================
-// function : setSettings()
+// function : SetSettings()
 // purpose  :
 //=====================================================================================
-bool VisuGUI::setSettings(QAD_Desktop* parent)
+bool VisuGUI::SetSettings(QAD_Desktop* parent)
 {
-  VisuGUI::GetOrCreateVisuGUI(parent);
+  int anId = 53;
+  QMenuData* pp;
+  QMenuItem* item = parent->menuBar()->findItem(anId,&pp);
+  QString aValue = QAD_CONFIG->getSetting("Visu:BuildResult");
+  
+  if(aValue.isEmpty()? 0 : aValue.toInt()) 
+    pp->setItemChecked(anId, true);
+  
+  anId = 54;
+  item = parent->menuBar()->findItem(anId,&pp);
+  aValue  = QAD_CONFIG->getSetting("Visu:BuildDefaultPrs3d");
+  
+  if(aValue.isEmpty()? 0 : aValue.toInt()) 
+    pp->setItemChecked(anId, true);
+  
+  anId = 50;
+  parent->menuBar()->changeItem(anId,parent->getComponentUserName("VISU"));
+
+  ::UpdateViewFrame();
+
   return true;
 }
 
@@ -796,14 +864,14 @@ bool VisuGUI::setSettings(QAD_Desktop* parent)
 // purpose  :
 //=====================================================================================
 void VisuGUI::DisplayPrs() {
-  MESSAGE("VisuGUI::DisplayPrs");
+  if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs");
   Handle(SALOME_InteractiveObject) anIO;
   CORBA::Object_var anObject = GetSelectedObj(&anIO);
   if ( !CORBA::is_nil( anObject ) ) {
     // is it Prs3d object ?
-    VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
+    VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject).in());
     if(aPrsObject){
-      MESSAGE("VisuGUI::DisplayPrs : Prs3d object");
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Prs3d object");
       UpdateViewer(aPrsObject);
       if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) {
        vf->getRenderer()->ResetCameraClippingRange();
@@ -813,23 +881,23 @@ void VisuGUI::DisplayPrs() {
       return;
     }
     // is it Curve ?
-    VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject));
+    VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject).in());
     if(aCurve){
-      MESSAGE("VisuGUI::DisplayPrs : Curve object");
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Curve object");
       PlotCurve(aCurve, VISU::eDisplay );
       return;
     }
     // is it Container ?
-    VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject));
+    VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject).in());
     if(aContainer){
-      MESSAGE("VisuGUI::DisplayPrs : Container object");
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Container object");
       PlotContainer(aContainer, VISU::eDisplay );
       return;
     }
     // is it Table ?
-    VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject));
+    VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject).in());
     if(aTable){
-      MESSAGE("VisuGUI::DisplayPrs : Table object");
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Table object");
       PlotTable(aTable, VISU::eDisplay );
       return;
     }
@@ -841,27 +909,27 @@ void VisuGUI::DisplayPrs() {
 // purpose  :
 //=====================================================================================
 void VisuGUI::DisplayOnlyPrs() {
-  MESSAGE("VisuGUI::DisplayOnlyPrs");
+  if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyPrs");
   CORBA::Object_var anObject = GetSelectedObj();
   if ( !CORBA::is_nil( anObject ) ) {
     // is it Prs3d object ?
-    PortableServer::Servant aServant = VISU::GetServant(anObject);
-    if(VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant)){
-      MESSAGE("VisuGUI::DisplayOnlyPrs : Prs3d object");
+    PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
+    if(VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in())){
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyPrs : Prs3d object");
       UpdateViewer(aPrsObject, true);
       VTKViewer_ViewFrame* vf = GetVtkViewFrame();
       if (vf) {
        vf->getRenderer()->ResetCameraClippingRange();
        vf->Repaint();
       }
-    }else if(VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aServant)){
-      MESSAGE("VisuGUI::DisplayOnlyPrs : Curve object");
+    }else if(VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aServant.in())){
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyPrs : Curve object");
       PlotCurve(aCurve, VISU::eDisplayOnly );
-    }else if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aServant)){
-      MESSAGE("VisuGUI::DisplayOnlyPrs : Container object");
+    }else if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aServant.in())){
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyPrs : Container object");
       PlotContainer(aContainer, VISU::eDisplayOnly );
-    }else if(VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aServant)){
-      MESSAGE("VisuGUI::DisplayOnlyPrs : Table object");
+    }else if(VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aServant.in())){
+      if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyPrs : Table object");
       PlotTable(aTable, VISU::eDisplayOnly );
     }
   }
@@ -871,48 +939,50 @@ void VisuGUI::DisplayOnlyPrs() {
 // function : ErasePrs()
 // purpose  :
 //=====================================================================================
-void VisuGUI::ErasePrs() {
-  MESSAGE("VisuGUI::ErasePrs");
-  CORBA::Object_var anObject = GetSelectedObj();
-  if ( !CORBA::is_nil( anObject ) ) {
-    // is it Prs3d object ?
-    VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
-    if(aPrsObject){
-      MESSAGE("VisuGUI::ErasePrs : Prs3d object");
-      ErasePrs(aPrsObject);
-      VTKViewer_ViewFrame* vf = GetVtkViewFrame();
-      if (vf) {
-       vf->Repaint();
-      }
-    }
-    // is it Curve ?
-    VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject));
-    if(aCurve){
-      MESSAGE("VisuGUI::ErasePrs : Curve object");
-      PlotCurve(aCurve, VISU::eErase );
+static void ErasePrs(CORBA::Object_ptr theObject) {
+  if(MYDEBUG) MESSAGE("ErasePrs");
+  if ( !CORBA::is_nil( theObject ) ) {
+    VISU::Base_var aBase = VISU::Base::_narrow(theObject);
+    if ( CORBA::is_nil( aBase ) ) return;
+    VISU::VISUType aType = aBase->GetType();
+    switch (aType){
+    case VISU::TCURVE:{
+      if(VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
+       VisuGUI::PlotCurve(aCurve, VISU::eErase );
+      break;
     }
-    // is it Container ?
-    VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject));
-    if(aContainer){
-      MESSAGE("VisuGUI::ErasePrs : Container object");
-      PlotContainer(aContainer, VISU::eErase );
+    case VISU::TCONTAINER:{
+      if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
+       VisuGUI::PlotContainer(aContainer, VISU::eErase );
+      break;
     }
-    // is it Table ?
-    VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject));
-    if(aTable){
-      MESSAGE("VisuGUI::ErasePrs : Table object");
-      PlotTable(aTable, VISU::eErase );
+    case VISU::TTABLE:{
+      if(VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
+       VisuGUI::PlotTable(aTable, VISU::eErase );
+      break;
     }
+    default:{
+      if(VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())){
+       VisuGUI::ErasePrs(aPrsObject);
+       if (VTKViewer_ViewFrame* vf = VisuGUI::GetVtkViewFrame())
+         vf->Repaint();
+      }
+    }}
   }
 }
 
+void VisuGUI::ErasePrs() {
+  ::ErasePrs(GetSelectedObj());
+}
+
+
 //=====================================================================================
 // function : DisplayManyPrs()
 // purpose  :
 //=====================================================================================
 void VisuGUI::DisplayManyPrs()
 {
-  MESSAGE("VisuGUI::DisplayManyPrs");
+  if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs");
   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
   for ( ; It.More(); It.Next() ) {
@@ -925,9 +995,9 @@ void VisuGUI::DisplayManyPrs()
        CORBA::Object_var aCORBAObject = VISU::SObjectToObject(aSObject);
        if ( !CORBA::is_nil( aCORBAObject ) ) {
          // is it Prs3d object ?
-         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aCORBAObject).in());
          if(aPrsObject){
-           MESSAGE("VisuGUI::DisplayManyPrs : Prs3d object");
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs : Prs3d object");
            UpdateViewer(aPrsObject);
            VTKViewer_ViewFrame* vf = GetVtkViewFrame();
            if (vf) {
@@ -938,23 +1008,23 @@ void VisuGUI::DisplayManyPrs()
            continue;
          }
          // is it Curve ?
-         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCORBAObject).in());
          if(aCurve){
-           MESSAGE("VisuGUI::DisplayManyPrs: Curve object");
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs: Curve object");
            PlotCurve(aCurve, VISU::eDisplay );
            continue;
          }
          // is it Container ?
-         VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCORBAObject).in());
          if(aContainer){
-           MESSAGE("VisuGUI::DisplayManyPrs : Container object");
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs : Container object");
            PlotContainer(aContainer, VISU::eDisplay );
            continue;
          }
          // is it Table ?
-         VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aCORBAObject).in());
          if(aTable){
-           MESSAGE("VisuGUI::DisplayManyPrs : Table object");
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs : Table object");
            PlotTable(aTable, VISU::eDisplay );
            continue;
          }
@@ -964,13 +1034,85 @@ void VisuGUI::DisplayManyPrs()
   }
 }
 
+//=====================================================================================
+// function : DisplayOnlyManyPrs()
+// purpose  :
+//=====================================================================================
+void VisuGUI::DisplayOnlyManyPrs() {
+  if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyManyPrs");
+  SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
+  SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
+  bool aFirstElem = true;
+  for ( ; It.More(); It.Next() ) {
+    Handle(SALOME_InteractiveObject)& anIO = It.Value();
+    if ( anIO->hasEntry() ) {
+      SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+      SALOMEDS::SObject_var aSObject = aStudy->FindObjectID( anIO->getEntry() );
+      VISU::Storable::TRestoringMap pMap;
+      if( !aSObject->_is_nil() ) {
+       CORBA::Object_var aCORBAObject = VISU::SObjectToObject(aSObject);
+       if ( !CORBA::is_nil( aCORBAObject ) ) {
+         // is it Prs3d object ?
+         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aCORBAObject).in());
+         if(aPrsObject){
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyManyPrs : Prs3d object");
+           UpdateViewer(aPrsObject, aFirstElem);
+           if (aFirstElem) aFirstElem = false;
+           VTKViewer_ViewFrame* vf = GetVtkViewFrame();
+           if (vf) {
+             vf->getRenderer()->ResetCameraClippingRange();
+             vf->Repaint();
+             vf->highlight(anIO, 1);
+           }
+           continue;
+         }
+         // is it Curve ?
+         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCORBAObject).in());
+         if(aCurve){
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyManyPrs: Curve object");
+           if (aFirstElem) {
+             PlotCurve(aCurve, VISU::eDisplayOnly );
+             aFirstElem = false;
+           }
+           else PlotCurve(aCurve, VISU::eDisplay );
+           continue;
+         }
+         // is it Container ?
+         VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCORBAObject).in());
+         if(aContainer){
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyManyPrs : Container object");
+           if (aFirstElem) {
+             PlotContainer(aContainer, VISU::eDisplayOnly );
+             aFirstElem = false;
+           }
+           else PlotContainer(aContainer, VISU::eDisplay );
+           continue;
+         }
+         // is it Table ?
+         VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aCORBAObject).in());
+         if(aTable){
+           if(MYDEBUG) MESSAGE("VisuGUI::DisplayOnlyManyPrs : Table object");
+           if (aFirstElem) {
+             PlotTable(aTable, VISU::eDisplayOnly );
+             aFirstElem = false;
+           }
+           else PlotTable(aTable, VISU::eDisplay );
+           continue;
+         }
+       }
+      }
+    }
+  }
+}
+
+
 //=====================================================================================
 // function : EraseManyPrs()
 // purpose  :
 //=====================================================================================
 void VisuGUI::EraseManyPrs()
 {
-  MESSAGE("VisuGUI::EraseManyPrs");
+  if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs");
   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
   SALOME_ListIO LIO; LIO = Sel->StoredIObjects();
   SALOME_ListIteratorOfListIO It( LIO );
@@ -984,9 +1126,9 @@ void VisuGUI::EraseManyPrs()
        CORBA::Object_var aCORBAObject = VISU::SObjectToObject(aSObject);
        if ( !CORBA::is_nil( aCORBAObject ) ) {
          // is it Prs3d object ?
-         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aCORBAObject).in());
          if(aPrsObject){
-           MESSAGE("VisuGUI::EraseManyPrs : Prs3d object");
+           if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Prs3d object");
            ErasePrs(aPrsObject);
            VTKViewer_ViewFrame* vf = GetVtkViewFrame();
            if (vf) {
@@ -995,23 +1137,23 @@ void VisuGUI::EraseManyPrs()
            continue;
          }
          // is it Curve ?
-         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCORBAObject).in());
          if(aCurve){
-           MESSAGE("VisuGUI::EraseManyPrs : Curve object");
+           if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Curve object");
            PlotCurve(aCurve, VISU::eErase );
            continue;
          }
          // is it Container ?
-         VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCORBAObject).in());
          if(aContainer){
-           MESSAGE("VisuGUI::EraseManyPrs : Container object");
+           if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Container object");
            PlotContainer(aContainer, VISU::eErase );
            continue;
          }
          // is it Table ?
-         VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aCORBAObject));
+         VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aCORBAObject).in());
          if(aTable){
-           MESSAGE("VisuGUI::EraseManyPrs : Table object");
+           if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Table object");
            PlotTable(aTable, VISU::eErase );
            continue;
          }
@@ -1027,14 +1169,34 @@ void VisuGUI::EraseManyPrs()
 //=====================================================================================
 void VisuGUI::RecreateActor(VISU::Prs3d_i* thePrs) {
   QApplication::setOverrideCursor(Qt::waitCursor);
-  thePrs->Update();
-  for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++)
-    if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){
-      QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame();
-      if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame))
-       if(VISU_Actor* anActor = GetActor(thePrs,aViewFrame))
-         thePrs->UpdateActor(anActor);
-    }
+  try{
+    thePrs->Update();
+    //UpdateViewer(thePrs); Avoid unnessary settings of visibility on for thePrs
+    for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++)
+      if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){
+       QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame();
+       if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame))
+         if(VISU_Actor* anActor = GetActor(thePrs,aViewFrame))
+           thePrs->UpdateActor(anActor);
+      }
+  }catch(std::runtime_error& ex){
+    INFOS(ex.what());
+    QApplication::restoreOverrideCursor();
+    QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"), 
+                           tr ("ERR_CANT_BUILD_PRESENTATION") + " " + tr(ex.what()), 
+                           tr ("VISU_BUT_OK") );
+    for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++)
+      if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){
+       QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame();
+       if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame)) {
+         if(VISU_Actor* anActor = GetActor(thePrs,aViewFrame)) {
+           aViewFrame->RemoveActor(anActor);
+           anActor->Delete();
+         }
+       }
+      }
+    return;
+  }
   QApplication::restoreOverrideCursor();
 }
 
@@ -1048,16 +1210,16 @@ void VisuGUI::RecreateActor(VISU::Prs3d_i* thePrs) {
       PrsName* aPrsObject = dynamic_cast<PrsName*>(aPrs3d); \
       if (aPrsObject) { \
        DlgName* aDlg = new DlgName(); \
-       aDlg->initFromPrsObject(aPrsObject); \
+        aDlg->initFromPrsObject(aPrsObject); \
        if ( aDlg->exec() )  { \
-         aDlg->storeToPrsObject(aPrsObject); \
+         if(!(aDlg->storeToPrsObject(aPrsObject))){ \
+           delete aDlg; \
+            return; \
+          } \
          RecreateActor(aPrsObject); \
-         /*RepaintCurrentView();*/ \
-         VTKViewer_ViewFrame* vf = GetVtkViewFrame(); \
-         if (vf) { \
+         if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) { \
            if ( vf->getRenderer()->GetActors()->GetNumberOfItems () > 0 ) { \
                  vf->getRenderer()->ResetCameraClippingRange(); \
-                vf->onViewFitAll(); \
                 vf->Repaint(); \
              }\
          } \
@@ -1066,7 +1228,6 @@ void VisuGUI::RecreateActor(VISU::Prs3d_i* thePrs) {
       } \
     }
 
-
 void VisuGUI::EditPrs() {
   VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d();
 
@@ -1077,17 +1238,96 @@ void VisuGUI::EditPrs() {
   case VISU::TSCALARMAP: // ScalarMap 18
     EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
     break;
-
+    
   case VISU::TDEFORMEDSHAPE: // Deformed Shape 28
     EDITPRS(VISU::DeformedShape_i, VisuGUI_MagnitudeDlg);
     break;
-
+    
   case VISU::TCUTPLANES: // Cut planes 42
-    EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
+    //EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
+    {
+      VISU::CutPlanes_i* aPrsObject = dynamic_cast<VISU::CutPlanes_i*>(aPrs3d);
+      if (aPrsObject) {
+       VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(false, false); 
+        aDlg->initFromPrsObject(aPrsObject);
+       aDlg->show();
+       myActiveDialogBox = aDlg;      
+//     if ( aDlg->exec() )  {
+//       if(!(aDlg->storeToPrsObject(aPrsObject))){
+//         delete aDlg;
+//             return;
+//           }
+//       RecreateActor(aPrsObject);
+//       if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) {
+//         if ( vf->getRenderer()->GetActors()->GetNumberOfItems () > 0 ) {
+//                  vf->getRenderer()->ResetCameraClippingRange();
+//              vf->Repaint();
+//           }
+//       }
+//     }
+//     delete aDlg;
+      }
+    }
     break;
 
   case VISU::TCUTLINES: // Cut planes 42
-    EDITPRS(VISU::CutLines_i, VisuGUI_CutLinesDlg);
+    //EDITPRS(VISU::CutLines_i, VisuGUI_CutLinesDlg);
+    {
+      VISU::CutLines_i* aPrsObject = dynamic_cast<VISU::CutLines_i*>(aPrs3d); 
+      if (aPrsObject) { 
+       VisuGUI_CutLinesDlg* aDlg = new VisuGUI_CutLinesDlg(false); 
+        aDlg->initFromPrsObject(aPrsObject); 
+       aDlg->show();
+       myActiveDialogBox = aDlg;
+//     if ( aDlg->exec() )  { 
+//       aDlg->storeToPrsObject(aPrsObject); 
+//       RecreateActor(aPrsObject); 
+//       if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) { 
+//         if ( vf->getRenderer()->GetActors()->GetNumberOfItems () > 0 ) { 
+//           vf->getRenderer()->ResetCameraClippingRange(); 
+//           vf->Repaint(); 
+//         }
+//       }
+//       // Remove old Table
+//       SALOMEDS::Study_var aStudy = GetActiveStudy()->getStudyDocument();
+//       SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(aPrsObject->GetEntry());
+//       if(!aSObject->_is_nil()) {
+//         SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator( aSObject );
+//         SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
+//         for ( ;aIter->More(); aIter->Next()) {
+//           SALOMEDS::SObject_var aTblObj = aIter->Value();
+//           if (!aTblObj->_is_nil()) {
+//             SALOMEDS::GenericAttribute_var anAttr;
+//             if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
+//               aBuilder->RemoveObjectWithChildren(aIter->Value()); // We should have only one child
+//               break;
+//             }
+//           }
+//         }
+//         if (aDlg->isGenerateTable()) {
+//           GetVisuGen()->CreateTable(aSObject->GetID());
+//           if (aDlg->isGenerateCurves()) {
+//             SALOMEDS::Study_var aStudy = GetActiveStudy()->getStudyDocument();
+//             SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator( aSObject );
+//             SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
+//             for ( ;aIter->More(); aIter->Next()) {
+//               SALOMEDS::SObject_var aTblObj = aIter->Value();
+//               if (!aTblObj->_is_nil()) {
+//                 SALOMEDS::GenericAttribute_var anAttr;
+//                 if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
+//                   CreatePlot(aTblObj);
+//                 }
+//               }
+
+//             }
+//           }
+//         }
+//         GetActiveStudy()->updateObjBrowser();
+//       }
+//     } 
+//     delete aDlg; 
+      } 
+    } 
     break;
 
   case VISU::TISOSURFACE: // Iso surfaces
@@ -1099,34 +1339,16 @@ void VisuGUI::EditPrs() {
 
   case VISU::TSTREAMLINES:
     EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
-  }
-}
-
-
-//=====================================================================================
-// function : EditScalarBar()
-// purpose  :
-//=====================================================================================
-void VisuGUI::EditScalarBar() {
-  VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d();
-  VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(aPrs3d);
-  if (aPrsObject) {
-    VisuGUI_ScalarBarDlg* aDlg = new VisuGUI_ScalarBarDlg(false);
-    aDlg->initFromPrsObject(aPrsObject);
-    if ( aDlg->exec() )  {
-      aDlg->storeToPrsObject(aPrsObject);
-      RecreateActor(aPrsObject);
-      
-      VTKViewer_ViewFrame* vf = GetVtkViewFrame();
-      if (vf)
-       vf->Repaint();
-      
-      if (aDlg->isToSave())
-       aDlg->storeToResources();
-    }
-    delete aDlg;
+    break;
+  default: 
+    return;        
   }
   
+  Handle(SALOME_InteractiveObject) anIO;
+  CORBA::Object_var anObject = GetSelectedObj(&anIO);
+  if ( !CORBA::is_nil( anObject ) ) 
+    if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) 
+      vf->highlight(anIO, 1);
 }
 
 
@@ -1158,7 +1380,6 @@ void VisuGUI::CreateMesh() {
                          tr ("VISU_BUT_OK"));
     return;
   }
-
   VISU::Storable::TRestoringMap aMap;
   SALOMEDS::GenericAttribute_var anAttr;
   if(aSObject->FindAttribute(anAttr, "AttributeComment")) {
@@ -1176,16 +1397,20 @@ void VisuGUI::CreateMesh() {
   Utils_Timer timer;
   timer.Start();
 #endif
+  VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());
   if(aComment == "ENTITY"){
     VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
-    aMesh = GetVisuGen()->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
+    if(VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
+      aMesh = GetVisuGen()->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
   }else if(aComment == "FAMILY"){
     VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
     string aFamilyName = VISU::Storable::FindValue(aMap,"myName").latin1();
-    aMesh = GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
+    if(VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
+      aMesh = GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
   }else if(aComment == "GROUP"){
     string aGroupName = VISU::Storable::FindValue(aMap,"myName").latin1();
-    aMesh = GetVisuGen()->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
+    if(VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
+      aMesh = GetVisuGen()->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
   }
 #ifdef CHECKTIME
   timer.Stop();
@@ -1196,7 +1421,7 @@ void VisuGUI::CreateMesh() {
   QApplication::restoreOverrideCursor();
   VISU::Mesh_i* pPresent = NULL;
   if(!CORBA::is_nil(aMesh)) 
-    pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh));
+    pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
   if (pPresent == NULL) {
     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"), 
                            tr ("ERR_CANT_BUILD_PRESENTATION"), 
@@ -1205,92 +1430,92 @@ void VisuGUI::CreateMesh() {
   }
 
   if(VTKViewer_ViewFrame* vf = GetVtkViewFrame()){
-    VISU_Actor *anActor = pPresent->CreateActor();
-    if (! anActor ) {
-      QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"), 
-                             tr ("ERR_CANT_CREATE_ACTOR"), 
-                             tr ("VISU_BUT_OK") ); 
-      return;
-    }
+    try{
+      VISU_Actor *anActor = pPresent->CreateActor();
 #ifdef CHECKTIME
-    Utils_Timer timer;
-    timer.Start();
+      Utils_Timer timer;
+      timer.Start();
 #endif
-    vf->AddActor(anActor);
-    vf->getRenderer()->ResetCameraClippingRange();
-    vf->onViewFitAll();
+      vf->AddActor(anActor);
+      SetFitAll(vf);
 #ifdef CHECKTIME
-    timer.Stop();
-    MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
-    timer.Show();
+      timer.Stop();
+      MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
+      timer.Show();
 #endif
-  }
-  //GetActiveStudy()->updateObjBrowser(); //not necessary
-  GetDesktop()->putInfo("Ready");
-}
+      //GetActiveStudy()->updateObjBrowser(); //not necessary
+      GetDesktop()->putInfo("Ready");
+    }catch(std::runtime_error& exc){
+      INFOS(exc.what());
+      QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"), 
+                             tr ("ERR_CANT_CREATE_ACTOR") + " " + tr(exc.what()), 
+                             tr ("VISU_BUT_OK") ); 
+    }
+  }
+}
 
 //=====================================================================================
 // function : CreateManyMesh()
 // purpose  :
 //=====================================================================================
-void VisuGUI::CreateManyMesh()
-{
+void VisuGUI::CreateManyMesh(){
   if (checkLock(GetStudyDocument())) return;
 
   SALOME_Selection* Sel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
   for ( ; It.More(); It.Next() ) {
-  SALOMEDS::SObject_var aSObject  = GetActiveStudy()->getStudyDocument()->FindObjectID( It.Value()->getEntry() );
-  
-  SALOMEDS::SObject_var aSObj = aSObject->GetFather();
-  aSObj = aSObj->GetFather();
-  aSObj = aSObj->GetFather();
-  CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
-  if(CORBA::is_nil(anObject)) {
+    SALOMEDS::SObject_var aSObject  = GetStudyDocument()->FindObjectID(It.Value()->getEntry());
+    SALOMEDS::SObject_var aSObj = aSObject->GetFather();
     aSObj = aSObj->GetFather();
-    anObject = VISU::SObjectToObject(aSObj);
-    if(CORBA::is_nil(anObject)) return;
-  }
-  VISU::Result_var aResult = VISU::Result::_narrow(anObject);
-  if(CORBA::is_nil(aResult)) return;
-
-  VISU::Storable::TRestoringMap aMap;
-  SALOMEDS::GenericAttribute_var anAttr;
-  if(aSObject->FindAttribute(anAttr, "AttributeComment")) {
-    SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
-    string aComm = aComment->Value();
-    QString strIn(aComm.c_str());
-    VISU::Storable::StrToMap(strIn,aMap);
-  }
-  bool isExist;
-  string aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist).latin1();
-  if(!isExist) return;
-  CORBA::Object_var aMesh;
-  string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").latin1();
-  if(aComment == "ENTITY"){
-    VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
-    aMesh = GetVisuGen()->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
-  }else if(aComment == "FAMILY"){
-    VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
-    string aFamilyName = VISU::Storable::FindValue(aMap,"myName").latin1();
-    aMesh = GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
-  }else if(aComment == "GROUP"){
-    string aGroupName = VISU::Storable::FindValue(aMap,"myName").latin1();
-    aMesh = GetVisuGen()->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
-  }
-  QApplication::restoreOverrideCursor();
-  if(CORBA::is_nil(aMesh)) return;
-
-  VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh));
-  VISU_Actor *anActor = pPresent->CreateActor();
-  if (! anActor ) return;
-  if(VTKViewer_ViewFrame* vf = GetVtkViewFrame()){
-    vf->AddActor(anActor);
-    vf->getRenderer()->ResetCameraClippingRange();
-    vf->onViewFitAll();
-  }
+    aSObj = aSObj->GetFather();
+    CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
+    if(CORBA::is_nil(anObject)) {
+      aSObj = aSObj->GetFather();
+      anObject = VISU::SObjectToObject(aSObj);
+      if(CORBA::is_nil(anObject)) return;
+    }
+    VISU::Result_var aResult = VISU::Result::_narrow(anObject);
+    if(CORBA::is_nil(aResult)) return;
+    
+    VISU::Storable::TRestoringMap aMap;
+    SALOMEDS::GenericAttribute_var anAttr;
+    if(aSObject->FindAttribute(anAttr, "AttributeComment")) {
+      SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
+      string aComm = aComment->Value();
+      QString strIn(aComm.c_str());
+      VISU::Storable::StrToMap(strIn,aMap);
+    }
+    bool isExist;
+    string aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist).latin1();
+    if(!isExist) return;
+    CORBA::Object_var aMesh;
+    string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").latin1();
+    if(aComment == "ENTITY"){
+      VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
+      aMesh = GetVisuGen()->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
+    }else if(aComment == "FAMILY"){
+      VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
+      string aFamilyName = VISU::Storable::FindValue(aMap,"myName").latin1();
+      aMesh = GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
+    }else if(aComment == "GROUP"){
+      string aGroupName = VISU::Storable::FindValue(aMap,"myName").latin1();
+      aMesh = GetVisuGen()->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
+    }
+    QApplication::restoreOverrideCursor();
+    if(CORBA::is_nil(aMesh)) return;
+    
+    VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
+    try{
+      VISU_Actor *anActor = pPresent->CreateActor();
+      if(VTKViewer_ViewFrame* vf = GetVtkViewFrame()){
+       vf->AddActor(anActor);
+       SetFitAll(vf);
+      }
+      GetDesktop()->putInfo("Ready");
+    }catch(std::runtime_error& exc){
+      INFOS(exc.what());
+    }
   }
-  GetDesktop()->putInfo("Ready");
 }
 
 //=====================================================================================
@@ -1299,48 +1524,54 @@ void VisuGUI::CreateManyMesh()
 //=====================================================================================
 
 static void ShrinkMesh(VISU_Actor *theActor){
-  if(theActor->isShrunk()) 
-    theActor->unShrink();
+  if(theActor->IsShrunk()) 
+    theActor->UnShrink();
   else
-    theActor->setShrink(0.8);
+    theActor->SetShrink();
 }
 
-void VisuGUI::ChangeRepresentation(RepresentType theType) {
-  if(VISU::Prs3d_i* aPrsObject = GetSelectedPrs3d()){
+void VisuGUI::ChangeRepresentation(VISU::PresentationType theType) {
+  if(VISU::Prs3d_i* aPrsObject = GetSelectedPrs3d())
     if(VISU_Actor* anActor = GetActor(aPrsObject)){
       switch (theType) {
-      case POINTS:
-      case WIREFRAME:
-      case SURFACE:
-       anActor->SetRepresentation(theType);
-       break;
-      case SHRINK:
+      case VISU::SHRINK:
        ShrinkMesh(anActor);
        break;
+      default:
+       if(VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrsObject)){
+         aMesh->SetPresentationType(theType);
+         RecreateActor(aMesh);
+       }else
+         anActor->SetRepresentation(theType);
       }
       if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) 
        vf->Repaint();
     }
-  }
 }
 
-void VisuGUI::MakeWireframe() {
-  ChangeRepresentation(WIREFRAME);
+
+void VisuGUI::MakeSurfaceframe() {
+  ChangeRepresentation(VISU::SURFACEFRAME);
 }
 
+void VisuGUI::MakeInsideframe() {
+  ChangeRepresentation(VISU::INSIDEFRAME);
+}
 
-void VisuGUI::MakeSurface() {
-  ChangeRepresentation(SURFACE);
+void VisuGUI::MakeWireframe() {
+  ChangeRepresentation(VISU::WIREFRAME);
 }
 
+void VisuGUI::MakeSurface() {
+  ChangeRepresentation(VISU::SHADED);
+}
 
 void VisuGUI::MakePoints() {
-  ChangeRepresentation(POINTS);
+  ChangeRepresentation(VISU::POINT);
 }
 
-
 void VisuGUI::MakeShrink() {
-  ChangeRepresentation(SHRINK);
+  ChangeRepresentation(VISU::SHRINK);
 }
 
 
@@ -1352,7 +1583,9 @@ void VisuGUI::MakeShrink() {
 VISU::Prs3d_i* VisuGUI::GetSelectedPrs3d(Handle(SALOME_InteractiveObject)* theIO) {
   CORBA::Object_var anObject = GetSelectedObj(theIO);
   if(CORBA::is_nil(anObject)) return NULL;
-  return dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
+  PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
+  if(!aServant.in()) return NULL;
+  return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
 }
 
 void VisuGUI::ChageColor() {
@@ -1364,13 +1597,13 @@ void VisuGUI::ChageColor() {
   NewColor(anActor);
 }
 
-void VisuGUI::ChangeOutlineColor() {
+void VisuGUI::ChangeWireframeColor() {
   VISU::Prs3d_i* aPrsObject = GetSelectedPrs3d();
   if(!aPrsObject) return;
 
-  VISUMesh_Actor* anActor = dynamic_cast<VISUMesh_Actor*>(GetActor(aPrsObject));
+  VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(GetActor(aPrsObject));
   if (!anActor) return;
-  NewOutlineColor(anActor);
+  NewWireframeColor(anActor);
 }
 
 
@@ -1394,7 +1627,6 @@ void VisuGUI::ChangeLines() {
 }
 void VisuGUI::PlotTable( VISU::Table_i* table, int theDisplaying )
 {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   if ( table && GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
     Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
     if ( theDisplaying == VISU::eDisplayOnly ) 
@@ -1409,7 +1641,7 @@ void VisuGUI::PlotTable( VISU::Table_i* table, int theDisplaying )
        if( !CORBA::is_nil( childObject ) ) {
          CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
          if( !CORBA::is_nil( aCurve ) ) {
-           VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aCurve ) );
+           VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
            Plot2d_Curve* plotCurve = 0;
            for ( int i = 0; i < clist.count(); i++ ) {
              if ( clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
@@ -1425,19 +1657,25 @@ void VisuGUI::PlotTable( VISU::Table_i* table, int theDisplaying )
            }
            else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
              if ( plotCurve ) {
-               plotCurve->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
-               //plotCurve->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
-               plotCurve->setVerTitle( strdup( theCurve->GetName() ) );
-               plotCurve->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
-               plotCurve->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
+               plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
+               //plotCurve->setVerTitle(  theCurve->GetVerTitle().c_str() );
+               plotCurve->setVerTitle( theCurve->GetName() );
+               plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
+               plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
                /* - DATA NOT UPDATED */
-               if ( !plotCurve->isAutoAssign() ) {
+               double* xList = 0;
+               double* yList = 0;
+               int     nbPoints = theCurve->GetData( xList, yList );
+               if ( nbPoints > 0 && xList && yList ) {
+                 plotCurve->setData( xList, yList, nbPoints );
+               }
+               if ( !theCurve->IsAuto() ) {
                  plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
                  plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
                  SALOMEDS::Color color = theCurve->GetColor();
                  plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
-                 plotCurve->setAutoAssign( theCurve->IsAuto() );
                }
+               plotCurve->setAutoAssign( theCurve->IsAuto() );
                aPlot->displayCurve( plotCurve, false );
              }
              else {
@@ -1451,6 +1689,7 @@ void VisuGUI::PlotTable( VISU::Table_i* table, int theDisplaying )
                  newColor.G = crv->getColor().green()/255.;
                  newColor.B = crv->getColor().blue()/255.;
                  theCurve->SetColor( newColor );
+                 crv->setAutoAssign( theCurve->IsAuto() );
                }
              }
            }
@@ -1463,7 +1702,6 @@ void VisuGUI::PlotTable( VISU::Table_i* table, int theDisplaying )
 }
 void VisuGUI::PlotCurve( VISU::Curve_i* theCurve, int theDisplaying )
 {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   if ( theCurve && GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
     Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
 //  if ( theDisplaying == VISU::eDisplayOnly ) 
@@ -1485,19 +1723,24 @@ void VisuGUI::PlotCurve( VISU::Curve_i* theCurve, int theDisplaying )
     }
     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
       if ( plotCurve ) {
-       plotCurve->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
-       //plotCurve->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
-       plotCurve->setVerTitle( strdup( theCurve->GetName() ) );
-       plotCurve->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
-       plotCurve->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
-       /* DATA NOT UPDATED */
-       if ( !plotCurve->isAutoAssign() ) {
+       plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
+       //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
+       plotCurve->setVerTitle( theCurve->GetName() );
+       plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
+       plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
+       double* xList = 0;
+       double* yList = 0;
+       int     nbPoints = theCurve->GetData( xList, yList );
+       if ( nbPoints > 0 && xList && yList ) {
+         plotCurve->setData( xList, yList, nbPoints );
+       }
+       if ( !theCurve->IsAuto() ) {
          plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
          plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
          SALOMEDS::Color color = theCurve->GetColor();
          plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
-         plotCurve->setAutoAssign( theCurve->IsAuto() );
        }
+       plotCurve->setAutoAssign( theCurve->IsAuto() );
        aPlot->displayCurve( plotCurve, false );
       }
       else {
@@ -1511,6 +1754,7 @@ void VisuGUI::PlotCurve( VISU::Curve_i* theCurve, int theDisplaying )
          newColor.G = crv->getColor().green()/255.;
          newColor.B = crv->getColor().blue()/255.;
          theCurve->SetColor( newColor );
+         crv->setAutoAssign( theCurve->IsAuto() );
        }
       }
     }
@@ -1519,7 +1763,6 @@ void VisuGUI::PlotCurve( VISU::Curve_i* theCurve, int theDisplaying )
 }
 void VisuGUI::PlotContainer( VISU::Container_i* container, int theDisplaying )
 {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   if ( container && GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
     Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
     if ( theDisplaying == VISU::eDisplayOnly ) 
@@ -1531,7 +1774,7 @@ void VisuGUI::PlotContainer( VISU::Container_i* container, int theDisplaying )
       for ( int k = 1; k <= nbCurves; k++ ) {
        VISU::Curve_i* theCurve = container->GetCurve( k );
        if ( theCurve && theCurve->IsValid() ) {
-         Plot2d_Curve* plotCurve = aPlot->getCurveByIO( new SALOME_InteractiveObject( strdup(theCurve->GetEntry()), "", "" ) );
+         Plot2d_Curve* plotCurve = aPlot->getCurveByIO( new SALOME_InteractiveObject( theCurve->GetEntry(), "", "" ) );
 //       for ( int i = 0; i < clist.count(); i++ ) {
 //         if ( clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
 //           plotCurve = clist.at( i );
@@ -1546,19 +1789,24 @@ void VisuGUI::PlotContainer( VISU::Container_i* container, int theDisplaying )
          }
          else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
            if ( plotCurve ) {
-             plotCurve->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
-              //plotCurve->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
-              plotCurve->setVerTitle( strdup( theCurve->GetName() ) );
-             plotCurve->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
-             plotCurve->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
-             /* - DATA NOT UPDATED */
-             if ( !plotCurve->isAutoAssign() ) {
+             plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
+              //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
+              plotCurve->setVerTitle( theCurve->GetName() );
+             plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
+             plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
+             double* xList = 0;
+             double* yList = 0;
+             int     nbPoints = theCurve->GetData( xList, yList );
+             if ( nbPoints > 0 && xList && yList ) {
+               plotCurve->setData( xList, yList, nbPoints );
+             }
+             if ( !theCurve->IsAuto() ) {
                plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
                plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
                SALOMEDS::Color color = theCurve->GetColor();
                plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
-               plotCurve->setAutoAssign( theCurve->IsAuto() );
              }
+             plotCurve->setAutoAssign( theCurve->IsAuto() );
              aPlot->displayCurve( plotCurve, false );
            }
            else {
@@ -1572,6 +1820,7 @@ void VisuGUI::PlotContainer( VISU::Container_i* container, int theDisplaying )
                newColor.G = crv->getColor().green()/255.;
                newColor.B = crv->getColor().blue()/255.;
                theCurve->SetColor( newColor );
+               crv->setAutoAssign( theCurve->IsAuto() );
              }
            }
          }
@@ -1586,7 +1835,6 @@ void VisuGUI::PlotContainer( VISU::Container_i* container, int theDisplaying )
   Slot : opens Table view : for Table object or SObject with table attribute selected
 */
 void VisuGUI::ShowTable() {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   if( Sel->IObjectCount() !=1 )
     return;
@@ -1598,7 +1846,7 @@ void VisuGUI::ShowTable() {
     if ( !CORBA::is_nil( aVisuObj ) && aVisuObj->GetType() == VISU::TTABLE ) {
       CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
       if( !CORBA::is_nil( aTable ) ) {
-       VISU::Table_i* table = dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTable ) );
+       VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
        if ( table ) {
          SO = GetActiveStudy()->getStudyDocument()->FindObjectID( table->GetObjectEntry() );
        }
@@ -1608,10 +1856,10 @@ void VisuGUI::ShowTable() {
     // possibly this is Table SObject
     SO = GetActiveStudy()->getStudyDocument()->FindObjectID( anIO->getEntry() );
   }
-  SALOMEDS::GenericAttribute_var anAttr;
-  if ( SO->_is_nil() || ( !SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) 
-                      && !SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) 
+
+  if(!IsSObjectTable(SO))
     return;
+
   SALOMEGUI_TableDlg* dlg = new SALOMEGUI_TableDlg( QAD_Application::getDesktop(),
                                                    SO, 
                                                    false, 
@@ -1621,11 +1869,11 @@ void VisuGUI::ShowTable() {
   dlg->show();
 }
 
+
 /*!
   Slot : opens Table view : for Table object or SObject with table attribute selected
 */
 void VisuGUI::CreateTable() {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   if( aSel->IObjectCount() !=1 )
     return;
@@ -1637,10 +1885,7 @@ void VisuGUI::CreateTable() {
     if(!aSObject->_is_nil()) {
       CORBA::Object_var anObject = VISU::SObjectToObject(aSObject);
       VISU::CutLines_var aCutLines = VISU::CutLines::_narrow( anObject );
-      SALOMEDS::GenericAttribute_var anAttr;
-      if(!aCutLines->_is_nil() ||
-        aSObject->FindAttribute( anAttr, "AttributeTableOfInteger") ||
-        aSObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ){
+      if(!aCutLines->_is_nil() || IsSObjectTable(aSObject)) {
        GetVisuGen()->CreateTable(aSObject->GetID());
        GetActiveStudy()->updateObjBrowser();
       }
@@ -1648,11 +1893,75 @@ void VisuGUI::CreateTable() {
   }
 }
 
+
+/*!
+  Slot : deletes SObject with all subobjects
+*/
+void VisuGUI::DeleteObject() {
+  SALOMEDS::Study_var aStudy = GetStudyDocument();
+  if (checkLock(aStudy)) return;
+
+  SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
+  if( aSel->IObjectCount() !=1 )
+    return;
+  Handle(SALOME_InteractiveObject) anIO = aSel->firstIObject();
+  if (anIO->hasEntry()){
+    SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(anIO->getEntry());
+    if(!aSObject->_is_nil()){
+      SALOMEDS::ChildIterator_var aChildIter = aStudy->NewChildIterator(aSObject);
+      for(aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()){
+       SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
+       CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
+       ::ErasePrs(aChildObj);
+      }
+      SALOMEDS::StudyBuilder_var aStudyBuilder = VisuGUI::NewBuilder();
+      // There is a transaction
+      aStudyBuilder->NewCommand();
+      CORBA::Object_var anObj = VISU::SObjectToObject(aSObject);
+      if(!CORBA::is_nil(anObj)){
+       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
+       if(!CORBA::is_nil(aBase)){
+         VISU::VISUType aType = aBase->GetType();
+         switch (aType){
+         case VISU::TRESULT:{
+           SALOMEDS::ChildIterator_var aChildIter = aStudy->NewChildIterator(aSObject);
+           for(aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()){
+             SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
+             CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
+             if(CORBA::is_nil(aChildObj)) continue;
+             VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aChildObj);
+             if(CORBA::is_nil(aPrs3d)) continue;
+             VISU::Prs3d_i* pPrs3d = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aPrs3d).in());
+             DeletePresentation(pPrs3d);
+           }
+           break;
+         }}
+       }
+      }
+      aStudyBuilder->RemoveObjectWithChildren(aSObject);
+      aStudyBuilder->CommitCommand();
+      GetActiveStudy()->unHighlightAll();
+      GetActiveStudy()->updateObjBrowser(true);
+    }
+  }
+}
+
+
+/*!
+  Slot : deletes empty container
+*/
+void VisuGUI::CreatePlot2dView() {
+  if (checkLock(GetStudyDocument())) return;
+  GetVisuGen()->CreateContainer();
+  GetActiveStudy()->updateObjBrowser( true );
+}
+
+
+
 /*!
   Opens dialog box for curves creation. Acts only for selected SObject with table attribute.
 */
 void VisuGUI::PlotData() {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   if( Sel->IObjectCount() !=1 )
     return;
@@ -1664,18 +1973,17 @@ void VisuGUI::PlotData() {
       // Table (VISU object) is selected
       CORBA::Object_ptr aTbl = VISU::Table::_narrow( anObject );
       if( !CORBA::is_nil( aTbl ) ) {
-       VISU::Table_i* table = dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTbl ) );
+       VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTbl).in());
        if ( table ) {
          SALOMEDS::GenericAttribute_var anAttr;
          SALOMEDS::AttributeName_var    aName;
          QString SOName;
          SALOMEDS::SObject_var SO = GetActiveStudy()->getStudyDocument()->FindObjectID( table->GetObjectEntry() );
-         if ( !SO->_is_nil() && ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
-                                  SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
+         if ( IsSObjectTable(SO) ) {
            // get name of SObject
            if ( SO->FindAttribute( anAttr, "AttributeName" ) ) {
              aName = SALOMEDS::AttributeName::_narrow( anAttr );
-             SOName = strdup( aName->Value() );
+             SOName = aName->Value();
            }
            Plot2d_SetupPlot2dDlg* dlg = new Plot2d_SetupPlot2dDlg( SO, QAD_Application::getDesktop() );
            if ( dlg->exec() == QDialog::Accepted ) {
@@ -1688,12 +1996,12 @@ void VisuGUI::PlotData() {
                if ( horIndex >= 0 && verIndices.count() > 0 ) { 
                  CORBA::Object_var aContainer = GetVisuGen()->CreateContainer();
                  if( !CORBA::is_nil( aContainer ) ) {
-                   VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aContainer ) );
+                   VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
                    if ( pContainer ) {
                      for ( int i = 0; i < verIndices.count(); i++ ) {
                        CORBA::Object_var aNewCurve = GetVisuGen()->CreateCurve( table->_this(), horIndex+1, verIndices[i]+1 );
                        if( !CORBA::is_nil( aNewCurve ) ) {
-                         VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aNewCurve ) );
+                         VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aNewCurve).in());
                          if ( pCrv ) {
                            bool isAuto;
                            int  marker, line, lineWidth;
@@ -1740,12 +2048,11 @@ void VisuGUI::PlotData() {
       
     // check if Table SObject is selected
     SALOMEDS::SObject_var SO = GetActiveStudy()->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
-    if ( !SO->_is_nil() && ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
-                            SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
+    if ( IsSObjectTable(SO) ) {
       // get name of SObject
       if ( SO->FindAttribute( anAttr, "AttributeName" ) ) {
        aName = SALOMEDS::AttributeName::_narrow( anAttr );
-       SOName = strdup( aName->Value() );
+       SOName = aName->Value();
       }
       Plot2d_SetupPlot2dDlg* dlg = new Plot2d_SetupPlot2dDlg( SO, QAD_Application::getDesktop() );
       if ( dlg->exec() == QDialog::Accepted ) {
@@ -1759,14 +2066,14 @@ void VisuGUI::PlotData() {
            CORBA::Object_var aTable = GetVisuGen()->CreateTable( SO->GetID() );
            CORBA::Object_var aContainer = GetVisuGen()->CreateContainer();
            if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
-             VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTable ) );
-             VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aContainer ) );
+             VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
+             VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
            
              if ( pContainer && pTable ) {
                for ( int i = 0; i < verIndices.count(); i++ ) {
                  CORBA::Object_var aNewCurve = GetVisuGen()->CreateCurve( pTable->_this(), horIndex+1, verIndices[i]+1 );
                  if( !CORBA::is_nil( aNewCurve ) ) {
-                   VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aNewCurve ) );
+                   VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aNewCurve).in());
                    if ( pCrv ) {
                      bool isAuto;
                      int  marker, line, lineWidth;
@@ -1786,8 +2093,7 @@ void VisuGUI::PlotData() {
              }
            }
          }
-       }
-        else {
+       } else {
          // if study is locked just get curves info and plot them if current viewer is of VIEW_PLOT2D type
          if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
            Plot2d_CurveContainer container;
@@ -1802,14 +2108,44 @@ void VisuGUI::PlotData() {
        }
       }
       delete dlg;
+    } 
+  }
+}
+
+
+void VisuGUI::CreatePlot(SALOMEDS::SObject_var theTableSO) {
+  SALOMEDS::GenericAttribute_var anAttr;
+  SALOMEDS::AttributeName_var    aName;
+
+  if ( IsSObjectTable(theTableSO) ) {
+    CORBA::Object_var aTable = VISU::SObjectToObject(theTableSO);
+    CORBA::Object_var aContainer = GetVisuGen()->CreateContainer();
+    if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
+      VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>( VISU::GetServant(aTable).in() );
+      VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant(aContainer).in() );
+      
+      if ( pContainer && pTable ) {
+       for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
+         CORBA::Object_var aNewCurve = GetVisuGen()->CreateCurve( pTable->_this(), 1, i );
+         if( !CORBA::is_nil( aNewCurve ) ) {
+           VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
+           if ( pCrv ) {
+             pContainer->AddCurve( pCrv->_this() );
+           }
+         }
+       }
+       GetActiveStudy()->updateObjBrowser( true );
+       PlotContainer( pContainer, VISU::eDisplay );
+      }
     }
   }
 }
+
+
 /*!
   Slot : Opens "Setup curve" dialog to set curve properties : for Curve object selected
 */
 void VisuGUI::CurveProperties() {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   if( Sel->IObjectCount() !=1 )
     return;
@@ -1822,7 +2158,7 @@ void VisuGUI::CurveProperties() {
     // Curve object
     CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
     if( !CORBA::is_nil( aCurve ) ) {
-      VISU::Curve_i* curve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aCurve ) );
+      VISU::Curve_i* curve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
       if ( curve && !isStudyLocked( GetActiveStudy()->getStudyDocument() ) ) {
        SALOMEGUI_SetupCurveDlg* dlg = new SALOMEGUI_SetupCurveDlg( QAD_Application::getDesktop() );    
        dlg->setLine( (int)curve->GetLine(), curve->GetLineWidth() );
@@ -1867,7 +2203,6 @@ void VisuGUI::CurveProperties() {
   Slot : Clears container contents : for Container object selected
 */
 void VisuGUI::ClearContainer() {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   if( Sel->IObjectCount() !=1 )
     return;
@@ -1881,7 +2216,7 @@ void VisuGUI::ClearContainer() {
     // Container object
     CORBA::Object_ptr aCnt = VISU::Container::_narrow( anObject );
     if( !CORBA::is_nil( aCnt ) ) {
-      VISU::Container_i* container = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aCnt ) );
+      VISU::Container_i* container = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCnt).in());
       if ( container && container->GetNbCurves() > 0 && !isStudyLocked( GetActiveStudy()->getStudyDocument() ) ) {
        container->Clear();
        GetActiveStudy()->updateObjBrowser();
@@ -1890,68 +2225,69 @@ void VisuGUI::ClearContainer() {
   }
 }
 
+/*!
+  Slot : Edit container contents : for Container object selected
+*/
+void VisuGUI::EditContainer() {
+  CORBA::Object_var anObject = GetSelectedObj();
+  if(CORBA::is_nil(anObject)) return;
+  PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
+  if(!aServant.in()) return;
+  VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aServant.in());
+  if(!aContainer) return;
+  
+  VisuGUI_EditContainerDlg* aDlg = new VisuGUI_EditContainerDlg();
+  aDlg->initFromPrsObject(aContainer);
+  if (aDlg->exec()) {
+    aDlg->storeToPrsObject(aContainer);
+    GetActiveStudy()->updateObjBrowser( true );
+  }
+  delete aDlg;
+}
+
 
 void VisuGUI::DeletePrs() {
+  SALOMEDS::Study_var aStudy = GetStudyDocument();
+  if (checkLock(aStudy)) return;
+  
+  // There is a transaction
+  SALOMEDS::StudyBuilder_var aStudyBuilder = VisuGUI::NewBuilder();
+  aStudyBuilder->NewCommand();
+
   DeletePresentation(GetSelectedPrs3d());
+
+  aStudyBuilder->CommitCommand();
 }
 
 
 void VisuGUI::SaveViewParams()
 {
   if (checkLock(GetStudyDocument())) return;
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
-  SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
-  if ( Sel->IObjectCount() > 1 || GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) 
+  SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
+  QAD_StudyFrame* aStudyFrame = GetActiveStudy()->getActiveStudyFrame();
+  if ( aSel->IObjectCount() > 1 || aStudyFrame->getTypeView() != VIEW_VTK ) 
     return;
-  VISU::ViewManager_var aVM = GetVisuGen()->GetViewManager();
-  if(!CORBA::is_nil(aVM.in())){
-    VISU::View_var aView = aVM->GetCurrentView();
-    if(!CORBA::is_nil(aView.in())){
-      VISU::View3D_var aView3D = VISU::View3D::_narrow(aView);
-      if(CORBA::is_nil(aView3D.in())) return;
-      if ( Sel->IObjectCount()  == 0 ) {
-       // Save view parameters by new name
-       aView3D->SaveViewParams( 0 );
-       GetActiveStudy()->updateObjBrowser( true );
-      }else{
-       bool isExist;
-       VISU::Storable::TRestoringMap aMap;
-       Handle(SALOME_InteractiveObject) anIO;    
-       CORBA::Object_var anObject = GetSelectedObj(&anIO,GetActiveStudy(),&aMap);
-       VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
-       if(isExist && aType == VISU::TVIEW3D){
-         aView3D->SaveViewParams( anIO->getName() );
-         GetActiveStudy()->updateObjBrowser( true );
-       }
-      }
-    }
+  if ( aSel->IObjectCount()  == 0 ) {
+    VISU::View3D_i::SaveViewParams(aStudyFrame,VISU::View3D_i::GenerateViewParamsName().latin1());
+  }else{
+    const Handle(SALOME_InteractiveObject)& anIO = aSel->firstIObject();
+    VISU::View3D_i::SaveViewParams(aStudyFrame,anIO->getName());
   }
+  GetActiveStudy()->updateObjBrowser( true );
 }
 
 
 void VisuGUI::RestoreViewParams()
 {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
-  SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
-  if ( Sel->IObjectCount() > 1 || GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) 
+  SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
+  QAD_StudyFrame* aStudyFrame = GetActiveStudy()->getActiveStudyFrame();
+  if ( aSel->IObjectCount() > 1 || aStudyFrame->getTypeView() != VIEW_VTK ) 
     return;
-  VISU::ViewManager_var aVM = GetVisuGen()->GetViewManager();
-  if(!CORBA::is_nil(aVM.in())){
-    VISU::View_var aView = aVM->GetCurrentView();
-    if(!CORBA::is_nil(aView.in())){
-      VISU::View3D_var aView3D = VISU::View3D::_narrow(aView);
-      if(CORBA::is_nil(aView3D.in())) return;
-      bool isExist;
-      VISU::Storable::TRestoringMap aMap;
-      Handle(SALOME_InteractiveObject) anIO;    
-      CORBA::Object_var anObject = GetSelectedObj(&anIO,GetActiveStudy(),&aMap);
-      VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
-      if(isExist && aType == VISU::TVIEW3D)
-       aView3D->RestoreViewParams( anIO->getName() );
-    }
-  }
+  const Handle(SALOME_InteractiveObject)& anIO = aSel->firstIObject();
+  VISU::View3D_i::RestoreViewParams(aStudyFrame,anIO->getName());
 }
 
+
 //=====================================================================================
 // function : DeleteViewParams()
 // purpose  :
@@ -2009,14 +2345,20 @@ void VisuGUI::Sweep() {
   }
 
   QApplication::setOverrideCursor( Qt::waitCursor );
-  for (int j=0 ; j<aCycles; j++) {
-    for (int i=0 ; i<=aSteps; i++) {
-      float aPercents = float(i)/aSteps;
-      aPrsObject->SetMapScale(aPercents);
-      aPrsObject->UpdateActor(aActor);
-      vf->getRW()->getRenderWindow()->Render();
-      usleep(aTemp);
+  try{
+    for (int j=0 ; j<aCycles; j++) {
+      for (int i=0 ; i<=aSteps; i++) {
+       float aPercents = float(i)/aSteps;
+       aPrsObject->SetMapScale(aPercents);
+       aPrsObject->UpdateActor(aActor);
+       vf->getRW()->getRenderWindow()->Render();
+       usleep(aTemp);
+      }
     }
+  }catch(std::exception& exc){
+    INFOS("Follow exception was occured :\n"<<exc.what());
+  }catch(...){
+    INFOS("Unknown exception was occured!");
   }
   QApplication::restoreOverrideCursor();
 }
@@ -2053,7 +2395,6 @@ void VisuGUI::TimeAnimation() {
 
 void VisuGUI::ImportMedField() {
   if (checkLock(GetStudyDocument())) return;
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
   QApplication::setOverrideCursor( Qt::waitCursor );
@@ -2085,36 +2426,13 @@ void VisuGUI::ImportMedField() {
   GetActiveStudy()->updateObjBrowser( true );
   QApplication::restoreOverrideCursor();
 }
-/*
-void VisuGUI::ImportMedMesh() {
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
-  SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
-  if ( Sel->IObjectCount() != 1 )
-    return;
-  string aComment;
-  Handle(SALOME_InteractiveObject) anIO;    
-  CORBA::Object_var anObject = GetSelectedObj( aComment,anIO, GetActiveStudy());
-  if ( !CORBA::is_nil( anObject ) ) {
-    SALOME_MED::MESH_ptr aMesh = SALOME_MED::MESH::_narrow( anObject );
-    if( !CORBA::is_nil( aMesh ) ) {
-      GetVisuGen->ImportMedMesh( aMesh );
-      GetActiveStudy()->updateObjBrowser( true );
-    }
-    SALOME_MED::SUPPORT_ptr aSupport = SALOME_MED::SUPPORT::_narrow( anObject );
-    if( !CORBA::is_nil( aSupport ) ) {
-      GetVisuGen->ImportMedSupport( aSupport );
-      GetActiveStudy()->updateObjBrowser( true );
-    }
-  }
-}
-*/
+
 //=====================================================================================
 // functions : Rename()
 // purpose  :
 //=====================================================================================
 void VisuGUI::Rename() {
   if (checkLock(GetStudyDocument())) return;
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   if ( Sel->IObjectCount() != 1 )
     return;
@@ -2129,7 +2447,7 @@ void VisuGUI::Rename() {
       // Curve object
       CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
       if( !CORBA::is_nil( aCurve ) ) {
-       curve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aCurve ) );
+       curve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
       }
     }
   }
@@ -2154,6 +2472,99 @@ void VisuGUI::Rename() {
   }
 }
 
+//=====================================================================================
+// functions : RenameTable()
+// purpose  :
+//=====================================================================================
+void VisuGUI::RenameTable() {
+  if (checkLock(GetStudyDocument())) return;
+  SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
+  if ( Sel->IObjectCount() != 1 )
+    return;
+  SALOMEDS::SObject_var aSObj = GetStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
+  if( aSObj->_is_nil() ) return;
+   
+  VISU::Table_i* table = 0;
+  CORBA::Object_var anObject = GetSelectedObj();
+  if ( !CORBA::is_nil( anObject )) {
+    VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
+    if (!CORBA::is_nil(aVisuObj) && aVisuObj->GetType() == VISU::TTABLE) {
+      // Table object
+      CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
+      if( !CORBA::is_nil( aTable ) ) {
+       table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
+      }
+    }
+  }
+
+  //TEST DU PARENT == VISU
+  SALOMEDS::GenericAttribute_var anAttr;  
+  SALOMEDS::AttributeName_var    aName;
+  if ( aSObj->FindAttribute(anAttr, "AttributeName") ) {
+    aName = SALOMEDS::AttributeName::_narrow( anAttr );
+    QString Name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), aName->Value() );
+    if ( !Name.isEmpty() ) {
+      QApplication::setOverrideCursor( Qt::waitCursor );
+      if ( table )
+       table->SetName( Name.latin1() );
+      GetActiveStudy()->renameIObject( Sel->firstIObject(), Name );
+      QApplication::restoreOverrideCursor();
+      
+      //int TypeMode;  bool InViewer;
+      //VISU_Actor *ActorTmp = ActorSelected(parent,InViewer,&TypeMode);
+      //ActorTmp->setName((Standard_CString)Name.latin1());
+    }
+  }
+}
+
+
+
+//=====================================================================================
+// functions : RenameContainer()
+// purpose  :
+//=====================================================================================
+void VisuGUI::RenameContainer() {
+  if (checkLock(GetStudyDocument())) return;
+  SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
+  if ( Sel->IObjectCount() != 1 )
+    return;
+  SALOMEDS::SObject_var aSObj = GetStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
+  if( aSObj->_is_nil() ) return;
+   
+  VISU::Container_i* container = 0;
+  CORBA::Object_var anObject = GetSelectedObj();
+  if ( !CORBA::is_nil( anObject )) {
+    VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
+    if (!CORBA::is_nil(aVisuObj) && aVisuObj->GetType() == VISU::TCONTAINER) {
+      // Curve object
+      CORBA::Object_ptr aContainer = VISU::Container::_narrow( anObject );
+      if( !CORBA::is_nil( aContainer ) ) {
+       container = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
+      }
+    }
+  }
+
+  //TEST DU PARENT == VISU
+  SALOMEDS::GenericAttribute_var anAttr;  
+  SALOMEDS::AttributeName_var    aName;
+  if ( aSObj->FindAttribute(anAttr, "AttributeName") ) {
+    aName = SALOMEDS::AttributeName::_narrow( anAttr );
+    QString Name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), aName->Value() );
+    if ( !Name.isEmpty() ) {
+      QApplication::setOverrideCursor( Qt::waitCursor );
+      if ( container )
+       container->SetName( Name.latin1() );
+      GetActiveStudy()->renameIObject( Sel->firstIObject(), Name );
+      QApplication::restoreOverrideCursor();
+      
+      //int TypeMode;  bool InViewer;
+      //VISU_Actor *ActorTmp = ActorSelected(parent,InViewer,&TypeMode);
+      //ActorTmp->setName((Standard_CString)Name.latin1());
+    }
+  }
+}
+
+
 
 //=====================================================================================
 // function : CopyPresentation()
@@ -2232,99 +2643,7 @@ void VisuGUI::CopyPresentation(){
   GetActiveStudy()->updateObjBrowser();
 }
 
-//=====================================================================================
-// function : InfoOnPoint() [ slot ] 
-// purpose  :
-//=====================================================================================
-void VisuGUI::InfoOnPoint(){
-  SALOME_Selection *aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
-  int aTypeMode = aSel->SelectionMode();
-  if ( aTypeMode == SelectionPoint ){
-    if(VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d()){
-      vtkDataSet* aDataSet = aPrs3d->GetMapper()->GetInput();
-      VisuGUI_Selection::PickingPoint( GetActiveStudy(), aDataSet);
-    }
-  }else
-    QAD_MessageBox::warn1( GetDesktop(), 
-                          tr ("WARNING"),
-                          tr ("ERR_WRONG_SELECTION_MODE"),
-                          tr ("VISU_BUT_OK") );
-}
 
-//=====================================================================================
-// function : InfoOnCell() [ slot ] 
-// purpose  :
-//=====================================================================================
-void VisuGUI::InfoOnCell(){
-  SALOME_Selection *aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
-  int aTypeMode = aSel->SelectionMode();
-  if( aTypeMode == SelectionCell){
-    if(VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d()){
-      vtkDataSet* aDataSet = aPrs3d->GetMapper()->GetInput();
-      VisuGUI_Selection::PickingCell( GetActiveStudy(), aDataSet);
-    }
-  }else
-    QAD_MessageBox::warn1( GetDesktop(), 
-                          tr ("WARNING"),
-                          tr ("ERR_WRONG_SELECTION_MODE"),
-                          tr ("VISU_BUT_OK") );
-}
-
-//=====================================================================================
-// function : SelectPoint() [ slot ] 
-// purpose  :
-//=====================================================================================
-void VisuGUI::SelectPoint(){
-  SALOME_Selection *aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
-  if ( aSel->SelectionMode() != SelectionPoint ) {
-    QAD_MessageBox::warn1( GetDesktop(), 
-                          tr ("WARNING"),
-                          tr ("ERR_WRONG_SELECTION_MODE"),
-                          tr ("VISU_BUT_OK") );
-    return;
-  }
-  Handle(SALOME_InteractiveObject) anIO;
-  if(VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d(&anIO)){
-    bool ok = FALSE;
-    int anId = SALOMEGUI_SetValueDlg::getInteger( tr("Point selection"),
-                                                tr("Point number:" ), 
-                                                0,
-                                                &ok, 
-                                                GetDesktop());
-    vtkDataSet *aDataSet = aPrs3d->GetMapper()->GetInput();
-    int aMaxId = aDataSet->GetNumberOfPoints();
-    if (ok && 0 < anId && anId <= aMaxId )
-      VisuGUI_Selection::Highlight( GetActiveStudy(), anIO, anId );
-  }
-}
-
-//=====================================================================================
-// function : SelectCell() [ slot ] 
-// purpose  :
-//=====================================================================================
-void VisuGUI::SelectCell(){
-  SALOME_Selection *aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
-  if ( aSel->SelectionMode() != SelectionCell) {
-    QAD_MessageBox::warn1( GetDesktop(), 
-                          tr ("WARNING"),
-                          tr ("ERR_WRONG_SELECTION_MODE"),
-                          tr ("VISU_BUT_OK") );
-    return;
-  }
-  Handle(SALOME_InteractiveObject) anIO;
-  if(VISU::Prs3d_i* aPrs3d = GetSelectedPrs3d(&anIO)){
-    bool ok = FALSE;
-    int anId = SALOMEGUI_SetValueDlg::getInteger( tr("Cell selection"),
-                                                tr("Cell number:" ), 
-                                                0,
-                                                &ok, 
-                                                GetDesktop());
-    vtkDataSet *aDataSet = aPrs3d->GetMapper()->GetInput();
-    int aMaxId = aDataSet->GetNumberOfCells();
-    if (ok && 0 < anId && anId <= aMaxId )
-      VisuGUI_Selection::Highlight( GetActiveStudy(), anIO, anId );
-  }
-}
 
 //=====================================================================================
 // function : DefinePopup()
@@ -2332,7 +2651,6 @@ void VisuGUI::SelectCell(){
 //=====================================================================================
 void VisuGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
 {
-  VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
   theObject = "";
   theContext = "";
 }
@@ -2449,27 +2767,30 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
                          const QString & theParent, const QString & theObject)
 {
   int isViewer = (theParent.compare("ObjectBrowser") != 0), initId = isViewer? 800: 900;
-  VisuGUI::GetOrCreateVisuGUI(parent);
   QAD_ResourceMgr* rmgr = parent->createResourceManager();
 
+  bool aIsLocked = isStudyLocked( GetActiveStudy()->getStudyDocument() );
+  
   bool isVTKViewer = (GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK);
+  SALOME_Selection* aSelection = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
+  QString aParentComponent     = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
+  int nbSel = aSelection->IObjectCount();
+
   thePopup->clear();
 
-  SALOME_Selection* Sel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
-  if ( Sel->IObjectCount() == 0 ) {
-    if ( theParent == "Viewer" && isVTKViewer)
-      // Available only for VTK viewer
+  if ( nbSel == 0 ) {
+    if ( theParent == "Viewer" && isVTKViewer && !aIsLocked)
       thePopup->insertItem( "Save view parameters", visuGUI, SLOT( SaveViewParams() ) );
     return false;
   }
-
-  if( Sel->IObjectCount() > 1 ) {
+  if( nbSel > 1 ) {
     int selMode = checkHomoSelection();
-    MESSAGE( "VisuGUI::CustomPopup: multiple selection : selMode = "<<selMode );
+    if(MYDEBUG) MESSAGE("VisuGUI::CustomPopup: multiple selection : selMode = "<<selMode );
     if ( selMode == homoCurves ) {
       if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
        thePopup->insertItem( "Display", visuGUI, SLOT( DisplayManyPrs() ) );
        thePopup->insertItem( "Erase", visuGUI, SLOT( EraseManyPrs () ) );
+       thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyManyPrs() ) );
       }
     }
     else if ( selMode == homoPresentations ) {
@@ -2479,48 +2800,51 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
       }
     }
     else if ( selMode == homoPresentable ) {
-      thePopup->insertItem("Create Presentations", visuGUI, SLOT(CreateManyMesh()));    
+      if (!aIsLocked) thePopup->insertItem("Create Presentations", visuGUI, SLOT(CreateManyMesh()));    
     }
     else if ( selMode == homoAnimatable ) {
       thePopup->insertItem( "Animation...", visuGUI, SLOT( TimeAnimation() ) );
     }
     return true;
   }
-
   VISU::Storable::TRestoringMap aMap;
-  Handle(SALOME_InteractiveObject) anIO;    
+  Handle(SALOME_InteractiveObject) anIO;
   CORBA::Object_var anObject = GetSelectedObj(&anIO,GetActiveStudy(),&aMap);
   if (!CORBA::is_nil(anObject)) {
     SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(anIO->getEntry());
     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
     if (!CORBA::is_nil(aVisuObj)) {
       VISU::VISUType aType = aVisuObj->GetType();
-      MESSAGE("VisuGUI::CustomPopup - VISU object :: "<<aType);
+      if(MYDEBUG) MESSAGE("VisuGUI::CustomPopup - VISU object :: "<<aType);
       switch (aType) {
       case VISU::TVISUGEN:
-       thePopup->insertItem("Import From File", visuGUI, SLOT(ImportFromFile()));
+       thePopup->insertItem("Import MED", visuGUI, SLOT(ImportFile()));
+       thePopup->insertItem("Import TABLE", visuGUI, SLOT(ImportTablesFromFile()));
+       thePopup->insertItem("Create Plot2d View", visuGUI, SLOT(CreatePlot2dView()));
        break;
 
       case VISU::TRESULT:
-       //thePopup->insertItem("Create Mesh", visuGUI, SLOT(CreateMesh()));    
-       //thePopup->insertItem("Export To File", visuGUI, SLOT(ExportToFile()));    
-       //thePopup->insertItem("Delete", visuGUI, SLOT(DeletePrs()));
+       if (!aIsLocked) thePopup->insertItem("Delete", visuGUI, SLOT(DeleteObject()));
        break;
        
       case VISU::TTABLE:
+       if (!aIsLocked) thePopup->insertItem( "Rename...", visuGUI, SLOT( RenameTable() ) );
        thePopup->insertItem( "Show Table",    visuGUI, SLOT( ShowTable() ) );
-       thePopup->insertItem( "Create Curves", visuGUI, SLOT( PlotData() ) );
+       if (!aIsLocked) thePopup->insertItem( "Create Curves", visuGUI, SLOT( PlotData() ) );
+       thePopup->insertItem( "Export Table", visuGUI, SLOT( ExportTableToFile() ) );
+       thePopup->insertSeparator();
        if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
          if ( GetNbChildren( aSObject, false ) > 0 ) {
-           thePopup->insertItem( "Display",      visuGUI, SLOT( DisplayPrs() ) );
            thePopup->insertItem( "Erase",        visuGUI, SLOT( ErasePrs () ) );
+           thePopup->insertItem( "Display",      visuGUI, SLOT( DisplayPrs() ) );
            thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
          }
        }
+       thePopup->insertItem( "Delete", visuGUI, SLOT( DeleteObject() ) );
        break;
  
       case VISU::TCURVE:
-       if ( !isStudyLocked( GetActiveStudy()->getStudyDocument() ) ) {
+       if ( !aIsLocked ) {
          thePopup->insertItem( "Properties", visuGUI, SLOT( CurveProperties() ) );
          thePopup->insertItem( "Rename...", visuGUI, SLOT(Rename()));
        }
@@ -2534,111 +2858,162 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
        break;
 
       case VISU::TCONTAINER:
-       if( !CORBA::is_nil( anObject ) ) {
-         CORBA::Object_ptr aCnt = VISU::Container::_narrow( anObject );
-         if( !CORBA::is_nil( aCnt ) ) {
-           VISU::Container_i* container = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aCnt ) );
-           if ( container && container->GetNbCurves() > 0 ) {
-             if ( !isStudyLocked( GetActiveStudy()->getStudyDocument() ) ) 
-               thePopup->insertItem( "Clear", visuGUI, SLOT( ClearContainer() ) );
-             if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
-               thePopup->insertItem( "Display", visuGUI, SLOT( DisplayPrs() ) );
-               thePopup->insertItem( "Erase", visuGUI, SLOT( ErasePrs () ) );
-               thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
-             }
-           }
-         }
+//     if( !CORBA::is_nil( anObject ) ) {
+//       CORBA::Object_ptr aCnt = VISU::Container::_narrow( anObject );
+//       if( !CORBA::is_nil( aCnt ) ) {
+//         VISU::Container_i* container = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aCnt).in());
+//         if ( container ) {
+//           if ( !aIsLocked ) {
+//             thePopup->insertItem( "Edit...", visuGUI, SLOT( EditContainer() ) );
+//             thePopup->insertItem( "Rename...", visuGUI, SLOT( RenameContainer() ) );
+//             if (container->GetNbCurves() > 0)
+//               thePopup->insertItem( "Clear", visuGUI, SLOT( ClearContainer() ) );
+//           }
+//           if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
+//             thePopup->insertSeparator();
+//             thePopup->insertItem( "Display", visuGUI, SLOT( DisplayPrs() ) );
+//             thePopup->insertItem( "Erase", visuGUI, SLOT( ErasePrs () ) );
+//             thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
+//           }
+//         }
+//       }
+//     }
+       if ( !aIsLocked ) {
+         thePopup->insertItem( "Edit...", visuGUI, SLOT( EditContainer() ) );
+         thePopup->insertItem( "Rename...", visuGUI, SLOT( RenameContainer() ) );
+         thePopup->insertItem( "Clear", visuGUI, SLOT( ClearContainer() ) );
+       }
+       if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
+         thePopup->insertSeparator();
+         thePopup->insertItem( "Display", visuGUI, SLOT( DisplayPrs() ) );
+         thePopup->insertItem( "Erase", visuGUI, SLOT( ErasePrs () ) );
+         thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
        }
+       if ( !aIsLocked ) thePopup->insertItem( "Delete", visuGUI, SLOT( DeleteObject() ) );
        break;
 
       default: // Presentation
        {
-         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
+         VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject).in());
          if (aPrsObject) {
-           VISU_Actor* anVISUActor = visuGUI->GetActor(aPrsObject);
            if (isVTKViewer) {
              // Add Presentation menu
-             if ((aType != VISU::TSTREAMLINES) && anVISUActor) {
+             if (VISU_Actor* anVISUActor = visuGUI->GetActor(aPrsObject)){
                QPopupMenu* aPresMenu = new QPopupMenu(GetDesktop());
                int aRepresent = anVISUActor->GetRepresentation();
                switch(aRepresent){
-               case 0: //POINTS
+               case VISU::POINT :
                  aPresMenu->insertItem("Wireframe", visuGUI, SLOT(MakeWireframe()));
                  aPresMenu->insertItem("Surface", visuGUI, SLOT(MakeSurface()));
+                 if (aType == VISU::TMESH || aType == VISU::TSCALARMAP || aType == VISU::TDEFORMEDSHAPE)
+                   aPresMenu->insertItem("Insideframe", visuGUI, SLOT(MakeInsideframe()));
+                 if (aType == VISU::TMESH)  
+                   aPresMenu->insertItem("Surfaceframe", visuGUI, SLOT(MakeSurfaceframe()));
                  break;
-               case 1: //WIREFRAME
+               case VISU::WIREFRAME :
+                 aPresMenu->insertItem("Points", visuGUI, SLOT(MakePoints()));
                  aPresMenu->insertItem("Surface", visuGUI, SLOT(MakeSurface()));
+                 if (aType == VISU::TMESH || aType == VISU::TSCALARMAP || aType == VISU::TDEFORMEDSHAPE)
+                   aPresMenu->insertItem("Insideframe", visuGUI, SLOT(MakeInsideframe()));
+                 if (aType == VISU::TMESH)
+                   aPresMenu->insertItem("Surfaceframe", visuGUI, SLOT(MakeSurfaceframe()));
+                 break;
+               case VISU::SHADED :
                  aPresMenu->insertItem("Points", visuGUI, SLOT(MakePoints()));
+                 aPresMenu->insertItem("Wireframe", visuGUI, SLOT(MakeWireframe()));
+                 if (aType == VISU::TMESH || aType == VISU::TSCALARMAP || aType == VISU::TDEFORMEDSHAPE)
+                   aPresMenu->insertItem("Insideframe", visuGUI, SLOT(MakeInsideframe()));
+                 if (aType == VISU::TMESH)
+                   aPresMenu->insertItem("Surfaceframe", visuGUI, SLOT(MakeSurfaceframe()));
                  break;
-               case 2: //SURFACE
+               case VISU::INSIDEFRAME :
+                 aPresMenu->insertItem("Points", visuGUI, SLOT(MakePoints()));
+                 aPresMenu->insertItem("Surface", visuGUI, SLOT(MakeSurface()));
                  aPresMenu->insertItem("Wireframe", visuGUI, SLOT(MakeWireframe()));
+                 if (aType == VISU::TMESH)
+                   aPresMenu->insertItem("Surfaceframe", visuGUI, SLOT(MakeSurfaceframe()));
+                 break;
+               case VISU::SURFACEFRAME :
                  aPresMenu->insertItem("Points", visuGUI, SLOT(MakePoints()));
+                 aPresMenu->insertItem("Surface", visuGUI, SLOT(MakeSurface()));
+                 aPresMenu->insertItem("Wireframe", visuGUI, SLOT(MakeWireframe()));
+                 aPresMenu->insertItem("Insideframe", visuGUI, SLOT(MakeInsideframe()));
                  break;
                }
-               if (anVISUActor->GetShrinkable()) {
-                 if (anVISUActor->isShrunk())
-                   aPresMenu->insertItem("Unshrink", visuGUI, SLOT(MakeShrink()));
-                 else
-                   aPresMenu->insertItem("Shrink", visuGUI, SLOT(MakeShrink()));
+               if(anVISUActor->IsShrunkable())
+                 if(aType != VISU::TVECTORS && aType != VISU::TSTREAMLINES){
+                   if (anVISUActor->IsShrunk())
+                     aPresMenu->insertItem("Unshrink", visuGUI, SLOT(MakeShrink()));
+                   else
+                     aPresMenu->insertItem("Shrink", visuGUI, SLOT(MakeShrink()));
+                 }
+               thePopup->insertItem("Representation", aPresMenu);
+
+               // Add Properties
+               QPopupMenu* aPropMenu = new QPopupMenu(GetDesktop());
+               if(aType == VISU::TMESH){
+                 if(aRepresent == VISU::SURFACEFRAME){
+                   aPropMenu->insertItem("Cell Color", visuGUI, SLOT(ChageColor()));
+                   aPropMenu->insertItem("Edge Color", visuGUI, SLOT(ChangeWireframeColor()));
+                 }else
+                   aPropMenu->insertItem("Color", visuGUI, SLOT(ChageColor()));
+               }else if(aType == VISU::TDEFORMEDSHAPE)
+                 aPropMenu->insertItem("Color", visuGUI, SLOT(ChageColor()));
+
+               if (aType != VISU::TVECTORS && aType != VISU::TSTREAMLINES)
+                 aPropMenu->insertItem("Opacity", visuGUI, SLOT(ChangeOpacity()));
+               if (aType != VISU::TVECTORS){
+                 aPropMenu->insertItem("Line width", visuGUI, SLOT(ChangeLines()));
+                 thePopup->insertItem("Properties", aPropMenu);                  
                }
-               thePopup->insertItem("Representation", aPresMenu);        
+               thePopup->insertSeparator();
              }
-             
-             // Add Properties
-             QPopupMenu* aPropMenu = new QPopupMenu(GetDesktop());
-             if ((aType == VISU::TMESH) || 
-                 (aType ==  VISU::TDEFORMEDSHAPE) || 
-                 (aType == VISU::TVECTORS) ||
-                 (aType == VISU::TSTREAMLINES))
-               aPropMenu->insertItem("Color", visuGUI, SLOT(ChageColor()));
-             if (aType == VISU::TMESH)
-               aPropMenu->insertItem("Outline Color", visuGUI, SLOT(ChangeOutlineColor()));
-             
-             if ((aType != VISU::TVECTORS) && (aType != VISU::TSTREAMLINES))
-               aPropMenu->insertItem("Opacity", visuGUI, SLOT(ChangeOpacity()));
-             aPropMenu->insertItem("Line width", visuGUI, SLOT(ChangeLines()));
-             thePopup->insertItem("Properties", aPropMenu);              
-             
-             thePopup->insertSeparator();
            }
-           thePopup->insertItem("Rename...", visuGUI, SLOT(Rename()));
+           if ( !aIsLocked ) thePopup->insertItem("Rename...", visuGUI, SLOT(Rename()));
            if (aType != VISU::TMESH) {
-             if (aType != VISU::TSCALARMAP)
-               thePopup->insertItem("Edit...", visuGUI, SLOT(EditPrs()));
-             thePopup->insertItem("Edit Scalar Bar...", visuGUI, SLOT(EditScalarBar()));
+             //if (aType != VISU::TSCALARMAP)
+             if ( !aIsLocked ) thePopup->insertItem("Edit...", visuGUI, SLOT(EditPrs()));
              
-             if ((aType != VISU::TVECTORS) && (aType != VISU::TSTREAMLINES) 
-                  && (aType != VISU::TCUTLINES) && isVTKViewer)
-               thePopup->insertItem("Sweep", visuGUI, SLOT(Sweep()));
+             if (aType == VISU::TCUTLINES) {
+               // Check: Does it has living children (tables)
+               SALOMEDS::ChildIterator_var aIter = 
+                 GetActiveStudy()->getStudyDocument()->NewChildIterator( aSObject );
+               bool isPresent = false;
+               for ( ;aIter->More(); aIter->Next()) {
+                 SALOMEDS::SObject_var aTblObj = aIter->Value();
+                 isPresent = !aTblObj->_is_nil();
+                 if (isPresent) {
+                   SALOMEDS::GenericAttribute_var    anAttr;
+                   isPresent = aTblObj->FindAttribute(anAttr, "AttributeName");
+                   if (isPresent) break; // We have at least a one child
+                 }
+               }
+               if ((!isPresent) && (!aIsLocked) )
+                 thePopup->insertItem( "Create Table", visuGUI, SLOT( CreateTable() ) );
+             }
+             thePopup->insertItem("Sweep", visuGUI, SLOT(Sweep()));
              
-             if (aType == VISU::TCUTLINES)
-               thePopup->insertItem( "Create Table", visuGUI, SLOT( CreateTable() ) ); 
            }
            if (isVTKViewer) {
              if ( theParent == "Viewer" && 
                   ( aType == VISU::TMESH      || 
                     aType == VISU::TSCALARMAP || 
                     aType == VISU::TDEFORMEDSHAPE ) ) {
-               thePopup->insertSeparator();
-               if ( Sel->SelectionMode() == SelectionPoint ) {
-                 thePopup->insertItem("Results at Point", visuGUI, SLOT(InfoOnPoint()));
-                 thePopup->insertItem("Select a Point",   visuGUI, SLOT(SelectPoint()));
-               }
-               else if ( Sel->SelectionMode() == SelectionCell) {
-                 thePopup->insertItem("Results on Cell", visuGUI, SLOT(InfoOnCell()));
-                 thePopup->insertItem("Select a Cell",  visuGUI, SLOT(SelectCell()));
-               }
+               thePopup->insertSeparator();
+               thePopup->insertItem("Selection info...",   visuGUI, SLOT(SelectionInfo()));
              }
              thePopup->insertSeparator();
-             if (visuGUI->IsDisplayed(aPrsObject) )
+             
+             if (visuGUI->IsDisplayed(aPrsObject) ){
                thePopup->insertItem("Erase", visuGUI, SLOT(ErasePrs()));
+             }
              else
                thePopup->insertItem("Display", visuGUI, SLOT(DisplayPrs()));
              
              thePopup->insertItem("Display Only", visuGUI, SLOT(DisplayOnlyPrs()));
            }
-           if (aType != VISU::TMESH) {
-             thePopup->insertItem("Delete", visuGUI, SLOT(DeletePrs()));
+           thePopup->insertItem("Delete", visuGUI, SLOT(DeletePrs()));
+           if ((aType != VISU::TMESH) && (!aIsLocked)) {
              thePopup->insertSeparator();
              thePopup->insertItem("Same As", visuGUI, SLOT(CopyPresentation()));
            }
@@ -2647,14 +3022,24 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
       }
       return false;
     }
+    
     else {
-      // possibly this is the MED field/mesh and suppot objects
+      // possibly this is the MED field/mesh and support objects
       SALOME_MED::MED_ptr aMED = SALOME_MED::MED::_narrow( anObject );
       if(!CORBA::is_nil(aMED))
        thePopup->insertItem( "Import Structure", visuGUI, SLOT( ImportMedField() ) );
       SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow( anObject );
       if(!CORBA::is_nil(aField))
         thePopup->insertItem( "Import TimeStamp", visuGUI, SLOT( ImportMedField() ) );
+      if ( aParentComponent != parent->getActiveComponent() )  {
+        //insert pre-defined Display/Erase items
+       if ( thePopup->count() > 0 ) {
+         thePopup->insertSeparator();
+       }
+       thePopup->insertItem (tr ("MEN_APP_DISPLAY"),      GetActiveStudy()->getApp(), SLOT(onDisplay(int)), 0, QAD_Display_Popup_ID);
+       thePopup->insertItem (tr ("MEN_APP_DISPLAY_ONLY"), GetActiveStudy()->getApp(), SLOT(onDisplay(int)), 0, QAD_DisplayOnly_Popup_ID);
+       thePopup->insertItem (tr ("MEN_APP_ERASE"),        GetActiveStudy()->getApp(), SLOT(onErase()),      0, QAD_Erase_Popup_ID);
+      }
       return false;
     }
   }else{
@@ -2667,16 +3052,19 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
        case VISU::TENTITY:
        case VISU::TFAMILY:
        case VISU::TGROUP: 
-         thePopup->insertItem("Create Presentation", visuGUI, SLOT(CreateMesh()));    
+         if ( !aIsLocked )thePopup->insertItem("Create Presentation", visuGUI, SLOT(CreateMesh()));    
          break;
        case VISU::TVIEW3D: 
-         if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { 
-           // Available only for VTK viewer
-           thePopup->insertItem( "Save view parameters", visuGUI, SLOT( SaveViewParams() ) );
+         if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
            thePopup->insertItem( "Restore view parameters", visuGUI, SLOT( RestoreViewParams() ) );
+         if ( !aIsLocked ) {
+           if ( GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { 
+             // Available only for VTK viewer
+             thePopup->insertItem( "Save view parameters", visuGUI, SLOT( SaveViewParams() ) );
+           }
+           thePopup->insertItem( "Rename...", visuGUI, SLOT( Rename() ) );
+           thePopup->insertItem("Delete", visuGUI, SLOT(DeleteViewParams()));
          }
-         thePopup->insertItem( "Rename...", visuGUI, SLOT( Rename() ) );
-         thePopup->insertItem("Delete", visuGUI, SLOT(DeleteViewParams()));
          break;
        case VISU::TFIELD:
          if ((getValue(aSObject, "myNbTimeStamps").toLong() > 1) && isVTKViewer)
@@ -2684,20 +3072,20 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
          break;
        case VISU::TTIMESTAMP: {
          int aNunComponent = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist).toInt();
-         thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_SCALAR_MAP") ), 
+         thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_SCALAR_MAP") ), 
                               "Scalar Map...", visuGUI, SLOT(CreateScalarMap()));
-         thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_ISO_SURFACES") ),
+         thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_ISO_SURFACES") ),
                               "Iso Surfaces...", visuGUI, SLOT(CreateIsoSurfaces()));
-         thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_CUT_PLANES") ),
+         thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_CUT_PLANES") ),
                               "Cut Planes...", visuGUI, SLOT(CreateCutPlanes()));
-         thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_CUT_LINES") ),
+         thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_CUT_LINES") ),
                               "Cut Lines...", visuGUI, SLOT(CreateCutLines()));
          if(aNunComponent > 1){
-           thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_DEFORMED_SHAPE") ),
+           thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_DEFORMED_SHAPE") ),
                                 "Deformed Shape...", visuGUI, SLOT(CreateDeformedShape()));
-           thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_VECTORS") ),
+           thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_VECTORS") ),
                                 "Vectors...", visuGUI, SLOT(CreateVectors()));
-           thePopup->insertItem(rmgr->loadPixmap( "VisuGUI", tr("ICON_STREAM_LINES") ),
+           thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_STREAM_LINES") ),
                                 "Stream lines...", visuGUI, SLOT(CreateStreamLines()));
          }
          break;
@@ -2705,43 +3093,63 @@ bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QStri
        }
        return false;
       }else{
-       SALOMEDS::GenericAttribute_var anAttr;
-       if(aSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) || 
-          aSObject->FindAttribute( anAttr, "AttributeTableOfReal" )){
+
+       if(IsSObjectTable(aSObject)){
          thePopup->insertItem( "Show Table",    visuGUI, SLOT(ShowTable()));
          thePopup->insertItem( "Create Curves", visuGUI, SLOT(PlotData()));
+         thePopup->insertItem( "Export Table", visuGUI, SLOT( ExportTableToFile() ) );
+         thePopup->insertSeparator();
+         thePopup->insertItem( "Delete", visuGUI, SLOT( DeleteObject() ) );
+         return false;
+       }
+
+       CORBA::Long aTag = 1;
+       SALOMEDS::SObject_var aSubObject;
+       if(aSObject->FindSubObject(aTag,aSubObject) && IsSObjectTable(aSubObject)) {
+         thePopup->insertItem( "Delete", visuGUI, SLOT( DeleteObject() ) );
          return false;
        }
+
        aSObject = aSObject->GetFather();
+       if(aSObject->_is_nil()) return false;
+       SALOMEDS::GenericAttribute_var anAttr;
        aSObject->FindAttribute(anAttr, "AttributeName");
        SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
+       if(aName->_is_nil()) return false;
        CORBA::String_var aValue = aName->Value();
        //if(strcmp(aValue.in(),"MEDMESH") == 0)
        //  thePopup->insertItem( "Import MED", visuGUI, SLOT( ImportMedField() ) );
        if(strcmp(aValue.in(),"MEDFIELD") == 0)
          thePopup->insertItem( "Import Field", visuGUI, SLOT( ImportMedField() ) );
+       if ( aParentComponent != parent->getActiveComponent() )  {
+         //insert pre-defined Display/Erase items
+         if ( thePopup->count() > 0 ) {
+           thePopup->insertSeparator();
+         }
+         thePopup->insertItem (tr ("MEN_APP_DISPLAY"),      GetActiveStudy()->getApp(), SLOT(onDisplay(int)), 0, QAD_Display_Popup_ID);
+         thePopup->insertItem (tr ("MEN_APP_DISPLAY_ONLY"), GetActiveStudy()->getApp(), SLOT(onDisplay(int)), 0, QAD_DisplayOnly_Popup_ID);
+         thePopup->insertItem (tr ("MEN_APP_ERASE"),        GetActiveStudy()->getApp(), SLOT(onErase()),      0, QAD_Erase_Popup_ID);
+       }
        return false;
       }
     }
   }
+  return false;
 }
 
 //===========================================================================
 // BuildPresentation
 //===========================================================================
-void VisuGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
+void VisuGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
+                                 QAD_ViewFrame* )
 {
   BEGIN_OF("VisuGUI::BuildPresentation");
 
   if (theIO.IsNull()) {
-    MESSAGE("VisuGUI::BuildPresentation(): null SALOME_InteractiveObject passed");
+    if(MYDEBUG) MESSAGE("VisuGUI::BuildPresentation(): null SALOME_InteractiveObject passed");
     return;
   }
 
-   /* Create or retrieve an object VisuGUI */
-
-  VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
-
   SALOMEDS::Study_var aStudy = GetActiveStudy()->getStudyDocument();
   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
 
@@ -2752,97 +3160,53 @@ void VisuGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
   SALOMEDS::SObject_var aSObj = aStudy -> FindObjectID ( theIO->getEntry() );
   SCRUTE(aSObj);
   if (aSObj -> _is_nil() ) {
-    MESSAGE("No SObject for interacative object is found");
+    if(MYDEBUG) MESSAGE("No SObject for interacative object is found");
     return;
   }
   
   CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
   if(!CORBA::is_nil(anObject)) {
-    
-    VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
+    VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject).in());
     if ( !aPrsObject ) {
-      MESSAGE("The object is not VISU::Prs3d_i");
+      if(MYDEBUG) MESSAGE("The object is not VISU::Prs3d_i");
       return;
     }
     VISU_Actor *SelectedActor = visuGUI->GetActor(aPrsObject);
-    if ( ! SelectedActor )
-      SelectedActor = aPrsObject -> CreateActor();
-    SCRUTE(SelectedActor);
-    if  ( SelectedActor == NULL )   {  
-      MESSAGE("VisuGUI::BuildPresentation(): actor doesn't exist in Render");
-      return;
-    }
-    VTKViewer_ViewFrame* vf = GetVtkViewFrame();
-    vf->AddActor(SelectedActor);
-  }
-    else {
-      MESSAGE("CORBA::is_nil(anObject) = true");
-    }
+    if(!SelectedActor)
+      try{
+       SelectedActor = aPrsObject -> CreateActor();
+       if(VTKViewer_ViewFrame* vf = GetVtkViewFrame())
+         vf->AddActor(SelectedActor);
+      }catch(std::runtime_error& exc){
+       INFOS(exc.what());
+       throw exc; 
+      }
+  }else
+    if(MYDEBUG) MESSAGE("CORBA::is_nil(anObject) = true");
   END_OF("VisuGUI::BuildPresentation");
-
 }
 
-extern "C"
-{
-  bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
-  {
-    //MESSAGE("VisuGUI::OnGUIEvent "<< theCommandID);
-    return VisuGUI::OnGUIEvent(theCommandID, parent);
-  }
 
-  bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
-  {
-    MESSAGE("VisuGUI::OnKeyPress ");
-    return VisuGUI::OnKeyPress (pe, parent, studyFrame);
-  }
-
-  bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
-  {
-    //MESSAGE("VisuGUI::OnMousePress ");
-    return VisuGUI::OnMousePress (pe, parent, studyFrame);
-  }
-
-  bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
-  {
-    //MESSAGE("VisuGUI::OnMouseMove ");
-    return VisuGUI::OnMouseMove (pe, parent, studyFrame);
-  }
-
-  bool SetSettings ( QAD_Desktop* parent )
-  {
-    return VisuGUI::setSettings( parent );
-  }
-
-  bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
-                    const QString & theParent, const QString & theObject )
-  {
-    return VisuGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
-  }
-
-  void definePopup ( QString & theContext, QString & theParent, QString & theObject )
-  {
-    VisuGUI::DefinePopup( theContext, theParent, theObject );
-  }
+//===========================================================================
+// SupportedViewType
+//===========================================================================
+void VisuGUI::SupportedViewType(int* buffer, int bufferSize)
+{
+  if (!buffer || !bufferSize) return;
+  buffer[0] = (int)VIEW_VTK;
+  if (--bufferSize) buffer[1] = (int)VIEW_PLOT2D;
+} 
 
-  bool activeStudyChanged ( QAD_Desktop* parent )
-  {
-    //VisuGUI::activeStudyChanged( parent );
-  }
-    void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
-  {
-    VisuGUI::BuildPresentation(theIO);
+extern "C"
+{
+  Standard_EXPORT SALOMEGUI* GetComponentGUI() {
+    if ( !visuGUI )
+      visuGUI = new VisuGUI( "" );
+    return visuGUI;
   }
-
-  void supportedViewType(int* buffer, int bufferSize)
-  {
-    if (!buffer || !bufferSize) return;
-    buffer[0] = (int)VIEW_VTK;
-    if (--bufferSize) buffer[1] = (int)VIEW_PLOT2D;
-  }  
-
 }
 
+
 //////////////////////////////////////////////////////////////////////////////////
 ////////////////               CHANGE ACTOR COLOR         ////////////////////////
 //////////////////////////////////////////////////////////////////////////////////
@@ -2853,44 +3217,69 @@ extern "C"
 //
 
 void VisuGUI::NewColor(VISU_Actor *theActor){
-  if(VISU::Prs3d_i* aPrs3d = theActor->getPrs3d()){
-    SALOMEDS::Color anOldColor = aPrs3d->GetColor(), aNewColor;
+  if(VISU::Prs3d_i* aPrs3d = theActor->GetPrs3d()){
+    VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d);
+    VISU::DeformedShape_i* aDeformedShape = dynamic_cast<VISU::DeformedShape_i*>(aPrs3d);
+    SALOMEDS::Color anOldColor, aNewColor;
+    int aRepresent = theActor->GetRepresentation();
+    if(aMesh)
+      switch(aRepresent){
+      case VISU::POINT :
+       anOldColor = aMesh->GetNodeColor();
+       break;
+      case VISU::WIREFRAME :
+      case VISU::INSIDEFRAME :
+       anOldColor = aMesh->GetLinkColor();
+       break;
+      case VISU::SHADED :
+      case VISU::SURFACEFRAME :
+       anOldColor = aMesh->GetCellColor();
+       break;
+      }
+    else if(aDeformedShape)
+      anOldColor = aDeformedShape->GetColor();
+    else
+      return;
     QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
     QColor aColorNew = QColorDialog::getColor(aColor, GetDesktop());
     if(aColorNew.isValid()){
       aNewColor.R = aColorNew.red()/255.;
       aNewColor.G = aColorNew.green()/255.;
       aNewColor.B = aColorNew.blue()/255.;
-      aPrs3d->SetColor(aNewColor);
-      aPrs3d->Update();
-      for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++)
-       if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){
-         QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame();
-         if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame))
-           if(VISU_Actor* anActor = GetActor(aPrs3d,aViewFrame))
-             aPrs3d->UpdateActor(anActor);
+      if(aMesh)
+       switch(aRepresent){
+       case VISU::POINT :
+         aMesh->SetNodeColor(aNewColor);
+         break;
+       case VISU::WIREFRAME :
+       case VISU::INSIDEFRAME :
+         aMesh->SetLinkColor(aNewColor);
+         break;
+       case VISU::SHADED :
+       case VISU::SURFACEFRAME :
+         aMesh->SetCellColor(aNewColor);
+         break;
        }
+      else
+       aDeformedShape->SetColor(aNewColor);
+      RecreateActor(aPrs3d);
     }
   }
 }
 
-void VisuGUI::NewOutlineColor(VISUMesh_Actor *theActor){
-  if(VISU::Mesh_i* aPrs3d = dynamic_cast<VISU::Mesh_i*>(theActor->getPrs3d())){
-    SALOMEDS::Color anOldColor = aPrs3d->GetColor(), aNewColor;
-    QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
-    QColor aColorNew = QColorDialog::getColor(aColor, GetDesktop());
-    if(aColorNew.isValid()){
-      aNewColor.R = aColorNew.red()/255.;
-      aNewColor.G = aColorNew.green()/255.;
-      aNewColor.B = aColorNew.blue()/255.;
-      aPrs3d->SetLinkColor(aNewColor);
-      for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++)
-       if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){
-         QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame();
-         if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame))
-           if(VISU_Actor* anActor = GetActor(aPrs3d,aViewFrame))
-             aPrs3d->UpdateActor(anActor);
-       }
+void VisuGUI::NewWireframeColor(VISU_MeshAct *theActor){
+  if(VISU::Prs3d_i* aPrs3d = theActor->GetPrs3d()){
+    if(VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)){
+      SALOMEDS::Color anOldColor = aMesh->GetLinkColor(), aNewColor;
+      QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
+      QColor aColorNew = QColorDialog::getColor(aColor, GetDesktop());
+      if(aColorNew.isValid()){
+       aNewColor.R = aColorNew.red()/255.;
+       aNewColor.G = aColorNew.green()/255.;
+       aNewColor.B = aColorNew.blue()/255.;
+       aMesh->SetLinkColor(aNewColor);
+       VisuGUI::RecreateActor(aMesh);
+      }
     }
   }
 }
@@ -2914,8 +3303,8 @@ void VisuGUI::NewOpacity(VISU_Actor *Actor)
   int intopac;
   CursorDlg->Comment1->setText( tr( "Set value between") );
   CursorDlg->Comment2->setText( tr( "0 (transparent) and 100 (opaque)" ) );
-  oldopac=Actor->GetProperty()->GetOpacity();
-  intopac=int(oldopac*100.);
+  oldopac=Actor->GetOpacity();
+  intopac=int(oldopac*100.+0.5);
   CursorDlg->SpinBox1->setMinValue(0);
   CursorDlg->SpinBox1->setMaxValue(100);
   CursorDlg->SpinBox1->setValue(intopac);
@@ -2925,7 +3314,7 @@ void VisuGUI::NewOpacity(VISU_Actor *Actor)
     {
       intopac  = CursorDlg->SpinBox1->value() ;
       newopac = intopac/100.;
-      Actor->GetProperty()->SetOpacity(newopac);
+      Actor->SetOpacity(newopac);
     }
   delete CursorDlg;
 }
@@ -3054,7 +3443,6 @@ QString VisuGUI::getVisuOutputDir()
 /* ======================================================================================== */
 VISU::Result_i* VisuGUI::CreatePresent(SALOMEDS::SObject_var theField, VISU::Result_var& theResult){
   if(MYDEBUG) MESSAGE("VisuGUI::CreatePresent");
-  VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
   SALOMEDS::SObject_var aSObj = theField->GetFather(); 
   if (CORBA::is_nil(aSObj)) return NULL;
   aSObj = aSObj->GetFather(); if (CORBA::is_nil(aSObj)) return NULL;
@@ -3063,7 +3451,7 @@ VISU::Result_i* VisuGUI::CreatePresent(SALOMEDS::SObject_var theField, VISU::Res
   CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
   if(CORBA::is_nil(anObject)) return NULL;
   theResult = VISU::Result::_narrow(anObject);
-  VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject));
+  VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
   if(pResult == NULL)
     QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
                          tr ("WRN_NO_AVAILABLE_DATA"),
@@ -3074,18 +3462,16 @@ VISU::Result_i* VisuGUI::CreatePresent(SALOMEDS::SObject_var theField, VISU::Res
 #define CREATEPRS(PRSTYPE, FNAME, FCREATE) \
 PRSTYPE* FNAME(SALOMEDS::SObject_var theField, \
               const char* theMeshName, VISU::Entity theEntity, \
-              const char* theFieldName, double theTimeId) {\
+              const char* theFieldName, int theTimeId) {\
   VISU::Result_var aResult; \
   VISU::Result_i* pResult = CreatePresent(theField,aResult); \
   if(pResult != NULL){ \
-    if(PRSTYPE::IsPossible(pResult,theMeshName,(VISU::Entity)theEntity,theFieldName,theTimeId)){ \
-      QApplication::setOverrideCursor( Qt::waitCursor ); \
-      CORBA::Object_var anObject =  \
-       GetVisuGen()->FCREATE(aResult,theMeshName,theEntity,theFieldName,theTimeId); \
-      QApplication::restoreOverrideCursor(); \
-      if(!CORBA::is_nil(anObject))  \
-         return dynamic_cast<PRSTYPE*>(VISU::GetServant(anObject)); \
-    } \
+    QApplication::setOverrideCursor( Qt::waitCursor ); \
+    CORBA::Object_var anObject =  \
+      GetVisuGen()->FCREATE(aResult,theMeshName,theEntity,theFieldName,theTimeId); \
+    QApplication::restoreOverrideCursor(); \
+    if(!CORBA::is_nil(anObject))  \
+      return dynamic_cast<PRSTYPE*>(VISU::GetServant(anObject).in()); \
   } \
   QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"), \
                          tr ("ERR_CANT_BUILD_PRESENTATION"), \
@@ -3114,24 +3500,29 @@ bool FNAME(SALOMEDS::SObject_var theField) { \
   QString aTimeStampId = VISU::Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1(); \
   Utils_Timer timer; \
   if(MYCHECKTIME) timer.Start(); \
-  TYPE* pPresent = FCREATE(theField,aMeshName,(VISU::Entity)anEntity.toInt(),aFieldName,aTimeStampId.toDouble()); \
+  TYPE* pPresent = FCREATE(theField,aMeshName,(VISU::Entity)anEntity.toInt(),aFieldName,aTimeStampId.toInt()); \
   if(MYCHECKTIME) { \
     timer.Stop(); \
     MESSAGE("BUILDPRS(TYPE, FCREATE, FNAME, DLGNAME) - CREATE PRSOBJECT"); \
     timer.Show(); \
   } \
   if (pPresent) { \
-    DLGNAME* aDlg = new DLGNAME(); \
-    aDlg->initFromPrsObject(pPresent); \
-    if (aDlg->exec()) { \
-      aDlg->storeToPrsObject(pPresent); \
-    } else { \
-      DeletePresentation(pPresent); \
-      delete aDlg; \
-      return false; \
+    QString aValue = QAD_CONFIG->getSetting("Visu:BuildDefaultPrs3d"); \
+    if(aValue.isEmpty() || (!aValue.isEmpty() && !aValue.toInt())){ \
+      DLGNAME* aDlg = new DLGNAME(); \
+      aDlg->initFromPrsObject(pPresent); \
+      if (aDlg->exec() && (aDlg->storeToPrsObject(pPresent))) { \
+        delete aDlg; \
+      } else { \
+        DeletePresentation(pPresent); \
+        delete aDlg; \
+        return false; \
+      } \
     } \
-    delete aDlg; \
-    CreateActor(pPresent); \
+     try { \
+       CreateActor(pPresent); \
+     }catch (...) {\
+       return false;} \
     return true; \
   } \
   return false; \
@@ -3141,78 +3532,299 @@ BUILDPRS(VISU::ScalarMap_i, CreateScalarMapPrs, VisuGUI::CreateScalarMap, VisuGU
 BUILDPRS(VISU::DeformedShape_i, CreateDeformedShapePrs, VisuGUI::CreateDeformedShape, VisuGUI_MagnitudeDlg);
 BUILDPRS(VISU::Vectors_i, CreateVectorsPrs, VisuGUI::CreateVectors, VisuGUI_VectorsDlg);
 BUILDPRS(VISU::IsoSurfaces_i, CreateIsoSurfacesPrs, VisuGUI::CreateIsoSurfaces, VisuGUI_IsoSurfacesDlg);
-BUILDPRS(VISU::CutPlanes_i, CreateCutPlanesPrs, VisuGUI::CreateCutPlanes, VisuGUI_CutPlanesDlg);
-BUILDPRS(VISU::CutLines_i, CreateCutLinesPrs, VisuGUI::CreateCutLines, VisuGUI_CutLinesDlg);
+//BUILDPRS(VISU::CutPlanes_i, CreateCutPlanesPrs, VisuGUI::CreateCutPlanes, VisuGUI_CutPlanesDlg);
+//BUILDPRS(VISU::CutLines_i, CreateCutLinesPrs, VisuGUI::CreateCutLines, VisuGUI_CutLinesDlg);
 BUILDPRS(VISU::StreamLines_i, CreateStreamLinesPrs, VisuGUI::CreateStreamLines, VisuGUI_StreamLinesDlg);
 
 
+bool VisuGUI::CreateCutPlanes(SALOMEDS::SObject_var theField) { 
+  try {
+  VISU::Storable::TRestoringMap aMap = getMapOfValue(theField); 
+  bool isExist; 
+  QString aType = VISU::Storable::FindValue(aMap,"myType",&isExist); 
+  if(!isExist || aType.toInt() != VISU::TTIMESTAMP ) return false; 
+  QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName",&isExist).latin1(); 
+  QString anEntity = VISU::Storable::FindValue(aMap,"myEntityId",&isExist).latin1();
+  QString aFieldName = VISU::Storable::FindValue(aMap,"myFieldName",&isExist).latin1(); 
+  QString aTimeStampId = VISU::Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1();
+  Utils_Timer timer;
+  if(MYCHECKTIME) timer.Start();
+  VISU::CutPlanes_i* pPresent = 
+    CreateCutPlanesPrs(theField,aMeshName,(VISU::Entity)anEntity.toInt(),aFieldName,aTimeStampId.toInt());
+  if(MYCHECKTIME) {
+    timer.Stop();
+    MESSAGE("BUILDPRS(TYPE, FCREATE, FNAME, DLGNAME) - CREATE PRSOBJECT");
+    timer.Show();
+  }
+  if (pPresent) {
+    QString aValue = QAD_CONFIG->getSetting("Visu:BuildDefaultPrs3d");
+    if(aValue.isEmpty() || (!aValue.isEmpty() && !aValue.toInt())){
+      VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(true, false);
+      aDlg->initFromPrsObject(pPresent);
+      aDlg->show();
+      myActiveDialogBox = aDlg;      
+//       if (aDlg->exec() && (aDlg->storeToPrsObject(pPresent))) {
+//         delete aDlg;
+//       } else {
+//         DeletePresentation(pPresent);
+//         delete aDlg;
+//         return false;
+//       }
+//     }
+//     CreateActor(pPresent);
+      return true;
+    }
+  }
+}catch (...){return false;}
+  return false;
+}
+
+bool VisuGUI::CreateCutLines(SALOMEDS::SObject_var theField) { 
+try {
+  VISU::Storable::TRestoringMap aMap = getMapOfValue(theField); 
+  bool isExist; 
+  QString aType = VISU::Storable::FindValue(aMap,"myType",&isExist); 
+  if(!isExist || aType.toInt() != VISU::TTIMESTAMP ) return false; 
+  QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName",&isExist).latin1(); 
+  QString anEntity = VISU::Storable::FindValue(aMap,"myEntityId",&isExist).latin1(); 
+  QString aFieldName = VISU::Storable::FindValue(aMap,"myFieldName",&isExist).latin1(); 
+  QString aTimeStampId = VISU::Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1(); 
+  Utils_Timer timer; 
+  if(MYCHECKTIME) timer.Start(); 
+  VISU::CutLines_i* pPresent = CreateCutLinesPrs(theField,aMeshName,
+                                    (VISU::Entity)anEntity.toInt(),
+                                    aFieldName,aTimeStampId.toInt()); 
+  if(MYCHECKTIME) { 
+    timer.Stop(); 
+    MESSAGE("BUILDPRS(VISU::CutLines_i, CreateCutLinesPrs, VisuGUI::CreateCutLines, VisuGUI_CutLinesDlg) - CREATE PRSOBJECT");
+    timer.Show(); 
+  } 
+  if (pPresent) { 
+    QString aValue = QAD_CONFIG->getSetting("Visu:BuildDefaultPrs3d"); 
+    if(aValue.isEmpty() || (!aValue.isEmpty() && !aValue.toInt())){ 
+      VisuGUI_CutLinesDlg* aDlg = new VisuGUI_CutLinesDlg(true); 
+      aDlg->initFromPrsObject(pPresent); 
+      aDlg->show();
+      myActiveDialogBox = aDlg;
+      return true;
+//       if (aDlg->exec()) { 
+//         aDlg->storeToPrsObject(pPresent);
+//     if (aDlg->isGenerateTable()) {
+//       GetVisuGen()->CreateTable(pPresent->GetEntry());
+//       if (aDlg->isGenerateCurves()) {
+//         SALOMEDS::Study_var aStudy = GetActiveStudy()->getStudyDocument();
+//         SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(pPresent->GetEntry());
+//         if(!aSObject->_is_nil()) {
+//           SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator( aSObject );
+//           SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
+//           for ( ;aIter->More(); aIter->Next()) {
+//             SALOMEDS::SObject_var aTblObj = aIter->Value();
+//             if (!aTblObj->_is_nil()) {
+//               SALOMEDS::GenericAttribute_var anAttr;
+//               if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
+//                 CreatePlot(aTblObj);
+//               }
+//             }
+//           }
+//         }
+//       }
+//       GetActiveStudy()->updateObjBrowser();  
+//     }
+//       } else { 
+//         DeletePresentation(pPresent); 
+//         delete aDlg; 
+//         return false; 
+//       } 
+//       delete aDlg; 
+//     } 
+//     CreateActor(pPresent); 
+//     return true; 
+    } 
+  }
+}catch (...){return false; }
+  return false; 
+}
+
+
 
 /* ======================================================================================== */
 /* Global Method to import tables from file */
 /* ======================================================================================== */
 void VisuGUI::ImportTablesFromFile(){
+  if (checkLock(GetActiveStudy()->getStudyDocument())) return;
   QStringList flt;
   flt.append( "Files (*.xls *.txt *.tab)" );
   flt.append( "All Files (*.*)" );
   QString aDir = getVisuInputDir();
-  QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
+  QFileInfo aFileInfo = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
                                           aDir,flt,tr("Import From File"),true);
-  if(!aFile.isEmpty()){
-    QAD_Application::getDesktop()->putInfo( "Importing From File " + aFile + "..." );
-    aDir = QAD_Tools::getDirFromPath(aFile);
+  
+  if(aFileInfo.exists()){
+    QAD_Application::getDesktop()->putInfo( "Importing From File " + aFileInfo.filePath() + "..." );
+    aDir = QAD_Tools::getDirFromPath(aFileInfo.filePath());
     QAD_CONFIG->addSetting("Visu:InputDir",aDir);
-    QApplication::setOverrideCursor( Qt::waitCursor );
-    QAD_PyInterp* myPyInterp = GetActiveStudy()->get_PyInterp();
-    myPyInterp->run("import VisuGUI");
-    myPyInterp->run("reload(VisuGUI)");
-    myPyInterp->run("VisuGUI.AddTablesInStudyFromFile('"+aFile+"')");
-    //     VISU::Result_var aResult = myComponent->ImportFile(aFile.latin1());
-    //     if(aResult->_is_nil())
-    //       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
-    //                               tr ("There is an error in imported file"),
-    //                               tr ("VISU_BUT_OK") );
-    //     else
-    // QAD_Application::getDesktop()->putInfo(aFile+" imported.");
+    QAD_WaitCursor wc;
+
+    CORBA::Object_var anObject;
+#ifdef CHECKTIME
+    Utils_Timer timer;
+    timer.Start();
+#endif
+   
+    anObject=GetVisuGen()->ImportTables(aFileInfo.filePath());
+    
+#ifdef CHECKTIME
+    timer.Stop();
+    MESSAGE("VisuGUI::ImportTablesFromFile() - IMPORT FILE");
+    timer.Show();
+#endif
+    
+    if(CORBA::is_nil(anObject)) {
+      wc.stop();
+      QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                             tr ("ERR_ERROR_IN_THE_FILE"),
+                             tr ("VISU_BUT_OK") );
+      wc.start();
+    }
+    else {
+      QAD_Application::getDesktop()->putInfo(aFileInfo.filePath()+" imported.");
+    }
     GetActiveStudy()->updateObjBrowser(); //update Object browser
-    QApplication::restoreOverrideCursor();
   }
-}
+} 
+
+void VisuGUI::ExportTableToFile() 
+{
+  QAD_Study *aQADStudy = VisuGUI::GetActiveStudy();
+  SALOME_Selection* aSel = SALOME_Selection::Selection (  aQADStudy -> getSelection() );
+
+  if( aSel->IObjectCount() > 0 ) {
+    const Handle(SALOME_InteractiveObject)& anIO = aSel->firstIObject();
+    if(anIO->hasEntry()){
+      SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
+      SALOMEDS::SObject_var aSObj = aStudy -> FindObjectID(anIO->getEntry());
+      if(CORBA::is_nil(aSObj))  return; 
+
+      QString aTitle;
+      SALOMEDS::GenericAttribute_var anAttr;
+
+      if (!aSObj->FindAttribute(anAttr, "AttributeTableOfReal") && 
+         !aSObj->FindAttribute(anAttr, "AttributeTableOfInteger")) {
+       aSObj = aSObj->GetFather(); //if the current SObject is a table title
+                                   // we take a father contaning the table 
+       if (!CORBA::is_nil(aSObj)) {
+         if (!aSObj->FindAttribute(anAttr, "AttributeTableOfReal") && 
+             !aSObj->FindAttribute(anAttr, "AttributeTableOfInteger"))
+           return;
+       }
+       else return;
+      }
+      if (CORBA::is_nil(anAttr)) return;
 
+      SALOMEDS::AttributeTableOfReal_var aTabAttr = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
+      if (!CORBA::is_nil(aTabAttr)) 
+       aTitle  = aTabAttr->GetTitle(); //get table title in order to have default name of the file 
+      else {
+       SALOMEDS::AttributeTableOfInteger_var aTabAttr = SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
+       if (!CORBA::is_nil(aTabAttr))
+         aTitle  = aTabAttr->GetTitle(); //get table title in order to have default name of the file 
+       else return;
+      }
+      aTitle.simplifyWhiteSpace();
+      QStringList flt;
+      flt.append("Table Files (*.xls)");
+      
+      QAD_FileDlg *aDlg = new QAD_FileDlg(QAD_Application::getDesktop(), false, true, true);
+      aDlg -> setCaption("Export Table To File");
+      aDlg -> setDir( getVisuOutputDir() );
+      aDlg -> setFilters(flt);
+      aDlg -> setSelection(aTitle.replace(QRegExp(" "), "_"));
+      aDlg -> exec();
+      QString aFile = aDlg -> selectedFile();
+      delete aDlg;
+
+      if(!aFile.isEmpty()){
+       QAD_Application::getDesktop()->putInfo( "Exporting To File " + aFile + "..." );
+       QString aDir = QAD_Tools::getDirFromPath(aFile);
+       QAD_CONFIG->addSetting("Visu:OutputDir",aDir);
+       
+       try {
+         GetVisuGen() -> ExportTableToFile(aSObj, aFile.latin1());
+         QAD_Application::getDesktop()->putInfo(aFile+" exported.");
+       } catch(std::exception& ex) {
+         INFOS(ex.what());
+         QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                                tr ("ERR_ERROR_DURING_EXPORT") + " " + tr(ex.what()),
+                                tr ("VISU_BUT_OK") );
+       } catch(...) {
+         INFOS(tr ("ERR_ERROR_DURING_EXPORT"));
+         QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                                tr ("ERR_ERROR_DURING_EXPORT"),
+                                tr ("VISU_BUT_OK") );
+       } 
+      } 
+    }
+  }
+}
 /* ======================================================================================== */
 /* Global Method to import mesh results in MED and DAT format                               */
 /* ======================================================================================== */
-void VisuGUI::ImportFromFile(){
+void VisuGUI::ImportFile(){
+  VisuGUI::ImportFromFile(&VISU::VISU_Gen_i::ImportFile);
+}
+void VisuGUI::CopyAndImportFile(){
+  VisuGUI::ImportFromFile(&VISU::VISU_Gen_i::CopyAndImportFile);
+}
+void VisuGUI::ImportFromFile(TImportFun theImportFun){
   if (checkLock(GetActiveStudy()->getStudyDocument())) return;
   QStringList flt;
   //flt.append( "Exportable Files (*.med *.dat)" );
   //flt.append( "Dat Files (*.dat)" );
   flt.append( "Med Files (*.med)" );
-  flt.append( "Dat Files (*.xls)" );
   QString aDir = getVisuInputDir();
-  QFileInfo aFileInfo = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                                aDir,flt,tr("Import From File"),true);
+  QFileInfo aFileInfo = VisuGUI_FileDlg::getFileName(QAD_Application::getDesktop(),
+                                                    aDir,flt,tr("Import From File"),true);
+  
   if(aFileInfo.exists()){
     QAD_Application::getDesktop()->putInfo( "Importing From File " + aFileInfo.filePath() + "..." );
     aDir = QAD_Tools::getDirFromPath(aFileInfo.filePath());
     QAD_CONFIG->addSetting("Visu:InputDir",aDir);
     QAD_WaitCursor wc;
-
-    CORBA::Object_var anObject;
+    
+    VISU::Result_var aResult;
+    
 #ifdef CHECKTIME
     Utils_Timer timer;
     timer.Start();
 #endif
-    if(aFileInfo.extension(false) == "med")
-       anObject = GetVisuGen()->ImportFile(aFileInfo.filePath());
-    else if(aFileInfo.extension(false) == "xls")
-       anObject = GetVisuGen()->ImportTables(aFileInfo.filePath());
+    if(aFileInfo.extension(false) == "med"){
+      QString IsBuild = QAD_CONFIG->getSetting("Visu:BuildResult");
+      bool isBuild = (IsBuild.isEmpty()? 0 : IsBuild.toInt());
+      if (VisuGUI_FileDlg::IsBuild){
+       aResult = GetVisuGen()->ImportFile(aFileInfo.filePath());
+       if(!CORBA::is_nil(aResult.in())) 
+         if(VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(GetServant(aResult).in())){
+           if(!pResult->IsPossible())
+             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                                     tr ("ERR_CANT_BUILD_PRESENTATION"),
+                                     tr ("VISU_BUT_OK") );
+           else
+             aResult->BuildAll();  
+         }
+      }else{
+       QAD_CONFIG->addSetting( "Visu:BuildResult", false );
+       //aResult=(GetVisuGen()->*theImportFun)(aFileInfo.filePath()); APO: 18/12/03 - fix crash on Linux RedHat 7.1
+       aResult=GetVisuGen()->ImportFile(aFileInfo.filePath());     // APO: 18/12/03 - fix crash on Linux RedHat 7.1
+       QAD_CONFIG->addSetting( "Visu:BuildResult", isBuild );
+      }
+    }
 #ifdef CHECKTIME
     timer.Stop();
     MESSAGE("VisuGUI::ImportFromFile() - IMPORT FILE");
     timer.Show();
 #endif
 
-    if(CORBA::is_nil(anObject)) {
+    if(CORBA::is_nil(aResult.in())) {
       wc.stop();
       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
                             tr ("ERR_ERROR_IN_THE_FILE"),
@@ -3229,7 +3841,7 @@ void VisuGUI::ImportFromFile(){
 void VisuGUI::ExportToFile(){
   CORBA::Object_var anObject = GetSelectedObj();
   if(CORBA::is_nil(anObject)) return;
-  VISU::Base_i* aBase = dynamic_cast<VISU::Base_i*>(VISU::GetServant(anObject));
+  VISU::Base_i* aBase = dynamic_cast<VISU::Base_i*>(VISU::GetServant(anObject).in());
   if(aBase != NULL && aBase->GetType() == VISU::TRESULT){
     QStringList flt;
     flt.append( "Dat Files (*.dat)" );
@@ -3245,7 +3857,14 @@ void VisuGUI::ExportToFile(){
        try{
          //APO - aResult->GetInput()->ToFile(aFile.latin1());
          QAD_Application::getDesktop()->putInfo(aFile+" exported.");
-       }catch(...){
+       }catch(std::exception& ex) {
+         INFOS(ex.what());
+         QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                                tr ("ERR_ERROR_DURING_EXPORT") + " " +tr(ex.what()),
+                                tr ("VISU_BUT_OK") );
+       } 
+       catch(...){
+         INFOS(tr ("ERR_ERROR_DURING_EXPORT").latin1());
          QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
                                 tr ("ERR_ERROR_DURING_EXPORT"),
                                 tr ("VISU_BUT_OK") );
@@ -3265,7 +3884,7 @@ bool VisuGUI::TestObjectBrowser(SALOMEDS::SObject_var& objVisu ){
   if(MYDEBUG) MESSAGE("VisuGUI::TestObjectBrowser");
   Handle(SALOME_InteractiveObject) anIO;    
   CORBA::Object_var anObject = GetSelectedObj(&anIO);
-  if(anIO->hasEntry()){
+  if(!anIO.IsNull() && anIO->hasEntry()){
     objVisu = GetStudyDocument()->FindObjectID(anIO->getEntry());
     QString aValue = getValue(objVisu,"myType");
     if((VISU::VISUType)aValue.toInt() == VISU::TTIMESTAMP) return true;
@@ -3286,7 +3905,7 @@ VISU_Actor* VisuGUI::GetActor(VISU::Prs3d_i* thePrs, VTKViewer_ViewFrame* theVie
   vtkActorCollection *anActColl = vf->getRenderer()->GetActors();
   for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;)
     if(VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor))
-      if(thePrs == anVISUActor->getPrs3d())
+      if(thePrs == anVISUActor->GetPrs3d())
        return anVISUActor->GetParent();
   return NULL;
 }
@@ -3309,26 +3928,33 @@ VISU_Actor* VisuGUI::UpdateViewer(VISU::Prs3d_i* thePrs, bool theDispOnly){
   for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
     if(anActor->IsA("VISU_Actor")){ 
       anVISUActor = VISU_Actor::SafeDownCast(anActor);
-      VISU::Prs3d_i* aPrs = anVISUActor->getPrs3d();      
+      VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();      
       if(aPrs == NULL) continue;
       if (thePrs == aPrs) {
        aResActor = anVISUActor->GetParent();
        thePrs->UpdateActor(aResActor);
        aResActor->VisibilityOn();
+        
       } else if (theDispOnly) {
-       anVISUActor->VisibilityOff();
+       anVISUActor->GetParent()->VisibilityOff();
+      } else {
       }
+    } else if (theDispOnly && anActor->GetVisibility()) {
+      anActor->VisibilityOff();
+    } else {
     } 
   }
   if (aResActor) return aResActor;
-  anVISUActor = thePrs->CreateActor();
-  MESSAGE("UpdateViewer - thePrs->CreateActor() = "<<anVISUActor);
-  if ( anVISUActor ) {
+  try{
+    anVISUActor = thePrs->CreateActor();
     vf->AddActor(anVISUActor);
-  } else 
+  } catch ( std::runtime_error& exc ){
+    INFOS(exc.what());
     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
-                           tr ("ERR_CANT_VISUALIZE_OBJECT"),
-                           tr ("VISU_BUT_OK") );
+                          tr("ERR_CANT_VISUALIZE_OBJECT") + " " + tr(exc.what()),
+                          tr ("VISU_BUT_OK") );
+    anVISUActor = NULL;
+  }
   return anVISUActor;
 }
 
@@ -3361,13 +3987,15 @@ void VisuGUI::DeletePresentation(VISU::Prs3d_i* thePrs) {
   for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++)
     if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){
       QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame();
-      if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame))
+      if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aVFrame)){
        if(VISU_Actor* anActor = GetActor(thePrs,aViewFrame)){
          aViewFrame->RemoveActor(anActor);
          anActor->Delete();
        }
+       aViewFrame->unHighlightAll();
+      }
     }
-  thePrs->Destroy();
+  thePrs->RemoveFromStudy(); 
   GetActiveStudy()->updateObjBrowser(); //update Object browser
 }
 
@@ -3375,27 +4003,40 @@ void VisuGUI::DeletePresentation(VISU::Prs3d_i* thePrs) {
  * Creates new actor of presentation
  */
 void VisuGUI::CreateActor(VISU::Prs3d_i* thePrs) {
- if (!thePrs) return;
+  if (GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK) return;
+  if (!thePrs) return;
   QApplication::setOverrideCursor( Qt::waitCursor );
-  VTKViewer_ViewFrame* vf = GetVtkViewFrame();
-  if (vf) {
+  if(VTKViewer_ViewFrame* vf = GetVtkViewFrame()){
 #ifdef CHECKTIME
-  Utils_Timer timer;
-  timer.Start();
+    Utils_Timer timer;
+    timer.Start();
 #endif
-    VISU_Actor* aActor = thePrs->CreateActor();
-    if ( ! aActor ) {
+    try{
+      MESSAGE("Available memory : "<<VISU_PipeLine::GetAvailableMemory());
+      VISU_Actor* aActor = thePrs->CreateActor();
+      vf->AddActor(aActor);
+    }catch(std::runtime_error& exc) {
+      INFOS("std::runtime_error "<<exc.what());
+      INFOS("Available memory : "<<VISU_PipeLine::GetAvailableMemory());
       QApplication::restoreOverrideCursor();
       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
-                            tr ("WRN_CANT_VISUALIZE_PRS"),
+                               tr ("WRN_CANT_VISUALIZE_PRS") + " " + tr(exc.what()),
+                               tr ("VISU_BUT_OK") );
+      throw exc;
+    } catch (...) {
+      MESSAGE(" Unknown exception");
+      QApplication::restoreOverrideCursor();
+      INFOS("Unknown exception is caught in VisuGUI::CreateActor");
+      INFOS("Available memory : "<<VISU_PipeLine::GetAvailableMemory());
+      QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
+                            tr ("WRN_CANT_VISUALIZE_PRS") + " " + tr("ERR_UNKNOWN_EXCEPTION"),
                             tr ("VISU_BUT_OK") );
-      return;
+      throw ;
     }
-    vf->AddActor(aActor);
 #ifdef CHECKTIME
-  timer.Stop();
-  MESSAGE("VisuGUI::CreateActor(VISU::Prs3d_i* thePrs) - DISPLAY ACTOR");
-  timer.Show();
+    timer.Stop();
+    MESSAGE("VisuGUI::CreateActor(VISU::Prs3d_i* thePrs) - DISPLAY ACTOR");
+    timer.Show();
 #endif
   }
   QApplication::restoreOverrideCursor();