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