Salome HOME
All modules must use SVTK package instead VTK
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
index 47acac98449d23758e2155b75f72312b58343a62..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)
@@ -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
@@ -415,7 +441,6 @@ namespace VISU
       }
     }
     thePrs->RemoveFromStudy();
-    theModule->updateObjBrowser(); //update Object browser
   }
 
   void
@@ -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;
 
@@ -615,8 +646,14 @@ namespace VISU
       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();
     }
@@ -957,7 +994,6 @@ namespace VISU
               }
             }
           }
-          theModule->updateObjBrowser();
           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),