--- /dev/null
+// VISU VISUGUI : GUI of VISU component
+//
+// 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 : VisuGUI_Slider.cxx
+// Author : Oleg UVAROV
+// Module : VISU
+
+#include "VisuGUI_Sweep.h"
+
+#include "SUIT_ResourceMgr.h"
+
+#include "LightApp_SelectionMgr.h"
+
+#include "VISU_Actor.h"
+
+#include "VisuGUI.h"
+#include "VisuGUI_Tools.h"
+#include "VISU_ScalarMap_i.hh"
+#include "VISU_Actor.h"
+
+#include "QtxDockWidget.h"
+#include "QtxIntSpinBox.h"
+#include "QtxDoubleSpinBox.h"
+
+#include <QMainWindow>
+#include <QComboBox>
+#include <QFont>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QToolButton>
+#include <QToolTip>
+#include <QSlider>
+#include <QGroupBox>
+#include <QCheckBox>
+#include <QRadioButton>
+#include <QTimer>
+
+#include <vtkMath.h>
+
+/*!
+ Constructor
+*/
+VisuGUI_Sweep::VisuGUI_Sweep( VisuGUI* theModule,
+ QMainWindow* theParent,
+ LightApp_SelectionMgr* theSelectionMgr )
+ : QWidget( theParent )
+ , myModule( theModule )
+ , myViewWindow( NULL )
+ , myScalarMap( NULL )
+ , myActor( NULL )
+{
+ setWindowTitle( tr("TITLE") );
+
+ SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+
+ //----------------------------------------------------------------------------
+ QVBoxLayout* aVBoxLayout = new QVBoxLayout( this );
+
+ QTabWidget* aTabWidget = new QTabWidget( this );
+ aVBoxLayout->addWidget( aTabWidget );
+
+ {
+ QWidget* aNavigationTab = new QWidget();
+ {
+ QVBoxLayout* aVBoxLayout = new QVBoxLayout( aNavigationTab );
+ {
+ QHBoxLayout* aHBoxLayout = new QHBoxLayout();
+
+ QLabel* aStartSweepPosition = new QLabel( aNavigationTab );
+ aStartSweepPosition->setText( tr( "START_SWEEP_POSITION" ) );
+ aHBoxLayout->addWidget( aStartSweepPosition );
+
+ mySweepSlider = new QSlider( aNavigationTab );
+ mySweepSlider->setOrientation( Qt::Horizontal );
+ mySweepSlider->setMinimum( 0 );
+ aHBoxLayout->addWidget( mySweepSlider );
+
+ QLabel* anEndSweepPosition = new QLabel( aNavigationTab );
+ anEndSweepPosition->setText( tr( "END_SWEEP_POSITION" ) );
+ aHBoxLayout->addWidget( anEndSweepPosition );
+
+ aVBoxLayout->addLayout( aHBoxLayout );
+ }
+ {
+ QHBoxLayout* aHBoxLayout = new QHBoxLayout();
+
+ myFirstButton = new QToolButton( aNavigationTab );
+ myFirstButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_FIRST" ) ) );
+ myFirstButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ connect( myFirstButton, SIGNAL( clicked() ), SLOT( onFirst() ) );
+ aHBoxLayout->addWidget( myFirstButton );
+
+ myPreviousButton = new QToolButton( aNavigationTab );
+ myPreviousButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PREVIOUS" ) ) );
+ myPreviousButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ connect( myPreviousButton, SIGNAL( clicked() ), SLOT( onPrevious() ) );
+ aHBoxLayout->addWidget( myPreviousButton );
+
+ myPlayButton = new QToolButton( aNavigationTab );
+ myPlayButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) ) );
+ myPlayButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ myPlayButton->setCheckable( true );
+ aHBoxLayout->addWidget( myPlayButton );
+
+ myNextButton = new QToolButton( aNavigationTab );
+ myNextButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_NEXT" ) ) );
+ myNextButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ connect( myNextButton, SIGNAL( clicked() ), SLOT( onNext() ) );
+ aHBoxLayout->addWidget( myNextButton );
+
+ myLastButton = new QToolButton( aNavigationTab );
+ myLastButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_LAST" ) ) );
+ myLastButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ connect( myLastButton, SIGNAL( clicked() ), SLOT( onLast() ) );
+ aHBoxLayout->addWidget( myLastButton );
+
+ aVBoxLayout->addLayout( aHBoxLayout );
+ }
+ {
+ QHBoxLayout* aHBoxLayout = new QHBoxLayout();
+
+ QToolButton* aStopButton = new QToolButton( aNavigationTab );
+ aStopButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SWEEP_STOP" ) ) );
+ aStopButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ aStopButton->setCheckable( true );
+ connect( aStopButton, SIGNAL( toggled( bool ) ), SLOT( onStop( bool ) ) );
+ aHBoxLayout->addWidget( aStopButton );
+
+ myIsCycled = new QCheckBox( aNavigationTab );
+ myIsCycled->setText( tr( "IS_CYCLED" ) );
+ myIsCycled->setChecked( true );
+ aHBoxLayout->addWidget( myIsCycled );
+
+ aVBoxLayout->addLayout( aHBoxLayout );
+ }
+ {
+ QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ aVBoxLayout->addItem( aSpacerItem );
+ }
+
+ aTabWidget->addTab( aNavigationTab, tr( "NAVIGATION_TAB" ) );
+ }
+ }
+ {
+ QWidget* aPropertiesTab = new QWidget();
+
+ QVBoxLayout* aVBoxLayout = new QVBoxLayout( aPropertiesTab );
+ {
+ QGridLayout* aGridLayout = new QGridLayout( aPropertiesTab );
+
+ QLabel* aModeAnnotation = new QLabel( aPropertiesTab );
+ aModeAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
+ aModeAnnotation->setText( tr( "MODE" ) );
+ aGridLayout->addWidget( aModeAnnotation, 0, 0 );
+
+ mySweepMode = new QComboBox( aPropertiesTab );
+ mySweepMode->insertItems( 0, QStringList()
+ << tr( "LINEAR" )
+ << tr( "COSINUSOIDAL" )
+ << tr( "SINUSOIDAL" ) );
+ mySweepMode->setCurrentIndex( aResourceMgr->integerValue( "VISU", "sweeping_modes", 0 ) );
+ aGridLayout->addWidget( mySweepMode, 0, 1 );
+
+ myIntervals = new QComboBox( aPropertiesTab );
+ myIntervals->insertItems( 0, QStringList()
+ << tr( "[ 0, +PI ]" )
+ << tr( "[ -PI, +PI ]" ) );
+ myIntervals->setCurrentIndex( aResourceMgr->integerValue( "VISU", "sweeping_is2PI", 0 ) );
+ aGridLayout->addWidget( myIntervals, 0, 2 );
+
+ QLabel* aNumberOfStepsAnnotation = new QLabel( aPropertiesTab );
+ aNumberOfStepsAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
+ aNumberOfStepsAnnotation->setText( tr( "NUMBER_OF_STEPS" ) );
+ aGridLayout->addWidget( aNumberOfStepsAnnotation, 1, 0 );
+
+ myNumberOfSteps = new QtxIntSpinBox( aPropertiesTab );
+ connect( myNumberOfSteps, SIGNAL( valueChanged( int ) ), SLOT( onNumberOfStepsChanged( int ) ) );
+ myNumberOfSteps->setValue( aResourceMgr->integerValue( "VISU", "sweeping_number_steps", 40 ) );
+ aGridLayout->addWidget( myNumberOfSteps, 1, 1, 1, 2 );
+
+ QLabel* aStepDelayAnnotation = new QLabel( aPropertiesTab );
+ aStepDelayAnnotation->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
+ aStepDelayAnnotation->setText( tr( "DELAY_BETWEEN_STEPS" ) );
+ aGridLayout->addWidget( aStepDelayAnnotation, 2, 0 );
+
+ myStepDelay = new QtxDoubleSpinBox( aPropertiesTab );
+ myStepDelay->setValue( aResourceMgr->doubleValue("VISU", "sweeping_time_step", 0.1) );
+ aGridLayout->addWidget( myStepDelay, 2, 1, 1, 2 );
+
+ QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ aGridLayout->addItem( aSpacerItem, 3, 0 );
+
+ aVBoxLayout->addLayout( aGridLayout );
+ }
+
+ aTabWidget->addTab( aPropertiesTab, tr( "PROPERTIES_TAB" ) );
+ }
+
+ {
+ QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ aVBoxLayout->addItem( aSpacerItem );
+ }
+
+
+ //----------------------------------------------------------------------------
+ QtxDockWidget* aQtxDockWidget = new QtxDockWidget( true, theParent );
+ theParent->addDockWidget( Qt::BottomDockWidgetArea , aQtxDockWidget );
+ aQtxDockWidget->setWidget( this );
+ aQtxDockWidget->show();
+
+
+ //----------------------------------------------------------------------------
+ myTimer = new QTimer( this );
+
+ connect( myTimer, SIGNAL( timeout() ), SLOT( onTimeout() ) );
+
+ connect( myPlayButton, SIGNAL( toggled( bool ) ), SLOT( onPlay( bool ) ) );
+
+ connect( mySweepSlider, SIGNAL( valueChanged( int ) ), SLOT( onValueChanged( int ) ) );
+
+ connect( myStepDelay, SIGNAL( valueChanged( double ) ), SLOT( onDelayChanged( double ) ) );
+
+ connect( mySweepMode, SIGNAL( currentIndexChanged( int ) ), SLOT( onModeChanged( int ) ) );
+
+ connect( theModule, SIGNAL( moduleDeactivated() ), SLOT( onModuleDeactivated() ) );
+
+ connect( theModule, SIGNAL( moduleActivated() ), SLOT( onModuleActivated() ) );
+
+ connect( theSelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionChanged() ) );
+
+ onSelectionChanged();
+
+ onModeChanged( mySweepMode->currentIndex() );
+
+ onPlay( true );
+}
+
+
+//----------------------------------------------------------------------------
+VisuGUI_Sweep::~VisuGUI_Sweep()
+{}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onModuleDeactivated()
+{
+ setHidden( true );
+
+ onStop( true );
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onModuleActivated()
+{
+ setHidden( false );
+}
+
+
+//----------------------------------------------------------------------------
+namespace
+{
+ struct TEnabler
+ {
+ VisuGUI_Sweep* myWidget;
+ VISU_Actor*& myActor;
+
+ TEnabler( VisuGUI_Sweep* theWidget, VISU_Actor*& theActor )
+ : myWidget( theWidget )
+ , myActor( theActor )
+ {}
+
+ ~TEnabler()
+ {
+ myWidget->setEnabled( myActor );
+ myWidget->onStop( !myActor );
+ }
+ };
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onSelectionChanged()
+{
+ VISU_Actor* anActor = NULL;
+ VISU::Prs3d_i* aPrs3d = NULL;
+ SVTK_ViewWindow* aViewWindow = NULL;
+
+ TEnabler anEnabler( this, anActor );
+
+ if( !VISU::GetPrs3dSelectionInfo( myModule, aPrs3d, aViewWindow, anActor ) )
+ return;
+
+ if ( anActor == myActor )
+ return;
+
+ VISU::ScalarMap_i* aScalarMap = dynamic_cast< VISU::ScalarMap_i* >( aPrs3d );
+ if ( !aScalarMap )
+ return;
+
+ if ( myActor ) {
+ myScalarMap->SetMapScale( 1.0 );
+ myScalarMap->UpdateActor( myActor );
+ myViewWindow->Repaint();
+ }
+
+ if ( anActor && !anActor->GetVisibility() )
+ anActor->VisibilityOn();
+
+ myViewWindow = aViewWindow;
+ myScalarMap = aScalarMap;
+ myActor = anActor;
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onValueChanged( int value )
+{
+ if ( !myActor )
+ return;
+
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+
+ int aSweepMode = mySweepMode->currentIndex();
+ int aNbSteps = myNumberOfSteps->value();
+
+ double anArgument = double( value ) / aNbSteps;
+
+ int anIntervalMode = myIntervals->currentIndex();
+ // To correct the input value according to the given interval mode
+ if ( aSweepMode != 0 ) {
+ switch ( anIntervalMode ) {
+ case 0 :
+ anArgument = vtkMath::Pi() * anArgument;
+ break;
+ case 1 :
+ anArgument = -vtkMath::Pi() + 2.0 * vtkMath::Pi() * anArgument;
+ break;
+ default :
+ break;
+ }
+ }
+
+ // To correct the input value according to the given sweep mode
+ double aValue = anArgument;
+ switch ( aSweepMode ) {
+ case 1 :
+ aValue = ( 1.0 - cos( anArgument ) ) / 2.0;
+ break;
+ case 2 :
+ aValue = sin( anArgument - vtkMath::Pi() / 2.0 );
+ break;
+ default :
+ break;
+ }
+
+// cout << "VisuGUI_Sweep::onValueChanged - ( " << value
+// << "; " << anArgument
+// << "; " << aValue
+// << ")" << endl;
+
+ try {
+ myScalarMap->SetMapScale( aValue );
+ myScalarMap->UpdateActor( myActor );
+ myViewWindow->Repaint();
+ } catch (std::exception& exc) {
+ INFOS( "Follow exception was occured :\n" << exc.what() );
+ } catch (...) {
+ INFOS( "Unknown exception was occured!" );
+ }
+
+ QApplication::restoreOverrideCursor();
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onDelayChanged( double value )
+{
+ myTimer->start( int( value * 1000 ) );
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onNumberOfStepsChanged( int value )
+{
+ int anOldNumberOfSteps = mySweepSlider->maximum();
+ mySweepSlider->setMaximum( value );
+
+ double aNewSweepValue = value / anOldNumberOfSteps * mySweepSlider->value();
+ mySweepSlider->setValue( int( aNewSweepValue ) );
+
+ double aNewPageStep = value / anOldNumberOfSteps * mySweepSlider->pageStep();
+ mySweepSlider->setPageStep( int( aNewPageStep ) );
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onModeChanged( int )
+{
+ myIntervals->setEnabled( mySweepMode->currentIndex() != 0 );
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onFirst()
+{
+ mySweepSlider->setValue( mySweepSlider->minimum() );
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onPrevious()
+{
+ mySweepSlider->setValue( mySweepSlider->value() - 1 );
+}
+
+void VisuGUI_Sweep::onNext()
+{
+ mySweepSlider->setValue( mySweepSlider->value() + 1 );
+}
+
+void VisuGUI_Sweep::onLast()
+{
+ mySweepSlider->setValue( mySweepSlider->maximum() );
+}
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onPlay( bool on )
+{
+ SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+ if ( on ) {
+ myPlayButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PAUSE" ) ) );
+ myTimer->start( int( myStepDelay->value() * 1000 ) );
+ myPlayButton->setChecked( true );
+ } else {
+ myTimer->stop();
+ myPlayButton->setChecked( false );
+ myPlayButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) ) );
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onStop( bool on )
+{
+ onPlay( false );
+
+ mySweepSlider->setValue( mySweepSlider->maximum() );
+
+ mySweepSlider->setEnabled( !on );
+
+ myFirstButton->setEnabled( !on );
+ myPreviousButton->setEnabled( !on );
+
+ myPlayButton->setEnabled( !on );
+
+ myNextButton->setEnabled( !on );
+ myLastButton->setEnabled( !on );
+}
+
+
+//----------------------------------------------------------------------------
+void VisuGUI_Sweep::onTimeout()
+{
+ int value = mySweepSlider->value();
+ if ( value < mySweepSlider->maximum() ) {
+ mySweepSlider->setValue( value + 1 );
+ } else {
+ if ( myIsCycled->isChecked() )
+ mySweepSlider->setValue( 0 );
+ else
+ myPlayButton->setChecked( false );
+ //myStopButton->setEnabled( false );
+ }
+}
+
+
+//----------------------------------------------------------------------------