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