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