Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI_TimeAnimation.cxx
index 476721a51807548745b242d04ec3a156a46d5e19..de4de17ef4c8fd15baec5a08295bfb72b8cc797b 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "VisuGUI.h"
 #include "VisuGUI_Tools.h"
+#include "VisuGUI_ViewTools.h"
 #include "VisuGUI_DeformedShapeDlg.h"
 #include "VisuGUI_CutPlanesDlg.h"
 #include "VisuGUI_CutLinesDlg.h"
 #define  MAXVAL 1e10
 
 ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator)
-  : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-    myAnimator(theAnimator), myViewWindow(theAnimator->getViewer())
+  : QDialog(theParent, "ArrangeDlg", true,
+            WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+    myAnimator(theAnimator),
+    myViewWindow(theAnimator->getViewer())
 {
   myCurrent = 0;
   init();
   QStringList aFieldNames;
   // Find names of fields
-  for (int i = 0; i < theAnimator->getNbFields(); i++) {
-    aFieldNames.append(VISU::getValue(theAnimator->getFieldData(i).myField, "myName"));
+  for (int i = 0; i < myAnimator->getNbFields(); i++) {
+    aFieldNames.append(VISU::getValue(myAnimator->getFieldData(i).myField, "myName"));
     Offset aOffs;
     aOffs.myOffset[0] = myAnimator->getFieldData(i).myOffset[0];
     aOffs.myOffset[1] = myAnimator->getFieldData(i).myOffset[1];
@@ -90,7 +93,7 @@ ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator)
 ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow)
   : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize |
             WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-    myAnimator(0), myViewWindow(theViewWindow)
+    myAnimator(NULL), myViewWindow(theViewWindow)
 {
   myCurrent = 0;
   init();
@@ -242,7 +245,7 @@ void ArrangeDlg::init()
 
 void ArrangeDlg::accept()
 {
-  if (myAnimator) {
+  if (myAnimator != NULL) {
     acceptAnimation();
   } else {
     acceptViewWindow();
@@ -456,6 +459,7 @@ SetupDlg::SetupDlg (QWidget* theParent,
   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
   aMainLayout->setSpacing(5);
 
+  // Range of time stamps
   QFrame* aRangeGrp = new QFrame(this);
   QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp );
   aRangeLayout->setSpacing( 6 );
@@ -466,16 +470,19 @@ SetupDlg::SetupDlg (QWidget* theParent,
   aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
   myUseRangeChk->setChecked(myAnimator->isRangeDefined());
 
+  double aMaxTime = myAnimator->getMaxTime();
+  double aMinTime = myAnimator->getMinTime();
+  double aStep = (aMaxTime - aMinTime) / (myAnimator->getFieldData(0).myNbTimes - 1);
+
   QLabel* aMinLbl = new QLabel("From", aRangeGrp);
   aMinLbl->setEnabled(myUseRangeChk->isChecked());
   aRangeLayout->addWidget(aMinLbl, 1, 0);
-  double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
-  myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
+  myMinVal = new QtxDblSpinBox( aMinTime, aMaxTime, aStep, aRangeGrp );
   myMinVal->setEnabled(myUseRangeChk->isChecked());
   if (myUseRangeChk->isChecked())
     myMinVal->setValue( myAnimator->getMinRange() );
   else
-    myMinVal->setValue( myAnimator->getMinTime() );
+    myMinVal->setValue( aMinTime );
 
   connect(myMinVal, SIGNAL( valueChanged(double)),
          this, SLOT( onMinValue(double) ));
@@ -484,12 +491,12 @@ SetupDlg::SetupDlg (QWidget* theParent,
   QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
   aMaxLbl->setEnabled(myUseRangeChk->isChecked());
   aRangeLayout->addWidget(aMaxLbl, 1, 2);
-  myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
+  myMaxVal = new QtxDblSpinBox( aMinTime, aMaxTime, aStep, aRangeGrp );
   myMaxVal->setEnabled(myUseRangeChk->isChecked());
   if (myUseRangeChk->isChecked())
     myMaxVal->setValue( myAnimator->getMaxRange() );
   else
-    myMaxVal->setValue( myAnimator->getMaxTime() );
+    myMaxVal->setValue( aMaxTime );
 
   connect(myMaxVal, SIGNAL( valueChanged(double)),
          this, SLOT( onMaxValue(double) ));
@@ -505,6 +512,7 @@ SetupDlg::SetupDlg (QWidget* theParent,
   aMainLayout->addWidget(aRangeGrp);
 
 
+  // Fields and Properties
   QHBox* aPropFrame = new QHBox(this);
   aPropFrame->setSpacing(5);
 
@@ -512,8 +520,8 @@ SetupDlg::SetupDlg (QWidget* theParent,
   myFieldLst = new QListBox(aNamesBox);
   QStringList aFieldNames;
   // Find names of fields
-  for (int i = 0; i < theAnimator->getNbFields(); i++) {
-    _PTR(SObject) aSO = theAnimator->getFieldData(i).myField;
+  for (int i = 0; i < myAnimator->getNbFields(); i++) {
+    _PTR(SObject) aSO = myAnimator->getFieldData(i).myField;
     aFieldNames.append(VISU::getValue(aSO, "myName"));
   }
   myFieldLst->insertStringList(aFieldNames);
@@ -536,7 +544,7 @@ SetupDlg::SetupDlg (QWidget* theParent,
   //      this, SLOT( onScalarBarDlg() ) );
 
   myPropBtn = new QPushButton("Properties...", aPropBox);
-  //  myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
+  //  myPropBtn->setEnabled(myAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
   connect( myPropBtn, SIGNAL( clicked() ),
           this, SLOT( onPreferencesDlg() ) );
 
@@ -647,7 +655,7 @@ void SetupDlg::onFieldChange (int theIndex)
     myTypeCombo->setCurrentItem(myTypeId2ComboId[TDEFORMEDSHAPE_ITEM]);
     break;
   case VISU::TSCALARMAPONDEFORMEDSHAPE: //Scalar Map on Deformed Shape
-    myTypeCombo->setCurrentItem(TSCALARMAPONDEFORMEDSHAPE_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TSCALARMAPONDEFORMEDSHAPE_ITEM]);
     break;
   case VISU::TVECTORS: //Vectors
     myTypeCombo->setCurrentItem(myTypeId2ComboId[TVECTORS_ITEM]);
@@ -766,13 +774,13 @@ void SetupDlg::onPreferencesDlg()
       if (aDlg->exec())
         { 
          int anbFrames=aDlg->getCurrentScalarNbIterations();
+         int aIter = 0;
          for (int i = 0; i < aData.myNbFrames; i++){
            TYPE* aCurrPrs_i = dynamic_cast<TYPE*>(aData.myPrs[i]);
+           aIter = i+1;
            if(i+1 > anbFrames)
-             aDlg->SetScalarField(anbFrames);
-           else
-             aDlg->SetScalarField(i+1);
-           aDlg->storeToPrsObject(aCurrPrs_i,false);
+             aIter=anbFrames;
+           aDlg->storeToPrsObject(aCurrPrs_i,false,aIter);
          }
        }
       delete aDlg;
@@ -970,7 +978,7 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
 
   myAnimator = new VISU_TimeAnimation (theStudy);
   myAnimator->setSpeed(1);
-  myAnimator->setViewer(VISU::GetViewWindow(theModule));
+  myAnimator->setViewer(VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule));
   connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
   connect(myAnimator, SIGNAL(stopped()),                 this, SLOT(onStop()));
 
@@ -1148,6 +1156,9 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
   SUIT_Study* aStudy = VISU::GetAppStudy(myModule);
   connect(aStudy, SIGNAL(destroyed()), this, SLOT(close()));
 
+  connect(myAnimator->getViewer(), SIGNAL(destroyed()), this, SLOT(close()));
+  connect(myAnimator->getViewer(), SIGNAL(closing(SUIT_ViewWindow*)), this, SLOT(close()));
+
   aMainLayout->addWidget(aBtnBox);
 
   myPlayFrame->setEnabled(false);
@@ -1156,7 +1167,10 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
 //------------------------------------------------------------------------
 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
 {
-  delete myAnimator;
+  if(myAnimator != NULL){
+    delete myAnimator;
+    myAnimator = NULL;
+  }
 }
 
 //------------------------------------------------------------------------
@@ -1272,11 +1286,23 @@ void VisuGUI_TimeAnimationDlg::showEvent(QShowEvent* theEvent)
 //------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
 {
-  myAnimator->stopAnimation();
-  myAnimator->wait(500);
-  if (myAnimator->running() && (! myAnimator->finished())) {
-    isClosing = true;
-    myEvent = theEvent;
+  if(myAnimator != NULL){
+    myAnimator->stopAnimation();
+    myAnimator->wait(500);
+    if (myAnimator->running() && (! myAnimator->finished())) {
+      isClosing = true;
+      myEvent = theEvent;
+      //        * Destroing data in myAnimator before study closed.
+      //        * It needed for correcting destroing of myAnimator, which 
+      //        * depend from SVTK_RenderWindowInteractor() e.t.c.
+      if(theEvent->type() == QEvent::Close){
+       for (int i = 0; i < myAnimator->getNbFields(); i++)
+         myAnimator->clearData(myAnimator->getFieldData(i));
+       myAnimator->clearFieldData();
+      }
+    } else {
+      QDialog::closeEvent(theEvent);
+    }
   } else {
     QDialog::closeEvent(theEvent);
   }