Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VISU_I / VISU_ViewManager_i.cc
index c86ac5d8cd41b7aa83fbb1c2ed9cf0794ddebd8d..1878c1074255f505b36e00bf1f6496ed1c869035 100644 (file)
@@ -1,6 +1,6 @@
-//  VISU OBJECT : interactive object for VISU entities implementation
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  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 OBJECT : interactive object for VISU entities implementation
 //  File   : VISU_ViewManager_i.cc
 //  Author : Alexey PETROV
 //  Module : VISU
-
+//
 #include "VISU_ViewManager_i.hh"
 #include "VISU_View_i.hh"
 #include "VISU_Prs3d_i.hh"
 #include "VISU_Table_i.hh"
 
 #include "VISU_Actor.h"
+#include "VISU_ActorFactory.h"
 
 #include "SUIT_Tools.h"
 #include "SUIT_Session.h"
 #include "SalomeApp_Application.h"
 #include "LightApp_SelectionMgr.h"
 
-#include "SALOME_Event.hxx"
+#include "SALOME_Event.h"
 #include "SALOME_ListIO.hxx"
 #include "SALOME_ListIteratorOfListIO.hxx"
 
+#include "VTKViewer_Algorithm.h"
+#include "SVTK_Functor.h"
+
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
 #include <vtkRenderWindow.h>
 
-#include <qapplication.h>
+#include <QApplication>
 
 using namespace std;
 
 #ifdef _DEBUG_
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
 #else
 static int MYDEBUG = 0;
 #endif
