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