1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU VISUGUI : GUI of VISU component
21 // File : VisuGUI_Slider.cxx
22 // Author : Oleg UVAROV
25 #include "VisuGUI_Sweep.h"
26 #include "VisuGUI_Tools.h"
28 #include "SUIT_ResourceMgr.h"
30 #include "LightApp_SelectionMgr.h"
32 #include <SalomeApp_IntSpinBox.h>
33 #include <SalomeApp_DoubleSpinBox.h>
35 #include "VISU_Actor.h"
38 #include "VisuGUI_Tools.h"
39 #include "VisuGUI_ViewTools.h"
40 #include "VISU_ColoredPrs3d_i.hh"
41 #include "VISU_Actor.h"
43 #include "QtxDockWidget.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 SalomeApp_IntSpinBox( aPropertiesTab );
198 myNumberOfSteps->setAcceptNames( false );
199 connect( myNumberOfSteps, SIGNAL( valueChanged( int ) ), SLOT( onNumberOfStepsChanged( int ) ) );
200 myNumberOfSteps->setValue( aResourceMgr->integerValue( "VISU", "sweeping_number_steps", 40 ) );
201 aGridLayout->addWidget( myNumberOfSteps, 1, 1, 1, 1 );
203 QLabel* aStepDelayAnnotation = new QLabel( aPropertiesTab );
204 aStepDelayAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
205 aStepDelayAnnotation->setText( tr( "DELAY_BETWEEN_STEPS" ) );
206 aGridLayout->addWidget( aStepDelayAnnotation, 2, 0, 1, 1 );
208 myStepDelay = new SalomeApp_DoubleSpinBox( aPropertiesTab );
209 VISU::initSpinBox( myStepDelay, 0., 99.99, .1, "parametric_precision" );
210 myStepDelay->setValue( aResourceMgr->doubleValue("VISU", "sweeping_time_step", 0.1) );
211 aGridLayout->addWidget( myStepDelay, 2, 1, 1, 1 );
214 aTabWidget->addTab( aPropertiesTab, tr( "PROPERTIES_TAB" ) );
218 QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
219 aVBoxLayout->addItem( aSpacerItem );
223 //----------------------------------------------------------------------------
224 QtxDockWidget* aQtxDockWidget = new QtxDockWidget( true, theParent );
225 theParent->addDockWidget( Qt::BottomDockWidgetArea , aQtxDockWidget );
226 aQtxDockWidget->setObjectName( objectName() );
227 aQtxDockWidget->setWidget( this );
229 myToggleViewAction = aQtxDockWidget->toggleViewAction();
230 myToggleViewAction->setIcon( QIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SWEEP_PANEL" ) ) ) );
231 myToggleViewAction->setToolTip( tr( "MEN_SWEEP_PANE" ) );
232 myToggleViewAction->setText( tr( "MEN_SWEEP_PANE" ) );
233 myToggleViewAction->setCheckable( true );
234 aQtxDockWidget->setVisible( false );
236 connect( myToggleViewAction, SIGNAL( toggled( bool ) ), this, SLOT( onToggleView( bool ) ) );
238 //----------------------------------------------------------------------------
239 myTimer = new QTimer( this );
241 myPlayPixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) );
242 myPausePixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PAUSE" ) );
244 connect( myTimer, SIGNAL( timeout() ), SLOT( onTimeout() ) );
246 connect( myPlayButton, SIGNAL( toggled( bool ) ), SLOT( onPlay( bool ) ) );
248 connect( mySweepSlider, SIGNAL( valueChanged( int ) ), SLOT( onValueChanged( int ) ) );
250 connect( myStepDelay, SIGNAL( valueChanged( double ) ), SLOT( onDelayChanged( double ) ) );
252 connect( mySweepMode, SIGNAL( currentIndexChanged( int ) ), SLOT( onModeChanged( int ) ) );
254 connect( theModule, SIGNAL( moduleDeactivated() ), SLOT( onModuleDeactivated() ) );
256 connect( theModule, SIGNAL( moduleActivated() ), SLOT( onModuleActivated() ) );
258 connect( theSelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionChanged() ) );
260 onSelectionChanged();
262 onModeChanged( mySweepMode->currentIndex() );
266 //----------------------------------------------------------------------------
267 VisuGUI_Sweep::~VisuGUI_Sweep()
271 //----------------------------------------------------------------------------
272 QAction* VisuGUI_Sweep::toggleViewAction()
274 return myToggleViewAction;
278 //----------------------------------------------------------------------------
279 void VisuGUI_Sweep::onModuleDeactivated()
287 //----------------------------------------------------------------------------
288 void VisuGUI_Sweep::onModuleActivated()
294 //----------------------------------------------------------------------------
299 VisuGUI_Sweep* myWidget;
300 bool& myIsValidSelection;
302 TEnabler( VisuGUI_Sweep* theWidget, bool& theIsValidSelection )
303 : myWidget( theWidget )
304 , myIsValidSelection( theIsValidSelection )
309 myWidget->onEnable( !myIsValidSelection );
315 //----------------------------------------------------------------------------
316 void VisuGUI_Sweep::onSelectionChanged()
318 VISU_Actor* anActor = NULL;
319 VISU::Prs3d_i* aPrs3d = NULL;
320 SVTK_ViewWindow* aViewWindow = NULL;
322 bool anIsValidSelection = VISU::GetPrs3dSelectionInfo( myModule, aPrs3d, aViewWindow, anActor );
324 // To instantiate special helper class which will analyze validity of selection
325 // and make appropritate actions
326 TEnabler anEnabler( this, anIsValidSelection );
328 anIsValidSelection &= bool( aViewWindow );
330 // To keep the pointer on the view window properly it is necessary to get known when
331 // it will be destroyed
332 if ( myViewWindow != aViewWindow ) {
334 disconnect( myViewWindow, SIGNAL( destroyed( QObject * ) ), this, SLOT( onSelectionChanged() ) );
336 myViewWindow = aViewWindow;
339 connect( myViewWindow, SIGNAL( destroyed( QObject * ) ), this, SLOT( onSelectionChanged() ) );
342 if(!VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule)) {
347 VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast< VISU::ColoredPrs3d_i* >( aPrs3d );
348 anIsValidSelection &= ( aColoredPrs3d && aColoredPrs3d->IsTimeStampFixed() );
350 myColoredPrs3d = aColoredPrs3d;
352 if ( myColoredPrs3d ) {
353 myColoredPrs3d->SetMapScale( 1.0 );
354 myColoredPrs3d->UpdateActors();
357 anIsValidSelection &= ( anActor && anActor->GetVisibility() );
363 //----------------------------------------------------------------------------
364 void VisuGUI_Sweep::onValueChanged( int value )
366 bool anIsValidSelection = ( myColoredPrs3d != NULL )
367 && (myActor != NULL );
369 if ( !anIsValidSelection )
372 QApplication::setOverrideCursor(Qt::WaitCursor);
374 int aSweepMode = mySweepMode->currentIndex();
375 int aNbSteps = myNumberOfSteps->value();
377 double anArgument = double( value ) / aNbSteps;
379 int anIntervalMode = myIntervals->currentIndex();
380 // To correct the input value according to the given interval mode
381 if ( aSweepMode != 0 ) {
382 switch ( anIntervalMode ) {
384 anArgument = vtkMath::Pi() * anArgument;
387 anArgument = -vtkMath::Pi() + 2.0 * vtkMath::Pi() * anArgument;
394 // To correct the input value according to the given sweep mode
395 double aValue = anArgument;
396 switch ( aSweepMode ) {
398 aValue = ( 1.0 - cos( anArgument ) ) / 2.0;
401 aValue = sin( anArgument - vtkMath::Pi() / 2.0 );
408 myColoredPrs3d->SetMapScale( aValue );
409 myColoredPrs3d->UpdateActor( myActor );
411 myViewWindow->Repaint();
412 } catch (std::exception& exc) {
413 INFOS( "Follow exception was occured :\n" << exc.what() );
415 INFOS( "Unknown exception was occured!" );
418 QApplication::restoreOverrideCursor();
422 //----------------------------------------------------------------------------
423 void VisuGUI_Sweep::onDelayChanged( double value )
425 myTimer->start( int( value * 1000 ) );
429 //----------------------------------------------------------------------------
430 void VisuGUI_Sweep::onNumberOfStepsChanged( int value )
432 int anOldNumberOfSteps = mySweepSlider->maximum();
433 mySweepSlider->setMaximum( value );
435 double aValue = double( value );
437 double aNewSweepValue = aValue / anOldNumberOfSteps * mySweepSlider->value();
438 mySweepSlider->setValue( int( aNewSweepValue + 1 ) );
440 double aNewPageStep = aValue / 10;
441 mySweepSlider->setPageStep( int( aNewPageStep + 1 ) );
445 //----------------------------------------------------------------------------
446 void VisuGUI_Sweep::onModeChanged( int )
448 myIntervals->setEnabled( mySweepMode->currentIndex() != 0 );
452 //----------------------------------------------------------------------------
453 void VisuGUI_Sweep::onFirst()
455 mySweepSlider->setValue( mySweepSlider->minimum() );
459 //----------------------------------------------------------------------------
460 void VisuGUI_Sweep::onPrevious()
462 mySweepSlider->setValue( mySweepSlider->value() - 1 );
465 void VisuGUI_Sweep::onNext()
467 mySweepSlider->setValue( mySweepSlider->value() + 1 );
470 void VisuGUI_Sweep::onLast()
472 mySweepSlider->setValue( mySweepSlider->maximum() );
475 //----------------------------------------------------------------------------
476 void VisuGUI_Sweep::onPlay( bool on )
479 myPlayButton->setIcon( myPausePixmap );
480 myTimer->start( int( myStepDelay->value() * 1000 ) );
481 myPlayButton->setChecked( true );
484 myPlayButton->setChecked( false );
485 myPlayButton->setIcon( myPlayPixmap );
490 //----------------------------------------------------------------------------
491 void VisuGUI_Sweep::onToggleView( bool on )
499 //----------------------------------------------------------------------------
500 void VisuGUI_Sweep::onStop()
503 mySweepSlider->setValue( mySweepSlider->maximum() );
506 myViewWindow->Repaint();
510 //----------------------------------------------------------------------------
511 void VisuGUI_Sweep::onEnable( bool on )
515 mySweepSlider->setEnabled( !on );
517 myFirstButton->setEnabled( !on );
518 myPreviousButton->setEnabled( !on );
520 myPlayButton->setEnabled( !on );
522 myNextButton->setEnabled( !on );
523 myLastButton->setEnabled( !on );
527 //----------------------------------------------------------------------------
528 void VisuGUI_Sweep::onTimeout()
530 int value = mySweepSlider->value();
531 if ( value < mySweepSlider->maximum() ) {
532 mySweepSlider->setValue( value + 1 );
534 if ( myIsCycled->isChecked() )
535 mySweepSlider->setValue( 0 );
537 myPlayButton->setChecked( false );
538 //myStopButton->setEnabled( false );
543 //----------------------------------------------------------------------------