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