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