1 // Copyright (C) 2007-2024 CEA, EDF, 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>
28 #include <vtkCamera.h>
29 #include <vtkRenderer.h>
30 #include <vtkActorCollection.h>
32 //#include "SUIT_Session.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"
40 #include "VTKViewer_Algorithm.h"
41 #include "VTKViewer_ViewModel.h"
43 #include "SUIT_ViewModel.h"
44 #include "SUIT_ViewManager.h"
46 #include "SALOME_Actor.h"
48 #include "QtxActionToolMgr.h"
49 #include "QtxBackgroundTool.h"
51 // VSR: Uncomment below line to allow texture background support in VTK viewer
52 #define VTK_ENABLE_TEXTURED_BACKGROUND
57 SVTK_Viewer::SVTK_Viewer()
59 myTrihedronSize = 105;
60 myTrihedronRelative = true;
61 myIsStaticTrihedronVisible = true;
62 myIncrementSpeed = 10;
69 mySelectionEnabled = true;
70 myPreSelectionMode = Standard_Preselection;
74 myDefaultBackground = Qtx::BackgroundData( Qt::black );
75 myQuadBufferSupport = false;
81 SVTK_Viewer::~SVTK_Viewer()
85 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
86 QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
88 gradList << tr( "GT_HORIZONTALGRADIENT" )
89 << tr( "GT_VERTICALGRADIENT" )
90 << tr( "GT_FIRSTDIAGONALGRADIENT" )
91 << tr( "GT_SECONDDIAGONALGRADIENT" )
92 << tr( "GT_FIRSTCORNERGRADIENT" )
93 << tr( "GT_SECONDCORNERGRADIENT" )
94 << tr( "GT_THIRDCORNERGRADIENT" )
95 << tr( "GT_FOURTHCORNERGRADIENT" );
96 idList << HorizontalGradient
98 << FirstDiagonalGradient
99 << SecondDiagonalGradient
100 << FirstCornerGradient
101 << SecondCornerGradient
102 << ThirdCornerGradient
103 << FourthCornerGradient;
104 #ifdef VTK_ENABLE_TEXTURED_BACKGROUND
105 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
107 return tr("BG_IMAGE_FILES");
110 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
111 void SVTK_Viewer::stereoData( QStringList& typeList, QIntList& idList )
113 typeList << tr("ST_CRYSTALEYES") << tr("ST_REDBLUE") <<
114 tr("ST_INTERLACED") << tr("ST_LEFT") <<
115 tr("ST_RIGHT") << tr("ST_DRESDEN") <<
116 tr("ST_ANAGLYPH") << tr("ST_CHECKERBOARD") <<
117 tr("ST_SPLITVIEWPORTHORIZONTAL");
118 idList << CrystalEyesType << RedBlueType <<
119 InterlacedType << LeftType <<
120 RightType << DresdenType <<
121 AnaglyphType << CheckerboardType <<
122 SplitViewPortHorizontalType;
125 //! Get background color of the viewer [obsolete]
126 QColor SVTK_Viewer::backgroundColor() const
128 return background().color();
131 //! Set background color to the viewer [obsolete]
132 void SVTK_Viewer::setBackgroundColor( const QColor& c )
134 Qtx::BackgroundData bg = background();
140 \return background data
142 Qtx::BackgroundData SVTK_Viewer::background() const
144 return myDefaultBackground;
149 \param theBackground - new background data
151 void SVTK_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
153 myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black );
154 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
155 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
156 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
157 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
158 aView->setBackground(myDefaultBackground);
164 /*!Create new instance of view window on desktop \a theDesktop.
165 *\retval SUIT_ViewWindow* - created view window pointer.
167 SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
169 TViewWindow* aViewWindow = new TViewWindow(theDesktop);
170 aViewWindow->Initialize(this);
172 aViewWindow->setBackground( background() );
173 aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
174 aViewWindow->SetStaticTrihedronVisible( isStaticTrihedronVisible() );
175 aViewWindow->SetProjectionMode( projectionMode() );
176 aViewWindow->SetStereoType( stereoType() );
177 aViewWindow->SetAnaglyphFilter( anaglyphFilter() );
178 aViewWindow->SetQuadBufferSupport( isQuadBufferSupport() );
179 aViewWindow->SetInteractionStyle( interactionStyle() );
180 aViewWindow->SetZoomingStyle( zoomingStyle() );
181 aViewWindow->SetPreSelectionMode( preSelectionMode() );
182 aViewWindow->SetSelectionEnabled( isSelectionEnabled() );
183 aViewWindow->SetIncrementalSpeed( incrementalSpeed(), incrementalSpeedMode() );
184 aViewWindow->SetSpacemouseButtons( spacemouseBtn(1), spacemouseBtn(2), spacemouseBtn(3) );
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*)));
195 \return trihedron size
197 double SVTK_Viewer::trihedronSize() const
199 return myTrihedronSize;
203 \return true if thihedron changes size in accordance with bounding box
205 bool SVTK_Viewer::trihedronRelative() const
207 return myTrihedronRelative;
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
215 void SVTK_Viewer::setTrihedronSize( const double theSize, const bool theRelative )
217 myTrihedronSize = theSize;
218 myTrihedronRelative = theRelative;
220 if (SUIT_ViewManager* aViewManager = getViewManager()) {
221 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
222 for ( int i = 0; i < aViews.count(); i++ )
224 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
225 aView->SetTrihedronSize( theSize, theRelative );
231 \return visibility status of the static trihedron
233 bool SVTK_Viewer::isStaticTrihedronVisible() const
235 return myIsStaticTrihedronVisible;
239 Sets visibility status of the static trihedron
240 \param theIsVisible - new visibility status
242 void SVTK_Viewer::setStaticTrihedronVisible( const bool theIsVisible )
244 myIsStaticTrihedronVisible = theIsVisible;
246 if (SUIT_ViewManager* aViewManager = getViewManager()) {
247 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
248 for ( int i = 0; i < aViews.count(); i++ )
250 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
251 aView->SetStaticTrihedronVisible( theIsVisible );
257 \return projection mode
259 int SVTK_Viewer::projectionMode() const
266 Sets projection mode: 0 - orthogonal, 1 - perspective projection
267 \param theMode - new projection mode
269 void SVTK_Viewer::setProjectionMode( const int theMode )
271 if ( myProjMode != theMode ) {
272 if ( theMode != SVTK_ViewWindow::Stereo )
273 myProjMode = theMode;
274 if (SUIT_ViewManager* aViewManager = getViewManager()) {
275 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
276 for ( int i = 0; i < aViews.count(); i++ )
278 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
279 aView->SetProjectionMode( theMode );
288 int SVTK_Viewer::stereoType() const
295 \param theType - new stereo type
297 void SVTK_Viewer::setStereoType( const int theType )
299 if ( myStereoType != theType ) {
300 myStereoType = theType;
302 if (SUIT_ViewManager* aViewManager = getViewManager()) {
303 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
304 for ( int i = 0; i < aViews.count(); i++ )
306 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
307 aView->SetStereoType( theType );
314 \return anaglyph filter
316 int SVTK_Viewer::anaglyphFilter() const
318 return myAnaglyphFilter;
323 \param theFilter - new anaglyph filter
325 void SVTK_Viewer::setAnaglyphFilter( const int theFilter )
327 if ( myAnaglyphFilter != theFilter ) {
328 myAnaglyphFilter = theFilter;
330 if (SUIT_ViewManager* aViewManager = getViewManager()) {
331 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
332 for ( int i = 0; i < aViews.count(); i++ )
334 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
335 aView->SetAnaglyphFilter( theFilter );
342 \return support quad-buffered stereo
344 bool SVTK_Viewer::isQuadBufferSupport() const
346 return myQuadBufferSupport;
350 Set support quad-buffered stereo
351 \param theEnable - enable/disable support quad-buffered stereo
353 void SVTK_Viewer::setQuadBufferSupport( const bool theEnable )
355 if ( myQuadBufferSupport != theEnable ) {
356 myQuadBufferSupport = theEnable;
358 if (SUIT_ViewManager* aViewManager = getViewManager()) {
359 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
360 for ( int i = 0; i < aViews.count(); i++ )
362 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
363 aView->SetQuadBufferSupport( theEnable );
369 \return interaction style
371 int SVTK_Viewer::interactionStyle() const
377 Sets interaction style: 0 - standard, 1 - keyboard free interaction
378 \param theStyle - new interaction style
380 void SVTK_Viewer::setInteractionStyle( const int theStyle )
384 if (SUIT_ViewManager* aViewManager = getViewManager()) {
385 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
386 for ( int i = 0; i < aViews.count(); i++ )
388 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
389 aView->SetInteractionStyle( theStyle );
395 \return zooming style
397 int SVTK_Viewer::zoomingStyle() const
399 return myZoomingStyle;
403 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
404 \param theStyle - new zooming style
406 void SVTK_Viewer::setZoomingStyle( const int theStyle )
408 myZoomingStyle = theStyle;
410 if (SUIT_ViewManager* aViewManager = getViewManager()) {
411 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
412 for ( int i = 0; i < aViews.count(); i++ )
414 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
415 aView->SetZoomingStyle( theStyle );
421 \return current preselection mode
423 Preselection_Mode SVTK_Viewer::preSelectionMode() const
425 return myPreSelectionMode;
429 Sets preselection mode
430 \param theMode - new preselection mode
432 void SVTK_Viewer::setPreSelectionMode( Preselection_Mode theMode )
434 myPreSelectionMode = theMode;
436 if (SUIT_ViewManager* aViewManager = getViewManager()) {
437 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
438 for ( int i = 0; i < aViews.count(); i++ )
440 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
441 aView->SetPreSelectionMode( theMode );
447 \return incremental speed value
449 int SVTK_Viewer::incrementalSpeed() const
451 return myIncrementSpeed;
455 \return modification mode of the incremental speed
457 int SVTK_Viewer::incrementalSpeedMode() const
459 return myIncrementMode;
463 Set the incremental speed value and modification mode
464 \param theValue - new value
465 \param theMode - new mode: 0 - arithmetic, 1 - geometrical progression
467 void SVTK_Viewer::setIncrementalSpeed( const int theValue, const int theMode )
469 myIncrementSpeed = theValue;
470 myIncrementMode = theMode;
472 if (SUIT_ViewManager* aViewManager = getViewManager()) {
473 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
474 for ( int i = 0; i < aViews.count(); i++ )
476 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
477 aView->SetIncrementalSpeed( theValue, theMode );
483 \return spacemouse button assigned to the specified function
484 \param theIndex - function by number (from 1 to 3)
486 int SVTK_Viewer::spacemouseBtn( const int theIndex ) const
488 if ( theIndex < 1 || theIndex > 3 )
490 return mySpaceBtn[theIndex-1];
494 Set the spacemouse buttons
495 \param theBtn1, theBtn2, theBtn3 - new buttons
497 void SVTK_Viewer::setSpacemouseButtons( const int theBtn1, const int theBtn2, const int theBtn3 )
499 mySpaceBtn[0] = theBtn1;
500 mySpaceBtn[1] = theBtn2;
501 mySpaceBtn[2] = theBtn3;
503 if (SUIT_ViewManager* aViewManager = getViewManager()) {
504 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
505 for ( int i = 0; i < aViews.count(); i++ )
507 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
508 aView->SetSpacemouseButtons( theBtn1, theBtn2, theBtn3 );
514 Sets new view manager
515 \param theViewManager - new view manager
517 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
519 SUIT_ViewModel::setViewManager(theViewManager);
521 if ( !theViewManager )
524 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
525 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
527 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
528 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
530 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
531 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
533 connect(theViewManager, SIGNAL(viewCreated(SUIT_ViewWindow*)),
534 this, SLOT(onViewCreated(SUIT_ViewWindow*)));
538 Builds popup for vtk viewer
540 void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
542 thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
543 thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
545 thePopup->addSeparator();
547 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
548 //Support of several toolbars in the popup menu
549 QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
550 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
551 for( ; it!=last; it++ )
552 thePopup->addAction( (*it)->toggleViewAction() );
553 aView->RefreshDumpImage();
558 SLOT: called on mouse button press, empty implementation
560 void SVTK_Viewer::onMousePress(SUIT_ViewWindow* /*vw*/, QMouseEvent* /*event*/)
564 SLOT: called on mouse move, empty implementation
566 void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* /*vw*/, QMouseEvent* /*event*/)
570 SLOT: called on mouse button release, empty implementation
572 void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* /*vw*/, QMouseEvent* /*event*/)
576 Enables/disables selection
577 \param isEnabled - new state
579 void SVTK_Viewer::enableSelection(bool isEnabled)
581 mySelectionEnabled = isEnabled;
582 //!! To be done for view windows
584 if (SUIT_ViewManager* aViewManager = getViewManager()) {
585 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
586 for ( int i = 0; i < aViews.count(); i++ )
588 if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
589 aView->SetSelectionEnabled( isEnabled );
594 //clear current selection in the viewer
595 bool blocked = blockSignals( true );
596 if ( SUIT_ViewManager* aViewMgr = getViewManager() ) {
597 if( SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewMgr->getActiveView() ) ){
598 if( SVTK_Selector* aSelector = aViewWindow->GetSelector() ) {
599 if(SVTK_View* aView = aViewWindow->getView()){
600 aSelector->ClearIObjects();
601 aView->onSelectionChanged();
606 blockSignals( blocked );
612 Enables/disables selection of many object
613 \param isEnabled - new state
615 void SVTK_Viewer::enableMultiselection(bool isEnable)
617 myMultiSelectionEnabled = isEnable;
618 //!! To be done for view windows
622 SLOT: called on dump view operation is activated, stores scene to raster file
624 void SVTK_Viewer::onDumpView()
626 if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
631 SLOT: called if background color is to be changed changed, passes new color to view port
633 void SVTK_Viewer::onChangeBackground()
635 SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
639 // get supported gradient types
640 QStringList gradList;
641 QIntList idList, txtList;
642 QString formats = backgroundData( gradList, idList, txtList );
645 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
646 aView, // parent for dialog box
647 txtList, // allowed texture modes
648 true, // enable solid color mode
649 true, // enable gradient mode
650 false, // disable custom gradient mode
651 !txtList.isEmpty(), // enable texture mode
652 gradList, // gradient names
653 idList, // gradient identifiers
654 formats ); // image formats
656 // set chosen background data to the viewer
657 if ( bgData.isValid() )
658 aView->setBackground( bgData );
663 \param prs - presentation
665 void SVTK_Viewer::Display( const SALOME_VTKPrs* prs )
667 // try do downcast object
668 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
671 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
672 anActorCollection->InitTraversal();
673 while(vtkActor* anActor = anActorCollection->GetNextActor()){
674 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
675 if(!anAct->ShouldBeDisplayed())
677 // Set visibility flag
678 // Temporarily commented to avoid awful dependecy on SALOMEDS
679 // TODO: better mechanism of storing display/erse status in a study
680 // should be provided...
681 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
682 //if(!anObj.IsNull() && anObj->hasEntry()){
683 // ToolsGUI::SetVisibility(anObj->getEntry(),true,this);
685 // just display the object
686 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
687 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
688 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
689 if(SVTK_View* aView = aViewWindow->getView()){
690 aView->Display(anAct,false);
691 if(anAct->IsSetCamera()){
692 vtkRenderer* aRenderer = aView->getRenderer();
693 anAct->SetCamera( aRenderer->GetActiveCamera() );
706 \param prs - presentation
707 \param forced - removes object from view
709 void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
711 // try do downcast object
712 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
715 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
716 anActorCollection->InitTraversal();
717 while(vtkActor* anActor = anActorCollection->GetNextActor())
718 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
719 // Set visibility flag
720 // Temporarily commented to avoid awful dependecy on SALOMEDS
721 // TODO: better mechanism of storing display/erase status in a study
722 // should be provided...
723 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
724 //if(!anObj.IsNull() && anObj->hasEntry()){
725 // ToolsGUI::SetVisibility(anObj->getEntry(),false,this);
727 // just display the object
728 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
729 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
730 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
731 if(SVTK_View* aView = aViewWindow->getView())
734 aView->Remove(anAct,false);
736 aView->Erase(anAct,forced);
745 Erase all presentations
746 \param forced - removes all objects from view
748 void SVTK_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
750 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
751 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
752 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
753 if(SVTK_View* aView = aViewWindow->getView()){
754 vtkRenderer* aRenderer = aView->getRenderer();
755 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
756 vtkActorCollection* anActorCollection = aCopy.GetActors();
757 anActorCollection->InitTraversal();
758 while(vtkActor* anActor = anActorCollection->GetNextActor()){
759 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
760 // Set visibility flag
761 // Temporarily commented to avoid awful dependecy on SALOMEDS
762 // TODO: better mechanism of storing display/erse status in a study
763 // should be provided...
764 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
765 //if(!anObj.IsNull() && anObj->hasEntry())
766 // ToolsGUI::SetVisibility(anObj->getEntry(),false,this);
768 if(SVTK_Renderer* aRnd = aView->GetRenderer())
769 aRnd->RemoveActor(anAct);
772 anAct->SetVisibility( false );
773 // erase dependent actors
774 vtkActorCollection* aCollection = vtkActorCollection::New();
775 anAct->GetChildActors( aCollection );
776 aCollection->InitTraversal();
777 while(vtkActor* aSubAct = aCollection->GetNextActor())
778 aSubAct->SetVisibility( false );
779 aCollection->Delete();
786 SALOME_View::EraseAll( d, forced );
792 Create presentation corresponding to the entry
795 SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry )
797 SVTK_Prs* prs = new SVTK_Prs( entry );
799 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
800 if(SVTK_View* aView = aViewWindow->getView()){
801 vtkRenderer* aRenderer = aView->getRenderer();
802 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
803 vtkActorCollection* theActors = aCopy.GetActors();
804 theActors->InitTraversal();
806 while( ( ac = theActors->GetNextActor() ) ) {
807 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
808 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
809 prs->AddObject( ac );
818 \return true if object is displayed in viewer
819 \param obj - object to be checked
821 bool SVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& io )
823 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
824 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
825 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
826 if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
827 if(SVTK_View* aView = aViewWnd->getView())
828 if(!aView->isVisible( io ))
835 \Collect objects visible in viewer
836 \param theList - visible objects collection
838 void SVTK_Viewer::GetVisible( SALOME_ListIO& theList )
840 // here we collect object if it is disaplaed even one view
841 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
842 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
843 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
844 if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
845 if(SVTK_View* aView = aViewWnd->getView())
846 aView->GetVisible( theList );
850 Updates current viewer
852 void SVTK_Viewer::Repaint()
854 // if (theUpdateTrihedron) onAdjustTrihedron();
855 QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
856 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
857 if(TViewWindow* aViewWindow = dynamic_cast<TViewWindow*>(aViews.at(i)))
858 if(SVTK_View* aView = aViewWindow->getView())
863 void SVTK_Viewer::onActorAdded(VTKViewer_Actor* theActor)
865 emit actorAdded((SVTK_ViewWindow*)sender(), theActor);
868 void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor)
870 emit actorRemoved((SVTK_ViewWindow*)sender(), theActor);
873 void SVTK_Viewer::onViewCreated( SUIT_ViewWindow* view) {
874 #ifdef VGL_WORKAROUND
875 if ( SVTK_ViewWindow* svw = dynamic_cast<SVTK_ViewWindow*>( view ) )
876 QTimer::singleShot(500, [svw] () { svw->Repaint(); } );