1 // Copyright (C) 2007-2008 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.
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
22 #include "SVTK_NonIsometricDlg.h"
23 #include "SVTK_UpdateRateDlg.h"
24 #include "SVTK_CubeAxesDlg.h"
25 #include "SVTK_SetRotationPointDlg.h"
26 #include "SVTK_ViewParameterDlg.h"
28 #include "SALOME_Actor.h"
32 #include <QXmlStreamWriter>
33 #include <QXmlStreamReader>
34 #include <QXmlStreamAttributes>
36 #include <vtkTextProperty.h>
37 #include <vtkActorCollection.h>
38 #include <vtkRenderWindow.h>
39 #include <vtkRenderer.h>
40 #include <vtkCamera.h>
41 #include <vtkPointPicker.h>
42 #include <vtkCellPicker.h>
43 #include <vtkAxisActor2D.h>
44 #include <vtkGL2PSExporter.h>
45 #include <vtkInteractorStyle.h>
47 #include "QtxAction.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_MessageBox.h"
51 #include "SUIT_Accel.h"
52 #include "SUIT_Tools.h"
53 #include "SUIT_ResourceMgr.h"
54 #include "SUIT_Accel.h"
55 #include "SUIT_OverrideCursor.h"
56 #include "QtxActionToolMgr.h"
57 #include "QtxMultiAction.h"
59 #include "VTKViewer_Utilities.h"
60 #include "VTKViewer_Trihedron.h"
62 #include "SVTK_View.h"
63 //#include "SVTK_MainWindow.h"
64 #include "SVTK_Selector.h"
66 #include "SVTK_Event.h"
67 #include "SVTK_Renderer.h"
68 #include "SVTK_ViewWindow.h"
69 #include "SVTK_ViewModelBase.h"
70 #include "SVTK_InteractorStyle.h"
71 #include "SVTK_RenderWindowInteractor.h"
72 #include "SVTK_GenericRenderWindowInteractor.h"
73 #include "SVTK_CubeAxesActor2D.h"
74 #include "SVTK_ComboAction.h"
75 #include "SVTK_KeyFreeInteractorStyle.h"
76 #include "SVTK_Selector.h"
77 #include "SVTK_Recorder.h"
78 #include "SVTK_RecorderDlg.h"
80 #include "SALOME_ListIteratorOfListIO.hxx"
82 #include "VTKViewer_Algorithm.h"
83 #include "SVTK_Functor.h"
88 int convertAction( const int accelAction )
90 switch ( accelAction ) {
91 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
92 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
93 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
94 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
95 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
96 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
97 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
98 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
99 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
100 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
113 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
114 SUIT_ViewWindow(theDesktop),
116 myDumpImage(QImage()),
117 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New())
119 setWindowFlags( windowFlags() & ~Qt::Window );
120 // specific of vtkSmartPointer
121 myKeyFreeInteractorStyle->Delete();
125 To initialize #SVTK_ViewWindow instance
127 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
129 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
131 SVTK_Selector* aSelector = SVTK_Selector::New();
133 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
134 aDevice->SetRenderWidget(myInteractor);
135 aDevice->SetSelector(aSelector);
137 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
138 aRenderer->Initialize(aDevice,aSelector);
140 myInteractor->Initialize(aDevice,aRenderer,aSelector);
146 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), -1, this );
147 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), -1, this );
149 createActions( SUIT_Session::session()->activeApplication()->resourceMgr() );
152 SetEventDispatcher(myInteractor->GetDevice());
153 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
154 myInteractor->setFocusPolicy(Qt::StrongFocus);
155 myInteractor->setFocus();
156 setFocusProxy(myInteractor);
158 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
159 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
160 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
161 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
162 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
163 myViewParameterDlg = new SVTK_ViewParameterDlg
164 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
166 SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
167 myInteractor->PushInteractorStyle(aStyle);
170 myRecorder = SVTK_Recorder::New();
172 myRecorder->SetNbFPS( 17.3 );
173 myRecorder->SetQuality( 100 );
174 myRecorder->SetProgressiveMode( true );
175 myRecorder->SetUseSkippedFrames( true );
176 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
178 setCentralWidget(myInteractor);
180 myView = new SVTK_View(this);
181 Initialize(myView,theModel);
183 myInteractor->getRenderWindow()->Render();
188 To initialize #SVTK_ViewWindow instance
190 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
191 SVTK_ViewModelBase* theModel)
193 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
194 this,SLOT(onKeyPressed(QKeyEvent*)) );
195 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
196 this,SLOT(onKeyReleased(QKeyEvent*)));
197 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
198 this,SLOT(onMousePressed(QMouseEvent*)));
199 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
200 this,SLOT(onMouseReleased(QMouseEvent*)));
201 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
202 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
203 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
204 this,SLOT(onMouseMoving(QMouseEvent*)));
205 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
206 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
207 connect(theView,SIGNAL(selectionChanged()),
208 theModel,SLOT(onSelectionChanged()));
214 SVTK_ViewWindow::~SVTK_ViewWindow()
219 \return corresponding view
221 SVTK_View* SVTK_ViewWindow::getView()
227 \return corresponding vtk render window
229 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
231 return GetInteractor()->getRenderWindow();
235 \return corresponding vtk render window interactor
237 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
243 \return corresponding vtk render window interactor
245 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
247 return myInteractor->GetDevice();
251 \return corresponding vtk renderer
253 vtkRenderer* SVTK_ViewWindow::getRenderer() const
255 return GetInteractor()->getRenderer();
259 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
261 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
263 return GetInteractor()->GetRenderer();
267 \return corresponding vtk selector
269 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
271 return GetInteractor()->GetSelector();
275 Processes transformation "front view"
277 void SVTK_ViewWindow::onFrontView()
279 GetRenderer()->OnFrontView();
284 Processes transformation "back view"
286 void SVTK_ViewWindow::onBackView()
288 GetRenderer()->OnBackView();
293 Processes transformation "top view"
295 void SVTK_ViewWindow::onTopView()
297 GetRenderer()->OnTopView();
302 Processes transformation "bottom view"
304 void SVTK_ViewWindow::onBottomView()
306 GetRenderer()->OnBottomView();
311 Processes transformation "left view"
313 void SVTK_ViewWindow::onLeftView()
315 GetRenderer()->OnLeftView();
320 Processes transformation "right view"
322 void SVTK_ViewWindow::onRightView()
324 GetRenderer()->OnRightView();
329 Processes transformation "reset view": sets default orientation of viewport camera
331 void SVTK_ViewWindow::onResetView()
333 GetRenderer()->OnResetView();
338 Processes transformation "fit all"
340 void SVTK_ViewWindow::onFitAll()
342 GetRenderer()->OnFitAll();
347 SLOT: called if selection is changed
349 void SVTK_ViewWindow::onSelectionChanged()
351 myView->onSelectionChanged();
355 Change selection mode
356 \param theMode - new selection mode
358 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
360 GetSelector()->SetSelectionMode(theMode);
364 \return selection mode
366 Selection_Mode SVTK_ViewWindow::SelectionMode() const
368 return GetSelector()->SelectionMode();
372 Unhilights all objects in viewer
374 void SVTK_ViewWindow::unHighlightAll()
376 myView->unHighlightAll();
380 Hilights/unhilights object in viewer
381 \param theIO - object to be updated
382 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
383 \param theIsUpdate - update current viewer
385 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
389 myView->highlight( theIO, theIsHighlight, theIsUpdate );
393 \return true if object is in viewer or in collector
394 \param theIO - object to be checked
396 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
398 return myView->isInViewer( theIO );
402 \return true if object is displayed in viewer
403 \param theIO - object to be checked
405 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
407 return myView->isVisible( theIO );
412 \param theEntry - entry that corresponds to intractive objects
414 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
416 return myView->FindIObject(theEntry);
421 \param theIO - object
422 \param theImmediatly - update viewer
424 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
427 myView->Display(theIO,theImmediatly);
432 \param theIO - object
433 \param theImmediatly - update viewer
435 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
438 myView->Erase(theIO,theImmediatly);
442 Display only passed object
443 \param theIO - object
445 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
447 myView->DisplayOnly(theIO);
451 Display all objects in view
453 void SVTK_ViewWindow::DisplayAll()
455 myView->DisplayAll();
459 Erase all objects in view
461 void SVTK_ViewWindow::EraseAll()
467 Sets background color
468 \param color - new background color
470 void SVTK_ViewWindow::setBackgroundColor( const QColor& theColor )
472 getRenderer()->SetBackground(theColor.red()/255.0,
473 theColor.green()/255.0,
474 theColor.blue()/255.0);
478 \return background color of viewer
480 QColor SVTK_ViewWindow::backgroundColor() const
482 vtkFloatingPointType aBackgroundColor[3];
483 getRenderer()->GetBackground(aBackgroundColor);
484 return QColor(int(aBackgroundColor[0]*255),
485 int(aBackgroundColor[1]*255),
486 int(aBackgroundColor[2]*255));
491 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
493 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
495 return GetInteractor()->GetInteractorStyle();
499 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
501 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
503 GetInteractor()->PushInteractorStyle(theStyle);
507 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
509 void SVTK_ViewWindow::PopInteractorStyle()
511 GetInteractor()->PopInteractorStyle();
515 Updates current viewer
517 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
519 if(theUpdateTrihedron)
520 GetRenderer()->OnAdjustTrihedron();
522 GetInteractor()->update();
524 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
530 Redirect the request to #SVTK_Renderer::GetScale
532 void SVTK_ViewWindow::GetScale( double theScale[3] )
534 GetRenderer()->GetScale( theScale );
538 Redirect the request to #SVTK_Renderer::SetScale
540 void SVTK_ViewWindow::SetScale( double theScale[3] )
542 GetRenderer()->SetScale( theScale );
547 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
549 bool SVTK_ViewWindow::isTrihedronDisplayed()
551 return GetRenderer()->IsTrihedronDisplayed();
555 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
557 bool SVTK_ViewWindow::isCubeAxesDisplayed()
559 return GetRenderer()->IsCubeAxesDisplayed();
563 Redirect the request to #SVTK_Renderer::OnViewTrihedron
565 void SVTK_ViewWindow::onViewTrihedron()
567 GetRenderer()->OnViewTrihedron();
572 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
574 void SVTK_ViewWindow::onViewCubeAxes()
576 GetRenderer()->OnViewCubeAxes();
581 Redirect the request to #SVTK_Renderer::GetTrihedron
583 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
585 return GetRenderer()->GetTrihedron();
589 Redirect the request to #SVTK_Renderer::GetCubeAxes
591 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
593 return GetRenderer()->GetCubeAxes();
597 \return trihedron size
599 vtkFloatingPointType SVTK_ViewWindow::GetTrihedronSize() const
601 return GetRenderer()->GetTrihedronSize();
606 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
608 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
610 activateProjectionMode( theMode );
615 Set the gravity center as a focal point
617 void SVTK_ViewWindow::activateSetFocalPointGravity()
619 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
623 Set the selected point as a focal point
625 void SVTK_ViewWindow::activateSetFocalPointSelected()
627 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
631 Set the point selected by user as a focal point
633 void SVTK_ViewWindow::activateStartFocalPointSelection()
635 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
638 void SVTK_ViewWindow::activateProjectionMode(int theMode)
641 toolMgr()->action( ProjectionModeId )->setChecked( true );
643 toolMgr()->action( ParallelModeId )->setChecked( true );
647 Sets actual interaction style
648 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
650 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
652 onSwitchInteractionStyle( theStyle==1 );
656 Switches "keyboard free" interaction style on/off
658 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
661 // check if style is already set
662 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
664 // keep the same style extensions
665 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
667 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
668 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
671 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
675 // pop only key free style
676 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
677 PopInteractorStyle();
680 // update action state if method is called outside
681 QtxAction* a = getAction( SwitchInteractionStyleId );
682 if ( a->isChecked() != theOn ) a->setChecked( theOn );
686 Sets incremental speed
687 \param theValue - new incremental speed
688 \param theMode - modification mode
690 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
692 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
693 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
697 Sets spacemouse buttons for the functions
698 \param theBtn1 - spacemouse button for the "decrease speed increment"
699 \param theBtn2 - spacemouse button for the "increase speed increment"
700 \param theBtn3 - spacemouse button for the "dominant combined switch"
702 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
707 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
709 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
711 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
716 \param theSize - new trihedron size
717 \param theRelative - trihedron relativeness
719 void SVTK_ViewWindow::SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative)
721 GetRenderer()->SetTrihedronSize(theSize, theRelative);
725 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
726 * trihedron and cube axes, even if trihedron and cube axes is invisible.
728 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
730 GetRenderer()->AdjustActors();
735 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
737 void SVTK_ViewWindow::onAdjustTrihedron()
739 GetRenderer()->OnAdjustTrihedron();
743 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
745 void SVTK_ViewWindow::onAdjustCubeAxes()
747 GetRenderer()->OnAdjustCubeAxes();
753 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
755 emit keyPressed( this, event );
761 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
763 emit keyReleased( this, event );
769 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
771 emit mousePressed(this, event);
777 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
779 emit mouseReleased( this, event );
785 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
787 emit mouseMoving( this, event );
791 Emits mouse double clicked
793 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
795 emit mouseDoubleClicked( this, event );
799 Redirect the request to #SVTK_Renderer::AddActor
801 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
804 GetRenderer()->AddActor(theActor);
807 emit actorAdded(theActor);
811 Redirect the request to #SVTK_Renderer::RemoveActor
813 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
816 GetRenderer()->RemoveActor(theActor);
819 emit actorRemoved(theActor);
822 QImage SVTK_ViewWindow::dumpViewContent()
824 vtkRenderWindow* aWindow = getRenderWindow();
825 int* aSize = aWindow->GetSize();
826 int aWidth = aSize[0];
827 int aHeight = aSize[1];
829 unsigned char *aData =
830 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
832 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
834 anImage = anImage.rgbSwapped();
835 anImage = anImage.mirrored();
840 \return QImage, containing all scene rendering in window
842 QImage SVTK_ViewWindow::dumpView()
844 if( myDumpImage.isNull() )
845 return dumpViewContent();
850 QString SVTK_ViewWindow::filter() const
852 return tr( "SVTK_IMAGE_FILES" );
855 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
857 if ( format != "PS" && format != "EPS" && format != "PDF" )
858 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
860 SUIT_OverrideCursor wc;
862 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
863 anExporter->SetRenderWindow(getRenderWindow());
865 if ( format == "PS" ) {
866 anExporter->SetFileFormatToPS();
867 anExporter->CompressOff();
870 if ( format == "EPS" ) {
871 anExporter->SetFileFormatToEPS();
872 anExporter->CompressOff();
875 if ( format == "PDF" ) {
876 anExporter->SetFileFormatToPDF();
879 QString aFilePrefix(fileName);
880 QString anExtension(SUIT_Tools::extension(fileName));
881 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
882 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
884 anExporter->Delete();
890 \refresh QImage, containing all scene rendering in window
892 void SVTK_ViewWindow::RefreshDumpImage()
894 myDumpImage = dumpViewContent();
898 Redirect the request to #SVTK_Renderer::SetSelectionProp
900 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
901 const double& theGreen,
902 const double& theBlue,
905 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
909 Redirect the request to #SVTK_Renderer::SetSelectionProp
911 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
912 const double& theGreen,
913 const double& theBlue,
916 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
920 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
922 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
923 const double& theTolItems,
924 const double& theTolObjects)
926 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
931 \param accelAction - action
933 bool SVTK_ViewWindow::action( const int accelAction )
935 if ( accelAction == SUIT_Accel::ZoomFit )
938 int anEvent = SVTK::convertAction( accelAction );
939 GetInteractor()->InvokeEvent(anEvent, 0);
945 \return action by it's id
947 QtxAction* SVTK_ViewWindow::getAction( int id ) const
949 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
953 // old visual parameters had 13 values. New format added additional
954 // 76 values for graduated axes, so both numbers are processed.
955 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
956 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
957 const int nTrihedronParams = 3; // number of parameters for Trihedron
958 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
960 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
962 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
969 bool isVisible = actor->GetTitleVisibility();
970 QString title ( actor->GetTitle() );
971 vtkFloatingPointType color[ 3 ];
972 int font = VTK_ARIAL;
977 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
980 txtProp->GetColor( color );
981 font = txtProp->GetFontFamily();
982 bold = txtProp->GetBold();
983 italic = txtProp->GetItalic();
984 shadow = txtProp->GetShadow();
986 writer.writeStartElement("GraduatedAxis");
987 writer.writeAttribute("Axis", theAxis);
989 writer.writeStartElement("Title");
990 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
991 writer.writeAttribute("Text", title);
992 writer.writeAttribute("Font", QString("%1").arg(font));
993 writer.writeAttribute("Bold", QString("%1").arg(bold));
994 writer.writeAttribute("Italic", QString("%1").arg(italic));
995 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
997 writer.writeStartElement("Color");
998 writer.writeAttribute("R", QString("%1").arg(color[0]));
999 writer.writeAttribute("G", QString("%1").arg(color[1]));
1000 writer.writeAttribute("B", QString("%1").arg(color[2]));
1001 writer.writeEndElement();
1002 writer.writeEndElement();
1004 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1005 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1008 isVisible = actor->GetLabelVisibility();
1009 int labels = actor->GetNumberOfLabels();
1010 int offset = actor->GetTickOffset();
1016 txtProp = actor->GetLabelTextProperty();
1019 txtProp->GetColor( color );
1020 font = txtProp->GetFontFamily();
1021 bold = txtProp->GetBold();
1022 italic = txtProp->GetItalic();
1023 shadow = txtProp->GetShadow();
1026 writer.writeStartElement("Labels");
1027 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1028 writer.writeAttribute("Number", QString("%1").arg(labels));
1029 writer.writeAttribute("Offset", QString("%1").arg(offset));
1030 writer.writeAttribute("Font", QString("%1").arg(font));
1031 writer.writeAttribute("Bold", QString("%1").arg(bold));
1032 writer.writeAttribute("Italic", QString("%1").arg(italic));
1033 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1035 writer.writeStartElement("Color");
1036 writer.writeAttribute("R", QString("%1").arg(color[0]));
1037 writer.writeAttribute("G", QString("%1").arg(color[1]));
1038 writer.writeAttribute("B", QString("%1").arg(color[2]));
1039 writer.writeEndElement();
1040 writer.writeEndElement();
1041 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1042 // color[0], color[1], color[2], font, bold, italic, shadow );
1045 isVisible = actor->GetTickVisibility();
1046 int length = actor->GetTickLength();
1047 writer.writeStartElement("TickMarks");
1048 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1049 writer.writeAttribute("Length", QString("%1").arg(length));
1050 writer.writeEndElement();
1052 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1054 writer.writeEndElement();
1058 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1065 } while (!reader.isStartElement());
1067 // Read title params
1068 QXmlStreamAttributes aAttr = reader.attributes();
1069 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1070 QString title = aAttr.value("Text").toString();
1071 int font = aAttr.value("Font").toString().toInt();
1072 int bold = aAttr.value("Bold").toString().toInt();
1073 int italic = aAttr.value("Italic").toString().toInt();
1074 int shadow = aAttr.value("Shadow").toString().toInt();
1076 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1080 } while (!reader.isStartElement());
1083 aAttr = reader.attributes();
1085 vtkFloatingPointType color[3];
1086 color[0] = aAttr.value("R").toString().toDouble();
1087 color[1] = aAttr.value("G").toString().toDouble();
1088 color[2] = aAttr.value("B").toString().toDouble();
1089 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1091 actor->SetTitleVisibility( isVisible );
1092 actor->SetTitle( title.toLatin1() );
1093 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1095 txtProp->SetColor( color );
1096 txtProp->SetFontFamily( font );
1097 txtProp->SetBold( bold );
1098 txtProp->SetItalic( italic );
1099 txtProp->SetShadow( shadow );
1106 } while (!reader.isStartElement());
1108 aAttr = reader.attributes();
1109 isVisible = aAttr.value("isVisible").toString().toUShort();
1110 int labels = aAttr.value("Number").toString().toInt();
1111 int offset = aAttr.value("Offset").toString().toInt();
1112 font = aAttr.value("Font").toString().toInt();
1113 bold = aAttr.value("Bold").toString().toInt();
1114 italic = aAttr.value("Italic").toString().toInt();
1115 shadow = aAttr.value("Shadow").toString().toInt();
1119 } while (!reader.isStartElement());
1121 aAttr = reader.attributes();
1123 color[0] = aAttr.value("R").toString().toDouble();
1124 color[1] = aAttr.value("G").toString().toDouble();
1125 color[2] = aAttr.value("B").toString().toDouble();
1127 actor->SetLabelVisibility( isVisible );
1128 actor->SetNumberOfLabels( labels );
1129 actor->SetTickOffset( offset );
1130 txtProp = actor->GetLabelTextProperty();
1132 txtProp->SetColor( color );
1133 txtProp->SetFontFamily( font );
1134 txtProp->SetBold( bold );
1135 txtProp->SetItalic( italic );
1136 txtProp->SetShadow( shadow );
1142 } while (!reader.isStartElement());
1143 aAttr = reader.attributes();
1145 // retrieve and set tick marks properties
1146 isVisible = aAttr.value("isVisible").toString().toUShort();
1147 int length = aAttr.value("Length").toString().toInt();
1149 actor->SetTickVisibility( isVisible );
1150 actor->SetTickLength( length );
1153 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1155 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1160 QStringList paramsLst = params.split( '*' );
1162 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1164 // retrieve and set name parameters
1165 bool isVisible = paramsLst[2].toUShort();
1166 QString title = paramsLst[3];
1167 vtkFloatingPointType color[3];
1168 color[0] = paramsLst[4].toDouble();
1169 color[1] = paramsLst[5].toDouble();
1170 color[2] = paramsLst[6].toDouble();
1171 int font = paramsLst[7].toInt();
1172 int bold = paramsLst[8].toInt();
1173 int italic = paramsLst[9].toInt();
1174 int shadow = paramsLst[10].toInt();
1176 actor->SetTitleVisibility( isVisible );
1177 actor->SetTitle( title.toLatin1() );
1178 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1180 txtProp->SetColor( color );
1181 txtProp->SetFontFamily( font );
1182 txtProp->SetBold( bold );
1183 txtProp->SetItalic( italic );
1184 txtProp->SetShadow( shadow );
1187 // retrieve and set lable parameters
1188 isVisible = paramsLst[12].toUShort();
1189 int labels = paramsLst[13].toInt();
1190 int offset = paramsLst[14].toInt();
1191 color[0] = paramsLst[15].toDouble();
1192 color[1] = paramsLst[16].toDouble();
1193 color[2] = paramsLst[17].toDouble();
1194 font = paramsLst[18].toInt();
1195 bold = paramsLst[19].toInt();
1196 italic = paramsLst[20].toInt();
1197 shadow = paramsLst[21].toInt();
1199 actor->SetLabelVisibility( isVisible );
1200 actor->SetNumberOfLabels( labels );
1201 actor->SetTickOffset( offset );
1202 txtProp = actor->GetLabelTextProperty();
1204 txtProp->SetColor( color );
1205 txtProp->SetFontFamily( font );
1206 txtProp->SetBold( bold );
1207 txtProp->SetItalic( italic );
1208 txtProp->SetShadow( shadow );
1211 // retrieve and set tick marks properties
1212 isVisible = paramsLst[23].toUShort();
1213 int length = paramsLst[24].toInt();
1215 actor->SetTickVisibility( isVisible );
1216 actor->SetTickLength( length );
1220 /*! The method returns the visual parameters of this view as a formated string
1222 QString SVTK_ViewWindow::getVisualParameters()
1224 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1226 // save position, focal point, viewUp, scale
1227 vtkCamera* camera = getRenderer()->GetActiveCamera();
1228 camera->GetPosition( pos );
1229 camera->GetFocalPoint( focalPnt );
1230 camera->GetViewUp( viewUp );
1231 parScale = camera->GetParallelScale();
1234 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1235 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1236 // Graduated axes parameters (X, Y, Z axes parameters)
1238 QXmlStreamWriter aWriter(&retStr);
1239 aWriter.setAutoFormatting(true);
1241 aWriter.writeStartDocument();
1242 aWriter.writeStartElement("ViewState");
1244 aWriter.writeStartElement("Position");
1245 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1246 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1247 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1248 aWriter.writeEndElement();
1250 aWriter.writeStartElement("FocalPoint");
1251 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1252 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1253 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1254 aWriter.writeEndElement();
1256 aWriter.writeStartElement("ViewUp");
1257 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1258 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1259 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1260 aWriter.writeEndElement();
1262 aWriter.writeStartElement("ViewScale");
1263 aWriter.writeAttribute("Parallel", QString::number(parScale));
1264 aWriter.writeAttribute("X", QString::number(scale[0]));
1265 aWriter.writeAttribute("Y", QString::number(scale[1]));
1266 aWriter.writeAttribute("Z", QString::number(scale[2]));
1267 aWriter.writeEndElement();
1269 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1270 aWriter.writeStartElement("DisplayCubeAxis");
1271 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1272 aWriter.writeEndElement();
1274 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1275 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1276 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1279 aWriter.writeStartElement("Trihedron");
1280 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1281 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1282 aWriter.writeEndElement();
1284 aWriter.writeEndElement();
1285 aWriter.writeEndDocument();
1291 The method restores visual parameters of this view or postpones it untill the view is shown
1293 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1295 //printf("#### %s\n", qPrintable(parameters));
1296 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1297 if ( anInteractor->isVisible() ) {
1298 doSetVisualParameters( parameters );
1301 myVisualParams = parameters;
1302 anInteractor->installEventFilter(this);
1307 The method restores visual parameters of this view from a formated string
1309 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters )
1311 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1313 QXmlStreamReader aReader(parameters);
1314 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1316 while(!aReader.atEnd()) {
1318 if (aReader.isStartElement()) {
1319 QXmlStreamAttributes aAttr = aReader.attributes();
1320 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1321 if (aReader.name() == "Position") {
1322 pos[0] = aAttr.value("X").toString().toDouble();
1323 pos[1] = aAttr.value("Y").toString().toDouble();
1324 pos[2] = aAttr.value("Z").toString().toDouble();
1325 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1326 } else if (aReader.name() == "FocalPoint") {
1327 focalPnt[0] = aAttr.value("X").toString().toDouble();
1328 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1329 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1330 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1331 } else if (aReader.name() == "ViewUp") {
1332 viewUp[0] = aAttr.value("X").toString().toDouble();
1333 viewUp[1] = aAttr.value("Y").toString().toDouble();
1334 viewUp[2] = aAttr.value("Z").toString().toDouble();
1335 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1336 } else if (aReader.name() == "ViewScale") {
1337 parScale = aAttr.value("Parallel").toString().toDouble();
1338 scale[0] = aAttr.value("X").toString().toDouble();
1339 scale[1] = aAttr.value("Y").toString().toDouble();
1340 scale[2] = aAttr.value("Z").toString().toDouble();
1341 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1342 } else if (aReader.name() == "DisplayCubeAxis") {
1343 if (aAttr.value("Show") == "0")
1344 gradAxesActor->VisibilityOff();
1346 gradAxesActor->VisibilityOn();
1347 } else if (aReader.name() == "GraduatedAxis") {
1348 if(aAttr.value("Axis") == "X")
1349 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1350 else if(aAttr.value("Axis") == "Y")
1351 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1352 else if(aAttr.value("Axis") == "Z")
1353 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1354 } else if (aReader.name() == "Trihedron") {
1355 if (aAttr.value("isShown") == "0")
1356 GetTrihedron()->VisibilityOff();
1358 GetTrihedron()->VisibilityOn();
1359 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1363 if (!aReader.hasError()) {
1364 vtkCamera* camera = getRenderer()->GetActiveCamera();
1365 camera->SetPosition( pos );
1366 camera->SetFocalPoint( focalPnt );
1367 camera->SetViewUp( viewUp );
1368 camera->SetParallelScale( parScale );
1371 QStringList paramsLst = parameters.split( '*' );
1372 if ( paramsLst.size() >= nNormalParams ) {
1373 // 'reading' list of parameters
1374 pos[0] = paramsLst[0].toDouble();
1375 pos[1] = paramsLst[1].toDouble();
1376 pos[2] = paramsLst[2].toDouble();
1377 focalPnt[0] = paramsLst[3].toDouble();
1378 focalPnt[1] = paramsLst[4].toDouble();
1379 focalPnt[2] = paramsLst[5].toDouble();
1380 viewUp[0] = paramsLst[6].toDouble();
1381 viewUp[1] = paramsLst[7].toDouble();
1382 viewUp[2] = paramsLst[8].toDouble();
1383 parScale = paramsLst[9].toDouble();
1384 scale[0] = paramsLst[10].toDouble();
1385 scale[1] = paramsLst[11].toDouble();
1386 scale[2] = paramsLst[12].toDouble();
1388 // applying parameters
1389 vtkCamera* camera = getRenderer()->GetActiveCamera();
1390 camera->SetPosition( pos );
1391 camera->SetFocalPoint( focalPnt );
1392 camera->SetViewUp( viewUp );
1393 camera->SetParallelScale( parScale );
1396 // apply graduated axes parameters
1397 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1398 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1399 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1400 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1401 i = j + 1; j += nGradAxisParams;
1402 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1403 i = j + 1; j += nGradAxisParams;
1404 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1406 if ( paramsLst[13].toUShort() )
1407 gradAxesActor->VisibilityOn();
1409 gradAxesActor->VisibilityOff();
1410 } else if ( paramsLst.size() == nAllParams ) {
1411 if ( paramsLst[90].toUShort() )
1412 GetTrihedron()->VisibilityOn();
1414 GetTrihedron()->VisibilityOff();
1416 SetTrihedronSize(paramsLst[91].toDouble());
1424 Delayed setVisualParameters
1426 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1428 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1429 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1430 if ( anInteractor->isVisible() ) {
1431 doSetVisualParameters( myVisualParams );
1432 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1435 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1440 Change rotation point
1442 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1445 mySetRotationPointDlg->addObserver();
1446 if ( mySetRotationPointDlg->IsFirstShown() )
1447 activateSetRotationGravity();
1448 mySetRotationPointDlg->show();
1450 mySetRotationPointDlg->hide();
1454 Set the gravity center as a rotation point
1456 void SVTK_ViewWindow::activateSetRotationGravity()
1458 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1462 Set the selected point as a rotation point
1464 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1466 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1470 Set the point selected by user as a rotation point
1472 void SVTK_ViewWindow::activateStartPointSelection()
1474 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1478 Set the view projection mode: orthogonal or perspective
1480 void SVTK_ViewWindow::onPerspectiveMode()
1482 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1483 aCamera->SetParallelProjection(toolMgr()->action( ParallelModeId )->isChecked());
1484 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1487 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1489 myEventDispatcher = theDispatcher;
1493 Creates all actions of svtk main window
1495 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1497 QtxAction* anAction;
1498 QtxActionToolMgr* mgr = toolMgr();
1501 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1502 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1503 tr( "MNU_DUMP_VIEW" ), 0, this);
1504 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1505 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1506 mgr->registerAction( anAction, DumpId );
1509 anAction = new QtxAction(tr("MNU_FITALL"),
1510 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1511 tr( "MNU_FITALL" ), 0, this);
1512 anAction->setStatusTip(tr("DSC_FITALL"));
1513 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1514 mgr->registerAction( anAction, FitAllId );
1517 anAction = new QtxAction(tr("MNU_FITRECT"),
1518 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1519 tr( "MNU_FITRECT" ), 0, this);
1520 anAction->setStatusTip(tr("DSC_FITRECT"));
1521 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1522 mgr->registerAction( anAction, FitRectId );
1525 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1526 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1527 tr( "MNU_ZOOM_VIEW" ), 0, this);
1528 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1529 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1530 mgr->registerAction( anAction, ZoomId );
1533 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1534 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1535 tr( "MNU_PAN_VIEW" ), 0, this);
1536 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1537 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1538 mgr->registerAction( anAction, PanId );
1541 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1542 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1543 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1544 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1545 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1546 mgr->registerAction( anAction, GlobalPanId );
1548 // Change rotation point
1549 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1550 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1551 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1552 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1553 anAction->setCheckable(true);
1554 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1555 mgr->registerAction( anAction, ChangeRotationPointId );
1558 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1559 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1560 tr( "MNU_ROTATE_VIEW" ), 0, this);
1561 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1562 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1563 mgr->registerAction( anAction, RotationId );
1566 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1567 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1568 tr( "MNU_FRONT_VIEW" ), 0, this);
1569 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1570 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1571 mgr->registerAction( anAction, FrontId );
1573 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
1574 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1575 tr( "MNU_BACK_VIEW" ), 0, this);
1576 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1577 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1578 mgr->registerAction( anAction, BackId );
1580 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
1581 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1582 tr( "MNU_TOP_VIEW" ), 0, this);
1583 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1584 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
1585 mgr->registerAction( anAction, TopId );
1587 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
1588 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
1589 tr( "MNU_BOTTOM_VIEW" ), 0, this);
1590 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1591 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
1592 mgr->registerAction( anAction, BottomId );
1594 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
1595 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
1596 tr( "MNU_LEFT_VIEW" ), 0, this);
1597 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1598 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
1599 mgr->registerAction( anAction, LeftId );
1601 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
1602 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
1603 tr( "MNU_RIGHT_VIEW" ), 0, this);
1604 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1605 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
1606 mgr->registerAction( anAction, RightId );
1609 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
1610 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
1611 tr( "MNU_RESET_VIEW" ), 0, this);
1612 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
1613 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
1614 mgr->registerAction( anAction, ResetId );
1616 // onViewTrihedron: Shows - Hides Trihedron
1617 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
1618 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
1619 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
1620 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
1621 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
1622 mgr->registerAction( anAction, ViewTrihedronId );
1624 // onNonIsometric: Manage non-isometric params
1625 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
1626 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
1627 tr( "MNU_SVTK_SCALING" ), 0, this);
1628 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
1629 anAction->setCheckable(true);
1630 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
1631 mgr->registerAction( anAction, NonIsometric );
1633 // onGraduatedAxes: Manage graduated axes params
1634 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
1635 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
1636 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
1637 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
1638 anAction->setCheckable(true);
1639 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
1640 mgr->registerAction( anAction, GraduatedAxes );
1642 // onGraduatedAxes: Manage graduated axes params
1643 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
1644 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
1645 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
1646 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
1647 anAction->setCheckable(true);
1648 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
1649 mgr->registerAction( anAction, UpdateRate );
1651 // Set perspective mode group
1652 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
1653 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
1654 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
1655 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
1656 anAction->setCheckable(true);
1657 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
1658 mgr->registerAction( anAction, ParallelModeId );
1660 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
1661 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
1662 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
1663 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
1664 anAction->setCheckable(true);
1665 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
1666 mgr->registerAction( anAction, ProjectionModeId );
1668 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
1669 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
1670 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
1673 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
1674 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
1675 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
1676 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
1677 anAction->setCheckable(true);
1678 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
1679 mgr->registerAction( anAction, ViewParametersId );
1681 // Switch between interaction styles
1682 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
1683 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
1684 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
1685 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
1686 anAction->setCheckable(true);
1687 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1688 mgr->registerAction( anAction, SwitchInteractionStyleId );
1691 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
1692 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
1693 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
1694 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
1695 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
1696 mgr->registerAction( myStartAction, StartRecordingId );
1699 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
1700 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
1701 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
1702 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
1703 myPlayAction->setEnabled( false );
1704 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
1705 mgr->registerAction( myPlayAction, PlayRecordingId );
1708 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
1709 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
1710 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
1711 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
1712 myPauseAction->setEnabled( false );
1713 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
1714 mgr->registerAction( myPauseAction, PauseRecordingId );
1717 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
1718 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
1719 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
1720 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
1721 myStopAction->setEnabled( false );
1722 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
1723 mgr->registerAction( myStopAction, StopRecordingId );
1727 Creates toolbar of svtk main window
1729 void SVTK_ViewWindow::createToolBar()
1731 QtxActionToolMgr* mgr = toolMgr();
1733 mgr->append( DumpId, myToolBar );
1734 mgr->append( SwitchInteractionStyleId, myToolBar );
1735 mgr->append( ViewTrihedronId, myToolBar );
1737 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1738 aScaleAction->insertAction( getAction( FitAllId ) );
1739 aScaleAction->insertAction( getAction( FitRectId ) );
1740 aScaleAction->insertAction( getAction( ZoomId ) );
1741 mgr->append( aScaleAction, myToolBar );
1743 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1744 aPanningAction->insertAction( getAction( PanId ) );
1745 aPanningAction->insertAction( getAction( GlobalPanId ) );
1746 mgr->append( aPanningAction, myToolBar );
1748 mgr->append( ChangeRotationPointId, myToolBar );
1750 mgr->append( RotationId, myToolBar );
1752 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1753 aViewsAction->insertAction( getAction( FrontId ) );
1754 aViewsAction->insertAction( getAction( BackId ) );
1755 aViewsAction->insertAction( getAction( TopId ) );
1756 aViewsAction->insertAction( getAction( BottomId ) );
1757 aViewsAction->insertAction( getAction( LeftId ) );
1758 aViewsAction->insertAction( getAction( RightId ) );
1759 mgr->append( aViewsAction, myToolBar );
1761 mgr->append( ResetId, myToolBar );
1763 mgr->append( UpdateRate, myToolBar );
1764 mgr->append( NonIsometric, myToolBar );
1765 mgr->append( GraduatedAxes, myToolBar );
1767 mgr->append( ViewParametersId, myToolBar );
1768 mgr->append( toolMgr()->separator(), myToolBar );
1769 mgr->append( ParallelModeId, myToolBar );
1770 mgr->append( ProjectionModeId, myToolBar );
1772 mgr->append( StartRecordingId, myRecordingToolBar );
1773 mgr->append( PlayRecordingId, myRecordingToolBar );
1774 mgr->append( PauseRecordingId, myRecordingToolBar );
1775 mgr->append( StopRecordingId, myRecordingToolBar );
1778 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
1781 myUpdateRateDlg->Update();
1782 myUpdateRateDlg->show();
1784 myUpdateRateDlg->hide();
1787 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
1790 myNonIsometricDlg->Update();
1791 myNonIsometricDlg->show();
1793 myNonIsometricDlg->hide();
1796 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
1799 myCubeAxesDlg->Update();
1800 myCubeAxesDlg->show();
1802 myCubeAxesDlg->hide();
1806 Starts rotation transformation
1808 void SVTK_ViewWindow::activateRotation()
1810 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
1815 Starts panning transformation
1817 void SVTK_ViewWindow::activatePanning()
1819 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
1823 Starts zoom transformation
1825 void SVTK_ViewWindow::activateZoom()
1827 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
1831 Starts window fit transformation
1833 void SVTK_ViewWindow::activateWindowFit()
1835 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
1839 Starts global panning transformation
1841 void SVTK_ViewWindow::activateGlobalPanning()
1843 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
1846 void SVTK_ViewWindow::onStartRecording()
1848 myRecorder->CheckExistAVIMaker();
1849 if (myRecorder->ErrorStatus()) {
1850 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
1853 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
1855 if( !aRecorderDlg->exec() )
1858 myStartAction->setEnabled( false );
1859 myPlayAction->setEnabled( false );
1860 myPauseAction->setEnabled( true );
1861 myStopAction->setEnabled( true );
1863 // to prevent resizing the window while recording
1864 myPreRecordingMinSize = minimumSize();
1865 myPreRecordingMaxSize = maximumSize();
1866 setFixedSize( size() );
1868 myRecorder->Record();
1872 void SVTK_ViewWindow::onPlayRecording()
1874 myStartAction->setEnabled( false );
1875 myPlayAction->setEnabled( false );
1876 myPauseAction->setEnabled( true );
1877 myStopAction->setEnabled( true );
1879 myRecorder->Pause();
1882 void SVTK_ViewWindow::onPauseRecording()
1884 myStartAction->setEnabled( false );
1885 myPlayAction->setEnabled( true );
1886 myPauseAction->setEnabled( false );
1887 myStopAction->setEnabled( true );
1889 myRecorder->Pause();
1892 void SVTK_ViewWindow::onStopRecording()
1894 myStartAction->setEnabled( true );
1895 myPlayAction->setEnabled( false );
1896 myPauseAction->setEnabled( false );
1897 myStopAction->setEnabled( false );
1901 setMinimumSize( myPreRecordingMinSize );
1902 setMaximumSize( myPreRecordingMaxSize );
1906 To invoke a VTK event on SVTK_RenderWindowInteractor instance
1908 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
1910 GetInteractor()->InvokeEvent(theEvent,theCallData);
1914 Modify view parameters
1916 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
1919 myViewParameterDlg->addObserver();
1920 myViewParameterDlg->show();
1922 myViewParameterDlg->hide();
1926 Custom show event handler
1928 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
1930 emit Show( theEvent );
1934 Custom hide event handler
1936 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
1938 emit Hide( theEvent );