Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
index d18611d1b45e74a678cc538770fb4a76f94c4f61..83eab7448da805b5fd5b2f614c54af15ac54f798 100644 (file)
@@ -41,7 +41,7 @@
 #include "SalomeApp_Module.h"
 #include "SalomeApp_Study.h"
 #include "SalomeApp_Application.h"
-#include "SalomeApp_SelectionMgr.h"
+#include "LightApp_SelectionMgr.h"
 
 #include "SALOME_ListIO.hxx"
 #include "SALOME_ListIteratorOfListIO.hxx"
@@ -71,7 +71,7 @@ namespace VISU
     return theModule->application()->desktop();
   }
 
-  SalomeApp_SelectionMgr*
+  LightApp_SelectionMgr*
   GetSelectionMgr(const SalomeApp_Module* theModule)
   {
     return theModule->getApp()->selectionMgr();
@@ -102,7 +102,18 @@ namespace VISU
   CheckLock( _PTR(Study) theStudy )
   {
     if(IsStudyLocked(theStudy))
-      throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
+      {
+       SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
+         (SUIT_Session::session()->activeApplication());
+       if (anApp)
+         {
+           SUIT_MessageBox::warn1(anApp->desktop(),
+                                   QObject::tr("WRN_VISU_WARNING"),
+                                   QObject::tr("WRN_STUDY_LOCKED"),
+                                   QObject::tr("BUT_OK"));
+           return true;
+         }
+      }
     return false;
   }
 
@@ -193,7 +204,7 @@ namespace VISU
                 Handle(SALOME_InteractiveObject)* theIO,
                 VISU::Storable::TRestoringMap* theMap)
   {
-    SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
+    LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
     SALOME_ListIO aListIO;
     aSelectionMgr->selectedObjects(aListIO);
     SALOME_ListIteratorOfListIO anIter(aListIO);
@@ -227,7 +238,7 @@ namespace VISU
   }
 
   void
-  Add(SalomeApp_SelectionMgr* theSelectionMgr,
+  Add(LightApp_SelectionMgr* theSelectionMgr,
       const Handle(SALOME_InteractiveObject)& theIO)
   {
     SALOME_ListIO aListIO;
@@ -237,7 +248,7 @@ namespace VISU
   }
 
   void
-  Remove(SalomeApp_SelectionMgr* theSelectionMgr,
+  Remove(LightApp_SelectionMgr* theSelectionMgr,
         const Handle(SALOME_InteractiveObject)& theIO)
   {
     if (theIO.IsNull()) return;
@@ -262,7 +273,7 @@ namespace VISU
   bool
   IsRemovableSelected (const SalomeApp_Module* theModule)
   {
-    SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
+    LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
     SALOME_ListIO aListIO;
     aSelectionMgr->selectedObjects(aListIO);
 
@@ -399,9 +410,6 @@ namespace VISU
       _PTR(SObject) aChildSObject = aChildIter->Value();
       
       CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
-      VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
-      if( !CORBA::is_nil( aRemovableObject ) ) 
-       study->deleteReferencesTo( aChildSObject );
       ErasePrs(theModule, aChildObj);
     }
 
@@ -411,7 +419,6 @@ namespace VISU
 
       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
       if (!CORBA::is_nil(aRemovableObject)) {
-       study->deleteReferencesTo( theSObject );
         aRemovableObject->RemoveFromStudy();
       }
     } else {
@@ -434,7 +441,7 @@ namespace VISU
       return;
     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
     CORBA::String_var anEntry = aSObject->GetID();
-    SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
+    LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
     Remove(aSelectionMgr,theIO);
     TViewWindows aViewWindows = GetViews(theModule);
     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
@@ -641,6 +648,23 @@ namespace VISU
   }
 
   SVTK_ViewWindow*
+  GetViewWindow( const SalomeApp_Module* theModule, const bool theCreate )
+  {
+    if (SalomeApp_Application* anApp = theModule->getApp())
+    {
+      SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
+      if( wnd )
+       return wnd;
+      else
+      {
+       SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate );
+       return aViewManager ? dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() ) : 0;
+      }
+    }
+    return NULL;
+  }
+
+  /*SVTK_ViewWindow*
   GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
   {
     if(SalomeApp_Application* anApp = theModule->getApp()){
@@ -651,7 +675,7 @@ namespace VISU
       }
     }
     return NULL;
-  }
+  }*/
 
 
   SVTK_ViewWindow*
@@ -943,7 +967,7 @@ namespace VISU
               int theDisplaying)
   {
     if ( theDisplaying == VISU::eErase ) {
-      if ( plotCurve )
+      if ( plotCurve && aPlot )
         aPlot->eraseCurve( plotCurve, false );
     }
     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
@@ -966,12 +990,14 @@ namespace VISU
           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
         }
         plotCurve->setAutoAssign( theCurve->IsAuto() );
-        aPlot->displayCurve( plotCurve, false );
+       if( aPlot )
+         aPlot->displayCurve( plotCurve, false );
       }
       else {
         Plot2d_Curve* crv = theCurve->CreatePresentation();
         if ( crv ) {
-          aPlot->displayCurve( crv, false );
+         if( aPlot )
+           aPlot->displayCurve( crv, false );
           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
           SALOMEDS::Color newColor;