Salome HOME
Fix for the "0022466: [CEA 1047] Mesh stays selected when selection is
[modules/gui.git] / src / SVTK / SVTK_ViewModel.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 #include <QMenu>
24 #include <QColorDialog>
25 #include <QToolBar>
26
27 #include <vtkCamera.h>
28 #include <vtkRenderer.h>
29 #include <vtkActorCollection.h>
30
31 //#include "SUIT_Session.h"
32 #include "SVTK_ViewModel.h"
33 #include "SVTK_ViewWindow.h"
34 #include "SVTK_View.h"
35 #include "SVTK_Renderer.h"
36 //#include "SVTK_MainWindow.h"
37 #include "SVTK_Prs.h"
38
39 #include "VTKViewer_Algorithm.h"
40 #include "VTKViewer_ViewModel.h"
41
42 #include "SUIT_ViewModel.h"
43 #include "SUIT_ViewManager.h"
44
45 #include "SALOME_Actor.h"
46
47 #include "QtxActionToolMgr.h"
48 #include "QtxBackgroundTool.h"
49
50 // VSR: Uncomment below line to allow texture background support in VTK viewer
51 #define VTK_ENABLE_TEXTURED_BACKGROUND
52
53
54 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
55 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from 
56 // SALOMEDS::StudyManager - no linkage with SalomeApp. 
57
58 // Temporarily commented to avoid awful dependecy on SALOMEDS
59 // TODO: better mechanism of storing display/erse status in a study
60 // should be provided...
61 //static _PTR(Study) getStudyDS() 
62 //{
63 //  SALOMEDSClient_Study* aStudy = NULL;
64 //  _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
65   // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
66   //    id of its underlying SALOMEDS::Study
67 //  SUIT_Application* app = SUIT_Session::session()->activeApplication();
68 //  if ( !app )  return _PTR(Study)(aStudy); 
69 //  SUIT_Study* stud = app->activeStudy();
70 //  if ( !stud ) return _PTR(Study)(aStudy);  
71 //  const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
72   // get SALOMEDS_Study with this id from StudyMgr
73 //  return aMgr->GetStudyByID( id );
74 //}
75
76 /*!
77   Constructor
78 */
79 SVTK_Viewer::SVTK_Viewer()
80 {
81   myTrihedronSize = 105;
82   myTrihedronRelative = true;
83   myIsStaticTrihedronVisible = true;
84   myIncrementSpeed = 10;
85   myIncrementMode = 0;
86   myProjMode = 0;
87   myStyle = 0;
88   myZoomingStyle = 0;
89   mySelectionEnabled = true;
90   myPreSelectionMode = Standard_Preselection;
91   mySpaceBtn[0] = 1;
92   mySpaceBtn[1] = 2;
93   mySpaceBtn[2] = 9;
94   myDefaultBackground = Qtx::BackgroundData( Qt::black );
95 }
96
97 /*!
98   Destructor
99 */
100 SVTK_Viewer::~SVTK_Viewer() 
101 {
102 }
103
104 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
105 QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
106 {
107   gradList << tr( "GT_HORIZONTALGRADIENT" )
108            << tr( "GT_VERTICALGRADIENT" )
109            << tr( "GT_FIRSTDIAGONALGRADIENT" )
110            << tr( "GT_SECONDDIAGONALGRADIENT" )
111            << tr( "GT_FIRSTCORNERGRADIENT" )
112            << tr( "GT_SECONDCORNERGRADIENT" )
113            << tr( "GT_THIRDCORNERGRADIENT" )
114            << tr( "GT_FOURTHCORNERGRADIENT" );
115   idList   << HorizontalGradient
116            << VerticalGradient
117            << FirstDiagonalGradient
118            << SecondDiagonalGradient
119            << FirstCornerGradient
120            << SecondCornerGradient
121            << ThirdCornerGradient
122            << FourthCornerGradient;
123 #ifdef VTK_ENABLE_TEXTURED_BACKGROUND
124   txtList  << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
125 #endif
126   return tr("BG_IMAGE_FILES");
127 }
128
129 //! Get background color of the viewer [obsolete]
130 QColor SVTK_Viewer::backgroundColor() const
131 {
132   return background().color();
133 }
134
135 //! Set background color to the viewer [obsolete]
136 void SVTK_Viewer::setBackgroundColor( const QColor& c )
137 {
138   Qtx::BackgroundData bg = background();
139   bg.setColor( c );
140   setBackground( bg );
141 }
142
143 /*!
144   \return background data
145 */
146 Qtx::BackgroundData SVTK_Viewer::background() const
147 {
148   return myDefaultBackground;
149 }
150
151 /*!
152   Changes background
153   \param theBackground - new background data
154 */
155 void SVTK_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
156 {
157   myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black );
158   QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
159   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
160     if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
161       if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
162         aView->setBackground(myDefaultBackground);
163       }
164     }
165   }  
166 }
167
168 /*!Create new instance of view window on desktop \a theDesktop.
169  *\retval SUIT_ViewWindow* - created view window pointer.
170  */
171 SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
172 {
173   TViewWindow* aViewWindow = new TViewWindow(theDesktop);
174   aViewWindow->Initialize(this);
175
176   aViewWindow->setBackground( background() );
177   aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
178   aViewWindow->SetStaticTrihedronVisible( isStaticTrihedronVisible() );
179   aViewWindow->SetProjectionMode( projectionMode() );
180   aViewWindow->SetInteractionStyle( interactionStyle() );
181   aViewWindow->SetZoomingStyle( zoomingStyle() );
182   aViewWindow->SetPreSelectionMode( preSelectionMode() );
183   aViewWindow->SetSelectionEnabled( isSelectionEnabled() );
184   aViewWindow->SetIncrementalSpeed( incrementalSpeed(), incrementalSpeedMode() );
185   aViewWindow->SetSpacemouseButtons( spacemouseBtn(1), spacemouseBtn(2), spacemouseBtn(3) );
186
187   connect(aViewWindow, SIGNAL( actorAdded(VTKViewer_Actor*) ), 
188           this,  SLOT(onActorAdded(VTKViewer_Actor*)));
189   connect(aViewWindow, SIGNAL( actorRemoved(VTKViewer_Actor*) ), 
190           this,  SLOT(onActorRemoved(VTKViewer_Actor*)));
191
192   return aViewWindow;
193 }
194
195 /*!
196   \return trihedron size
197 */
198 double SVTK_Viewer::trihedronSize() const
199 {
200   return myTrihedronSize;
201 }
202
203 /*!
204   \return true if thihedron changes size in accordance with bounding box
205 */
206 bool SVTK_Viewer::trihedronRelative() const
207 {
208   return myTrihedronRelative;
209 }
210
211 /*!
212   Sets trihedron size and relativeness( whether thihedron changes size in accordance with bounding box)
213   \param theSize - new size
214   \param theRelative - new relativeness
215 */
216 void SVTK_Viewer::setTrihedronSize( const double theSize, const bool theRelative )
217 {
218   myTrihedronSize = theSize;
219   myTrihedronRelative = theRelative;
220
221   if (SUIT_ViewManager* aViewManager = getViewManager()) {
222     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
223     for ( uint i = 0; i < aViews.count(); i++ )
224     {
225       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
226               aView->SetTrihedronSize( theSize, theRelative );
227     }
228   }
229 }
230
231 /*!
232   \return visibility status of the static trihedron
233 */
234 bool SVTK_Viewer::isStaticTrihedronVisible() const
235 {
236   return myIsStaticTrihedronVisible;
237 }
238
239 /*!
240   Sets visibility status of the static trihedron
241   \param theIsVisible - new visibility status
242 */
243 void SVTK_Viewer::setStaticTrihedronVisible( const bool theIsVisible )
244 {
245   myIsStaticTrihedronVisible = theIsVisible;
246
247   if (SUIT_ViewManager* aViewManager = getViewManager()) {
248     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
249     for ( uint i = 0; i < aViews.count(); i++ )
250     {
251       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
252         aView->SetStaticTrihedronVisible( theIsVisible );
253     }
254   }
255 }
256
257 /*!
258   \return projection mode
259 */
260 int SVTK_Viewer::projectionMode() const
261 {
262   return myProjMode;
263 }
264
265
266 /*!
267   Sets projection mode: 0 - orthogonal, 1 - perspective projection
268   \param theMode - new projection mode
269 */
270 void SVTK_Viewer::setProjectionMode( const int theMode )
271 {
272   if ( myProjMode != theMode ) {
273     myProjMode = theMode;
274
275     if (SUIT_ViewManager* aViewManager = getViewManager()) {
276       QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
277       for ( uint i = 0; i < aViews.count(); i++ )
278       {
279         if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
280           aView->SetProjectionMode( theMode );
281       }
282     }
283   }
284 }
285
286 /*!
287   \return interaction style
288 */
289 int SVTK_Viewer::interactionStyle() const
290 {
291   return myStyle;
292 }
293
294 /*!
295   Sets interaction style: 0 - standard, 1 - keyboard free interaction
296   \param theStyle - new interaction style
297 */
298 void SVTK_Viewer::setInteractionStyle( const int theStyle )
299 {
300   myStyle = theStyle;
301   
302   if (SUIT_ViewManager* aViewManager = getViewManager()) {
303     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
304     for ( uint i = 0; i < aViews.count(); i++ )
305     {
306       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
307         aView->SetInteractionStyle( theStyle );
308     }
309   }
310 }
311
312 /*!
313   \return zooming style
314 */
315 int SVTK_Viewer::zoomingStyle() const
316 {
317   return myZoomingStyle;
318 }
319
320 /*!
321   Sets zooming style: 0 - standard, 1 - advanced (at cursor)
322   \param theStyle - new zooming style
323 */
324 void SVTK_Viewer::setZoomingStyle( const int theStyle )
325 {
326   myZoomingStyle = theStyle;
327   
328   if (SUIT_ViewManager* aViewManager = getViewManager()) {
329     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
330     for ( uint i = 0; i < aViews.count(); i++ )
331     {
332       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
333         aView->SetZoomingStyle( theStyle );
334     }
335   }
336 }
337
338 /*!
339   \return current preselection mode
340 */
341 Preselection_Mode SVTK_Viewer::preSelectionMode() const
342 {
343   return myPreSelectionMode;
344 }
345
346 /*!
347   Sets preselection mode
348   \param theMode - new preselection mode
349 */
350 void SVTK_Viewer::setPreSelectionMode( Preselection_Mode theMode )
351 {
352   myPreSelectionMode = theMode;
353   
354   if (SUIT_ViewManager* aViewManager = getViewManager()) {
355     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
356     for ( uint i = 0; i < aViews.count(); i++ )
357     {
358       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
359         aView->SetPreSelectionMode( theMode );
360     }
361   }
362 }
363
364 /*!
365   \return incremental speed value
366 */
367 int SVTK_Viewer::incrementalSpeed() const
368 {
369   return myIncrementSpeed;
370 }
371
372 /*!
373   \return modification mode of the incremental speed 
374 */
375 int SVTK_Viewer::incrementalSpeedMode() const
376 {
377   return myIncrementMode;
378 }
379
380 /*!
381   Set the incremental speed value and modification mode
382   \param theValue - new value
383   \param theMode - new mode: 0 - arithmetic, 1 - geometrical progression
384 */
385 void SVTK_Viewer::setIncrementalSpeed( const int theValue, const int theMode )
386 {
387   myIncrementSpeed = theValue;
388   myIncrementMode = theMode;
389
390   if (SUIT_ViewManager* aViewManager = getViewManager()) {
391     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
392     for ( uint i = 0; i < aViews.count(); i++ )
393     {
394       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
395         aView->SetIncrementalSpeed( theValue, theMode );
396     }
397   }
398 }
399
400 /*!
401   \return spacemouse button assigned to the specified function
402   \param theIndex - function by number (from 1 to 3)
403 */
404 int SVTK_Viewer::spacemouseBtn( const int theIndex ) const
405 {
406   if ( theIndex < 1 || theIndex > 3 ) 
407     return -1;
408   return mySpaceBtn[theIndex-1];
409 }
410
411 /*!
412   Set the spacemouse buttons
413   \param theBtn1, theBtn2, theBtn3 - new buttons
414 */
415 void SVTK_Viewer::setSpacemouseButtons( const int theBtn1, const int theBtn2, const int theBtn3 )
416 {
417   mySpaceBtn[0] = theBtn1;
418   mySpaceBtn[1] = theBtn2;
419   mySpaceBtn[2] = theBtn3;
420
421   if (SUIT_ViewManager* aViewManager = getViewManager()) {
422     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
423     for ( uint i = 0; i < aViews.count(); i++ )
424     {
425       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
426         aView->SetSpacemouseButtons( theBtn1, theBtn2, theBtn3 );
427     }
428   }
429 }
430
431 /*!
432   Sets new view manager
433   \param theViewManager - new view manager
434 */
435 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
436 {
437   SUIT_ViewModel::setViewManager(theViewManager);
438
439   if ( !theViewManager )
440     return;
441
442   connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
443           this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
444   
445   connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), 
446           this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
447   
448   connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
449           this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
450 }
451
452 /*!
453   Builds popup for vtk viewer
454 */
455 void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
456 {
457   thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
458   thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
459
460   thePopup->addSeparator();
461
462   if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
463     //Support of several toolbars in the popup menu
464     QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
465     QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
466     for( ; it!=last; it++ )
467       thePopup->addAction( (*it)->toggleViewAction() );
468     aView->RefreshDumpImage();
469   }
470 }
471
472 /*!
473   SLOT: called on mouse button press, empty implementation
474 */
475 void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
476 {}
477
478 /*!
479   SLOT: called on mouse move, empty implementation
480 */
481 void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
482 {}
483
484 /*!
485   SLOT: called on mouse button release, empty implementation
486 */
487 void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
488 {}
489
490 /*!
491   Enables/disables selection
492   \param isEnabled - new state
493 */
494 void SVTK_Viewer::enableSelection(bool isEnabled)
495 {
496   mySelectionEnabled = isEnabled;
497   //!! To be done for view windows
498    
499   if (SUIT_ViewManager* aViewManager = getViewManager()) {
500     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
501     for ( uint i = 0; i < aViews.count(); i++ )
502     {
503       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
504         aView->SetSelectionEnabled( isEnabled );
505     }
506   }
507
508   if(!isEnabled) {
509     //clear current selection in the viewer
510     bool blocked = blockSignals( true );
511     if ( SUIT_ViewManager* aViewMgr = getViewManager() ) {
512       if( SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewMgr->getActiveView() ) ){
513         if( SVTK_Selector* aSelector = aViewWindow->GetSelector() ) {
514           if(SVTK_View* aView = aViewWindow->getView()){
515             aSelector->ClearIObjects();
516             aView->onSelectionChanged();
517           }
518         }
519       }
520     }
521     blockSignals( blocked );  
522   }
523
524 }
525
526 /*!
527   Enables/disables selection of many object
528   \param isEnabled - new state
529 */
530 void SVTK_Viewer::enableMultiselection(bool isEnable)
531 {
532   myMultiSelectionEnabled = isEnable;
533   //!! To be done for view windows
534 }
535
536 /*!
537   SLOT: called on dump view operation is activated, stores scene to raster file
538 */
539 void SVTK_Viewer::onDumpView()
540 {
541   if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
542     aView->onDumpView();
543 }
544
545 /*!
546   SLOT: called if background color is to be changed changed, passes new color to view port
547 */
548 void SVTK_Viewer::onChangeBackground()
549 {
550   SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
551   if ( !aView )
552     return;
553
554   // get supported gradient types
555   QStringList gradList;
556   QIntList    idList, txtList;
557   QString     formats = backgroundData( gradList, idList, txtList );
558
559   // invoke dialog box
560   Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(),  // initial background
561                                                                    aView,                // parent for dialog box
562                                                                    txtList,              // allowed texture modes
563                                                                    true,                 // enable solid color mode
564                                                                    true,                 // enable gradient mode
565                                                                    false,                // disable custom gradient mode
566                                                                    !txtList.isEmpty(),   // enable texture mode
567                                                                    gradList,             // gradient names
568                                                                    idList,               // gradient identifiers
569                                                                    formats );            // image formats
570
571   // set chosen background data to the viewer
572   if ( bgData.isValid() )
573     aView->setBackground( bgData );
574 }
575
576 /*!
577   Display presentation
578   \param prs - presentation
579 */
580 void SVTK_Viewer::Display( const SALOME_VTKPrs* prs )
581 {
582   // try do downcast object
583   if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
584     if(aPrs->IsNull())
585       return;
586     if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
587       // get SALOMEDS Study
588       // Temporarily commented to avoid awful dependecy on SALOMEDS
589       // TODO: better mechanism of storing display/erse status in a study
590       // should be provided...
591       // _PTR(Study) aStudy(getStudyDS());
592       anActorCollection->InitTraversal();
593       while(vtkActor* anActor = anActorCollection->GetNextActor()){
594         if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
595           if(!anAct->ShouldBeDisplayed())
596             continue;
597           // Set visibility flag
598           // Temporarily commented to avoid awful dependecy on SALOMEDS
599           // TODO: better mechanism of storing display/erse status in a study
600           // should be provided...
601           //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
602           //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
603           //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
604           //}
605           // just display the object
606           QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
607           for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
608             if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
609               if(SVTK_View* aView = aViewWindow->getView()){
610                 aView->Display(anAct,false);
611                 if(anAct->IsSetCamera()){
612                   vtkRenderer* aRenderer = aView->getRenderer();
613                   anAct->SetCamera( aRenderer->GetActiveCamera() );
614                 }
615               }
616             }
617           }
618         }
619       }
620     }
621   }
622 }
623
624 /*!
625   Erase presentation
626   \param prs - presentation
627   \param forced - removes object from view
628 */
629 void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
630 {
631   // try do downcast object
632   if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
633     if(aPrs->IsNull())
634       return;
635     if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
636       // get SALOMEDS Study
637       // Temporarily commented to avoid awful dependecy on SALOMEDS
638       // TODO: better mechanism of storing display/erase status in a study
639       // should be provided...
640       //_PTR(Study) aStudy(getStudyDS());
641       anActorCollection->InitTraversal();
642       while(vtkActor* anActor = anActorCollection->GetNextActor())
643         if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
644           // Set visibility flag
645           // Temporarily commented to avoid awful dependecy on SALOMEDS
646           // TODO: better mechanism of storing display/erase status in a study
647           // should be provided...
648           //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
649           //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
650           //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
651           //}
652           // just display the object
653           QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
654           for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
655             if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
656               if(SVTK_View* aView = aViewWindow->getView())
657               {
658                 if ( forced )
659                   aView->Remove(anAct,false);
660                 else
661                   aView->Erase(anAct,forced);
662               }
663           }
664         }
665     }
666   }
667 }
668
669 /*!
670   Erase all presentations
671   \param forced - removes all objects from view
672 */
673 void SVTK_Viewer::EraseAll( const bool forced )
674 {
675   // Temporarily commented to avoid awful dependecy on SALOMEDS
676   // TODO: better mechanism of storing display/erse status in a study
677   // should be provided...
678   //_PTR(Study) aStudy(getStudyDS());
679   QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
680   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
681     if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
682       if(SVTK_View* aView = aViewWindow->getView()){
683         vtkRenderer* aRenderer =  aView->getRenderer();
684         VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
685         vtkActorCollection* anActorCollection = aCopy.GetActors();
686         anActorCollection->InitTraversal();
687         while(vtkActor* anActor = anActorCollection->GetNextActor()){
688           if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
689             // Set visibility flag
690             // Temporarily commented to avoid awful dependecy on SALOMEDS
691             // TODO: better mechanism of storing display/erse status in a study
692             // should be provided...
693             //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
694             //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
695             //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
696             if(forced){
697               if(SVTK_Renderer* aRnd = aView->GetRenderer())
698                 aRnd->RemoveActor(anAct);
699             }else{
700               // just erase actor
701               anAct->SetVisibility( false );
702               // erase dependent actors
703               vtkActorCollection* aCollection = vtkActorCollection::New();
704               anAct->GetChildActors( aCollection );
705               aCollection->InitTraversal();
706               while(vtkActor* aSubAct = aCollection->GetNextActor())
707                 aSubAct->SetVisibility( false );
708               aCollection->Delete();
709             }
710           }
711         }
712       }
713   }
714   Repaint();
715 }
716
717 /*!
718   Create presentation corresponding to the entry
719   \param entry - entry
720 */
721 SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry )
722 {
723   SVTK_Prs* prs = new SVTK_Prs();
724   if ( entry ) {
725     if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
726       if(SVTK_View* aView = aViewWindow->getView()){
727         vtkRenderer* aRenderer =  aView->getRenderer();
728         VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
729         vtkActorCollection* theActors = aCopy.GetActors();
730         theActors->InitTraversal();
731         vtkActor* ac;
732         while( ( ac = theActors->GetNextActor() ) ) {
733           SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
734           if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
735             prs->AddObject( ac );
736           }
737         }
738       }
739   }
740   return prs;
741 }
742
743 /*!
744   \return true if object is displayed in viewer
745   \param obj - object to be checked
746 */
747 bool SVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& io )
748 {
749   QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
750   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
751     if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
752       if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
753         if(SVTK_View* aView = aViewWnd->getView())
754           if(!aView->isVisible( io ))
755             return false;
756
757   return true;
758 }
759
760 /*!
761   \Collect objects visible in viewer
762   \param theList - visible objects collection
763 */
764 void SVTK_Viewer::GetVisible( SALOME_ListIO& theList )
765 {
766   // here we collect object if it is disaplaed even one view
767   QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
768   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
769     if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
770       if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
771         if(SVTK_View* aView = aViewWnd->getView())
772           aView->GetVisible( theList );
773 }
774
775 /*!
776   Updates current viewer
777 */
778 void SVTK_Viewer::Repaint()
779 {
780 //  if (theUpdateTrihedron) onAdjustTrihedron();
781   QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
782   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
783     if(TViewWindow* aViewWindow = dynamic_cast<TViewWindow*>(aViews.at(i)))
784       if(SVTK_View* aView = aViewWindow->getView())
785         aView->Repaint();
786 }
787  
788
789 void SVTK_Viewer::onActorAdded(VTKViewer_Actor* theActor)
790 {
791   emit actorAdded((SVTK_ViewWindow*)sender(), theActor);
792 }
793
794 void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor)
795 {
796   emit actorRemoved((SVTK_ViewWindow*)sender(), theActor);
797 }