Salome HOME
IPAL22292 (Gauss Points doesn't appear in Clipping Planes after reload file): GaussPo...
[modules/visu.git] / src / VISUGUI / VisuGUI_ViewTools.cxx
index 601e2a17589da21bfdd6437c8c793df019ffe338..7e455698a1b4fc65bc60da56170ee2b1a6ed1e2d 100644 (file)
@@ -1,6 +1,6 @@
-//  VISU VISUGUI : GUI of VISU component
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  VISU VISUGUI : GUI of VISU component
 //  File   : VisuGUI_Tools.cxx
 //  Author : Sergey Anikin
 //  Module : VISU
-
-
+//
 #include "VisuGUI_ViewTools.h"
 
 #include "VISU_Actor.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
 
+#include <SUIT_Desktop.h>
+
 namespace VISU 
 {
+  //----------------------------------------------------------------------------
+  VISU_Actor*
+  PublishInView(VisuGUI* theModule,
+                Prs3d_i* thePrs,
+                SVTK_ViewWindow* theViewWindow,
+                bool theIsHighlight)
+  {
+    if (theViewWindow) {
+      QApplication::setOverrideCursor( Qt::WaitCursor );
+      try {
+        if (VISU_Actor* anActor = thePrs->CreateActor()) {
+          theViewWindow->AddActor(anActor);
+          if (theIsHighlight)
+            theViewWindow->highlight(anActor->getIO(),true);
+          theViewWindow->getRenderer()->ResetCameraClippingRange();
+          theViewWindow->Repaint();
+          QApplication::restoreOverrideCursor();
+          return anActor;
+        }
+      } catch(std::exception& exc) {
+        thePrs->RemoveActors();
+
+        QApplication::restoreOverrideCursor();
+        INFOS(exc.what());
+        SUIT_MessageBox::warning
+          (GetDesktop(theModule), QObject::tr("WRN_VISU"),
+           QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()));
+      }
+    }
+    return NULL;
+  }
+
+
+  //---------------------------------------------------------------
+  VISU_Actor*
+  UpdateViewer(VisuGUI* theModule,
+               VISU::Prs3d_i* thePrs,
+               bool theDispOnly,
+               const bool theIsHighlight)
+  {
+    if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
+      vtkRenderer *aRen = aViewWindow->getRenderer();
+      VTK::ActorCollectionCopy aCopy(aRen->GetActors());
+      vtkActorCollection *anActColl = aCopy.GetActors();
+      anActColl->InitTraversal();
+      VISU_Actor* aResActor = NULL;
+      bool isOk = true;
+      while (vtkActor *anAct = anActColl->GetNextActor()) {
+        if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
+          if (VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()) {
+            if (thePrs == aPrs3d) {
+              try {
+                aResActor = anActor;
+                thePrs->UpdateActors();
+                aResActor->VisibilityOn();
+              } catch (std::runtime_error& exc) {
+                thePrs->RemoveActors();
+                isOk = false;
+
+                INFOS(exc.what());
+                SUIT_MessageBox::warning
+                  (GetDesktop(theModule), QObject::tr("WRN_VISU"),
+                   QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
+              }
+            } else if (theDispOnly) {
+              anActor->VisibilityOff();
+            }
+          } else if (theDispOnly && anActor->GetVisibility()) {
+            anActor->VisibilityOff();
+          }
+        }
+      }
+      if (aResActor) {
+        if (theIsHighlight && isOk)
+          aViewWindow->highlight(aResActor->getIO(), true);
+        aViewWindow->getRenderer()->ResetCameraClippingRange();
+        aViewWindow->Repaint();
+        return aResActor;
+      }
+      return PublishInView(theModule, thePrs, aViewWindow, theIsHighlight);
+    }
+    return NULL;
+  }
+
+
+  //---------------------------------------------------------------
+  void
+  ErasePrs3d(VisuGUI* theModule,
+             VISU::Prs3d_i* thePrs,
+             bool theDoRepaint)
+  {
+    if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
+      if(VISU_Actor* anActor = FindActor(aViewWindow, thePrs)){
+        anActor->VisibilityOff();
+        if(theDoRepaint)
+          aViewWindow->Repaint();
+      }
+    }
+  }
+
+  //----------------------------------------------------------------------------
   void
   ErasePrs(VisuGUI* theModule,
-          CORBA::Object_ptr theObject
-          bool theDoRepaintVW)
+           Base_i* theBase
+           bool theDoRepaint)
   {
-    if (CORBA::is_nil(theObject)) return;
-    VISU::Base_var aBase = VISU::Base::_narrow(theObject);
-    if (CORBA::is_nil(aBase)) return;
+    if(!theBase)
+      return;
 
-    VISU::VISUType aType = aBase->GetType();
-    switch (aType) {
+    switch (theBase->GetType()) {
     case VISU::TCURVE: {
-      if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
-       PlotCurve(theModule, aCurve, VISU::eErase );
+      if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(theBase))
+        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 );
+      if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(theBase))
+        PlotContainer(theModule, aContainer, VISU::eErase );
       break;
     }
     case VISU::TTABLE: {
-      if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
-       PlotTable(theModule, aTable, VISU::eErase );
+      if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase))
+        PlotTable(theModule, aTable, VISU::eErase );
+      break;
+    }
+    case VISU::TPOINTMAP3D: {
+      if (VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(theBase)) {
+        if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
+          if(VISU_ActorBase* anActor = FindActorBase(aViewWindow, aTable3d)){
+            anActor->VisibilityOff();
+            if(theDoRepaint)
+            aViewWindow->Repaint();
+          }
+        } else {
+          if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase))
+            PlotTable(theModule, aTable, VISU::eErase );
+        }
+      }
       break;
     }
     default: {
-      if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
-        SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
-       RemoveScalarBarPosition(theModule, vw, aPrsObject);
-        ErasePrs3d(theModule, aPrsObject, theDoRepaintVW);
+      if(VISU::Prs3d_i* aPrs3d = VISU::GetPrs3dFromBase(theBase)){
+        if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
+          RemoveScalarBarPosition(theModule, aViewWindow, aPrs3d);
+          ErasePrs3d(theModule, aPrs3d, theDoRepaint);
+        }
       }
     }} // switch (aType)
   }
+
 }