Salome HOME
All modules must use SVTK package instead VTK
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
index 671c811d1627f99a1abe55afdde618e42a3c7676..030fdd0677e4ea2bcadc047c07b92a6ebc4a979d 100644 (file)
@@ -162,7 +162,7 @@ namespace VISU
     return aStr;
   }
 
-  //************************************************************
+  //------------------------------------------------------------
   // Selection
   CORBA::Object_var
   GetSelectedObj(const SalomeApp_Study* theStudy,
@@ -206,6 +206,25 @@ namespace VISU
     return CORBA::Object::_nil();
   }
 
+  VISU::Prs3d_i*
+  GetPrsToModify(const SalomeApp_Module* theModule,
+                Handle(SALOME_InteractiveObject)* theIO,
+                VISU::Storable::TRestoringMap* theMap)
+  {
+    if (CheckLock(GetCStudy(GetAppStudy(theModule))))
+      return NULL;
+
+    CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
+    if (CORBA::is_nil(anObject))
+      return NULL;
+
+    PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
+    if (!aServant.in())
+      return NULL;
+
+    return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
+  }
+
   void
   Add(SalomeApp_SelectionMgr* theSelectionMgr,
       const Handle(SALOME_InteractiveObject)& theIO)
@@ -253,7 +272,7 @@ namespace VISU
     if (!aStudy) return false;
 
     // In some cases single selection can have its own popup-menu item for deletion
-    if (aListIO.Extent() == 1) {
+    /*if (aListIO.Extent() == 1) {
       Handle(SALOME_InteractiveObject) anIO = aListIO.First();
       _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
       if (aSObject) {
@@ -262,7 +281,7 @@ namespace VISU
           return false; // special case
         }
       }
-    }
+    }*/
 
     SALOME_ListIteratorOfListIO anIter (aListIO);
     for (; anIter.More(); anIter.Next()) {
@@ -271,14 +290,14 @@ namespace VISU
         _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
         VISU::Storable::TRestoringMap pMap;
         if (aSObject) {
-         CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
-         if (!CORBA::is_nil(aCORBAObject)) {
-           VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
-           if (CORBA::is_nil(aRemovableObj)) {
+          CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
+          if (!CORBA::is_nil(aCORBAObject)) {
+            VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
+            if (CORBA::is_nil(aRemovableObj)) {
               // Not removable CORBA object
               return false;
             }
-         } else {
+          } else {
             // Can be removed, if lays directly under VISU
             // (first sub-level) or is a child of such an object
             string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
@@ -316,7 +335,7 @@ namespace VISU
                 return false;
               }
             }
-         }
+          }
         }
       }
     }
@@ -338,13 +357,13 @@ namespace VISU
       case VISU::TCURVE:
         {
           if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
-           PlotCurve(theModule, aCurve, VISU::eErase );
+            PlotCurve(theModule, aCurve, VISU::eErase );
           break;
         }
       case VISU::TCONTAINER:
         {
           if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
-           PlotContainer(theModule, aContainer, VISU::eErase );
+            PlotContainer(theModule, aContainer, VISU::eErase );
           break;
         }
       case VISU::TTABLE:
@@ -356,11 +375,11 @@ namespace VISU
       default:
         {
           if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
-           ErasePrs3d(theModule, aPrsObject);
-           if (theUpdate) {
-             if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
-               vw->Repaint();
-           }
+            ErasePrs3d(theModule, aPrsObject);
+            if (theUpdate) {
+              if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
+                vw->Repaint();
+            }
           }
         }
       } // switch (aType)
