]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_TimeAnimation.cxx
Salome HOME
IPAL9377: Save button remains inactive if to change the saved study - VISU fixed
[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
298     float dx = fabs(aBounds[1] - aBounds[0]);
299     float dy = fabs(aBounds[3] - aBounds[2]);
300     float dz = fabs(aBounds[5] - aBounds[4]);
301     float max = (dx > dy) ? dx : dy;
302     max = (dz > max) ? dz : max;
303     max /= 100.0;
304
305     if (aDist < max) {
306       // set base distance between centers of bounding boxes
307       // to minimal (but big enough) size of current bounding box
308       if (dx < max) dx = FLT_MAX;
309       if (dy < max) dy = FLT_MAX;
310       if (dz < max) dz = FLT_MAX;
311
312       aDist = (dx < dy) ? dx : dy;
313       aDist = (dz < aDist) ? dz : aDist;
314     }
315     aDist = aDist * getDistance();
316     for (int i = 0; i < myAnimator->getNbFields(); i++) {
317       myAnimator->getFieldData(i).myOffset[0] = 0;
318       myAnimator->getFieldData(i).myOffset[1] = 0;
319       myAnimator->getFieldData(i).myOffset[2] = 0;
320       myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i;
321     }
322
323     QApplication::restoreOverrideCursor();
324   }
325 }
326
327 void ArrangeDlg::acceptViewWindow()
328 {
329   if (getMode() == ManualMode) {
330     // Save from GUI
331     Offset& aOffs = myOffsets[myCurrent];
332     aOffs.myOffset[0] = myCoord[0]->value();
333     aOffs.myOffset[1] = myCoord[1]->value();
334     aOffs.myOffset[2] = myCoord[2]->value();
335
336     QMap<VISU::Prs3d_i*, int>::Iterator it;
337     for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) {
338       VISU::Prs3d_i* aPrs = it.key();
339       Offset& aOffs = myOffsets[it.data()];
340       if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow)) anActor->SetPosition(aOffs.myOffset);
341       if (mySaveChk)
342         if (mySaveChk->isChecked())
343           aPrs->SetOffset(aOffs.myOffset);
344     }
345   } else {
346     float aDist = 0;
347     float aShift = 0;
348     float aPrevDist = 0;
349     float aPrevShift = 0;
350     //    bool aInit = true;
351     int i;
352     QMap<VISU::Prs3d_i*, int>::Iterator it;
353     for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) {
354       VISU::Prs3d_i* aPrs = it.key();
355       if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)){
356         int aAxis = getAxis();
357         //      if (aInit) {
358         float aBounds[6];
359         aActor->GetBounds(aBounds);
360         switch (aAxis) {
361         case XAxis:
362           aDist = fabs(aBounds[1] - aBounds[0]);
363           break;
364         case YAxis:
365           aDist = fabs(aBounds[3] - aBounds[2]);
366           break;
367         case ZAxis:
368           aDist = fabs(aBounds[5] - aBounds[4]);
369         }
370         //        aInit = false;
371         //      }
372         float aOffset[3];
373         aOffset[0] = aOffset[1] = aOffset[2] = 0;
374
375         if (i > 0) {
376           float aCCDist = (aDist + aPrevDist) / 2.0;
377
378           float dx = fabs(aBounds[1] - aBounds[0]);
379           float dy = fabs(aBounds[3] - aBounds[2]);
380           float dz = fabs(aBounds[5] - aBounds[4]);
381           float max = (dx > dy) ? dx : dy;
382           max = (dz > max) ? dz : max;
383           max /= 100.0;
384
385           if (aCCDist < max) {
386             // set base distance between centers of bounding boxes
387             // to minimal (but big enough) size of current bounding box
388             if (dx < max) dx = FLT_MAX;
389             if (dy < max) dy = FLT_MAX;
390             if (dz < max) dz = FLT_MAX;
391
392             aCCDist = (dx < dy) ? dx : dy;
393             aCCDist = (dz < aCCDist) ? dz : aCCDist;
394           }
395
396           //-------------------------------->
397           //             aShift
398           //                                 aDist / 2
399           //                                 <-->
400           //            .--------------.     .------.
401           //----------->|              |     |      |
402           // aPrevShift '--------------'     '------'
403           //            <------>
404           //            aPrevDist / 2
405           //
406           //                    <--------------->
407           //                    (aDist + aPrevDist) * getDistance() / 2
408
409           aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0;
410         }
411
412         aOffset[aAxis] = aShift;
413         aActor->SetPosition(aOffset);
414         if (mySaveChk)
415           if (mySaveChk->isChecked())
416             aPrs->SetOffset(aOffset);
417
418         aPrevDist = aDist;
419         aPrevShift = aShift;
420       }
421     }
422   }
423   myViewWindow->getRenderer()->ResetCameraClippingRange();
424   myViewWindow->Repaint();
425 }
426
427
428 //*****************************************************************************************************
429 //*****************************************************************************************************
430 //*****************************************************************************************************
431 SetupDlg::SetupDlg (VisuGUI* theModule, VISU_TimeAnimation* theAnimator)
432      : QDialog(VISU::GetDesktop(theModule), "SetupDlg", true, WStyle_Customize |
433                WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
434        myModule(theModule)
435 {
436   setCaption("Setup Animation");
437   setSizeGripEnabled( TRUE );
438   myAnimator = theAnimator;
439
440   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
441   aMainLayout->setSpacing(5);
442
443
444   QFrame* aRangeGrp = new QFrame(this);
445   QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp );
446   aRangeLayout->setSpacing( 6 );
447   aRangeLayout->setMargin( 11 );
448   aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised);
449
450   myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp);
451   aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
452   myUseRangeChk->setChecked(myAnimator->isRangeDefined());
453
454   QLabel* aMinLbl = new QLabel("From", aRangeGrp);
455   aMinLbl->setEnabled(myUseRangeChk->isChecked());
456   aRangeLayout->addWidget(aMinLbl, 1, 0);
457   double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
458   myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
459   myMinVal->setEnabled(myUseRangeChk->isChecked());
460   if (myUseRangeChk->isChecked())
461     myMinVal->setValue( myAnimator->getMinRange() );
462   else
463     myMinVal->setValue( myAnimator->getMinTime() );
464
465   connect(myMinVal, SIGNAL( valueChanged(double)),
466           this, SLOT( onMinValue(double) ));
467   aRangeLayout->addWidget(myMinVal, 1, 1);
468
469   QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
470   aMaxLbl->setEnabled(myUseRangeChk->isChecked());
471   aRangeLayout->addWidget(aMaxLbl, 1, 2);
472   myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
473   myMaxVal->setEnabled(myUseRangeChk->isChecked());
474   if (myUseRangeChk->isChecked())
475     myMaxVal->setValue( myAnimator->getMaxRange() );
476   else
477     myMaxVal->setValue( myAnimator->getMaxTime() );
478
479   connect(myMaxVal, SIGNAL( valueChanged(double)),
480           this, SLOT( onMaxValue(double) ));
481   aRangeLayout->addWidget(myMaxVal, 1, 3);
482
483   connect(myUseRangeChk, SIGNAL( toggled(bool)),
484           aMinLbl, SLOT( setEnabled(bool) ));
485   connect(myUseRangeChk, SIGNAL( toggled(bool)),
486           aMaxLbl, SLOT( setEnabled(bool) ));
487   connect(myUseRangeChk, SIGNAL( toggled(bool)),
488           this, SLOT( onRangeCheck(bool) ));
489
490   aMainLayout->addWidget(aRangeGrp);
491
492
493   QHBox* aPropFrame = new QHBox(this);
494   aPropFrame->setSpacing(5);
495
496   QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame);
497   myFieldLst = new QListBox(aNamesBox);
498   QStringList aFieldNames;
499   // Find names of fields
500   for (int i = 0; i < theAnimator->getNbFields(); i++) {
501     _PTR(SObject) aSO = theAnimator->getFieldData(i).myField;
502     aFieldNames.append(VISU::getValue(aSO, "myName"));
503   }
504   myFieldLst->insertStringList(aFieldNames);
505   myFieldLst->setSelected(0, true);
506   connect( myFieldLst, SIGNAL( highlighted(int) ),
507            this, SLOT( onFieldChange(int) ) );
508
509
510   QVBox* aSetupBox = new QVBox(aPropFrame);
511   aSetupBox->setSpacing(5);
512
513   QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox);
514   //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);
515   myTypeCombo = new QComboBox(aPropBox);
516   connect( myTypeCombo, SIGNAL( activated(int) ),
517            this, SLOT( onTypeChanged(int) ) );
518
519   //  QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
520   //connect( aBarBtn, SIGNAL( clicked() ),
521   //       this, SLOT( onScalarBarDlg() ) );
522
523   myPropBtn = new QPushButton("Properties...", aPropBox);
524   //  myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
525   connect( myPropBtn, SIGNAL( clicked() ),
526            this, SLOT( onPreferencesDlg() ) );
527
528   if (myAnimator->getNbFields() > 1) {
529     myArrangeBtn = new QPushButton("Arrange...", aSetupBox);
530     connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) );
531   }
532   onFieldChange(0);
533   aMainLayout->addWidget(aPropFrame);
534
535   QHBox* aBtnBox = new QHBox(this);
536   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
537   aBtnLayout->addStretch();
538
539   QPushButton* aCloseBtn = new QPushButton(tr("BUT_OK"), aBtnBox);
540   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
541
542   aMainLayout->addWidget(aBtnBox);
543 }
544
545 //************************************************************************
546 enum PrsComboItem {
547   TSCALARMAP_ITEM     = 0, // VISU::TSCALARMAP
548   TISOSURFACE_ITEM    = 1, // VISU::TISOSURFACE
549   TCUTPLANES_ITEM     = 2, // VISU::TCUTPLANES
550   TPLOT3D_ITEM        = 3, // VISU::TPLOT3D
551   TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE
552   TVECTORS_ITEM       = 5, // VISU::TVECTORS
553   TSTREAMLINES_ITEM   = 6  // VISU::TSTREAMLINES
554 };
555
556 //************************************************************************
557 void SetupDlg::onFieldChange (int theIndex)
558 {
559   FieldData& aData = myAnimator->getFieldData(theIndex);
560   myTypeCombo->clear();
561   // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration
562   myTypeCombo->insertItem("Scalar Map");   // item 0
563   myTypeCombo->insertItem("Iso Surfaces"); // item 1
564   myTypeCombo->insertItem("Cut Planes");   // item 2
565   myTypeCombo->insertItem("Plot 3D");      // item 3
566
567   _PTR(SObject) aSObject = aData.myField;
568   long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong();
569   if (aNumComp > 1) {
570     myTypeCombo->insertItem("Deformed Shape"); // item 4
571     myTypeCombo->insertItem("Vectors");        // item 5
572     myTypeCombo->insertItem("Stream Lines");   // item 6
573   }
574   switch (aData.myPrsType) {
575   case VISU::TSCALARMAP: //Scalar Map
576     myTypeCombo->setCurrentItem(TSCALARMAP_ITEM);
577     break;
578   case VISU::TISOSURFACE: //Iso Surfaces
579     myTypeCombo->setCurrentItem(TISOSURFACE_ITEM);
580     break;
581   case VISU::TCUTPLANES: //Cut Planes
582     myTypeCombo->setCurrentItem(TCUTPLANES_ITEM);
583     break;
584   case VISU::TPLOT3D: //Plot 3D
585     myTypeCombo->setCurrentItem(TPLOT3D_ITEM);
586     break;
587   case VISU::TDEFORMEDSHAPE: //Deformed Shape
588     myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM);
589     break;
590   case VISU::TVECTORS: //Vectors
591     myTypeCombo->setCurrentItem(TVECTORS_ITEM);
592     break;
593   case VISU::TSTREAMLINES: //Stream Lines
594     myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM);
595     aData.myPrsType = VISU::TSTREAMLINES;
596     break;
597   }
598   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
599 }
600
601 //************************************************************************
602 void SetupDlg::onTypeChanged (int theIndex)
603 {
604   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
605   switch (theIndex) {
606   case TSCALARMAP_ITEM: //Scalar Map
607     aData.myPrsType = VISU::TSCALARMAP;
608     break;
609   case TISOSURFACE_ITEM: //Iso Surfaces
610     aData.myPrsType = VISU::TISOSURFACE;
611     break;
612   case TCUTPLANES_ITEM: //Cut Planes
613     aData.myPrsType = VISU::TCUTPLANES;
614     break;
615   case TPLOT3D_ITEM: //Plot 3D
616     aData.myPrsType = VISU::TPLOT3D;
617     break;
618   case TDEFORMEDSHAPE_ITEM: //Deformed Shape
619     aData.myPrsType = VISU::TDEFORMEDSHAPE;
620     break;
621   case TVECTORS_ITEM: //Vectors
622     aData.myPrsType = VISU::TVECTORS;
623     break;
624   case TSTREAMLINES_ITEM: //Stream Lines
625     aData.myPrsType = VISU::TSTREAMLINES;
626     break;
627   }
628   myAnimator->clearData(aData);
629   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
630   //myAnimator->generatePresentations(myFieldLst->currentItem());
631 }
632
633 //************************************************************************
634 /*void SetupDlg::onScalarBarDlg() {
635   QApplication::setOverrideCursor( Qt::waitCursor );
636   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
637   if (aData.myPrs == 0)
638     myAnimator->generatePresentations(myFieldLst->currentItem());
639   QApplication::restoreOverrideCursor();
640
641   VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
642   aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
643   if (aScalarBarDlg->exec()) {
644     for (int i = 0; i < aData.myNbFrames; i++)
645       aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
646   }
647 }
648 */
649
650 //************************************************************************
651 void SetupDlg::onPreferencesDlg()
652 {
653   SUIT_OverrideCursor c;
654   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
655   if (aData.myPrs.empty())
656     myAnimator->generatePresentations(myFieldLst->currentItem());
657
658 // BUG VISU5725 : Compatibility gcc 2.95
659 // #define EDITPRS(TYPE, DLG) \
660 //     { \
661 //       DLG* aDlg = new DLG(); \
662 //       aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(0))); \
663 //       if (aDlg->exec()) { \
664 //      for (int i = 0; i < aData.myNbFrames; i++) \
665 //        aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(i))); \
666 //       } \
667 //       delete aDlg; \
668 //     }
669
670
671 #define EDITPRS(TYPE, DLG) {\
672         DLG* aDlg = new DLG (myModule);\
673         aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]));\
674         if (aDlg->exec())\
675         { \
676          for (int i = 0; i < aData.myNbFrames; i++)\
677           aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i]));\
678         } \
679         delete aDlg;}
680
681   switch (myTypeCombo->currentItem()) {
682   case TSCALARMAP_ITEM: //Scalar Map
683     c.suspend();
684     EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
685     break;
686   case TISOSURFACE_ITEM: //Iso Surfaces
687     c.suspend();
688     EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
689     break;
690   case TCUTPLANES_ITEM: //Cut Planes
691     c.suspend();
692     EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
693     /*{
694       VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg (myModule);
695       //_CS_PhB :operator [] .at      aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(0)));
696       aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
697
698       if (aDlg->exec()) {
699         for (int i = 0; i < aData.myNbFrames; i++)
700       //_CS_PhB:operator [] .at   aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(i)));
701           aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
702       }
703       delete aDlg;
704     }*/
705     break;
706   case TPLOT3D_ITEM: //Plot 3D
707     c.suspend();
708     EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg);
709     break;
710   case TDEFORMEDSHAPE_ITEM: //Deformed Shape
711     c.suspend();
712     EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg);
713     break;
714   case TVECTORS_ITEM: //Vectors
715     c.suspend();
716     EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
717     break;
718   case TSTREAMLINES_ITEM: //Stream Lines
719     c.suspend();
720     EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
721     break;
722   }
723 #undef EDITPRS
724 }
725
726
727 //************************************************************************
728 void SetupDlg::onArrangeDlg()
729 {
730   ArrangeDlg aDlg(this, myAnimator);
731   aDlg.exec();
732 }
733
734 //************************************************************************
735 void SetupDlg::onRangeCheck (bool theCheck)
736 {
737   for (int i = 0; i < myAnimator->getNbFields(); i++)
738     myAnimator->clearData(myAnimator->getFieldData(i));
739
740   myMinVal->setEnabled(theCheck);
741   myMaxVal->setEnabled(theCheck);
742
743   if (!theCheck)
744     myAnimator->setAnimationRange(0, 0);
745   else {
746     //    if (myMinVal->value() < myMaxVal->value())
747     myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value());
748 //     else if (myMinVal->value() > myMaxVal->value())
749 //       myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value());
750 //     else // equal case
751 //       myAnimator->setAnimationRange(0, 0);
752   }
753 }
754
755 //************************************************************************
756 void SetupDlg::onMinValue (double theVal)
757 {
758   if (theVal > myAnimator->getMaxRange()) {
759     myMinVal->setValue( myAnimator->getMinTime() );
760     myMinVal->setFocus();
761     return;
762   }
763   for (int i = 0; i < myAnimator->getNbFields(); i++)
764     myAnimator->clearData(myAnimator->getFieldData(i));
765   myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
766 }
767
768 //************************************************************************
769 void SetupDlg::onMaxValue (double theVal)
770 {
771   if (theVal < myAnimator->getMinRange()) {
772     myMaxVal->setValue( myAnimator->getMaxTime() );
773     myMaxVal->setFocus();
774     return;
775   }
776   for (int i = 0; i < myAnimator->getNbFields(); i++)
777     myAnimator->clearData(myAnimator->getFieldData(i));
778   myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal);
779 }
780
781 static const char * firstIco[] = {
782 "18 10 2 1",
783 "       g None",
784 ".      g #000000",
785 "         .     .  ",
786 "  ..    ..    ..  ",
787 "  ..   ...   ...  ",
788 "  ..  ....  ....  ",
789 "  .. ..... .....  ",
790 "  .. ..... .....  ",
791 "  ..  ....  ....  ",
792 "  ..   ...   ...  ",
793 "  ..    ..    ..  ",
794 "         .     .  "};
795
796
797 static const char * lastIco[] = {
798 "18 10 2 1",
799 "       g None",
800 ".      g #000000",
801 "  .     .         ",
802 "  ..    ..    ..  ",
803 "  ...   ...   ..  ",
804 "  ....  ....  ..  ",
805 "  ..... ..... ..  ",
806 "  ..... ..... ..  ",
807 "  ....  ....  ..  ",
808 "  ...   ...   ..  ",
809 "  ..    ..    ..  ",
810 "  .     .         "};
811
812
813 static const char * leftIco[] = {
814 "11 10 2 1",
815 "       g None",
816 ".      g #000000",
817 "    .     .",
818 "   ..    ..",
819 "  ...   ...",
820 " ....  ....",
821 "..... .....",
822 "..... .....",
823 " ....  ....",
824 "  ...   ...",
825 "   ..    ..",
826 "    .     ."};
827
828 static const char * playIco[] = {
829 "14 14 2 1",
830 "       g None",
831 ".      g #000000",
832 "              ",
833 "              ",
834 "  ..          ",
835 "  ....        ",
836 "  ......      ",
837 "  ........    ",
838 "  ..........  ",
839 "  ..........  ",
840 "  ........    ",
841 "  ......      ",
842 "  ....        ",
843 "  ..          ",
844 "              ",
845 "              "};
846
847 static QPixmap MYplayPixmap(playIco);
848
849
850 static const char * rightIco[] = {
851 "11 10 2 1",
852 "       g None",
853 ".      g #000000",
854 ".     .    ",
855 "..    ..   ",
856 "...   ...  ",
857 "....  .... ",
858 "..... .....",
859 "..... .....",
860 "....  .... ",
861 "...   ...  ",
862 "..    ..   ",
863 ".     .    "};
864
865
866 static const char * pauseIco[] = {
867 "14 14 2 1",
868 "       g None",
869 ".      g #000000",
870 "              ",
871 "              ",
872 "   ..    ..   ",
873 "   ..    ..   ",
874 "   ..    ..   ",
875 "   ..    ..   ",
876 "   ..    ..   ",
877 "   ..    ..   ",
878 "   ..    ..   ",
879 "   ..    ..   ",
880 "   ..    ..   ",
881 "   ..    ..   ",
882 "              ",
883 "              "};
884
885 static QPixmap MYpausePixmap(pauseIco);
886
887
888 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy)
889      : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
890                WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
891        myModule(theModule),
892        myStudy(theStudy)
893 {
894   setCaption("Animation");
895   setSizeGripEnabled( TRUE );
896   isClosing = false;
897
898   myAnimator = new VISU_TimeAnimation (theStudy);
899   myAnimator->setSpeed(1);
900   myAnimator->setViewer(VISU::GetViewWindow());
901   connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
902   connect(myAnimator, SIGNAL(stopped()),                  this, SLOT(onStop()));
903
904   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
905   aMainLayout->setSpacing(5);
906
907   mySetupBtn = new QPushButton("Setup Animation...", this);
908   connect( mySetupBtn, SIGNAL( clicked() ),
909            this, SLOT( onSetupDlg() ) );
910   aMainLayout->addWidget(mySetupBtn);
911
912   myGenBtn = new QPushButton("Generate frames", this);
913   connect( myGenBtn, SIGNAL( clicked() ),
914            this, SLOT( createFrames() ) );
915   aMainLayout->addWidget(myGenBtn);
916
917   myPlayFrame = new QFrame(this);
918   myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
919   myPlayFrame->setLineWidth( 1 );
920
921
922   // --- Play controls ---
923   QGridLayout* TopLayout = new QGridLayout( myPlayFrame );
924   TopLayout->setSpacing( 6 );
925   TopLayout->setMargin( 11 );
926
927   myTimeLbl = new QLabel("0", myPlayFrame);
928   TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter);
929
930   mySlider = new QSlider(Qt::Horizontal, myPlayFrame);
931   mySlider->setMinValue(0);
932   mySlider->setMaxValue(3);
933   mySlider->setTickInterval(1);
934   //mySlider->setTickmarks(QSlider::Below);
935   mySlider->setTracking(false);
936   connect( mySlider, SIGNAL( valueChanged(int) ),
937            this, SLOT( onWindowChanged(int) ) );
938   TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2);
939
940   myPlayBtn = new QToolButton(myPlayFrame);
941   myPlayBtn->setIconSet(MYplayPixmap);
942   myPlayBtn->setToggleButton(true);
943   connect( myPlayBtn, SIGNAL( clicked() ),
944            this, SLOT( onPlayPressed() ) );
945   TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1);
946
947   QToolButton* aBackBtn = new QToolButton(myPlayFrame);
948   aBackBtn->setIconSet(QPixmap(leftIco));
949   connect( aBackBtn, SIGNAL( clicked() ),
950            this, SLOT( onBackPressed() ) );
951   TopLayout->addWidget(aBackBtn, 3, 0);
952
953   QToolButton* aForvardBtn = new QToolButton(myPlayFrame);
954   aForvardBtn->setIconSet(QPixmap(rightIco));
955   connect( aForvardBtn, SIGNAL( clicked() ),
956            this, SLOT( onForvardPressed() ) );
957   TopLayout->addWidget(aForvardBtn, 3, 1);
958
959   QToolButton* aFirstBtn = new QToolButton(myPlayFrame);
960   aFirstBtn->setIconSet(QPixmap(firstIco));
961   connect( aFirstBtn, SIGNAL( clicked() ),
962            this, SLOT( onFirstPressed() ) );
963   TopLayout->addWidget(aFirstBtn, 4, 0);
964
965   QToolButton* aLastBtn = new QToolButton(myPlayFrame);
966   aLastBtn->setIconSet(QPixmap(lastIco));
967   connect( aLastBtn, SIGNAL( clicked() ),
968            this, SLOT( onLastPressed() ) );
969   TopLayout->addWidget(aLastBtn, 4, 1);
970
971   QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
972   TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
973
974   QLCDNumber* aSpeedNum  = new QLCDNumber( 2, myPlayFrame );
975   aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
976   aSpeedNum->display(1);
977   TopLayout->addWidget(aSpeedNum, 4, 3);
978
979   QwtWheel* aWheel = new QwtWheel(myPlayFrame);
980   aWheel->setOrientation(Qt::Vertical);
981   aWheel->setRange(1, 99, 1);
982   connect( aWheel, SIGNAL(valueChanged(double)),
983            aSpeedNum, SLOT(display(double)) );
984   connect( aWheel, SIGNAL(valueChanged(double)),
985            this, SLOT(onSpeedChange(double)) );
986   TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight);
987
988   QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
989   aCycleCheck->setChecked(myAnimator->isCycling());
990   connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
991   TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3);
992
993   QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
994   aPropCheck->setChecked(myAnimator->isProportional());
995   connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
996   TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
997
998   QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
999   aSaveBox->setColumnLayout(0, Qt::Horizontal );
1000   QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
1001   aSaveLay->setSpacing( 5 );
1002   aSaveLay->setMargin( 5 );
1003
1004   mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
1005   aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
1006   connect(mySaveCheck, SIGNAL( toggled(bool)),
1007           aWheel, SLOT( setDisabled(bool) ));
1008
1009   QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
1010   aPathLbl->setEnabled(false);
1011   connect(mySaveCheck, SIGNAL( toggled(bool)),
1012           aPathLbl, SLOT( setEnabled(bool) ));
1013   aSaveLay->addWidget(aPathLbl, 1, 0);
1014
1015   myPathEdit = new QLineEdit(aSaveBox);
1016   myPathEdit->setEnabled(false);
1017   connect(mySaveCheck, SIGNAL( toggled(bool)),
1018           myPathEdit, SLOT( setEnabled(bool) ));
1019   aSaveLay->addWidget(myPathEdit, 1, 1);
1020
1021   QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
1022   aBrowseBtn->setEnabled(false);
1023   connect(mySaveCheck, SIGNAL( toggled(bool)),
1024           aBrowseBtn, SLOT( setEnabled(bool) ));
1025   connect(aBrowseBtn, SIGNAL( clicked()),
1026           this, SLOT( onBrowse() ));
1027   mySaveCheck->setChecked(false);
1028   aSaveLay->addWidget(aBrowseBtn, 1, 2);
1029
1030   TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
1031
1032   aMainLayout->addWidget(myPlayFrame);
1033
1034   QHBox* aPublishBox = new QHBox(this);
1035   aPublishBox->setSpacing(5);
1036
1037   myPublishBtn = new QPushButton("Publish to study", aPublishBox);
1038   connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
1039
1040   mySaveBtn = new QPushButton("Save Animation", aPublishBox);
1041   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1042   connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
1043
1044   aMainLayout->addWidget(aPublishBox);
1045
1046
1047   QHBox* aBtnBox = new QHBox(this);
1048   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
1049   aBtnLayout->addStretch();
1050
1051   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
1052   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
1053
1054   SUIT_Study* aStudy = VISU::GetAppStudy(myModule);
1055   connect(aStudy, SIGNAL(destroyed()), this, SLOT(close()));
1056
1057   aMainLayout->addWidget(aBtnBox);
1058
1059   myPlayFrame->setEnabled(false);
1060 }
1061
1062 //************************************************************************
1063 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
1064 {
1065   delete myAnimator;
1066 }
1067
1068 //************************************************************************
1069 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
1070 {
1071   stopAnimation();
1072   myPropBtn->setEnabled(index != 0);
1073
1074   clearView();
1075   myPlayFrame->setEnabled(false);
1076 }
1077
1078 //************************************************************************
1079 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
1080 {
1081   myPlayFrame->setEnabled(false);
1082   myAnimator->addField(VISU::GetSObject(theSObject));
1083 }
1084
1085 //************************************************************************
1086 void VisuGUI_TimeAnimationDlg::createFrames()
1087 {
1088   stopAnimation();
1089   SUIT_OverrideCursor c;
1090
1091   for (int i = 0; i < myAnimator->getNbFields(); i++) {
1092     if (myAnimator->getFieldData(i).myPrs.empty())
1093       myAnimator->generatePresentations(i);
1094   }
1095   if (myAnimator->getNbFrames() == 0) {
1096     myPlayFrame->setEnabled(false);
1097     c.suspend();
1098     SUIT_MessageBox::warn1(this,
1099                            tr("ERROR"),
1100                            tr("MSG_NO_ANIMATIONDATA"),
1101                            tr("&OK"));
1102     return;
1103   }
1104   mySlider->setMaxValue(myAnimator->getNbFrames()-1);
1105   myPlayFrame->setEnabled(true);
1106   if (!myAnimator->generateFrames()) {
1107     c.suspend();
1108     //myPlayFrame->setEnabled(false);
1109     SUIT_MessageBox::warn1(this,
1110                            tr("ERROR"),
1111                            myAnimator->getLastErrorMsg(),
1112                            tr("&OK"));
1113     return;
1114   }
1115   //myPlayFrame->setEnabled(true);
1116 }
1117
1118 //************************************************************************
1119 void VisuGUI_TimeAnimationDlg::onPlayPressed()
1120 {
1121   if (myPlayBtn->isOn() && (!myAnimator->running())) {
1122     myPlayBtn->setIconSet(MYpausePixmap);
1123     if (mySaveCheck->isChecked())
1124       myAnimator->dumpTo(myPathEdit->text());
1125     else
1126       myAnimator->dumpTo("");
1127     mySetupBtn->setEnabled(false);
1128     myGenBtn->setEnabled(false);
1129     myAnimator->startAnimation();
1130   } else {
1131     myPlayBtn->setIconSet(MYplayPixmap);
1132     myAnimator->stopAnimation();
1133     mySetupBtn->setEnabled(true);
1134     myGenBtn->setEnabled(true);
1135   }
1136 }
1137
1138 //************************************************************************
1139 void VisuGUI_TimeAnimationDlg::onBackPressed()
1140 {
1141   //stopAnimation();
1142   myAnimator->prevFrame();
1143 }
1144
1145 //************************************************************************
1146 void VisuGUI_TimeAnimationDlg::onForvardPressed()
1147 {
1148   myAnimator->nextFrame();
1149 }
1150
1151 //************************************************************************
1152 void VisuGUI_TimeAnimationDlg::onLastPressed()
1153 {
1154   myAnimator->lastFrame();
1155 }
1156
1157 //************************************************************************
1158 void VisuGUI_TimeAnimationDlg::onFirstPressed()
1159 {
1160   myAnimator->firstFrame();
1161 }
1162
1163 //************************************************************************
1164 void VisuGUI_TimeAnimationDlg::clearView()
1165 {
1166   myAnimator->clearView();
1167 }
1168
1169 //************************************************************************
1170 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
1171 {
1172   myAnimator->stopAnimation();
1173   myAnimator->wait(500);
1174   if (myAnimator->running() && (! myAnimator->finished())) {
1175     isClosing = true;
1176     myEvent = theEvent;
1177   } else {
1178     QDialog::closeEvent(theEvent);
1179   }
1180 }
1181
1182 //************************************************************************
1183 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
1184 {
1185   if (myAnimator->isRunning()) return;
1186   myAnimator->gotoFrame(index);
1187 }
1188
1189 //************************************************************************
1190 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
1191 {
1192   myAnimator->setSpeed((int)theSpeed);
1193 }
1194
1195 //************************************************************************
1196 void VisuGUI_TimeAnimationDlg::stopAnimation()
1197 {
1198   myAnimator->stopAnimation();
1199   myPlayBtn->setOn(false);
1200   myPlayBtn->setIconSet(MYplayPixmap);
1201   mySetupBtn->setEnabled(true);
1202   myGenBtn->setEnabled(true);
1203 }
1204
1205 //************************************************************************
1206 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
1207 {
1208   myTimeLbl->setText(QString("%1").arg(theTime));
1209   mySlider->setValue(theNewFrame);
1210 }
1211
1212 //************************************************************************
1213 void VisuGUI_TimeAnimationDlg::onSetupDlg()
1214 {
1215   if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
1216   SetupDlg* aDlg = new SetupDlg (myModule, myAnimator);
1217   aDlg->exec();
1218   myPlayFrame->setEnabled(false);
1219   delete aDlg;
1220 }
1221
1222 //************************************************************************
1223 void VisuGUI_TimeAnimationDlg::onBrowse()
1224 {
1225   QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path");
1226   if (!aPath.isEmpty())
1227     myPathEdit->setText(aPath);
1228 }
1229
1230 //************************************************************************
1231 void VisuGUI_TimeAnimationDlg::onStop()
1232 {
1233   if (isClosing) {
1234     QDialog::closeEvent(myEvent);
1235   } else {
1236     myPlayBtn->setOn(false);
1237     myPlayBtn->setIconSet(MYplayPixmap);
1238     mySetupBtn->setEnabled(true);
1239     myGenBtn->setEnabled(true);
1240   }
1241 }
1242
1243 //************************************************************************
1244 void VisuGUI_TimeAnimationDlg::saveToStudy()
1245 {
1246   myAnimator->saveAnimation();
1247   VISU::UpdateObjBrowser(myModule, true);
1248 }
1249
1250 //************************************************************************
1251 void VisuGUI_TimeAnimationDlg::publishToStudy()
1252 {
1253   myAnimator->publishInStudy();
1254   VISU::UpdateObjBrowser(myModule, true);
1255   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1256 }
1257
1258 //************************************************************************
1259 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
1260 {
1261   myAnimator->restoreFromStudy(theAnimation);
1262   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1263 }