Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_I / VISU_ViewManager_i.cc
1 // Copyright (C) 2007-2012  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               aSPlot2dC->setScale(theCurve->GetScale());
443             }
444             else {
445               if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - " << aSPlot2dC);
446             }
447             double* xList = 0;
448             double* yList = 0;
449             QStringList zList;
450             int     nbPoints = theCurve->GetData( xList, yList, zList );
451             if (nbPoints > 0 && xList && yList) {
452               aSPlot2dC->setData( xList, yList, nbPoints, zList );
453             }
454             if (theDisplaying == eUpdateData) {
455               theView->updateCurve(aSPlot2dC, true);
456             } else {
457               aSPlot2dC->setHorTitle( theCurve->GetHorTitle().c_str() );
458               aSPlot2dC->setVerTitle( theCurve->GetVerTitle().c_str() );
459               aSPlot2dC->setHorUnits( theCurve->GetHorUnits().c_str() );
460               aSPlot2dC->setVerUnits( theCurve->GetVerUnits().c_str() );
461               if (!theCurve->IsAuto()) {
462                 aSPlot2dC->setLine((Plot2d::LineType)theCurve->GetLine(),
463                                    theCurve->GetLineWidth());
464                 aSPlot2dC->setMarker((Plot2d::MarkerType)theCurve->GetMarker());
465                 SALOMEDS::Color color = theCurve->GetColor();
466                 aSPlot2dC->setColor(QColor((int)(color.R*255.),
467                                            (int)(color.G*255.),
468                                            (int)(color.B*255.)));
469               }
470               aSPlot2dC->setAutoAssign(theCurve->IsAuto());
471               theView->displayCurve(aSPlot2dC);
472               bFound = true;
473             }
474           } else if (theDisplaying == eDisplayOnly) {
475             theView->eraseCurve(aSPlot2dC);
476           }
477         }
478         if (!bFound && theDisplaying != eUpdateData) {
479           Plot2d_Curve* crv = theCurve->CreatePresentation();
480           if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve (new) - "<<crv );
481           if (crv) {
482             theView->displayCurve( crv );
483             theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
484             theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
485             SALOMEDS::Color newColor;
486             newColor.R = crv->getColor().red()/255.;
487             newColor.G = crv->getColor().green()/255.;
488             newColor.B = crv->getColor().blue()/255.;
489             theCurve->SetColor( newColor );
490             crv->setAutoAssign( theCurve->IsAuto() );
491           }
492         }
493       }
494     }
495   }
496
497
498   //----------------------------------------------------------------------------
499   struct TIsSamePrs3d
500   {
501     VISU::Prs3d_i* myPrs3d;
502
503     TIsSamePrs3d(VISU::Prs3d_i* thePrs3d):
504       myPrs3d(thePrs3d)
505     {}
506     
507     bool
508     operator()(VISU_Actor* theActor) 
509     {
510       return theActor->GetPrs3d() == myPrs3d;
511     }
512   };
513
514
515   //----------------------------------------------------------------------------
516   VISU_Actor* 
517   FindActor(SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d)
518   {
519     if(!thePrs3d)
520       return NULL;
521
522     vtkRenderer* aRenderer = theViewWindow->getRenderer();
523     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
524     vtkActorCollection* anActors = aCopy.GetActors();
525     return SVTK::Find<VISU_Actor>(anActors, VISU::TIsSamePrs3d(thePrs3d));
526   }
527
528
529   //----------------------------------------------------------------------------
530   struct TIsSameActor
531   {
532     VISU::TActorFactory* myActor;
533
534     TIsSameActor(VISU::TActorFactory* theActor):
535       myActor(theActor)
536     {}
537     
538     bool
539     operator()(VISU_ActorBase* theActor) 
540     {
541       return theActor->GetFactory() == myActor;
542     }
543   };
544
545   //----------------------------------------------------------------------------
546   VISU_ActorBase* 
547   FindActorBase(SVTK_ViewWindow* theViewWindow, VISU::TActorFactory* theActor)
548   {
549     if(!theActor)
550       return NULL;
551
552     vtkRenderer* aRenderer = theViewWindow->getRenderer();
553     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
554     vtkActorCollection* anActors = aCopy.GetActors();
555     return SVTK::Find<VISU_ActorBase>(anActors, VISU::TIsSameActor(theActor));
556   }
557
558
559   //----------------------------------------------------------------------------
560   struct TDeleteActorsEvent: public SALOME_Event
561   {
562     VISU::Curve_i* myPrs;
563
564     TDeleteActorsEvent (VISU::Curve_i* thePrs):
565       myPrs(thePrs)
566     {}
567
568     virtual
569     void
570     Execute()
571     {
572       if (!myPrs) return;
573
574       // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
575       SALOMEDS::Study_var myStudyDocument = myPrs->GetStudyDocument();
576       SalomeApp_Application* anApp = NULL;
577       CORBA::String_var studyName = myStudyDocument->Name();
578       std::string aStudyName = studyName.in();
579       SUIT_Session* aSession = SUIT_Session::session();
580       QList<SUIT_Application*> anApplications = aSession->applications();
581       QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
582       while ( anIter != anApplications.end() ) {
583         SUIT_Application* aSUITApp = *anIter;
584         if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
585           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
586             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
587               if (aStudyName == aCStudy->Name()) {
588                 anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
589                 break;
590               }
591             }
592           }
593         }
594         anIter++;
595       }
596       if (!anApp)
597         return;
598
599       // 2. Remove corresponding IO from selection
600       SALOMEDS::SObject_var aSObject = myPrs->GetSObject();
601       CORBA::String_var anEntry = aSObject->GetID();
602
603       LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
604       SALOME_ListIO aListIO, aNewListIO;
605       aSelectionMgr->selectedObjects(aListIO);
606
607       for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
608         if (it.Value()->hasEntry()) {
609           std::string aCurEntry (it.Value()->getEntry());
610           if (aCurEntry != std::string( anEntry.in() ) ) {
611             aNewListIO.Append(it.Value());
612           }
613         }
614       }
615
616       aSelectionMgr->setSelectedObjects(aNewListIO);
617
618       // 3. Remove Actors
619       ViewManagerList aViewManagerList;
620       anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
621       QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
622       for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
623         SUIT_ViewManager* aViewManager = *anVMIter;
624         QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
625         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
626           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
627             if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
628               Plot2d_ViewFrame* vf = vw->getViewFrame();
629               QList<Plot2d_Curve*> clist;
630               vf->getCurves(clist);
631               for (int i = 0; i < clist.count(); i++) {
632                 if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
633                   if (cu->hasIO() &&
634                       strcmp(myPrs->GetEntry().c_str(), cu->getIO()->getEntry())) {
635                     vf->eraseCurve(cu);
636                   }
637                 }
638               }
639               vf->Repaint();
640               //jfa tmp:aViewFrame->unHighlightAll();
641             }
642           }
643         }
644       }
645     }
646   };
647
648   void DeleteActors (VISU::Curve_i* thePrs)
649   {
650     if (!thePrs) return;
651     ProcessVoidEvent(new TDeleteActorsEvent (thePrs));
652
653 /*    // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
654     SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument();
655     SalomeApp_Application* anApp = NULL;
656     CORBA::String_var studyName = myStudyDocument->Name();
657     std::string aStudyName = studyName.in();
658     SUIT_Session* aSession = SUIT_Session::session();
659     QPtrList<SUIT_Application> anApplications = aSession->applications();
660     QPtrListIterator<SUIT_Application> anIter (anApplications);
661     while (SUIT_Application* aSUITApp = anIter.current()) {
662       ++anIter;
663       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
664         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
665           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
666             if (aStudyName == aCStudy->Name()) {
667               anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
668               break;
669             }
670           }
671         }
672       }
673     }
674     if (!anApp)
675       return;
676
677     // 2. Remove corresponding IO from selection
678     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
679     CORBA::String_var anEntry = aSObject->GetID();
680
681     LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
682     SALOME_ListIO aListIO, aNewListIO;
683     aSelectionMgr->selectedObjects(aListIO);
684
685     for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
686       if (it.Value()->hasEntry()) {
687         std::string aCurEntry (it.Value()->getEntry());
688         if (aCurEntry != std::string( anEntry.in() ) ) {
689           aNewListIO.Append(it.Value());
690         }
691       }
692     }
693
694     aSelectionMgr->setSelectedObjects(aNewListIO);
695
696     // 3. Remove Actors
697     ViewManagerList aViewManagerList;
698     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
699     QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
700     for (; anVMIter.current(); ++anVMIter) {
701       SUIT_ViewManager* aViewManager = anVMIter.current();
702       QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
703       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
704         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
705           if (Plot2d_ViewWindow* vw = dynamic_cast<Plot2d_ViewWindow*>(aViewWindow)) {
706             Plot2d_ViewFrame* vf = vw->getViewFrame();
707             QList<Plot2d_Curve> clist;
708             vf->getCurves(clist);
709             for (int i = 0; i < clist.count(); i++) {
710               if (SPlot2d_Curve* cu = dynamic_cast<SPlot2d_Curve*>(clist.at(i))) {
711                 if (cu->hasIO() &&
712                     strcmp(cu->getIO()->getEntry(), thePrs->GetEntry()) == 0) {
713                   vf->eraseCurve(cu);
714                 }
715               }
716             }
717             vf->Repaint();
718             //jfa tmp:aViewFrame->unHighlightAll();
719           }
720         }
721       }
722 }*/
723   }
724
725   void DeleteActors (VISU::Prs3d_i* thePrs)
726   {
727     if (!thePrs) return;
728
729     // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute())
730     SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument();
731     SalomeApp_Application* anApp = NULL;
732     CORBA::String_var studyName = myStudyDocument->Name();
733     std::string aStudyName = studyName.in();
734     SUIT_Session* aSession = SUIT_Session::session();
735     QList<SUIT_Application*> anApplications = aSession->applications();
736     QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
737     while (anIter != anApplications.end()) {
738       SUIT_Application* aSUITApp = *anIter;
739       if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
740         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
741           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
742             if (aStudyName == aCStudy->Name()) {
743               anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
744               break;
745             }
746           }
747         }
748       }
749       anIter++;
750     }
751     if (!anApp)
752       return;
753
754     // 2. Remove corresponding IO from selection
755     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
756     CORBA::String_var anEntry = aSObject->GetID();
757
758     LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
759     SALOME_ListIO aListIO, aNewListIO;
760     aSelectionMgr->selectedObjects(aListIO);
761
762     for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
763       if (it.Value()->hasEntry()) {
764         std::string aCurEntry (it.Value()->getEntry());
765         if (aCurEntry != std::string( anEntry.in() ) ) {
766           aNewListIO.Append(it.Value());
767         }
768       }
769     }
770
771     aSelectionMgr->setSelectedObjects(aNewListIO);
772
773     // 3. Remove Actors
774     ViewManagerList aViewManagerList;
775     anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
776     QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
777     for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
778       SUIT_ViewManager* aViewManager = *anVMIter;
779       QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
780       for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
781         if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
782           if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
783             VISU_Actor* anActor = NULL;
784             VTK::ActorCollectionCopy aCopy(vw->getRenderer()->GetActors());
785             vtkActorCollection *anActColl = aCopy.GetActors();
786             anActColl->InitTraversal();
787             vtkActor *aVTKActor = anActColl->GetNextActor();
788             for (; !anActor && aVTKActor; aVTKActor = anActColl->GetNextActor()) {
789               if (VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(aVTKActor)) {
790                 if (thePrs == anVISUActor->GetPrs3d()) {
791                   anActor = anVISUActor;
792                 }
793               }
794             }
795             if (anActor) {
796               vw->RemoveActor(anActor);
797             }
798           }
799         }
800       }
801     }
802   }
803 }