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