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