@@ -372,21 +391,28 @@ namespace VISU
                  _PTR(Study)       theStudy,
                  _PTR(SObject)     theSObject)
   {
+    SalomeApp_Study* study = GetAppStudy( theModule );
+    study->deleteReferencesTo( theSObject );
+
     _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
       _PTR(SObject) aChildSObject = aChildIter->Value();
+      study->deleteReferencesTo( aChildSObject );
       CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
       ErasePrs(theModule, aChildObj);
     }
 
     CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
     if (!CORBA::is_nil(anObj)) {
+      ErasePrs(theModule, anObj);
+
       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
       if (!CORBA::is_nil(aRemovableObject)) {
         aRemovableObject->RemoveFromStudy();
       }
     } else {
       // Remove aSObject together with all its sub-objects
+
       VISU::RemoveFromStudy(theSObject,
                             false,  // remove not only IOR attribute, but Object With Children
                             false); // not Destroy() sub-objects
@@ -395,8 +421,8 @@ namespace VISU
 
   void
   DeletePrs3d(SalomeApp_Module* theModule,
-             VISU::Prs3d_i* thePrs,
-             const Handle(SALOME_InteractiveObject)& theIO)
+              VISU::Prs3d_i* thePrs,
+              const Handle(SALOME_InteractiveObject)& theIO)
   {
     if (!thePrs)
       return;
@@ -410,22 +436,21 @@ namespace VISU
     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
       SVTK_ViewWindow* aView = aViewWindows[i];
       if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
-       aView->RemoveActor(anActor);
-       anActor->Delete();
+        aView->RemoveActor(anActor);
+        anActor->Delete();
       }
     }
     thePrs->RemoveFromStudy();
-    theModule->updateObjBrowser(); //update Object browser
   }
 
   void
   ErasePrs3d(const SalomeApp_Module* theModule,
-            VISU::Prs3d_i* thePrs)
+             VISU::Prs3d_i* thePrs)
   {
     if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
       VISU_Actor* anVISUActor = FindActor( vw, thePrs );
       if (anVISUActor) {
-       anVISUActor->VisibilityOff();
+        anVISUActor->VisibilityOff();
       }
     }
   }
@@ -437,13 +462,19 @@ namespace VISU
   ChangeRepresentation (const SalomeApp_Module* theModule,
                         VISU::PresentationType  theType)
   {
-    SUIT_ViewWindow* aView = GetActiveView(theModule, VTKViewer_Viewer::Type());
+    SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
     if (!aView) return;
-    SVTK_ViewWindow* vw  = (SVTK_ViewWindow*) aView;
+    SVTK_ViewWindow* vw  = dynamic_cast<SVTK_ViewWindow*>( aView );
+    if( !vw )
+      return;
 
     Handle(SALOME_InteractiveObject) anIO;
     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
     if (CORBA::is_nil(anObject)) return;
+
+    VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
+    if (CORBA::is_nil(aVisuObj)) return;
+
     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
     if (!aServant.in()) return;
 
@@ -456,13 +487,13 @@ namespace VISU
             anActor->UnShrink();
           else
             anActor->SetShrink();
-         break;
+          break;
         default:
-         if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
-           aMesh->SetPresentationType(theType);
-           RecreateActor(theModule, aMesh);
-         } else {
-           anActor->SetRepresentation(theType);
+          if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
+            aMesh->SetPresentationType(theType);
+            RecreateActor(theModule, aMesh);
+          } else {
+            anActor->SetRepresentation(theType);
           }
         }
         vw->Repaint();
@@ -475,8 +506,8 @@ namespace VISU
 
   bool
   CheckTimeStamp(const SalomeApp_Module* theModule,
-                _PTR(SObject)&          theSObject,
-                Handle(SALOME_InteractiveObject)* theIO)
+                 _PTR(SObject)&          theSObject,
+                 Handle(SALOME_InteractiveObject)* theIO)
   {
     Handle(SALOME_InteractiveObject) anIO;
     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
@@ -487,19 +518,19 @@ namespace VISU
       theSObject = aStudy->FindObjectID(anIO->getEntry());
       QString aValue = getValue(theSObject,"myType");
       if (aValue.toInt() == int(VISU::TTIMESTAMP))
-       return true;
+        return true;
     }
     SUIT_MessageBox::warn1(GetDesktop(theModule),
-                          QObject::tr("WRN_VISU"),
-                          QObject::tr("WRN_NO_AVAILABLE_DATA"),
-                          QObject::tr("BUT_OK") );
+                           QObject::tr("WRN_VISU"),
+                           QObject::tr("WRN_NO_AVAILABLE_DATA"),
+                           QObject::tr("BUT_OK") );
     return false;
   }
 
   VISU::Result_i*
   CheckResult(const SalomeApp_Module* theModule,
-             _PTR(SObject)           theSource,
-             VISU::Result_var&       theResult)
+              _PTR(SObject)           theSource,
+              VISU::Result_var&       theResult)
   {
     _PTR(SObject) aSObj = theSource->GetFather();
     if (!aSObj)
@@ -528,9 +559,9 @@ namespace VISU
     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
     if (pResult == NULL)
       SUIT_MessageBox::warn1(GetDesktop(theModule),
-                            QObject::tr("WRN_VISU"),
-                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
-                            QObject::tr("BUT_OK"));
+                             QObject::tr("WRN_VISU"),
+                             QObject::tr("WRN_NO_AVAILABLE_DATA"),
+                             QObject::tr("BUT_OK"));
     return pResult;
   }
 
