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