From: nkv Date: Thu, 5 Jun 2008 09:54:53 +0000 (+0000) Subject: Set view projection mode via toolbar buttons X-Git-Tag: TG_VISU_2008_2008-06-26~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=01ae71e05e0049941f01239f09a9bbbe3c8ad59b;p=modules%2Fgui.git Set view projection mode via toolbar buttons --- diff --git a/src/SVTK/Makefile.am b/src/SVTK/Makefile.am index f652ecb8c..67d38a199 100755 --- a/src/SVTK/Makefile.am +++ b/src/SVTK/Makefile.am @@ -53,6 +53,7 @@ salomeinclude_HEADERS= \ SVTK_ViewModelBase.h \ SVTK_SetRotationPointDlg.h \ SVTK_ViewParameterDlg.h \ + SVTK_ComboAction.h \ SVTK_Extension.h dist_libSVTK_la_SOURCES= \ @@ -81,6 +82,7 @@ dist_libSVTK_la_SOURCES= \ SVTK_Selector.cxx \ SVTK_SetRotationPointDlg.cxx \ SVTK_ViewParameterDlg.cxx \ + SVTK_ComboAction.cxx \ SVTK_Extension.cxx EXTRA_DIST+= SVTK_SelectorDef.h SVTK_Trihedron.h @@ -100,7 +102,8 @@ MOC_FILES= \ SVTK_ViewModel_moc.cxx \ SVTK_View_moc.cxx \ SVTK_SetRotationPointDlg_moc.cxx \ - SVTK_ViewParameterDlg_moc.cxx + SVTK_ViewParameterDlg_moc.cxx \ + SVTK_ComboAction_moc.cxx nodist_libSVTK_la_SOURCES= $(MOC_FILES) dist_salomeres_DATA=\ 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_MainWindow.cxx b/src/SVTK/SVTK_MainWindow.cxx index 6d10964f0..5ba722889 100644 --- a/src/SVTK/SVTK_MainWindow.cxx +++ b/src/SVTK/SVTK_MainWindow.cxx @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -55,6 +56,7 @@ #include "SVTK_RenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" #include "SVTK_Selector.h" +#include "SVTK_ComboAction.h" /*! Constructor @@ -584,6 +586,14 @@ SVTK_MainWindow 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" ) ), @@ -640,6 +650,7 @@ SVTK_MainWindow mgr->append( NonIsometric, myToolBar ); mgr->append( GraduatedAxes, myToolBar ); + mgr->append( ProjectionModeId, myToolBar ); mgr->append( ViewParametersId, myToolBar ); } @@ -739,6 +750,18 @@ SVTK_MainWindow myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0); } +/*! + 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 */ @@ -779,6 +802,12 @@ SVTK_MainWindow myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0); } +void SVTK_MainWindow::activateProjectionMode(int mode) +{ + SVTK_ComboAction* a = ::qobject_cast( action(ProjectionModeId) ); + if ( a ) a->setCurrentIndex(mode); +} + /*! Starts global panning transformation */ diff --git a/src/SVTK/SVTK_MainWindow.h b/src/SVTK/SVTK_MainWindow.h index 7bdba4a78..30d4a5261 100644 --- a/src/SVTK/SVTK_MainWindow.h +++ b/src/SVTK/SVTK_MainWindow.h @@ -225,6 +225,8 @@ public: void onViewParameters(bool theIsActivate); + void activateProjectionMode(int); + void activateSetFocalPointGravity(); void activateSetFocalPointSelected(); void activateStartFocalPointSelection(); @@ -239,6 +241,8 @@ public: void onAdjustTrihedron(); void onAdjustCubeAxes(); + void onProjectionMode(int mode); + public: QImage dumpView(); @@ -260,7 +264,7 @@ public: ChangeRotationPointId, RotationId, FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate, - ViewParametersId }; + ProjectionModeId, ViewParametersId }; SUIT_ViewWindow* myViewWindow; diff --git a/src/SVTK/SVTK_ViewParameterDlg.cxx b/src/SVTK/SVTK_ViewParameterDlg.cxx index fcb6c6f80..cc456fac1 100755 --- a/src/SVTK/SVTK_ViewParameterDlg.cxx +++ b/src/SVTK/SVTK_ViewParameterDlg.cxx @@ -449,6 +449,7 @@ void SVTK_ViewParameterDlg::updateData() 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; @@ -507,6 +508,8 @@ void SVTK_ViewParameterDlg::onProjectionModeChanged(int mode) vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera(); aCamera->SetParallelProjection(aBtn == 0); + myMainWindow->activateProjectionMode(aBtn); + // update view myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);