@@ -541,11 +572,11 @@ namespace VISU
   {
     if(SalomeApp_Application* anApp = theModule->getApp()){
       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
-       if (!theType.isNull()) {
-         if (aViewManager->getType() != theType)
-           return 0;
-       }
-       return aViewManager->getActiveView();
+        if (!theType.isNull()) {
+          if (aViewManager->getType() != theType)
+            return 0;
+        }
+        return aViewManager->getActiveView();
       }
     }
     return 0;
@@ -563,13 +594,13 @@ namespace VISU
       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
       while(SUIT_ViewManager* aViewManager = anIter.current()){
-       QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
-       for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-         if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-           if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-             aViewWindows.push_back(aView);
-       }
-       ++anIter;
+        QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+        for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+          if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
+            if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
+              aViewWindows.push_back(aView);
+        }
+        ++anIter;
       }
     }
     return aViewWindows;
@@ -580,9 +611,9 @@ namespace VISU
   {
     if(SalomeApp_Application* anApp = theModule->getApp()){
       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
-       if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
-         return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
-       }
+        if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
+          return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
+        }
       }
     }
     return NULL;
@@ -596,11 +627,11 @@ namespace VISU
       (SUIT_Session::session()->activeApplication());
     if (anApp) {
       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
-       if (aViewManager->getType() == SVTK_Viewer::Type()) {
-         if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
-           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
-         }
-       }
+        if (aViewManager->getType() == SVTK_Viewer::Type()) {
+          if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
+            return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
+          }
+        }
       }
     }
     return NULL;
@@ -608,15 +639,21 @@ namespace VISU
 
   VISU_Actor*
   PublishInView(const SalomeApp_Module* theModule,
-               VISU::Prs3d_i* thePrs)
+                VISU::Prs3d_i* thePrs)
   {
     VISU_Actor* aActor = NULL;
     if(!thePrs)
       return aActor;
     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
       QApplication::setOverrideCursor( Qt::waitCursor );
-      if(aActor = thePrs->CreateActor()){
-       aView->AddActor(aActor);
+      try{
+       if(aActor = thePrs->CreateActor())
+         aView->AddActor(aActor);
+      }catch(std::exception& exc){
+       SUIT_MessageBox::warn1(GetDesktop(theModule),
+                              QObject::tr("WRN_VISU"),
+                              QObject::tr("ERR_CANT_CREATE_ACTOR"),
+                              QObject::tr("BUT_OK"));
       }
       QApplication::restoreOverrideCursor();
     }
@@ -625,8 +662,8 @@ namespace VISU
 
   VISU_Actor*
   UpdateViewer(const SalomeApp_Module* theModule,
-              VISU::Prs3d_i* thePrs,
-              bool theDispOnly)
+               VISU::Prs3d_i* thePrs,
+               bool theDispOnly)
   {
     SVTK_ViewWindow* vw = GetViewWindow( theModule );
     if (!vw) return NULL;
@@ -639,22 +676,22 @@ namespace VISU
     VISU_Actor* aResActor = NULL;
     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
       if(!SALOME_Actor::SafeDownCast(anActor))
-       continue;
+        continue;
       if(anActor->IsA("VISU_Actor")){
-       anVISUActor = VISU_Actor::SafeDownCast(anActor);
-       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->GetParent()->VisibilityOff();
-       } else {
-       }
+        anVISUActor = VISU_Actor::SafeDownCast(anActor);
+        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->GetParent()->VisibilityOff();
+        } else {
+        }
       } else if (theDispOnly && anActor->GetVisibility()) {
-       anActor->VisibilityOff();
+        anActor->VisibilityOff();
       } else {
       }
     }
