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