From: vsv Date: Mon, 29 Sep 2008 14:56:46 +0000 (+0000) Subject: Merge with VISU 2008 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aad4054425ecba334dc1f47668088ca9a8dec4a7;p=modules%2Fgui.git Merge with VISU 2008 --- diff --git a/src/SVTK/Makefile.am b/src/SVTK/Makefile.am index ddfde32f7..62facfcb6 100755 --- a/src/SVTK/Makefile.am +++ b/src/SVTK/Makefile.am @@ -25,87 +25,110 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am lib_LTLIBRARIES = libSVTK.la -salomeinclude_HEADERS = \ - SVTK.h \ - SVTK_Prs.h \ - SVTK_Actor.h \ - SALOME_Actor.h \ - SVTK_RectPicker.h \ - SVTK_DeviceActor.h \ - SVTK_DialogBase.h \ - SVTK_FontWidget.h \ - SVTK_CubeAxesActor2D.h \ - SVTK_Functor.h \ - SVTK_MainWindow.h \ - SVTK_View.h \ - SVTK_ViewManager.h \ - SVTK_ViewModel.h \ - SVTK_ViewWindow.h \ - SVTK_Renderer.h \ - SVTK_InteractorStyle.h \ - SVTK_RenderWindowInteractor.h \ - SVTK_GenericRenderWindowInteractor.h \ - SVTK_Selector.h \ - SVTK_Selection.h \ - SVTK_SelectionEvent.h \ - SVTK_SpaceMouse.h \ - SVTK_Event.h \ - SVTK_ViewModelBase.h \ - SVTK_SetRotationPointDlg.h \ - SVTK_Extension.h +salomeinclude_HEADERS= \ + SVTK.h \ + SVTK_Prs.h \ + SVTK_Actor.h \ + SALOME_Actor.h \ + SVTK_RectPicker.h \ + SVTK_DeviceActor.h \ + SVTK_DialogBase.h \ + SVTK_FontWidget.h \ + SVTK_CubeAxesActor2D.h \ + SVTK_Functor.h \ + SVTK_View.h \ + SVTK_ViewManager.h \ + SVTK_ViewModel.h \ + SVTK_ViewWindow.h \ + SVTK_Renderer.h \ + SVTK_InteractorStyle.h \ + SVTK_KeyFreeInteractorStyle.h \ + SVTK_RenderWindowInteractor.h \ + SVTK_GenericRenderWindowInteractor.h \ + SVTK_Selector.h \ + SVTK_Selection.h \ + SVTK_SelectionEvent.h \ + SVTK_SpaceMouse.h \ + SVTK_Event.h \ + SVTK_ViewModelBase.h \ + SVTK_SetRotationPointDlg.h \ + SVTK_ViewParameterDlg.h \ + SVTK_ComboAction.h \ + SVTK_Extension.h \ + SVTK_Recorder.h \ + SVTK_RecorderDlg.h \ + SVTK_ImageWriter.h \ + SVTK_ImageWriterMgr.h + +dist_libSVTK_la_SOURCES= \ + SVTK_Prs.cxx \ + SVTK_Actor.cxx \ + SALOME_Actor.cxx \ + SVTK_RectPicker.cxx \ + SVTK_DeviceActor.cxx \ + SVTK_CubeAxesActor2D.cxx \ + SVTK_NonIsometricDlg.cxx \ + SVTK_UpdateRateDlg.cxx \ + SVTK_CubeAxesDlg.cxx \ + SVTK_DialogBase.cxx \ + SVTK_FontWidget.cxx \ + SVTK_Trihedron.cxx \ + SVTK_View.cxx \ + SVTK_ViewManager.cxx \ + SVTK_ViewModel.cxx \ + SVTK_Renderer.cxx \ + SVTK_ViewWindow.cxx \ + SVTK_InteractorStyle.cxx \ + SVTK_KeyFreeInteractorStyle.cxx \ + SVTK_RenderWindowInteractor.cxx \ + SVTK_GenericRenderWindowInteractor.cxx \ + SVTK_SpaceMouse.cxx \ + SVTK_Selector.cxx \ + SVTK_SetRotationPointDlg.cxx \ + SVTK_ViewParameterDlg.cxx \ + SVTK_ComboAction.cxx \ + SVTK_Extension.cxx \ + SVTK_Recorder.cxx \ + SVTK_RecorderDlg.cxx \ + SVTK_ImageWriter.cxx \ + SVTK_ImageWriterMgr.cxx -dist_libSVTK_la_SOURCES = \ - SVTK_Prs.cxx \ - SVTK_Actor.cxx \ - SALOME_Actor.cxx \ - SVTK_RectPicker.cxx \ - SVTK_DeviceActor.cxx \ - SVTK_CubeAxesActor2D.cxx \ - SVTK_NonIsometricDlg.cxx \ - SVTK_UpdateRateDlg.cxx \ - SVTK_CubeAxesDlg.cxx \ - SVTK_DialogBase.cxx \ - SVTK_FontWidget.cxx \ - SVTK_Trihedron.cxx \ - SVTK_MainWindow.cxx \ - SVTK_View.cxx \ - SVTK_ViewManager.cxx \ - SVTK_ViewModel.cxx \ - SVTK_Renderer.cxx \ - SVTK_ViewWindow.cxx \ - SVTK_InteractorStyle.cxx \ - SVTK_RenderWindowInteractor.cxx \ - SVTK_GenericRenderWindowInteractor.cxx \ - SVTK_SpaceMouse.cxx \ - SVTK_Selector.cxx \ - SVTK_SetRotationPointDlg.cxx \ - SVTK_Extension.cxx # internal headers EXTRA_DIST += SVTK_SelectorDef.h SVTK_Trihedron.h -MOC_FILES = \ - SVTK_GenericRenderWindowInteractor_moc.cxx \ - SVTK_RenderWindowInteractor_moc.cxx \ - SVTK_NonIsometricDlg_moc.cxx \ - SVTK_UpdateRateDlg_moc.cxx \ - SVTK_CubeAxesDlg_moc.cxx \ - SVTK_FontWidget_moc.cxx \ - SVTK_DialogBase_moc.cxx \ - SVTK_ViewModelBase_moc.cxx \ - SVTK_ViewManager_moc.cxx \ - SVTK_ViewWindow_moc.cxx \ - SVTK_MainWindow_moc.cxx \ - SVTK_ViewModel_moc.cxx \ - SVTK_View_moc.cxx \ - SVTK_SetRotationPointDlg_moc.cxx -nodist_libSVTK_la_SOURCES = $(MOC_FILES) +MOC_FILES= \ + SVTK_GenericRenderWindowInteractor_moc.cxx \ + SVTK_RenderWindowInteractor_moc.cxx \ + SVTK_NonIsometricDlg_moc.cxx \ + SVTK_UpdateRateDlg_moc.cxx \ + SVTK_CubeAxesDlg_moc.cxx \ + SVTK_FontWidget_moc.cxx \ + SVTK_DialogBase_moc.cxx \ + SVTK_ViewModelBase_moc.cxx \ + SVTK_ViewManager_moc.cxx \ + SVTK_ViewWindow_moc.cxx \ + SVTK_ViewModel_moc.cxx \ + SVTK_View_moc.cxx \ + SVTK_SetRotationPointDlg_moc.cxx \ + SVTK_ViewParameterDlg_moc.cxx \ + SVTK_ComboAction_moc.cxx \ + SVTK_RecorderDlg_moc.cxx +nodist_libSVTK_la_SOURCES= $(MOC_FILES) -dist_salomeres_DATA = \ - resources/vtk_view_graduated_axes.png \ - resources/vtk_view_scaling.png \ - resources/vtk_view_update_rate.png \ - resources/vtk_view_rotation_point.png +dist_salomeres_DATA=\ + resources/vtk_view_graduated_axes.png \ + resources/vtk_view_scaling.png \ + resources/vtk_view_update_rate.png \ + resources/vtk_view_rotation_point.png \ + resources/vtk_view_parallel.png \ + resources/vtk_view_perspective.png \ + resources/vtk_view_parameters.png \ + resources/vtk_view_style_switch.png \ + resources/vtk_view_recording_start.png \ + resources/vtk_view_recording_play.png \ + resources/vtk_view_recording_pause.png \ + resources/vtk_view_recording_stop.png nodist_salomeres_DATA = \ SVTK_msg_en.qm \ diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 678d9de95..83305d7e5 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -419,7 +419,7 @@ SALOME_Actor { if ( !GetPickable() ) return false; - + vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); // myPreHighlightActor->SetVisibility( false ); diff --git a/src/SVTK/SVTK.cxx b/src/SVTK/SVTK.cxx index 674714f77..0e3b1af7f 100644 --- a/src/SVTK/SVTK.cxx +++ b/src/SVTK/SVTK.cxx @@ -35,8 +35,7 @@ #include "SVTK_CubeAxesActor2D.h" #include "SVTK_Functor.h" #include "SVTK_View.h" -#include "SVTK_MainWindow.h" -#include "SVTK_MainWindow.h" +//#include "SVTK_MainWindow.h" #include "SVTK_NonIsometricDlg.h" #include "SVTK_CubeAxesDlg.h" #include "SVTK_FontWidget.h" diff --git a/src/SVTK/SVTK.pro b/src/SVTK/SVTK.pro index f1561b744..2713f0d59 100644 --- a/src/SVTK/SVTK.pro +++ b/src/SVTK/SVTK.pro @@ -35,13 +35,13 @@ HEADERS += SVTK_DialogBase.h HEADERS += SVTK_FontWidget.h HEADERS += SVTK_CubeAxesActor2D.h HEADERS += SVTK_Functor.h -HEADERS += SVTK_MainWindow.h HEADERS += SVTK_View.h HEADERS += SVTK_ViewManager.h HEADERS += SVTK_ViewModel.h HEADERS += SVTK_ViewWindow.h HEADERS += SVTK_Renderer.h HEADERS += SVTK_InteractorStyle.h +HEADERS += SVTK_KeyFreeInteractorStyle.h HEADERS += SVTK_RenderWindowInteractor.h HEADERS += SVTK_GenericRenderWindowInteractor.h HEADERS += SVTK_Selector.h @@ -51,6 +51,8 @@ HEADERS += SVTK_SpaceMouse.h HEADERS += SVTK_Event.h HEADERS += SVTK_ViewModelBase.h HEADERS += SVTK_SetRotationPointDlg.h +HEADERS += SVTK_ViewParametersDlg.h +HEADERS += SVTK_ComboAction.h HEADERS += SVTK_Extension.h SOURCES = SVTK_Prs.cxx @@ -65,18 +67,20 @@ SOURCES += SVTK_CubeAxesDlg.cxx SOURCES += SVTK_DialogBase.cxx SOURCES += SVTK_FontWidget.cxx SOURCES += SVTK_Trihedron.cxx -SOURCES += SVTK_MainWindow.cxx SOURCES += SVTK_View.cxx SOURCES += SVTK_ViewManager.cxx SOURCES += SVTK_ViewModel.cxx SOURCES += SVTK_Renderer.cxx SOURCES += SVTK_ViewWindow.cxx SOURCES += SVTK_InteractorStyle.cxx +SOURCES += SVTK_KeyFreeInteractorStyle.cxx SOURCES += SVTK_RenderWindowInteractor.cxx SOURCES += SVTK_GenericRenderWindowInteractor.cxx SOURCES += SVTK_SpaceMouse.cxx SOURCES += SVTK_Selector.cxx SOURCES += SVTK_SetRotationPointDlg.cxx +SOURCES += SVTK_ViewParametersDlg.cxx +SOURCES += SVTK_ComboAction.cxx SOURCES += SVTK_Extension.cxx TRANSLATIONS = resources/SVTK_images.ts \ diff --git a/src/SVTK/SVTK_ComboAction.cxx b/src/SVTK/SVTK_ComboAction.cxx new file mode 100644 index 000000000..95d33c5f6 --- /dev/null +++ b/src/SVTK/SVTK_ComboAction.cxx @@ -0,0 +1,123 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : +// Author : +// Module : SALOME +// $Header: + +#include "SVTK_ComboAction.h" + +#include +#include + +SVTK_ComboAction::SVTK_ComboAction( QObject* parent ) + : QWidgetAction( parent ) +{ + myCurId = -1; +} + +SVTK_ComboAction::SVTK_ComboAction( const QString& text, QObject* parent ) + : QWidgetAction( parent ) +{ + setToolTip( text ); + myCurId = -1; +} + +SVTK_ComboAction::~SVTK_ComboAction() +{ + myIcons.clear(); +} + +void SVTK_ComboAction::insertItem( const QIcon& icon, const int index ) +{ + if ( index < 0 || index > myIcons.size() ) + myIcons.append( icon ); + else + myIcons.insert( index, icon ); + + update(); +} + +void SVTK_ComboAction::clear() +{ + myIcons.clear(); + update(); +} + +void SVTK_ComboAction::setCurrentIndex( const int id ) +{ + if ( myCurId != id ) + { + myCurId = id; + update(); + } +} + +int SVTK_ComboAction::currentIndex() const +{ + return myCurId; +} + +QWidget* SVTK_ComboAction::createWidget( QWidget* parent ) +{ + QWidget* w = 0; + if ( parent->inherits("QToolBar") ) + { + w = new QWidget( parent ); + QHBoxLayout* l = new QHBoxLayout( w ); + l->setSpacing(0); l->setMargin(0); + QComboBox* combo = new QComboBox( w ); + combo->setFocusPolicy( Qt::NoFocus ); + combo->setSizeAdjustPolicy( QComboBox::AdjustToContents ); + l->addSpacing( 3 ); + l->addWidget( combo ); + l->addSpacing( 3 ); + + updateCombo( combo ); + connect( combo, SIGNAL( activated( int ) ), this, SIGNAL( triggered( int ) ) ); + } + return w; +} + +void SVTK_ComboAction::update() +{ + QList aList = createdWidgets(); + for ( QList::const_iterator it = aList.begin(); it != aList.end(); ++it ) + updateCombo( qFindChild(*it) ); +} + +void SVTK_ComboAction::updateCombo( QComboBox* combo ) +{ + if ( !combo ) return; + + combo->clear(); + + for ( QList::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it ) + combo->addItem( *it, "" ); + + if ( combo->count() > 0 ) { + if ( myCurId < 0 ) myCurId = 0; + combo->setCurrentIndex( myCurId ); + } +} diff --git a/src/SVTK/SVTK_ComboAction.h b/src/SVTK/SVTK_ComboAction.h new file mode 100644 index 000000000..823eb1c81 --- /dev/null +++ b/src/SVTK/SVTK_ComboAction.h @@ -0,0 +1,66 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : +// Author : +// Module : SALOME +// $Header: + +#ifndef SVTK_COMBOACTION_H +#define SVTK_COMBOACTION_H + +#include "SVTK.h" + +#include + +class QComboBox; +class SVTK_EXPORT SVTK_ComboAction : public QWidgetAction +{ + Q_OBJECT + +public: + SVTK_ComboAction( QObject* = 0 ); + SVTK_ComboAction( const QString&, QObject* = 0 ); + virtual ~SVTK_ComboAction(); + + void insertItem( const QIcon&, const int = -1 ); + void clear(); + + void setCurrentIndex( const int ); + int currentIndex() const; + +signals: + void triggered( int ); + +protected: + virtual QWidget* createWidget( QWidget* ); + + virtual void update(); + virtual void updateCombo( QComboBox* ); + +private: + QList myIcons; + int myCurId; +}; + +#endif // SVTK_COMBOACTION_H diff --git a/src/SVTK/SVTK_CubeAxesDlg.cxx b/src/SVTK/SVTK_CubeAxesDlg.cxx index 92c3f2847..8126a0a4d 100644 --- a/src/SVTK/SVTK_CubeAxesDlg.cxx +++ b/src/SVTK/SVTK_CubeAxesDlg.cxx @@ -27,7 +27,7 @@ #include "SVTK_CubeAxesDlg.h" -#include "SVTK_MainWindow.h" +#include "SVTK_ViewWindow.h" #include "SVTK_FontWidget.h" #include "SVTK_CubeAxesActor2D.h" @@ -376,7 +376,7 @@ bool SVTK_CubeAxesDlg::AxisWidget::Apply(vtkAxisActor2D* theActor) Constructor */ SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName): SVTK_DialogBase(theAction, theParent, diff --git a/src/SVTK/SVTK_CubeAxesDlg.h b/src/SVTK/SVTK_CubeAxesDlg.h index d4f90568a..05a3dbda7 100644 --- a/src/SVTK/SVTK_CubeAxesDlg.h +++ b/src/SVTK/SVTK_CubeAxesDlg.h @@ -36,7 +36,10 @@ class QCheckBox; class QtxAction; class SVTK_CubeAxesActor2D; -class SVTK_MainWindow; + +class SVTK_FontWidget; +class SVTK_AxisWidget; +class SVTK_ViewWindow; /*! * Class : SVTK_CubeAxesDlg @@ -50,7 +53,7 @@ class SVTK_CubeAxesDlg : public SVTK_DialogBase public: SVTK_CubeAxesDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName); virtual ~SVTK_CubeAxesDlg(); @@ -67,7 +70,7 @@ private: bool isValid() const; private: - SVTK_MainWindow *myMainWindow; + SVTK_ViewWindow *myMainWindow; SVTK_CubeAxesActor2D* myActor; QTabWidget* myTabWg; diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx index a3bb03773..e025131f3 100644 --- a/src/SVTK/SVTK_DeviceActor.cxx +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -36,6 +36,7 @@ // VTK Includes #include #include +#include #include #include @@ -58,6 +59,9 @@ SVTK_DeviceActor myIsShrunk = false; myIsShrinkable = true; + myIsFeatureEdgesAllowed = false; + myIsFeatureEdgesEnabled = false; + myIsShaded = true; myProperty = vtkProperty::New(); myRepresentation = SVTK::Representation::Surface; @@ -70,6 +74,8 @@ SVTK_DeviceActor myShrinkFilter = vtkShrinkFilter::New(); + myFeatureEdges = vtkFeatureEdges::New(); + myGeomFilter = VTKViewer_GeometryFilter::New(); myTransformFilter = VTKViewer_TransformFilter::New(); @@ -94,6 +100,8 @@ SVTK_DeviceActor myShrinkFilter->Delete(); + myFeatureEdges->Delete(); + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) myPassFilter[i]->Delete(); } @@ -192,6 +200,9 @@ SVTK_DeviceActor if(myIsShrunk) mTime = max(mTime,myShrinkFilter->GetMTime()); + if(myIsFeatureEdgesEnabled) + mTime = max(mTime,myFeatureEdges->GetMTime()); + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) max(mTime,myPassFilter[i]->GetMTime()); @@ -300,6 +311,148 @@ SVTK_DeviceActor myShrinkFilter->SetShrinkFactor(theValue); } +/*! + \return true if feature edges are allowed for this actor +*/ +bool +SVTK_DeviceActor +::IsFeatureEdgesAllowed() +{ + return myIsFeatureEdgesAllowed; +} + +/*! + Allows feature edges for this actor on or off + \param theIsFeatureEdgesAllowed - flag which allows feature edges for this actor on or off +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed) +{ + myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed; +} + +/*! + \return true if feature edges are enabled +*/ +bool +SVTK_DeviceActor +::IsFeatureEdgesEnabled() +{ + return myIsFeatureEdgesEnabled; +} + +/*! + Enables feature edges on or off + \param theIsFeatureEdgesEnabled - flag which enables feature edges on or off +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled) +{ + if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled ) + return; + + if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() ) + { + if( theIsFeatureEdgesEnabled ) + { + aPolyData->Update(); + myFeatureEdges->SetInput( aPolyData ); + myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() ); + myIsFeatureEdgesEnabled = true; + } + else + { + myPassFilter[3]->SetInput( aPolyData ); + myIsFeatureEdgesEnabled = false; + } + myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled; + } +} + +/*! + \return angle of feature edges' filter +*/ +vtkFloatingPointType +SVTK_DeviceActor +::GetFeatureEdgesAngle() +{ + return myFeatureEdges->GetFeatureAngle(); +} + +/*! + Sets angle of feature edges' filter + \param theAngle angle of feature edges' filter +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesAngle(vtkFloatingPointType theAngle) +{ + myFeatureEdges->SetFeatureAngle(theAngle); +} + +/*! + Gets information about kinds of edges which are displayed by feature edges' filter + \param theIsFeatureEdges flag which shows whether feature edges are displayed + \param theIsBoundaryEdges flag which shows whether boundary edges are displayed + \param theIsManifoldEdges flag which shows whether manifold edges are displayed + \param theIsNonManifoldEdges flag which shows whether non-manifold edges are displayed +*/ +void +SVTK_DeviceActor +::GetFeatureEdgesFlags(bool& theIsFeatureEdges, + bool& theIsBoundaryEdges, + bool& theIsManifoldEdges, + bool& theIsNonManifoldEdges) +{ + theIsFeatureEdges = myFeatureEdges->GetFeatureEdges(); + theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges(); + theIsManifoldEdges = myFeatureEdges->GetManifoldEdges(); + theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges(); +} + +/*! + Sets different kinds of edges to be displayed by feature edges' filter + \param theIsFeatureEdges flag which displays feature edges + \param theIsBoundaryEdges flag which displays boundary edges + \param theIsManifoldEdges flag which displays manifold edges + \param theIsNonManifoldEdges flag which displays non-manifold edges +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesFlags(bool theIsFeatureEdges, + bool theIsBoundaryEdges, + bool theIsManifoldEdges, + bool theIsNonManifoldEdges) +{ + myFeatureEdges->SetFeatureEdges(theIsFeatureEdges); + myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges); + myFeatureEdges->SetManifoldEdges(theIsManifoldEdges); + myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges); +} + +/*! + \return feature edges' coloring flag +*/ +bool +SVTK_DeviceActor +::GetFeatureEdgesColoring() +{ + return myFeatureEdges->GetColoring(); +} + +/*! + Sets feature edges' coloring flag + \param theIsColoring feature edges' coloring flag +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesColoring(bool theIsColoring) +{ + myFeatureEdges->SetColoring(theIsColoring); +} + /*! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on) param theMode - new mode diff --git a/src/SVTK/SVTK_DeviceActor.h b/src/SVTK/SVTK_DeviceActor.h index 47fc3e12d..0fdd18b9f 100644 --- a/src/SVTK/SVTK_DeviceActor.h +++ b/src/SVTK/SVTK_DeviceActor.h @@ -44,6 +44,7 @@ class VTKViewer_GeometryFilter; class vtkCell; class vtkDataSet; class vtkShrinkFilter; +class vtkFeatureEdges; class vtkDataSetMapper; class vtkPassThroughFilter; @@ -148,6 +149,54 @@ class SVTK_EXPORT SVTK_DeviceActor: public vtkLODActor UnShrink(); //@} + /** @name For feature edges management purpose */ + //@{ + virtual + bool + IsFeatureEdgesAllowed(); + + virtual + void + SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed); + + virtual + bool + IsFeatureEdgesEnabled(); + + virtual + void + SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled); + + virtual + vtkFloatingPointType + GetFeatureEdgesAngle(); + + virtual + void + SetFeatureEdgesAngle(vtkFloatingPointType theAngle); + + virtual + void + GetFeatureEdgesFlags(bool& theIsFeatureEdges, + bool& theIsBoundaryEdges, + bool& theIsManifoldEdges, + bool& theIsNonManifoldEdges); + virtual + void + SetFeatureEdgesFlags(bool theIsFeatureEdges, + bool theIsBoundaryEdges, + bool theIsManifoldEdges, + bool theIsNonManifoldEdges); + + virtual + bool + GetFeatureEdgesColoring(); + + virtual + void + SetFeatureEdgesColoring(bool theIsColoring); + //@} + /** @name For representation mamnagement purpose */ virtual void @@ -190,11 +239,15 @@ class SVTK_EXPORT SVTK_DeviceActor: public vtkLODActor VTKViewer_TransformFilter *myTransformFilter; std::vector myPassFilter; vtkShrinkFilter* myShrinkFilter; + vtkFeatureEdges* myFeatureEdges; vtkDataSetMapper* myMapper; bool myIsShrinkable; bool myIsShrunk; + bool myIsFeatureEdgesAllowed; + bool myIsFeatureEdgesEnabled; + bool myIsResolveCoincidentTopology; vtkFloatingPointType myPolygonOffsetFactor; vtkFloatingPointType myPolygonOffsetUnits; diff --git a/src/SVTK/SVTK_Event.h b/src/SVTK/SVTK_Event.h index 00a9e2c0f..7006785de 100644 --- a/src/SVTK/SVTK_Event.h +++ b/src/SVTK/SVTK_Event.h @@ -62,12 +62,17 @@ namespace SVTK StartFitArea, SetRotateGravity, - StartPointSelection, SetRotateSelected, + StartPointSelection, BBCenterChanged, RotationPointChanged, ChangeRotationPoint, + + SetFocalPointGravity, + SetFocalPointSelected, + StartFocalPointSelection, + FocalPointChanged, LastEvent }; diff --git a/src/SVTK/SVTK_ImageWriter.cxx b/src/SVTK/SVTK_ImageWriter.cxx new file mode 100755 index 000000000..e14e0e528 --- /dev/null +++ b/src/SVTK/SVTK_ImageWriter.cxx @@ -0,0 +1,103 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "SVTK_ImageWriter.h" + +#include + +#include +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//---------------------------------------------------------------------------- +SVTK_ImageWriter +::SVTK_ImageWriter(QSemaphore* theSemaphore, + vtkImageData* theImageData, + const std::string& theName, + int theProgressive, + int theQuality): + mySemaphore(theSemaphore), + myImageData(theImageData), + myName(theName), + myProgressive(theProgressive), + myQuality(theQuality), + myConstraint16Flag(true) +{} + +//---------------------------------------------------------------------------- +SVTK_ImageWriter +::~SVTK_ImageWriter() +{ + if(MYDEBUG) cout<<"SVTK_ImageWriter::~SVTK_ImageWriter - this = "< anImageClip; + // + if(myConstraint16Flag){ + int uExtent[6]; + myImageData->UpdateInformation(); + myImageData->GetUpdateExtent(uExtent); + unsigned int width = uExtent[1] - uExtent[0] + 1; + unsigned int height = uExtent[3] - uExtent[2] + 1; + width = (width / 16) * 16; + height= (height / 16) * 16; + uExtent[1] = uExtent[0] + width - 1; + uExtent[3] = uExtent[2] + height - 1; + // + anImageClip = vtkImageClip::New(); + anImageClip->Delete(); + + anImageClip->SetInput(myImageData); + anImageClip->SetOutputWholeExtent(uExtent); + anImageClip->ClipDataOn(); + anImageData = anImageClip->GetOutput(); + } + // + aWriter->WriteToMemoryOff(); + aWriter->SetFileName(myName.c_str()); + aWriter->SetQuality(myQuality); + aWriter->SetProgressive(myProgressive); + aWriter->SetInput(anImageData); + aWriter->Write(); + + aWriter->Delete(); + myImageData->Delete(); + + if(MYDEBUG) cout<<"SVTK_ImageWriter::run "<< + "- this = "< + +#include + +#include + + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//---------------------------------------------------------------------------- +SVTK_ImageWriterMgr +::SVTK_ImageWriterMgr() +{ + int aMax = std::numeric_limits::max() / 2; + mySemaphore = new QSemaphore(aMax); + mySemaphore->acquire( aMax ); + if(MYDEBUG) cout<<"SVTK_ImageWriterMgr::SVTK_ImageWriterMgr "<< + //"- total = "<total()<< + "; available = "<available()<start(); + +} + + +//---------------------------------------------------------------------------- +void +SVTK_ImageWriterMgr +::Stop() +{ + if(MYDEBUG) cout<<"SVTK_ImageWriterMgr::Stop "<< + //"- total = "<total()<< + "; available = "<available()<hide(); @@ -1487,12 +1431,10 @@ SVTK_InteractorStyle /*! Main process event method (reimplemented from #vtkInteractorStyle) */ -void -SVTK_InteractorStyle -::ProcessEvents( vtkObject* object, - unsigned long event, - void* clientData, - void* callData ) +void SVTK_InteractorStyle::ProcessEvents( vtkObject* object, + unsigned long event, + void* clientData, + void* callData ) { if ( clientData ) { vtkObject* anObject = reinterpret_cast( clientData ); @@ -1577,9 +1519,9 @@ SVTK_InteractorStyle case SVTK::SetRotateGravity: if ( self->myCurrRotationPointType == SVTK::StartPointSelection ) { - self->myHighlightRotationPointActor->SetVisibility( false ); + self->myHighlightSelectionPointActor->SetVisibility( false ); if( self->GetCurrentRenderer() != NULL ) - self->GetCurrentRenderer()->RemoveActor( self->myHighlightRotationPointActor.GetPointer() ); + self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() ); self->GetRenderWidget()->setCursor(self->myDefCursor); } self->myPrevRotationPointType = self->myCurrRotationPointType; @@ -1595,9 +1537,9 @@ SVTK_InteractorStyle case SVTK::ChangeRotationPoint: if ( self->myCurrRotationPointType == SVTK::StartPointSelection ) { - self->myHighlightRotationPointActor->SetVisibility( false ); + self->myHighlightSelectionPointActor->SetVisibility( false ); if( self->GetCurrentRenderer() != NULL ) - self->GetCurrentRenderer()->RemoveActor( self->myHighlightRotationPointActor.GetPointer() ); + self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() ); self->GetRenderWidget()->setCursor(self->myDefCursor); } self->myPrevRotationPointType = self->myCurrRotationPointType; @@ -1607,6 +1549,36 @@ SVTK_InteractorStyle self->myRotationPointY = aSelectedPoint[1]; self->myRotationPointZ = aSelectedPoint[2]; return; + + case SVTK::SetFocalPointGravity: + if ( self->myCurrFocalPointType == SVTK::StartPointSelection ) + { + self->myHighlightSelectionPointActor->SetVisibility( false ); + if( self->GetCurrentRenderer() != NULL ) + self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() ); + self->GetRenderWidget()->setCursor(self->myDefCursor); + } + self->myCurrFocalPointType = SVTK::SetFocalPointGravity; + if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) { + // invoke event for update coordinates in SVTK_ViewParameterDlg + self->InvokeEvent(SVTK::FocalPointChanged,(void*)aCenter); + } + return; + case SVTK::StartFocalPointSelection: + self->startFocalPointSelection(); + return; + + case SVTK::SetFocalPointSelected: + if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection ) + { + self->myHighlightSelectionPointActor->SetVisibility( false ); + if( self->GetCurrentRenderer() != NULL ) + self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() ); + self->GetRenderWidget()->setCursor(self->myDefCursor); + } + self->myPrevFocalPointType = self->myCurrFocalPointType; + self->myCurrFocalPointType = SVTK::SetFocalPointSelected; + return; } } } @@ -1619,6 +1591,11 @@ SVTK_InteractorStyle */ void SVTK_InteractorStyle::OnChar() { + char key = GetInteractor()->GetKeyCode(); + switch ( key ) { + case '+': ControllerIncrement()->Increase(); break; + case '-': ControllerIncrement()->Decrease(); break; + } } /*! @@ -1665,13 +1642,29 @@ SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown() } /*! - To get current increment controller + To set current increment controller */ void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController) { myControllerIncrement=theController; } +/*! + To modify current increment controller +*/ +void SVTK_InteractorStyle::SetIncrementSpeed(const int theValue, const int theMode) +{ + SVTK_ControllerIncrement* c = 0; + switch (theMode) { + case 0: c = SVTK_ControllerIncrement::New(); break; + case 1: c = SVTK_GeomControllerIncrement::New(); break; + } + c->SetStartValue(theValue); + + SetControllerIncrement(c); + c->Delete(); +} + /*! To get current increment controller */ @@ -1709,6 +1702,27 @@ int SVTK_ControllerIncrement::Decrease() return myIncrement; } +vtkStandardNewMacro(SVTK_GeomControllerIncrement); +SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement() +{ +} +SVTK_GeomControllerIncrement::~SVTK_GeomControllerIncrement() +{ +} +int SVTK_GeomControllerIncrement::Increase() +{ + myIncrement*=2; + return myIncrement; +} +int SVTK_GeomControllerIncrement::Decrease() +{ + myIncrement/=2; + if (myIncrement<1){ + myIncrement=1; + } + return myIncrement; +} + vtkStandardNewMacro(SVTK_ControllerOnKeyDown); /*! diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index b02941bfb..969531065 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -49,10 +49,10 @@ #endif // -//! Control the value of increment in SALOME way. +//! Control the value of increment in arithmetic progression mode. /*! This class controls of value of increment, - for pan/rotate/zoom operations in SALOME way + for pan/rotate/zoom operations in arithmetic progression mode */ class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{ public: @@ -79,6 +79,30 @@ class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{ SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented void operator=(const SVTK_ControllerIncrement&); //Not implemented }; + +// +//! Control the value of increment in geometric progression mode. +/*! + This class controls of value of increment, + for pan/rotate/zoom operations in geometric progression mode. +*/ +class SVTK_EXPORT SVTK_GeomControllerIncrement : public SVTK_ControllerIncrement{ + public: + vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement); + static SVTK_GeomControllerIncrement* New(); + + //! Increace the increment value by add 1 + virtual int Increase(); + + //! Decreace the increment value by subtract 1 + virtual int Decrease(); + protected: + SVTK_GeomControllerIncrement(); + virtual ~SVTK_GeomControllerIncrement(); + private: + SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement&);//Not implemented + void operator=(const SVTK_GeomControllerIncrement&); //Not implemented +}; // //! Control the behaviour of KeyDown event in SALOME way. /*! @@ -138,78 +162,53 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle //! Generate special #SVTK_SelectionEvent - virtual - SVTK_SelectionEvent* - GetSelectionEvent(); + virtual SVTK_SelectionEvent* GetSelectionEvent(); //! Generate special #SVTK_SelectionEvent with flipped Y coordinate - virtual - SVTK_SelectionEvent* - GetSelectionEventFlipY(); + virtual SVTK_SelectionEvent* GetSelectionEventFlipY(); //! Redefined in order to add an observer (callback) for custom event (space mouse event) - virtual - void - SetInteractor( vtkRenderWindowInteractor* ); + virtual void SetInteractor( vtkRenderWindowInteractor* ); //! To invoke #vtkRenderWindowInteractor::CreateTimer - virtual - void - Render(); + virtual void Render(); //! To implement cached rendering - virtual - void - OnTimer(); + virtual void OnTimer(); //! To reset reset view - virtual - void - OnConfigure(); + virtual void OnConfigure(); //! To handle mouse move event - virtual - void - OnMouseMove(); + virtual void OnMouseMove(); //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle) - virtual - void - OnLeftButtonDown(); + virtual void OnLeftButtonDown(); //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle) - virtual - void - OnLeftButtonUp(); + virtual void OnLeftButtonUp(); //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle) - virtual - void - OnMiddleButtonDown(); + virtual void OnMiddleButtonDown(); //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle) - virtual - void - OnMiddleButtonUp(); + virtual void OnMiddleButtonUp(); //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle) - virtual - void - OnRightButtonDown(); + virtual void OnRightButtonDown(); //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle) - virtual - void - OnRightButtonUp(); + virtual void OnRightButtonUp(); //! To handle keyboard event (reimplemented from #vtkInteractorStyle) - virtual - void - OnChar(); + virtual void OnChar(); //! To set current increment controller void SetControllerIncrement(SVTK_ControllerIncrement*); + //! To modify current increment controller + void SetIncrementSpeed(const int, const int = 0); + //! To get current increment controller SVTK_ControllerIncrement* ControllerIncrement(); @@ -283,6 +282,7 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle void startSpin(); void startPointSelection(); + void startFocalPointSelection(); protected: void loadCursors(); @@ -336,11 +336,14 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle unsigned long myCurrRotationPointType; unsigned long myPrevRotationPointType; + unsigned long myCurrFocalPointType; + unsigned long myPrevFocalPointType; + double myRotationPointX; double myRotationPointY; double myRotationPointZ; - vtkSmartPointer myHighlightRotationPointActor; + vtkSmartPointer myHighlightSelectionPointActor; vtkSmartPointer myPointPicker; vtkFloatingPointType myBBCenter[3]; diff --git a/src/SVTK/SVTK_KeyFreeInteractorStyle.cxx b/src/SVTK/SVTK_KeyFreeInteractorStyle.cxx new file mode 100644 index 000000000..193b406f1 --- /dev/null +++ b/src/SVTK/SVTK_KeyFreeInteractorStyle.cxx @@ -0,0 +1,162 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SVTK_KeyFreeInteractorStyle.cxx +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + + +#include "SVTK_KeyFreeInteractorStyle.h" +#include "SVTK_Selector.h" + +#include +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_KeyFreeInteractorStyle); +//---------------------------------------------------------------------------- + +SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle(): + myIsMidButtonDown( false ), + myIsLeftButtonDown( false ) +{ +} + +//---------------------------------------------------------------------------- +SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle() +{ +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift, + int x, int y) +{ + myIsLeftButtonDown = true; + + if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) { + this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL); + return; + } + this->FindPokedRenderer(x, y); + if (this->CurrentRenderer == NULL) { + return; + } + myShiftState = shift; + // finishing current viewer operation + if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); + } + myOtherPoint = myPoint = QPoint(x, y); + if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + startOperation(ForcedState); + } + else { + if (!(ctrl||shift)){ + if (myIsMidButtonDown){ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + } + else{ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); + } + } + } + return; +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl, + int shift, + int x, int y) +{ + myIsMidButtonDown = true; + + if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) { + this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL); + return; + } + this->FindPokedRenderer(x, y); + if (this->CurrentRenderer == NULL) { + return; + } + myShiftState = shift; + // finishing current viewer operation + if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); + } + myOtherPoint = myPoint = QPoint(x, y); + if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + startOperation(ForcedState); + } + else { + if (!(ctrl||shift)){ + if ( myIsLeftButtonDown ){ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + } + else{ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN); + } + } + } +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y) +{ + myIsLeftButtonDown = false; + SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y ); + + if ( myIsMidButtonDown ) + OnMiddleButtonDown( ctrl, shift, x, y ); +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y) +{ + myIsMidButtonDown = false; + SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y ); + + if ( myIsLeftButtonDown ) + OnLeftButtonDown( ctrl, shift, x, y ); +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnChar() +{ + char key = GetInteractor()->GetKeyCode(); + switch (key) { + case 's': + case 'S': + ActionPicking(); + EventCallbackCommand->AbortFlagOn(); + return; + } + SVTK_InteractorStyle::OnChar(); +} diff --git a/src/SVTK/SVTK_KeyFreeInteractorStyle.h b/src/SVTK/SVTK_KeyFreeInteractorStyle.h new file mode 100644 index 000000000..7e598a3c9 --- /dev/null +++ b/src/SVTK/SVTK_KeyFreeInteractorStyle.h @@ -0,0 +1,72 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SVTK_KeyFreeInteractorStyle.h +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + +#ifndef __SVTK_KeyFreeInteractorStyle_h +#define __SVTK_KeyFreeInteractorStyle_h + + +#include "SVTK.h" + +#include "SVTK_InteractorStyle.h" + +//! Introduce new style of interaction (keyboard free) +class SVTK_EXPORT SVTK_KeyFreeInteractorStyle : public SVTK_InteractorStyle +{ + public: + static SVTK_KeyFreeInteractorStyle *New(); + vtkTypeMacro(SVTK_KeyFreeInteractorStyle,SVTK_InteractorStyle); + + protected: + SVTK_KeyFreeInteractorStyle(); + ~SVTK_KeyFreeInteractorStyle(); + + SVTK_KeyFreeInteractorStyle(const SVTK_KeyFreeInteractorStyle&); // Not implemented + void operator=(const SVTK_KeyFreeInteractorStyle&); // Not implemented + + // Generic event bindings must be overridden in subclasses + + //! Redefine SVTK_InteractorStyle::OnLeftButtonDown + virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnMiddleButtonDown + virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnLeftButtonUp + virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnMiddleButtonUp + virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnChar + virtual void OnChar(); + + bool myIsMidButtonDown; + bool myIsLeftButtonDown; +}; + +#endif diff --git a/src/SVTK/SVTK_MainWindow.cxx b/src/SVTK/SVTK_MainWindow.cxx index a35d87567..64f31ce7d 100644 --- a/src/SVTK/SVTK_MainWindow.cxx +++ b/src/SVTK/SVTK_MainWindow.cxx @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -49,36 +49,42 @@ #include "SVTK_UpdateRateDlg.h" #include "SVTK_CubeAxesDlg.h" #include "SVTK_SetRotationPointDlg.h" +#include "SVTK_ViewParameterDlg.h" #include "SVTK_MainWindow.h" #include "SVTK_Event.h" #include "SVTK_Renderer.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" +#include "SVTK_KeyFreeInteractorStyle.h" #include "SVTK_Selector.h" +#include "SVTK_ComboAction.h" +#include "SVTK_Recorder.h" +#include "SVTK_RecorderDlg.h" /*! Constructor */ -SVTK_MainWindow -::SVTK_MainWindow(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr, - SUIT_ViewWindow* theViewWindow) : +SVTK_MainWindow::SVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow) : QMainWindow(theParent), - myViewWindow(theViewWindow) + myViewWindow(theViewWindow), + myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()) { setObjectName(theName); setWindowFlags( windowFlags() & ~Qt::Window ); + // specific of vtkSmartPointer + myKeyFreeInteractorStyle->Delete(); } /*! To initialize the class */ -void -SVTK_MainWindow -::Initialize(SVTK_RenderWindowInteractor* theInteractor) +void SVTK_MainWindow::Initialize(SVTK_RenderWindowInteractor* theInteractor) { myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), -1, this ); + myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), -1, this ); createActions( SUIT_Session::session()->activeApplication()->resourceMgr() ); createToolBar(); @@ -98,14 +104,28 @@ SVTK_MainWindow myCubeAxesDlg = new SVTK_CubeAxesDlg( action( GraduatedAxes ), this, "SVTK_CubeAxesDlg" ); mySetRotationPointDlg = new SVTK_SetRotationPointDlg ( action( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" ); + myViewParameterDlg = new SVTK_ViewParameterDlg + ( action( ViewParametersId ), this, "SVTK_ViewParameterDlg" ); + + myRecorder = SVTK_Recorder::New(); + //myRecorder->CheckExistAVIMaker(); + //if(myRecorder->ErrorStatus()) + // myRecordingToolBar->setEnabled(false); + + myRecorder->SetNbFPS( 17.3 ); + myRecorder->SetQuality( 100 ); + myRecorder->SetProgressiveMode( true ); + myRecorder->SetUseSkippedFrames( true ); + myRecorder->SetRenderWindow( theInteractor->getRenderWindow() ); } /*! Destructor */ -SVTK_MainWindow -::~SVTK_MainWindow() +SVTK_MainWindow::~SVTK_MainWindow() { + if(myRecorder) + myRecorder->Delete(); } /*! @@ -119,9 +139,7 @@ QtxActionToolMgr* SVTK_MainWindow::toolMgr() const /*! \return used SVTK_RenderWindowInteractor */ -SVTK_RenderWindowInteractor* -SVTK_MainWindow -::GetInteractor() +SVTK_RenderWindowInteractor* SVTK_MainWindow::GetInteractor() { return myInteractor; } @@ -129,9 +147,7 @@ SVTK_MainWindow /*! \return used #vtkRenderWindowInteractor (obsolete) */ -vtkRenderWindowInteractor* -SVTK_MainWindow -::getInteractor() +vtkRenderWindowInteractor* SVTK_MainWindow::getInteractor() { return GetInteractor()->GetDevice(); } @@ -139,9 +155,7 @@ SVTK_MainWindow /*! \return used vtkRenderWindow (obsolete) */ -vtkRenderWindow* -SVTK_MainWindow -::getRenderWindow() +vtkRenderWindow* SVTK_MainWindow::getRenderWindow() { return GetInteractor()->getRenderWindow(); } @@ -150,9 +164,7 @@ SVTK_MainWindow To repaint the view \param theUpdateTrihedron - adjust trihedron */ -void -SVTK_MainWindow -::Repaint(bool theUpdateTrihedron) +void SVTK_MainWindow::Repaint(bool theUpdateTrihedron) { if(theUpdateTrihedron) GetRenderer()->OnAdjustTrihedron(); @@ -166,9 +178,7 @@ SVTK_MainWindow /*! To invoke a VTK event on SVTK_RenderWindowInteractor instance */ -void -SVTK_MainWindow -::InvokeEvent(unsigned long theEvent, void* theCallData) +void SVTK_MainWindow::InvokeEvent(unsigned long theEvent, void* theCallData) { GetInteractor()->InvokeEvent(theEvent,theCallData); } @@ -176,9 +186,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle */ -vtkInteractorStyle* -SVTK_MainWindow -::GetInteractorStyle() +vtkInteractorStyle* SVTK_MainWindow::GetInteractorStyle() { return GetInteractor()->GetInteractorStyle(); } @@ -186,9 +194,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle */ -void -SVTK_MainWindow -::PushInteractorStyle(vtkInteractorStyle* theStyle) +void SVTK_MainWindow::PushInteractorStyle(vtkInteractorStyle* theStyle) { GetInteractor()->PushInteractorStyle(theStyle); } @@ -196,9 +202,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle */ -void -SVTK_MainWindow -::PopInteractorStyle() +void SVTK_MainWindow::PopInteractorStyle() { GetInteractor()->PopInteractorStyle(); } @@ -206,9 +210,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::GetSelector */ -SVTK_Selector* -SVTK_MainWindow -::GetSelector() +SVTK_Selector* SVTK_MainWindow::GetSelector() { return GetInteractor()->GetSelector(); } @@ -216,9 +218,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::SelectionMode */ -Selection_Mode -SVTK_MainWindow -::SelectionMode() +Selection_Mode SVTK_MainWindow::SelectionMode() { return GetSelector()->SelectionMode(); } @@ -226,9 +226,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::SetSelectionMode */ -void -SVTK_MainWindow -::SetSelectionMode(Selection_Mode theMode) +void SVTK_MainWindow::SetSelectionMode(Selection_Mode theMode) { GetSelector()->SetSelectionMode(theMode); } @@ -236,9 +234,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::GetRenderer */ -SVTK_Renderer* -SVTK_MainWindow -::GetRenderer() +SVTK_Renderer* SVTK_MainWindow::GetRenderer() { return GetInteractor()->GetRenderer(); } @@ -246,9 +242,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_RenderWindowInteractor::getRenderer */ -vtkRenderer* -SVTK_MainWindow -::getRenderer() +vtkRenderer* SVTK_MainWindow::getRenderer() { return GetInteractor()->getRenderer(); } @@ -257,9 +251,7 @@ SVTK_MainWindow Sets background color of the view \param theColor - new background color */ -void -SVTK_MainWindow -::SetBackgroundColor(const QColor& theColor) +void SVTK_MainWindow::SetBackgroundColor(const QColor& theColor) { getRenderer()->SetBackground(theColor.red()/255.0, theColor.green()/255.0, @@ -269,9 +261,7 @@ SVTK_MainWindow /*! \return background color of the view */ -QColor -SVTK_MainWindow -::BackgroundColor() +QColor SVTK_MainWindow::BackgroundColor() { vtkFloatingPointType aBackgroundColor[3]; getRenderer()->GetBackground(aBackgroundColor); @@ -283,9 +273,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::GetScale */ -void -SVTK_MainWindow -::GetScale( double theScale[3] ) +void SVTK_MainWindow::GetScale( double theScale[3] ) { GetRenderer()->GetScale( theScale ); } @@ -293,9 +281,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::SetScale */ -void -SVTK_MainWindow -::SetScale( double theScale[3] ) +void SVTK_MainWindow::SetScale( double theScale[3] ) { GetRenderer()->SetScale( theScale ); Repaint(); @@ -304,10 +290,8 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::AddActor */ -void -SVTK_MainWindow -::AddActor(VTKViewer_Actor* theActor, - bool theIsUpdate) +void SVTK_MainWindow::AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate) { GetRenderer()->AddActor(theActor); if(theIsUpdate) @@ -317,22 +301,41 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::RemoveActor */ -void -SVTK_MainWindow -::RemoveActor(VTKViewer_Actor* theActor, - bool theIsUpdate) +void SVTK_MainWindow::RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate) { GetRenderer()->RemoveActor(theActor); if(theIsUpdate) Repaint(); } +/*! + Redirect the request to SVTK_InteractorStyle::SetTrihedronSize +*/ +void SVTK_MainWindow::SetIncrementalSpeed( const int theValue, const int theMode ) +{ + if ( (SVTK_InteractorStyle*)GetInteractorStyle() ) + ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode); +} + +/*! + Redirect the request to SVTK_InteractorStyle +*/ +void SVTK_MainWindow::SetSMButtons( const int theBtn1, const int theBtn2, const int theBtn3 ) +{ + int val = theBtn1; + myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val); + val = theBtn2; + myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val); + val = theBtn3; + myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val); +} + + /*! Redirect the request to SVTK_Renderer::GetTrihedronSize */ -vtkFloatingPointType -SVTK_MainWindow -::GetTrihedronSize() +vtkFloatingPointType SVTK_MainWindow::GetTrihedronSize() { return GetRenderer()->GetTrihedronSize(); } @@ -340,9 +343,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::SetTrihedronSize */ -void -SVTK_MainWindow -::SetTrihedronSize( const vtkFloatingPointType theSize, const bool theRelative ) +void SVTK_MainWindow::SetTrihedronSize( const vtkFloatingPointType theSize, const bool theRelative ) { GetRenderer()->SetTrihedronSize(theSize, theRelative); Repaint(); @@ -352,9 +353,7 @@ SVTK_MainWindow /*! If parameter theIsForcedUpdate is true, recalculate parameters for * trihedron and cube axes, even if trihedron and cube axes is invisible. */ -void -SVTK_MainWindow -::AdjustActors() +void SVTK_MainWindow::AdjustActors() { GetRenderer()->AdjustActors(); Repaint(); @@ -363,9 +362,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::IsTrihedronDisplayed */ -bool -SVTK_MainWindow -::IsTrihedronDisplayed() +bool SVTK_MainWindow::IsTrihedronDisplayed() { return GetRenderer()->IsTrihedronDisplayed(); } @@ -373,9 +370,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::IsCubeAxesDisplayed */ -bool -SVTK_MainWindow -::IsCubeAxesDisplayed() +bool SVTK_MainWindow::IsCubeAxesDisplayed() { return GetRenderer()->IsCubeAxesDisplayed(); } @@ -383,9 +378,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::GetTrihedron */ -VTKViewer_Trihedron* -SVTK_MainWindow -::GetTrihedron() +VTKViewer_Trihedron* SVTK_MainWindow::GetTrihedron() { return GetRenderer()->GetTrihedron(); } @@ -393,9 +386,7 @@ SVTK_MainWindow /*! Redirect the request to SVTK_Renderer::GetCubeAxes */ -SVTK_CubeAxesActor2D* -SVTK_MainWindow -::GetCubeAxes() +SVTK_CubeAxesActor2D* SVTK_MainWindow::GetCubeAxes() { return GetRenderer()->GetCubeAxes(); } @@ -403,16 +394,12 @@ SVTK_MainWindow /*! \return toolbar of svtk main window */ -QToolBar* -SVTK_MainWindow -::getToolBar() +QToolBar* SVTK_MainWindow::getToolBar() { return toolMgr()->toolBar( myToolBar ); } -void -SVTK_MainWindow -::SetEventDispatcher(vtkObject* theDispatcher) +void SVTK_MainWindow::SetEventDispatcher(vtkObject* theDispatcher) { myEventDispatcher = theDispatcher; } @@ -424,9 +411,7 @@ SVTK_MainWindow /*! Creates all actions of svtk main window */ -void -SVTK_MainWindow -::createActions(SUIT_ResourceMgr* theResourceMgr) +void SVTK_MainWindow::createActions(SUIT_ResourceMgr* theResourceMgr) { QtxAction* anAction; QtxActionToolMgr* mgr = toolMgr(); @@ -581,6 +566,67 @@ SVTK_MainWindow anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool))); mgr->registerAction( anAction, UpdateRate ); + + // Set projection mode + SVTK_ComboAction* aModeAction = new SVTK_ComboAction(tr("MNU_SVTK_PROJECTION_MODE"), this); + aModeAction->setStatusTip(tr("DSC_SVTK_PROJECTION_MODE")); + aModeAction->insertItem(theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ) ); + aModeAction->insertItem(theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ) ); + connect(aModeAction, SIGNAL(triggered(int)), this, SLOT(onProjectionMode(int))); + mgr->registerAction( aModeAction, ProjectionModeId ); + + // View Parameters + anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ), + tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool))); + mgr->registerAction( anAction, ViewParametersId ); + + // Switch between interaction styles + anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ), + tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool))); + mgr->registerAction( anAction, SwitchInteractionStyleId ); + + // Start recording + myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ), + tr( "MNU_SVTK_RECORDING_START" ), 0, this); + myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START")); + connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) ); + mgr->registerAction( myStartAction, StartRecordingId ); + + // Play recording + myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ), + tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this); + myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY")); + myPlayAction->setEnabled( false ); + connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) ); + mgr->registerAction( myPlayAction, PlayRecordingId ); + + // Pause recording + myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ), + tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this); + myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE")); + myPauseAction->setEnabled( false ); + connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) ); + mgr->registerAction( myPauseAction, PauseRecordingId ); + + // Stop recording + myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ), + tr( "MNU_SVTK_RECORDING_STOP" ), 0, this); + myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP")); + myStopAction->setEnabled( false ); + connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) ); + mgr->registerAction( myStopAction, StopRecordingId ); } #if defined(WIN32) && !defined(_DEBUG) @@ -590,13 +636,12 @@ SVTK_MainWindow /*! Creates toolbar of svtk main window */ -void -SVTK_MainWindow -::createToolBar() +void SVTK_MainWindow::createToolBar() { QtxActionToolMgr* mgr = toolMgr(); mgr->append( DumpId, myToolBar ); + mgr->append( SwitchInteractionStyleId, myToolBar ); mgr->append( ViewTrihedronId, myToolBar ); QtxMultiAction* aScaleAction = new QtxMultiAction( this ); @@ -628,14 +673,20 @@ SVTK_MainWindow mgr->append( UpdateRate, myToolBar ); mgr->append( NonIsometric, myToolBar ); mgr->append( GraduatedAxes, myToolBar ); + + mgr->append( ViewParametersId, myToolBar ); + mgr->append( ProjectionModeId, myToolBar ); + + mgr->append( StartRecordingId, myRecordingToolBar ); + mgr->append( PlayRecordingId, myRecordingToolBar ); + mgr->append( PauseRecordingId, myRecordingToolBar ); + mgr->append( StopRecordingId, myRecordingToolBar ); } /*! Custom show event handler */ -void -SVTK_MainWindow -::showEvent( QShowEvent * theEvent ) +void SVTK_MainWindow::showEvent( QShowEvent * theEvent ) { emit Show( theEvent ); } @@ -643,9 +694,7 @@ SVTK_MainWindow /*! Custom hide event handler */ -void -SVTK_MainWindow -::hideEvent( QHideEvent * theEvent ) +void SVTK_MainWindow::hideEvent( QHideEvent * theEvent ) { emit Hide( theEvent ); } @@ -653,9 +702,7 @@ SVTK_MainWindow /*! Starts zoom transformation */ -void -SVTK_MainWindow -::activateZoom() +void SVTK_MainWindow::activateZoom() { myEventDispatcher->InvokeEvent(SVTK::StartZoom,0); } @@ -663,9 +710,7 @@ SVTK_MainWindow /*! Starts panning transformation */ -void -SVTK_MainWindow -::activatePanning() +void SVTK_MainWindow::activatePanning() { myEventDispatcher->InvokeEvent(SVTK::StartPan,0); } @@ -673,9 +718,7 @@ SVTK_MainWindow /*! Starts rotation transformation */ -void -SVTK_MainWindow -::activateRotation() +void SVTK_MainWindow::activateRotation() { myEventDispatcher->InvokeEvent(SVTK::StartRotate,0); } @@ -683,9 +726,7 @@ SVTK_MainWindow /*! Change rotation point */ -void -SVTK_MainWindow -::onChangeRotationPoint(bool theIsActivate) +void SVTK_MainWindow::onChangeRotationPoint(bool theIsActivate) { if(theIsActivate){ mySetRotationPointDlg->addObserver(); @@ -699,9 +740,7 @@ SVTK_MainWindow /*! Set the gravity center as a rotation point */ -void -SVTK_MainWindow -::activateSetRotationGravity() +void SVTK_MainWindow::activateSetRotationGravity() { myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0); } @@ -709,9 +748,7 @@ SVTK_MainWindow /*! Set the selected point as a rotation point */ -void -SVTK_MainWindow -::activateSetRotationSelected(void* theData) +void SVTK_MainWindow::activateSetRotationSelected(void* theData) { myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData); } @@ -719,19 +756,69 @@ SVTK_MainWindow /*! Set the point selected by user as a rotation point */ -void -SVTK_MainWindow -::activateStartPointSelection() +void SVTK_MainWindow::activateStartPointSelection() { myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0); } /*! - Starts global panning transformation + Set the view projection mode: orthogonal or perspective +*/ +void SVTK_MainWindow::onProjectionMode(int mode) +{ + vtkCamera* aCamera = getRenderer()->GetActiveCamera(); + aCamera->SetParallelProjection(mode==0); + GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); +} + +/*! + Modify view parameters +*/ +void SVTK_MainWindow::onViewParameters(bool theIsActivate) +{ + if(theIsActivate){ + myViewParameterDlg->addObserver(); + myViewParameterDlg->show(); + }else + myViewParameterDlg->hide(); +} + +/*! + Set the gravity center as a focal point +*/ +void SVTK_MainWindow::activateSetFocalPointGravity() +{ + myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0); +} + +/*! + Set the selected point as a focal point +*/ +void SVTK_MainWindow::activateSetFocalPointSelected() +{ + myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0); +} + +/*! + Set the point selected by user as a focal point */ void SVTK_MainWindow -::activateGlobalPanning() +::activateStartFocalPointSelection() +{ + myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0); +} + +void SVTK_MainWindow::activateProjectionMode(int mode) +{ + SVTK_ComboAction* a = ::qobject_cast( toolMgr()->action( ProjectionModeId ) ); + if ( a ) a->setCurrentIndex(mode); +} + +/*! + Starts global panning transformation +*/ +void SVTK_MainWindow::activateGlobalPanning() { myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0); } @@ -739,19 +826,45 @@ SVTK_MainWindow /*! Starts window fit transformation */ -void -SVTK_MainWindow -::activateWindowFit() +void SVTK_MainWindow::activateWindowFit() { myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0); } +/*! + Switches "keyboard free" interaction style on/off +*/ +void SVTK_MainWindow::onSwitchInteractionStyle(bool theOn) +{ + if (theOn) { + // check if style is already set + if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() ) + { + // keep the same style extensions + SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle(); + if ( aStyle ) { + myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement()); + myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown()); + } + + PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer()); + } + } + else { + // pop only key free style + if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() ) + PopInteractorStyle(); + } + + // update action state if method is called outside + QtxAction* a = action( SwitchInteractionStyleId ); + if ( a->isChecked() != theOn ) a->setChecked( theOn ); +} + /*! Processes transformation "front view" */ -void -SVTK_MainWindow -::onFrontView() +void SVTK_MainWindow::onFrontView() { GetRenderer()->OnFrontView(); Repaint(); @@ -760,9 +873,7 @@ SVTK_MainWindow /*! Processes transformation "back view" */ -void -SVTK_MainWindow -::onBackView() +void SVTK_MainWindow::onBackView() { GetRenderer()->OnBackView(); Repaint(); @@ -771,9 +882,7 @@ SVTK_MainWindow /*! Processes transformation "top view" */ -void -SVTK_MainWindow -::onTopView() +void SVTK_MainWindow::onTopView() { GetRenderer()->OnTopView(); Repaint(); @@ -782,9 +891,7 @@ SVTK_MainWindow /*! Processes transformation "bottom view" */ -void -SVTK_MainWindow -::onBottomView() +void SVTK_MainWindow::onBottomView() { GetRenderer()->OnBottomView(); Repaint(); @@ -793,9 +900,7 @@ SVTK_MainWindow /*! Processes transformation "left view" */ -void -SVTK_MainWindow -::onLeftView() +void SVTK_MainWindow::onLeftView() { GetRenderer()->OnLeftView(); Repaint(); @@ -804,9 +909,7 @@ SVTK_MainWindow /*! Processes transformation "right view" */ -void -SVTK_MainWindow -::onRightView() +void SVTK_MainWindow::onRightView() { GetRenderer()->OnRightView(); Repaint(); @@ -815,9 +918,7 @@ SVTK_MainWindow /*! Processes transformation "reset view": sets default orientation of viewport camera */ -void -SVTK_MainWindow -::onResetView() +void SVTK_MainWindow::onResetView() { GetRenderer()->OnResetView(); Repaint(); @@ -826,9 +927,7 @@ SVTK_MainWindow /*! Processes transformation "fit all" */ -void -SVTK_MainWindow -::onFitAll() +void SVTK_MainWindow::onFitAll() { GetRenderer()->OnFitAll(); Repaint(); @@ -837,9 +936,7 @@ SVTK_MainWindow /*! Shows trihedron */ -void -SVTK_MainWindow -::onViewTrihedron() +void SVTK_MainWindow::onViewTrihedron() { GetRenderer()->OnViewTrihedron(); Repaint(); @@ -848,17 +945,13 @@ SVTK_MainWindow /*! Shows cube axes */ -void -SVTK_MainWindow -::onViewCubeAxes() +void SVTK_MainWindow::onViewCubeAxes() { GetRenderer()->OnViewCubeAxes(); Repaint(); } -void -SVTK_MainWindow -::onUpdateRate(bool theIsActivate) +void SVTK_MainWindow::onUpdateRate(bool theIsActivate) { if(theIsActivate){ myUpdateRateDlg->Update(); @@ -867,9 +960,7 @@ SVTK_MainWindow myUpdateRateDlg->hide(); } -void -SVTK_MainWindow -::onNonIsometric(bool theIsActivate) +void SVTK_MainWindow::onNonIsometric(bool theIsActivate) { if(theIsActivate){ myNonIsometricDlg->Update(); @@ -878,9 +969,7 @@ SVTK_MainWindow myNonIsometricDlg->hide(); } -void -SVTK_MainWindow -::onGraduatedAxes(bool theIsActivate) +void SVTK_MainWindow::onGraduatedAxes(bool theIsActivate) { if(theIsActivate){ myCubeAxesDlg->Update(); @@ -889,16 +978,12 @@ SVTK_MainWindow myCubeAxesDlg->hide(); } -void -SVTK_MainWindow -::onAdjustTrihedron() +void SVTK_MainWindow::onAdjustTrihedron() { GetRenderer()->OnAdjustTrihedron(); } -void -SVTK_MainWindow -::onAdjustCubeAxes() +void SVTK_MainWindow::onAdjustCubeAxes() { GetRenderer()->OnAdjustCubeAxes(); } @@ -906,9 +991,7 @@ SVTK_MainWindow /*! \return QImage, containing all scene rendering in window */ -QImage -SVTK_MainWindow -::dumpView() +QImage SVTK_MainWindow::dumpView() { vtkRenderWindow* aWindow = GetInteractor()->getRenderWindow(); int* aSize = aWindow->GetSize(); @@ -932,3 +1015,62 @@ QtxAction* SVTK_MainWindow::action( int id ) const { return dynamic_cast( toolMgr()->action( id ) ); } + +void SVTK_MainWindow::onStartRecording() +{ + myRecorder->CheckExistAVIMaker(); + if (myRecorder->ErrorStatus()) { + SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") ); + } + else { + SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder ); + + if( !aRecorderDlg->exec() ) + return; + + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( true ); + myStopAction->setEnabled( true ); + + // to prevent resizing the window while recording + myPreRecordingMinSize = minimumSize(); + myPreRecordingMaxSize = maximumSize(); + setFixedSize( size() ); + + myRecorder->Record(); + } +} + +void SVTK_MainWindow::onPlayRecording() +{ + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( true ); + myStopAction->setEnabled( true ); + + myRecorder->Pause(); +} + +void SVTK_MainWindow::onPauseRecording() +{ + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( true ); + myPauseAction->setEnabled( false ); + myStopAction->setEnabled( true ); + + myRecorder->Pause(); +} + +void SVTK_MainWindow::onStopRecording() +{ + myStartAction->setEnabled( true ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( false ); + myStopAction->setEnabled( false ); + + myRecorder->Stop(); + + setMinimumSize( myPreRecordingMinSize ); + setMaximumSize( myPreRecordingMaxSize ); +} diff --git a/src/SVTK/SVTK_MainWindow.h b/src/SVTK/SVTK_MainWindow.h index 510266f73..f6ea61d13 100644 --- a/src/SVTK/SVTK_MainWindow.h +++ b/src/SVTK/SVTK_MainWindow.h @@ -48,8 +48,11 @@ class SVTK_UpdateRateDlg; class SVTK_CubeAxesActor2D; class SVTK_CubeAxesDlg; class SVTK_SetRotationPointDlg; +class SVTK_ViewParameterDlg; class SVTK_Renderer; class SVTK_Selector; +class SVTK_KeyFreeInteractorStyle; +class SVTK_Recorder; class VTKViewer_Trihedron; class VTKViewer_Actor; @@ -70,124 +73,99 @@ public: SUIT_ViewWindow* theViewWindow); //! To initialize the class - virtual - void - Initialize(SVTK_RenderWindowInteractor* theInteractor); + virtual void Initialize(SVTK_RenderWindowInteractor* theInteractor); - virtual - ~SVTK_MainWindow(); + virtual ~SVTK_MainWindow(); //---------------------------------------------------------------------------- //! Get used #SVTK_RenderWindowInteractor - SVTK_RenderWindowInteractor* - GetInteractor(); + SVTK_RenderWindowInteractor* GetInteractor(); //! Get used #vtkRenderWindowInteractor (obsolete) - vtkRenderWindowInteractor* - getInteractor(); + vtkRenderWindowInteractor* getInteractor(); //! Get used #vtkRenderWindow (obsolete) - vtkRenderWindow* - getRenderWindow(); + vtkRenderWindow* getRenderWindow(); //! To repaint the view - void - Repaint(bool theUpdateTrihedron = true); + void Repaint(bool theUpdateTrihedron = true); //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance - void - InvokeEvent(unsigned long theEvent, void* theCallData); + void InvokeEvent(unsigned long theEvent, void* theCallData); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_RenderWindowInteractor::GetInteractorStyle - vtkInteractorStyle* - GetInteractorStyle(); + vtkInteractorStyle* GetInteractorStyle(); //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle - void - PushInteractorStyle(vtkInteractorStyle* theStyle); + void PushInteractorStyle(vtkInteractorStyle* theStyle); //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle - void - PopInteractorStyle(); + void PopInteractorStyle(); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_RenderWindowInteractor::GetSelector - SVTK_Selector* - GetSelector(); + SVTK_Selector* GetSelector(); //! Redirect the request to #SVTK_RenderWindowInteractor::SelectionMode - Selection_Mode - SelectionMode(); + Selection_Mode SelectionMode(); //! Redirect the request to #SVTK_RenderWindowInteractor::SetSelectionMode - void - SetSelectionMode(Selection_Mode theMode); + void SetSelectionMode(Selection_Mode theMode); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_RenderWindowInteractor::GetRenderer - SVTK_Renderer* - GetRenderer(); + SVTK_Renderer* GetRenderer(); //! Redirect the request to #SVTK_RenderWindowInteractor::getRenderer - vtkRenderer* - getRenderer(); + vtkRenderer* getRenderer(); //! Set background color to the view - void - SetBackgroundColor(const QColor& theColor); + void SetBackgroundColor(const QColor& theColor); //! Get background color of the view - QColor - BackgroundColor(); + QColor BackgroundColor(); //! Redirect the request to #SVTK_Renderer::SetScale - void - SetScale(double theScale[3]); + void SetScale(double theScale[3]); //! Redirect the request to #SVTK_Renderer::GetScale - void - GetScale(double theScale[3]); + void GetScale(double theScale[3]); //! Redirect the request to #SVTK_Renderer::AddActor - virtual - void - AddActor(VTKViewer_Actor* theActor, - bool theIsUpdate = false); + virtual void AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); //! Redirect the request to #SVTK_Renderer::RemoveActor - virtual - void - RemoveActor(VTKViewer_Actor* theActor, - bool theIsUpdate = false); + virtual void RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //! Redirect the request to #SVTK_InteractorStyle::SetIncrementalSpeed + void SetIncrementalSpeed( const int, const int = 0 ); + + //! Redirect the request to #SVTK_InteractorStyle::SetIncrementalSpeed + void SetSMButtons( const int, const int, const int ); //! Redirect the request to #SVTK_Renderer::GetTrihedronSize - vtkFloatingPointType - GetTrihedronSize(); + vtkFloatingPointType GetTrihedronSize(); //! Redirect the request to #SVTK_Renderer::SetTrihedronSize - void - SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative = true); + void SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative = true); //! Redirect the request to #SVTK_Renderer::AdjustActors - void - AdjustActors(); + void AdjustActors(); //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed - bool - IsTrihedronDisplayed(); + bool IsTrihedronDisplayed(); //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed - bool - IsCubeAxesDisplayed(); + bool IsCubeAxesDisplayed(); //! Redirect the request to #SVTK_Renderer::GetTrihedron - VTKViewer_Trihedron* - GetTrihedron(); + VTKViewer_Trihedron* GetTrihedron(); //! Redirect the request to #SVTK_Renderer::GetCubeAxes - SVTK_CubeAxesActor2D* - GetCubeAxes(); + SVTK_CubeAxesActor2D* GetCubeAxes(); //---------------------------------------------------------------------------- QToolBar* getToolBar(); @@ -222,6 +200,14 @@ public: void onResetView(); void onFitAll(); + void onViewParameters(bool theIsActivate); + + void activateProjectionMode(int); + + void activateSetFocalPointGravity(); + void activateSetFocalPointSelected(); + void activateStartFocalPointSelection(); + void onViewTrihedron(); void onViewCubeAxes(); @@ -232,27 +218,35 @@ public: void onAdjustTrihedron(); void onAdjustCubeAxes(); + void onProjectionMode(int mode); + + void onSwitchInteractionStyle(bool theOn); + + void onStartRecording(); + void onPlayRecording(); + void onPauseRecording(); + void onStopRecording(); + public: QImage dumpView(); protected: virtual QtxActionToolMgr* toolMgr() const; - void - createActions(SUIT_ResourceMgr* theResourceMgr); + void createActions(SUIT_ResourceMgr* theResourceMgr); - void - createToolBar(); + void createToolBar(); - void - SetEventDispatcher(vtkObject* theDispatcher); + void SetEventDispatcher(vtkObject* theDispatcher); QtxAction* action( int ) const; enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, ChangeRotationPointId, RotationId, FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, - ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate}; + ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate, + ProjectionModeId, ViewParametersId, SwitchInteractionStyleId, + StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId }; SUIT_ViewWindow* myViewWindow; @@ -260,11 +254,23 @@ public: SVTK_UpdateRateDlg* myUpdateRateDlg; SVTK_CubeAxesDlg* myCubeAxesDlg; SVTK_SetRotationPointDlg* mySetRotationPointDlg; + SVTK_ViewParameterDlg* myViewParameterDlg; vtkSmartPointer myEventDispatcher; int myToolBar; + int myRecordingToolBar; SVTK_RenderWindowInteractor* myInteractor; + vtkSmartPointer myKeyFreeInteractorStyle; + + QSize myPreRecordingMinSize; + QSize myPreRecordingMaxSize; + + SVTK_Recorder* myRecorder; + QtxAction* myStartAction; + QtxAction* myPlayAction; + QtxAction* myPauseAction; + QtxAction* myStopAction; }; #ifdef WIN32 diff --git a/src/SVTK/SVTK_NonIsometricDlg.cxx b/src/SVTK/SVTK_NonIsometricDlg.cxx index a3a2044ae..826444148 100644 --- a/src/SVTK/SVTK_NonIsometricDlg.cxx +++ b/src/SVTK/SVTK_NonIsometricDlg.cxx @@ -27,7 +27,7 @@ // $Header$ #include "SVTK_NonIsometricDlg.h" -#include "SVTK_MainWindow.h" +#include "SVTK_ViewWindow.h" #include "SVTK_Renderer.h" #include "QtxDoubleSpinBox.h" @@ -45,7 +45,7 @@ using namespace std; */ SVTK_NonIsometricDlg ::SVTK_NonIsometricDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName): SVTK_DialogBase(theAction, theParent, diff --git a/src/SVTK/SVTK_NonIsometricDlg.h b/src/SVTK/SVTK_NonIsometricDlg.h index bcb730d52..222f883e7 100644 --- a/src/SVTK/SVTK_NonIsometricDlg.h +++ b/src/SVTK/SVTK_NonIsometricDlg.h @@ -31,7 +31,7 @@ #include "SVTK_DialogBase.h" -class SVTK_MainWindow; +class SVTK_ViewWindow; class QtxDoubleSpinBox; class QtxAction; @@ -45,7 +45,7 @@ class SVTK_NonIsometricDlg : public SVTK_DialogBase public: SVTK_NonIsometricDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName); ~SVTK_NonIsometricDlg(); @@ -53,7 +53,7 @@ public: void Update(); protected: - SVTK_MainWindow *m_MainWindow; + SVTK_ViewWindow *m_MainWindow; QtxDoubleSpinBox* m_sbXcoeff; QtxDoubleSpinBox* m_sbYcoeff; diff --git a/src/SVTK/SVTK_Recorder.cxx b/src/SVTK/SVTK_Recorder.cxx new file mode 100755 index 000000000..67aac1de0 --- /dev/null +++ b/src/SVTK/SVTK_Recorder.cxx @@ -0,0 +1,481 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "SVTK_Recorder.h" + +#include "SVTK_ImageWriter.h" +#include "SVTK_ImageWriterMgr.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +#include +#include +#include + +//#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +namespace +{ + //---------------------------------------------------------------------------- + inline + void + GetNameJPEG(const std::string& thePreffix, + const int theIndex, + std::string& theName) + { + using namespace std; + ostringstream aStream; + aStream<SetClientData(this); + myCommand->SetCallback(SVTK_Recorder::ProcessEvents); +} + + +//---------------------------------------------------------------------------- +SVTK_Recorder +::~SVTK_Recorder() +{ + myCommand->Delete(); + myFilter->Delete(); + delete myWriterMgr; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::CheckExistAVIMaker() +{ + myErrorStatus = 0; + using namespace std; + ostringstream aStream; + aStream<<"which "<& /dev/null"; + std::string anAVIMakeCheck = aStream.str(); + int iErr = system(anAVIMakeCheck.c_str()); + if(iErr != 0) + myErrorStatus = 127; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::SetName(const char* theName) +{ + myName = theName; +} + +const char* +SVTK_Recorder::Name() const +{ + return myName.c_str(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::SetNbFPS(const double theNbFPS) +{ + myNbFPS = theNbFPS; +} + +double +SVTK_Recorder +::NbFPS() const +{ + return myNbFPS; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::SetQuality(int theQuality) +{ + myQuality = theQuality; +} + +int +SVTK_Recorder +::GetQuality() const +{ + return myQuality; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::SetRenderWindow(vtkRenderWindow* theRenderWindow) +{ + myRenderWindow = theRenderWindow; +} + +vtkRenderWindow* +SVTK_Recorder +::RenderWindow() +{ + return myRenderWindow; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::SetProgressiveMode(bool theProgressiveMode) +{ + myProgressiveMode = theProgressiveMode; +} + +bool +SVTK_Recorder +::GetProgressiveMode() const +{ + return myProgressiveMode; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::SetUseSkippedFrames(bool theUseSkippedFrames) +{ + myUseSkippedFrames = theUseSkippedFrames; +} + +bool +SVTK_Recorder +::UseSkippedFrames() const +{ + return myUseSkippedFrames; +} + + +//---------------------------------------------------------------------------- +int +SVTK_Recorder +::ErrorStatus() const +{ + return myErrorStatus; +} + +int +SVTK_Recorder +::State() const +{ + return myState; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + if(vtkObject* anObj = reinterpret_cast(theClientData)){ + if(SVTK_Recorder* aSelf = dynamic_cast(anObj)){ + if(theEvent==vtkCommand::EndEvent){ + if(aSelf->State() == SVTK_Recorder::SVTK_Recorder_Record){ + aSelf->DoRecord(); + } + } + } + } +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::Record() +{ + if(myState == SVTK_Recorder_Stop){ + if(myRenderWindow){ + myState = SVTK_Recorder_Record; + myFilter->SetInput(myRenderWindow); + myFrameIndex = -1; + myNbWrittenFrames = 0; + myRenderWindow->RemoveObserver(myCommand); + myRenderWindow->AddObserver(vtkCommand::EndEvent, + myCommand, + myPriority); + myRenderWindow->Render(); + } + } +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::Stop() +{ + QApplication::setOverrideCursor( Qt::WaitCursor ); + + if(myState == SVTK_Recorder_Record){ + if(!myPaused) + DoRecord(); + + myWriterMgr->Stop(); + + if(myUseSkippedFrames) + AddSkippedFrames(); + + myFrameIndexes.clear(); + + MakeFileAVI(); + } + myState = SVTK_Recorder_Stop; + myPaused = 0; + + QApplication::restoreOverrideCursor(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Recorder +::Pause() +{ + myPaused = myPaused ? 0 : 1; + if(myPaused && !myFrameIndexes.empty()){ + myFrameIndexes.back() *= -1; + if(MYDEBUG) cout<<"SVTK_Recorder::Pause - myFrameIndexes.back() = "< +#include +#include + +#include + +class vtkRenderWindow; +class vtkCallbackCommand; +class vtkWindowToImageFilter; +class SVTK_ImageWriterMgr; + +class SVTK_Recorder : public vtkObject +{ + protected: + enum State { + SVTK_Recorder_Unknown=0, + SVTK_Recorder_Record, + SVTK_Recorder_Stop + }; + + public: + static SVTK_Recorder *New(); + vtkTypeRevisionMacro(SVTK_Recorder,vtkObject); + + void + SetRenderWindow(vtkRenderWindow* theRenderWindow); + + vtkRenderWindow* + RenderWindow(); + + void + SetName(const char *theName); + + const char* + Name() const; + + void + SetNbFPS(const double theNbFPS); + + double + NbFPS() const; + + void + SetQuality(int theQuality); + + int + GetQuality() const; + + void + SetProgressiveMode(bool theProgressiveMode); + + bool + GetProgressiveMode() const; + + void + SetUseSkippedFrames(bool theUseSkippedFrames); + + bool + UseSkippedFrames() const; + + void + Record(); + + void + Pause(); + + void + Stop(); + + int + State() const; + + int + ErrorStatus() const; + + void + CheckExistAVIMaker(); + +protected : + SVTK_Recorder(); + + ~SVTK_Recorder(); + + void + DoRecord(); + + void + MakeFileAVI(); + + void + AddSkippedFrames(); + + void + PreWrite(); + + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + +protected : + int myState; + int myPaused; + int myErrorStatus; + + float myPriority; + double myTimeStart; + + int myFrameIndex; + int myNbWrittenFrames; + + double myNbFPS; + int myQuality; + bool myProgressiveMode; + + typedef std::vector TFrameIndexes; + TFrameIndexes myFrameIndexes; + bool myUseSkippedFrames; + + std::string myName; + std::string myNameAVIMaker; + + vtkCallbackCommand *myCommand; + vtkRenderWindow *myRenderWindow; + vtkWindowToImageFilter *myFilter; + SVTK_ImageWriterMgr *myWriterMgr; + +private: + SVTK_Recorder(const SVTK_Recorder&); //Not implemented + void operator=(const SVTK_Recorder&); //Not implemented +}; + +#endif diff --git a/src/SVTK/SVTK_RecorderDlg.cxx b/src/SVTK/SVTK_RecorderDlg.cxx new file mode 100644 index 000000000..e6f318dab --- /dev/null +++ b/src/SVTK/SVTK_RecorderDlg.cxx @@ -0,0 +1,212 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "SVTK_RecorderDlg.h" +#include "SVTK_Recorder.h" + +#include +#include +#include +#include + +#include +#include + +//#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + * Constructor + */ +SVTK_RecorderDlg::SVTK_RecorderDlg( QWidget* theParent, SVTK_Recorder* theRecorder ): + QDialog( theParent ), + myRecorder( theRecorder ) +{ + setWindowTitle( tr( "DLG_RECORDER_TITLE" ) ); + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + QVBoxLayout* aTopLayout = new QVBoxLayout( this ); + aTopLayout->setSpacing( 6 ); + aTopLayout->setMargin( 6 ); + + // Settings + QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this ); + + QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox ); + aSettingsLayout->setSpacing( 6 ); + aSettingsLayout->setMargin( 11 ); + + QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox ); + myFileNameLineEdit = new QLineEdit( mySettingsBox ); + myFileNameLineEdit->setMinimumWidth( 250 ); + myFileNameLineEdit->setReadOnly( true ); + + QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox ); + myRecordingModeComboBox = new QComboBox( mySettingsBox ); + myRecordingModeComboBox->addItem( tr( "SKIPPED_FRAMES" ) ); + myRecordingModeComboBox->addItem( tr( "ALL_DISLPAYED_FRAMES" ) ); + myRecordingModeComboBox->setCurrentIndex( aResourceMgr->integerValue( "VTKViewer", "recorder_mode", 1 ) ); + + QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox ); + myFPSSpinBox = new QtxDoubleSpinBox( 0.1, 100.0, 1.0, mySettingsBox ); + myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VTKViewer", "recorder_fps", 10.0 ) ); + + QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox ); + myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox ); + myQualitySpinBox->setValue( aResourceMgr->integerValue( "VTKViewer", "recorder_quality", 80 ) ); + + myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox ); + myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VTKViewer", "recorder_progressive", false ) ); + + aSettingsLayout->addWidget( aFileNameLabel, 0, 0 ); + aSettingsLayout->addWidget( myFileNameLineEdit, 1, 0, 1, 2 ); + aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 ); + aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 ); + aSettingsLayout->addWidget( aFPSLabel, 3, 0 ); + aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 ); + aSettingsLayout->addWidget( aQualityLabel, 4, 0 ); + aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 ); + aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 ); + + aTopLayout->addWidget( mySettingsBox ); + + // Start / Close + QGroupBox* CommonGroup = new QGroupBox( this ); + QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup ); + CommonGroupLayout->setAlignment( Qt::AlignTop ); + CommonGroupLayout->setSpacing( 6 ); + CommonGroupLayout->setMargin( 11 ); + + QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup ); + aStartButton->setAutoDefault( true ); + aStartButton->setDefault( true ); + CommonGroupLayout->addWidget( aStartButton, 0, 0 ); + CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup ); + aCloseButton->setAutoDefault( true ); + CommonGroupLayout->addWidget( aCloseButton, 0, 2 ); + + //QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup ); + //aHelpButton->setAutoDefault( true ); + //CommonGroupLayout->addWidget( aHelpButton, 0, 3 ); + + aTopLayout->addWidget( CommonGroup ); + + connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) ); + connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) ); + //connect( aHelpButton, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); +} + +SVTK_RecorderDlg::~SVTK_RecorderDlg() +{ +} + +void SVTK_RecorderDlg::onStart() +{ + if( myFileName.isNull() ) + return; + + myRecorder->SetName( (const char*)myFileName.toLatin1() ); + + myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentIndex() == 0 ); + myRecorder->SetNbFPS( myFPSSpinBox->value() ); + myRecorder->SetQuality( myQualitySpinBox->value() ); + myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() ); + + accept(); + +} + +void SVTK_RecorderDlg::onClose() +{ + reject(); +} + +void SVTK_RecorderDlg::onHelp() +{ + /* + QString aHelpFileName = "animation_in_gauss_viewer.htm"; + LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); + if (app) + app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName); + else { + QString platform; +#ifdef WIN32 + platform = "winapplication"; +#else + platform = "application"; +#endif + SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"), + QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) ); + } + */ +} + +bool SVTK_RecorderDlg::onBrowseFile() +{ + QStringList aFilter; + aFilter.append( tr( "FLT_AVI_FILES" ) ); + aFilter.append( tr( "FLT_ALL_FILES" ) ); + + QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter, + tr( "FILE_NAME" ), false ); + + if( aFileName.isNull() ) + return false; + + myFileName = aFileName; + myFileNameLineEdit->setText( aFileName.section( '/', -1 ) ); + + return true; +} + +int SVTK_RecorderDlg::exec() +{ + if( !onBrowseFile() ) + { + reject(); + return 0; + } + return QDialog::exec(); +} + +void SVTK_RecorderDlg::keyPressEvent( QKeyEvent* e ) +{ + QDialog::keyPressEvent( e ); + if ( e->isAccepted() ) + return; + + if ( e->key() == Qt::Key_F1 ) + { + e->accept(); + onHelp(); + } +} diff --git a/src/SVTK/SVTK_RecorderDlg.h b/src/SVTK/SVTK_RecorderDlg.h new file mode 100644 index 000000000..93e19e660 --- /dev/null +++ b/src/SVTK/SVTK_RecorderDlg.h @@ -0,0 +1,71 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#ifndef SVTK_RECORDERDLG_H +#define SVTK_RECORDERDLG_H + +#include + +class QCheckBox; +class QComboBox; +class QGroupBox; +class QLCDNumber; +class QLineEdit; +class QPushButton; +class QTimer; + +class QtxDoubleSpinBox; +class QtxIntSpinBox; + +class SVTK_Recorder; + +class SVTK_RecorderDlg : public QDialog +{ + Q_OBJECT + +public: + SVTK_RecorderDlg( QWidget*, SVTK_Recorder* ); + ~SVTK_RecorderDlg(); + + int exec(); + + QString fileName() const { return myFileName; } + +private: + virtual void keyPressEvent( QKeyEvent* ); + +protected slots: + void onStart(); + void onClose(); + void onHelp(); + + bool onBrowseFile(); + +private: + SVTK_Recorder* myRecorder; + QString myFileName; + + QLineEdit* myFileNameLineEdit; + + QComboBox* myRecordingModeComboBox; + QtxDoubleSpinBox* myFPSSpinBox; + QtxIntSpinBox* myQualitySpinBox; + QCheckBox* myProgressiveCheckBox; +}; + +#endif diff --git a/src/SVTK/SVTK_SetRotationPointDlg.cxx b/src/SVTK/SVTK_SetRotationPointDlg.cxx index f6202845d..f29fb1f77 100755 --- a/src/SVTK/SVTK_SetRotationPointDlg.cxx +++ b/src/SVTK/SVTK_SetRotationPointDlg.cxx @@ -27,7 +27,7 @@ // $Header$ #include "SVTK_SetRotationPointDlg.h" -#include "SVTK_MainWindow.h" +#include "SVTK_ViewWindow.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_Event.h" #include "SVTK_InteractorStyle.h" @@ -53,7 +53,7 @@ using namespace std; */ SVTK_SetRotationPointDlg ::SVTK_SetRotationPointDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName): SVTK_DialogBase(theAction, theParent, diff --git a/src/SVTK/SVTK_SetRotationPointDlg.h b/src/SVTK/SVTK_SetRotationPointDlg.h index 57df00166..7fd700909 100755 --- a/src/SVTK/SVTK_SetRotationPointDlg.h +++ b/src/SVTK/SVTK_SetRotationPointDlg.h @@ -35,7 +35,7 @@ #include -class SVTK_MainWindow; +class SVTK_ViewWindow; class SVTK_RenderWindowInteractor; class QtxAction; @@ -54,7 +54,7 @@ class SVTK_EXPORT SVTK_SetRotationPointDlg : public SVTK_DialogBase public: SVTK_SetRotationPointDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName); ~SVTK_SetRotationPointDlg(); @@ -63,7 +63,7 @@ public: bool IsFirstShown(); protected: - SVTK_MainWindow *myMainWindow; + SVTK_ViewWindow *myMainWindow; SVTK_RenderWindowInteractor* myRWInteractor; bool myIsObserverAdded; diff --git a/src/SVTK/SVTK_UpdateRateDlg.cxx b/src/SVTK/SVTK_UpdateRateDlg.cxx index 4c5262ebc..2b91a1786 100644 --- a/src/SVTK/SVTK_UpdateRateDlg.cxx +++ b/src/SVTK/SVTK_UpdateRateDlg.cxx @@ -28,7 +28,7 @@ #include "SVTK_UpdateRateDlg.h" -#include "SVTK_MainWindow.h" +#include "SVTK_ViewWindow.h" #include "SVTK_RenderWindowInteractor.h" #include "VTKViewer_Algorithm.h" #include "SALOME_Actor.h" @@ -165,7 +165,7 @@ namespace */ SVTK_UpdateRateDlg ::SVTK_UpdateRateDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName): SVTK_DialogBase(theAction, theParent, diff --git a/src/SVTK/SVTK_UpdateRateDlg.h b/src/SVTK/SVTK_UpdateRateDlg.h index 761f75afe..7cc869b92 100644 --- a/src/SVTK/SVTK_UpdateRateDlg.h +++ b/src/SVTK/SVTK_UpdateRateDlg.h @@ -33,7 +33,7 @@ #include -class SVTK_MainWindow; +class SVTK_ViewWindow; class SVTK_RenderWindowInteractor; class QtxDoubleSpinBox; @@ -52,7 +52,7 @@ class SVTK_UpdateRateDlg : public SVTK_DialogBase public: SVTK_UpdateRateDlg(QtxAction* theAction, - SVTK_MainWindow* theParent, + SVTK_ViewWindow* theParent, const char* theName); ~SVTK_UpdateRateDlg(); diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 57e6e49eb..d9186b84c 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -30,7 +30,7 @@ #include "SVTK_View.h" #include "SVTK_Renderer.h" -#include "SVTK_MainWindow.h" +#include "SVTK_ViewWindow.h" #include "SVTK_RenderWindowInteractor.h" #include "SALOME_ListIteratorOfListIO.hxx" @@ -44,7 +44,7 @@ Constructor */ SVTK_SignalHandler -::SVTK_SignalHandler(SVTK_MainWindow* theMainWindow): +::SVTK_SignalHandler(SVTK_ViewWindow* theMainWindow): QObject(theMainWindow), myMainWindow(theMainWindow) { @@ -79,7 +79,7 @@ SVTK_SignalHandler /*! \return corresponding svtk main window */ -SVTK_MainWindow* +SVTK_ViewWindow* SVTK_SignalHandler ::GetMainWindow() { @@ -88,7 +88,7 @@ SVTK_SignalHandler /*! - Redirect the request to #SVTK_MainWindow::Repaint (just for flexibility) + Redirect the request to #SVTK_ViewWindow::Repaint (just for flexibility) */ void SVTK_SignalHandler @@ -98,7 +98,7 @@ SVTK_SignalHandler } /*! - Redirect the request to #SVTK_MainWindow::GetRenderer (just for flexibility) + Redirect the request to #SVTK_ViewWindow::GetRenderer (just for flexibility) */ SVTK_Renderer* SVTK_SignalHandler @@ -108,7 +108,7 @@ SVTK_SignalHandler } /*! - Redirect the request to #SVTK_MainWindow::getRenderer (just for flexibility) + Redirect the request to #SVTK_ViewWindow::getRenderer (just for flexibility) */ vtkRenderer* SVTK_SignalHandler @@ -164,7 +164,7 @@ SVTK_SignalHandler Constructor */ SVTK_View -::SVTK_View(SVTK_MainWindow* theMainWindow) : +::SVTK_View(SVTK_ViewWindow* theMainWindow) : SVTK_SignalHandler(theMainWindow) { } diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index ff463ab5e..7e31e56b2 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -31,7 +31,7 @@ class vtkActorCollection; class vtkRenderer; -class SVTK_MainWindow; +class SVTK_ViewWindow; class SVTK_Renderer; class SALOME_Actor; @@ -43,12 +43,12 @@ class QContextMenuEvent; class QColor; -//! Main purpose of the class is to provide a way to customize #SVTK_MainWindow. +//! Main purpose of the class is to provide a way to customize #SVTK_ViewWindow. /*! - This class is initialized by #SVTK_MainWindow and just pass Qt signals from - corresponding #SVTK_RenderWindowInteractor of the #SVTK_MainWindow. - Its main purpose is to provide a simple and flexible way to customize the #SVTK_MainWindow. - So, in your own viewer it is possible to derive new #SVTK_MainWindow and + This class is initialized by #SVTK_ViewWindow and just pass Qt signals from + corresponding #SVTK_RenderWindowInteractor of the #SVTK_ViewWindow. + Its main purpose is to provide a simple and flexible way to customize the #SVTK_ViewWindow. + So, in your own viewer it is possible to derive new #SVTK_ViewWindow and use existing functionality without any modifications. */ class SVTK_EXPORT SVTK_SignalHandler : public QObject @@ -56,26 +56,26 @@ class SVTK_EXPORT SVTK_SignalHandler : public QObject Q_OBJECT; public: - SVTK_SignalHandler(SVTK_MainWindow* theMainWindow); + SVTK_SignalHandler(SVTK_ViewWindow* theMainWindow); virtual ~SVTK_SignalHandler(); - //! Get reference to its #SVTK_MainWindow - SVTK_MainWindow* + //! Get reference to its #SVTK_ViewWindow + SVTK_ViewWindow* GetMainWindow(); //---------------------------------------------------------------------------- - //! Redirect the request to #SVTK_MainWindow::Repaint (just for flexibility) + //! Redirect the request to #SVTK_ViewWindow::Repaint (just for flexibility) void Repaint(bool theUpdateTrihedron = true); //---------------------------------------------------------------------------- - //! Redirect the request to #SVTK_MainWindow::GetRenderer (just for flexibility) + //! Redirect the request to #SVTK_ViewWindow::GetRenderer (just for flexibility) SVTK_Renderer* GetRenderer(); - //! Redirect the request to #SVTK_MainWindow::getRenderer (just for flexibility) + //! Redirect the request to #SVTK_ViewWindow::getRenderer (just for flexibility) vtkRenderer* getRenderer(); @@ -98,7 +98,7 @@ public: void selectionChanged(); protected: - SVTK_MainWindow* myMainWindow; + SVTK_ViewWindow* myMainWindow; }; @@ -113,7 +113,7 @@ class SVTK_EXPORT SVTK_View : public SVTK_SignalHandler Q_OBJECT; public: - SVTK_View(SVTK_MainWindow* theMainWindow); + SVTK_View(SVTK_ViewWindow* theMainWindow); virtual ~SVTK_View(); diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index b8edb171c..954d39f8b 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -25,20 +25,22 @@ #include //#include "SUIT_Session.h" -#include "SUIT_ViewModel.h" -#include "SUIT_ViewManager.h" - #include "SVTK_Selection.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" #include "SVTK_View.h" -#include "SVTK_MainWindow.h" +//#include "SVTK_MainWindow.h" #include "SVTK_Prs.h" #include "VTKViewer_ViewModel.h" +#include "SUIT_ViewModel.h" +#include "SUIT_ViewManager.h" + #include +#include + // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study. // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from // SALOMEDS::StudyManager - no linkage with SalomeApp. @@ -68,6 +70,13 @@ SVTK_Viewer::SVTK_Viewer() { myTrihedronSize = 105; myTrihedronRelative = true; + myIncrementSpeed = 10; + myIncrementMode = 0; + myProjMode = 0; + myStyle = 0; + mySpaceBtn[0] = 1; + mySpaceBtn[1] = 2; + mySpaceBtn[2] = 9; } /*! @@ -80,9 +89,7 @@ SVTK_Viewer::~SVTK_Viewer() /*! \return background color */ -QColor -SVTK_Viewer -::backgroundColor() const +QColor SVTK_Viewer::backgroundColor() const { return myBgColor; } @@ -91,9 +98,7 @@ SVTK_Viewer Changes background color \param theColor - new background color */ -void -SVTK_Viewer -::setBackgroundColor( const QColor& theColor ) +void SVTK_Viewer::setBackgroundColor( const QColor& theColor ) { if ( !theColor.isValid() ) return; @@ -113,15 +118,22 @@ SVTK_Viewer /*!Create new instance of view window on desktop \a theDesktop. *\retval SUIT_ViewWindow* - created view window pointer. */ -SUIT_ViewWindow* -SVTK_Viewer:: -createView( SUIT_Desktop* theDesktop ) +SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop ) { TViewWindow* aViewWindow = new TViewWindow(theDesktop); aViewWindow->Initialize(this); aViewWindow->setBackgroundColor( backgroundColor() ); aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() ); + aViewWindow->SetProjectionMode( projectionMode() ); + aViewWindow->SetInteractionStyle( interactionStyle() ); + aViewWindow->SetIncrementalSpeed( incrementalSpeed(), incrementalSpeedMode() ); + aViewWindow->SetSpacemouseButtons( spacemouseBtn(1), spacemouseBtn(2), spacemouseBtn(3) ); + + connect(aViewWindow, SIGNAL( actorAdded(VTKViewer_Actor*) ), + this, SLOT(onActorAdded(VTKViewer_Actor*))); + connect(aViewWindow, SIGNAL( actorRemoved(VTKViewer_Actor*) ), + this, SLOT(onActorRemoved(VTKViewer_Actor*))); return aViewWindow; } @@ -162,6 +174,129 @@ void SVTK_Viewer::setTrihedronSize( const vtkFloatingPointType theSize, const bo } } + +/*! + \return projection mode +*/ +int SVTK_Viewer::projectionMode() const +{ + return myProjMode; +} + + +/*! + Sets projection mode: 0 - orthogonal, 1 - perspective projection + \param theMode - new projection mode +*/ +void SVTK_Viewer::setProjectionMode( const int theMode ) +{ + if ( myProjMode != theMode ) { + myProjMode = theMode; + + if (SUIT_ViewManager* aViewManager = getViewManager()) { + QVector aViews = aViewManager->getViews(); + for ( uint i = 0; i < aViews.count(); i++ ) + { + if ( TViewWindow* aView = dynamic_cast(aViews.at( i )) ) + aView->SetProjectionMode( theMode ); + } + } + } +} + +/*! + \return interaction style +*/ +int SVTK_Viewer::interactionStyle() const +{ + return myStyle; +} + +/*! + Sets interaction style: 0 - standard, 1 - keyboard free interaction + \param theStyle - new interaction style +*/ +void SVTK_Viewer::setInteractionStyle( const int theStyle ) +{ + myStyle = theStyle; + + if (SUIT_ViewManager* aViewManager = getViewManager()) { + QVector aViews = aViewManager->getViews(); + for ( uint i = 0; i < aViews.count(); i++ ) + { + if ( TViewWindow* aView = dynamic_cast(aViews.at( i )) ) + aView->SetInteractionStyle( theStyle ); + } + } +} + +/*! + \return incremental speed value +*/ +int SVTK_Viewer::incrementalSpeed() const +{ + return myIncrementSpeed; +} + +/*! + \return modification mode of the incremental speed +*/ +int SVTK_Viewer::incrementalSpeedMode() const +{ + return myIncrementMode; +} + +/*! + Set the incremental speed value and modification mode + \param theValue - new value + \param theMode - new mode: 0 - arithmetic, 1 - geometrical progression +*/ +void SVTK_Viewer::setIncrementalSpeed( const int theValue, const int theMode ) +{ + myIncrementSpeed = theValue; + myIncrementMode = theMode; + + if (SUIT_ViewManager* aViewManager = getViewManager()) { + QVector aViews = aViewManager->getViews(); + for ( uint i = 0; i < aViews.count(); i++ ) + { + if ( TViewWindow* aView = dynamic_cast(aViews.at( i )) ) + aView->SetIncrementalSpeed( theValue, theMode ); + } + } +} + +/*! + \return spacemouse button assigned to the specified function + \param theIndex - function by number (from 1 to 3) +*/ +int SVTK_Viewer::spacemouseBtn( const int theIndex ) const +{ + if ( theIndex < 1 || theIndex > 3 ) + return -1; + return mySpaceBtn[theIndex-1]; +} + +/*! + Set the spacemouse buttons + \param theBtn1, theBtn2, theBtn3 - new buttons +*/ +void SVTK_Viewer::setSpacemouseButtons( const int theBtn1, const int theBtn2, const int theBtn3 ) +{ + mySpaceBtn[0] = theBtn1; + mySpaceBtn[1] = theBtn2; + mySpaceBtn[2] = theBtn3; + + if (SUIT_ViewManager* aViewManager = getViewManager()) { + QVector aViews = aViewManager->getViews(); + for ( uint i = 0; i < aViews.count(); i++ ) + { + if ( TViewWindow* aView = dynamic_cast(aViews.at( i )) ) + aView->SetSpacemouseButtons( theBtn1, theBtn2, theBtn3 ); + } + } +} + /*! Sets new view manager \param theViewManager - new view manager @@ -186,9 +321,7 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) /*! Builds popup for vtk viewer */ -void -SVTK_Viewer -::contextMenuPopup( QMenu* thePopup ) +void SVTK_Viewer::contextMenuPopup( QMenu* thePopup ) { thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); @@ -208,34 +341,26 @@ SVTK_Viewer /*! SLOT: called on mouse button press, empty implementation */ -void -SVTK_Viewer -::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) +void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) {} /*! SLOT: called on mouse move, empty implementation */ -void -SVTK_Viewer -::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event) +void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event) {} /*! SLOT: called on mouse button release, empty implementation */ -void -SVTK_Viewer -::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) +void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) {} /*! Enables/disables selection \param isEnabled - new state */ -void -SVTK_Viewer -::enableSelection(bool isEnabled) +void SVTK_Viewer::enableSelection(bool isEnabled) { mySelectionEnabled = isEnabled; //!! To be done for view windows @@ -245,9 +370,7 @@ SVTK_Viewer Enables/disables selection of many object \param isEnabled - new state */ -void -SVTK_Viewer -::enableMultiselection(bool isEnable) +void SVTK_Viewer::enableMultiselection(bool isEnable) { myMultiSelectionEnabled = isEnable; //!! To be done for view windows @@ -256,9 +379,7 @@ SVTK_Viewer /*! SLOT: called on dump view operation is activated, stores scene to raster file */ -void -SVTK_Viewer -::onDumpView() +void SVTK_Viewer::onDumpView() { if(SUIT_ViewWindow* aView = myViewManager->getActiveView()) aView->onDumpView(); @@ -267,9 +388,7 @@ SVTK_Viewer /*! SLOT: called if background color is to be changed changed, passes new color to view port */ -void -SVTK_Viewer -::onChangeBgColor() +void SVTK_Viewer::onChangeBgColor() { if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){ QColor aColor = QColorDialog::getColor( backgroundColor(), aView); @@ -281,9 +400,7 @@ SVTK_Viewer Display presentation \param prs - presentation */ -void -SVTK_Viewer -::Display( const SALOME_VTKPrs* prs ) +void SVTK_Viewer::Display( const SALOME_VTKPrs* prs ) { // try do downcast object if(const SVTK_Prs* aPrs = dynamic_cast( prs )){ @@ -330,9 +447,7 @@ SVTK_Viewer \param prs - presentation \param forced - removes object from view */ -void -SVTK_Viewer -::Erase( const SALOME_VTKPrs* prs, const bool forced ) +void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced ) { // try do downcast object if(const SVTK_Prs* aPrs = dynamic_cast( prs )){ @@ -374,9 +489,7 @@ SVTK_Viewer Erase all presentations \param forced - removes all objects from view */ -void -SVTK_Viewer -::EraseAll( const bool forced ) +void SVTK_Viewer::EraseAll( const bool forced ) { // Temporarily commented to avoid awful dependecy on SALOMEDS // TODO: better mechanism of storing display/erse status in a study @@ -422,9 +535,7 @@ SVTK_Viewer Create presentation corresponding to the entry \param entry - entry */ -SALOME_Prs* -SVTK_Viewer -::CreatePrs( const char* entry ) +SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry ) { SVTK_Prs* prs = new SVTK_Prs(); if ( entry ) { @@ -448,9 +559,7 @@ SVTK_Viewer /*! Auxiliary method called before displaying of objects */ -void -SVTK_Viewer -::BeforeDisplay( SALOME_Displayer* d ) +void SVTK_Viewer::BeforeDisplay( SALOME_Displayer* d ) { d->BeforeDisplay( this, SALOME_VTKViewType() ); } @@ -458,8 +567,7 @@ SVTK_Viewer /*! Auxiliary method called after displaying of objects */ -void -SVTK_Viewer::AfterDisplay( SALOME_Displayer* d ) +void SVTK_Viewer::AfterDisplay( SALOME_Displayer* d ) { d->AfterDisplay( this, SALOME_VTKViewType() ); } @@ -468,9 +576,7 @@ SVTK_Viewer::AfterDisplay( SALOME_Displayer* d ) \return true if object is displayed in viewer \param obj - object to be checked */ -bool -SVTK_Viewer -::isVisible( const Handle(SALOME_InteractiveObject)& io ) +bool SVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& io ) { QVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) @@ -486,9 +592,7 @@ SVTK_Viewer /*! Updates current viewer */ -void -SVTK_Viewer -::Repaint() +void SVTK_Viewer::Repaint() { // if (theUpdateTrihedron) onAdjustTrihedron(); QVector aViews = myViewManager->getViews(); @@ -497,3 +601,14 @@ SVTK_Viewer if(SVTK_View* aView = aViewWindow->getView()) aView->Repaint(); } + + +void SVTK_Viewer::onActorAdded(VTKViewer_Actor* theActor) +{ + emit actorAdded((SVTK_ViewWindow*)sender(), theActor); +} + +void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor) +{ + emit actorRemoved((SVTK_ViewWindow*)sender(), theActor); +} diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index a76da1dbc..e37d32401 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -26,10 +26,12 @@ #include "SALOME_InteractiveObject.hxx" #include +#include class QMouseEvent; class SVTK_ViewWindow; +class VTKViewer_Actor; //! Extends two interfaces #SVTK_ViewModelBase and #SALOME_View class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View @@ -72,6 +74,33 @@ public: //! Set size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize) void setTrihedronSize( const vtkFloatingPointType, const bool = true ); + //! Gets projection mode + int projectionMode() const; + + //! Sets projection mode + void setProjectionMode( const int ); + + //! Gets interaction style + int interactionStyle() const; + + //! Sets interaction style + void setInteractionStyle( const int ); + + //! Get incremental speed (see #SVTK_InteractorStyle::ControllerIncrement) + int incrementalSpeed() const; + + //! Returns modification mode of incremental speed (see #SVTK_InteractorStyle::ControllerIncrement) + int incrementalSpeedMode() const; + + //! Set the incremental speed for view operation (see #SVTK_InteractorStyle::ControllerIncrement) + void setIncrementalSpeed( const int, const int = 0 ); + + //! Gets spacemouse button for specified function + int spacemouseBtn( const int ) const; + + //! Sets spacemouse buttons + void setSpacemouseButtons( const int, const int, const int ); + public: void enableSelection(bool isEnabled); bool isSelectionEnabled() const { return mySelectionEnabled; } @@ -107,6 +136,10 @@ public: //! See #SALOME_View::Repaint() virtual void Repaint(); + signals: + void actorAdded(SVTK_ViewWindow*, VTKViewer_Actor*); + void actorRemoved(SVTK_ViewWindow*, VTKViewer_Actor*); + protected slots: void onMousePress(SUIT_ViewWindow*, QMouseEvent*); void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); @@ -115,12 +148,23 @@ protected slots: void onDumpView(); void onChangeBgColor(); + void onActorAdded(VTKViewer_Actor*); + void onActorRemoved(VTKViewer_Actor*); + private: + void updateToolBars(); + + QColor myBgColor; vtkFloatingPointType myTrihedronSize; bool myTrihedronRelative; bool mySelectionEnabled; bool myMultiSelectionEnabled; + int myIncrementSpeed; + int myIncrementMode; + int myProjMode; + int myStyle; + int mySpaceBtn[3]; }; #endif diff --git a/src/SVTK/SVTK_ViewParameterDlg.cxx b/src/SVTK/SVTK_ViewParameterDlg.cxx new file mode 100755 index 000000000..7a7a9d25c --- /dev/null +++ b/src/SVTK/SVTK_ViewParameterDlg.cxx @@ -0,0 +1,743 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : +// Author : +// Module : SALOME +// $Header: + +#include "SVTK_ViewParameterDlg.h" +#include "SVTK_ViewWindow.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_Event.h" +#include "SVTK_InteractorStyle.h" + +#include "VTKViewer_Utilities.h" + +#include "QtxAction.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +/*! + Constructor +*/ +SVTK_ViewParameterDlg::SVTK_ViewParameterDlg(QtxAction* theAction, + SVTK_ViewWindow* theParent, + const char* theName): + SVTK_DialogBase(theAction, theParent, theName), + myMainWindow(theParent), + myPriority(0.0), + myEventCallbackCommand(vtkCallbackCommand::New()), + myRWInteractor(theParent->GetInteractor()) +{ + setWindowTitle(tr("DLG_TITLE")); + setSizeGripEnabled(TRUE); + + // Top layout + QVBoxLayout* aTopLayout = new QVBoxLayout(this); + aTopLayout->setSpacing(6); + aTopLayout->setMargin(11); + + // Projection mode + QGroupBox* aGroupBoxMode = new QGroupBox(tr("PROJECTION_MODE"), this); + QHBoxLayout* aLayout1 = new QHBoxLayout(aGroupBoxMode); + + QRadioButton* aOrtho = new QRadioButton(tr("ORTHOGONAL_MODE"), aGroupBoxMode); + QRadioButton* aPersp = new QRadioButton(tr("PERSPECTIVE_MODE"), aGroupBoxMode); + + aLayout1->addWidget(aOrtho); + aLayout1->addWidget(aPersp); + + myProjectionMode = new QButtonGroup(aGroupBoxMode); + myProjectionMode->addButton(aOrtho, 0); + myProjectionMode->addButton(aPersp, 1); + connect(myProjectionMode, SIGNAL(buttonClicked(int)), SLOT(onProjectionModeChanged(int))); + + // Focal point + QGroupBox* aGroupBoxFocal = new QGroupBox(tr("FOCAL_POINT"), this); + QVBoxLayout* aLayout2 = new QVBoxLayout(aGroupBoxFocal); + + myToBBCenter = new QPushButton(aGroupBoxFocal); + myToBBCenter->setText(tr("LBL_TOBBCENTER")); + aLayout2->addWidget(myToBBCenter); + connect(myToBBCenter, SIGNAL(clicked()), this, SLOT(onToBBCenter())); + + myToOrigin = new QPushButton(aGroupBoxFocal); + myToOrigin->setText(tr("LBL_TOORIGIN")); + aLayout2->addWidget(myToOrigin); + connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin())); + + mySelectPoint = new QPushButton(aGroupBoxFocal); + mySelectPoint->setText(tr("LBL_SELECTPOINT")); + mySelectPoint->setCheckable(true); + aLayout2->addWidget(mySelectPoint); + connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint())); + + // Focal point coordinates + myFocalCoords = new QFrame(aGroupBoxFocal); + myFocalCoords->setObjectName("FocalPointCoordinates"); + + QHBoxLayout* aCoordLayout = new QHBoxLayout(myFocalCoords); + aCoordLayout->setSpacing(6); + aCoordLayout->setMargin(0); + + QLabel* aLabelX = new QLabel(tr("LBL_X"), myFocalCoords); + aLabelX->setFixedWidth(25); + myFocalX = new QLineEdit(myFocalCoords); + myFocalX->setValidator(new QDoubleValidator(myFocalX)); + myFocalX->setText(QString::number(0.0)); + connect(myFocalX, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged())); + + QLabel* aLabelY = new QLabel(tr("LBL_Y"), myFocalCoords); + aLabelY->setFixedWidth(25); + myFocalY = new QLineEdit(myFocalCoords); + myFocalY->setValidator(new QDoubleValidator(myFocalY)); + myFocalY->setText(QString::number(0.0)); + connect(myFocalY, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged())); + + QLabel* aLabelZ = new QLabel(tr("LBL_Z"), myFocalCoords); + aLabelZ->setFixedWidth(25); + myFocalZ = new QLineEdit(myFocalCoords); + myFocalZ->setValidator(new QDoubleValidator(myFocalZ)); + myFocalZ->setText(QString::number(0.0)); + connect(myFocalZ, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged())); + + aCoordLayout->addWidget(aLabelX); + aCoordLayout->addWidget(myFocalX); + aCoordLayout->addWidget(aLabelY); + aCoordLayout->addWidget(myFocalY); + aCoordLayout->addWidget(aLabelZ); + aCoordLayout->addWidget(myFocalZ); + aLayout2->addWidget(myFocalCoords); + + // Camera position + QGroupBox* aGroupBoxCamera = new QGroupBox(tr("CAMERA_POSITION"), this); + QVBoxLayout* aLayout3 = new QVBoxLayout(aGroupBoxCamera); + + QRadioButton* aWorld = new QRadioButton(tr("WORLD_COORDINATES"), aGroupBoxCamera); + QRadioButton* aRelative = new QRadioButton(tr("FOCAL_RELATIVE"), aGroupBoxCamera); + + QHBoxLayout* aHLayout = new QHBoxLayout; + aHLayout->addWidget(aWorld); + aHLayout->addWidget(aRelative); + aLayout3->addLayout(aHLayout); + + myCameraPositionMode = new QButtonGroup(aGroupBoxCamera); + myCameraPositionMode->addButton(aWorld, 0); + myCameraPositionMode->addButton(aRelative, 1); + connect(myCameraPositionMode, SIGNAL(buttonClicked(int)), SLOT(onPositionModeChanged(int))); + + // Camera coordinates + myCameraCoords = new QFrame(aGroupBoxCamera); + myCameraCoords->setObjectName("CameraCoordinates"); + + aCoordLayout = new QHBoxLayout(myCameraCoords); + aCoordLayout->setSpacing(6); + aCoordLayout->setMargin(0); + + aLabelX = new QLabel(tr("LBL_X"), myCameraCoords); + aLabelX->setFixedWidth(25); + myCameraX = new QLineEdit(myCameraCoords); + myCameraX->setValidator(new QDoubleValidator(myCameraX)); + myCameraX->setText(QString::number(0.0)); + connect(myCameraX, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged())); + + aLabelY = new QLabel(tr("LBL_Y"), myCameraCoords); + aLabelY->setFixedWidth(25); + myCameraY = new QLineEdit(myCameraCoords); + myCameraY->setValidator(new QDoubleValidator(myCameraY)); + myCameraY->setText(QString::number(0.0)); + connect(myCameraY, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged())); + + aLabelZ = new QLabel(tr("LBL_Z"), myCameraCoords); + aLabelZ->setFixedWidth(25); + myCameraZ = new QLineEdit(myCameraCoords); + myCameraZ->setValidator(new QDoubleValidator(myCameraZ)); + myCameraZ->setText(QString::number(1.0)); + connect(myCameraZ, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged())); + + aCoordLayout->addWidget(aLabelX); + aCoordLayout->addWidget(myCameraX); + aCoordLayout->addWidget(aLabelY); + aCoordLayout->addWidget(myCameraY); + aCoordLayout->addWidget(aLabelZ); + aCoordLayout->addWidget(myCameraZ); + aLayout3->addWidget(myCameraCoords); + + // Projection direction + QFrame* line1 = new QFrame(aGroupBoxCamera); + line1->setFrameStyle(QFrame::HLine | QFrame::Sunken); + aLayout3->addWidget(line1); + + QLabel* aLabel = new QLabel(tr("PROJECTION_DIRECTION"), aGroupBoxCamera); + aLayout3->addWidget(aLabel); + + myProjDirection = new QFrame(aGroupBoxCamera); + myProjDirection->setObjectName("ProjectionDirection"); + + aCoordLayout = new QHBoxLayout(myProjDirection); + aCoordLayout->setSpacing(6); + aCoordLayout->setMargin(0); + + aLabelX = new QLabel(tr("LBL_DX"), myProjDirection); + aLabelX->setFixedWidth(25); + myProjDirX = new QLineEdit(myProjDirection); + myProjDirX->setValidator(new QDoubleValidator(myProjDirX)); + myProjDirX->setText(QString::number(0.0)); + connect(myProjDirX, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged())); + + aLabelY = new QLabel(tr("LBL_DY"), myProjDirection); + aLabelY->setFixedWidth(25); + myProjDirY = new QLineEdit(myProjDirection); + myProjDirY->setValidator(new QDoubleValidator(myProjDirY)); + myProjDirY->setText(QString::number(0.0)); + connect(myProjDirY, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged())); + + aLabelZ = new QLabel(tr("LBL_DZ"), myProjDirection); + aLabelZ->setFixedWidth(25); + myProjDirZ = new QLineEdit(myProjDirection); + myProjDirZ->setValidator(new QDoubleValidator(myProjDirZ)); + myProjDirZ->setText(QString::number(-1.0)); + connect(myProjDirZ, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged())); + + aCoordLayout->addWidget(aLabelX); + aCoordLayout->addWidget(myProjDirX); + aCoordLayout->addWidget(aLabelY); + aCoordLayout->addWidget(myProjDirY); + aCoordLayout->addWidget(aLabelZ); + aCoordLayout->addWidget(myProjDirZ); + aLayout3->addWidget(myProjDirection); + + // Distance to focal point + QHBoxLayout* aHorLayout = new QHBoxLayout; + aHorLayout->setSpacing(6); + + aLabel = new QLabel(tr("FOCAL_DISTANCE"), aGroupBoxCamera); + myDistance = new QLineEdit(aGroupBoxCamera); + QDoubleValidator* aVal = new QDoubleValidator(myDistance); + aVal->setBottom(0.0002); // VTK minimal distance + myDistance->setValidator(aVal); + myDistance->setText(QString::number(1.0)); + connect(myDistance, SIGNAL(textChanged(const QString&)), SLOT(onDistanceChanged())); + + aHorLayout->addWidget(aLabel); + aHorLayout->addWidget(myDistance); + aLayout3->addLayout(aHorLayout); + + // View Up direction + QFrame* line2 = new QFrame(aGroupBoxCamera); + line2->setFrameStyle(QFrame::HLine | QFrame::Sunken); + aLayout3->addWidget(line2); + + aLabel = new QLabel(tr("VIEW_UP_DIRECTION"), aGroupBoxCamera); + aLayout3->addWidget(aLabel); + + myViewDirection = new QFrame(aGroupBoxCamera); + myViewDirection->setObjectName("ViewUpDirection"); + aLayout3->addWidget(myViewDirection); + + aCoordLayout = new QHBoxLayout(myViewDirection); + aCoordLayout->setSpacing(6); + aCoordLayout->setMargin(0); + + aLabelX = new QLabel(tr("LBL_DX"), myViewDirection); + aLabelX->setFixedWidth(25); + myViewDirX = new QLineEdit(myViewDirection); + myViewDirX->setValidator(new QDoubleValidator(myViewDirX)); + myViewDirX->setText(QString::number(0.0)); + connect(myViewDirX, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged())); + + aLabelY = new QLabel(tr("LBL_DY"), myViewDirection); + aLabelY->setFixedWidth(25); + myViewDirY = new QLineEdit(myViewDirection); + myViewDirY->setValidator(new QDoubleValidator(myViewDirY)); + myViewDirY->setText(QString::number(1.0)); + connect(myViewDirY, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged())); + + aLabelZ = new QLabel(tr("LBL_DZ"), myViewDirection); + aLabelZ->setFixedWidth(25); + myViewDirZ = new QLineEdit(myViewDirection); + myViewDirZ->setValidator(new QDoubleValidator(myViewDirZ)); + myViewDirZ->setText(QString::number(0.0)); + connect(myViewDirZ, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged())); + + aCoordLayout->addWidget(aLabelX); + aCoordLayout->addWidget(myViewDirX); + aCoordLayout->addWidget(aLabelY); + aCoordLayout->addWidget(myViewDirY); + aCoordLayout->addWidget(aLabelZ); + aCoordLayout->addWidget(myViewDirZ); + + // Zooming + QGroupBox* aGroupBoxZoom = new QGroupBox(tr("ZOOMING"), this); + QVBoxLayout* aLayout4 = new QVBoxLayout(aGroupBoxZoom); + + // Parallel scale + myScaleBox = new QFrame(aGroupBoxZoom); + myScaleBox->setObjectName("ScaleValue"); + + aHorLayout = new QHBoxLayout(myScaleBox); + aHorLayout->setSpacing(6); + aHorLayout->setMargin(0); + + aLabel = new QLabel(tr("LBL_SCALE"), myScaleBox); + myScale = new QLineEdit(myScaleBox); + QDoubleValidator* aVal2 = new QDoubleValidator(myScale); + aVal2->setBottom(0.000001); // VTK minimal scale + myScale->setValidator(aVal2); + myScale->setText(QString::number(1.0)); + connect(myScale, SIGNAL(textChanged(const QString&)), SLOT(onZoomChanged())); + + aHorLayout->addWidget(aLabel); + aHorLayout->addWidget(myScale); + aLayout4->addWidget(myScaleBox); + + // View Angle + myViewAngleBox = new QFrame(aGroupBoxZoom); + myViewAngleBox->setObjectName("ViewAngle"); + + aHorLayout = new QHBoxLayout(myViewAngleBox); + aHorLayout->setSpacing(6); + aHorLayout->setMargin(0); + + aLabel = new QLabel(tr("LBL_VIEW_ANGLE"), myViewAngleBox); + myViewAngle = new QLineEdit(myViewAngleBox); + QDoubleValidator* aVal3 = new QDoubleValidator(myViewAngle); + aVal3->setBottom(0.000001); // VTK minimal scale + aVal3->setTop(179); // VTK minimal scale + myViewAngle->setValidator(aVal3); + myViewAngle->setText(QString::number(30.0)); + connect(myViewAngle, SIGNAL(textChanged(const QString&)), SLOT(onZoomChanged())); + + aHorLayout->addWidget(aLabel); + aHorLayout->addWidget(myViewAngle); + aLayout4->addWidget(myViewAngleBox); + + // "Close" button + QGroupBox* aGroupBox = new QGroupBox(this); + QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox); + aHBoxLayout2->setMargin(11); + aHBoxLayout2->setSpacing(6); + + QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox ); + m_bClose->setObjectName("m_bClose"); + m_bClose->setAutoDefault(TRUE); + m_bClose->setFixedSize(m_bClose->sizeHint()); + connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose())); + + // Layout buttons + aHBoxLayout2->addWidget(m_bClose); + + // Layout top level widgets + aTopLayout->addWidget(aGroupBoxMode); + aTopLayout->addWidget(aGroupBoxFocal); + aTopLayout->addWidget(aGroupBoxCamera); + aTopLayout->addWidget(aGroupBoxZoom); + aTopLayout->addWidget(aGroupBox); + aTopLayout->addStretch(); + + // initial state + myProjectionMode->button(0)->setChecked(true); + myCameraPositionMode->button(0)->setChecked(true); + + setEnabled(myCameraCoords, myCameraPositionMode->checkedId() == 0); + + myScaleBox->setVisible(myProjectionMode->checkedId() == 0); + myViewAngleBox->setVisible(myProjectionMode->checkedId() == 1); + + updateData(); + + this->resize(400, this->sizeHint().height()); + + myEventCallbackCommand->Delete(); + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(SVTK_ViewParameterDlg::ProcessEvents); + myIsObserverAdded = false; + myBusy = false; +} + +/* + * Destroys the object and frees any allocated resources + */ +SVTK_ViewParameterDlg::~SVTK_ViewParameterDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +void SVTK_ViewParameterDlg::addObserver() +{ + if ( !myIsObserverAdded ) { + vtkInteractorStyle* aIStyle = myRWInteractor->GetInteractorStyle(); + aIStyle->AddObserver(SVTK::FocalPointChanged, myEventCallbackCommand.GetPointer(), myPriority); + + vtkRenderer *aRenderer = myRWInteractor->getRenderer(); + aRenderer->AddObserver(vtkCommand::EndEvent, myEventCallbackCommand.GetPointer(), myPriority); + + myIsObserverAdded = true; + } +} + +/*! + Processes events +*/ +void SVTK_ViewParameterDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* theCallData) +{ + SVTK_ViewParameterDlg* self = reinterpret_cast(theClientData); + vtkFloatingPointType* aCoord; + switch ( theEvent ) { + case SVTK::FocalPointChanged: + if ( theCallData ) + { + aCoord = (vtkFloatingPointType*)theCallData; + self->myBusy = true; + self->myFocalX->setText( QString::number(aCoord[0]) ); + self->myFocalY->setText( QString::number(aCoord[1]) ); + self->myFocalZ->setText( QString::number(aCoord[2]) ); + self->myBusy = false; + self->onFocalCoordChanged(); + } + break; + case vtkCommand::EndEvent: + if ( self->myRWInteractor->getRenderer()->GetActiveCamera()->GetMTime() > self->myCameraMTime ) + self->updateData(); + break; + } +} + +void SVTK_ViewParameterDlg::updateData() +{ + myBusy = true; + vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); + + int aParallel = aCamera->GetParallelProjection(); + myProjectionMode->button(aParallel?0:1)->setChecked(true); + onProjectionModeChanged( myProjectionMode->checkedId() ); + + double focal[3], pos[3], vup[3], proj[3], dist, scale, angle; + + aCamera->GetFocalPoint(focal); + myFocalX->setText(QString::number(focal[0])); + myFocalY->setText(QString::number(focal[1])); + myFocalZ->setText(QString::number(focal[2])); + + aCamera->GetPosition(pos); + myCameraX->setText(QString::number(pos[0])); + myCameraY->setText(QString::number(pos[1])); + myCameraZ->setText(QString::number(pos[2])); + + aCamera->GetDirectionOfProjection(proj); + myProjDirX->setText(QString::number(proj[0])); + myProjDirY->setText(QString::number(proj[1])); + myProjDirZ->setText(QString::number(proj[2])); + + aCamera->GetViewUp(vup); + myViewDirX->setText(QString::number(vup[0])); + myViewDirY->setText(QString::number(vup[1])); + myViewDirZ->setText(QString::number(vup[2])); + + dist = aCamera->GetDistance(); + myDistance->setText(QString::number(dist)); + + scale = aCamera->GetParallelScale(); + myScale->setText(QString::number(scale)); + + angle = aCamera->GetViewAngle(); + myViewAngle->setText(QString::number(angle)); + + myCameraMTime.Modified(); + myBusy = false; +} + +void SVTK_ViewParameterDlg::setEnabled(QFrame* theWidget, const bool theState) +{ + QObjectList aChildren(theWidget->children()); + QObject* anObj; + for(int i = 0; i < aChildren.size(); i++) + { + anObj = aChildren.at(i); + if (anObj !=0 && anObj->inherits("QLineEdit")) + ((QLineEdit*)anObj)->setReadOnly(!theState); + if (anObj !=0 && anObj->inherits("QPushButton")) + ((QLineEdit*)anObj)->setEnabled(theState); + } + +} + +void SVTK_ViewParameterDlg::onProjectionModeChanged(int mode) +{ + int aBtn = myProjectionMode->checkedId(); + + vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); + aCamera->SetParallelProjection(aBtn == 0); + + myMainWindow->activateProjectionMode(aBtn); + + // update view + myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); + + if ( aBtn == 0 ) { + myViewAngleBox->setVisible(false); + myScaleBox->setVisible(true); + } + else { + myScaleBox->setVisible(false); + myViewAngleBox->setVisible(true); + } +} + +void SVTK_ViewParameterDlg::onPositionModeChanged(int mode) +{ + setEnabled(myCameraCoords, myCameraPositionMode->checkedId() == 0); +} + +void SVTK_ViewParameterDlg::onToBBCenter() +{ + if ( mySelectPoint->isChecked() ) + mySelectPoint->toggle(); + + myMainWindow->activateSetFocalPointGravity(); +} + +void SVTK_ViewParameterDlg::onToOrigin() +{ + if ( mySelectPoint->isChecked() ) + mySelectPoint->toggle(); + + myBusy = true; + myFocalX->setText(QString::number(0.0)); + myFocalY->setText(QString::number(0.0)); + myFocalZ->setText(QString::number(0.0)); + myBusy = false; + + onFocalCoordChanged(); +} + +void SVTK_ViewParameterDlg::onSelectPoint() +{ + if ( mySelectPoint->isChecked() ) + myMainWindow->activateStartFocalPointSelection(); + else + mySelectPoint->toggle(); +} + +void SVTK_ViewParameterDlg::onFocalCoordChanged() +{ + if ( myBusy ) return; + + if ( mySelectPoint->isChecked() ) + mySelectPoint->toggle(); + + vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); + aCamera->SetFocalPoint(myFocalX->text().toDouble(), + myFocalY->text().toDouble(), + myFocalZ->text().toDouble()); + + aCamera->OrthogonalizeViewUp(); + myRWInteractor->getRenderer()->ResetCameraClippingRange(); + + // update view + myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); + + myMainWindow->activateSetFocalPointSelected(); + + //updateProjection(); +} + +void SVTK_ViewParameterDlg::onCameraCoordChanged() +{ + if ( myBusy ) return; + + vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); + aCamera->SetPosition(myCameraX->text().toDouble(), + myCameraY->text().toDouble(), + myCameraZ->text().toDouble()); + + aCamera->OrthogonalizeViewUp(); + myRWInteractor->getRenderer()->ResetCameraClippingRange(); + + // update view + myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); + + //updateProjection(); +} + +void SVTK_ViewParameterDlg::onDirectionChanged() +{ + if ( myBusy ) return; + + updateCoordinates(); +} + +void SVTK_ViewParameterDlg::onDistanceChanged() +{ + if ( myBusy ) return; + + updateCoordinates(); +} + +void SVTK_ViewParameterDlg::onViewDirectionChanged() +{ + if ( myBusy ) return; + + vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); + aCamera->SetViewUp(myViewDirX->text().toDouble(), + myViewDirY->text().toDouble(), + myViewDirZ->text().toDouble()); + + // update view + myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); +} + +void SVTK_ViewParameterDlg::onZoomChanged() +{ + if ( myBusy ) return; + + vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); + + switch( myProjectionMode->checkedId() ) { + case 0: + aCamera->SetParallelScale(myScale->text().toDouble()); + break; + case 1: + aCamera->SetViewAngle(myViewAngle->text().toDouble()); + break; + } + + // update view + myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); +} + +void SVTK_ViewParameterDlg::onClickClose() +{ + reject(); +} + +void SVTK_ViewParameterDlg::updateProjection() +{ + double pnt[3], pos[3], dir[3], dist; + + pnt[0] = myFocalX->text().toDouble(); + pnt[1] = myFocalY->text().toDouble(); + pnt[2] = myFocalZ->text().toDouble(); + + pos[0] = myCameraX->text().toDouble(); + pos[1] = myCameraY->text().toDouble(); + pos[2] = myCameraZ->text().toDouble(); + + dir[0] = pnt[0] - pos[0]; + dir[1] = pnt[1] - pos[1]; + dir[2] = pnt[2] - pos[2]; + + dist = sqrt( dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2] ); + + if ( dist > 0.0002 ) { + dir[0] = dir[0] / dist; + dir[1] = dir[1] / dist; + dir[2] = dir[2] / dist; + } + + myBusy = true; + myProjDirX->setText(QString::number(dir[0])); + myProjDirY->setText(QString::number(dir[1])); + myProjDirZ->setText(QString::number(dir[2])); + + myDistance->setText(QString::number(dist)); + myBusy = false; +} + +void SVTK_ViewParameterDlg::updateCoordinates() +{ + double pnt[3], pos[3], dir[3], dist; + + pnt[0] = myFocalX->text().toDouble(); + pnt[1] = myFocalY->text().toDouble(); + pnt[2] = myFocalZ->text().toDouble(); + + pos[0] = myCameraX->text().toDouble(); + pos[1] = myCameraY->text().toDouble(); + pos[2] = myCameraZ->text().toDouble(); + + dir[0] = myProjDirX->text().toDouble(); + dir[1] = myProjDirY->text().toDouble(); + dir[2] = myProjDirZ->text().toDouble(); + + dist = myDistance->text().toDouble(); + + if (myCameraPositionMode->checkedId() == 1) { + // recompute camera position + dir[0] = -dir[0]; dir[1] = -dir[1]; dir[2] = -dir[2]; + if (computePoint(pnt, dir, dist, pos)) { + myBusy = true; + myCameraX->setText(QString::number(pos[0])); + myCameraY->setText(QString::number(pos[1])); + myCameraZ->setText(QString::number(pos[2])); + myBusy = false; + onCameraCoordChanged(); + } + } + else { + // recompute focal point + if (computePoint(pos, dir, dist, pnt)) { + if (mySelectPoint->isChecked()) + mySelectPoint->toggle(); + myBusy = true; + myFocalX->setText(QString::number(pnt[0])); + myFocalY->setText(QString::number(pnt[1])); + myFocalZ->setText(QString::number(pnt[2])); + myBusy = false; + onFocalCoordChanged(); + } + } +} + +bool SVTK_ViewParameterDlg::computePoint(const double start[3], + const double dir[3], + const double dist, + double result[3]) +{ + double d = sqrt(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]); + if ( d < 0.0002 ) return false; + + for (int i = 0; i < 3; i++) + result[i] = start[i] + dir[i] * dist / d; + + return true; +} diff --git a/src/SVTK/SVTK_ViewParameterDlg.h b/src/SVTK/SVTK_ViewParameterDlg.h new file mode 100755 index 000000000..4ad77f3f4 --- /dev/null +++ b/src/SVTK/SVTK_ViewParameterDlg.h @@ -0,0 +1,153 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : +// Author : +// Module : SALOME +// $Header: + +#ifndef SVTK_VIEWPARAMETERDLG_H +#define SVTK_VIEWPARAMETERDLG_H + +#include "SVTK.h" + +#include "SVTK_DialogBase.h" + +#include +#include + +class SVTK_ViewWindow; +class SVTK_RenderWindowInteractor; + +class QtxAction; + +class QLineEdit; +class QPushButton; +class QFrame; +class QCheckBox; +class QButtonGroup; + +class vtkCallbackCommand; +class vtkObject; + +class SVTK_EXPORT SVTK_ViewParameterDlg : public SVTK_DialogBase +{ + Q_OBJECT; + +public: + SVTK_ViewParameterDlg(QtxAction* theAction, + SVTK_ViewWindow* theParent, + const char* theName); + + ~SVTK_ViewParameterDlg(); + + void addObserver(); + +protected: + SVTK_ViewWindow *myMainWindow; + SVTK_RenderWindowInteractor* myRWInteractor; + bool myIsObserverAdded; + bool myBusy; + + QButtonGroup* myProjectionMode; + + QPushButton* myToBBCenter; + QPushButton* myToOrigin; + QPushButton* mySelectPoint; + + QFrame* myFocalCoords; + QLineEdit* myFocalX; + QLineEdit* myFocalY; + QLineEdit* myFocalZ; + + QButtonGroup* myCameraPositionMode; + + QFrame* myCameraCoords; + QLineEdit* myCameraX; + QLineEdit* myCameraY; + QLineEdit* myCameraZ; + + QFrame* myProjDirection; + QLineEdit* myProjDirX; + QLineEdit* myProjDirY; + QLineEdit* myProjDirZ; + + QLineEdit* myDistance; + + QFrame* myViewDirection; + QLineEdit* myViewDirX; + QLineEdit* myViewDirY; + QLineEdit* myViewDirZ; + + QFrame* myScaleBox; + QLineEdit* myScale; + + QFrame* myViewAngleBox; + QLineEdit* myViewAngle; + + void setEnabled(QFrame* theWidget, const bool theState); + bool computePoint(const double start[3], const double dir[3], + const double dist, double result[3]); + void updateProjection(); + void updateCoordinates(); + + void updateData(); + + //---------------------------------------------------------------------------- + // Priority at which events are processed + vtkFloatingPointType myPriority; + + // Used to process events + vtkSmartPointer myEventCallbackCommand; + + // Used to update camera + vtkTimeStamp myCameraMTime; + + // Description: + // Main process event method + static void ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + +protected slots: + void onProjectionModeChanged(int); + void onPositionModeChanged(int); + + void onToBBCenter(); + void onToOrigin(); + void onSelectPoint(); + + void onFocalCoordChanged(); + void onCameraCoordChanged(); + void onDirectionChanged(); + void onDistanceChanged(); + void onViewDirectionChanged(); + + void onZoomChanged(); + + void onClickClose(); + +}; + +#endif // SVTK_VIEWPARAMETERDLG_H diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index be2e4468f..3093d1ba5 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -16,10 +16,20 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + +#include "SVTK_NonIsometricDlg.h" +#include "SVTK_UpdateRateDlg.h" +#include "SVTK_CubeAxesDlg.h" +#include "SVTK_SetRotationPointDlg.h" +#include "SVTK_ViewParameterDlg.h" + #include "SALOME_Actor.h" #include #include +#include +#include +#include #include #include @@ -30,6 +40,7 @@ #include #include #include +#include #include "QtxAction.h" @@ -40,11 +51,13 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_Accel.h" #include "SUIT_OverrideCursor.h" +#include "QtxActionToolMgr.h" +#include "QtxMultiAction.h" #include "VTKViewer_Utilities.h" #include "SVTK_View.h" -#include "SVTK_MainWindow.h" +//#include "SVTK_MainWindow.h" #include "SVTK_Selector.h" #include "SVTK_Event.h" @@ -55,6 +68,11 @@ #include "SVTK_RenderWindowInteractor.h" #include "SVTK_GenericRenderWindowInteractor.h" #include "SVTK_CubeAxesActor2D.h" +#include "SVTK_ComboAction.h" +#include "SVTK_KeyFreeInteractorStyle.h" +#include "SVTK_Selector.h" +#include "SVTK_Recorder.h" +#include "SVTK_RecorderDlg.h" #include "SALOME_ListIteratorOfListIO.hxx" @@ -89,66 +107,95 @@ namespace SVTK /*! Constructor */ -SVTK_ViewWindow -::SVTK_ViewWindow(SUIT_Desktop* theDesktop): +SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop): SUIT_ViewWindow(theDesktop), - myMainWindow(0), + //myMainWindow(0), myView(NULL), - myDumpImage(QImage()) -{} + myDumpImage(QImage()), + myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()) +{ + setWindowFlags( windowFlags() & ~Qt::Window ); + // specific of vtkSmartPointer + myKeyFreeInteractorStyle->Delete(); +} /*! To initialize #SVTK_ViewWindow instance */ -void -SVTK_ViewWindow -::Initialize(SVTK_ViewModelBase* theModel) +void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) { - if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ - myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr,this); - - SVTK_RenderWindowInteractor* anIteractor = - new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor"); - - SVTK_Selector* aSelector = SVTK_Selector::New(); - - SVTK_GenericRenderWindowInteractor* aDevice = - SVTK_GenericRenderWindowInteractor::New(); - aDevice->SetRenderWidget(anIteractor); - aDevice->SetSelector(aSelector); + // if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ + //myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr,this); - SVTK_Renderer* aRenderer = SVTK_Renderer::New(); - aRenderer->Initialize(aDevice,aSelector); - - anIteractor->Initialize(aDevice,aRenderer,aSelector); - - aDevice->Delete(); - aRenderer->Delete(); - aSelector->Delete(); - - myMainWindow->Initialize(anIteractor); - - SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); - anIteractor->PushInteractorStyle(aStyle); - aStyle->Delete(); - - setCentralWidget(myMainWindow); - - myView = new SVTK_View(myMainWindow); - Initialize(myView,theModel); - - anIteractor->getRenderWindow()->Render(); - myMainWindow->onResetView(); - } + //SVTK_RenderWindowInteractor* anIteractor = + // new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor"); + myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor"); + + SVTK_Selector* aSelector = SVTK_Selector::New(); + + SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New(); + aDevice->SetRenderWidget(myInteractor); + aDevice->SetSelector(aSelector); + + SVTK_Renderer* aRenderer = SVTK_Renderer::New(); + aRenderer->Initialize(aDevice,aSelector); + + myInteractor->Initialize(aDevice,aRenderer,aSelector); + + aDevice->Delete(); + aRenderer->Delete(); + aSelector->Delete(); + + //myMainWindow->Initialize(anIteractor); + myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), -1, this ); + myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), -1, this ); + + createActions( SUIT_Session::session()->activeApplication()->resourceMgr() ); + createToolBar(); + + SetEventDispatcher(myInteractor->GetDevice()); + myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground + myInteractor->setFocusPolicy(Qt::StrongFocus); + myInteractor->setFocus(); + setFocusProxy(myInteractor); + + myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" ); + myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" ); + myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" ); + mySetRotationPointDlg = new SVTK_SetRotationPointDlg + ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" ); + myViewParameterDlg = new SVTK_ViewParameterDlg + ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" ); + + SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); + myInteractor->PushInteractorStyle(aStyle); + aStyle->Delete(); + + myRecorder = SVTK_Recorder::New(); + + myRecorder->SetNbFPS( 17.3 ); + myRecorder->SetQuality( 100 ); + myRecorder->SetProgressiveMode( true ); + myRecorder->SetUseSkippedFrames( true ); + myRecorder->SetRenderWindow( myInteractor->getRenderWindow() ); + + //setCentralWidget(myMainWindow); + setCentralWidget(myInteractor); + + //myView = new SVTK_View(myMainWindow); + myView = new SVTK_View(this); + Initialize(myView,theModel); + + myInteractor->getRenderWindow()->Render(); + onResetView(); + //} } /*! To initialize #SVTK_ViewWindow instance */ -void -SVTK_ViewWindow -::Initialize(SVTK_View* theView, - SVTK_ViewModelBase* theModel) +void SVTK_ViewWindow::Initialize(SVTK_View* theView, + SVTK_ViewModelBase* theModel) { connect(theView,SIGNAL(KeyPressed(QKeyEvent*)), this,SLOT(onKeyPressed(QKeyEvent*)) ); @@ -171,17 +218,14 @@ SVTK_ViewWindow /*! Destructor */ -SVTK_ViewWindow -::~SVTK_ViewWindow() +SVTK_ViewWindow::~SVTK_ViewWindow() {} /*! \return corresponding view */ -SVTK_View* -SVTK_ViewWindow -::getView() +SVTK_View* SVTK_ViewWindow::getView() { return myView; } @@ -189,139 +233,143 @@ SVTK_ViewWindow /*! \return corresponding vtk main window */ -SVTK_MainWindow* -SVTK_ViewWindow -::getMainWindow() -{ - return myMainWindow; -} +// SVTK_MainWindow* SVTK_ViewWindow::getMainWindow() +// { +// return myMainWindow; +// } /*! \return corresponding vtk render window */ -vtkRenderWindow* -SVTK_ViewWindow -::getRenderWindow() +vtkRenderWindow* SVTK_ViewWindow::getRenderWindow() +{ + return GetInteractor()->getRenderWindow(); +} + +/*! + \return corresponding vtk render window interactor +*/ +SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const { - return getMainWindow()->getRenderWindow(); + return myInteractor; } /*! \return corresponding vtk render window interactor */ -vtkRenderWindowInteractor* -SVTK_ViewWindow -::getInteractor() +vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const { - return getMainWindow()->getInteractor(); + return myInteractor->GetDevice(); } /*! \return corresponding vtk renderer */ -vtkRenderer* -SVTK_ViewWindow -::getRenderer() +vtkRenderer* SVTK_ViewWindow::getRenderer() const +{ + return GetInteractor()->getRenderer(); +} + +/*! + Redirect the request to SVTK_RenderWindowInteractor::GetRenderer +*/ +SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const { - return myMainWindow->getRenderer(); + return GetInteractor()->GetRenderer(); } /*! \return corresponding vtk selector */ -SVTK_Selector* -SVTK_ViewWindow -::GetSelector() +SVTK_Selector* SVTK_ViewWindow::GetSelector() const { - return myMainWindow->GetSelector(); + return GetInteractor()->GetSelector(); } /*! Processes transformation "front view" */ -void -SVTK_ViewWindow -::onFrontView() +void SVTK_ViewWindow::onFrontView() { - myMainWindow->onFrontView(); + //myMainWindow->onFrontView(); + GetRenderer()->OnFrontView(); + Repaint(); } /*! Processes transformation "back view" */ -void -SVTK_ViewWindow -::onBackView() +void SVTK_ViewWindow::onBackView() { - myMainWindow->onBackView(); + //myMainWindow->onBackView(); + GetRenderer()->OnBackView(); + Repaint(); } /*! Processes transformation "top view" */ -void -SVTK_ViewWindow -::onTopView() +void SVTK_ViewWindow::onTopView() { - myMainWindow->onTopView(); + //myMainWindow->onTopView(); + GetRenderer()->OnTopView(); + Repaint(); } /*! Processes transformation "bottom view" */ -void -SVTK_ViewWindow -::onBottomView() +void SVTK_ViewWindow::onBottomView() { - myMainWindow->onBottomView(); + //myMainWindow->onBottomView(); + GetRenderer()->OnBottomView(); + Repaint(); } /*! Processes transformation "left view" */ -void -SVTK_ViewWindow -::onLeftView() +void SVTK_ViewWindow::onLeftView() { - myMainWindow->onLeftView(); + //myMainWindow->onLeftView(); + GetRenderer()->OnLeftView(); + Repaint(); } /*! Processes transformation "right view" */ -void -SVTK_ViewWindow -::onRightView() +void SVTK_ViewWindow::onRightView() { - myMainWindow->onRightView(); + //myMainWindow->onRightView(); + GetRenderer()->OnRightView(); + Repaint(); } /*! Processes transformation "reset view": sets default orientation of viewport camera */ -void -SVTK_ViewWindow -::onResetView() +void SVTK_ViewWindow::onResetView() { - myMainWindow->onResetView(); + //myMainWindow->onResetView(); + GetRenderer()->OnResetView(); + Repaint(); } /*! Processes transformation "fit all" */ -void -SVTK_ViewWindow -::onFitAll() +void SVTK_ViewWindow::onFitAll() { - myMainWindow->onFitAll(); + //myMainWindow->onFitAll(); + GetRenderer()->OnFitAll(); + Repaint(); } /*! SLOT: called if selection is changed */ -void -SVTK_ViewWindow -::onSelectionChanged() +void SVTK_ViewWindow::onSelectionChanged() { myView->onSelectionChanged(); } @@ -330,29 +378,25 @@ SVTK_ViewWindow Change selection mode \param theMode - new selection mode */ -void -SVTK_ViewWindow -::SetSelectionMode(Selection_Mode theMode) +void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode) { - myMainWindow->SetSelectionMode( theMode ); + //myMainWindow->SetSelectionMode( theMode ); + GetSelector()->SetSelectionMode(theMode); } /*! \return selection mode */ -Selection_Mode -SVTK_ViewWindow -::SelectionMode() const +Selection_Mode SVTK_ViewWindow::SelectionMode() const { - return myMainWindow->SelectionMode(); + //return myMainWindow->SelectionMode(); + return GetSelector()->SelectionMode(); } /*! Unhilights all objects in viewer */ -void -SVTK_ViewWindow -::unHighlightAll() +void SVTK_ViewWindow::unHighlightAll() { myView->unHighlightAll(); } @@ -363,11 +407,9 @@ SVTK_ViewWindow \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted \param theIsUpdate - update current viewer */ -void -SVTK_ViewWindow -::highlight(const Handle(SALOME_InteractiveObject)& theIO, - bool theIsHighlight, - bool theIsUpdate ) +void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight, + bool theIsUpdate ) { myView->highlight( theIO, theIsHighlight, theIsUpdate ); } @@ -376,9 +418,7 @@ SVTK_ViewWindow \return true if object is in viewer or in collector \param theIO - object to be checked */ -bool -SVTK_ViewWindow -::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) +bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) { return myView->isInViewer( theIO ); } @@ -387,9 +427,7 @@ SVTK_ViewWindow \return true if object is displayed in viewer \param theIO - object to be checked */ -bool -SVTK_ViewWindow -::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) +bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) { return myView->isVisible( theIO ); } @@ -398,9 +436,7 @@ SVTK_ViewWindow Display object \param theEntry - entry that corresponds to intractive objects */ -Handle(SALOME_InteractiveObject) -SVTK_ViewWindow -::FindIObject(const char* theEntry) +Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry) { return myView->FindIObject(theEntry); } @@ -410,10 +446,8 @@ SVTK_ViewWindow \param theIO - object \param theImmediatly - update viewer */ -void -SVTK_ViewWindow -::Display(const Handle(SALOME_InteractiveObject)& theIO, - bool theImmediatly) +void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO, + bool theImmediatly) { myView->Display(theIO,theImmediatly); } @@ -423,10 +457,8 @@ SVTK_ViewWindow \param theIO - object \param theImmediatly - update viewer */ -void -SVTK_ViewWindow -::Erase(const Handle(SALOME_InteractiveObject)& theIO, - bool theImmediatly) +void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO, + bool theImmediatly) { myView->Erase(theIO,theImmediatly); } @@ -435,9 +467,7 @@ SVTK_ViewWindow Display only passed object \param theIO - object */ -void -SVTK_ViewWindow -::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) +void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) { myView->DisplayOnly(theIO); } @@ -445,9 +475,7 @@ SVTK_ViewWindow /*! Display all objects in view */ -void -SVTK_ViewWindow -::DisplayAll() +void SVTK_ViewWindow::DisplayAll() { myView->DisplayAll(); } @@ -455,9 +483,7 @@ SVTK_ViewWindow /*! Erase all objects in view */ -void -SVTK_ViewWindow -::EraseAll() +void SVTK_ViewWindow::EraseAll() { myView->EraseAll(); } @@ -466,121 +492,260 @@ SVTK_ViewWindow Sets background color \param color - new background color */ -void -SVTK_ViewWindow -::setBackgroundColor( const QColor& color ) +void SVTK_ViewWindow::setBackgroundColor( const QColor& theColor ) { - myMainWindow->SetBackgroundColor( color ); + //myMainWindow->SetBackgroundColor( color ); + getRenderer()->SetBackground(theColor.red()/255.0, + theColor.green()/255.0, + theColor.blue()/255.0); } /*! \return background color of viewer */ -QColor -SVTK_ViewWindow -::backgroundColor() const +QColor SVTK_ViewWindow::backgroundColor() const { - return myMainWindow->BackgroundColor(); + //return myMainWindow->BackgroundColor(); + vtkFloatingPointType aBackgroundColor[3]; + getRenderer()->GetBackground(aBackgroundColor); + return QColor(int(aBackgroundColor[0]*255), + int(aBackgroundColor[1]*255), + int(aBackgroundColor[2]*255)); +} + + +/*! + Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle +*/ +vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const +{ + return GetInteractor()->GetInteractorStyle(); +} + +/*! + Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle +*/ +void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle) +{ + GetInteractor()->PushInteractorStyle(theStyle); +} + +/*! + Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle +*/ +void SVTK_ViewWindow::PopInteractorStyle() +{ + GetInteractor()->PopInteractorStyle(); } /*! Updates current viewer */ -void -SVTK_ViewWindow -::Repaint(bool theUpdateTrihedron) +void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron) { - myMainWindow->Repaint( theUpdateTrihedron ); + //myMainWindow->Repaint( theUpdateTrihedron ); + if(theUpdateTrihedron) + GetRenderer()->OnAdjustTrihedron(); + + GetInteractor()->update(); + + SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle(); + if ( aStyle ) + aStyle->OnTimer(); } /*! Redirect the request to #SVTK_Renderer::GetScale */ -void -SVTK_ViewWindow -::GetScale( double theScale[3] ) +void SVTK_ViewWindow::GetScale( double theScale[3] ) { - myMainWindow->GetScale( theScale ); + //myMainWindow->GetScale( theScale ); + GetRenderer()->GetScale( theScale ); } /*! Redirect the request to #SVTK_Renderer::SetScale */ -void -SVTK_ViewWindow -::SetScale( double theScale[3] ) +void SVTK_ViewWindow::SetScale( double theScale[3] ) { - myMainWindow->SetScale( theScale ); + //myMainWindow->SetScale( theScale ); + GetRenderer()->SetScale( theScale ); + Repaint(); } /*! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed */ -bool -SVTK_ViewWindow -::isTrihedronDisplayed() +bool SVTK_ViewWindow::isTrihedronDisplayed() { - return myMainWindow->IsTrihedronDisplayed(); + return GetRenderer()->IsTrihedronDisplayed(); + // return myMainWindow->IsTrihedronDisplayed(); } /*! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed */ -bool -SVTK_ViewWindow -::isCubeAxesDisplayed() +bool SVTK_ViewWindow::isCubeAxesDisplayed() { - return myMainWindow->IsCubeAxesDisplayed(); + //return myMainWindow->IsCubeAxesDisplayed(); + return GetRenderer()->IsCubeAxesDisplayed(); } /*! Redirect the request to #SVTK_Renderer::OnViewTrihedron */ -void -SVTK_ViewWindow -::onViewTrihedron() +void SVTK_ViewWindow::onViewTrihedron() { - myMainWindow->onViewTrihedron(); + //myMainWindow->onViewTrihedron(); + GetRenderer()->OnViewTrihedron(); + Repaint(); } /*! Redirect the request to #SVTK_Renderer::OnViewCubeAxes */ -void -SVTK_ViewWindow -::onViewCubeAxes() +void SVTK_ViewWindow::onViewCubeAxes() { - myMainWindow->onViewCubeAxes(); + //myMainWindow->onViewCubeAxes(); + GetRenderer()->OnViewCubeAxes(); + Repaint(); } /*! Redirect the request to #SVTK_Renderer::GetTrihedron */ -VTKViewer_Trihedron* -SVTK_ViewWindow:: -GetTrihedron() +VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron() { - return myMainWindow->GetTrihedron(); + //return myMainWindow->GetTrihedron(); + return GetRenderer()->GetTrihedron(); } /*! Redirect the request to #SVTK_Renderer::GetCubeAxes */ -SVTK_CubeAxesActor2D* -SVTK_ViewWindow -::GetCubeAxes() +SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes() { - return myMainWindow->GetCubeAxes(); + //return myMainWindow->GetCubeAxes(); + return GetRenderer()->GetCubeAxes(); } /*! \return trihedron size */ -vtkFloatingPointType -SVTK_ViewWindow -::GetTrihedronSize() const +vtkFloatingPointType SVTK_ViewWindow::GetTrihedronSize() const +{ + //return myMainWindow->GetTrihedronSize(); + return GetRenderer()->GetTrihedronSize(); +} + +/*! + Sets projection mode + \param theMode - projection mode ( 0 - orthogonal, 1 - perspective ) +*/ +void SVTK_ViewWindow::SetProjectionMode(const int theMode) +{ + activateProjectionMode( theMode ); +} + + +/*! + Set the gravity center as a focal point +*/ +void SVTK_ViewWindow::activateSetFocalPointGravity() +{ + myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0); +} + +/*! + Set the selected point as a focal point +*/ +void SVTK_ViewWindow::activateSetFocalPointSelected() +{ + myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0); +} + +/*! + Set the point selected by user as a focal point +*/ +void SVTK_ViewWindow::activateStartFocalPointSelection() +{ + myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0); +} + +void SVTK_ViewWindow::activateProjectionMode(int theMode) +{ + SVTK_ComboAction* a = ::qobject_cast( toolMgr()->action( ProjectionModeId ) ); + if ( a ) a->setCurrentIndex(theMode); +} + +/*! + Sets actual interaction style + \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free ) +*/ +void SVTK_ViewWindow::SetInteractionStyle(const int theStyle) +{ + onSwitchInteractionStyle( theStyle==1 ); +} + +/*! + Switches "keyboard free" interaction style on/off +*/ +void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn) +{ + if (theOn) { + // check if style is already set + if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() ) + { + // keep the same style extensions + SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle(); + if ( aStyle ) { + myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement()); + myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown()); + } + + PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer()); + } + } + else { + // pop only key free style + if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() ) + PopInteractorStyle(); + } + + // update action state if method is called outside + QtxAction* a = getAction( SwitchInteractionStyleId ); + if ( a->isChecked() != theOn ) a->setChecked( theOn ); +} + +/*! + Sets incremental speed + \param theValue - new incremental speed + \param theMode - modification mode +*/ +void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode) { - return myMainWindow->GetTrihedronSize(); + //myMainWindow->SetIncrementalSpeed(theValue, theMode); + if ( (SVTK_InteractorStyle*)GetInteractorStyle() ) + ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode); +} + +/*! + Sets spacemouse buttons for the functions + \param theBtn1 - spacemouse button for the "decrease speed increment" + \param theBtn2 - spacemouse button for the "increase speed increment" + \param theBtn3 - spacemouse button for the "dominant combined switch" +*/ +void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1, + const int theBtn2, + const int theBtn3) +{ + //myMainWindow->SetSMButtons(theBtn1, theBtn2, theBtn3); + int val = theBtn1; + myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val); + val = theBtn2; + myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val); + val = theBtn3; + myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val); } /*! @@ -588,49 +753,45 @@ SVTK_ViewWindow \param theSize - new trihedron size \param theRelative - trihedron relativeness */ -void -SVTK_ViewWindow -::SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative) +void SVTK_ViewWindow::SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative) { - myMainWindow->SetTrihedronSize(theSize, theRelative); + //myMainWindow->SetTrihedronSize(theSize, theRelative); + GetRenderer()->SetTrihedronSize(theSize, theRelative); + Repaint(); } /*! If parameter theIsForcedUpdate is true, recalculate parameters for * trihedron and cube axes, even if trihedron and cube axes is invisible. */ -void -SVTK_ViewWindow -::AdjustTrihedrons(const bool theIsForcedUpdate) +void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate) { - myMainWindow->AdjustActors(); + //myMainWindow->AdjustActors(); + GetRenderer()->AdjustActors(); + Repaint(); } /*! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron */ -void -SVTK_ViewWindow -::onAdjustTrihedron() +void SVTK_ViewWindow::onAdjustTrihedron() { - myMainWindow->onAdjustTrihedron(); + //myMainWindow->onAdjustTrihedron(); + GetRenderer()->OnAdjustTrihedron(); } /*! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes */ -void -SVTK_ViewWindow -::onAdjustCubeAxes() +void SVTK_ViewWindow::onAdjustCubeAxes() { - myMainWindow->onAdjustCubeAxes(); + //myMainWindow->onAdjustCubeAxes(); + GetRenderer()->OnAdjustCubeAxes(); } /*! Emits key pressed */ -void -SVTK_ViewWindow -::onKeyPressed(QKeyEvent* event) +void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event) { emit keyPressed( this, event ); } @@ -638,9 +799,7 @@ SVTK_ViewWindow /*! Emits key released */ -void -SVTK_ViewWindow -::onKeyReleased(QKeyEvent* event) +void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event) { emit keyReleased( this, event ); } @@ -648,9 +807,7 @@ SVTK_ViewWindow /*! Emits mouse pressed */ -void -SVTK_ViewWindow -::onMousePressed(QMouseEvent* event) +void SVTK_ViewWindow::onMousePressed(QMouseEvent* event) { emit mousePressed(this, event); } @@ -658,9 +815,7 @@ SVTK_ViewWindow /*! Emits mouse released */ -void -SVTK_ViewWindow -::onMouseReleased(QMouseEvent* event) +void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event) { emit mouseReleased( this, event ); } @@ -668,9 +823,7 @@ SVTK_ViewWindow /*! Emits mouse moving */ -void -SVTK_ViewWindow -::onMouseMoving(QMouseEvent* event) +void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event) { emit mouseMoving( this, event ); } @@ -678,9 +831,7 @@ SVTK_ViewWindow /*! Emits mouse double clicked */ -void -SVTK_ViewWindow -::onMouseDoubleClicked( QMouseEvent* event ) +void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event ) { emit mouseDoubleClicked( this, event ); } @@ -688,36 +839,40 @@ SVTK_ViewWindow /*! Redirect the request to #SVTK_Renderer::AddActor */ -void -SVTK_ViewWindow -::AddActor( VTKViewer_Actor* theActor, - bool theUpdate ) +void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor, + bool theUpdate ) { - myMainWindow->AddActor( theActor, theUpdate ); + //myMainWindow->AddActor( theActor, theUpdate ); + GetRenderer()->AddActor(theActor); + if(theUpdate) + Repaint(); + emit actorAdded(theActor); } /*! Redirect the request to #SVTK_Renderer::RemoveActor */ -void -SVTK_ViewWindow -::RemoveActor( VTKViewer_Actor* theActor, - bool theUpdate ) +void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, + bool theUpdate ) { - myMainWindow->RemoveActor( theActor, theUpdate ); + //myMainWindow->RemoveActor( theActor, theUpdate ); + GetRenderer()->RemoveActor(theActor); + if(theUpdate) + Repaint(); + emit actorRemoved(theActor); } /*! \return QImage, containing all scene rendering in window */ -QImage -SVTK_ViewWindow -::dumpView() +QImage SVTK_ViewWindow::dumpView() { - if ( myMainWindow->getToolBar()->testAttribute(Qt::WA_UnderMouse) || myDumpImage.isNull() ) - return myMainWindow->dumpView(); +// if ( myMainWindow->getToolBar()->testAttribute(Qt::WA_UnderMouse) || myDumpImage.isNull() ) +// return myMainWindow->dumpView(); - return myDumpImage; +// return myDumpImage; + QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() ); + return px.toImage(); } QString SVTK_ViewWindow::filter() const @@ -764,18 +919,18 @@ bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileNa */ void SVTK_ViewWindow::RefreshDumpImage() { - myDumpImage = myMainWindow->dumpView(); + //myDumpImage = myMainWindow->dumpView(); + QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() ); + myDumpImage = px.toImage(); } /*! Redirect the request to #SVTK_Renderer::SetSelectionProp */ -void -SVTK_ViewWindow -::SetSelectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) +void SVTK_ViewWindow::SetSelectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) { myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth); } @@ -783,12 +938,10 @@ SVTK_ViewWindow /*! Redirect the request to #SVTK_Renderer::SetSelectionProp */ -void -SVTK_ViewWindow -::SetPreselectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) +void SVTK_ViewWindow::SetPreselectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) { myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth); } @@ -796,11 +949,9 @@ SVTK_ViewWindow /*! Redirect the request to #SVTK_Renderer::SetSelectionTolerance */ -void -SVTK_ViewWindow -::SetSelectionTolerance(const double& theTolNodes, - const double& theTolItems, - const double& theTolObjects) +void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes, + const double& theTolItems, + const double& theTolObjects) { myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects); } @@ -809,21 +960,29 @@ SVTK_ViewWindow Performs action \param accelAction - action */ -bool -SVTK_ViewWindow -::action( const int accelAction ) +bool SVTK_ViewWindow::action( const int accelAction ) { - if ( !myMainWindow->hasFocus() ) - return false; + // if ( !myMainWindow->hasFocus() ) + // return false; if ( accelAction == SUIT_Accel::ZoomFit ) onFitAll(); else { int anEvent = SVTK::convertAction( accelAction ); - myMainWindow->InvokeEvent( anEvent, 0 ); + //myMainWindow->InvokeEvent( anEvent, 0 ); + GetInteractor()->InvokeEvent(anEvent, 0); } return true; } +/*! + \return action by it's id +*/ +QtxAction* SVTK_ViewWindow::getAction( int id ) const +{ + return dynamic_cast( toolMgr()->action( id ) ); +} + + // old visual parameters had 13 values. New format added additional // 76 values for graduated axes, so both numbers are processed. const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params @@ -832,11 +991,11 @@ const int nAllParams = nNormalParams + 3*nGradAxisParams + 1; // number of all v /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes) */ -QString getGradAxisVisualParams( vtkAxisActor2D* actor ) +void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis ) { - QString params; + //QString params; if ( !actor ) - return params; + return ;//params; // Name bool isVisible = actor->GetTitleVisibility(); @@ -856,8 +1015,26 @@ QString getGradAxisVisualParams( vtkAxisActor2D* actor ) italic = txtProp->GetItalic(); shadow = txtProp->GetShadow(); } - params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, - title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow ); + writer.writeStartElement("GraduatedAxis"); + writer.writeAttribute("Axis", theAxis); + + writer.writeStartElement("Title"); + writer.writeAttribute("isVisible", QString("%1").arg(isVisible)); + writer.writeAttribute("Text", title); + writer.writeAttribute("Font", QString("%1").arg(font)); + writer.writeAttribute("Bold", QString("%1").arg(bold)); + writer.writeAttribute("Italic", QString("%1").arg(italic)); + writer.writeAttribute("Shadow", QString("%1").arg(shadow)); + + writer.writeStartElement("Color"); + writer.writeAttribute("R", QString("%1").arg(color[0])); + writer.writeAttribute("G", QString("%1").arg(color[1])); + writer.writeAttribute("B", QString("%1").arg(color[2])); + writer.writeEndElement(); + writer.writeEndElement(); + + //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, + // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow ); // Labels isVisible = actor->GetLabelVisibility(); @@ -877,16 +1054,132 @@ QString getGradAxisVisualParams( vtkAxisActor2D* actor ) italic = txtProp->GetItalic(); shadow = txtProp->GetShadow(); } - params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset, - color[0], color[1], color[2], font, bold, italic, shadow ); + + writer.writeStartElement("Labels"); + writer.writeAttribute("isVisible", QString("%1").arg(isVisible)); + writer.writeAttribute("Number", QString("%1").arg(labels)); + writer.writeAttribute("Offset", QString("%1").arg(offset)); + writer.writeAttribute("Font", QString("%1").arg(font)); + writer.writeAttribute("Bold", QString("%1").arg(bold)); + writer.writeAttribute("Italic", QString("%1").arg(italic)); + writer.writeAttribute("Shadow", QString("%1").arg(shadow)); + + writer.writeStartElement("Color"); + writer.writeAttribute("R", QString("%1").arg(color[0])); + writer.writeAttribute("G", QString("%1").arg(color[1])); + writer.writeAttribute("B", QString("%1").arg(color[2])); + writer.writeEndElement(); + writer.writeEndElement(); + // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset, + // color[0], color[1], color[2], font, bold, italic, shadow ); // Tick marks isVisible = actor->GetTickVisibility(); int length = actor->GetTickLength(); + writer.writeStartElement("TickMarks"); + writer.writeAttribute("isVisible", QString("%1").arg(isVisible)); + writer.writeAttribute("Length", QString("%1").arg(length)); + writer.writeEndElement(); + + //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length ); - params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length ); + writer.writeEndElement(); + //return params; +} + +void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor) +{ + if ( !actor ) + return; + + do { + reader.readNext(); + } while (!reader.isStartElement()); + + // Read title params + QXmlStreamAttributes aAttr = reader.attributes(); + bool isVisible = aAttr.value("isVisible").toString().toUShort(); + QString title = aAttr.value("Text").toString(); + int font = aAttr.value("Font").toString().toInt(); + int bold = aAttr.value("Bold").toString().toInt(); + int italic = aAttr.value("Italic").toString().toInt(); + int shadow = aAttr.value("Shadow").toString().toInt(); + + //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow); + + do { + reader.readNext(); + } while (!reader.isStartElement()); + + // Read title color + aAttr = reader.attributes(); + + vtkFloatingPointType color[3]; + color[0] = aAttr.value("R").toString().toDouble(); + color[1] = aAttr.value("G").toString().toDouble(); + color[2] = aAttr.value("B").toString().toDouble(); + //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]); + + actor->SetTitleVisibility( isVisible ); + actor->SetTitle( title.toLatin1() ); + vtkTextProperty* txtProp = actor->GetTitleTextProperty(); + if ( txtProp ) { + txtProp->SetColor( color ); + txtProp->SetFontFamily( font ); + txtProp->SetBold( bold ); + txtProp->SetItalic( italic ); + txtProp->SetShadow( shadow ); + } + + // Labels + + do { + reader.readNext(); + } while (!reader.isStartElement()); + // Read labels + aAttr = reader.attributes(); + isVisible = aAttr.value("isVisible").toString().toUShort(); + int labels = aAttr.value("Number").toString().toInt(); + int offset = aAttr.value("Offset").toString().toInt(); + font = aAttr.value("Font").toString().toInt(); + bold = aAttr.value("Bold").toString().toInt(); + italic = aAttr.value("Italic").toString().toInt(); + shadow = aAttr.value("Shadow").toString().toInt(); + + do { + reader.readNext(); + } while (!reader.isStartElement()); + // Read Color + aAttr = reader.attributes(); + + color[0] = aAttr.value("R").toString().toDouble(); + color[1] = aAttr.value("G").toString().toDouble(); + color[2] = aAttr.value("B").toString().toDouble(); + + actor->SetLabelVisibility( isVisible ); + actor->SetNumberOfLabels( labels ); + actor->SetTickOffset( offset ); + txtProp = actor->GetLabelTextProperty(); + if ( txtProp ) { + txtProp->SetColor( color ); + txtProp->SetFontFamily( font ); + txtProp->SetBold( bold ); + txtProp->SetItalic( italic ); + txtProp->SetShadow( shadow ); + } + + // Tick Marks + do { + reader.readNext(); + } while (!reader.isStartElement()); + aAttr = reader.attributes(); + + // retrieve and set tick marks properties + isVisible = aAttr.value("isVisible").toString().toUShort(); + int length = aAttr.value("Length").toString().toInt(); - return params; + actor->SetTickVisibility( isVisible ); + actor->SetTickLength( length ); } /*! The method restores visual parameters of a graduated axis actor (x,y,z axis) @@ -958,9 +1251,7 @@ void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params ) /*! The method returns the visual parameters of this view as a formated string */ -QString -SVTK_ViewWindow -::getVisualParameters() +QString SVTK_ViewWindow::getVisualParameters() { double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; @@ -976,29 +1267,72 @@ SVTK_ViewWindow // view up values (3 digits), parallel scale (1 digit), scale (3 digits, // Graduated axes parameters (X, Y, Z axes parameters) QString retStr; - retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", - pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], - viewUp[0], viewUp[1], viewUp[2], parScale, scale[0], scale[1], scale[2] ); + QXmlStreamWriter aWriter(&retStr); + aWriter.setAutoFormatting(true); + + aWriter.writeStartDocument(); + aWriter.writeStartElement("ViewState"); + + aWriter.writeStartElement("Position"); + aWriter.writeAttribute("X", QString("%1").arg(pos[0])); + aWriter.writeAttribute("Y", QString("%1").arg(pos[1])); + aWriter.writeAttribute("Z", QString("%1").arg(pos[2])); + aWriter.writeEndElement(); + + aWriter.writeStartElement("FocalPoint"); + aWriter.writeAttribute("X", QString::number(focalPnt[0])); + aWriter.writeAttribute("Y", QString::number(focalPnt[1])); + aWriter.writeAttribute("Z", QString::number(focalPnt[2])); + aWriter.writeEndElement(); + + aWriter.writeStartElement("ViewUp"); + aWriter.writeAttribute("X", QString::number(viewUp[0])); + aWriter.writeAttribute("Y", QString::number(viewUp[1])); + aWriter.writeAttribute("Z", QString::number(viewUp[2])); + aWriter.writeEndElement(); + + aWriter.writeStartElement("ViewScale"); + aWriter.writeAttribute("Parallel", QString::number(parScale)); + aWriter.writeAttribute("X", QString::number(scale[0])); + aWriter.writeAttribute("Y", QString::number(scale[1])); + aWriter.writeAttribute("Z", QString::number(scale[2])); + aWriter.writeEndElement(); - // save graduated axes parameters if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) { - retStr += QString( "*%1" ).arg( getMainWindow()->IsCubeAxesDisplayed() ); - retStr += ::getGradAxisVisualParams( gradAxesActor->GetXAxisActor2D() ); - retStr += ::getGradAxisVisualParams( gradAxesActor->GetYAxisActor2D() ); - retStr += ::getGradAxisVisualParams( gradAxesActor->GetZAxisActor2D() ); + aWriter.writeStartElement("DisplayCubeAxis"); + aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed())); + aWriter.writeEndElement(); + + getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X"); + getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y"); + getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z"); } + aWriter.writeEndElement(); + aWriter.writeEndDocument(); + +// retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", +// pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], +// viewUp[0], viewUp[1], viewUp[2], parScale, scale[0], scale[1], scale[2] ); + +// // save graduated axes parameters +// if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) { +// retStr += QString( "*%1" ).arg( GetRenderer()->IsCubeAxesDisplayed() ); +// retStr += ::getGradAxisVisualParams( gradAxesActor->GetXAxisActor2D() ); +// retStr += ::getGradAxisVisualParams( gradAxesActor->GetYAxisActor2D() ); +// retStr += ::getGradAxisVisualParams( gradAxesActor->GetZAxisActor2D() ); +// } + return retStr; } /*! The method restores visual parameters of this view or postpones it untill the view is shown -*/ -void -SVTK_ViewWindow -::setVisualParameters( const QString& parameters ) +*/ +void SVTK_ViewWindow::setVisualParameters( const QString& parameters ) { - SVTK_RenderWindowInteractor* anInteractor = getMainWindow()->GetInteractor(); + //printf("#### %s\n", qPrintable(parameters)); + SVTK_RenderWindowInteractor* anInteractor = GetInteractor(); if ( anInteractor->isVisible() ) { doSetVisualParameters( parameters ); } @@ -1011,51 +1345,103 @@ SVTK_ViewWindow /*! The method restores visual parameters of this view from a formated string */ -void -SVTK_ViewWindow -::doSetVisualParameters( const QString& parameters ) -{ - QStringList paramsLst = parameters.split( '*' ); - if ( paramsLst.size() >= nNormalParams ) { - // 'reading' list of parameters - double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; - pos[0] = paramsLst[0].toDouble(); - pos[1] = paramsLst[1].toDouble(); - pos[2] = paramsLst[2].toDouble(); - focalPnt[0] = paramsLst[3].toDouble(); - focalPnt[1] = paramsLst[4].toDouble(); - focalPnt[2] = paramsLst[5].toDouble(); - viewUp[0] = paramsLst[6].toDouble(); - viewUp[1] = paramsLst[7].toDouble(); - viewUp[2] = paramsLst[8].toDouble(); - parScale = paramsLst[9].toDouble(); - scale[0] = paramsLst[10].toDouble(); - scale[1] = paramsLst[11].toDouble(); - scale[2] = paramsLst[12].toDouble(); - - // applying parameters +void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters ) +{ + double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; + + QXmlStreamReader aReader(parameters); + SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes(); + + while(!aReader.atEnd()) { + aReader.readNext(); + if (aReader.isStartElement()) { + QXmlStreamAttributes aAttr = aReader.attributes(); + //printf("### Name = %s\n", qPrintable(aReader.name().toString())); + if (aReader.name() == "Position") { + pos[0] = aAttr.value("X").toString().toDouble(); + pos[1] = aAttr.value("Y").toString().toDouble(); + pos[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]); + } else if (aReader.name() == "FocalPoint") { + focalPnt[0] = aAttr.value("X").toString().toDouble(); + focalPnt[1] = aAttr.value("Y").toString().toDouble(); + focalPnt[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]); + } else if (aReader.name() == "ViewUp") { + viewUp[0] = aAttr.value("X").toString().toDouble(); + viewUp[1] = aAttr.value("Y").toString().toDouble(); + viewUp[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]); + } else if (aReader.name() == "ViewScale") { + parScale = aAttr.value("Parallel").toString().toDouble(); + scale[0] = aAttr.value("X").toString().toDouble(); + scale[1] = aAttr.value("Y").toString().toDouble(); + scale[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]); + } else if (aReader.name() == "DisplayCubeAxis") { + if (aAttr.value("Show") == "0") + gradAxesActor->VisibilityOff(); + else + gradAxesActor->VisibilityOn(); + } else if (aReader.name() == "GraduatedAxis") { + if(aAttr.value("Axis") == "X") + setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D()); + else if(aAttr.value("Axis") == "Y") + setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D()); + else if(aAttr.value("Axis") == "Z") + setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D()); + } + } + } + if (!aReader.hasError()) { vtkCamera* camera = getRenderer()->GetActiveCamera(); camera->SetPosition( pos ); camera->SetFocalPoint( focalPnt ); camera->SetViewUp( viewUp ); camera->SetParallelScale( parScale ); SetScale( scale ); - - // apply graduated axes parameters - SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes(); - if ( gradAxesActor && paramsLst.size() == nAllParams ) { + } else { + QStringList paramsLst = parameters.split( '*' ); + if ( paramsLst.size() >= nNormalParams ) { + // 'reading' list of parameters + pos[0] = paramsLst[0].toDouble(); + pos[1] = paramsLst[1].toDouble(); + pos[2] = paramsLst[2].toDouble(); + focalPnt[0] = paramsLst[3].toDouble(); + focalPnt[1] = paramsLst[4].toDouble(); + focalPnt[2] = paramsLst[5].toDouble(); + viewUp[0] = paramsLst[6].toDouble(); + viewUp[1] = paramsLst[7].toDouble(); + viewUp[2] = paramsLst[8].toDouble(); + parScale = paramsLst[9].toDouble(); + scale[0] = paramsLst[10].toDouble(); + scale[1] = paramsLst[11].toDouble(); + scale[2] = paramsLst[12].toDouble(); + + // applying parameters + vtkCamera* camera = getRenderer()->GetActiveCamera(); + camera->SetPosition( pos ); + camera->SetFocalPoint( focalPnt ); + camera->SetViewUp( viewUp ); + camera->SetParallelScale( parScale ); + SetScale( scale ); - int i = nNormalParams+1, j = i + nGradAxisParams - 1; - ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) ); - i = j + 1; j += nGradAxisParams; - ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) ); - i = j + 1; j += nGradAxisParams; - ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) ); - - if ( paramsLst[13].toUShort() ) - gradAxesActor->VisibilityOn(); - else - gradAxesActor->VisibilityOff(); + // apply graduated axes parameters + SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes(); + if ( gradAxesActor && paramsLst.size() == nAllParams ) { + + int i = nNormalParams+1, j = i + nGradAxisParams - 1; + ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) ); + i = j + 1; j += nGradAxisParams; + ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) ); + i = j + 1; j += nGradAxisParams; + ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) ); + + if ( paramsLst[13].toUShort() ) + gradAxesActor->VisibilityOn(); + else + gradAxesActor->VisibilityOff(); + } } } } @@ -1075,3 +1461,492 @@ bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent ) } return SUIT_ViewWindow::eventFilter( theWatched, theEvent ); } + + +/*! + Change rotation point +*/ +void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate) +{ + if(theIsActivate){ + mySetRotationPointDlg->addObserver(); + if ( mySetRotationPointDlg->IsFirstShown() ) + activateSetRotationGravity(); + mySetRotationPointDlg->show(); + }else + mySetRotationPointDlg->hide(); +} + +/*! + Set the gravity center as a rotation point +*/ +void SVTK_ViewWindow::activateSetRotationGravity() +{ + myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0); +} + +/*! + Set the selected point as a rotation point +*/ +void SVTK_ViewWindow::activateSetRotationSelected(void* theData) +{ + myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData); +} + +/*! + Set the point selected by user as a rotation point +*/ +void SVTK_ViewWindow::activateStartPointSelection() +{ + myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0); +} + +/*! + Set the view projection mode: orthogonal or perspective +*/ +void SVTK_ViewWindow::onProjectionMode(int mode) +{ + vtkCamera* aCamera = getRenderer()->GetActiveCamera(); + aCamera->SetParallelProjection(mode==0); + GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); +} + +void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher) +{ + myEventDispatcher = theDispatcher; +} + +/*! + Creates all actions of svtk main window +*/ +void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) +{ + QtxAction* anAction; + QtxActionToolMgr* mgr = toolMgr(); + + // Dump view + anAction = new QtxAction(tr("MNU_DUMP_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_DUMP_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView())); + mgr->registerAction( anAction, DumpId ); + + // FitAll + anAction = new QtxAction(tr("MNU_FITALL"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this); + anAction->setStatusTip(tr("DSC_FITALL")); + connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll())); + mgr->registerAction( anAction, FitAllId ); + + // FitRect + anAction = new QtxAction(tr("MNU_FITRECT"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this); + anAction->setStatusTip(tr("DSC_FITRECT")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit())); + mgr->registerAction( anAction, FitRectId ); + + // Zoom + anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_ZOOM_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom())); + mgr->registerAction( anAction, ZoomId ); + + // Panning + anAction = new QtxAction(tr("MNU_PAN_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_PAN_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning())); + mgr->registerAction( anAction, PanId ); + + // Global Panning + anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning())); + mgr->registerAction( anAction, GlobalPanId ); + + // Change rotation point + anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ), + tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool))); + mgr->registerAction( anAction, ChangeRotationPointId ); + + // Rotation + anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), + tr( "MNU_ROTATE_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_ROTATE_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation())); + mgr->registerAction( anAction, RotationId ); + + // Projections + anAction = new QtxAction(tr("MNU_FRONT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), + tr( "MNU_FRONT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_FRONT_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView())); + mgr->registerAction( anAction, FrontId ); + + anAction = new QtxAction(tr("MNU_BACK_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), + tr( "MNU_BACK_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_BACK_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onBackView())); + mgr->registerAction( anAction, BackId ); + + anAction = new QtxAction(tr("MNU_TOP_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), + tr( "MNU_TOP_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_TOP_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onTopView())); + mgr->registerAction( anAction, TopId ); + + anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), + tr( "MNU_BOTTOM_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_BOTTOM_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView())); + mgr->registerAction( anAction, BottomId ); + + anAction = new QtxAction(tr("MNU_LEFT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), + tr( "MNU_LEFT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_LEFT_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView())); + mgr->registerAction( anAction, LeftId ); + + anAction = new QtxAction(tr("MNU_RIGHT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), + tr( "MNU_RIGHT_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_RIGHT_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onRightView())); + mgr->registerAction( anAction, RightId ); + + // Reset + anAction = new QtxAction(tr("MNU_RESET_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_RESET_VIEW")); + connect(anAction, SIGNAL(activated()), this, SLOT(onResetView())); + mgr->registerAction( anAction, ResetId ); + + // onViewTrihedron: Shows - Hides Trihedron + anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), + tr( "MNU_SHOW_TRIHEDRON" ), 0, this); + anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON")); + connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron())); + mgr->registerAction( anAction, ViewTrihedronId ); + + // onNonIsometric: Manage non-isometric params + anAction = new QtxAction(tr("MNU_SVTK_SCALING"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ), + tr( "MNU_SVTK_SCALING" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_SCALING")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool))); + mgr->registerAction( anAction, NonIsometric ); + + // onGraduatedAxes: Manage graduated axes params + anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ), + tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool))); + mgr->registerAction( anAction, GraduatedAxes ); + + // onGraduatedAxes: Manage graduated axes params + anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ), + tr( "MNU_SVTK_UPDATE_RATE" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool))); + mgr->registerAction( anAction, UpdateRate ); + + // Set projection mode + SVTK_ComboAction* aModeAction = new SVTK_ComboAction(tr("MNU_SVTK_PROJECTION_MODE"), this); + aModeAction->setStatusTip(tr("DSC_SVTK_PROJECTION_MODE")); + aModeAction->insertItem(theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ) ); + aModeAction->insertItem(theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ) ); + connect(aModeAction, SIGNAL(triggered(int)), this, SLOT(onProjectionMode(int))); + mgr->registerAction( aModeAction, ProjectionModeId ); + + // View Parameters + anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ), + tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this); + anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool))); + mgr->registerAction( anAction, ViewParametersId ); + + // Switch between interaction styles + anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ), + tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool))); + mgr->registerAction( anAction, SwitchInteractionStyleId ); + + // Start recording + myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ), + tr( "MNU_SVTK_RECORDING_START" ), 0, this); + myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START")); + connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) ); + mgr->registerAction( myStartAction, StartRecordingId ); + + // Play recording + myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ), + tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this); + myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY")); + myPlayAction->setEnabled( false ); + connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) ); + mgr->registerAction( myPlayAction, PlayRecordingId ); + + // Pause recording + myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ), + tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this); + myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE")); + myPauseAction->setEnabled( false ); + connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) ); + mgr->registerAction( myPauseAction, PauseRecordingId ); + + // Stop recording + myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ), + tr( "MNU_SVTK_RECORDING_STOP" ), 0, this); + myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP")); + myStopAction->setEnabled( false ); + connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) ); + mgr->registerAction( myStopAction, StopRecordingId ); +} + +/*! + Creates toolbar of svtk main window +*/ +void SVTK_ViewWindow::createToolBar() +{ + QtxActionToolMgr* mgr = toolMgr(); + + mgr->append( DumpId, myToolBar ); + mgr->append( SwitchInteractionStyleId, myToolBar ); + mgr->append( ViewTrihedronId, myToolBar ); + + QtxMultiAction* aScaleAction = new QtxMultiAction( this ); + aScaleAction->insertAction( getAction( FitAllId ) ); + aScaleAction->insertAction( getAction( FitRectId ) ); + aScaleAction->insertAction( getAction( ZoomId ) ); + mgr->append( aScaleAction, myToolBar ); + + QtxMultiAction* aPanningAction = new QtxMultiAction( this ); + aPanningAction->insertAction( getAction( PanId ) ); + aPanningAction->insertAction( getAction( GlobalPanId ) ); + mgr->append( aPanningAction, myToolBar ); + + mgr->append( ChangeRotationPointId, myToolBar ); + + mgr->append( RotationId, myToolBar ); + + QtxMultiAction* aViewsAction = new QtxMultiAction( this ); + aViewsAction->insertAction( getAction( FrontId ) ); + aViewsAction->insertAction( getAction( BackId ) ); + aViewsAction->insertAction( getAction( TopId ) ); + aViewsAction->insertAction( getAction( BottomId ) ); + aViewsAction->insertAction( getAction( LeftId ) ); + aViewsAction->insertAction( getAction( RightId ) ); + mgr->append( aViewsAction, myToolBar ); + + mgr->append( ResetId, myToolBar ); + + mgr->append( UpdateRate, myToolBar ); + mgr->append( NonIsometric, myToolBar ); + mgr->append( GraduatedAxes, myToolBar ); + + mgr->append( ViewParametersId, myToolBar ); + mgr->append( ProjectionModeId, myToolBar ); + + mgr->append( StartRecordingId, myRecordingToolBar ); + mgr->append( PlayRecordingId, myRecordingToolBar ); + mgr->append( PauseRecordingId, myRecordingToolBar ); + mgr->append( StopRecordingId, myRecordingToolBar ); +} + +void SVTK_ViewWindow::onUpdateRate(bool theIsActivate) +{ + if(theIsActivate){ + myUpdateRateDlg->Update(); + myUpdateRateDlg->show(); + }else + myUpdateRateDlg->hide(); +} + +void SVTK_ViewWindow::onNonIsometric(bool theIsActivate) +{ + if(theIsActivate){ + myNonIsometricDlg->Update(); + myNonIsometricDlg->show(); + }else + myNonIsometricDlg->hide(); +} + +void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate) +{ + if(theIsActivate){ + myCubeAxesDlg->Update(); + myCubeAxesDlg->show(); + }else + myCubeAxesDlg->hide(); +} + +/*! + Starts rotation transformation +*/ +void SVTK_ViewWindow::activateRotation() +{ + myEventDispatcher->InvokeEvent(SVTK::StartRotate,0); +} + + +/*! + Starts panning transformation +*/ +void SVTK_ViewWindow::activatePanning() +{ + myEventDispatcher->InvokeEvent(SVTK::StartPan,0); +} + +/*! + Starts zoom transformation +*/ +void SVTK_ViewWindow::activateZoom() +{ + myEventDispatcher->InvokeEvent(SVTK::StartZoom,0); +} + +/*! + Starts window fit transformation +*/ +void SVTK_ViewWindow::activateWindowFit() +{ + myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0); +} + +/*! + Starts global panning transformation +*/ +void SVTK_ViewWindow::activateGlobalPanning() +{ + myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0); +} + +void SVTK_ViewWindow::onStartRecording() +{ + myRecorder->CheckExistAVIMaker(); + if (myRecorder->ErrorStatus()) { + SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") ); + } + else { + SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder ); + + if( !aRecorderDlg->exec() ) + return; + + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( true ); + myStopAction->setEnabled( true ); + + // to prevent resizing the window while recording + myPreRecordingMinSize = minimumSize(); + myPreRecordingMaxSize = maximumSize(); + setFixedSize( size() ); + + myRecorder->Record(); + } +} + +void SVTK_ViewWindow::onPlayRecording() +{ + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( true ); + myStopAction->setEnabled( true ); + + myRecorder->Pause(); +} + +void SVTK_ViewWindow::onPauseRecording() +{ + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( true ); + myPauseAction->setEnabled( false ); + myStopAction->setEnabled( true ); + + myRecorder->Pause(); +} + +void SVTK_ViewWindow::onStopRecording() +{ + myStartAction->setEnabled( true ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( false ); + myStopAction->setEnabled( false ); + + myRecorder->Stop(); + + setMinimumSize( myPreRecordingMinSize ); + setMaximumSize( myPreRecordingMaxSize ); +} + +/*! + To invoke a VTK event on SVTK_RenderWindowInteractor instance +*/ +void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData) +{ + GetInteractor()->InvokeEvent(theEvent,theCallData); +} + +/*! + Modify view parameters +*/ +void SVTK_ViewWindow::onViewParameters(bool theIsActivate) +{ + if(theIsActivate){ + myViewParameterDlg->addObserver(); + myViewParameterDlg->show(); + }else + myViewParameterDlg->hide(); +} + +/*! + Custom show event handler +*/ +void SVTK_ViewWindow::showEvent( QShowEvent * theEvent ) +{ + emit Show( theEvent ); +} + +/*! + Custom hide event handler +*/ +void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent ) +{ + emit Hide( theEvent ); +} + diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 811752c97..0b5f2014a 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -30,14 +30,16 @@ #include "SALOME_InteractiveObject.hxx" #include +#include class SUIT_Desktop; +class SUIT_ResourceMgr; class VTKViewer_Actor; class VTKViewer_Trihedron; class SVTK_ViewModelBase; -class SVTK_MainWindow; +//class SVTK_MainWindow; class SVTK_Selector; class SVTK_View; @@ -46,6 +48,19 @@ class SVTK_CubeAxesActor2D; class vtkRenderer; class vtkRenderWindow; class vtkRenderWindowInteractor; +class vtkInteractorStyle; +class SVTK_RenderWindowInteractor; +class SVTK_Renderer; +class SVTK_NonIsometricDlg; +class SVTK_UpdateRateDlg; +class SVTK_CubeAxesDlg; +class SVTK_SetRotationPointDlg; +class SVTK_KeyFreeInteractorStyle; +class SVTK_ViewParameterDlg; +class SVTK_Recorder; + +class vtkObject; +class QtxAction; namespace SVTK { @@ -62,279 +77,258 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow //! To construct #SVTK_ViewWindow instance SVTK_ViewWindow(SUIT_Desktop* theDesktop); - virtual - ~SVTK_ViewWindow(); + virtual ~SVTK_ViewWindow(); virtual QImage dumpView(); //! To initialize #SVTK_ViewWindow instance - virtual - void - Initialize(SVTK_ViewModelBase* theModel); + virtual void Initialize(SVTK_ViewModelBase* theModel); //! Get #SVTK_View - SVTK_View* - getView(); + SVTK_View* getView(); //! Get #SVTK_MainWindow - SVTK_MainWindow* - getMainWindow(); + //SVTK_MainWindow* getMainWindow(); //! Redirect the request to #SVTK_MainWindow::getRenderWindow - vtkRenderWindow* - getRenderWindow(); + vtkRenderWindow* getRenderWindow(); //! Redirect the request to #SVTK_MainWindow::getInteractor - vtkRenderWindowInteractor* - getInteractor(); + vtkRenderWindowInteractor* getInteractor() const; + + //! Redirect the request to #SVTK_MainWindow::getInteractor + SVTK_RenderWindowInteractor* GetInteractor() const; + + vtkInteractorStyle* GetInteractorStyle() const; + + //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle + void PushInteractorStyle(vtkInteractorStyle* theStyle); + + //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle + void PopInteractorStyle(); //! Redirect the request to #SVTK_MainWindow::getRenderer - vtkRenderer* - getRenderer(); + vtkRenderer* getRenderer() const; + + SVTK_Renderer* GetRenderer() const; //! Redirect the request to #SVTK_MainWindow::GetSelector - SVTK_Selector* - GetSelector(); + SVTK_Selector* GetSelector() const; //! Redirect the request to #SVTK_Selector::SelectionMode - Selection_Mode - SelectionMode() const; + Selection_Mode SelectionMode() const; //! Change selection mode - virtual - void - SetSelectionMode(Selection_Mode theMode); + virtual void SetSelectionMode(Selection_Mode theMode); //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor - virtual - void - setBackgroundColor( const QColor& ); + virtual void setBackgroundColor( const QColor& ); //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor - QColor - backgroundColor() const; + QColor backgroundColor() const; //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed - bool - isTrihedronDisplayed(); + bool isTrihedronDisplayed(); //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed - bool - isCubeAxesDisplayed(); + bool isCubeAxesDisplayed(); /* interactive object management */ //! Redirect the request to #SVTK_View::highlight (to support old code) - virtual - void - highlight(const Handle(SALOME_InteractiveObject)& theIO, - bool theIsHighlight = true, - bool theIsUpdate = true); + virtual void highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight = true, + bool theIsUpdate = true); //! Redirect the request to #SVTK_View::unHighlightAll (to support old code) - virtual - void - unHighlightAll(); + virtual void unHighlightAll(); //! Redirect the request to #SVTK_View::isInViewer (to support old code) - bool - isInViewer(const Handle(SALOME_InteractiveObject)& theIObject); + bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject); //! Redirect the request to #SVTK_View::isVisible (to support old code) - bool - isVisible(const Handle(SALOME_InteractiveObject)& theIObject); + bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject); //! Redirect the request to #SVTK_View::FindIObject (to support old code) //---------------------------------------------------------------------------- - Handle(SALOME_InteractiveObject) - FindIObject(const char* theEntry); + Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry); /* display */ //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_View::Display (to support old code) - virtual - void - Display(const Handle(SALOME_InteractiveObject)& theIObject, - bool theImmediatly = true); + virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject, + bool theImmediatly = true); //! Redirect the request to #SVTK_View::DisplayOnly (to support old code) - virtual - void - DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject); + virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject); //! Redirect the request to #SVTK_View::Erase (to support old code) - virtual - void - Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool theImmediatly = true); + virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject, + bool theImmediatly = true); //! Redirect the request to #SVTK_View::DisplayAll (to support old code) - virtual - void - DisplayAll(); + virtual void DisplayAll(); //! Redirect the request to #SVTK_View::EraseAll (to support old code) - virtual - void - EraseAll(); + virtual void EraseAll(); //! To repaint the viewer - virtual - void - Repaint(bool theUpdateTrihedron = true); + virtual void Repaint(bool theUpdateTrihedron = true); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_Renderer::SetScale - virtual - void - SetScale( double theScale[3] ); + virtual void SetScale( double theScale[3] ); //! Redirect the request to #SVTK_Renderer::GetScale - virtual - void - GetScale( double theScale[3] ); + virtual void GetScale( double theScale[3] ); //! Redirect the request to #SVTK_Renderer::AddActor - virtual - void - AddActor(VTKViewer_Actor* theActor, - bool theIsUpdate = false); + virtual void AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); //! Redirect the request to #SVTK_Renderer::RemoveActor - virtual - void - RemoveActor(VTKViewer_Actor* theActor, - bool theIsUpdate = false); + virtual void RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_Renderer::AdjustActors - virtual - void - AdjustTrihedrons(const bool theIsForced); + virtual void AdjustTrihedrons(const bool theIsForced); //! Redirect the request to #SVTK_Renderer::GetTrihedron - VTKViewer_Trihedron* - GetTrihedron(); + VTKViewer_Trihedron* GetTrihedron(); //! Redirect the request to #SVTK_Renderer::GetCubeAxes - SVTK_CubeAxesActor2D* - GetCubeAxes(); + SVTK_CubeAxesActor2D* GetCubeAxes(); //! Redirect the request to #SVTK_Renderer::GetTrihedronSize - vtkFloatingPointType - GetTrihedronSize() const; + vtkFloatingPointType GetTrihedronSize() const; //! Redirect the request to #SVTK_Renderer::SetTrihedronSize - virtual - void - SetTrihedronSize( const vtkFloatingPointType, const bool = true ); + virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true ); + + //! Redirect the request to #SVTK_MainWindow::SetIncrementalSpeed + virtual void SetIncrementalSpeed( const int, const int = 0 ); + + //! Redirect the request to #SVTK_MainWindow::SetProjectionMode + virtual void SetProjectionMode( const int ); + + //! Redirect the request to #SVTK_MainWindow::SetInteractionStyle + virtual void SetInteractionStyle( const int ); + + //! Redirect the request to #SVTK_MainWindow::SetSpacemouseButtons + virtual void SetSpacemouseButtons( const int, const int, const int ); //! Redirect the request to #SVTK_Renderer::SetSelectionProp - virtual - void - SetSelectionProp(const double& theRed = 1, - const double& theGreen = 1, - const double& theBlue = 0, - const int& theWidth = 5); + virtual void SetSelectionProp(const double& theRed = 1, + const double& theGreen = 1, + const double& theBlue = 0, + const int& theWidth = 5); //! Redirect the request to #SVTK_Renderer::SetPreselectionProp - virtual - void - SetPreselectionProp(const double& theRed = 0, - const double& theGreen = 1, - const double& theBlue = 1, - const int& theWidth = 5); + virtual void SetPreselectionProp(const double& theRed = 0, + const double& theGreen = 1, + const double& theBlue = 1, + const int& theWidth = 5); //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance - virtual - void - SetSelectionTolerance(const double& theTolNodes = 0.025, - const double& theTolCell = 0.001, - const double& theTolObjects = 0.025); + virtual void SetSelectionTolerance(const double& theTolNodes = 0.025, + const double& theTolCell = 0.001, + const double& theTolObjects = 0.025); //! Methods to save/restore visual parameters of a view (pan, zoom, etc.) - virtual - QString - getVisualParameters(); + virtual QString getVisualParameters(); - virtual - void - setVisualParameters( const QString& parameters ); + virtual void setVisualParameters( const QString& parameters ); - virtual - bool - eventFilter( QObject*, QEvent* ); + virtual bool eventFilter( QObject*, QEvent* ); - virtual - void RefreshDumpImage(); + virtual void RefreshDumpImage(); + + //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance + void InvokeEvent(unsigned long theEvent, void* theCallData); + signals: + void Show( QShowEvent * ); + void Hide( QHideEvent * ); + public slots: - virtual - void - onSelectionChanged(); + virtual void showEvent( QShowEvent * ); + virtual void hideEvent( QHideEvent * ); + virtual void onSelectionChanged(); + + void onChangeRotationPoint(bool theIsActivate); + + void activateSetRotationGravity(); + void activateSetRotationSelected(void* theData); + void activateStartPointSelection(); + + void onUpdateRate(bool theIsActivate); + void onNonIsometric(bool theIsActivate); + void onGraduatedAxes(bool theIsActivate); + + void activateZoom(); + void activateWindowFit(); + void activateRotation(); + void activatePanning(); + void activateGlobalPanning(); + + void onProjectionMode(int mode); + + void activateProjectionMode(int); + + void activateSetFocalPointGravity(); + void activateSetFocalPointSelected(); + void activateStartFocalPointSelection(); + + void onViewParameters(bool theIsActivate); + + void onSwitchInteractionStyle(bool theOn); + + void onStartRecording(); + void onPlayRecording(); + void onPauseRecording(); + void onStopRecording(); signals: void selectionChanged(); + void actorAdded(VTKViewer_Actor*); + void actorRemoved(VTKViewer_Actor*); public slots: //! Redirect the request to #SVTK_Renderer::OnFrontView - virtual - void - onFrontView(); + virtual void onFrontView(); //! Redirect the request to #SVTK_Renderer::OnBackView - virtual - void - onBackView(); + virtual void onBackView(); //! Redirect the request to #SVTK_Renderer::OnTopView - virtual - void - onTopView(); + virtual void onTopView(); //! Redirect the request to #SVTK_Renderer::OnBottomView - virtual - void - onBottomView(); + virtual void onBottomView(); //! Redirect the request to #SVTK_Renderer::OnRightView - virtual - void - onRightView(); + virtual void onRightView(); //! Redirect the request to #SVTK_Renderer::OnLeftView - virtual - void - onLeftView(); + virtual void onLeftView(); //! Redirect the request to #SVTK_Renderer::OnResetView - virtual - void - onResetView(); + virtual void onResetView(); //! Redirect the request to #SVTK_Renderer::OnFitAll - virtual - void - onFitAll(); + virtual void onFitAll(); //! Redirect the request to #SVTK_Renderer::OnViewTrihedron - virtual - void - onViewTrihedron(); + virtual void onViewTrihedron(); //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes - virtual - void - onViewCubeAxes(); + virtual void onViewCubeAxes(); //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron - virtual - void - onAdjustTrihedron(); + virtual void onAdjustTrihedron(); //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes - virtual - void - onAdjustCubeAxes(); + virtual void onAdjustCubeAxes(); protected slots: void onKeyPressed(QKeyEvent* event); @@ -345,25 +339,58 @@ protected slots: void onMouseMoving(QMouseEvent* event); protected: - virtual - void - Initialize(SVTK_View* theView, - SVTK_ViewModelBase* theModel); + virtual void Initialize(SVTK_View* theView, + SVTK_ViewModelBase* theModel); - void - doSetVisualParameters( const QString& ); + void doSetVisualParameters( const QString& ); + void SetEventDispatcher(vtkObject* theDispatcher); virtual QString filter() const; virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format ); virtual bool action( const int ); + QtxAction* getAction( int ) const; + void createToolBar(); + void createActions(SUIT_ResourceMgr* theResourceMgr); + + enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, + ChangeRotationPointId, RotationId, + FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, + ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate, + ProjectionModeId, ViewParametersId, SwitchInteractionStyleId, + StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId }; + + SVTK_View* myView; - SVTK_MainWindow* myMainWindow; + //SVTK_MainWindow* myMainWindow; SVTK_ViewModelBase* myModel; + SVTK_RenderWindowInteractor* myInteractor; + vtkSmartPointer myKeyFreeInteractorStyle; + QString myVisualParams; // used for delayed setting of view parameters + vtkSmartPointer myEventDispatcher; + + SVTK_NonIsometricDlg* myNonIsometricDlg; + SVTK_UpdateRateDlg* myUpdateRateDlg; + SVTK_CubeAxesDlg* myCubeAxesDlg; + SVTK_SetRotationPointDlg* mySetRotationPointDlg; + SVTK_ViewParameterDlg* myViewParameterDlg; + + QSize myPreRecordingMinSize; + QSize myPreRecordingMaxSize; + + SVTK_Recorder* myRecorder; + QtxAction* myStartAction; + QtxAction* myPlayAction; + QtxAction* myPauseAction; + QtxAction* myStopAction; + + int myToolBar; + int myRecordingToolBar; + private: QImage myDumpImage; }; diff --git a/src/SVTK/resources/SVTK_images.ts b/src/SVTK/resources/SVTK_images.ts index 060908a75..38b7285ff 100644 --- a/src/SVTK/resources/SVTK_images.ts +++ b/src/SVTK/resources/SVTK_images.ts @@ -17,5 +17,37 @@ ICON_SVTK_UPDATE_RATE vtk_view_update_rate.png + + ICON_SVTK_VIEW_PARAMETERS + vtk_view_parameters.png + + + ICON_SVTK_VIEW_PARALLEL + vtk_view_parallel.png + + + ICON_SVTK_VIEW_PERSPECTIVE + vtk_view_perspective.png + + + ICON_SVTK_STYLE_SWITCH + vtk_view_style_switch.png + + + ICON_SVTK_RECORDING_START + vtk_view_recording_start.png + + + ICON_SVTK_RECORDING_PLAY + vtk_view_recording_play.png + + + ICON_SVTK_RECORDING_PAUSE + vtk_view_recording_pause.png + + + ICON_SVTK_RECORDING_STOP + vtk_view_recording_stop.png + diff --git a/src/SVTK/resources/SVTK_msg_en.ts b/src/SVTK/resources/SVTK_msg_en.ts index 56b0e3d74..e8467cd57 100644 --- a/src/SVTK/resources/SVTK_msg_en.ts +++ b/src/SVTK/resources/SVTK_msg_en.ts @@ -153,6 +153,30 @@ SVTK_IMAGE_FILES Images Files (*.bmp *.png *.jpg *.jpeg *.pdf *.ps *.eps) + + MNU_VIEWPARAMETERS_VIEW + Change View Parameters + + + DSC_VIEWPARAMETERS_VIEW + Change the parameters of the view + + + MNU_SVTK_PROJECTION_MODE + Projection Mode + + + DSC_SVTK_PROJECTION_MODE + Set orthogonal or perspective projection of the view + + + DSC_SVTK_STYLE_SWITCH + Interactiion style switch + + + MNU_SVTK_STYLE_SWITCH + Interaction Style Switch + SVTK_CubeAxesDlg @@ -237,7 +261,7 @@ - SVTK_MainWindow + SVTK_ViewWindow DSC_SVTK_UPDATE_RATE Update rate @@ -262,6 +286,47 @@ MNU_SVTK_UPDATE_RATE Update rate + + DSC_SVTK_RECORDING_START + Start recording + + + MNU_SVTK_RECORDING_START + Start recording + + + DSC_SVTK_RECORDING_PLAY + Play recording + + + MNU_SVTK_RECORDING_PLAY + Play recording + + + DSC_SVTK_RECORDING_PAUSE + Pause recording + + + MNU_SVTK_RECORDING_PAUSE + Pause recording + + + DSC_SVTK_RECORDING_STOP + Stop recording + + + MNU_SVTK_RECORDING_STOP + Stop recording + + + LBL_TOOLBAR_RECORD_LABEL + Recording Operations + + + MSG_NO_AVI_MAKER + Tool jpeg2yuv, necessary for AVI recording, is not available. +Please, refer to the documentation. + SVTK_NonIsometricDlg @@ -286,6 +351,65 @@ Scaling + + SVTK_RecorderDlg + + ALL_DISLPAYED_FRAMES + Recording all displayed frames + + + CLOSE + Close + + + DLG_RECORDER_TITLE + Recorder + + + FILE_NAME + Save to file : + + + FLT_ALL_FILES + All Files (*.*) + + + FLT_AVI_FILES + AVI Files (*.avi) + + + FPS + FPS : + + + HELP + Help + + + PROGRESSIVE + Progressive + + + QUALITY + Quality : + + + RECORDING_MODE + Mode : + + + SETTINGS + Settings + + + SKIPPED_FRAMES + Recording at a given FPS + + + START + Start + + SVTK_SetRotationPointDlg @@ -333,6 +457,105 @@ Set Rotation Point + + SVTK_ViewParameterDlg + + LBL_X + X : + + + LBL_Y + Y : + + + LBL_Z + Z : + + + LBL_DX + DX : + + + LBL_DY + DY : + + + LBL_DZ + DZ : + + + PROJECTION_MODE + Projection Mode + + + ORTHOGONAL_MODE + Orthogonal + + + PERSPECTIVE_MODE + Perspective + + + USE_BBCENTER + Use Bounding Box Center + + + LBL_TOBBCENTER + Set to Bounding Box Center + + + LBL_TOORIGIN + Set to Origin + + + LBL_SELECTPOINT + Select Point from View + + + FOCAL_POINT + Focal Point + + + CAMERA_POSITION + Camera Position + + + WORLD_COORDINATES + World Coordinates + + + FOCAL_RELATIVE + Relative to Focal Point + + + PROJECTION_DIRECTION + Projection Direction : + + + FOCAL_DISTANCE + Focal Distance : + + + VIEW_UP_DIRECTION + View Up Direction : + + + ZOOMING + Zooming + + + LBL_SCALE + Scale + + + LBL_VIEW_ANGLE + View Angle + + + DLG_TITLE + View Parameters + + SVTK_UpdateRateDlg diff --git a/src/SVTK/resources/vtk_view_parallel.png b/src/SVTK/resources/vtk_view_parallel.png new file mode 100755 index 000000000..dd7a67600 Binary files /dev/null and b/src/SVTK/resources/vtk_view_parallel.png differ diff --git a/src/SVTK/resources/vtk_view_parameters.png b/src/SVTK/resources/vtk_view_parameters.png new file mode 100755 index 000000000..0eee8cc0c Binary files /dev/null and b/src/SVTK/resources/vtk_view_parameters.png differ diff --git a/src/SVTK/resources/vtk_view_perspective.png b/src/SVTK/resources/vtk_view_perspective.png new file mode 100755 index 000000000..36cdd4c31 Binary files /dev/null and b/src/SVTK/resources/vtk_view_perspective.png differ diff --git a/src/SVTK/resources/vtk_view_recording_pause.png b/src/SVTK/resources/vtk_view_recording_pause.png new file mode 100644 index 000000000..f181a0f6b Binary files /dev/null and b/src/SVTK/resources/vtk_view_recording_pause.png differ diff --git a/src/SVTK/resources/vtk_view_recording_play.png b/src/SVTK/resources/vtk_view_recording_play.png new file mode 100644 index 000000000..7724f48bb Binary files /dev/null and b/src/SVTK/resources/vtk_view_recording_play.png differ diff --git a/src/SVTK/resources/vtk_view_recording_start.png b/src/SVTK/resources/vtk_view_recording_start.png new file mode 100644 index 000000000..5b71dc511 Binary files /dev/null and b/src/SVTK/resources/vtk_view_recording_start.png differ diff --git a/src/SVTK/resources/vtk_view_recording_stop.png b/src/SVTK/resources/vtk_view_recording_stop.png new file mode 100644 index 000000000..04db9e3a6 Binary files /dev/null and b/src/SVTK/resources/vtk_view_recording_stop.png differ diff --git a/src/SVTK/resources/vtk_view_style_switch.png b/src/SVTK/resources/vtk_view_style_switch.png new file mode 100755 index 000000000..b0a9c807e Binary files /dev/null and b/src/SVTK/resources/vtk_view_style_switch.png differ