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