@@ -675,33 +712,33 @@ namespace VISU
       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
       QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
       while (SUIT_ViewManager* aViewManager = anIter.current()) {
-       QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
-       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
-         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
-           if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
+        QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+        for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
+          if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
+            if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
               if (vw->isVisible(theIObject)) {
                 vw->getRenderer()->ResetCameraClippingRange();
                 vw->Repaint();
                 vw->highlight(theIObject, true, true);
               }
-           }
-         }
-       }
-       ++anIter;
+            }
+          }
+        }
+        ++anIter;
       }
     }
   }
 
   VISU_Actor*
   FindActor(SVTK_ViewWindow* theViewWindow,
-           const char* theEntry)
+            const char* theEntry)
   {
     using namespace VTK;
     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
-       if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
-         return anActor->GetParent();
-       }
+        if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
+          return anActor->GetParent();
+        }
       }
     }
     return NULL;
@@ -709,7 +746,7 @@ namespace VISU
 
   VISU_Actor*
   FindActor(SVTK_ViewWindow* theViewWindow,
-           VISU::Prs3d_i* thePrs)
+            VISU::Prs3d_i* thePrs)
   {
     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
     CORBA::String_var anEntry = aSObject->GetID();
@@ -732,7 +769,7 @@ namespace VISU
       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
         SVTK_ViewWindow* aView = aViewWindows[i];
         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
-         thePrs->UpdateActor(anActor);
+          thePrs->UpdateActor(anActor);
         }
       }
     } catch (std::runtime_error& ex) {
@@ -746,8 +783,8 @@ namespace VISU
       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
         SVTK_ViewWindow* aView = aViewWindows[i];
         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
-         aView->RemoveActor(anActor);
-         anActor->Delete();
+          aView->RemoveActor(anActor);
+          anActor->Delete();
         }
       }
       return;
@@ -763,7 +800,7 @@ namespace VISU
   {
     if(SalomeApp_Application* anApp = theModule->getApp()){
       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
-       return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
+        return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
       }
     }
     return NULL;
@@ -772,57 +809,57 @@ namespace VISU
   // Internal function used by several public functions below
   void
   UpdateCurve(VISU::Curve_i* theCurve,
-             Plot2d_ViewFrame* aPlot,
-             SPlot2d_Curve* plotCurve,
-             int theDisplaying)
+              Plot2d_ViewFrame* aPlot,
+              SPlot2d_Curve* plotCurve,
+              int theDisplaying)
   {
     if ( theDisplaying == VISU::eErase ) {
       if ( plotCurve )
-       aPlot->eraseCurve( plotCurve, false );
+        aPlot->eraseCurve( plotCurve, false );
     }
     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
       if ( plotCurve ) {
-       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() );
-       aPlot->displayCurve( plotCurve, false );
+        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() );
+        aPlot->displayCurve( plotCurve, false );
       }
       else {
-       Plot2d_Curve* crv = theCurve->CreatePresentation();
-       if ( crv ) {
-         aPlot->displayCurve( crv, false );
-         theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
-         theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
-         SALOMEDS::Color newColor;
-         newColor.R = crv->getColor().red()/255.;
-         newColor.G = crv->getColor().green()/255.;
-         newColor.B = crv->getColor().blue()/255.;
-         theCurve->SetColor( newColor );
-         crv->setAutoAssign( theCurve->IsAuto() );
-       }
+        Plot2d_Curve* crv = theCurve->CreatePresentation();
+        if ( crv ) {
+          aPlot->displayCurve( crv, false );
+          theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
+          theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
+          SALOMEDS::Color newColor;
+          newColor.R = crv->getColor().red()/255.;
+          newColor.G = crv->getColor().green()/255.;
+          newColor.B = crv->getColor().blue()/255.;
+          theCurve->SetColor( newColor );
+          crv->setAutoAssign( theCurve->IsAuto() );
+        }
       }
     }
   }
 
   void
   PlotTable(const SalomeApp_Module* theModule,
-           VISU::Table_i* table,
-           int theDisplaying)
+            VISU::Table_i* table,
+            int theDisplaying)
   {
     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
     if ( !aView )
@@ -840,29 +877,29 @@ namespace VISU
     if ( TableSO ) {
       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
       for ( ; Iter->More(); Iter->Next() ) {
-       CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
-       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).in());
-           SPlot2d_Curve* plotCurve = 0;
-           SPlot2d_Curve* tmpCurve;
-           for ( int i = 0; i < clist.count(); i++ ) {
-             tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
-             if (tmpCurve && tmpCurve->hasIO() &&
+        CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
+        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).in());
+            SPlot2d_Curve* plotCurve = 0;
+            SPlot2d_Curve* tmpCurve;
+            for ( int i = 0; i < clist.count(); i++ ) {
+              tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
+              if (tmpCurve && tmpCurve->hasIO() &&
                   !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
-               plotCurve = tmpCurve;
-               break;
-             }
-           }
-
-           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
-
-           if ( theDisplaying == VISU::eErase && plotCurve ) {
-             clist.remove( plotCurve );
-           }
-         }
-       }
+                plotCurve = tmpCurve;
+                break;
+              }
+            }
+
+            UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
+
+            if ( theDisplaying == VISU::eErase && plotCurve ) {
+              clist.remove( plotCurve );
+            }
+          }
+        }
       }
       aPlot->Repaint();
     }
