1 // Copyright (C) 2007-2015 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 );
102 SVTK_Viewer::~SVTK_Viewer()
106 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
107 QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
109 gradList << tr( "GT_HORIZONTALGRADIENT" )
110 << tr( "GT_VERTICALGRADIENT" )
111 << tr( "GT_FIRSTDIAGONALGRADIENT" )
112 << tr( "GT_SECONDDIAGONALGRADIENT" )
113 << tr( "GT_FIRSTCORNERGRADIENT" )
114 << tr( "GT_SECONDCORNERGRADIENT" )
115 << tr( "GT_THIRDCORNERGRADIENT" )
116 << tr( "GT_FOURTHCORNERGRADIENT" );
117 idList << HorizontalGradient
119 << FirstDiagonalGradient
120 << SecondDiagonalGradient
121 << FirstCornerGradient
122 << SecondCornerGradient
123 << ThirdCornerGradient
124 << FourthCornerGradient;
125 #ifdef VTK_ENABLE_TEXTURED_BACKGROUND
126 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
128 return tr("BG_IMAGE_FILES");
131 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
132 void SVTK_Viewer::stereoData( QStringList& typeList, QIntList& idList )
134 typeList << tr("ST_CRYSTALEYES") << tr("ST_REDBLUE") <<
135 tr("ST_INTERLACED") << tr("ST_LEFT") <<
136 tr("ST_RIGHT") << tr("ST_DRESDEN") <<
137 tr("ST_ANAGLYPH") << tr("ST_CHECKERBOARD") <<
138 tr("ST_SPLITVIEWPORTHORIZONTAL");
139 idList << CrystalEyesType << RedBlueType <<
140 InterlacedType << LeftType <<
141 RightType << DresdenType <<
142 AnaglyphType << CheckerboardType <<
143 SplitViewPortHorizontalType;
146 //! Get background color of the viewer [obsolete]
147 QColor SVTK_Viewer::backgroundColor() const
149 return background().color();
152 //! Set background color to the viewer [obsolete]
153 void SVTK_Viewer::setBackgroundColor( const QColor& c )
155 Qtx::BackgroundData bg = background();
161 \return background data
163 Qtx::BackgroundData SVTK_Viewer::background() const
165 return myDefaultBackground;
170 \param theBackground - new background data
172 void SVTK_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
174 myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black );
175 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
176 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
177 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
178 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
179 aView->setBackground(myDefaultBackground);
185 /*!Create new instance of view window on desktop \a theDesktop.
186 *\retval SUIT_ViewWindow* - created view window pointer.
188 SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
190 TViewWindow* aViewWindow = new TViewWindow(theDesktop);
191 aViewWindow->Initialize(this);
193 aViewWindow->setBackground( background() );
194 aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
195 aViewWindow->SetStaticTrihedronVisible( isStaticTrihedronVisible() );
196 aViewWindow->SetProjectionMode( projectionMode() );
197 aViewWindow->SetStereoType( stereoType() );
198 aViewWindow->SetAnaglyphFilter( anaglyphFilter() );
199 aViewWindow->SetQuadBufferSupport( isQuadBufferSupport() );
200 aViewWindow->SetInteractionStyle( interactionStyle() );
201 aViewWindow->SetZoomingStyle( zoomingStyle() );
202 aViewWindow->SetPreSelectionMode( preSelectionMode() );
203 aViewWindow->SetSelectionEnabled( isSelectionEnabled() );
204 aViewWindow->SetIncrementalSpeed( incrementalSpeed(), incrementalSpeedMode() );
205 aViewWindow->SetSpacemouseButtons( spacemouseBtn(1), spacemouseBtn(2), spacemouseBtn(3) );
207 connect(aViewWindow, SIGNAL( actorAdded(VTKViewer_Actor*) ),
208 this, SLOT(onActorAdded(VTKViewer_Actor*)));
209 connect(aViewWindow, SIGNAL( actorRemoved(VTKViewer_Actor*) ),
210 this, SLOT(onActorRemoved(VTKViewer_Actor*)));
216 \return trihedron size
218 double SVTK_Viewer::trihedronSize() const
220 return myTrihedronSize;
224 \return true if thihedron changes size in accordance with bounding box
226 bool SVTK_Viewer::trihedronRelative() const
228 return myTrihedronRelative;
232 Sets trihedron size and relativeness( whether thihedron changes size in accordance with bounding box)
233 \param theSize - new size
234 \param theRelative - new relativeness
236 void SVTK_Viewer::setTrihedronSize( const double theSize, const bool theRelative )
238 myTrihedronSize = theSize;
239 myTrihedronRelative = theRelative;
241 if (SUIT_ViewManager* aViewManager = getViewManager()) {
242 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
243 for ( uint i = 0; i < aViews.count(); i++ )
245 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
246 aView->SetTrihedronSize( theSize, theRelative );
252 \return visibility status of the static trihedron
254 bool SVTK_Viewer::isStaticTrihedronVisible() const
256 return myIsStaticTrihedronVisible;
260 Sets visibility status of the static trihedron
261 \param theIsVisible - new visibility status
263 void SVTK_Viewer::setStaticTrihedronVisible( const bool theIsVisible )
265 myIsStaticTrihedronVisible = theIsVisible;
267 if (SUIT_ViewManager* aViewManager = getViewManager()) {
268 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
269 for ( uint i = 0; i < aViews.count(); i++ )
271 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
272 aView->SetStaticTrihedronVisible( theIsVisible );
278 \return projection mode
280 int SVTK_Viewer::projectionMode() const
287 Sets projection mode: 0 - orthogonal, 1 - perspective projection
288 \param theMode - new projection mode
290 void SVTK_Viewer::setProjectionMode( const int theMode )
292 if ( myProjMode != theMode ) {
293 if ( theMode != SVTK_ViewWindow::Stereo )
294 myProjMode = theMode;
295 if (SUIT_ViewManager* aViewManager = getViewManager()) {
296 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
297 for ( uint i = 0; i < aViews.count(); i++ )
299 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
300 aView->SetProjectionMode( theMode );
309 int SVTK_Viewer::stereoType() const
316 \param theType - new stereo type
318 void SVTK_Viewer::setStereoType( const int theType )
320 if ( myStereoType != theType ) {
321 myStereoType = theType;
323 if (SUIT_ViewManager* aViewManager = getViewManager()) {
324 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
325 for ( uint i = 0; i < aViews.count(); i++ )
327 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
328 aView->SetStereoType( theType );
335 \return anaglyph filter
337 int SVTK_Viewer::anaglyphFilter() const
339 return myAnaglyphFilter;
344 \param theFilter - new anaglyph filter
346 void SVTK_Viewer::setAnaglyphFilter( const int theFilter )
348 if ( myAnaglyphFilter != theFilter ) {
349 myAnaglyphFilter = theFilter;
351 if (SUIT_ViewManager* aViewManager = getViewManager()) {
352 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
353 for ( uint i = 0; i < aViews.count(); i++ )
355 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
356 aView->SetAnaglyphFilter( theFilter );
363 \return support quad-buffered stereo
365 bool SVTK_Viewer::isQuadBufferSupport() const
367 return myQuadBufferSupport;
371 Set support quad-buffered stereo
372 \param theEnable - enable/disable support quad-buffered stereo
374 void SVTK_Viewer::setQuadBufferSupport( const bool theEnable )
376 if ( myQuadBufferSupport != theEnable ) {
377 myQuadBufferSupport = theEnable;
379 if (SUIT_ViewManager* aViewManager = getViewManager()) {
380 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
381 for ( uint i = 0; i < aViews.count(); i++ )
383 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
384 aView->SetQuadBufferSupport( theEnable );
390 \return interaction style
392 int SVTK_Viewer::interactionStyle() const
398 Sets interaction style: 0 - standard, 1 - keyboard free interaction
399 \param theStyle - new interaction style
401 void SVTK_Viewer::setInteractionStyle( const int theStyle )
405 if (SUIT_ViewManager* aViewManager = getViewManager()) {
406 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
407 for ( uint i = 0; i < aViews.count(); i++ )
409 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
410 aView->SetInteractionStyle( theStyle );
416 \return zooming style
418 int SVTK_Viewer::zoomingStyle() const
420 return myZoomingStyle;
424 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
425 \param theStyle - new zooming style
427 void SVTK_Viewer::setZoomingStyle( const int theStyle )
429 myZoomingStyle = theStyle;
431 if (SUIT_ViewManager* aViewManager = getViewManager()) {
432 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
433 for ( uint i = 0; i < aViews.count(); i++ )
435 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
436 aView->SetZoomingStyle( theStyle );
442 \return current preselection mode
444 Preselection_Mode SVTK_Viewer::preSelectionMode() const
446 return myPreSelectionMode;
450 Sets preselection mode
451 \param theMode - new preselection mode
453 void SVTK_Viewer::setPreSelectionMode( Preselection_Mode theMode )
455 myPreSelectionMode = theMode;
457 if (SUIT_ViewManager* aViewManager = getViewManager()) {
458 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
459 for ( uint i = 0; i < aViews.count(); i++ )
461 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
462 aView->SetPreSelectionMode( theMode );
468 \return incremental speed value
470 int SVTK_Viewer::incrementalSpeed() const
472 return myIncrementSpeed;
476 \return modification mode of the incremental speed
478 int SVTK_Viewer::incrementalSpeedMode() const
480 return myIncrementMode;
484 Set the incremental speed value and modification mode
485 \param theValue - new value
486 \param theMode - new mode: 0 - arithmetic, 1 - geometrical progression
488 void SVTK_Viewer::setIncrementalSpeed( const int theValue, const int theMode )
490 myIncrementSpeed = theValue;
491 myIncrementMode = theMode;
493 if (SUIT_ViewManager* aViewManager = getViewManager()) {
494 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
495 for ( uint i = 0; i < aViews.count(); i++ )
497 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
498 aView->SetIncrementalSpeed( theValue, theMode );
504 \return spacemouse button assigned to the specified function
505 \param theIndex - function by number (from 1 to 3)
507 int SVTK_Viewer::spacemouseBtn( const int theIndex ) const
509 if ( theIndex < 1 || theIndex > 3 )
511 return mySpaceBtn[theIndex-1];
515 Set the spacemouse buttons
516 \param theBtn1, theBtn2, theBtn3 - new buttons
518 void SVTK_Viewer::setSpacemouseButtons( const int theBtn1, const int theBtn2, const int theBtn3 )
520 mySpaceBtn[0] = theBtn1;
521 mySpaceBtn[1] = theBtn2;
522 mySpaceBtn[2] = theBtn3;
524 if (SUIT_ViewManager* aViewManager = getViewManager()) {
525 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
526 for ( uint i = 0; i < aViews.count(); i++ )
528 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
529 aView->SetSpacemouseButtons( theBtn1, theBtn2, theBtn3 );
535 Sets new view manager
536 \param theViewManager - new view manager
538 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
540 SUIT_ViewModel::setViewManager(theViewManager);
542 if ( !theViewManager )
545 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
546 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
548 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
549 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
551 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
552 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
556 Builds popup for vtk viewer
558 void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
560 thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
561 thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
563 thePopup->addSeparator();
565 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
566 //Support of several toolbars in the popup menu
567 QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
568 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
569 for( ; it!=last; it++ )
570 thePopup->addAction( (*it)->toggleViewAction() );
571 aView->RefreshDumpImage();
576 SLOT: called on mouse button press, empty implementation
578 void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
582 SLOT: called on mouse move, empty implementation
584 void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
588 SLOT: called on mouse button release, empty implementation
590 void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
594 Enables/disables selection
595 \param isEnabled - new state
597 void SVTK_Viewer::enableSelection(bool isEnabled)
599 mySelectionEnabled = isEnabled;
600 //!! To be done for view windows
602 if (SUIT_ViewManager* aViewManager = getViewManager()) {
603 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
604 for ( uint i = 0; i < aViews.count(); i++ )
606 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
607 aView->SetSelectionEnabled( isEnabled );
612 //clear current selection in the viewer
613 bool blocked = blockSignals( true );
614 if ( SUIT_ViewManager* aViewMgr = getViewManager() ) {
615 if( SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewMgr->getActiveView() ) ){
616 if( SVTK_Selector* aSelector = aViewWindow->GetSelector() ) {
617 if(SVTK_View* aView = aViewWindow->getView()){
618 aSelector->ClearIObjects();
619 aView->onSelectionChanged();
624 blockSignals( blocked );
630 Enables/disables selection of many object
631 \param isEnabled - new state
633 void SVTK_Viewer::enableMultiselection(bool isEnable)
635 myMultiSelectionEnabled = isEnable;
636 //!! To be done for view windows
640 SLOT: called on dump view operation is activated, stores scene to raster file
642 void SVTK_Viewer::onDumpView()
644 if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
649 SLOT: called if background color is to be changed changed, passes new color to view port
651 void SVTK_Viewer::onChangeBackground()
653 SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
657 // get supported gradient types
658 QStringList gradList;
659 QIntList idList, txtList;
660 QString formats = backgroundData( gradList, idList, txtList );
663 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
664 aView, // parent for dialog box
665 txtList, // allowed texture modes
666 true, // enable solid color mode
667 true, // enable gradient mode
668 false, // disable custom gradient mode
669 !txtList.isEmpty(), // enable texture mode
670 gradList, // gradient names
671 idList, // gradient identifiers
672 formats ); // image formats
674 // set chosen background data to the viewer
675 if ( bgData.isValid() )
676 aView->setBackground( bgData );
681 \param prs - presentation
683 void SVTK_Viewer::Display( const SALOME_VTKPrs* prs )
685 // try do downcast object
686 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
689 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
690 // get SALOMEDS Study
691 // Temporarily commented to avoid awful dependecy on SALOMEDS
692 // TODO: better mechanism of storing display/erse status in a study
693 // should be provided...
694 // _PTR(Study) aStudy(getStudyDS());
695 anActorCollection->InitTraversal();
696 while(vtkActor* anActor = anActorCollection->GetNextActor()){
697 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
698 if(!anAct->ShouldBeDisplayed())
700 // Set visibility flag
701 // Temporarily commented to avoid awful dependecy on SALOMEDS
702 // TODO: better mechanism of storing display/erse status in a study
703 // should be provided...
704 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
705 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
706 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
708 // just display the object
709 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
710 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
711 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
712 if(SVTK_View* aView = aViewWindow->getView()){
713 aView->Display(anAct,false);
714 if(anAct->IsSetCamera()){
715 vtkRenderer* aRenderer = aView->getRenderer();
716 anAct->SetCamera( aRenderer->GetActiveCamera() );
729 \param prs - presentation
730 \param forced - removes object from view
732 void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
734 // try do downcast object
735 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
738 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
739 // get SALOMEDS Study
740 // Temporarily commented to avoid awful dependecy on SALOMEDS
741 // TODO: better mechanism of storing display/erase status in a study
742 // should be provided...
743 //_PTR(Study) aStudy(getStudyDS());
744 anActorCollection->InitTraversal();
745 while(vtkActor* anActor = anActorCollection->GetNextActor())
746 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
747 // Set visibility flag
748 // Temporarily commented to avoid awful dependecy on SALOMEDS
749 // TODO: better mechanism of storing display/erase status in a study
750 // should be provided...
751 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
752 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
753 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
755 // just display the object
756 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
757 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
758 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
759 if(SVTK_View* aView = aViewWindow->getView())
762 aView->Remove(anAct,false);
764 aView->Erase(anAct,forced);
773 Erase all presentations
774 \param forced - removes all objects from view
776 void SVTK_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
778 // Temporarily commented to avoid awful dependecy on SALOMEDS
779 // TODO: better mechanism of storing display/erse status in a study
780 // should be provided...
781 //_PTR(Study) aStudy(getStudyDS());
782 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
783 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
784 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
785 if(SVTK_View* aView = aViewWindow->getView()){
786 vtkRenderer* aRenderer = aView->getRenderer();
787 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
788 vtkActorCollection* anActorCollection = aCopy.GetActors();
789 anActorCollection->InitTraversal();
790 while(vtkActor* anActor = anActorCollection->GetNextActor()){
791 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
792 // Set visibility flag
793 // Temporarily commented to avoid awful dependecy on SALOMEDS
794 // TODO: better mechanism of storing display/erse status in a study
795 // should be provided...
796 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
797 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
798 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
800 if(SVTK_Renderer* aRnd = aView->GetRenderer())
801 aRnd->RemoveActor(anAct);
804 anAct->SetVisibility( false );
805 // erase dependent actors
806 vtkActorCollection* aCollection = vtkActorCollection::New();
807 anAct->GetChildActors( aCollection );
808 aCollection->InitTraversal();
809 while(vtkActor* aSubAct = aCollection->GetNextActor())
810 aSubAct->SetVisibility( false );
811 aCollection->Delete();
818 SALOME_View::EraseAll( d, forced );
824 Create presentation corresponding to the entry
827 SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry )
829 SVTK_Prs* prs = new SVTK_Prs( entry );
831 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
832 if(SVTK_View* aView = aViewWindow->getView()){
833 vtkRenderer* aRenderer = aView->getRenderer();
834 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
835 vtkActorCollection* theActors = aCopy.GetActors();
836 theActors->InitTraversal();
838 while( ( ac = theActors->GetNextActor() ) ) {
839 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
840 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
841 prs->AddObject( ac );
850 \return true if object is displayed in viewer
851 \param obj - object to be checked
853 bool SVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& io )
855 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
856 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
857 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
858 if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
859 if(SVTK_View* aView = aViewWnd->getView())
860 if(!aView->isVisible( io ))
867 \Collect objects visible in viewer
868 \param theList - visible objects collection
870 void SVTK_Viewer::GetVisible( SALOME_ListIO& theList )
872 // here we collect object if it is disaplaed even one view
873 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
874 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
875 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
876 if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
877 if(SVTK_View* aView = aViewWnd->getView())
878 aView->GetVisible( theList );
882 Updates current viewer
884 void SVTK_Viewer::Repaint()
886 // if (theUpdateTrihedron) onAdjustTrihedron();
887 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
888 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
889 if(TViewWindow* aViewWindow = dynamic_cast<TViewWindow*>(aViews.at(i)))
890 if(SVTK_View* aView = aViewWindow->getView())
895 void SVTK_Viewer::onActorAdded(VTKViewer_Actor* theActor)
897 emit actorAdded((SVTK_ViewWindow*)sender(), theActor);
900 void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor)
902 emit actorRemoved((SVTK_ViewWindow*)sender(), theActor);