@@ -84,10 +88,10 @@ namespace VISU {
     {
       MESSAGE("Find application for study with id = : " << myStudyId);
       SUIT_Session* aSession = SUIT_Session::session();
-      QPtrList<SUIT_Application> anApplications = aSession->applications();
-      QPtrListIterator<SUIT_Application> anIter (anApplications);
-      while (SUIT_Application* anApp = anIter.current()) {
-       ++anIter;
+      QList<SUIT_Application*> anApplications = aSession->applications();
+      QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
+      while ( anIter != anApplications.end() ) {
+       SUIT_Application* anApp = *anIter;
        if (SUIT_Study* aSStudy = anApp->activeStudy()) {
          if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
@@ -99,6 +103,7 @@ namespace VISU {
            }
          }
        }
+       anIter++;
       }
       if (!myResult) {
         //MESSAGE("Error: application is not found for study : " << myStudyName);
@@ -257,31 +262,29 @@ namespace VISU {
   //===========================================================================
   // VISU namespace functions
   //===========================================================================
-  SVTK_ViewWindow* GetViewWindow (SUIT_ViewWindow* theStudyFrame)
+  vtkRenderer* GetRenderer (SUIT_ViewWindow* theViewWindow)
   {
-    return dynamic_cast<SVTK_ViewWindow*>(theStudyFrame);
-  }
-
-  vtkRenderer* GetRenderer (SUIT_ViewWindow* theStudyFrame)
-  {
-    return GetViewWindow(theStudyFrame)->getRenderer();
+    if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(theViewWindow))
+      return vw->getRenderer();
+    return NULL;
   }
 
-  vtkCamera* GetCamera (SUIT_ViewWindow* theStudyFrame)
+  vtkCamera* GetCamera (SUIT_ViewWindow* theViewWindow)
   {
-    return GetRenderer(theStudyFrame)->GetActiveCamera();
+    return GetRenderer(theViewWindow)->GetActiveCamera();
   }
 
   void RepaintView (SUIT_ViewWindow* theViewWindow)
   {
-    SVTK_ViewWindow* vf = GetViewWindow(theViewWindow);
-    vf->getRenderer()->ResetCameraClippingRange();
-    vf->getRenderWindow()->Render();
+    if (SVTK_ViewWindow* vf = dynamic_cast<SVTK_ViewWindow*>(theViewWindow)) {
+      vf->getRenderer()->ResetCameraClippingRange();
+      vf->getRenderWindow()->Render();
+    }
   }
 
-  VISU_Actor* UpdateViewer (SUIT_ViewWindow* theStudyFrame, int theDisplaing, Prs3d_i* thePrs)
+  VISU_Actor* UpdateViewer (SUIT_ViewWindow* theViewWindow, int theDisplaing, Prs3d_i* thePrs)
   {
-    SVTK_ViewWindow* vf = GetViewWindow(theStudyFrame);
+    SVTK_ViewWindow* vf = dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
     if (!vf) return NULL;
     if(MYDEBUG) MESSAGE("UpdateViewer - theDisplaing = "<<theDisplaing<<"; thePrs = "<<thePrs);
     vtkRenderer *aRen = vf->getRenderer();
@@ -306,7 +309,7 @@ namespace VISU {
       }
     }
     if (aResActor) {
-      RepaintView(theStudyFrame);
+      RepaintView(theViewWindow);
       return aResActor;
     }
     if(thePrs != NULL && theDisplaing < eErase){
@@ -321,7 +324,7 @@ namespace VISU {
        return NULL;
       }
     }
-    RepaintView(theStudyFrame);
+    RepaintView(theViewWindow);
     return anVISUActor;
   }
 
@@ -330,7 +333,7 @@ namespace VISU {
     if(MYDEBUG) MESSAGE("UpdatePlot2d - theDisplaying = " << theDisplaying);
     if (!theView)
       return;
-    QList<Plot2d_Curve> clist;
+    QList<Plot2d_Curve*> clist;
     theView->getCurves(clist);
     if (theDisplaying == eEraseAll) {
       for (int i = 0; i < clist.count(); i++) {
@@ -342,7 +345,7 @@ namespace VISU {
        for (int i = 0; i < clist.count(); i++) {
          SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
          if (aSPlot2dC->hasIO() &&
-             !strcmp(aSPlot2dC->getIO()->getEntry(), theCurve->GetEntry())) {
+             !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
            if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing : curve - " << aSPlot2dC);
            theView->eraseCurve(aSPlot2dC);
          }
@@ -354,7 +357,7 @@ namespace VISU {
        for (int i = 0; i < clist.count(); i++) {
          SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
          if (aSPlot2dC->hasIO() &&
-             !strcmp(aSPlot2dC->getIO()->getEntry(), theCurve->GetEntry())) {
+             !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
            if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - " << aSPlot2dC);
            aSPlot2dC->setHorTitle( theCurve->GetHorTitle().c_str() );
            aSPlot2dC->setVerTitle( theCurve->GetVerTitle().c_str() );
@@ -362,14 +365,15 @@ namespace VISU {
            aSPlot2dC->setVerUnits( theCurve->GetVerUnits().c_str() );
            double* xList = 0;
            double* yList = 0;
-           int     nbPoints = theCurve->GetData( xList, yList );
+           QStringList zList;
+           int     nbPoints = theCurve->GetData( xList, yList, zList );
            if (nbPoints > 0 && xList && yList) {
-             aSPlot2dC->setData( xList, yList, nbPoints );
+             aSPlot2dC->setData( xList, yList, nbPoints, zList );
            }
            if (!theCurve->IsAuto()) {
-             aSPlot2dC->setLine((Plot2d_Curve::LineType)theCurve->GetLine(),
+             aSPlot2dC->setLine((Plot2d::LineType)theCurve->GetLine(),
                                 theCurve->GetLineWidth());
-             aSPlot2dC->setMarker((Plot2d_Curve::MarkerType)theCurve->GetMarker());
+             aSPlot2dC->setMarker((Plot2d::MarkerType)theCurve->GetMarker());
              SALOMEDS::Color color = theCurve->GetColor();
              aSPlot2dC->setColor(QColor((int)(color.R*255.),
                                         (int)(color.G*255.),
@@ -402,7 +406,7 @@ namespace VISU {
        for (int i = 0; i < clist.count(); i++) {
          SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
          if (aSPlot2dC->hasIO() &&
-             !strcmp(aSPlot2dC->getIO()->getEntry(), theCurve->GetEntry())) {
+             !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
            if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying only : curve - " << aSPlot2dC);
            aSPlot2dC->setHorTitle( theCurve->GetHorTitle().c_str() );
            aSPlot2dC->setVerTitle( theCurve->GetVerTitle().c_str() );
@@ -410,13 +414,14 @@ namespace VISU {
            aSPlot2dC->setVerUnits( theCurve->GetVerUnits().c_str() );
            double* xList = 0;
            double* yList = 0;
-           int     nbPoints = theCurve->GetData( xList, yList );
+           QStringList zList;
+           int     nbPoints = theCurve->GetData( xList, yList, zList );
            if ( nbPoints > 0 && xList && yList ) {
-             aSPlot2dC->setData( xList, yList, nbPoints );
+             aSPlot2dC->setData( xList, yList, nbPoints, zList );
            }
            if ( !theCurve->IsAuto() ) {
-             aSPlot2dC->setLine((Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth());
-             aSPlot2dC->setMarker((Plot2d_Curve::MarkerType)theCurve->GetMarker());
+             aSPlot2dC->setLine((Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth());
+             aSPlot2dC->setMarker((Plot2d::MarkerType)theCurve->GetMarker());
              SALOMEDS::Color color = theCurve->GetColor();
              aSPlot2dC->setColor(QColor((int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.)));
            }
@@ -446,17 +451,67 @@ namespace VISU {
     }
   }
 
-  VISU_Actor* GetActor (VISU::Prs3d_i* thePrs3d, SVTK_ViewWindow* theVTKFrame)
+
+  //----------------------------------------------------------------------------
+  struct TIsSamePrs3d
   {
-    vtkActorCollection *anActColl = theVTKFrame->getRenderer()->GetActors();
-    anActColl->InitTraversal();
-    while (vtkActor *anActor = anActColl->GetNextActor())
-      if (VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor))
-       if (thePrs3d == anVISUActor->GetPrs3d())
-         return anVISUActor;
-    return NULL;
+    VISU::Prs3d_i* myPrs3d;
+
+    TIsSamePrs3d(VISU::Prs3d_i* thePrs3d):
+      myPrs3d(thePrs3d)
+    {}
+    
+    bool
+    operator()(VISU_Actor* theActor) 
+    {
+      return theActor->GetPrs3d() == myPrs3d;
+    }
+  };
+
+
+  //----------------------------------------------------------------------------
+  VISU_Actor* 
+  FindActor(SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d)
+  {
+    if(!thePrs3d)
+      return NULL;
+
+    vtkRenderer* aRenderer = theViewWindow->getRenderer();
+    vtkActorCollection* anActors = aRenderer->GetActors();
+    return SVTK::Find<VISU_Actor>(anActors, VISU::TIsSamePrs3d(thePrs3d));
+  }
+
+
+  //----------------------------------------------------------------------------
+  struct TIsSameActor
+  {
+    VISU::TActorFactory* myActor;
+
+    TIsSameActor(VISU::TActorFactory* theActor):
+      myActor(theActor)
+    {}
+    
+    bool
+    operator()(VISU_ActorBase* theActor) 
+    {
+      return theActor->GetFactory() == myActor;
+    }
+  };
+
+  //----------------------------------------------------------------------------
+  VISU_ActorBase* 
+  FindActorBase(SVTK_ViewWindow* theViewWindow, VISU::TActorFactory* theActor)
+  {
+    if(!theActor)
+      return NULL;
+
+    vtkRenderer* aRenderer = theViewWindow->getRenderer();
+    vtkActorCollection* anActors = aRenderer->GetActors();
+    return SVTK::Find<VISU_ActorBase>(anActors, VISU::TIsSameActor(theActor));
   }
 
+
+  //----------------------------------------------------------------------------
   struct TDeleteActorsEvent: public SALOME_Event
   {
     VISU::Curve_i* myPrs;
@@ -477,10 +532,10 @@ namespace VISU {
       CORBA::String_var studyName = myStudyDocument->Name();
       std::string aStudyName = studyName.in();
       SUIT_Session* aSession = SUIT_Session::session();
-      QPtrList<SUIT_Application> anApplications = aSession->applications();
-      QPtrListIterator<SUIT_Application> anIter (anApplications);
-      while (SUIT_Application* aSUITApp = anIter.current()) {
-        ++anIter;
+      QList<SUIT_Application*> anApplications = aSession->applications();
+      QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
+      while ( anIter != anApplications.end() ) {
+       SUIT_Application* aSUITApp = *anIter;
        if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
@@ -491,6 +546,7 @@ namespace VISU {
            }
          }
         }
+       anIter++;
       }
       if (!anApp)
         return;
@@ -517,20 +573,20 @@ namespace VISU {
       // 3. Remove Actors
       ViewManagerList aViewManagerList;
       anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
-      QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
-      for (; anVMIter.current(); ++anVMIter) {
-        SUIT_ViewManager* aViewManager = anVMIter.current();
-       QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+      QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
+      for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
+        SUIT_ViewManager* aViewManager = *anVMIter;
+       QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
        for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
          if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
            if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
               Plot2d_ViewFrame* vf = vw->getViewFrame();
-             QList<Plot2d_Curve> clist;
+             QList<Plot2d_Curve*> clist;
              vf->getCurves(clist);
              for (int i = 0; i < clist.count(); i++) {
                 if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
                  if (cu->hasIO() &&
-                     strcmp(cu->getIO()->getEntry(), myPrs->GetEntry()) == 0) {
+                     strcmp(myPrs->GetEntry().c_str(), cu->getIO()->getEntry())) {
                    vf->eraseCurve(cu);
                  }
                }
@@ -631,10 +687,10 @@ namespace VISU {
     CORBA::String_var studyName = myStudyDocument->Name();
     std::string aStudyName = studyName.in();
     SUIT_Session* aSession = SUIT_Session::session();
-    QPtrList<SUIT_Application> anApplications = aSession->applications();
-    QPtrListIterator<SUIT_Application> anIter (anApplications);
-    while (SUIT_Application* aSUITApp = anIter.current()) {
-      ++anIter;
+    QList<SUIT_Application*> anApplications = aSession->applications();
+    QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
+    while (anIter != anApplications.end()) {
+      SUIT_Application* aSUITApp = *anIter;
       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
@@ -645,6 +701,7 @@ namespace VISU {
          }
        }
       }
+      anIter++;
     }
     if (!anApp)
       return;
@@ -671,10 +728,10 @@ namespace VISU {
     // 3. Remove Actors
     ViewManagerList aViewManagerList;
     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
-    QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
-    for (; anVMIter.current(); ++anVMIter) {
-      SUIT_ViewManager* aViewManager = anVMIter.current();
-      QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+    QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
+    for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
+      SUIT_ViewManager* aViewManager = *anVMIter;
+      QVector<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)) {