Salome HOME
e32654e7bda04754a5aa570feddc55b93b702130
[modules/visu.git] / src / VISUGUI / VisuGUI_Slider.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_Slider.cxx
24 //  Author : Oleg UVAROV
25 //  Module : VISU
26 //
27 #include "VisuGUI_Slider.h"
28
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
31
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_Study.h"
34
35 #include "LightApp_SelectionMgr.h"
36
37 #include "SALOME_ListIteratorOfListIO.hxx"
38
39 #include "VISU_PipeLine.hxx"
40
41 #include "VISU_Actor.h"
42
43 #include "VISU_Gen_i.hh"
44 #include "VisuGUI.h"
45 #include "VisuGUI_Tools.h"
46 #include "VisuGUI_Prs3dTools.h"
47
48 #include "VTKViewer_Algorithm.h"
49 #include "SVTK_Functor.h"
50
51 #include "QtxDockWidget.h"
52 #include "QtxDoubleSpinBox.h"
53
54 #include <vtkActorCollection.h>
55 #include <vtkRenderer.h>
56
57 #include <QMainWindow>
58 #include <QComboBox>
59 #include <QFont>
60 #include <QLabel>
61 #include <QLayout>
62 #include <QLineEdit>
63 #include <QToolButton>
64 #include <QToolTip>
65 #include <QSlider>
66 #include <QSpinBox>
67 #include <QGroupBox>
68 #include <QCheckBox>
69 #include <QRadioButton>
70 #include <QTimer>
71 #include <QAction>
72
73 using namespace std;
74
75 /*!
76   Constructor
77 */
78 VisuGUI_Slider::VisuGUI_Slider( VisuGUI* theModule, 
79                                 QMainWindow* theParent,
80                                 LightApp_SelectionMgr* theSelectionMgr )
81   : QWidget( theParent )
82   , myViewManager( VISU::GetVisuGen( theModule )->GetViewManager() )
83   , mySelectionMgr( theSelectionMgr )
84   , myModule( theModule )
85 {
86   setWindowTitle( tr("TITLE") );
87   setObjectName( tr("TITLE") );
88
89   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
90
91   //----------------------------------------------------------------------------
92   QVBoxLayout* aVBoxLayout = new QVBoxLayout( this );
93
94   QTabWidget* aTabWidget = new QTabWidget( this );
95   aTabWidget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
96
97   aVBoxLayout->addWidget( aTabWidget );
98
99   {
100     QWidget* aParent = new QWidget();
101     {
102       QGridLayout* aGridLayout = new QGridLayout( aParent );
103       {
104         myFirstTimeStamp = new QLabel( aParent );
105         myFirstTimeStamp->setAlignment( Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter );
106         myFirstTimeStamp->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
107         aGridLayout->addWidget( myFirstTimeStamp, 0, 0, 1, 1 );
108         
109         mySlider = new QSlider( aParent );
110         mySlider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
111         mySlider->setFocusPolicy( Qt::StrongFocus );
112         mySlider->setOrientation( Qt::Horizontal );
113         mySlider->setTracking( false );
114         mySlider->setMinimum( 0 );
115         aGridLayout->addWidget( mySlider, 0, 1, 1, 3 );
116         
117         myLastTimeStamp = new QLabel( aParent );
118         aGridLayout->addWidget( myLastTimeStamp, 0, 4, 1, 1 );
119       }     
120       {
121         myFirstButton = new QToolButton( aParent );
122         myFirstButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_FIRST" ) ) );
123         myFirstButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
124         aGridLayout->addWidget( myFirstButton, 1, 0, 1, 1 );
125
126         myPreviousButton = new QToolButton( aParent );
127         myPreviousButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PREVIOUS" ) ) );
128         myPreviousButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
129         aGridLayout->addWidget( myPreviousButton, 1, 1, 1, 1 );
130
131         myPlayButton = new QToolButton( aParent );
132         myPlayButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) ) );
133         myPlayButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
134         myPlayButton->setCheckable( true );
135         aGridLayout->addWidget( myPlayButton, 1, 2, 1, 1 );
136
137         myNextButton = new QToolButton( aParent );
138         myNextButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_NEXT" ) ) );
139         myNextButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
140         aGridLayout->addWidget( myNextButton, 1, 3, 1, 1 );
141
142         myLastButton = new QToolButton( aParent );
143         myLastButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_LAST" ) ) );
144         myLastButton->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
145         aGridLayout->addWidget( myLastButton, 1, 4, 1, 1 );
146       }
147       {
148         myTimeStampIndexes = new QComboBox( aParent );
149         myTimeStampIndexes->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
150         myTimeStampIndexes->setFocusPolicy( Qt::StrongFocus );
151         aGridLayout->addWidget( myTimeStampIndexes, 2, 0, 1, 2 );
152
153         myIsCycled = new QToolButton( aParent );
154         myIsCycled->setText( tr( "IS_CYCLED" ) );
155         myIsCycled->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
156         myIsCycled->setLayoutDirection( Qt::LeftToRight );
157         myIsCycled->setCheckable( true );
158         //myIsCycled->setEnabled( false );
159         aGridLayout->addWidget( myIsCycled, 2, 2, 1, 1 );
160
161         myTimeStampStrings = new QComboBox( aParent );
162         myTimeStampStrings->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
163         myTimeStampStrings->setFocusPolicy( Qt::StrongFocus );
164         aGridLayout->addWidget( myTimeStampStrings, 2, 3, 1, 2 );
165       }
166     }
167
168     aTabWidget->addTab( aParent, tr( "NAVIGATION_TAB" ) );
169     myPlayTab = aParent;
170   }
171
172   {
173     QWidget* aParent = new QWidget();
174     {
175       QVBoxLayout* aVBoxLayout = new QVBoxLayout( aParent );
176       {
177         QHBoxLayout* aHBoxLayout = new QHBoxLayout();
178         
179         myMinimalMemoryButton = new QRadioButton( tr( "MINIMAL_MEMORY" ), aParent );
180         aHBoxLayout->addWidget( myMinimalMemoryButton );        
181
182         QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );     
183         aHBoxLayout->addItem( aSpacerItem );
184
185         myLimitedMemoryButton = new QRadioButton( tr( "LIMITED_MEMORY" ), aParent );
186         myLimitedMemoryButton->setChecked( true );
187         aHBoxLayout->addWidget( myLimitedMemoryButton );
188         
189         myLimitedMemory = new QtxDoubleSpinBox( aParent );
190         myLimitedMemory->setMaximum( 10000 );
191         myLimitedMemory->setValue( 512 );
192         aHBoxLayout->addWidget( myLimitedMemory );
193         
194         QLabel* aMemoryDimensionLabel = new QLabel( aParent );
195         aMemoryDimensionLabel->setText( tr( "MEMORY_UNITS" ) );
196         aHBoxLayout->addWidget( aMemoryDimensionLabel );
197         
198         aVBoxLayout->addLayout( aHBoxLayout );
199       }
200       {
201         QHBoxLayout* aHBoxLayout = new QHBoxLayout();
202             
203         QLabel* aUsedMemoryLabel = new QLabel( tr( "USED_BY_CACHE" ), aParent );
204         aUsedMemoryLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
205         aHBoxLayout->addWidget( aUsedMemoryLabel );
206         
207         myUsedMemory = new QLineEdit( aParent );
208         myUsedMemory->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
209         //myUsedMemory->setEnabled( false );
210         aHBoxLayout->addWidget( myUsedMemory );
211             
212         QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );     
213         aHBoxLayout->addItem( aSpacerItem );
214
215         QLabel* aFreeMemoryLabel = new QLabel( tr( "AVAILABLE_MEMORY" ), aParent );
216         aHBoxLayout->addWidget( aFreeMemoryLabel );
217     
218         myFreeMemory = new QLineEdit( aParent );
219         myFreeMemory->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
220         //myFreeMemory->setEnabled( false );
221         aHBoxLayout->addWidget( myFreeMemory );
222
223         aVBoxLayout->addLayout( aHBoxLayout );
224       }
225       {
226         QHBoxLayout* aHBoxLayout = new QHBoxLayout();
227         
228         QLabel* aLabel = new QLabel( tr( "SPEED" ), aParent );
229         aLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
230         aHBoxLayout->addWidget( aLabel );   
231       
232         mySpeedSlider = new QSlider( aParent );
233         mySpeedSlider->setMinimum( 1 );
234         mySpeedSlider->setMaximum( 100 );
235         mySpeedSlider->setValue( mySpeedSlider->maximum() / 2 );
236         mySpeedSlider->setPageStep( mySpeedSlider->maximum() / 5 );
237         mySpeedSlider->setTickInterval( mySpeedSlider->pageStep() );    
238         mySpeedSlider->setOrientation( Qt::Horizontal );
239         mySpeedSlider->setTickPosition( QSlider::TicksBelow );
240         aHBoxLayout->addWidget( mySpeedSlider );   
241         
242         aVBoxLayout->addLayout( aHBoxLayout );
243       }
244       
245       aTabWidget->addTab( aParent, tr( "PROPERTIES_TAB" ) );
246     }
247   }
248
249   {
250     QSpacerItem* aSpacerItem = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
251     aVBoxLayout->addItem( aSpacerItem );
252   }
253
254
255   //----------------------------------------------------------------------------
256   myPlayPixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) );
257   myPausePixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PAUSE" ) );
258
259   myTimer = new QTimer( this );
260
261   // Common
262   connect( theModule, SIGNAL( moduleDeactivated() ), SLOT( onModuleDeactivated() ) );
263
264   connect( theModule, SIGNAL( moduleActivated() ), SLOT( onModuleActivated() ) );
265
266   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionChanged() ) );
267
268   connect( myTimeStampStrings, SIGNAL( activated( int ) ),    SLOT( onTimeStampActivated( int ) ) );
269   connect( myTimeStampIndexes, SIGNAL( activated( int ) ),    SLOT( onTimeStampActivated( int ) ) );
270
271   connect( myFirstButton,      SIGNAL( clicked() ),           SLOT( onFirst() ) );
272   connect( myPreviousButton,   SIGNAL( clicked() ),           SLOT( onPrevious() ) );
273   connect( myPlayButton,       SIGNAL( toggled( bool ) ),     SLOT( onPlay( bool ) ) );
274   connect( myNextButton,       SIGNAL( clicked() ),           SLOT( onNext() ) );
275   connect( myLastButton,       SIGNAL( clicked() ),           SLOT( onLast() ) );
276
277   connect( mySlider,           SIGNAL( valueChanged( int ) ), SLOT( onValueChanged( int ) ) );
278
279   connect( mySpeedSlider,      SIGNAL( valueChanged( int ) ), SLOT( onSpeedChanged( int ) ) );
280
281   connect( myTimer,            SIGNAL( timeout() ),           SLOT( onTimeout() ) );
282
283   //----------------------------------------------------------------------------
284   connect( myLimitedMemoryButton, SIGNAL( toggled( bool ) ), this, SLOT( onMemoryModeChanged( bool ) ) );
285   connect( myLimitedMemory, SIGNAL( valueChanged( double ) ), this, SLOT( onMemorySizeChanged( double ) ) );
286
287   //----------------------------------------------------------------------------
288   enableControls( false );
289
290   QtxDockWidget* aQtxDockWidget = new QtxDockWidget( true, theParent );
291   theParent->addDockWidget( Qt::BottomDockWidgetArea , aQtxDockWidget );
292   aQtxDockWidget->setObjectName( objectName() );
293   aQtxDockWidget->setWidget( this );
294   
295   myToggleViewAction = aQtxDockWidget->toggleViewAction();
296   myToggleViewAction->setIcon( QIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PANEL" ) ) ) );
297   myToggleViewAction->setToolTip( tr( "MEN_SLIDER_PANE" ) );
298   myToggleViewAction->setText( tr( "MEN_SLIDER_PANE" ) );
299   myToggleViewAction->setCheckable( true );
300   aQtxDockWidget->setVisible( false );
301
302   connect( myToggleViewAction, SIGNAL( toggled( bool ) ), this, SLOT( onToggleView( bool ) ) );
303 }
304
305
306 //----------------------------------------------------------------------------
307 VisuGUI_Slider::~VisuGUI_Slider()
308 {
309 }
310
311
312 //----------------------------------------------------------------------------
313 QAction* VisuGUI_Slider::toggleViewAction()
314 {
315   return myToggleViewAction;
316 }
317
318
319 //----------------------------------------------------------------------------
320 void VisuGUI_Slider::onModuleDeactivated()
321 {
322   setHidden( true );
323 }
324
325
326 //----------------------------------------------------------------------------
327 void VisuGUI_Slider::onModuleActivated()
328 {
329   setHidden( false );
330 }
331
332
333 //----------------------------------------------------------------------------
334 void VisuGUI_Slider::onMemoryModeChanged( bool )
335 {
336   using namespace VISU;
337   SALOMEDS::Study_var aStudy = GetDSStudy( GetCStudy( GetAppStudy( myModule ) ) );
338   VISU::ColoredPrs3dCache_var aCache = GetVisuGen( myModule )->GetColoredPrs3dCache( aStudy );
339
340   if ( myLimitedMemoryButton->isChecked() ) {
341     aCache->SetMemoryMode( VISU::ColoredPrs3dCache::LIMITED );
342     aCache->SetLimitedMemory( myLimitedMemory->value() );
343   } else
344     aCache->SetMemoryMode( VISU::ColoredPrs3dCache::MINIMAL );
345
346   myLimitedMemory->setEnabled( myLimitedMemoryButton->isChecked() );
347 }
348
349
350 //----------------------------------------------------------------------------
351 void VisuGUI_Slider::onMemorySizeChanged( double )
352 {
353   onMemoryModeChanged( myLimitedMemoryButton->isChecked() );
354 }
355
356
357 //----------------------------------------------------------------------------
358 bool VisuGUI_Slider::checkHolderList()
359 {
360   THolderList aHolderList;
361   THolderList::const_iterator anIter = myHolderList.begin();
362   THolderList::const_iterator anIterEnd = myHolderList.end();
363   for(; anIter != anIterEnd; anIter++){
364     VISU::ColoredPrs3dHolder_var aHolder = *anIter;
365     if(!aHolder->_non_existent())
366       aHolderList.push_back(aHolder);
367   }
368   myHolderList.swap(aHolderList);
369   return myHolderList.empty();
370 }
371
372
373 //----------------------------------------------------------------------------
374 void VisuGUI_Slider::enableControls( bool on )
375 {
376   myPlayTab->setEnabled( on );
377
378   if( on )
379   {
380     if( checkHolderList() )
381       return;
382
383     myTimeStampStrings->clear();
384     myTimeStampIndexes->clear();
385
386     VISU::ColoredPrs3dHolder_var aHolder = myHolderList.front();
387
388     VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = aHolder->GetTimeStampsRange();
389     CORBA::Long aLength = aTimeStampsRange->length();
390
391     VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
392     CORBA::Long aTimeStampNumber = anInput->myTimeStampNumber;
393
394     myFirstTimeStamp->setText( aTimeStampsRange[0].myTime.in() );
395     myLastTimeStamp->setText( aTimeStampsRange[aLength-1].myTime.in() );
396
397     int aPageStep = aLength / 10;
398     aPageStep = std::max(aPageStep, 1);
399     mySlider->setPageStep(aPageStep);
400
401     CORBA::Long a_current_index = 0;
402     for( CORBA::Long an_index = 0; an_index < aLength; an_index++ )
403     {
404       VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ an_index ];
405       CORBA::Long aNumber = anInfo.myNumber;
406       QString aTime = anInfo.myTime.in();
407
408       myTimeStampStrings->addItem( aTime );
409       myTimeStampIndexes->addItem( QString::number( aNumber ) );
410
411       if( aNumber == aTimeStampNumber )
412         a_current_index = an_index;
413     }
414     // work around - to update controls' sizes
415     myTimeStampStrings->setFont(myTimeStampStrings->font());
416     myTimeStampStrings->updateGeometry();
417     
418     myTimeStampIndexes->setFont(myTimeStampStrings->font());
419     myTimeStampIndexes->updateGeometry();
420
421     if( a_current_index > mySlider->maximum() )
422       mySlider->setMaximum( aLength-1 );
423
424     myTimeStampStrings->setCurrentIndex( a_current_index );
425     myTimeStampIndexes->setCurrentIndex( a_current_index );
426     mySlider->setValue( a_current_index );
427
428     if( a_current_index <= mySlider->maximum() )
429       mySlider->setMaximum( aLength-1 );
430
431     using namespace VISU;
432     SALOMEDS::Study_var aStudy = GetDSStudy( GetCStudy( GetAppStudy( myModule ) ) );
433     VISU::ColoredPrs3dCache_var aCache = GetVisuGen( myModule )->GetColoredPrs3dCache( aStudy );
434
435     long aMb = 1024 * 1024;
436     double aLimitedMemory = aCache->GetLimitedMemory();
437     myLimitedMemory->setValue( aLimitedMemory );
438
439     double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 2048 * aMb ) / (double)aMb;
440     double anUsedMemory = aCache->GetMemorySize();
441     double aLimitedMemoryMax = max( anUsedMemory + aFreeMemory, aLimitedMemory );
442     myLimitedMemory->setMaximum( aLimitedMemoryMax );
443   }
444   else
445   {
446     myPlayButton->setChecked( false );
447   }
448
449 }
450
451
452 //----------------------------------------------------------------------------
453 void VisuGUI_Slider::updateMemoryState()
454 {
455   if( checkHolderList() )
456     return;
457
458   VISU::ColoredPrs3dHolder_var aHolder = myHolderList.front();
459   VISU::ColoredPrs3dCache_var aCache = aHolder->GetCache();
460
461   CORBA::Float aCacheMemory = aCache->GetMemorySize();
462   myUsedMemory->setText( QString::number( double( aCacheMemory ), 'E', 2 ) + " Mb" );
463   myUsedMemory->setFont( myUsedMemory->font() );
464   myUsedMemory->updateGeometry();
465     
466
467   long aMb = 1024 * 1024;
468   double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 2048 * aMb ) / (double)aMb;
469   myFreeMemory->setText( QString::number( double( aFreeMemory ), 'E', 2 ) + " Mb" );
470   myFreeMemory->setFont( myFreeMemory->font() );
471   myFreeMemory->updateGeometry();
472 }
473
474
475 //----------------------------------------------------------------------------
476 void VisuGUI_Slider::onSelectionChanged()
477 {
478   //cout << "VisuGUI_Slider::onSelectionChanged()" << endl;
479   myHolderList.clear();
480
481   _PTR(SObject) aSObject;
482
483   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
484     (SUIT_Session::session()->activeApplication());
485
486   SALOME_ListIO aListIO;
487   mySelectionMgr->selectedObjects(aListIO);
488   SALOME_ListIteratorOfListIO anIter(aListIO);
489   for(; anIter.More(); anIter.Next() ){
490     Handle(SALOME_InteractiveObject) anIO = anIter.Value();
491     if (anIO->hasEntry()) {
492       SalomeApp_Study* theStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
493       _PTR(Study) aStudy = theStudy->studyDS();
494       aSObject = aStudy->FindObjectID(anIO->getEntry());
495
496       if (aSObject) {
497         CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
498         if (!CORBA::is_nil(anObject)) {
499           VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
500
501           if(!CORBA::is_nil(aHolder))
502           {
503             //cout << "ColoredPrs3dHolder" << endl;
504             myHolderList.push_back(aHolder);
505           }
506         }
507       }
508     }
509   }
510
511   VISU::View_var aView = myViewManager->GetCurrentView();
512
513   enableControls( !checkHolderList() && !CORBA::is_nil( aView.in() ) );
514
515   updateMemoryState();
516 }
517
518
519 //----------------------------------------------------------------------------
520 void VisuGUI_Slider::onTimeStampActivated( int value )
521 {
522   mySlider->setValue( value );
523   onValueChanged( value );
524 }
525
526
527 //----------------------------------------------------------------------------
528 void VisuGUI_Slider::onFirst()
529 {
530   int value = mySlider->minimum();
531   mySlider->setValue( value );
532 }
533
534
535 //----------------------------------------------------------------------------
536 void VisuGUI_Slider::onPrevious()
537 {
538   int value = mySlider->value() - 1;
539   if( value >= mySlider->minimum() )
540     mySlider->setValue( value );
541 }
542
543
544 //----------------------------------------------------------------------------
545 void VisuGUI_Slider::onPlay( bool on )
546 {
547   if( on )
548   {
549     myPlayButton->setIcon( myPausePixmap );
550
551     int delay = int( 50.0 * mySpeedSlider->maximum() / mySpeedSlider->value() );
552     myTimer->start( delay );
553   }
554   else
555   {
556     myTimer->stop();
557     myPlayButton->setIcon( myPlayPixmap );
558   }
559 }
560
561
562 //----------------------------------------------------------------------------
563 void VisuGUI_Slider::onToggleView( bool on )
564 {
565   if ( !on ) {
566     onPlay( on );
567   }
568 }
569
570
571 //----------------------------------------------------------------------------
572 void VisuGUI_Slider::onNext()
573 {
574   int value = mySlider->value() + 1;
575   if( value <= mySlider->maximum() )
576     mySlider->setValue( value );
577 }
578
579
580 //----------------------------------------------------------------------------
581 void VisuGUI_Slider::onLast()
582 {
583   int value = mySlider->maximum();
584   mySlider->setValue( value );
585 }
586
587
588 //----------------------------------------------------------------------------
589 void VisuGUI_Slider::onValueChanged( int value )
590 {
591   if ( checkHolderList() ) {
592     enableControls( false );
593     return;
594   }
595
596   myTimeStampStrings->setCurrentIndex( value );
597   myTimeStampIndexes->setCurrentIndex( value );
598
599   VISU::ColoredPrs3dHolder_var aHolder = myHolderList.front();
600
601   VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = aHolder->GetTimeStampsRange();
602   CORBA::Long aLength = aTimeStampsRange->length();
603   if ( value < 0 || aLength <= value )
604     return;
605
606   VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
607   CORBA::Long aTimeStampNumber = anInput->myTimeStampNumber;
608   CORBA::Long aNumber = aTimeStampsRange[ value ].myNumber;
609   if ( aNumber == aTimeStampNumber )
610     return;
611
612   VISU::View_var aView = myViewManager->GetCurrentView();
613   if ( CORBA::is_nil( aView.in() ) ) {
614     enableControls( false );
615     return;
616   }
617
618   VISU::View3D_var aView3D = VISU::View3D::_narrow( aView );
619
620   THolderList::const_iterator anIter = myHolderList.begin();
621   THolderList::const_iterator anIterEnd = myHolderList.end();
622   for( ; anIter != anIterEnd; anIter++ )
623   {
624     VISU::ColoredPrs3dHolder_var aHolder = *anIter;
625     if( CORBA::is_nil( aHolder.in() ) )
626       continue;
627
628     VISU::ColoredPrs3d_var aPrs3d = aHolder->GetDevice();
629     VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
630     anInput->myTimeStampNumber = aNumber;
631
632     QApplication::setOverrideCursor(Qt::WaitCursor);
633     
634     aHolder->Apply( aPrs3d, anInput, aView3D );
635     
636     QApplication::restoreOverrideCursor();
637   }
638
639   aView3D->Destroy();
640
641   updateMemoryState();
642 }
643
644
645 //----------------------------------------------------------------------------
646 void VisuGUI_Slider::onSpeedChanged( int value )
647 {
648   if(myPlayButton->isChecked()){
649     int delay = int( 50.0 * mySpeedSlider->maximum() / mySpeedSlider->value() );
650     myTimer->start( delay );
651   }
652 }
653
654
655 //----------------------------------------------------------------------------
656 void VisuGUI_Slider::onTimeout()
657 {
658   int value = mySlider->value();
659   if ( value < mySlider->maximum() ) {
660     onNext();
661   } else {
662     if ( myIsCycled->isChecked() )
663       onFirst();
664     else
665       myPlayButton->setChecked( false );
666   }
667 }
668
669
670 //----------------------------------------------------------------------------