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