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