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