Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
index 208b8a1a81bd440b3756c6528645ecd581d4b2b9..83eab7448da805b5fd5b2f614c54af15ac54f798 100644 (file)
 #include "VISU_ViewManager_i.hh"
 
 #include "VISU_Actor.h"
+#include "VISU_ScalarMapAct.h"
 
 #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"
@@ -70,7 +71,7 @@ namespace VISU
     return theModule->application()->desktop();
   }
 
-  SalomeApp_SelectionMgr*
+  LightApp_SelectionMgr*
   GetSelectionMgr(const SalomeApp_Module* theModule)
   {
     return theModule->getApp()->selectionMgr();
@@ -101,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;
   }
 
@@ -192,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);
@@ -226,7 +238,7 @@ namespace VISU
   }
 
   void
-  Add(SalomeApp_SelectionMgr* theSelectionMgr,
+  Add(LightApp_SelectionMgr* theSelectionMgr,
       const Handle(SALOME_InteractiveObject)& theIO)
   {
     SALOME_ListIO aListIO;
@@ -236,7 +248,7 @@ namespace VISU
   }
 
   void
-  Remove(SalomeApp_SelectionMgr* theSelectionMgr,
+  Remove(LightApp_SelectionMgr* theSelectionMgr,
         const Handle(SALOME_InteractiveObject)& theIO)
   {
     if (theIO.IsNull()) return;
@@ -261,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);
 
@@ -392,12 +404,11 @@ namespace VISU
                  _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);
     }
@@ -430,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++){
@@ -500,6 +511,36 @@ namespace VISU
       }
     }
   }
+  
+  void
+  SetShading ( const SalomeApp_Module* theModule,
+             bool theOn )
+  {
+    SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
+    if (!aView) return;
+    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;
+
+    VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
+    if (aPrs3d) {
+      if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
+       if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
+         aScalarMapActor->SetShading( theOn );
+      }
+      vw->Repaint();
+    }
+  }
 
   //************************************************************
   // SObject type
@@ -607,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()){
@@ -617,7 +675,7 @@ namespace VISU
       }
     }
     return NULL;
-  }
+  }*/
 
 
   SVTK_ViewWindow*
@@ -683,9 +741,16 @@ namespace VISU
         if(aPrs == NULL) continue;
         if (thePrs == aPrs) {
           aResActor = anVISUActor->GetParent();
-          thePrs->UpdateActor(aResActor);
-          aResActor->VisibilityOn();
-
+          try {
+            thePrs->UpdateActor(aResActor);
+            aResActor->VisibilityOn();
+          } catch (std::runtime_error& ex) {
+            aResActor->VisibilityOff();
+            INFOS(ex.what());
+            SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"),
+                                   QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(ex.what()),
+                                   QObject::tr("BUT_OK"));
+          }
         } else if (theDispOnly) {
           anVISUActor->GetParent()->VisibilityOff();
         } else {
@@ -698,7 +763,7 @@ namespace VISU
     if (aResActor)
       return aResActor;
 
-    anVISUActor = PublishInView( theModule, thePrs );
+    //anVISUActor = PublishInView( theModule, thePrs );
     return anVISUActor;
   }
 
@@ -902,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 ) {
@@ -925,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;