]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_TimeAnimation.cxx
Salome HOME
MPV: Merge V1_2d
[modules/visu.git] / src / VISUGUI / VisuGUI_TimeAnimation.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : VisuGUI_TimeAnimation.cxx
8 //  Author : Vitaly SMETANNIKOV
9 //  Module : VISU
10
11 #include "VisuGUI_TimeAnimation.h"
12 #include "VisuGUI.h"
13
14 #include <qlayout.h>
15 #include <qhbox.h>
16 #include <qhgroupbox.h>
17 #include <qmessagebox.h>
18 #include <qwt_wheel.h>
19 #include <qlcdnumber.h>
20 #include <qlistbox.h>
21 #include <qvgroupbox.h>
22 #include <qthread.h> 
23
24 #include "QAD_Application.h"
25 #include "QAD_Desktop.h"
26 #include "QAD_FileDlg.h"
27
28 #include "VTKViewer_ViewFrame.h"
29 #include "VISU_ScalarBarActor.hxx"
30
31 #include "VisuGUI_MagnitudeDlg.h"
32 #include "VisuGUI_CutPlanesDlg.h"
33 #include "VisuGUI_VectorsDlg.h"
34 #include "VisuGUI_IsoSurfacesDlg.h"
35 #include "VisuGUI_StreamLinesDlg.h"
36 #include "VISU_TimeAnimation.h"
37
38 #include "VISU_ScalarMap_i.hh"
39 #include "VISU_IsoSurfaces_i.hh"
40 #include "VISU_DeformedShape_i.hh"
41 #include "VISU_CutPlanes_i.hh"
42 #include "VISU_CutLines_i.hh"
43 #include "VISU_Vectors_i.hh"
44 #include "VISU_StreamLines_i.hh"
45
46 static double MAXVALUE = 1.0E+300;
47
48
49 SetupDlg::SetupDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) 
50   : QDialog( theParent, "SetupDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )  
51 {
52   setCaption("Setup Animation");
53   setSizeGripEnabled( TRUE );
54   myAnimator = theAnimator;
55   
56   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
57   aMainLayout->setSpacing(5);
58
59
60   QFrame* aRangeGrp = new QFrame(this);
61   QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp ); 
62   aRangeLayout->setSpacing( 6 );
63   aRangeLayout->setMargin( 11 );
64   aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised);
65
66   myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp);
67   aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
68   myUseRangeChk->setChecked(myAnimator->isRangeDefined());
69   
70   QLabel* aMinLbl = new QLabel("From", aRangeGrp);
71   aMinLbl->setEnabled(myUseRangeChk->isChecked());
72   aRangeLayout->addWidget(aMinLbl, 1, 0);
73   double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
74   myMinVal = new QAD_SpinBoxDbl(aRangeGrp, myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep );
75   myMinVal->setEnabled(myUseRangeChk->isChecked());
76   if (myUseRangeChk->isChecked())
77     myMinVal->setValue( myAnimator->getMinRange() );
78   else
79     myMinVal->setValue( myAnimator->getMinTime() );
80     
81   connect(myMinVal, SIGNAL( valueChanged(double)),
82           this, SLOT( onMinValue(double) ));
83   aRangeLayout->addWidget(myMinVal, 1, 1);
84
85   QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
86   aMaxLbl->setEnabled(myUseRangeChk->isChecked());
87   aRangeLayout->addWidget(aMaxLbl, 1, 2);
88   myMaxVal = new QAD_SpinBoxDbl(aRangeGrp, myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep );
89   myMaxVal->setEnabled(myUseRangeChk->isChecked());
90   if (myUseRangeChk->isChecked())
91     myMaxVal->setValue( myAnimator->getMaxRange() );
92   else
93     myMaxVal->setValue( myAnimator->getMaxTime() );
94
95   connect(myMaxVal, SIGNAL( valueChanged(double)),
96           this, SLOT( onMaxValue(double) ));
97   aRangeLayout->addWidget(myMaxVal, 1, 3);
98   
99   connect(myUseRangeChk, SIGNAL( toggled(bool)),
100           aMinLbl, SLOT( setEnabled(bool) ));
101   connect(myUseRangeChk, SIGNAL( toggled(bool)),
102           aMaxLbl, SLOT( setEnabled(bool) ));
103   connect(myUseRangeChk, SIGNAL( toggled(bool)),
104           this, SLOT( onRangeCheck(bool) ));
105
106   aMainLayout->addWidget(aRangeGrp);
107
108   
109   QHBox* aPropFrame = new QHBox(this);
110   aPropFrame->setSpacing(5);
111   
112   QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame);  
113   myFieldLst = new QListBox(aNamesBox);
114   QStringList aFieldNames;
115   // Find names of fields
116   for (int i = 0; i < theAnimator->getNbFields(); i++) {
117     aFieldNames.append(VisuGUI::getValue(theAnimator->getFieldData(i).myField, "myName"));
118   }
119   myFieldLst->insertStringList(aFieldNames);
120   myFieldLst->setSelected(0, true);
121   connect( myFieldLst, SIGNAL( highlighted(int) ), 
122            this, SLOT( onFieldChange(int) ) );
123
124   
125   QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);  
126   myTypeCombo = new QComboBox(aPropBox);
127   connect( myTypeCombo, SIGNAL( activated(int) ), 
128            this, SLOT( onTypeChanged(int) ) );
129   
130   //  QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
131   //connect( aBarBtn, SIGNAL( clicked() ), 
132   //       this, SLOT( onScalarBarDlg() ) );
133  
134   myPropBtn = new QPushButton("Properties...", aPropBox);
135   //  myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
136   connect( myPropBtn, SIGNAL( clicked() ), 
137            this, SLOT( onPreferencesDlg() ) );
138
139   onFieldChange(0);
140   aMainLayout->addWidget(aPropFrame);
141   
142   QHBox* aBtnBox = new QHBox(this);
143   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout()); 
144   aBtnLayout->addStretch();
145   
146   QPushButton* aCloseBtn = new QPushButton(tr("VISU_BUT_OK"), aBtnBox);
147   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
148   
149   aMainLayout->addWidget(aBtnBox);
150 }
151
152
153 //************************************************************************
154 void SetupDlg::onFieldChange(int theIndex) {
155   FieldData& aData = myAnimator->getFieldData(theIndex);
156   myTypeCombo->clear();
157   myTypeCombo->insertItem("Scalar Map");
158   myTypeCombo->insertItem("Iso Surfaces");
159   myTypeCombo->insertItem("Cut Planes");
160
161   SALOMEDS::SObject_var aSObject = aData.myField;
162   long aNumComp = VisuGUI::getValue(aSObject, "myNumComponent").toLong();
163   if (aNumComp > 1) {
164     myTypeCombo->insertItem("Deformed Shape");
165     myTypeCombo->insertItem("Vectors");
166     myTypeCombo->insertItem("Stream Lines");
167   }
168   switch (aData.myPrsType) {
169   case VISU::TSCALARMAP: //Scalar Map
170     myTypeCombo->setCurrentItem(0);
171     break;
172   case VISU::TISOSURFACE: //Iso Surfaces
173     myTypeCombo->setCurrentItem(1);
174     break;
175   case VISU::TCUTPLANES: //Cut Planes
176     myTypeCombo->setCurrentItem(2);
177     break;
178   case VISU::TDEFORMEDSHAPE: //Deformed Shape
179     myTypeCombo->setCurrentItem(3);
180     break;
181   case VISU::TVECTORS: //Vectors
182     myTypeCombo->setCurrentItem(4);
183     break;
184   case VISU::TSTREAMLINES: //Stream Lines
185     myTypeCombo->setCurrentItem(5);
186     aData.myPrsType = VISU::TSTREAMLINES;
187     break;
188   }  
189   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
190 }
191
192 //************************************************************************
193 void SetupDlg::onTypeChanged(int theIndex) {
194   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
195   switch (theIndex) {
196   case 0: //Scalar Map
197     aData.myPrsType = VISU::TSCALARMAP;
198     break;
199   case 1: //Iso Surfaces
200     aData.myPrsType = VISU::TISOSURFACE;
201     break;
202   case 2: //Cut Planes
203     aData.myPrsType = VISU::TCUTPLANES;
204     break;
205   case 3: //Deformed Shape
206     aData.myPrsType = VISU::TDEFORMEDSHAPE;
207     break;
208   case 4: //Vectors
209     aData.myPrsType = VISU::TVECTORS;
210     break;
211   case 5: //Stream Lines
212     aData.myPrsType = VISU::TSTREAMLINES;
213     break;
214   }
215   myAnimator->clearData(aData);
216   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
217   //myAnimator->generatePresentations(myFieldLst->currentItem());
218 }
219
220
221 //************************************************************************
222 /*void SetupDlg::onScalarBarDlg() {
223   QApplication::setOverrideCursor( Qt::waitCursor );
224   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
225   if (aData.myPrs == 0) 
226     myAnimator->generatePresentations(myFieldLst->currentItem());
227   QApplication::restoreOverrideCursor();
228
229   VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
230   aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
231   if (aScalarBarDlg->exec()) {
232     for (int i = 0; i < aData.myNbFrames; i++)
233       aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
234   }
235 }
236 */
237 //************************************************************************
238 void SetupDlg::onPreferencesDlg() {
239   QApplication::setOverrideCursor( Qt::waitCursor );
240   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
241   if (aData.myPrs == 0)
242     myAnimator->generatePresentations(myFieldLst->currentItem());
243   QApplication::restoreOverrideCursor();
244
245 #define EDITPRS(TYPE, DLG) \
246     { \
247       DLG* aDlg = new DLG(); \
248       aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0])); \
249       if (aDlg->exec()) { \
250         for (int i = 0; i < aData.myNbFrames; i++) \
251           aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i])); \
252       } \
253       delete aDlg; \
254     }
255
256
257   switch (myTypeCombo->currentItem()) {
258   case 0: //Scalar Map
259     EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
260     break;
261   case 1: //Iso Surfaces
262     EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
263     break;
264   case 2: //Cut Planes
265     //    EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
266     {
267       VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(false, true);
268       aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
269       if (aDlg->exec()) {
270         for (int i = 0; i < aData.myNbFrames; i++)
271           aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
272       }
273       delete aDlg;
274     }
275     break;
276   case 3: //Deformed Shape
277     EDITPRS(VISU::DeformedShape_i, VisuGUI_MagnitudeDlg);
278     break;
279   case 4: //Vectors
280     EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
281     break;
282   case 5: //Stream Lines
283     EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
284     break;
285   }
286 #undef EDITPRS
287 }
288
289 //************************************************************************
290 void SetupDlg::onRangeCheck(bool theCheck) {
291   for (int i = 0; i < myAnimator->getNbFields(); i++) 
292     myAnimator->clearData(myAnimator->getFieldData(i));
293
294   myMinVal->setEnabled(theCheck);
295   myMaxVal->setEnabled(theCheck);
296
297   if (!theCheck)
298     myAnimator->setAnimationRange(0, 0);
299   else {
300     //    if (myMinVal->value() < myMaxVal->value())
301     myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value());    
302 //     else if (myMinVal->value() > myMaxVal->value())
303 //       myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value());
304 //     else // equal case
305 //       myAnimator->setAnimationRange(0, 0);
306   }
307 }
308
309 //************************************************************************
310 void SetupDlg::onMinValue(double theVal) {
311   if (theVal > myAnimator->getMaxRange()) {
312     myMinVal->setValue( myAnimator->getMinTime() );
313     myMinVal->setFocus();
314     return;
315   }
316   for (int i = 0; i < myAnimator->getNbFields(); i++) 
317     myAnimator->clearData(myAnimator->getFieldData(i));
318   myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
319 }
320
321 //************************************************************************
322 void SetupDlg::onMaxValue(double theVal) {
323   if (theVal < myAnimator->getMinRange()) {
324     myMaxVal->setValue( myAnimator->getMaxTime() );
325     myMaxVal->setFocus();
326     return;
327   }
328   for (int i = 0; i < myAnimator->getNbFields(); i++) 
329     myAnimator->clearData(myAnimator->getFieldData(i));
330   myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal);
331 }
332
333
334 static const char * firstIco[] = {
335 "18 10 2 1",
336 "       g None",
337 ".      g #000000",
338 "         .     .  ",
339 "  ..    ..    ..  ",
340 "  ..   ...   ...  ",
341 "  ..  ....  ....  ",
342 "  .. ..... .....  ",
343 "  .. ..... .....  ",
344 "  ..  ....  ....  ",
345 "  ..   ...   ...  ",
346 "  ..    ..    ..  ",
347 "         .     .  "};
348
349
350 static const char * lastIco[] = {
351 "18 10 2 1",
352 "       g None",
353 ".      g #000000",
354 "  .     .         ",
355 "  ..    ..    ..  ",
356 "  ...   ...   ..  ",
357 "  ....  ....  ..  ",
358 "  ..... ..... ..  ",
359 "  ..... ..... ..  ",
360 "  ....  ....  ..  ",
361 "  ...   ...   ..  ",
362 "  ..    ..    ..  ",
363 "  .     .         "};
364
365
366 static const char * leftIco[] = {
367 "11 10 2 1",
368 "       g None",
369 ".      g #000000",
370 "    .     .",
371 "   ..    ..",
372 "  ...   ...",
373 " ....  ....",
374 "..... .....",
375 "..... .....",
376 " ....  ....",
377 "  ...   ...",
378 "   ..    ..",
379 "    .     ."};
380
381 static const char * playIco[] = {
382 "14 14 2 1",
383 "       g None",
384 ".      g #000000",
385 "              ",
386 "              ",
387 "  ..          ",
388 "  ....        ",
389 "  ......      ",
390 "  ........    ",
391 "  ..........  ",
392 "  ..........  ",
393 "  ........    ",
394 "  ......      ",
395 "  ....        ",
396 "  ..          ",
397 "              ",
398 "              "};
399
400 static QPixmap MYplayPixmap(playIco);
401
402
403
404 static const char * rightIco[] = {
405 "11 10 2 1",
406 "       g None",
407 ".      g #000000",
408 ".     .    ",
409 "..    ..   ",
410 "...   ...  ",
411 "....  .... ",
412 "..... .....",
413 "..... .....",
414 "....  .... ",
415 "...   ...  ",
416 "..    ..   ",
417 ".     .    "};
418
419
420 static const char * pauseIco[] = {
421 "14 14 2 1",
422 "       g None",
423 ".      g #000000",
424 "              ",
425 "              ",
426 "   ..    ..   ",
427 "   ..    ..   ",
428 "   ..    ..   ",
429 "   ..    ..   ",
430 "   ..    ..   ",
431 "   ..    ..   ",
432 "   ..    ..   ",
433 "   ..    ..   ",
434 "   ..    ..   ",
435 "   ..    ..   ",
436 "              ",
437 "              "};
438
439 static QPixmap MYpausePixmap(pauseIco);
440
441
442 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg(SALOMEDS::Study_var theStudy) 
443   : QDialog( QAD_Application::getDesktop(), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
444 {
445   setCaption("Animation");
446   setSizeGripEnabled( TRUE );
447   myStudy = theStudy;
448   isClosing = false;
449
450   myAnimator = new VISU_TimeAnimation(theStudy);
451   myAnimator->setSpeed(1);
452   myAnimator->setViewer(VisuGUI::GetVtkViewFrame());
453   connect( myAnimator, SIGNAL( frameChanged(long, double) ), 
454            this, SLOT( onExecution(long, double) ) );
455   connect( myAnimator, SIGNAL( stopped() ), 
456            this, SLOT( onStop() ) );
457
458   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
459   aMainLayout->setSpacing(5);
460
461   mySetupBtn = new QPushButton("Setup Animation...", this);
462   connect( mySetupBtn, SIGNAL( clicked() ), 
463            this, SLOT( onSetupDlg() ) );
464   aMainLayout->addWidget(mySetupBtn);  
465   
466   myGenBtn = new QPushButton("Generate frames", this);
467   connect( myGenBtn, SIGNAL( clicked() ), 
468            this, SLOT( createFrames() ) );
469   aMainLayout->addWidget(myGenBtn);
470
471   myPlayFrame = new QFrame(this);
472   myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
473   myPlayFrame->setLineWidth( 1 );
474  
475
476   // --- Play controls ---
477   QGridLayout* TopLayout = new QGridLayout( myPlayFrame ); 
478   TopLayout->setSpacing( 6 );
479   TopLayout->setMargin( 11 );
480
481   myTimeLbl = new QLabel("0", myPlayFrame);
482   TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter);
483
484   mySlider = new QSlider(Qt::Horizontal, myPlayFrame);
485   mySlider->setMinValue(0);
486   mySlider->setMaxValue(3);
487   mySlider->setTickInterval(1);
488   //mySlider->setTickmarks(QSlider::Below);
489   mySlider->setTracking(false);
490   connect( mySlider, SIGNAL( valueChanged(int) ), 
491            this, SLOT( onFrameChanged(int) ) );
492   TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2);
493
494   myPlayBtn = new QToolButton(myPlayFrame);
495   myPlayBtn->setIconSet(MYplayPixmap);
496   myPlayBtn->setToggleButton(true);
497   connect( myPlayBtn, SIGNAL( clicked() ), 
498            this, SLOT( onPlayPressed() ) );
499   TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1);
500
501   QToolButton* aBackBtn = new QToolButton(myPlayFrame);
502   aBackBtn->setIconSet(QPixmap(leftIco));
503   connect( aBackBtn, SIGNAL( clicked() ), 
504            this, SLOT( onBackPressed() ) );
505   TopLayout->addWidget(aBackBtn, 3, 0);
506
507   QToolButton* aForvardBtn = new QToolButton(myPlayFrame);
508   aForvardBtn->setIconSet(QPixmap(rightIco));
509   connect( aForvardBtn, SIGNAL( clicked() ), 
510            this, SLOT( onForvardPressed() ) );
511   TopLayout->addWidget(aForvardBtn, 3, 1);
512
513   QToolButton* aFirstBtn = new QToolButton(myPlayFrame);
514   aFirstBtn->setIconSet(QPixmap(firstIco));
515   connect( aFirstBtn, SIGNAL( clicked() ), 
516            this, SLOT( onFirstPressed() ) );
517   TopLayout->addWidget(aFirstBtn, 4, 0);
518   
519   QToolButton* aLastBtn = new QToolButton(myPlayFrame);
520   aLastBtn->setIconSet(QPixmap(lastIco));
521   connect( aLastBtn, SIGNAL( clicked() ), 
522            this, SLOT( onLastPressed() ) );
523   TopLayout->addWidget(aLastBtn, 4, 1);
524   
525   QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
526   TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
527
528   QLCDNumber* aSpeedNum  = new QLCDNumber( 2, myPlayFrame );
529   aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
530   aSpeedNum->display(1);
531   TopLayout->addWidget(aSpeedNum, 4, 3);
532
533   QwtWheel* aWheel = new QwtWheel(myPlayFrame);
534   aWheel->setOrientation(Qt::Vertical);
535   aWheel->setRange(1, 99, 1);
536   connect( aWheel, SIGNAL(valueChanged(double)), 
537            aSpeedNum, SLOT(display(double)) );
538   connect( aWheel, SIGNAL(valueChanged(double)), 
539            this, SLOT(onSpeedChange(double)) );
540   TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight);
541
542   QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
543   aCycleCheck->setChecked(myAnimator->isCycling());
544   connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
545   TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3);
546
547   QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
548   aPropCheck->setChecked(myAnimator->isProportional());
549   connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
550   TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
551
552   QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
553   aSaveBox->setColumnLayout(0, Qt::Horizontal );
554   QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
555   aSaveLay->setSpacing( 5 );
556   aSaveLay->setMargin( 5 );
557
558   mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
559   aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
560
561   QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
562   aPathLbl->setEnabled(false);
563   connect(mySaveCheck, SIGNAL( toggled(bool)),
564           aPathLbl, SLOT( setEnabled(bool) ));
565   aSaveLay->addWidget(aPathLbl, 1, 0);
566   
567   myPathEdit = new QLineEdit(aSaveBox);
568   myPathEdit->setEnabled(false);
569   connect(mySaveCheck, SIGNAL( toggled(bool)),
570           myPathEdit, SLOT( setEnabled(bool) ));
571   aSaveLay->addWidget(myPathEdit, 1, 1);
572
573   QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
574   aBrowseBtn->setEnabled(false);
575   connect(mySaveCheck, SIGNAL( toggled(bool)),
576           aBrowseBtn, SLOT( setEnabled(bool) ));
577   connect(aBrowseBtn, SIGNAL( clicked()),
578           this, SLOT( onBrowse() ));
579   mySaveCheck->setChecked(false);
580   aSaveLay->addWidget(aBrowseBtn, 1, 2);
581
582   TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
583
584   aMainLayout->addWidget(myPlayFrame);
585
586   QHBox* aBtnBox = new QHBox(this);
587   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout()); 
588   aBtnLayout->addStretch();
589
590   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
591   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
592   
593   aMainLayout->addWidget(aBtnBox);
594
595   myPlayFrame->setEnabled(false);
596 }
597
598
599 //************************************************************************
600 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg() {
601   delete myAnimator;
602 }
603
604
605 //************************************************************************
606 void VisuGUI_TimeAnimationDlg::onTypeChange(int index) {
607   stopAnimation();
608   myPropBtn->setEnabled(index != 0);
609   
610   clearView();
611   myPlayFrame->setEnabled(false);
612 }
613
614
615 //************************************************************************
616 void  VisuGUI_TimeAnimationDlg::addField(SALOMEDS::SObject_var theSObject) {
617   myPlayFrame->setEnabled(false);
618   myAnimator->addField(theSObject);
619 }
620
621
622
623 //************************************************************************
624 void VisuGUI_TimeAnimationDlg::createFrames() {
625   stopAnimation();
626   QApplication::setOverrideCursor( Qt::waitCursor );
627
628   for (int i = 0; i < myAnimator->getNbFields(); i++) {
629     if (myAnimator->getFieldData(i).myPrs == 0) 
630       myAnimator->generatePresentations(i);
631   }
632   if (myAnimator->getNbFrames() == 0) {
633     myPlayFrame->setEnabled(false);
634     QApplication::restoreOverrideCursor();
635     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_NO_ANIMATIONDATA")); 
636     return;    
637   }    
638   mySlider->setMaxValue(myAnimator->getNbFrames()-1);
639   myPlayFrame->setEnabled(true);
640   if (!myAnimator->generateFrames()) {
641     QApplication::restoreOverrideCursor();
642     //myPlayFrame->setEnabled(false);
643     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), myAnimator->getLastErrorMsg()); 
644     return;
645   }
646   //myPlayFrame->setEnabled(true);
647   QApplication::restoreOverrideCursor();
648 }
649  
650   
651
652 //************************************************************************
653 void VisuGUI_TimeAnimationDlg::onPlayPressed() {
654   if (myPlayBtn->isOn() && (!myAnimator->running())) {
655     myPlayBtn->setIconSet(MYpausePixmap);
656     if (mySaveCheck->isChecked())
657       myAnimator->dumpTo(myPathEdit->text());
658     else
659       myAnimator->dumpTo("");
660     mySetupBtn->setEnabled(false);
661     myGenBtn->setEnabled(false);
662     myAnimator->startAnimation();
663   } else {
664     myPlayBtn->setIconSet(MYplayPixmap);
665     myAnimator->stopAnimation();
666     mySetupBtn->setEnabled(true);
667     myGenBtn->setEnabled(true);
668   }
669 }
670
671 //************************************************************************
672 void VisuGUI_TimeAnimationDlg::onBackPressed() {
673   //stopAnimation();
674   myAnimator->prevFrame();
675 }
676
677
678 //************************************************************************
679 void VisuGUI_TimeAnimationDlg::onForvardPressed() {
680   myAnimator->nextFrame();
681 }
682
683
684 //************************************************************************
685 void VisuGUI_TimeAnimationDlg::onLastPressed() {
686   myAnimator->lastFrame();
687 }
688
689
690 //************************************************************************
691 void VisuGUI_TimeAnimationDlg::onFirstPressed() {
692   myAnimator->firstFrame();
693 }
694
695
696
697 //************************************************************************
698 void VisuGUI_TimeAnimationDlg::clearView() {
699   myAnimator->clearView();
700 }
701
702
703 //************************************************************************
704 void VisuGUI_TimeAnimationDlg::closeEvent(QCloseEvent* theEvent) {
705   myAnimator->stopAnimation();
706   if (myAnimator->running() && (! myAnimator->finished())) {
707     isClosing = true;
708     myEvent = theEvent;
709   } else {
710     QDialog::closeEvent(theEvent);
711   }
712 }
713
714
715 //************************************************************************
716 void VisuGUI_TimeAnimationDlg::onFrameChanged(int index) {
717   if (myAnimator->isRunning()) return;
718   myAnimator->gotoFrame(index);
719 }
720
721
722 //************************************************************************
723 void VisuGUI_TimeAnimationDlg::onSpeedChange(double theSpeed) {
724   myAnimator->setSpeed((int)theSpeed);
725 }
726     
727
728 //************************************************************************
729 void VisuGUI_TimeAnimationDlg::stopAnimation() {
730   myAnimator->stopAnimation();
731   myPlayBtn->setOn(false);
732   myPlayBtn->setIconSet(MYplayPixmap);
733   mySetupBtn->setEnabled(true);
734   myGenBtn->setEnabled(true);
735 }
736
737 //************************************************************************
738 void VisuGUI_TimeAnimationDlg::onExecution(long theNewFrame, double theTime) {
739   myTimeLbl->setText(QString("%1").arg(theTime));
740   mySlider->setValue(theNewFrame);
741 }
742
743
744 //************************************************************************
745 void VisuGUI_TimeAnimationDlg::onSetupDlg() {
746   if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
747   SetupDlg* aDlg = new SetupDlg(this, myAnimator);
748   aDlg->exec();
749   myPlayFrame->setEnabled(false);
750   delete aDlg;
751 }
752
753 //************************************************************************
754 void VisuGUI_TimeAnimationDlg::onBrowse() {
755   QString aPath = QAD_FileDlg::getExistingDirectory(this, "/","Select path");
756   if (!aPath.isEmpty())
757     myPathEdit->setText(aPath);
758 }
759
760
761 //************************************************************************
762 void VisuGUI_TimeAnimationDlg::onStop() {
763   if (isClosing) {
764     QDialog::closeEvent(myEvent);
765   } else {
766     myPlayBtn->setOn(false);
767     myPlayBtn->setIconSet(MYplayPixmap);
768     mySetupBtn->setEnabled(true);
769     myGenBtn->setEnabled(true);
770   }
771 }