Salome HOME
cfb7e796bf4edbbb1f6b5089cb44fbfbcda66b5f
[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_Plot3DDlg.h"
18 #include "VisuGUI_VectorsDlg.h"
19 #include "VisuGUI_IsoSurfacesDlg.h"
20 #include "VisuGUI_StreamLinesDlg.h"
21
22 #include "VISU_TimeAnimation.h"
23
24 #include "VISU_ScalarMap_i.hh"
25 #include "VISU_IsoSurfaces_i.hh"
26 #include "VISU_DeformedShape_i.hh"
27 #include "VISU_CutPlanes_i.hh"
28 #include "VISU_Plot3D_i.hh"
29 #include "VISU_CutLines_i.hh"
30 #include "VISU_Vectors_i.hh"
31 #include "VISU_StreamLines_i.hh"
32
33 #include "VISU_ViewManager_i.hh"
34
35 #include "VISU_ScalarBarActor.hxx"
36 #include "VISU_Actor.h"
37
38 #include "SalomeApp_Study.h"
39 #include "SalomeApp_Application.h"
40
41 #include "SVTK_ViewWindow.h"
42
43 #include "SUIT_OverrideCursor.h"
44 #include "SUIT_MessageBox.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_FileDlg.h"
47
48 #include <vtkRenderer.h>
49
50 #include <qhbox.h>
51 #include <qgrid.h>
52 #include <qlayout.h>
53 #include <qslider.h>
54 #include <qthread.h>
55 #include <qlistbox.h>
56 #include <qwt_wheel.h>
57 #include <qhgroupbox.h>
58 #include <qlcdnumber.h>
59 #include <qvgroupbox.h>
60
61 #define  MAXVAL 1e10
62
63 ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator)
64   : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
65     myAnimator(theAnimator), myViewWindow(theAnimator->getViewer())
66 {
67   myCurrent = 0;
68   init();
69   QStringList aFieldNames;
70   // Find names of fields
71   for (int i = 0; i < theAnimator->getNbFields(); i++) {
72     aFieldNames.append(VISU::getValue(theAnimator->getFieldData(i).myField, "myName"));
73     Offset aOffs;
74     aOffs.myOffset[0] = myAnimator->getFieldData(i).myOffset[0];
75     aOffs.myOffset[1] = myAnimator->getFieldData(i).myOffset[1];
76     aOffs.myOffset[2] = myAnimator->getFieldData(i).myOffset[2];
77     myOffsets.append(aOffs);
78   }
79   myFieldLst->insertStringList(aFieldNames);
80   myFieldLst->setSelected(0, true);
81 }
82
83 ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow)
84   : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize |
85             WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
86     myAnimator(0), myViewWindow(theViewWindow)
87 {
88   myCurrent = 0;
89   init();
90   QStringList aPrsNames;
91   vtkActor* anActor;
92   vtkActorCollection *anActColl = myViewWindow->getRenderer()->GetActors();
93   for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;) {
94     VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor);
95     if (anVISUActor)
96       if (anVISUActor->GetVisibility() != 0) {
97         VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d();
98         if (aPrs) {
99           if (!myPrsMap.contains(aPrs)) {
100             SALOMEDS::SObject_var aSObject = aPrs->GetSObject();
101             if(!aSObject->_is_nil()){
102               SALOMEDS::GenericAttribute_var anAttr;
103               if (aSObject->FindAttribute(anAttr, "AttributeName")) {
104                 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
105                 string aNam = aName->Value();
106                 QString strIn(aNam.c_str());
107                 aPrsNames.append(strIn);
108                 myPrsMap[aPrs] = myOffsets.count();
109                 Offset aOffs;
110                 anVISUActor->GetPosition(aOffs.myOffset);
111                 myOffsets.append(aOffs);
112               }
113             }
114           }
115         }
116       }
117   }
118   myFieldLst->insertStringList(aPrsNames);
119   myFieldLst->setSelected(0, true);
120 }
121
122 void ArrangeDlg::init()
123 {
124   setCaption("Arrange Presentations");
125   setSizeGripEnabled( TRUE );
126
127   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
128   aMainLayout->setSpacing(5);
129
130   QButtonGroup* aBtnGrp = new QButtonGroup(2, Qt::Horizontal, this);
131   aBtnGrp->setExclusive(true);
132   aMainLayout->addWidget(aBtnGrp);
133
134   QRadioButton* aAutoBtn = new QRadioButton("Auto", aBtnGrp);
135   aBtnGrp->insert(aAutoBtn, AutoMode);
136
137   QRadioButton* aManualBtn = new QRadioButton("Manual", aBtnGrp);
138   aBtnGrp->insert(aManualBtn, ManualMode);
139   aBtnGrp->setButton(AutoMode);
140
141   myStackWgt = new QWidgetStack(this);
142   aMainLayout->addWidget(myStackWgt);
143
144   //  AUTO Pane
145   QVBox* aAutoPane = new QVBox(myStackWgt);
146   aAutoPane->setSpacing(5);
147   // Axis Group
148   myAxisGrp = new QButtonGroup(3, Qt::Horizontal,"Axis", aAutoPane);
149
150   QRadioButton* aXBtn = new QRadioButton("X",myAxisGrp );
151   myAxisGrp->insert(aXBtn, XAxis);
152
153   QRadioButton* aYBtn = new QRadioButton("Y",myAxisGrp );
154   myAxisGrp->insert(aYBtn, YAxis);
155
156   QRadioButton* aZBtn = new QRadioButton("Z",myAxisGrp );
157   myAxisGrp->insert(aZBtn, ZAxis);
158
159   myAxisGrp->setButton(XAxis);
160
161   //Distance Input
162   QHBox* aDistPane = new QHBox(aAutoPane);
163   aDistPane->setSpacing(5);
164   new QLabel("Relative Distance", aDistPane);
165   myDistVal = new QtxDblSpinBox (-10,10, 0.5, aDistPane);
166   myDistVal->setValue(1);
167
168   myStackWgt->addWidget(aAutoPane, AutoMode);
169
170   // Manual Pane
171   QHBox* aManualPane = new QHBox(myStackWgt);
172   aManualPane->setSpacing(10);
173
174   myFieldLst = new QListBox(aManualPane);
175   connect( myFieldLst, SIGNAL( highlighted(int) ),
176            this, SLOT( onFieldChange(int) ) );
177
178   QGrid* aCoordPane = new QGrid(2, aManualPane);
179   aCoordPane->setSpacing(5);
180
181   new QLabel("X", aCoordPane);
182   myCoord[0] = new QtxDblSpinBox(aCoordPane);
183   myCoord[0]->setRange(-MAXVAL, MAXVAL);
184
185   new QLabel("Y", aCoordPane);
186   myCoord[1] = new QtxDblSpinBox(aCoordPane);
187   myCoord[1]->setRange(-MAXVAL, MAXVAL);
188
189   new QLabel("Z", aCoordPane);
190   myCoord[2] = new QtxDblSpinBox(aCoordPane);
191   myCoord[2]->setRange(-MAXVAL, MAXVAL);
192
193   myStackWgt->addWidget(aManualPane, ManualMode);
194
195   myStackWgt->raiseWidget(AutoMode);
196
197   connect(aBtnGrp, SIGNAL(clicked(int)), myStackWgt, SLOT(raiseWidget(int)) );
198
199   SUIT_Study* aSUITStudy = myViewWindow->getViewManager()->study();
200   SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(aSUITStudy);
201   _PTR(Study) aCStudy = VISU::GetCStudy(anAppStudy);
202   if (!myAnimator && !aCStudy->GetProperties()->IsLocked()) {
203     mySaveChk = new QCheckBox ("Save to presentation", this);
204     mySaveChk->setChecked(false);
205     aMainLayout->addWidget(mySaveChk);
206   } else {
207     mySaveChk = 0;
208   }
209
210   // Common buttons ===========================================================
211   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
212   GroupButtons->setColumnLayout(0, Qt::Vertical );
213   GroupButtons->layout()->setSpacing( 0 );
214   GroupButtons->layout()->setMargin( 0 );
215   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
216   GroupButtonsLayout->setAlignment( Qt::AlignTop );
217   GroupButtonsLayout->setSpacing( 6 );
218   GroupButtonsLayout->setMargin( 11 );
219
220   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
221   buttonOk->setAutoDefault( TRUE );
222   buttonOk->setDefault( TRUE );
223   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
224   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
225
226   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
227   buttonCancel->setAutoDefault( TRUE );
228   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
229
230   aMainLayout->addWidget( GroupButtons );
231
232   connect( buttonOk,     SIGNAL( clicked() ),      this, SLOT( accept() ) );
233   connect( buttonCancel, SIGNAL( clicked() ),      this, SLOT( reject() ) );
234 }
235
236 void ArrangeDlg::accept()
237 {
238   if (myAnimator) {
239     acceptAnimation();
240   } else {
241     acceptViewWindow();
242   }
243   QDialog::accept();
244 }
245
246 void ArrangeDlg::onFieldChange(int theCurrent)
247 {
248   if (myCurrent != theCurrent) {
249     Offset& aOffs = myOffsets[myCurrent];
250     aOffs.myOffset[0] = myCoord[0]->value();
251     aOffs.myOffset[1] = myCoord[1]->value();
252     aOffs.myOffset[2] = myCoord[2]->value();
253   }
254   myCurrent = theCurrent;
255   const Offset& aNewOffs = myOffsets[myCurrent];
256   myCoord[0]->setValue(aNewOffs.myOffset[0]);
257   myCoord[1]->setValue(aNewOffs.myOffset[1]);
258   myCoord[2]->setValue(aNewOffs.myOffset[2]);
259 }
260
261 void ArrangeDlg::acceptAnimation()
262 {
263   if (getMode() == ManualMode) {
264     // Save from GUI
265     Offset& aOffs = myOffsets[myCurrent];
266     aOffs.myOffset[0] = myCoord[0]->value();
267     aOffs.myOffset[1] = myCoord[1]->value();
268     aOffs.myOffset[2] = myCoord[2]->value();
269
270     for (int i = 0; i < myAnimator->getNbFields(); i++) {
271       Offset aOffs = myOffsets[i];
272       myAnimator->getFieldData(i).myOffset[0] = aOffs.myOffset[0];
273       myAnimator->getFieldData(i).myOffset[1] = aOffs.myOffset[1];
274       myAnimator->getFieldData(i).myOffset[2] = aOffs.myOffset[2];
275     }
276   } else {
277     QApplication::setOverrideCursor( Qt::waitCursor );
278     FieldData& aData = myAnimator->getFieldData(0);
279     if (aData.myPrs.empty())
280       myAnimator->generatePresentations(0);
281     VISU_Actor* aActor = aActor = aData.myPrs[0]->CreateActor();
282     float aBounds[6];
283     aActor->GetBounds(aBounds);
284     aActor->Delete();
285     float aDist = 0;
286     int aAxis = getAxis();
287     switch (aAxis) {
288     case XAxis:
289       aDist = fabs(aBounds[1] - aBounds[0]);
290       break;
291     case YAxis:
292       aDist = fabs(aBounds[3] - aBounds[2]);
293       break;
294     case ZAxis:
295       aDist = fabs(aBounds[5] - aBounds[4]);
296     }
297     aDist = aDist*getDistance();
298     for (int i = 0; i < myAnimator->getNbFields(); i++) {
299       myAnimator->getFieldData(i).myOffset[0] = 0;
300       myAnimator->getFieldData(i).myOffset[1] = 0;
301       myAnimator->getFieldData(i).myOffset[2] = 0;
302       myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i;
303     }
304
305     QApplication::restoreOverrideCursor();
306   }
307 }
308
309 void ArrangeDlg::acceptViewWindow()
310 {
311   if (getMode() == ManualMode) {
312     // Save from GUI
313     Offset& aOffs = myOffsets[myCurrent];
314     aOffs.myOffset[0] = myCoord[0]->value();
315     aOffs.myOffset[1] = myCoord[1]->value();
316     aOffs.myOffset[2] = myCoord[2]->value();
317
318     QMap<VISU::Prs3d_i*, int>::Iterator it;
319     for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) {
320       VISU::Prs3d_i* aPrs = it.key();
321       Offset& aOffs = myOffsets[it.data()];
322       if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow)) anActor->SetPosition(aOffs.myOffset);
323       if (mySaveChk)
324         if (mySaveChk->isChecked())
325           aPrs->SetOffset(aOffs.myOffset);
326     }
327   } else {
328     float aDist = 0;
329     float aShift = 0;
330     float aPrevDist = 0;
331     //    bool aInit = true;
332     int i;
333     QMap<VISU::Prs3d_i*, int>::Iterator it;
334     for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) {
335       VISU::Prs3d_i* aPrs = it.key();
336       if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)){
337         int aAxis = getAxis();
338         //      if (aInit) {
339         float aBounds[6];
340         aActor->GetBounds(aBounds);
341         switch (aAxis) {
342         case XAxis:
343           aDist = fabs(aBounds[1] - aBounds[0]);
344           break;
345         case YAxis:
346           aDist = fabs(aBounds[3] - aBounds[2]);
347           break;
348         case ZAxis:
349           aDist = fabs(aBounds[5] - aBounds[4]);
350         }
351         //        aInit = false;
352         //      }
353         float aOffset[3];
354         aOffset[0] = aOffset[1] = aOffset[2] = 0;
355
356         aShift = (i == 0)? 0 : aShift + (aDist + aPrevDist) * getDistance() / 2;
357
358         aOffset[aAxis] = aShift;
359         aActor->SetPosition(aOffset);
360         if (mySaveChk)
361           if (mySaveChk->isChecked())
362             aPrs->SetOffset(aOffset);
363         aPrevDist = aDist;
364       }
365     }
366   }
367   myViewWindow->getRenderer()->ResetCameraClippingRange();
368   myViewWindow->Repaint();
369 }
370
371
372 //*****************************************************************************************************
373 //*****************************************************************************************************
374 //*****************************************************************************************************
375 SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
376      : QDialog(theParent, "SetupDlg", true, WStyle_Customize |
377                WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
378 {
379   setCaption("Setup Animation");
380   setSizeGripEnabled( TRUE );
381   myAnimator = theAnimator;
382
383   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
384   aMainLayout->setSpacing(5);
385
386
387   QFrame* aRangeGrp = new QFrame(this);
388   QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp );
389   aRangeLayout->setSpacing( 6 );
390   aRangeLayout->setMargin( 11 );
391   aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised);
392
393   myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp);
394   aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
395   myUseRangeChk->setChecked(myAnimator->isRangeDefined());
396
397   QLabel* aMinLbl = new QLabel("From", aRangeGrp);
398   aMinLbl->setEnabled(myUseRangeChk->isChecked());
399   aRangeLayout->addWidget(aMinLbl, 1, 0);
400   double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
401   myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
402   myMinVal->setEnabled(myUseRangeChk->isChecked());
403   if (myUseRangeChk->isChecked())
404     myMinVal->setValue( myAnimator->getMinRange() );
405   else
406     myMinVal->setValue( myAnimator->getMinTime() );
407
408   connect(myMinVal, SIGNAL( valueChanged(double)),
409           this, SLOT( onMinValue(double) ));
410   aRangeLayout->addWidget(myMinVal, 1, 1);
411
412   QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
413   aMaxLbl->setEnabled(myUseRangeChk->isChecked());
414   aRangeLayout->addWidget(aMaxLbl, 1, 2);
415   myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
416   myMaxVal->setEnabled(myUseRangeChk->isChecked());
417   if (myUseRangeChk->isChecked())
418     myMaxVal->setValue( myAnimator->getMaxRange() );
419   else
420     myMaxVal->setValue( myAnimator->getMaxTime() );
421
422   connect(myMaxVal, SIGNAL( valueChanged(double)),
423           this, SLOT( onMaxValue(double) ));
424   aRangeLayout->addWidget(myMaxVal, 1, 3);
425
426   connect(myUseRangeChk, SIGNAL( toggled(bool)),
427           aMinLbl, SLOT( setEnabled(bool) ));
428   connect(myUseRangeChk, SIGNAL( toggled(bool)),
429           aMaxLbl, SLOT( setEnabled(bool) ));
430   connect(myUseRangeChk, SIGNAL( toggled(bool)),
431           this, SLOT( onRangeCheck(bool) ));
432
433   aMainLayout->addWidget(aRangeGrp);
434
435
436   QHBox* aPropFrame = new QHBox(this);
437   aPropFrame->setSpacing(5);
438
439   QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame);
440   myFieldLst = new QListBox(aNamesBox);
441   QStringList aFieldNames;
442   // Find names of fields
443   for (int i = 0; i < theAnimator->getNbFields(); i++) {
444     _PTR(SObject) aSO = theAnimator->getFieldData(i).myField;
445     aFieldNames.append(VISU::getValue(aSO, "myName"));
446   }
447   myFieldLst->insertStringList(aFieldNames);
448   myFieldLst->setSelected(0, true);
449   connect( myFieldLst, SIGNAL( highlighted(int) ),
450            this, SLOT( onFieldChange(int) ) );
451
452
453   QVBox* aSetupBox = new QVBox(aPropFrame);
454   aSetupBox->setSpacing(5);
455
456   QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox);
457   //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);
458   myTypeCombo = new QComboBox(aPropBox);
459   connect( myTypeCombo, SIGNAL( activated(int) ),
460            this, SLOT( onTypeChanged(int) ) );
461
462   //  QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
463   //connect( aBarBtn, SIGNAL( clicked() ),
464   //       this, SLOT( onScalarBarDlg() ) );
465
466   myPropBtn = new QPushButton("Properties...", aPropBox);
467   //  myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
468   connect( myPropBtn, SIGNAL( clicked() ),
469            this, SLOT( onPreferencesDlg() ) );
470
471   if (myAnimator->getNbFields() > 1) {
472     myArrangeBtn = new QPushButton("Arrange...", aSetupBox);
473     connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) );
474   }
475   onFieldChange(0);
476   aMainLayout->addWidget(aPropFrame);
477
478   QHBox* aBtnBox = new QHBox(this);
479   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
480   aBtnLayout->addStretch();
481
482   QPushButton* aCloseBtn = new QPushButton(tr("BUT_OK"), aBtnBox);
483   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
484
485   aMainLayout->addWidget(aBtnBox);
486 }
487
488 //************************************************************************
489 enum PrsComboItem {
490   TSCALARMAP_ITEM     = 0, // VISU::TSCALARMAP
491   TISOSURFACE_ITEM    = 1, // VISU::TISOSURFACE
492   TCUTPLANES_ITEM     = 2, // VISU::TCUTPLANES
493   TPLOT3D_ITEM        = 3, // VISU::TPLOT3D
494   TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE
495   TVECTORS_ITEM       = 5, // VISU::TVECTORS
496   TSTREAMLINES_ITEM   = 6  // VISU::TSTREAMLINES
497 };
498
499 //************************************************************************
500 void SetupDlg::onFieldChange (int theIndex)
501 {
502   FieldData& aData = myAnimator->getFieldData(theIndex);
503   myTypeCombo->clear();
504   // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration
505   myTypeCombo->insertItem("Scalar Map");   // item 0
506   myTypeCombo->insertItem("Iso Surfaces"); // item 1
507   myTypeCombo->insertItem("Cut Planes");   // item 2
508   myTypeCombo->insertItem("Plot 3D");      // item 3
509
510   _PTR(SObject) aSObject = aData.myField;
511   long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong();
512   if (aNumComp > 1) {
513     myTypeCombo->insertItem("Deformed Shape"); // item 4
514     myTypeCombo->insertItem("Vectors");        // item 5
515     myTypeCombo->insertItem("Stream Lines");   // item 6
516   }
517   switch (aData.myPrsType) {
518   case VISU::TSCALARMAP: //Scalar Map
519     myTypeCombo->setCurrentItem(TSCALARMAP_ITEM);
520     break;
521   case VISU::TISOSURFACE: //Iso Surfaces
522     myTypeCombo->setCurrentItem(TISOSURFACE_ITEM);
523     break;
524   case VISU::TCUTPLANES: //Cut Planes
525     myTypeCombo->setCurrentItem(TCUTPLANES_ITEM);
526     break;
527   case VISU::TPLOT3D: //Plot 3D
528     myTypeCombo->setCurrentItem(TPLOT3D_ITEM);
529     break;
530   case VISU::TDEFORMEDSHAPE: //Deformed Shape
531     myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM);
532     break;
533   case VISU::TVECTORS: //Vectors
534     myTypeCombo->setCurrentItem(TVECTORS_ITEM);
535     break;
536   case VISU::TSTREAMLINES: //Stream Lines
537     myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM);
538     aData.myPrsType = VISU::TSTREAMLINES;
539     break;
540   }
541   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
542 }
543
544 //************************************************************************
545 void SetupDlg::onTypeChanged (int theIndex)
546 {
547   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
548   switch (theIndex) {
549   case TSCALARMAP_ITEM: //Scalar Map
550     aData.myPrsType = VISU::TSCALARMAP;
551     break;
552   case TISOSURFACE_ITEM: //Iso Surfaces
553     aData.myPrsType = VISU::TISOSURFACE;
554     break;
555   case TCUTPLANES_ITEM: //Cut Planes
556     aData.myPrsType = VISU::TCUTPLANES;
557     break;
558   case TPLOT3D_ITEM: //Plot 3D
559     aData.myPrsType = VISU::TPLOT3D;
560     break;
561   case TDEFORMEDSHAPE_ITEM: //Deformed Shape
562     aData.myPrsType = VISU::TDEFORMEDSHAPE;
563     break;
564   case TVECTORS_ITEM: //Vectors
565     aData.myPrsType = VISU::TVECTORS;
566     break;
567   case TSTREAMLINES_ITEM: //Stream Lines
568     aData.myPrsType = VISU::TSTREAMLINES;
569     break;
570   }
571   myAnimator->clearData(aData);
572   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
573   //myAnimator->generatePresentations(myFieldLst->currentItem());
574 }
575
576 //************************************************************************
577 /*void SetupDlg::onScalarBarDlg() {
578   QApplication::setOverrideCursor( Qt::waitCursor );
579   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
580   if (aData.myPrs == 0)
581     myAnimator->generatePresentations(myFieldLst->currentItem());
582   QApplication::restoreOverrideCursor();
583
584   VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
585   aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
586   if (aScalarBarDlg->exec()) {
587     for (int i = 0; i < aData.myNbFrames; i++)
588       aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
589   }
590 }
591 */
592
593 //************************************************************************
594 void SetupDlg::onPreferencesDlg()
595 {
596   MESSAGE("SetupDlg::onPreferencesDlg() is not implemented");
597   SUIT_OverrideCursor c;
598   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
599   if (aData.myPrs.empty())
600     myAnimator->generatePresentations(myFieldLst->currentItem());
601
602 // BUG VISU5725 : Compatibility gcc 2.95
603 // #define EDITPRS(TYPE, DLG) \
604 //     { \
605 //       DLG* aDlg = new DLG(); \
606 //       aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(0))); \
607 //       if (aDlg->exec()) { \
608 //      for (int i = 0; i < aData.myNbFrames; i++) \
609 //        aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(i))); \
610 //       } \
611 //       delete aDlg; \
612 //     }
613
614
615 #define EDITPRS(TYPE, DLG) {\
616         DLG* aDlg = new DLG(this);\
617         aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]));\
618         if (aDlg->exec())\
619         { \
620          for (int i = 0; i < aData.myNbFrames; i++)\
621           aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i]));\
622         } \
623         delete aDlg;}
624
625   switch (myTypeCombo->currentItem()) {
626   case TSCALARMAP_ITEM: //Scalar Map
627     c.suspend();
628     EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
629     break;
630   case TISOSURFACE_ITEM: //Iso Surfaces
631     c.suspend();
632     EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
633     break;
634   case TCUTPLANES_ITEM: //Cut Planes
635     //    EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
636     {
637       c.suspend();
638       VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(false, true);
639       //_CS_PhB :operator [] .at      aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(0)));
640       aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
641
642       if (aDlg->exec()) {
643         for (int i = 0; i < aData.myNbFrames; i++)
644       //_CS_PhB:operator [] .at   aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(i)));
645           aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
646       }
647       delete aDlg;
648     }
649     break;
650   case TPLOT3D_ITEM: //Plot 3D
651     c.suspend();
652     EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg);
653     break;
654   case TDEFORMEDSHAPE_ITEM: //Deformed Shape
655     c.suspend();
656     EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg);
657     break;
658   case TVECTORS_ITEM: //Vectors
659     c.suspend();
660     EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
661     break;
662   case TSTREAMLINES_ITEM: //Stream Lines
663     c.suspend();
664     EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
665     break;
666   }
667 #undef EDITPRS
668 }
669
670
671 //************************************************************************
672 void SetupDlg::onArrangeDlg()
673 {
674   ArrangeDlg aDlg(this, myAnimator);
675   aDlg.exec();
676 }
677
678 //************************************************************************
679 void SetupDlg::onRangeCheck (bool theCheck)
680 {
681   for (int i = 0; i < myAnimator->getNbFields(); i++)
682     myAnimator->clearData(myAnimator->getFieldData(i));
683
684   myMinVal->setEnabled(theCheck);
685   myMaxVal->setEnabled(theCheck);
686
687   if (!theCheck)
688     myAnimator->setAnimationRange(0, 0);
689   else {
690     //    if (myMinVal->value() < myMaxVal->value())
691     myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value());
692 //     else if (myMinVal->value() > myMaxVal->value())
693 //       myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value());
694 //     else // equal case
695 //       myAnimator->setAnimationRange(0, 0);
696   }
697 }
698
699 //************************************************************************
700 void SetupDlg::onMinValue (double theVal)
701 {
702   if (theVal > myAnimator->getMaxRange()) {
703     myMinVal->setValue( myAnimator->getMinTime() );
704     myMinVal->setFocus();
705     return;
706   }
707   for (int i = 0; i < myAnimator->getNbFields(); i++)
708     myAnimator->clearData(myAnimator->getFieldData(i));
709   myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
710 }
711
712 //************************************************************************
713 void SetupDlg::onMaxValue (double theVal)
714 {
715   if (theVal < myAnimator->getMinRange()) {
716     myMaxVal->setValue( myAnimator->getMaxTime() );
717     myMaxVal->setFocus();
718     return;
719   }
720   for (int i = 0; i < myAnimator->getNbFields(); i++)
721     myAnimator->clearData(myAnimator->getFieldData(i));
722   myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal);
723 }
724
725 static const char * firstIco[] = {
726 "18 10 2 1",
727 "       g None",
728 ".      g #000000",
729 "         .     .  ",
730 "  ..    ..    ..  ",
731 "  ..   ...   ...  ",
732 "  ..  ....  ....  ",
733 "  .. ..... .....  ",
734 "  .. ..... .....  ",
735 "  ..  ....  ....  ",
736 "  ..   ...   ...  ",
737 "  ..    ..    ..  ",
738 "         .     .  "};
739
740
741 static const char * lastIco[] = {
742 "18 10 2 1",
743 "       g None",
744 ".      g #000000",
745 "  .     .         ",
746 "  ..    ..    ..  ",
747 "  ...   ...   ..  ",
748 "  ....  ....  ..  ",
749 "  ..... ..... ..  ",
750 "  ..... ..... ..  ",
751 "  ....  ....  ..  ",
752 "  ...   ...   ..  ",
753 "  ..    ..    ..  ",
754 "  .     .         "};
755
756
757 static const char * leftIco[] = {
758 "11 10 2 1",
759 "       g None",
760 ".      g #000000",
761 "    .     .",
762 "   ..    ..",
763 "  ...   ...",
764 " ....  ....",
765 "..... .....",
766 "..... .....",
767 " ....  ....",
768 "  ...   ...",
769 "   ..    ..",
770 "    .     ."};
771
772 static const char * playIco[] = {
773 "14 14 2 1",
774 "       g None",
775 ".      g #000000",
776 "              ",
777 "              ",
778 "  ..          ",
779 "  ....        ",
780 "  ......      ",
781 "  ........    ",
782 "  ..........  ",
783 "  ..........  ",
784 "  ........    ",
785 "  ......      ",
786 "  ....        ",
787 "  ..          ",
788 "              ",
789 "              "};
790
791 static QPixmap MYplayPixmap(playIco);
792
793
794 static const char * rightIco[] = {
795 "11 10 2 1",
796 "       g None",
797 ".      g #000000",
798 ".     .    ",
799 "..    ..   ",
800 "...   ...  ",
801 "....  .... ",
802 "..... .....",
803 "..... .....",
804 "....  .... ",
805 "...   ...  ",
806 "..    ..   ",
807 ".     .    "};
808
809
810 static const char * pauseIco[] = {
811 "14 14 2 1",
812 "       g None",
813 ".      g #000000",
814 "              ",
815 "              ",
816 "   ..    ..   ",
817 "   ..    ..   ",
818 "   ..    ..   ",
819 "   ..    ..   ",
820 "   ..    ..   ",
821 "   ..    ..   ",
822 "   ..    ..   ",
823 "   ..    ..   ",
824 "   ..    ..   ",
825 "   ..    ..   ",
826 "              ",
827 "              "};
828
829 static QPixmap MYpausePixmap(pauseIco);
830
831
832 //VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (QWidget* parent, _PTR(Study) theStudy)
833 //     : QDialog(parent, "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
834 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy)
835      : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
836                WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
837 {
838   setCaption("Animation");
839   setSizeGripEnabled( TRUE );
840   myModule = theModule;
841   myStudy = theStudy;
842   isClosing = false;
843
844   //myAnimator = new VISU_TimeAnimation (VISU::GetDSStudy(theStudy));
845   myAnimator = new VISU_TimeAnimation (theStudy);
846   myAnimator->setSpeed(1);
847   myAnimator->setViewer(VISU::GetViewWindow());
848   connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
849   connect(myAnimator, SIGNAL(stopped()),                  this, SLOT(onStop()));
850
851   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
852   aMainLayout->setSpacing(5);
853
854   mySetupBtn = new QPushButton("Setup Animation...", this);
855   connect( mySetupBtn, SIGNAL( clicked() ),
856            this, SLOT( onSetupDlg() ) );
857   aMainLayout->addWidget(mySetupBtn);
858
859   myGenBtn = new QPushButton("Generate frames", this);
860   connect( myGenBtn, SIGNAL( clicked() ),
861            this, SLOT( createFrames() ) );
862   aMainLayout->addWidget(myGenBtn);
863
864   myPlayFrame = new QFrame(this);
865   myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
866   myPlayFrame->setLineWidth( 1 );
867
868
869   // --- Play controls ---
870   QGridLayout* TopLayout = new QGridLayout( myPlayFrame );
871   TopLayout->setSpacing( 6 );
872   TopLayout->setMargin( 11 );
873
874   myTimeLbl = new QLabel("0", myPlayFrame);
875   TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter);
876
877   mySlider = new QSlider(Qt::Horizontal, myPlayFrame);
878   mySlider->setMinValue(0);
879   mySlider->setMaxValue(3);
880   mySlider->setTickInterval(1);
881   //mySlider->setTickmarks(QSlider::Below);
882   mySlider->setTracking(false);
883   connect( mySlider, SIGNAL( valueChanged(int) ),
884            this, SLOT( onWindowChanged(int) ) );
885   TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2);
886
887   myPlayBtn = new QToolButton(myPlayFrame);
888   myPlayBtn->setIconSet(MYplayPixmap);
889   myPlayBtn->setToggleButton(true);
890   connect( myPlayBtn, SIGNAL( clicked() ),
891            this, SLOT( onPlayPressed() ) );
892   TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1);
893
894   QToolButton* aBackBtn = new QToolButton(myPlayFrame);
895   aBackBtn->setIconSet(QPixmap(leftIco));
896   connect( aBackBtn, SIGNAL( clicked() ),
897            this, SLOT( onBackPressed() ) );
898   TopLayout->addWidget(aBackBtn, 3, 0);
899
900   QToolButton* aForvardBtn = new QToolButton(myPlayFrame);
901   aForvardBtn->setIconSet(QPixmap(rightIco));
902   connect( aForvardBtn, SIGNAL( clicked() ),
903            this, SLOT( onForvardPressed() ) );
904   TopLayout->addWidget(aForvardBtn, 3, 1);
905
906   QToolButton* aFirstBtn = new QToolButton(myPlayFrame);
907   aFirstBtn->setIconSet(QPixmap(firstIco));
908   connect( aFirstBtn, SIGNAL( clicked() ),
909            this, SLOT( onFirstPressed() ) );
910   TopLayout->addWidget(aFirstBtn, 4, 0);
911
912   QToolButton* aLastBtn = new QToolButton(myPlayFrame);
913   aLastBtn->setIconSet(QPixmap(lastIco));
914   connect( aLastBtn, SIGNAL( clicked() ),
915            this, SLOT( onLastPressed() ) );
916   TopLayout->addWidget(aLastBtn, 4, 1);
917
918   QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
919   TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
920
921   QLCDNumber* aSpeedNum  = new QLCDNumber( 2, myPlayFrame );
922   aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
923   aSpeedNum->display(1);
924   TopLayout->addWidget(aSpeedNum, 4, 3);
925
926   QwtWheel* aWheel = new QwtWheel(myPlayFrame);
927   aWheel->setOrientation(Qt::Vertical);
928   aWheel->setRange(1, 99, 1);
929   connect( aWheel, SIGNAL(valueChanged(double)),
930            aSpeedNum, SLOT(display(double)) );
931   connect( aWheel, SIGNAL(valueChanged(double)),
932            this, SLOT(onSpeedChange(double)) );
933   TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight);
934
935   QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
936   aCycleCheck->setChecked(myAnimator->isCycling());
937   connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
938   TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3);
939
940   QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
941   aPropCheck->setChecked(myAnimator->isProportional());
942   connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
943   TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
944
945   QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
946   aSaveBox->setColumnLayout(0, Qt::Horizontal );
947   QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
948   aSaveLay->setSpacing( 5 );
949   aSaveLay->setMargin( 5 );
950
951   mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
952   aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
953   connect(mySaveCheck, SIGNAL( toggled(bool)),
954           aWheel, SLOT( setDisabled(bool) ));
955
956   QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
957   aPathLbl->setEnabled(false);
958   connect(mySaveCheck, SIGNAL( toggled(bool)),
959           aPathLbl, SLOT( setEnabled(bool) ));
960   aSaveLay->addWidget(aPathLbl, 1, 0);
961
962   myPathEdit = new QLineEdit(aSaveBox);
963   myPathEdit->setEnabled(false);
964   connect(mySaveCheck, SIGNAL( toggled(bool)),
965           myPathEdit, SLOT( setEnabled(bool) ));
966   aSaveLay->addWidget(myPathEdit, 1, 1);
967
968   QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
969   aBrowseBtn->setEnabled(false);
970   connect(mySaveCheck, SIGNAL( toggled(bool)),
971           aBrowseBtn, SLOT( setEnabled(bool) ));
972   connect(aBrowseBtn, SIGNAL( clicked()),
973           this, SLOT( onBrowse() ));
974   mySaveCheck->setChecked(false);
975   aSaveLay->addWidget(aBrowseBtn, 1, 2);
976
977   TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
978
979   aMainLayout->addWidget(myPlayFrame);
980
981   QHBox* aPublishBox = new QHBox(this);
982   aPublishBox->setSpacing(5);
983
984   myPublishBtn = new QPushButton("Publish to study", aPublishBox);
985   connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
986
987   mySaveBtn = new QPushButton("Save Animation", aPublishBox);
988   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
989   connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
990
991   aMainLayout->addWidget(aPublishBox);
992
993
994   QHBox* aBtnBox = new QHBox(this);
995   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
996   aBtnLayout->addStretch();
997
998   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
999   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
1000
1001   aMainLayout->addWidget(aBtnBox);
1002
1003   myPlayFrame->setEnabled(false);
1004 }
1005
1006 //************************************************************************
1007 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
1008 {
1009   delete myAnimator;
1010 }
1011
1012 //************************************************************************
1013 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
1014 {
1015   stopAnimation();
1016   myPropBtn->setEnabled(index != 0);
1017
1018   clearView();
1019   myPlayFrame->setEnabled(false);
1020 }
1021
1022 //************************************************************************
1023 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
1024 {
1025   myPlayFrame->setEnabled(false);
1026   myAnimator->addField(VISU::GetSObject(theSObject));
1027 }
1028
1029 //************************************************************************
1030 void VisuGUI_TimeAnimationDlg::createFrames()
1031 {
1032   stopAnimation();
1033   SUIT_OverrideCursor c;
1034
1035   for (int i = 0; i < myAnimator->getNbFields(); i++) {
1036     if (myAnimator->getFieldData(i).myPrs.empty())
1037       myAnimator->generatePresentations(i);
1038   }
1039   if (myAnimator->getNbFrames() == 0) {
1040     myPlayFrame->setEnabled(false);
1041     c.suspend();
1042     SUIT_MessageBox::warn1(this,
1043                            tr("ERROR"),
1044                            tr("MSG_NO_ANIMATIONDATA"),
1045                            tr("&OK"));
1046     return;
1047   }
1048   mySlider->setMaxValue(myAnimator->getNbFrames()-1);
1049   myPlayFrame->setEnabled(true);
1050   if (!myAnimator->generateFrames()) {
1051     c.suspend();
1052     //myPlayFrame->setEnabled(false);
1053     SUIT_MessageBox::warn1(this,
1054                            tr("ERROR"),
1055                            myAnimator->getLastErrorMsg(),
1056                            tr("&OK"));
1057     return;
1058   }
1059   //myPlayFrame->setEnabled(true);
1060 }
1061
1062 //************************************************************************
1063 void VisuGUI_TimeAnimationDlg::onPlayPressed()
1064 {
1065   if (myPlayBtn->isOn() && (!myAnimator->running())) {
1066     myPlayBtn->setIconSet(MYpausePixmap);
1067     if (mySaveCheck->isChecked())
1068       myAnimator->dumpTo(myPathEdit->text());
1069     else
1070       myAnimator->dumpTo("");
1071     mySetupBtn->setEnabled(false);
1072     myGenBtn->setEnabled(false);
1073     myAnimator->startAnimation();
1074   } else {
1075     myPlayBtn->setIconSet(MYplayPixmap);
1076     myAnimator->stopAnimation();
1077     mySetupBtn->setEnabled(true);
1078     myGenBtn->setEnabled(true);
1079   }
1080 }
1081
1082 //************************************************************************
1083 void VisuGUI_TimeAnimationDlg::onBackPressed()
1084 {
1085   //stopAnimation();
1086   myAnimator->prevFrame();
1087 }
1088
1089 //************************************************************************
1090 void VisuGUI_TimeAnimationDlg::onForvardPressed()
1091 {
1092   myAnimator->nextFrame();
1093 }
1094
1095 //************************************************************************
1096 void VisuGUI_TimeAnimationDlg::onLastPressed()
1097 {
1098   myAnimator->lastFrame();
1099 }
1100
1101 //************************************************************************
1102 void VisuGUI_TimeAnimationDlg::onFirstPressed()
1103 {
1104   myAnimator->firstFrame();
1105 }
1106
1107 //************************************************************************
1108 void VisuGUI_TimeAnimationDlg::clearView()
1109 {
1110   myAnimator->clearView();
1111 }
1112
1113 //************************************************************************
1114 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
1115 {
1116   myAnimator->stopAnimation();
1117   myAnimator->wait(500);
1118   if (myAnimator->running() && (! myAnimator->finished())) {
1119     isClosing = true;
1120     myEvent = theEvent;
1121   } else {
1122     QDialog::closeEvent(theEvent);
1123   }
1124 }
1125
1126 //************************************************************************
1127 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
1128 {
1129   if (myAnimator->isRunning()) return;
1130   myAnimator->gotoFrame(index);
1131 }
1132
1133 //************************************************************************
1134 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
1135 {
1136   myAnimator->setSpeed((int)theSpeed);
1137 }
1138
1139 //************************************************************************
1140 void VisuGUI_TimeAnimationDlg::stopAnimation()
1141 {
1142   myAnimator->stopAnimation();
1143   myPlayBtn->setOn(false);
1144   myPlayBtn->setIconSet(MYplayPixmap);
1145   mySetupBtn->setEnabled(true);
1146   myGenBtn->setEnabled(true);
1147 }
1148
1149 //************************************************************************
1150 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
1151 {
1152   myTimeLbl->setText(QString("%1").arg(theTime));
1153   mySlider->setValue(theNewFrame);
1154 }
1155
1156 //************************************************************************
1157 void VisuGUI_TimeAnimationDlg::onSetupDlg()
1158 {
1159   if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
1160   SetupDlg* aDlg = new SetupDlg(this, myAnimator);
1161   aDlg->exec();
1162   myPlayFrame->setEnabled(false);
1163   delete aDlg;
1164 }
1165
1166 //************************************************************************
1167 void VisuGUI_TimeAnimationDlg::onBrowse()
1168 {
1169   QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path");
1170   if (!aPath.isEmpty())
1171     myPathEdit->setText(aPath);
1172 }
1173
1174 //************************************************************************
1175 void VisuGUI_TimeAnimationDlg::onStop()
1176 {
1177   if (isClosing) {
1178     QDialog::closeEvent(myEvent);
1179   } else {
1180     myPlayBtn->setOn(false);
1181     myPlayBtn->setIconSet(MYplayPixmap);
1182     mySetupBtn->setEnabled(true);
1183     myGenBtn->setEnabled(true);
1184   }
1185 }
1186
1187 //************************************************************************
1188 void VisuGUI_TimeAnimationDlg::saveToStudy()
1189 {
1190   myAnimator->saveAnimation();
1191   myModule->updateObjBrowser( true );
1192 }
1193
1194 //************************************************************************
1195 void VisuGUI_TimeAnimationDlg::publishToStudy()
1196 {
1197   myAnimator->publishInStudy();
1198   myModule->updateObjBrowser( true );
1199   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1200 }
1201
1202 //************************************************************************
1203 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
1204 {
1205   myAnimator->restoreFromStudy(theAnimation);
1206   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1207 }