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