@@ -870,8 +907,8 @@ namespace VISU
 
   void
   PlotCurve(const SalomeApp_Module* theModule,
-           VISU::Curve_i* theCurve,
-           int theDisplaying)
+            VISU::Curve_i* theCurve,
+            int theDisplaying)
   {
     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
     if ( !aView )
@@ -890,9 +927,9 @@ namespace VISU
       tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
       if (tmpCurve && tmpCurve->hasIO() &&
           !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
-       plotCurve = tmpCurve;
+        plotCurve = tmpCurve;
       } else if (theDisplaying == VISU::eDisplayOnly) {
-       aPlot->eraseCurve(clist.at(i));
+        aPlot->eraseCurve(clist.at(i));
       }
     }
 
@@ -903,8 +940,8 @@ namespace VISU
 
   void
   PlotContainer(const SalomeApp_Module* theModule,
-               VISU::Container_i* container,
-               int theDisplaying)
+                VISU::Container_i* container,
+                int theDisplaying)
   {
     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
     if ( !aView )
@@ -920,17 +957,17 @@ namespace VISU
     if ( container->GetNbCurves() > 0 ) {
       int nbCurves = container->GetNbCurves();
       for ( int k = 1; k <= nbCurves; k++ ) {
-       VISU::Curve_i* theCurve = container->GetCurve( k );
-       if ( theCurve && theCurve->IsValid() ) {
-         SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
+        VISU::Curve_i* theCurve = container->GetCurve( k );
+        if ( theCurve && theCurve->IsValid() ) {
+          SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
             (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
 
-         UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
+          UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
 
-         if ( plotCurve && theDisplaying == VISU::eErase ) {
-           clist.remove( plotCurve );
-         }
-       }
+          if ( plotCurve && theDisplaying == VISU::eErase ) {
+            clist.remove( plotCurve );
+          }
+        }
       }
     }
     aPlot->Repaint();
@@ -938,28 +975,27 @@ namespace VISU
 
   void
   CreatePlot(SalomeApp_Module* theModule,
-            _PTR(SObject) theTableSO)
+             _PTR(SObject) theTableSO)
   {
     if ( IsSObjectTable(theTableSO) ) {
       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
       CORBA::Object_var aContainer = GetVisuGen( theModule )->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( theModule )->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() );
-             }
-           }
-         }
-         theModule->updateObjBrowser();
-         PlotContainer( theModule, pContainer, VISU::eDisplay );
-       }
+        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( theModule )->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() );
+              }
+            }
+          }
+          PlotContainer( theModule, pContainer, VISU::eDisplay );
+        }
       }
     }
   }
@@ -1041,6 +1077,8 @@ namespace VISU
         timer.Show();
 #endif
         theModule->application()->putInfo(QObject::tr("INF_DONE"));
+        // Make "Save" button active
+        theModule->getApp()->updateActions();
       } catch (std::runtime_error& exc) {
         INFOS(exc.what());
         SUIT_MessageBox::warn1 (GetDesktop(theModule),