1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Slider.cxx
24 // Author : Oleg UVAROV
27 #include "VisuGUI_Sweep.h"
29 #include "SUIT_ResourceMgr.h"
31 #include "LightApp_SelectionMgr.h"
33 #include "VISU_Actor.h"
36 #include "VisuGUI_Tools.h"
37 #include "VisuGUI_ViewTools.h"
38 #include "VISU_ColoredPrs3d_i.hh"
39 #include "VISU_Actor.h"
41 #include "QtxDockWidget.h"
42 #include "QtxIntSpinBox.h"
43 #include "QtxDoubleSpinBox.h"
45 #include <QMainWindow>
51 #include <QToolButton>
56 #include <QRadioButton>
65 VisuGUI_Sweep::VisuGUI_Sweep( VisuGUI* theModule,
66 QMainWindow* theParent,
67 LightApp_SelectionMgr* theSelectionMgr )
68 : QWidget( theParent )
69 , myModule( theModule )
70 , myViewWindow( NULL )
72 setWindowTitle( tr("TITLE") );
73 setObjectName( tr("TITLE") );
75 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
77 //----------------------------------------------------------------------------
78 QVBoxLayout* aVBoxLayout = new QVBoxLayout( this );
80 QTabWidget* aTabWidget = new QTabWidget( this );
81 aTabWidget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
82 aVBoxLayout->addWidget( aTabWidget );
85 QWidget* aNavigationTab = new QWidget();
87 QVBoxLayout* aVBoxLayout = new QVBoxLayout( aNavigationTab );
89 QHBoxLayout* aHBoxLayout = new QHBoxLayout();
91 QLabel* aStartSweepPosition = new QLabel( aNavigationTab );
92 aStartSweepPosition->setText( tr( "START_SWEEP_POSITION" ) );
93 aHBoxLayout->addWidget( aStartSweepPosition );
95 mySweepSlider = new QSlider( aNavigationTab );
96 mySweepSlider->setOrientation( Qt::Horizontal );
97 mySweepSlider->setMinimum( 0 );
98 aHBoxLayout->addWidget( mySweepSlider );
100 QLabel* anEndSweepPosition = new QLabel( aNavigationTab );
101 anEndSweepPosition->setText( tr( "END_SWEEP_POSITION" ) );
102 aHBoxLayout->addWidget( anEndSweepPosition );
104 aVBoxLayout->addLayout( aHBoxLayout );
107 QHBoxLayout* aHBoxLayout = new QHBoxLayout();
109 myFirstButton = new QToolButton( aNavigationTab );
110 myFirstButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_FIRST" ) ) );
111 myFirstButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
112 connect( myFirstButton, SIGNAL( clicked() ), SLOT( onFirst() ) );
113 aHBoxLayout->addWidget( myFirstButton );
115 myPreviousButton = new QToolButton( aNavigationTab );
116 myPreviousButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PREVIOUS" ) ) );
117 myPreviousButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
118 connect( myPreviousButton, SIGNAL( clicked() ), SLOT( onPrevious() ) );
119 aHBoxLayout->addWidget( myPreviousButton );
121 myPlayButton = new QToolButton( aNavigationTab );
122 myPlayButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) ) );
123 myPlayButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
124 myPlayButton->setCheckable( true );
125 aHBoxLayout->addWidget( myPlayButton );
127 myNextButton = new QToolButton( aNavigationTab );
128 myNextButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_NEXT" ) ) );
129 myNextButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
130 connect( myNextButton, SIGNAL( clicked() ), SLOT( onNext() ) );
131 aHBoxLayout->addWidget( myNextButton );
133 myLastButton = new QToolButton( aNavigationTab );
134 myLastButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_LAST" ) ) );
135 myLastButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
136 connect( myLastButton, SIGNAL( clicked() ), SLOT( onLast() ) );
137 aHBoxLayout->addWidget( myLastButton );
139 aVBoxLayout->addLayout( aHBoxLayout );
142 QHBoxLayout* aHBoxLayout = new QHBoxLayout();
144 QToolButton* aStopButton = new QToolButton( aNavigationTab );
145 aStopButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SWEEP_STOP" ) ) );
146 aStopButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
147 aStopButton->setCheckable( false );
148 connect( aStopButton, SIGNAL( clicked( ) ), SLOT( onStop( ) ) );
149 aHBoxLayout->addWidget( aStopButton );
151 myIsCycled = new QCheckBox( aNavigationTab );
152 myIsCycled->setText( tr( "IS_CYCLED" ) );
153 myIsCycled->setChecked( false );
154 aHBoxLayout->addWidget( myIsCycled );
156 aVBoxLayout->addLayout( aHBoxLayout );
159 aTabWidget->addTab( aNavigationTab, tr( "NAVIGATION_TAB" ) );
163 QWidget* aPropertiesTab = new QWidget();
165 QGridLayout* aGridLayout = new QGridLayout( aPropertiesTab );
167 QHBoxLayout* aHBoxLayout = new QHBoxLayout();
169 QLabel* aModeAnnotation = new QLabel( aPropertiesTab );
170 aModeAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
171 aModeAnnotation->setText( tr( "MODE" ) );
172 aHBoxLayout->addWidget( aModeAnnotation );
174 mySweepMode = new QComboBox( aPropertiesTab );
175 mySweepMode->insertItems( 0, QStringList()
177 << tr( "COSINUSOIDAL" )
178 << tr( "SINUSOIDAL" ) );
179 mySweepMode->setCurrentIndex( aResourceMgr->integerValue( "VISU", "sweeping_modes", 0 ) );
180 aHBoxLayout->addWidget( mySweepMode );
182 myIntervals = new QComboBox( aPropertiesTab );
183 myIntervals->insertItems( 0, QStringList()
184 << tr( "[ 0, +PI ]" )
185 << tr( "[ -PI, +PI ]" ) );
186 myIntervals->setCurrentIndex( aResourceMgr->integerValue( "VISU", "sweeping_is2PI", 0 ) );
187 aHBoxLayout->addWidget( myIntervals );
189 aGridLayout->addLayout( aHBoxLayout, 0, 0, 1, 2 );
192 QLabel* aNumberOfStepsAnnotation = new QLabel( aPropertiesTab );
193 aNumberOfStepsAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
194 aNumberOfStepsAnnotation->setText( tr( "NUMBER_OF_STEPS" ) );
195 aGridLayout->addWidget( aNumberOfStepsAnnotation, 1, 0, 1, 1 );
197 myNumberOfSteps = new QtxIntSpinBox( aPropertiesTab );
198 connect( myNumberOfSteps, SIGNAL( valueChanged( int ) ), SLOT( onNumberOfStepsChanged( int ) ) );
199 myNumberOfSteps->setValue( aResourceMgr->integerValue( "VISU", "sweeping_number_steps", 40 ) );
200 aGridLayout->addWidget( myNumberOfSteps, 1, 1, 1, 1 );
202 QLabel* aStepDelayAnnotation = new QLabel( aPropertiesTab );
203 aStepDelayAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
204 aStepDelayAnnotation->setText( tr( "DELAY_BETWEEN_STEPS" ) );
205 aGridLayout->addWidget( aStepDelayAnnotation, 2, 0, 1, 1 );
207 myStepDelay = new QtxDoubleSpinBox( aPropertiesTab );
208 myStepDelay->setValue( aResourceMgr->doubleValue("VISU", "sweeping_time_step", 0.1) );
209 aGridLayout->addWidget( myStepDelay, 2, 1, 1, 1 );
212 aTabWidget->addTab( aPropertiesTab, tr( "PROPERTIES_TAB" ) );
216 QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
217 aVBoxLayout->addItem( aSpacerItem );
221 //----------------------------------------------------------------------------
222 QtxDockWidget* aQtxDockWidget = new QtxDockWidget( true, theParent );
223 theParent->addDockWidget( Qt::BottomDockWidgetArea , aQtxDockWidget );
224 aQtxDockWidget->setObjectName( objectName() );
225 aQtxDockWidget->setWidget( this );
227 myToggleViewAction = aQtxDockWidget->toggleViewAction();
228 myToggleViewAction->setIcon( QIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SWEEP_PANEL" ) ) ) );
229 myToggleViewAction->setToolTip( tr( "MEN_SWEEP_PANE" ) );
230 myToggleViewAction->setText( tr( "MEN_SWEEP_PANE" ) );
231 myToggleViewAction->setCheckable( true );
232 aQtxDockWidget->setVisible( false );
234 connect( myToggleViewAction, SIGNAL( toggled( bool ) ), this, SLOT( onToggleView( bool ) ) );
236 //----------------------------------------------------------------------------
237 myTimer = new QTimer( this );
239 myPlayPixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) );
240 myPausePixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PAUSE" ) );
242 connect( myTimer, SIGNAL( timeout() ), SLOT( onTimeout() ) );
244 connect( myPlayButton, SIGNAL( toggled( bool ) ), SLOT( onPlay( bool ) ) );
246 connect( mySweepSlider, SIGNAL( valueChanged( int ) ), SLOT( onValueChanged( int ) ) );
248 connect( myStepDelay, SIGNAL( valueChanged( double ) ), SLOT( onDelayChanged( double ) ) );
250 connect( mySweepMode, SIGNAL( currentIndexChanged( int ) ), SLOT( onModeChanged( int ) ) );
252 connect( theModule, SIGNAL( moduleDeactivated() ), SLOT( onModuleDeactivated() ) );
254 connect( theModule, SIGNAL( moduleActivated() ), SLOT( onModuleActivated() ) );
256 connect( theSelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionChanged() ) );
258 onSelectionChanged();
260 onModeChanged( mySweepMode->currentIndex() );
264 //----------------------------------------------------------------------------
265 VisuGUI_Sweep::~VisuGUI_Sweep()
269 //----------------------------------------------------------------------------
270 QAction* VisuGUI_Sweep::toggleViewAction()
272 return myToggleViewAction;
276 //----------------------------------------------------------------------------
277 void VisuGUI_Sweep::onModuleDeactivated()
285 //----------------------------------------------------------------------------
286 void VisuGUI_Sweep::onModuleActivated()
292 //----------------------------------------------------------------------------
297 VisuGUI_Sweep* myWidget;
298 bool& myIsValidSelection;
300 TEnabler( VisuGUI_Sweep* theWidget, bool& theIsValidSelection )
301 : myWidget( theWidget )
302 , myIsValidSelection( theIsValidSelection )
307 myWidget->onEnable( !myIsValidSelection );
313 //----------------------------------------------------------------------------
314 void VisuGUI_Sweep::onSelectionChanged()
316 VISU_Actor* anActor = NULL;
317 VISU::Prs3d_i* aPrs3d = NULL;
318 SVTK_ViewWindow* aViewWindow = NULL;
320 bool anIsValidSelection = VISU::GetPrs3dSelectionInfo( myModule, aPrs3d, aViewWindow, anActor );
322 // To instantiate special helper class which will analyze validity of selection
323 // and make appropritate actions
324 TEnabler anEnabler( this, anIsValidSelection );
326 anIsValidSelection &= bool( aViewWindow );
328 // To keep the pointer on the view window properly it is necessary to get known when
329 // it will be destroyed
330 if ( myViewWindow != aViewWindow ) {
332 disconnect( myViewWindow, SIGNAL( destroyed( QObject * ) ), this, SLOT( onSelectionChanged() ) );
334 myViewWindow = aViewWindow;
337 connect( myViewWindow, SIGNAL( destroyed( QObject * ) ), this, SLOT( onSelectionChanged() ) );
340 if(!VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule)) {
345 VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast< VISU::ColoredPrs3d_i* >( aPrs3d );
346 anIsValidSelection &= ( aColoredPrs3d && aColoredPrs3d->IsTimeStampFixed() );
348 myColoredPrs3d = aColoredPrs3d;
350 if ( myColoredPrs3d ) {
351 myColoredPrs3d->SetMapScale( 1.0 );
352 myColoredPrs3d->UpdateActors();
355 anIsValidSelection &= ( anActor && anActor->GetVisibility() );
361 //----------------------------------------------------------------------------
362 void VisuGUI_Sweep::onValueChanged( int value )
364 bool anIsValidSelection = ( myColoredPrs3d != NULL )
365 && (myActor != NULL );
367 if ( !anIsValidSelection )
370 QApplication::setOverrideCursor(Qt::WaitCursor);
372 int aSweepMode = mySweepMode->currentIndex();
373 int aNbSteps = myNumberOfSteps->value();
375 double anArgument = double( value ) / aNbSteps;
377 int anIntervalMode = myIntervals->currentIndex();
378 // To correct the input value according to the given interval mode
379 if ( aSweepMode != 0 ) {
380 switch ( anIntervalMode ) {
382 anArgument = vtkMath::Pi() * anArgument;
385 anArgument = -vtkMath::Pi() + 2.0 * vtkMath::Pi() * anArgument;
392 // To correct the input value according to the given sweep mode
393 double aValue = anArgument;
394 switch ( aSweepMode ) {
396 aValue = ( 1.0 - cos( anArgument ) ) / 2.0;
399 aValue = sin( anArgument - vtkMath::Pi() / 2.0 );
406 myColoredPrs3d->SetMapScale( aValue );
407 myColoredPrs3d->UpdateActor( myActor );
409 myViewWindow->Repaint();
410 } catch (std::exception& exc) {
411 INFOS( "Follow exception was occured :\n" << exc.what() );
413 INFOS( "Unknown exception was occured!" );
416 QApplication::restoreOverrideCursor();
420 //----------------------------------------------------------------------------
421 void VisuGUI_Sweep::onDelayChanged( double value )
423 myTimer->start( int( value * 1000 ) );
427 //----------------------------------------------------------------------------
428 void VisuGUI_Sweep::onNumberOfStepsChanged( int value )
430 int anOldNumberOfSteps = mySweepSlider->maximum();
431 mySweepSlider->setMaximum( value );
433 double aValue = double( value );
435 double aNewSweepValue = aValue / anOldNumberOfSteps * mySweepSlider->value();
436 mySweepSlider->setValue( int( aNewSweepValue + 1 ) );
438 double aNewPageStep = aValue / 10;
439 mySweepSlider->setPageStep( int( aNewPageStep + 1 ) );
443 //----------------------------------------------------------------------------
444 void VisuGUI_Sweep::onModeChanged( int )
446 myIntervals->setEnabled( mySweepMode->currentIndex() != 0 );
450 //----------------------------------------------------------------------------
451 void VisuGUI_Sweep::onFirst()
453 mySweepSlider->setValue( mySweepSlider->minimum() );
457 //----------------------------------------------------------------------------
458 void VisuGUI_Sweep::onPrevious()
460 mySweepSlider->setValue( mySweepSlider->value() - 1 );
463 void VisuGUI_Sweep::onNext()
465 mySweepSlider->setValue( mySweepSlider->value() + 1 );
468 void VisuGUI_Sweep::onLast()
470 mySweepSlider->setValue( mySweepSlider->maximum() );
473 //----------------------------------------------------------------------------
474 void VisuGUI_Sweep::onPlay( bool on )
477 myPlayButton->setIcon( myPausePixmap );
478 myTimer->start( int( myStepDelay->value() * 1000 ) );
479 myPlayButton->setChecked( true );
482 myPlayButton->setChecked( false );
483 myPlayButton->setIcon( myPlayPixmap );
488 //----------------------------------------------------------------------------
489 void VisuGUI_Sweep::onToggleView( bool on )
497 //----------------------------------------------------------------------------
498 void VisuGUI_Sweep::onStop()
501 mySweepSlider->setValue( mySweepSlider->maximum() );
504 myViewWindow->Repaint();
508 //----------------------------------------------------------------------------
509 void VisuGUI_Sweep::onEnable( bool on )
513 mySweepSlider->setEnabled( !on );
515 myFirstButton->setEnabled( !on );
516 myPreviousButton->setEnabled( !on );
518 myPlayButton->setEnabled( !on );
520 myNextButton->setEnabled( !on );
521 myLastButton->setEnabled( !on );
525 //----------------------------------------------------------------------------
526 void VisuGUI_Sweep::onTimeout()
528 int value = mySweepSlider->value();
529 if ( value < mySweepSlider->maximum() ) {
530 mySweepSlider->setValue( value + 1 );
532 if ( myIsCycled->isChecked() )
533 mySweepSlider->setValue( 0 );
535 myPlayButton->setChecked( false );
536 //myStopButton->setEnabled( false );
541 //----------------------------------------------------------------------------