]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_ViewManager_i.cc
Salome HOME
cf3594506005594805999603678206add7621c3b
[modules/visu.git] / src / VISU_I / VISU_ViewManager_i.cc
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_ViewManager_i.cc
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_ViewManager_i.hh"
29 #include "VISU_View_i.hh"
30 #include "VISU_Prs3d_i.hh"
31 #include "VISU_Table_i.hh"
32 #include "VISU_Tools.h"
33
34 #include "VISU_Actor.h"
35 #include "VISU_ActorFactory.h"
36
37 #include "SUIT_Tools.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_ViewWindow.h"
40 #include "SUIT_ViewManager.h"
41
42 #include "SVTK_ViewWindow.h"
43 #include "SVTK_ViewModel.h"
44 #include "VTKViewer_Algorithm.h"
45 #include "SPlot2d_Curve.h"
46 #include "SPlot2d_ViewModel.h"
47 #include "Plot2d_ViewFrame.h"
48 #include "Plot2d_ViewWindow.h"
49 #include "Plot2d_ViewModel.h"
50 #include "Plot2d_ViewManager.h"
51
52 #include "SalomeApp_Study.h"
53 #include "SalomeApp_Application.h"
54 #include "LightApp_SelectionMgr.h"
55
56 #include "SALOME_Event.h"
57 #include "SALOME_ListIO.hxx"
58 #include "SALOME_ListIteratorOfListIO.hxx"
59
60 #include "VTKViewer_Algorithm.h"
61 #include "SVTK_Functor.h"
62
63 #include <vtkCamera.h>
64 #include <vtkRenderer.h>
65 #include <vtkRenderWindow.h>
66
67 #include <QApplication>
68
69 using namespace std;
70
71 #ifdef _DEBUG_
72 static int MYDEBUG = 0;
73 #else
74 static int MYDEBUG = 0;
75 #endif
76
77 namespace VISU {
78
79   struct TNewViewManagerEvent: public SALOME_Event
80   {
81     int myStudyId;
82     typedef SalomeApp_Application* TResult;
83     TResult myResult;
84
85     TNewViewManagerEvent (const int theStudyId):
86       myStudyId(theStudyId),
87       myResult(NULL)
88     {}
89
90     virtual
91     void
92     Execute()
93     {
94       MESSAGE("Find application for study with id = : " << myStudyId);
95       SUIT_Session* aSession = SUIT_Session::session();
96       QList<SUIT_Application*> anApplications = aSession->applications();
97       QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
98       while ( anIter != anApplications.end() ) {
99         SUIT_Application* anApp = *anIter;
100         if (SUIT_Study* aSStudy = anApp->activeStudy()) {
101           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
102             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
103               //if (myStudyName == aCStudy->Name()) {
104               if (myStudyId == aCStudy->StudyId()) {
105                 myResult = dynamic_cast<SalomeApp_Application*>(anApp);
106                 break;
107               }
108             }
109           }
110         }
111         anIter++;
112       }
113       if (!myResult) {
114         //MESSAGE("Error: application is not found for study : " << myStudyName);
115         MESSAGE("Error: application is not found for study with id = : " << myStudyId);
116       }
117     }
118   };
119
120   //===========================================================================
121   ViewManager_i::ViewManager_i(SALOMEDS::Study_ptr theStudy)
122   {
123     if(MYDEBUG) MESSAGE("ViewManager_i::ViewManager_i - "<<this);
124
125     //CORBA::String_var aStudyName = theStudy->Name();
126     //myApplication = ProcessEvent(new TNewViewManagerEvent(aStudyName.in()));
127     int aStudyID = theStudy->StudyId();
128     myApplication = ProcessEvent(new TNewViewManagerEvent(aStudyID));
129   }
130
131
132   ViewManager_i::~ViewManager_i()
133   {
134     if(MYDEBUG) MESSAGE("ViewManager_i::~ViewManager_i - "<<this);
135   }
136
137
138   struct TCurrentViewEvent: public SALOME_Event
139   {
140     SalomeApp_Application* myApplication;
141     typedef VISU::View_ptr TResult;
142     TResult myResult;
143
144     TCurrentViewEvent(SalomeApp_Application* theApplication):
145       myApplication(theApplication),
146       myResult(VISU::View::_nil())
147     {}
148
149     virtual
150     void
151     Execute()
152     {
153       VISU::View3D_i* aView = new View3D_i (myApplication);
154       if (aView->Create(0))
155         myResult = aView->_this();
156     }
157   };
158
159   VISU::View_ptr ViewManager_i::GetCurrentView(){
160     return ProcessEvent(new TCurrentViewEvent(myApplication));
161   }
162
163
164   template<class TViewFrame>
165   struct TCreateViewFrameEvent: public SALOME_Event
166   {
167     SalomeApp_Application* myApplication;
168     typedef typename TViewFrame::TInterface TInterface;
169     typedef typename TInterface::_ptr_type TResult;
170     TResult myResult;
171
172     TCreateViewFrameEvent (SalomeApp_Application* theApplication):
173       myApplication(theApplication),
174       myResult(TInterface::_nil())
175     {}
176
177     virtual
178     void
179     Execute()
180     {
181       //if (CheckStudy(myStudyDocument)) {
182       if (myApplication) {
183         TViewFrame* pView = new TViewFrame (myApplication);
184         if (pView->Create(1)) {
185           myResult = pView->_this();
186           qApp->processEvents(); // Fix for bug 9929
187         }
188       }
189     }
190   };
191
192
193   VISU::View3D_ptr ViewManager_i::Create3DView()
194   {
195     if (MYDEBUG) MESSAGE("ViewManager_i::Create3DView");
196     return ProcessEvent(new TCreateViewFrameEvent<View3D_i>(myApplication));
197   }
198
199   VISU::XYPlot_ptr ViewManager_i::CreateXYPlot()
200   {
201     if (MYDEBUG) MESSAGE("ViewManager_i::CreateXYPlot");
202     return ProcessEvent(new TCreateViewFrameEvent<XYPlot_i>(myApplication));
203   }
204
205   class TCreateViewEvent: public SALOME_Event
206   {
207   public:
208     TCreateViewEvent (SalomeApp_Application* theApplication)
209       : myApplication(theApplication)
210     {}
211   protected:
212     SalomeApp_Application* myApplication;
213   };
214
215   class TCreateTableViewFrameEvent: public TCreateViewEvent
216   {
217     Table_ptr myTable;
218   public:
219     TCreateTableViewFrameEvent (SalomeApp_Application* theApplication,
220                                 Table_ptr theTable):
221       TCreateViewEvent(theApplication),
222       myTable(theTable),
223       myResult(VISU::TableView::_nil())
224     {}
225
226     virtual void Execute()
227     {
228       //if (CheckStudy(myStudyDocument)) {
229         VISU::TableView_i* pView = new TableView_i (myApplication);
230         if (pView->Create(myTable) != NULL)
231           myResult = pView->_this();
232       //}
233     }
234     typedef VISU::TableView_ptr TResult;
235     TResult myResult;
236   };
237
238   VISU::TableView_ptr ViewManager_i::CreateTableView (VISU::Table_ptr theTable)
239   {
240     if (MYDEBUG) MESSAGE("ViewManager_i::CreateTableView");
241     //return ProcessEvent(new TCreateViewFrameEvent<TableView_i>(myApplication));
242     return ProcessEvent(new TCreateTableViewFrameEvent (myApplication, theTable));
243   }
244
245   void ViewManager_i::Destroy (View_ptr theView)
246   {
247     class TEvent: public SALOME_Event {
248       View_ptr myView;
249     public:
250       TEvent(View_ptr theView):
251         myView(theView)
252       {}
253       virtual void Execute(){
254         if (!CORBA::is_nil(myView)) {
255           if (VISU::View_i* pView = dynamic_cast<VISU::View_i*>(VISU::GetServant(myView).in())) {
256             pView->Close();
257             pView->_remove_ref();
258           }
259         }
260       }
261     };
262
263     if (MYDEBUG) MESSAGE("ViewManager_i::Destroy - " << theView->_is_nil());
264     ProcessVoidEvent(new TEvent(theView));
265   }
266
267   //===========================================================================
268   // VISU namespace functions
269   //===========================================================================
270   vtkRenderer* GetRenderer (SUIT_ViewWindow* theViewWindow)
271   {
272     if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(theViewWindow))
273       return vw->getRenderer();
274     return NULL;
275   }
276
277   vtkCamera* GetCamera (SUIT_ViewWindow* theViewWindow)
278   {
279     return GetRenderer(theViewWindow)->GetActiveCamera();
280   }
281
282   void RepaintView (SUIT_ViewWindow* theViewWindow)
283   {
284     if (SVTK_ViewWindow* vf = dynamic_cast<SVTK_ViewWindow*>(theViewWindow)) {
285       vf->getRenderer()->ResetCameraClippingRange();
286       vf->getRenderWindow()->Render();
287     }
288   }
289
290   VISU_Actor* UpdateViewer (SUIT_ViewWindow* theViewWindow, int theDisplaing, Prs3d_i* thePrs)
291   {
292     SVTK_ViewWindow* vf = dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
293     if (!vf) return NULL;
294     if(MYDEBUG) MESSAGE("UpdateViewer - theDisplaing = "<<theDisplaing<<"; thePrs = "<<thePrs);
295     vtkRenderer *aRen = vf->getRenderer();
296     VTK::ActorCollectionCopy aCopy(aRen->GetActors());
297     vtkActorCollection* anActColl = aCopy.GetActors();
298     vtkActor *anActor;
299     VISU_Actor *anVISUActor = NULL, *aResActor = NULL;
300     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;) {
301       if( anActor->IsA("VISU_Actor") ) {
302         anVISUActor = VISU_Actor::SafeDownCast(anActor);
303         if (thePrs == anVISUActor->GetPrs3d()) {
304           aResActor = anVISUActor;
305           if(theDisplaing < eErase) {
306             aResActor->VisibilityOn();
307             VISU::SetVisibilityState(aResActor, Qtx::ShownState);
308           }
309           else {
310             aResActor->VisibilityOff();
311             VISU::SetVisibilityState(aResActor, Qtx::HiddenState);
312           }
313         } else {
314           if(theDisplaing == eEraseAll || theDisplaing == eDisplayOnly) {
315             anVISUActor->VisibilityOff();
316             VISU::SetVisibilityState(anVISUActor, Qtx::HiddenState);
317           }
318           else if ( theDisplaing == eDisplayAll ) {
319             anVISUActor->VisibilityOn();
320             VISU::SetVisibilityState(anVISUActor, Qtx::ShownState);
321           }
322         }
323       } else if ( anActor->IsA("SALOME_Actor") && (theDisplaing == eEraseAll || theDisplaing == eDisplayOnly) ) {
324         // rnv : fix for the 21254: EDF 1861 VISU: Eye symbol and VISU presentations.
325         //       Take into account presentations created in other modules.
326         SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(anActor);
327         if( aSActor ) {
328           aSActor->VisibilityOff();
329           VISU::SetVisibilityState(aSActor, Qtx::HiddenState);
330         }
331       }
332     }
333     
334     if (aResActor) {
335       RepaintView(theViewWindow);
336       return aResActor;
337     }
338     if(thePrs != NULL && theDisplaing < eErase) {
339       try{
340         anVISUActor = thePrs->CreateActor();
341         vf->AddActor(anVISUActor);
342         VISU::SetVisibilityState(anVISUActor, Qtx::ShownState);
343       }catch(std::exception& exc){
344         if(MYDEBUG) INFOS(exc.what());
345         return NULL;
346       }catch(...){
347         if(MYDEBUG) INFOS("Unknown exception was occured!!!");
348         return NULL;
349       }
350     }
351     RepaintView(theViewWindow);
352     return anVISUActor;
353   }
354
355   struct TUpdatePlot2dEvent: public SALOME_Event
356   {
357     Curve_i*          myCurve;
358     int               myDisplaying;
359
360     TUpdatePlot2dEvent (Curve_i* theCurve, const int theDisplaying):
361       myCurve(theCurve),
362       myDisplaying(theDisplaying)
363     {}
364
365     virtual void Execute()
366     {
367       SalomeApp_Application* anApp = NULL;
368       CORBA::String_var studyName = myCurve->GetStudyDocument()->Name();
369       std::string aStudyName = studyName.in();
370       SUIT_Session* aSession = SUIT_Session::session();
371       QList<SUIT_Application*> anApplications = aSession->applications();
372       QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
373       while (anIter != anApplications.end()) {
374         SUIT_Application* aSUITApp = *anIter;
375         if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
376           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
377             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
378               if (aStudyName == aCStudy->Name()) {
379                 anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
380                 break;
381               }
382             }
383           }
384         }
385         anIter++;
386       }
387       if (!anApp)
388         return;
389       
390       ViewManagerList aViewManagerList;
391       anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList);
392       SUIT_ViewManager* aViewManager;
393       foreach( aViewManager, aViewManagerList ) {
394         if (Plot2d_ViewManager* aManager = dynamic_cast<Plot2d_ViewManager*>(aViewManager)) {
395           if (SPlot2d_Viewer* aViewer = dynamic_cast<SPlot2d_Viewer*>(aManager->getViewModel())) {
396             if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) {
397               UpdatePlot2d(myCurve, myDisplaying, aViewFrame);
398             }
399           }            
400         }
401       }
402     }
403   };
404
405   void UpdatePlot2d (Curve_i* theCurve, int theDisplaying, Plot2d_ViewFrame* theView)
406   {
407     if(MYDEBUG) MESSAGE("UpdatePlot2d - theDisplaying = " << theDisplaying);
408     if (!theView) {
409       // update all views
410       ProcessVoidEvent(new TUpdatePlot2dEvent(theCurve, theDisplaying));
411       return;
412     }
413     QList<Plot2d_Curve*> clist;
414     theView->getCurves(clist);
415     if (theDisplaying == eEraseAll) {
416       for (int i = 0; i < clist.count(); i++) {
417         if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing all : curve - " << clist.at(i));
418         theView->eraseCurve(clist.at(i));
419       }
420     } else if (theDisplaying == eErase) {
421       if (theCurve) {
422         for (int i = 0; i < clist.count(); i++) {
423           SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
424           if (aSPlot2dC->hasIO() &&
425               !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
426             if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing : curve - " << aSPlot2dC);
427             theView->eraseCurve(aSPlot2dC);
428           }
429         }
430       }
431     } else if (theDisplaying == eDisplay ||
432                theDisplaying == eDisplayOnly ||
433                theDisplaying == eUpdateData) {
434       if (theCurve) {
435         bool bFound = false;
436         for (int i = 0; i < clist.count(); i++) {
437           SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
438           if (aSPlot2dC->hasIO() &&
439               !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
440             if (theDisplaying == eUpdateData) {
441               if(MYDEBUG) MESSAGE("UpdatePlot2d - updating data : curve - " << aSPlot2dC);
442             }
443             else {
444               if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - " << aSPlot2dC);
445             }
446             double* xList = 0;
447             double* yList = 0;
448             QStringList zList;
449             int     nbPoints = theCurve->GetData( xList, yList, zList );
450             if (nbPoints > 0 && xList && yList) {
451               aSPlot2dC->setData( xList, yList, nbPoints, zList );
452             }
453             if (theDisplaying == eUpdateData) {
454               theView->updateCurve(aSPlot2dC, true);
455             } else {
456               aSPlot2dC->setHorTitle( theCurve->GetHorTitle().c_str() );
457               aSPlot2dC->setVerTitle( theCurve->GetVerTitle().c_str() );
458               aSPlot2dC->setHorUnits( theCurve->GetHorUnits().c_str() );
459               aSPlot2dC->setVerUnits( theCurve->GetVerUnits().c_str() );
460               if (!theCurve->IsAuto()) {
461                 aSPlot2dC->setLine((Plot2d::LineType)theCurve->GetLine(),
462                                    theCurve->GetLineWidth());
463                 aSPlot2dC->setMarker((Plot2d::MarkerType)theCurve->GetMarker());
464                 SALOMEDS::Color color = theCurve->GetColor();
465                 aSPlot2dC->setColor(QColor((int)(color.R*255.),
466                                            (int)(color.G*255.),
467                                            (int)(color.B*255.)));
468               }
469               aSPlot2dC->setAutoAssign(theCurve->IsAuto());
470               theView->displayCurve(aSPlot2dC);
471               bFound = true;
472             }
473           } else if (theDisplaying == eDisplayOnly) {
474             theView->eraseCurve(aSPlot2dC);
475           }
476         }
477         if (!bFound && theDisplaying != eUpdateData) {
478           Plot2d_Curve* crv = theCurve->CreatePresentation();
479           if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve (new) - "<<crv );
480           if (crv) {
481             theView->displayCurve( crv );
482             theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
483             theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
484             SALOMEDS::Color newColor;
485             newColor.R = crv->getColor().red()/255.;
486             newColor.G = crv->getColor().green()/255.;
487             newColor.B = crv->getColor().blue()/255.;
488             theCurve->SetColor( newColor );
489             crv->setAutoAssign( theCurve->IsAuto() );
490           }
491         }
492       }
493     }
494   }
495
496
497   //----------------------------------------------------------------------------
498   struct TIsSamePrs3d
499   {
500     VISU::Prs3d_i* myPrs3d;
501
502     TIsSamePrs3d(VISU::Prs3d_i* thePrs3d):
503       myPrs3d(thePrs3d)
504     {}
505     
506     bool
507     operator()(VISU_Actor* theActor) 
508     {
509       return theActor->GetPrs3d() == myPrs3d;
510     }
511   };
512
513
514   //----------------------------------------------------------------------------
515   VISU_Actor* 
516   FindActor(SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d)
517   {
518     if(!thePrs3d)
519       return NULL;
520
521     vtkRenderer* aRenderer = theViewWindow->getRenderer();
522     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
523     vtkActorCollection* anActors = aCopy.GetActors();
524     return SVTK::Find<VISU_Actor>(anActors, VISU::TIsSamePrs3d(thePrs3d));
525   }
526
527
528   //----------------------------------------------------------------------------
529   struct TIsSameActor
530   {
531     VISU::TActorFactory* myActor;
532
533     TIsSameActor(VISU::TActorFactory* theActor):
534       myActor(theActor)
535     {}
536     
537     bool
538     operator()(VISU_ActorBase* theActor) 
539     {
540       return theActor->GetFactory() == myActor;
541     }
542   };
543
544   //----------------------------------------------------------------------------
545   VISU_ActorBase* 
546   FindActorBase(SVTK_ViewWindow* theViewWindow, VISU::TActorFactory* theActor)
547   {
548     if(!theActor)
549       return NULL;
550
551     vtkRenderer* aRenderer = theViewWindow->getRenderer();
552     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
553     vtkActorCollection* anActors = aCopy.GetActors();
554     return SVTK::Find<VISU_ActorBase>(anActors, VISU::TIsSameActor(theActor));
555   }
556
557
558   //----------------------------------------------------------------------------
559   struct TDeleteActorsEvent: public SALOME_Event
560   {
561     VISU::Curve_i* myPrs;
562
563     TDeleteActorsEvent (VISU::Curve_i* thePrs):
564       myPrs(thePrs)
565     {}
566
567     virtual
568     void
569     Execute()
570     {
571       if (!myPrs) return;
572
573       // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
574       SALOMEDS::Study_var myStudyDocument = myPrs->GetStudyDocument();
575       SalomeApp_Application* anApp = NULL;
576       CORBA::String_var studyName = myStudyDocument->Name();
577       std::string aStudyName = studyName.in();
578       SUIT_Session* aSession = SUIT_Session::session();
579       QList<SUIT_Application*> anApplications = aSession->applications();
580       QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
581       while ( anIter != anApplications.end() ) {
582         SUIT_Application* aSUITApp = *anIter;
583         if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
584           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
585             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
586               if (aStudyName == aCStudy->Name()) {
587                 anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
588                 break;
589               }
590             }
591           }
592         }
593         anIter++;
594       }
595       if (!anApp)
596         return;
597
598       // 2. Remove corresponding IO from selection
599       SALOMEDS::SObject_var aSObject = myPrs->GetSObject();
600       CORBA::String_var anEntry = aSObject->GetID();
601
602       LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
603       SALOME_ListIO aListIO, aNewListIO;
604       aSelectionMgr->selectedObjects(aListIO);
605
606       for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
607         if (it.Value()->hasEntry()) {
608           std::string aCurEntry (it.Value()->getEntry());
609           if (aCurEntry != std::string( anEntry.in() ) ) {
610             aNewListIO.Append(it.Value());
611           }
612         }
613       }
614
615       aSelectionMgr->setSelectedObjects(aNewListIO);
616
617       // 3. Remove Actors
618       ViewManagerList aViewManagerList;
619       anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
620       QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
621       for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
622         SUIT_ViewManager* aViewManager = *anVMIter;
623         QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
624         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
625           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
626             if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
627               Plot2d_ViewFrame* vf = vw->getViewFrame();
628               QList<Plot2d_Curve*> clist;
629               vf->getCurves(clist);
630               for (int i = 0; i < clist.count(); i++) {
631                 if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
632                   if (cu->hasIO() &&
633                       strcmp(myPrs->GetEntry().c_str(), cu->getIO()->getEntry())) {
634                     vf->eraseCurve(cu);
635                   }
636                 }
637               }
638               vf->Repaint();
639               //jfa tmp:aViewFrame->unHighlightAll();
640             }
641           }
642         }
643       }
644     }
645   };
646
647   void DeleteActors (VISU::Curve_i* thePrs)
648   {
649     if (!thePrs) return;
650     ProcessVoidEvent(new TDeleteActorsEvent (thePrs));
651
652 /*    // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
653     SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument();
654     SalomeApp_Application* anApp = NULL;
655     CORBA::String_var studyName = myStudyDocument->Name();
656     std::string aStudyName = studyName.in();
657     SUIT_Session* aSession = SUIT_Session::session();
658     QPtrList<SUIT_Application> anApplications = aSession->applications();
659     QPtrListIterator<SUIT_Application> anIter (anApplications);
660     while (SUIT_Application* aSUITApp = anIter.current()) {
661       ++anIter;
662       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
663         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
664           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
665             if (aStudyName == aCStudy->Name()) {
666               anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
667               break;
668             }
669           }
670         }
671       }
672     }
673     if (!anApp)
674       return;
675
676     // 2. Remove corresponding IO from selection
677     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
678     CORBA::String_var anEntry = aSObject->GetID();
679
680     LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
681     SALOME_ListIO aListIO, aNewListIO;
682     aSelectionMgr->selectedObjects(aListIO);
683
684     for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
685       if (it.Value()->hasEntry()) {
686         std::string aCurEntry (it.Value()->getEntry());
687         if (aCurEntry != std::string( anEntry.in() ) ) {
688           aNewListIO.Append(it.Value());
689         }
690       }
691     }
692
693     aSelectionMgr->setSelectedObjects(aNewListIO);
694
695     // 3. Remove Actors
696     ViewManagerList aViewManagerList;
697     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
698     QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
699     for (; anVMIter.current(); ++anVMIter) {
700       SUIT_ViewManager* aViewManager = anVMIter.current();
701       QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
702       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
703         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
704           if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
705             Plot2d_ViewFrame* vf = vw->getViewFrame();
706             QList<Plot2d_Curve> clist;
707             vf->getCurves(clist);
708             for (int i = 0; i < clist.count(); i++) {
709               if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
710                 if (cu->hasIO() &&
711                     strcmp(cu->getIO()->getEntry(), thePrs->GetEntry()) == 0) {
712                   vf->eraseCurve(cu);
713                 }
714               }
715             }
716             vf->Repaint();
717             //jfa tmp:aViewFrame->unHighlightAll();
718           }
719         }
720       }
721 }*/
722   }
723
724   void DeleteActors (VISU::Prs3d_i* thePrs)
725   {
726     if (!thePrs) return;
727
728     // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
729     SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument();
730     SalomeApp_Application* anApp = NULL;
731     CORBA::String_var studyName = myStudyDocument->Name();
732     std::string aStudyName = studyName.in();
733     SUIT_Session* aSession = SUIT_Session::session();
734     QList<SUIT_Application*> anApplications = aSession->applications();
735     QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
736     while (anIter != anApplications.end()) {
737       SUIT_Application* aSUITApp = *anIter;
738       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
739         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
740           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
741             if (aStudyName == aCStudy->Name()) {
742               anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
743               break;
744             }
745           }
746         }
747       }
748       anIter++;
749     }
750     if (!anApp)
751       return;
752
753     // 2. Remove corresponding IO from selection
754     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
755     CORBA::String_var anEntry = aSObject->GetID();
756
757     LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
758     SALOME_ListIO aListIO, aNewListIO;
759     aSelectionMgr->selectedObjects(aListIO);
760
761     for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
762       if (it.Value()->hasEntry()) {
763         std::string aCurEntry (it.Value()->getEntry());
764         if (aCurEntry != std::string( anEntry.in() ) ) {
765           aNewListIO.Append(it.Value());
766         }
767       }
768     }
769
770     aSelectionMgr->setSelectedObjects(aNewListIO);
771
772     // 3. Remove Actors
773     ViewManagerList aViewManagerList;
774     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
775     QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
776     for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
777       SUIT_ViewManager* aViewManager = *anVMIter;
778       QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
779       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
780         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
781           if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
782             VISU_Actor* anActor = NULL;
783             VTK::ActorCollectionCopy aCopy(vw->getRenderer()->GetActors());
784             vtkActorCollection *anActColl = aCopy.GetActors();
785             anActColl->InitTraversal();
786             vtkActor *aVTKActor = anActColl->GetNextActor();
787             for (; !anActor && aVTKActor; aVTKActor = anActColl->GetNextActor()) {
788               if (VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(aVTKActor)) {
789                 if (thePrs == anVISUActor->GetPrs3d()) {
790                   anActor = anVISUActor;
791                 }
792               }
793             }
794             if (anActor) {
795               vw->RemoveActor(anActor);
796             }
797           }
798         }
799       }
800     }
801   }
802 }