1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include <QColorDialog>
27 #include <vtkCamera.h>
28 #include <vtkRenderer.h>
29 #include <vtkActorCollection.h>
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"
39 #include "VTKViewer_Algorithm.h"
40 #include "VTKViewer_ViewModel.h"
42 #include "SUIT_ViewModel.h"
43 #include "SUIT_ViewManager.h"
45 #include "SALOME_Actor.h"
47 #include "QtxActionToolMgr.h"
48 #include "QtxBackgroundTool.h"
50 // VSR: Uncomment below line to allow texture background support in VTK viewer
51 #define VTK_ENABLE_TEXTURED_BACKGROUND
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.
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()
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 );
79 SVTK_Viewer::SVTK_Viewer()
81 myTrihedronSize = 105;
82 myTrihedronRelative = true;
83 myIsStaticTrihedronVisible = true;
84 myIncrementSpeed = 10;
91 mySelectionEnabled = true;
92 myPreSelectionMode = Standard_Preselection;
96 myDefaultBackground = Qtx::BackgroundData( Qt::black );
97 myQuadBufferSupport = false;
103 SVTK_Viewer::~SVTK_Viewer()
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 )
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
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;
129 return tr("BG_IMAGE_FILES");
132 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
133 void SVTK_Viewer::stereoData( QStringList& typeList, QIntList& idList )
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;
147 //! Get background color of the viewer [obsolete]
148 QColor SVTK_Viewer::backgroundColor() const
150 return background().color();
153 //! Set background color to the viewer [obsolete]
154 void SVTK_Viewer::setBackgroundColor( const QColor& c )
156 Qtx::BackgroundData bg = background();
162 \return background data
164 Qtx::BackgroundData SVTK_Viewer::background() const
166 return myDefaultBackground;
171 \param theBackground - new background data
173 void SVTK_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
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);
186 /*!Create new instance of view window on desktop \a theDesktop.
187 *\retval SUIT_ViewWindow* - created view window pointer.
189 SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
191 TViewWindow* aViewWindow = new TViewWindow(theDesktop);
192 aViewWindow->Initialize(this);
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) );
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*)));
217 \return trihedron size
219 double SVTK_Viewer::trihedronSize() const
221 return myTrihedronSize;
225 \return true if thihedron changes size in accordance with bounding box
227 bool SVTK_Viewer::trihedronRelative() const
229 return myTrihedronRelative;
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
237 void SVTK_Viewer::setTrihedronSize( const double theSize, const bool theRelative )
239 myTrihedronSize = theSize;
240 myTrihedronRelative = theRelative;
242 if (SUIT_ViewManager* aViewManager = getViewManager()) {
243 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
244 for ( uint i = 0; i < aViews.count(); i++ )
246 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
247 aView->SetTrihedronSize( theSize, theRelative );
253 \return visibility status of the static trihedron
255 bool SVTK_Viewer::isStaticTrihedronVisible() const
257 return myIsStaticTrihedronVisible;
261 Sets visibility status of the static trihedron
262 \param theIsVisible - new visibility status
264 void SVTK_Viewer::setStaticTrihedronVisible( const bool theIsVisible )
266 myIsStaticTrihedronVisible = theIsVisible;
268 if (SUIT_ViewManager* aViewManager = getViewManager()) {
269 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
270 for ( uint i = 0; i < aViews.count(); i++ )
272 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
273 aView->SetStaticTrihedronVisible( theIsVisible );
279 \return projection mode
281 int SVTK_Viewer::projectionMode() const
288 Sets projection mode: 0 - orthogonal, 1 - perspective projection
289 \param theMode - new projection mode
291 void SVTK_Viewer::setProjectionMode( const int theMode )
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++ )
300 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
301 aView->SetProjectionMode( theMode );
310 int SVTK_Viewer::stereoType() const
317 \param theType - new stereo type
319 void SVTK_Viewer::setStereoType( const int theType )
321 if ( myStereoType != theType ) {
322 myStereoType = theType;
324 if (SUIT_ViewManager* aViewManager = getViewManager()) {
325 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
326 for ( uint i = 0; i < aViews.count(); i++ )
328 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
329 aView->SetStereoType( theType );
336 \return anaglyph filter
338 int SVTK_Viewer::anaglyphFilter() const
340 return myAnaglyphFilter;
345 \param theFilter - new anaglyph filter
347 void SVTK_Viewer::setAnaglyphFilter( const int theFilter )
349 if ( myAnaglyphFilter != theFilter ) {
350 myAnaglyphFilter = theFilter;
352 if (SUIT_ViewManager* aViewManager = getViewManager()) {
353 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
354 for ( uint i = 0; i < aViews.count(); i++ )
356 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
357 aView->SetAnaglyphFilter( theFilter );
364 \return support quad-buffered stereo
366 bool SVTK_Viewer::isQuadBufferSupport() const
368 return myQuadBufferSupport;
372 Set support quad-buffered stereo
373 \param theEnable - enable/disable support quad-buffered stereo
375 void SVTK_Viewer::setQuadBufferSupport( const bool theEnable )
377 if ( myQuadBufferSupport != theEnable ) {
378 myQuadBufferSupport = theEnable;
380 if (SUIT_ViewManager* aViewManager = getViewManager()) {
381 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
382 for ( uint i = 0; i < aViews.count(); i++ )
384 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
385 aView->SetQuadBufferSupport( theEnable );
391 \return interaction style
393 int SVTK_Viewer::interactionStyle() const
399 Sets interaction style: 0 - standard, 1 - keyboard free interaction
400 \param theStyle - new interaction style
402 void SVTK_Viewer::setInteractionStyle( const int theStyle )
406 if (SUIT_ViewManager* aViewManager = getViewManager()) {
407 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
408 for ( uint i = 0; i < aViews.count(); i++ )
410 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
411 aView->SetInteractionStyle( theStyle );
417 \return zooming style
419 int SVTK_Viewer::zoomingStyle() const
421 return myZoomingStyle;
425 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
426 \param theStyle - new zooming style
428 void SVTK_Viewer::setZoomingStyle( const int theStyle )
430 myZoomingStyle = theStyle;
432 if (SUIT_ViewManager* aViewManager = getViewManager()) {
433 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
434 for ( uint i = 0; i < aViews.count(); i++ )
436 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
437 aView->SetZoomingStyle( theStyle );
443 \return current preselection mode
445 Preselection_Mode SVTK_Viewer::preSelectionMode() const
447 return myPreSelectionMode;
451 Sets preselection mode
452 \param theMode - new preselection mode
454 void SVTK_Viewer::setPreSelectionMode( Preselection_Mode theMode )
456 myPreSelectionMode = theMode;
458 if (SUIT_ViewManager* aViewManager = getViewManager()) {
459 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
460 for ( uint i = 0; i < aViews.count(); i++ )
462 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
463 aView->SetPreSelectionMode( theMode );
469 \return incremental speed value
471 int SVTK_Viewer::incrementalSpeed() const
473 return myIncrementSpeed;
477 \return modification mode of the incremental speed
479 int SVTK_Viewer::incrementalSpeedMode() const
481 return myIncrementMode;
485 Set the incremental speed value and modification mode
486 \param theValue - new value
487 \param theMode - new mode: 0 - arithmetic, 1 - geometrical progression
489 void SVTK_Viewer::setIncrementalSpeed( const int theValue, const int theMode )
491 myIncrementSpeed = theValue;
492 myIncrementMode = theMode;
494 if (SUIT_ViewManager* aViewManager = getViewManager()) {
495 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
496 for ( uint i = 0; i < aViews.count(); i++ )
498 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
499 aView->SetIncrementalSpeed( theValue, theMode );
505 \return spacemouse button assigned to the specified function
506 \param theIndex - function by number (from 1 to 3)
508 int SVTK_Viewer::spacemouseBtn( const int theIndex ) const
510 if ( theIndex < 1 || theIndex > 3 )
512 return mySpaceBtn[theIndex-1];
516 Set the spacemouse buttons
517 \param theBtn1, theBtn2, theBtn3 - new buttons
519 void SVTK_Viewer::setSpacemouseButtons( const int theBtn1, const int theBtn2, const int theBtn3 )
521 mySpaceBtn[0] = theBtn1;
522 mySpaceBtn[1] = theBtn2;
523 mySpaceBtn[2] = theBtn3;
525 if (SUIT_ViewManager* aViewManager = getViewManager()) {
526 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
527 for ( uint i = 0; i < aViews.count(); i++ )
529 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
530 aView->SetSpacemouseButtons( theBtn1, theBtn2, theBtn3 );
536 Sets new view manager
537 \param theViewManager - new view manager
539 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
541 SUIT_ViewModel::setViewManager(theViewManager);
543 if ( !theViewManager )
546 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
547 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
549 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
550 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
552 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
553 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
557 Builds popup for vtk viewer
559 void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
561 thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
562 thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
564 thePopup->addSeparator();
566 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
567 //Support of several toolbars in the popup menu
568 QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
569 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
570 for( ; it!=last; it++ )
571 thePopup->addAction( (*it)->toggleViewAction() );
572 aView->RefreshDumpImage();
577 SLOT: called on mouse button press, empty implementation
579 void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
583 SLOT: called on mouse move, empty implementation
585 void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
589 SLOT: called on mouse button release, empty implementation
591 void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
595 Enables/disables selection
596 \param isEnabled - new state
598 void SVTK_Viewer::enableSelection(bool isEnabled)
600 mySelectionEnabled = isEnabled;
601 //!! To be done for view windows
603 if (SUIT_ViewManager* aViewManager = getViewManager()) {
604 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
605 for ( uint i = 0; i < aViews.count(); i++ )
607 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
608 aView->SetSelectionEnabled( 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();
625 blockSignals( blocked );
631 Enables/disables selection of many object
632 \param isEnabled - new state
634 void SVTK_Viewer::enableMultiselection(bool isEnable)
636 myMultiSelectionEnabled = isEnable;
637 //!! To be done for view windows
641 SLOT: called on dump view operation is activated, stores scene to raster file
643 void SVTK_Viewer::onDumpView()
645 if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
650 SLOT: called if background color is to be changed changed, passes new color to view port
652 void SVTK_Viewer::onChangeBackground()
654 SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
658 // get supported gradient types
659 QStringList gradList;
660 QIntList idList, txtList;
661 QString formats = backgroundData( gradList, idList, txtList );
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
675 // set chosen background data to the viewer
676 if ( bgData.isValid() )
677 aView->setBackground( bgData );
682 \param prs - presentation
684 void SVTK_Viewer::Display( const SALOME_VTKPrs* prs )
686 // try do downcast object
687 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
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())
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);
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() );
730 \param prs - presentation
731 \param forced - removes object from view
733 void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
735 // try do downcast object
736 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
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);
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())
763 aView->Remove(anAct,false);
765 aView->Erase(anAct,forced);
774 Erase all presentations
775 \param forced - removes all objects from view
777 void SVTK_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
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);
801 if(SVTK_Renderer* aRnd = aView->GetRenderer())
802 aRnd->RemoveActor(anAct);
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();
819 SALOME_View::EraseAll( d, forced );
825 Create presentation corresponding to the entry
828 SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry )
830 SVTK_Prs* prs = new SVTK_Prs( 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();
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 );
851 \return true if object is displayed in viewer
852 \param obj - object to be checked
854 bool SVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& io )
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 ))
868 \Collect objects visible in viewer
869 \param theList - visible objects collection
871 void SVTK_Viewer::GetVisible( SALOME_ListIO& theList )
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 );
883 Updates current viewer
885 void SVTK_Viewer::Repaint()
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())
896 void SVTK_Viewer::onActorAdded(VTKViewer_Actor* theActor)
898 emit actorAdded((SVTK_ViewWindow*)sender(), theActor);
901 void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor)
903 emit actorRemoved((SVTK_ViewWindow*)sender(), theActor);