Salome HOME
Restore support of med-2.1 in MEDWrapper
[modules/visu.git] / src / VISU_I / VISU_ViewManager_i.cc
1 //  Copyright (C) 2007-2010  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(aResActor, Qtx::HiddenState);
317           }
318           else if ( theDisplaing == eDisplayAll ) {
319             anVISUActor->VisibilityOn();
320             VISU::SetVisibilityState(aResActor, Qtx::HiddenState);
321           }
322         }
323       }
324     }
325     if (aResActor) {
326       RepaintView(theViewWindow);
327       return aResActor;
328     }
329     if(thePrs != NULL && theDisplaing < eErase){
330       try{
331         anVISUActor = thePrs->CreateActor();
332         vf->AddActor(anVISUActor);
333       }catch(std::exception& exc){
334         if(MYDEBUG) INFOS(exc.what());
335         return NULL;
336       }catch(...){
337         if(MYDEBUG) INFOS("Unknown exception was occured!!!");
338         return NULL;
339       }
340     }
341     RepaintView(theViewWindow);
342     return anVISUActor;
343   }
344
345   struct TUpdatePlot2dEvent: public SALOME_Event
346   {
347     Curve_i*          myCurve;
348     int               myDisplaying;
349
350     TUpdatePlot2dEvent (Curve_i* theCurve, const int theDisplaying):
351       myCurve(theCurve),
352       myDisplaying(theDisplaying)
353     {}
354
355     virtual void Execute()
356     {
357       SalomeApp_Application* anApp = NULL;
358       CORBA::String_var studyName = myCurve->GetStudyDocument()->Name();
359       std::string aStudyName = studyName.in();
360       SUIT_Session* aSession = SUIT_Session::session();
361       QList<SUIT_Application*> anApplications = aSession->applications();
362       QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
363       while (anIter != anApplications.end()) {
364         SUIT_Application* aSUITApp = *anIter;
365         if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
366           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
367             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
368               if (aStudyName == aCStudy->Name()) {
369                 anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
370                 break;
371               }
372             }
373           }
374         }
375         anIter++;
376       }
377       if (!anApp)
378         return;
379       
380       ViewManagerList aViewManagerList;
381       anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList);
382       SUIT_ViewManager* aViewManager;
383       foreach( aViewManager, aViewManagerList ) {
384         if (Plot2d_ViewManager* aManager = dynamic_cast<Plot2d_ViewManager*>(aViewManager)) {
385           if (SPlot2d_Viewer* aViewer = dynamic_cast<SPlot2d_Viewer*>(aManager->getViewModel())) {
386             if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) {
387               UpdatePlot2d(myCurve, myDisplaying, aViewFrame);
388             }
389           }            
390         }
391       }
392     }
393   };
394
395   void UpdatePlot2d (Curve_i* theCurve, int theDisplaying, Plot2d_ViewFrame* theView)
396   {
397     if(MYDEBUG) MESSAGE("UpdatePlot2d - theDisplaying = " << theDisplaying);
398     if (!theView) {
399       // update all views
400       ProcessVoidEvent(new TUpdatePlot2dEvent(theCurve, theDisplaying));
401       return;
402     }
403     QList<Plot2d_Curve*> clist;
404     theView->getCurves(clist);
405     if (theDisplaying == eEraseAll) {
406       for (int i = 0; i < clist.count(); i++) {
407         if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing all : curve - " << clist.at(i));
408         theView->eraseCurve(clist.at(i));
409       }
410     } else if (theDisplaying == eErase) {
411       if (theCurve) {
412         for (int i = 0; i < clist.count(); i++) {
413           SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
414           if (aSPlot2dC->hasIO() &&
415               !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
416             if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing : curve - " << aSPlot2dC);
417             theView->eraseCurve(aSPlot2dC);
418           }
419         }
420       }
421     } else if (theDisplaying == eDisplay ||
422                theDisplaying == eDisplayOnly ||
423                theDisplaying == eUpdateData) {
424       if (theCurve) {
425         bool bFound = false;
426         for (int i = 0; i < clist.count(); i++) {
427           SPlot2d_Curve* aSPlot2dC = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
428           if (aSPlot2dC->hasIO() &&
429               !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) {
430             if (theDisplaying == eUpdateData) {
431               if(MYDEBUG) MESSAGE("UpdatePlot2d - updating data : curve - " << aSPlot2dC);
432             }
433             else {
434               if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - " << aSPlot2dC);
435             }
436             double* xList = 0;
437             double* yList = 0;
438             QStringList zList;
439             int     nbPoints = theCurve->GetData( xList, yList, zList );
440             if (nbPoints > 0 && xList && yList) {
441               aSPlot2dC->setData( xList, yList, nbPoints, zList );
442             }
443             if (theDisplaying == eUpdateData) {
444               theView->updateCurve(aSPlot2dC, true);
445             } else {
446               aSPlot2dC->setHorTitle( theCurve->GetHorTitle().c_str() );
447               aSPlot2dC->setVerTitle( theCurve->GetVerTitle().c_str() );
448               aSPlot2dC->setHorUnits( theCurve->GetHorUnits().c_str() );
449               aSPlot2dC->setVerUnits( theCurve->GetVerUnits().c_str() );
450               if (!theCurve->IsAuto()) {
451                 aSPlot2dC->setLine((Plot2d::LineType)theCurve->GetLine(),
452                                    theCurve->GetLineWidth());
453                 aSPlot2dC->setMarker((Plot2d::MarkerType)theCurve->GetMarker());
454                 SALOMEDS::Color color = theCurve->GetColor();
455                 aSPlot2dC->setColor(QColor((int)(color.R*255.),
456                                            (int)(color.G*255.),
457                                            (int)(color.B*255.)));
458               }
459               aSPlot2dC->setAutoAssign(theCurve->IsAuto());
460               theView->displayCurve(aSPlot2dC);
461               bFound = true;
462             }
463           } else if (theDisplaying == eDisplayOnly) {
464             theView->eraseCurve(aSPlot2dC);
465           }
466         }
467         if (!bFound && theDisplaying != eUpdateData) {
468           Plot2d_Curve* crv = theCurve->CreatePresentation();
469           if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve (new) - "<<crv );
470           if (crv) {
471             theView->displayCurve( crv );
472             theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
473             theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
474             SALOMEDS::Color newColor;
475             newColor.R = crv->getColor().red()/255.;
476             newColor.G = crv->getColor().green()/255.;
477             newColor.B = crv->getColor().blue()/255.;
478             theCurve->SetColor( newColor );
479             crv->setAutoAssign( theCurve->IsAuto() );
480           }
481         }
482       }
483     }
484   }
485
486
487   //----------------------------------------------------------------------------
488   struct TIsSamePrs3d
489   {
490     VISU::Prs3d_i* myPrs3d;
491
492     TIsSamePrs3d(VISU::Prs3d_i* thePrs3d):
493       myPrs3d(thePrs3d)
494     {}
495     
496     bool
497     operator()(VISU_Actor* theActor) 
498     {
499       return theActor->GetPrs3d() == myPrs3d;
500     }
501   };
502
503
504   //----------------------------------------------------------------------------
505   VISU_Actor* 
506   FindActor(SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d)
507   {
508     if(!thePrs3d)
509       return NULL;
510
511     vtkRenderer* aRenderer = theViewWindow->getRenderer();
512     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
513     vtkActorCollection* anActors = aCopy.GetActors();
514     return SVTK::Find<VISU_Actor>(anActors, VISU::TIsSamePrs3d(thePrs3d));
515   }
516
517
518   //----------------------------------------------------------------------------
519   struct TIsSameActor
520   {
521     VISU::TActorFactory* myActor;
522
523     TIsSameActor(VISU::TActorFactory* theActor):
524       myActor(theActor)
525     {}
526     
527     bool
528     operator()(VISU_ActorBase* theActor) 
529     {
530       return theActor->GetFactory() == myActor;
531     }
532   };
533
534   //----------------------------------------------------------------------------
535   VISU_ActorBase* 
536   FindActorBase(SVTK_ViewWindow* theViewWindow, VISU::TActorFactory* theActor)
537   {
538     if(!theActor)
539       return NULL;
540
541     vtkRenderer* aRenderer = theViewWindow->getRenderer();
542     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
543     vtkActorCollection* anActors = aCopy.GetActors();
544     return SVTK::Find<VISU_ActorBase>(anActors, VISU::TIsSameActor(theActor));
545   }
546
547
548   //----------------------------------------------------------------------------
549   struct TDeleteActorsEvent: public SALOME_Event
550   {
551     VISU::Curve_i* myPrs;
552
553     TDeleteActorsEvent (VISU::Curve_i* thePrs):
554       myPrs(thePrs)
555     {}
556
557     virtual
558     void
559     Execute()
560     {
561       if (!myPrs) return;
562
563       // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
564       SALOMEDS::Study_var myStudyDocument = myPrs->GetStudyDocument();
565       SalomeApp_Application* anApp = NULL;
566       CORBA::String_var studyName = myStudyDocument->Name();
567       std::string aStudyName = studyName.in();
568       SUIT_Session* aSession = SUIT_Session::session();
569       QList<SUIT_Application*> anApplications = aSession->applications();
570       QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
571       while ( anIter != anApplications.end() ) {
572         SUIT_Application* aSUITApp = *anIter;
573         if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
574           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
575             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
576               if (aStudyName == aCStudy->Name()) {
577                 anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
578                 break;
579               }
580             }
581           }
582         }
583         anIter++;
584       }
585       if (!anApp)
586         return;
587
588       // 2. Remove corresponding IO from selection
589       SALOMEDS::SObject_var aSObject = myPrs->GetSObject();
590       CORBA::String_var anEntry = aSObject->GetID();
591
592       LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
593       SALOME_ListIO aListIO, aNewListIO;
594       aSelectionMgr->selectedObjects(aListIO);
595
596       for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
597         if (it.Value()->hasEntry()) {
598           std::string aCurEntry (it.Value()->getEntry());
599           if (aCurEntry != std::string( anEntry.in() ) ) {
600             aNewListIO.Append(it.Value());
601           }
602         }
603       }
604
605       aSelectionMgr->setSelectedObjects(aNewListIO);
606
607       // 3. Remove Actors
608       ViewManagerList aViewManagerList;
609       anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
610       QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
611       for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
612         SUIT_ViewManager* aViewManager = *anVMIter;
613         QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
614         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
615           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
616             if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
617               Plot2d_ViewFrame* vf = vw->getViewFrame();
618               QList<Plot2d_Curve*> clist;
619               vf->getCurves(clist);
620               for (int i = 0; i < clist.count(); i++) {
621                 if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
622                   if (cu->hasIO() &&
623                       strcmp(myPrs->GetEntry().c_str(), cu->getIO()->getEntry())) {
624                     vf->eraseCurve(cu);
625                   }
626                 }
627               }
628               vf->Repaint();
629               //jfa tmp:aViewFrame->unHighlightAll();
630             }
631           }
632         }
633       }
634     }
635   };
636
637   void DeleteActors (VISU::Curve_i* thePrs)
638   {
639     if (!thePrs) return;
640     ProcessVoidEvent(new TDeleteActorsEvent (thePrs));
641
642 /*    // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
643     SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument();
644     SalomeApp_Application* anApp = NULL;
645     CORBA::String_var studyName = myStudyDocument->Name();
646     std::string aStudyName = studyName.in();
647     SUIT_Session* aSession = SUIT_Session::session();
648     QPtrList<SUIT_Application> anApplications = aSession->applications();
649     QPtrListIterator<SUIT_Application> anIter (anApplications);
650     while (SUIT_Application* aSUITApp = anIter.current()) {
651       ++anIter;
652       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
653         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
654           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
655             if (aStudyName == aCStudy->Name()) {
656               anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
657               break;
658             }
659           }
660         }
661       }
662     }
663     if (!anApp)
664       return;
665
666     // 2. Remove corresponding IO from selection
667     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
668     CORBA::String_var anEntry = aSObject->GetID();
669
670     LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
671     SALOME_ListIO aListIO, aNewListIO;
672     aSelectionMgr->selectedObjects(aListIO);
673
674     for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
675       if (it.Value()->hasEntry()) {
676         std::string aCurEntry (it.Value()->getEntry());
677         if (aCurEntry != std::string( anEntry.in() ) ) {
678           aNewListIO.Append(it.Value());
679         }
680       }
681     }
682
683     aSelectionMgr->setSelectedObjects(aNewListIO);
684
685     // 3. Remove Actors
686     ViewManagerList aViewManagerList;
687     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
688     QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
689     for (; anVMIter.current(); ++anVMIter) {
690       SUIT_ViewManager* aViewManager = anVMIter.current();
691       QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
692       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
693         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
694           if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
695             Plot2d_ViewFrame* vf = vw->getViewFrame();
696             QList<Plot2d_Curve> clist;
697             vf->getCurves(clist);
698             for (int i = 0; i < clist.count(); i++) {
699               if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
700                 if (cu->hasIO() &&
701                     strcmp(cu->getIO()->getEntry(), thePrs->GetEntry()) == 0) {
702                   vf->eraseCurve(cu);
703                 }
704               }
705             }
706             vf->Repaint();
707             //jfa tmp:aViewFrame->unHighlightAll();
708           }
709         }
710       }
711 }*/
712   }
713
714   void DeleteActors (VISU::Prs3d_i* thePrs)
715   {
716     if (!thePrs) return;
717
718     // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
719     SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument();
720     SalomeApp_Application* anApp = NULL;
721     CORBA::String_var studyName = myStudyDocument->Name();
722     std::string aStudyName = studyName.in();
723     SUIT_Session* aSession = SUIT_Session::session();
724     QList<SUIT_Application*> anApplications = aSession->applications();
725     QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
726     while (anIter != anApplications.end()) {
727       SUIT_Application* aSUITApp = *anIter;
728       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
729         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
730           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
731             if (aStudyName == aCStudy->Name()) {
732               anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
733               break;
734             }
735           }
736         }
737       }
738       anIter++;
739     }
740     if (!anApp)
741       return;
742
743     // 2. Remove corresponding IO from selection
744     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
745     CORBA::String_var anEntry = aSObject->GetID();
746
747     LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
748     SALOME_ListIO aListIO, aNewListIO;
749     aSelectionMgr->selectedObjects(aListIO);
750
751     for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
752       if (it.Value()->hasEntry()) {
753         std::string aCurEntry (it.Value()->getEntry());
754         if (aCurEntry != std::string( anEntry.in() ) ) {
755           aNewListIO.Append(it.Value());
756         }
757       }
758     }
759
760     aSelectionMgr->setSelectedObjects(aNewListIO);
761
762     // 3. Remove Actors
763     ViewManagerList aViewManagerList;
764     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
765     QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
766     for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
767       SUIT_ViewManager* aViewManager = *anVMIter;
768       QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
769       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
770         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
771           if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
772             VISU_Actor* anActor = NULL;
773             VTK::ActorCollectionCopy aCopy(vw->getRenderer()->GetActors());
774             vtkActorCollection *anActColl = aCopy.GetActors();
775             anActColl->InitTraversal();
776             vtkActor *aVTKActor = anActColl->GetNextActor();
777             for (; !anActor && aVTKActor; aVTKActor = anActColl->GetNextActor()) {
778               if (VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(aVTKActor)) {
779                 if (thePrs == anVISUActor->GetPrs3d()) {
780                   anActor = anVISUActor;
781                 }
782               }
783             }
784             if (anActor) {
785               vw->RemoveActor(anActor);
786             }
787           }
788         }
789       }
790     }
791   }
792 }