Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI_TimeAnimation.cxx
index cfb7e796bf4edbbb1f6b5089cb44fbfbcda66b5f..de4de17ef4c8fd15baec5a08295bfb72b8cc797b 100644 (file)
 
 #include "VisuGUI.h"
 #include "VisuGUI_Tools.h"
+#include "VisuGUI_ViewTools.h"
 #include "VisuGUI_DeformedShapeDlg.h"
 #include "VisuGUI_CutPlanesDlg.h"
+#include "VisuGUI_CutLinesDlg.h"
 #include "VisuGUI_Plot3DDlg.h"
 #include "VisuGUI_VectorsDlg.h"
 #include "VisuGUI_IsoSurfacesDlg.h"
 #include "VisuGUI_StreamLinesDlg.h"
+#include "VisuGUI_ScalarMapOnDeformedShapeDlg.h"
+#include "VisuGUI_GaussPointsDlg.h"
 
 #include "VISU_TimeAnimation.h"
 
@@ -29,6 +33,8 @@
 #include "VISU_CutLines_i.hh"
 #include "VISU_Vectors_i.hh"
 #include "VISU_StreamLines_i.hh"
+#include "VISU_ScalarMapOnDeformedShape_i.hh"
+#include "VISU_GaussPoints_i.hh"
 
 #include "VISU_ViewManager_i.hh"
 
 #include "SUIT_FileDlg.h"
 
 #include <vtkRenderer.h>
+#include <vtkMapper.h>
 
 #include <qhbox.h>
 #include <qgrid.h>
+#include <qimage.h>
 #include <qlayout.h>
 #include <qslider.h>
 #include <qthread.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];
@@ -83,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();
@@ -94,7 +104,7 @@ ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow)
     VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor);
     if (anVISUActor)
       if (anVISUActor->GetVisibility() != 0) {
-       VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d();
+       VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
        if (aPrs) {
          if (!myPrsMap.contains(aPrs)) {
            SALOMEDS::SObject_var aSObject = aPrs->GetSObject();
@@ -235,7 +245,7 @@ void ArrangeDlg::init()
 
 void ArrangeDlg::accept()
 {
-  if (myAnimator) {
+  if (myAnimator != NULL) {
     acceptAnimation();
   } else {
     acceptViewWindow();
@@ -278,7 +288,7 @@ void ArrangeDlg::acceptAnimation()
     FieldData& aData = myAnimator->getFieldData(0);
     if (aData.myPrs.empty())
       myAnimator->generatePresentations(0);
-    VISU_Actor* aActor = aActor = aData.myPrs[0]->CreateActor();
+    VISU_Actor* aActor = aData.myPrs[0]->CreateActor();
     float aBounds[6];
     aActor->GetBounds(aBounds);
     aActor->Delete();
@@ -294,7 +304,25 @@ void ArrangeDlg::acceptAnimation()
     case ZAxis:
       aDist = fabs(aBounds[5] - aBounds[4]);
     }
-    aDist = aDist*getDistance();
+
+    float dx = fabs(aBounds[1] - aBounds[0]);
+    float dy = fabs(aBounds[3] - aBounds[2]);
+    float dz = fabs(aBounds[5] - aBounds[4]);
+    float max = (dx > dy) ? dx : dy;
+    max = (dz > max) ? dz : max;
+    max /= 100.0;
+
+    if (aDist < max) {
+      // set base distance between centers of bounding boxes
+      // to minimal (but big enough) size of current bounding box
+      if (dx < max) dx = FLT_MAX;
+      if (dy < max) dy = FLT_MAX;
+      if (dz < max) dz = FLT_MAX;
+
+      aDist = (dx < dy) ? dx : dy;
+      aDist = (dz < aDist) ? dz : aDist;
+    }
+    aDist = aDist * getDistance();
     for (int i = 0; i < myAnimator->getNbFields(); i++) {
       myAnimator->getFieldData(i).myOffset[0] = 0;
       myAnimator->getFieldData(i).myOffset[1] = 0;
@@ -319,7 +347,8 @@ void ArrangeDlg::acceptViewWindow()
     for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) {
       VISU::Prs3d_i* aPrs = it.key();
       Offset& aOffs = myOffsets[it.data()];
-      if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow)) anActor->SetPosition(aOffs.myOffset);
+      if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow))
+        anActor->SetPosition(aOffs.myOffset);
       if (mySaveChk)
        if (mySaveChk->isChecked())
          aPrs->SetOffset(aOffs.myOffset);
@@ -328,14 +357,19 @@ void ArrangeDlg::acceptViewWindow()
     float aDist = 0;
     float aShift = 0;
     float aPrevDist = 0;
-    //    bool aInit = true;
+    float aPrevShift = 0;
     int i;
     QMap<VISU::Prs3d_i*, int>::Iterator it;
     for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) {
       VISU::Prs3d_i* aPrs = it.key();
-      if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)){
+      if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)) {
        int aAxis = getAxis();
-       //      if (aInit) {
+
+       float aZeroOffset[3];
+        aZeroOffset[0] = aZeroOffset[1] = aZeroOffset[2] = 0;
+       aActor->SetPosition(aZeroOffset);
+        aActor->GetMapper()->Update();
+
        float aBounds[6];
        aActor->GetBounds(aBounds);
        switch (aAxis) {
@@ -348,19 +382,56 @@ void ArrangeDlg::acceptViewWindow()
        case ZAxis:
          aDist = fabs(aBounds[5] - aBounds[4]);
        }
-       //        aInit = false;
-       //      }
        float aOffset[3];
-       aOffset[0] = aOffset[1] = aOffset[2] = 0;
-
-       aShift = (i == 0)? 0 : aShift + (aDist + aPrevDist) * getDistance() / 2;
-
-       aOffset[aAxis] = aShift;
+        aOffset[0] = aOffset[1] = aOffset[2] = 0;
+        aOffset[aAxis] =
+          (aBounds[2*aAxis+1] < aBounds[2*aAxis]) ? -aBounds[2*aAxis+1] : -aBounds[2*aAxis];
+
+        if (i > 0) {
+          float aCCDist = (aDist + aPrevDist) / 2.0;
+
+          float dx = fabs(aBounds[1] - aBounds[0]);
+          float dy = fabs(aBounds[3] - aBounds[2]);
+          float dz = fabs(aBounds[5] - aBounds[4]);
+          float max = (dx > dy) ? dx : dy;
+          max = (dz > max) ? dz : max;
+          max /= 100.0;
+
+          if (aCCDist < max) {
+            // set base distance between centers of bounding boxes
+            // to minimal (but big enough) size of current bounding box
+            if (dx < max) dx = FLT_MAX;
+            if (dy < max) dy = FLT_MAX;
+            if (dz < max) dz = FLT_MAX;
+
+            aCCDist = (dx < dy) ? dx : dy;
+            aCCDist = (dz < aCCDist) ? dz : aCCDist;
+          }
+
+          //-------------------------------->
+          //             aShift
+          //                                 aDist / 2
+          //                                 <-->
+          //            .--------------.     .------.
+          //----------->|              |     |      |
+          // aPrevShift '--------------'     '------'
+          //            <------>
+          //            aPrevDist / 2
+          //
+          //                    <--------------->
+          //                    (aDist + aPrevDist) * getDistance() / 2
+
+          aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0;
+        }
+
+       aOffset[aAxis] += aShift;
        aActor->SetPosition(aOffset);
        if (mySaveChk)
          if (mySaveChk->isChecked())
            aPrs->SetOffset(aOffset);
+
        aPrevDist = aDist;
+       aPrevShift = aShift;
       }
     }
   }
@@ -369,21 +440,26 @@ void ArrangeDlg::acceptViewWindow()
 }
 
 
-//*****************************************************************************************************
-//*****************************************************************************************************
-//*****************************************************************************************************
-SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
-     : QDialog(theParent, "SetupDlg", true, WStyle_Customize |
-               WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+//------------------------------------------------------------------------
+//------------------------------------------------------------------------
+//------------------------------------------------------------------------
+SetupDlg::SetupDlg (QWidget* theParent,
+                   VisuGUI* theModule, 
+                   VISU_TimeAnimation* theAnimator) :
+  QDialog(theParent, 
+         "SetupDlg", 
+         true, 
+         WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+  myAnimator(theAnimator),
+  myModule(theModule)
 {
   setCaption("Setup Animation");
   setSizeGripEnabled( TRUE );
-  myAnimator = theAnimator;
 
   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 );
@@ -394,16 +470,19 @@ SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
   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) ));
@@ -412,12 +491,12 @@ SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
   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) ));
@@ -433,6 +512,7 @@ SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
   aMainLayout->addWidget(aRangeGrp);
 
 
+  // Fields and Properties
   QHBox* aPropFrame = new QHBox(this);
   aPropFrame->setSpacing(5);
 
@@ -440,8 +520,8 @@ SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
   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);
@@ -464,7 +544,7 @@ SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
   //      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() ) );
 
@@ -485,67 +565,117 @@ SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
   aMainLayout->addWidget(aBtnBox);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 enum PrsComboItem {
   TSCALARMAP_ITEM     = 0, // VISU::TSCALARMAP
   TISOSURFACE_ITEM    = 1, // VISU::TISOSURFACE
   TCUTPLANES_ITEM     = 2, // VISU::TCUTPLANES
-  TPLOT3D_ITEM        = 3, // VISU::TPLOT3D
-  TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE
-  TVECTORS_ITEM       = 5, // VISU::TVECTORS
-  TSTREAMLINES_ITEM   = 6  // VISU::TSTREAMLINES
+  TCUTLINES_ITEM      = 3, // VISU::TCUTLINES
+  TPLOT3D_ITEM        = 4, // VISU::TPLOT3D
+  TDEFORMEDSHAPE_ITEM = 5, // VISU::TDEFORMEDSHAPE
+  TVECTORS_ITEM       = 6, // VISU::TVECTORS
+  TSTREAMLINES_ITEM   = 7, // VISU::TSTREAMLINES
+  TGAUSSPOINTS_ITEM   = 8, // VISU::TGAUSSPOINTS
+  TSCALARMAPONDEFORMEDSHAPE_ITEM = 9 // VISU::TSCALARMAPONDEFORMEDSHAPE
 };
 
-//************************************************************************
+//------------------------------------------------------------------------
 void SetupDlg::onFieldChange (int theIndex)
 {
   FieldData& aData = myAnimator->getFieldData(theIndex);
   myTypeCombo->clear();
+  myTypeId2ComboId.clear();
+  myComboId2TypeId.clear();
+
   // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration
   myTypeCombo->insertItem("Scalar Map");   // item 0
+  myTypeId2ComboId[TSCALARMAP_ITEM] = myComboId2TypeId.size();
+  myComboId2TypeId.push_back(TSCALARMAP_ITEM);;
+
   myTypeCombo->insertItem("Iso Surfaces"); // item 1
+  myTypeId2ComboId[TISOSURFACE_ITEM] = myComboId2TypeId.size();
+  myComboId2TypeId.push_back(TISOSURFACE_ITEM);;
+
   myTypeCombo->insertItem("Cut Planes");   // item 2
-  myTypeCombo->insertItem("Plot 3D");      // item 3
+  myTypeId2ComboId[TCUTPLANES_ITEM] = myComboId2TypeId.size();
+  myComboId2TypeId.push_back(TCUTPLANES_ITEM);;
+
+  myTypeCombo->insertItem("Cut Lines");   // item 3
+  myTypeId2ComboId[TCUTLINES_ITEM] = myComboId2TypeId.size();
+  myComboId2TypeId.push_back(TCUTLINES_ITEM);;
+
+  myTypeCombo->insertItem("Plot 3D");      // item 4
+  myTypeId2ComboId[TPLOT3D_ITEM] = myComboId2TypeId.size();
+  myComboId2TypeId.push_back(TPLOT3D_ITEM);;
 
   _PTR(SObject) aSObject = aData.myField;
   long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong();
   if (aNumComp > 1) {
-    myTypeCombo->insertItem("Deformed Shape"); // item 4
-    myTypeCombo->insertItem("Vectors");        // item 5
-    myTypeCombo->insertItem("Stream Lines");   // item 6
+    myTypeCombo->insertItem("Deformed Shape"); // item 5
+    myTypeId2ComboId[TDEFORMEDSHAPE_ITEM] = myComboId2TypeId.size();
+    myComboId2TypeId.push_back(TDEFORMEDSHAPE_ITEM);;
+
+    myTypeCombo->insertItem("Vectors");        // item 6
+    myTypeId2ComboId[TVECTORS_ITEM] = myComboId2TypeId.size();
+    myComboId2TypeId.push_back(TVECTORS_ITEM);;
+
+    myTypeCombo->insertItem("Stream Lines");   // item 7
+    myTypeId2ComboId[TSTREAMLINES_ITEM] = myComboId2TypeId.size();
+    myComboId2TypeId.push_back(TSTREAMLINES_ITEM);;
+
+    myTypeCombo->insertItem("Scalar map on Deformed shape");   // item 9
+    myTypeId2ComboId[TSCALARMAPONDEFORMEDSHAPE_ITEM] = myComboId2TypeId.size();
+    myComboId2TypeId.push_back(TSCALARMAPONDEFORMEDSHAPE_ITEM);;
   }
+
+  long anEntityId = VISU::getValue(aSObject, "myEntityId").toLong();
+  if(anEntityId == VISU::CELL){
+    myTypeCombo->insertItem("Gauss Points");   // item 8
+    myTypeId2ComboId[TGAUSSPOINTS_ITEM] = myComboId2TypeId.size();
+    myComboId2TypeId.push_back(TGAUSSPOINTS_ITEM);;
+  }
+
   switch (aData.myPrsType) {
   case VISU::TSCALARMAP: //Scalar Map
-    myTypeCombo->setCurrentItem(TSCALARMAP_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TSCALARMAP_ITEM]);
     break;
   case VISU::TISOSURFACE: //Iso Surfaces
-    myTypeCombo->setCurrentItem(TISOSURFACE_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TISOSURFACE_ITEM]);
     break;
   case VISU::TCUTPLANES: //Cut Planes
-    myTypeCombo->setCurrentItem(TCUTPLANES_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TCUTPLANES_ITEM]);
+    break;
+  case VISU::TCUTLINES: //Cut Lines
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TCUTLINES_ITEM]);
     break;
   case VISU::TPLOT3D: //Plot 3D
-    myTypeCombo->setCurrentItem(TPLOT3D_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TPLOT3D_ITEM]);
     break;
   case VISU::TDEFORMEDSHAPE: //Deformed Shape
-    myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TDEFORMEDSHAPE_ITEM]);
+    break;
+  case VISU::TSCALARMAPONDEFORMEDSHAPE: //Scalar Map on Deformed Shape
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TSCALARMAPONDEFORMEDSHAPE_ITEM]);
     break;
   case VISU::TVECTORS: //Vectors
-    myTypeCombo->setCurrentItem(TVECTORS_ITEM);
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TVECTORS_ITEM]);
     break;
   case VISU::TSTREAMLINES: //Stream Lines
-    myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM);
-    aData.myPrsType = VISU::TSTREAMLINES;
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TSTREAMLINES_ITEM]);
+    break;
+  case VISU::TGAUSSPOINTS: //Gauss Points
+    myTypeCombo->setCurrentItem(myTypeId2ComboId[TGAUSSPOINTS_ITEM]);
     break;
   }
   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void SetupDlg::onTypeChanged (int theIndex)
 {
   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
-  switch (theIndex) {
+  int aType = myComboId2TypeId[theIndex];
+  switch (aType) {
   case TSCALARMAP_ITEM: //Scalar Map
     aData.myPrsType = VISU::TSCALARMAP;
     break;
@@ -555,127 +685,131 @@ void SetupDlg::onTypeChanged (int theIndex)
   case TCUTPLANES_ITEM: //Cut Planes
     aData.myPrsType = VISU::TCUTPLANES;
     break;
+  case TCUTLINES_ITEM: //Cut Lines
+    aData.myPrsType = VISU::TCUTLINES;
+    break;
   case TPLOT3D_ITEM: //Plot 3D
     aData.myPrsType = VISU::TPLOT3D;
     break;
   case TDEFORMEDSHAPE_ITEM: //Deformed Shape
     aData.myPrsType = VISU::TDEFORMEDSHAPE;
     break;
+  case TSCALARMAPONDEFORMEDSHAPE_ITEM: //Scalar Map on Deformed Shape
+    aData.myPrsType = VISU::TSCALARMAPONDEFORMEDSHAPE;
+    break;
   case TVECTORS_ITEM: //Vectors
     aData.myPrsType = VISU::TVECTORS;
     break;
   case TSTREAMLINES_ITEM: //Stream Lines
     aData.myPrsType = VISU::TSTREAMLINES;
     break;
+  case TGAUSSPOINTS_ITEM: //Gauss Points
+    aData.myPrsType = VISU::TGAUSSPOINTS;
+    break;
   }
   myAnimator->clearData(aData);
   //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
   //myAnimator->generatePresentations(myFieldLst->currentItem());
 }
 
-//************************************************************************
-/*void SetupDlg::onScalarBarDlg() {
-  QApplication::setOverrideCursor( Qt::waitCursor );
-  FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
-  if (aData.myPrs == 0)
-    myAnimator->generatePresentations(myFieldLst->currentItem());
-  QApplication::restoreOverrideCursor();
 
-  VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
-  aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
-  if (aScalarBarDlg->exec()) {
-    for (int i = 0; i < aData.myNbFrames; i++)
-      aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
+//------------------------------------------------------------------------
+namespace
+{
+  template<class TPrs3d, class TDialog>
+  void
+  EditPrs(VisuGUI* theModule,
+         FieldData& theData)
+  {
+    TDialog* aDlg = new TDialog(theModule);
+    aDlg->initFromPrsObject(dynamic_cast<TPrs3d*>(theData.myPrs[0]));
+    if (aDlg->exec())
+      for (int i = 0; i < theData.myNbFrames; i++)
+       aDlg->storeToPrsObject(dynamic_cast<TPrs3d*>(theData.myPrs[i]));
+    delete aDlg;
   }
 }
-*/
 
-//************************************************************************
+
 void SetupDlg::onPreferencesDlg()
 {
-  MESSAGE("SetupDlg::onPreferencesDlg() is not implemented");
   SUIT_OverrideCursor c;
   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
   if (aData.myPrs.empty())
     myAnimator->generatePresentations(myFieldLst->currentItem());
 
-// BUG VISU5725 : Compatibility gcc 2.95
-// #define EDITPRS(TYPE, DLG) \
-//     { \
-//       DLG* aDlg = new DLG(); \
-//       aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(0))); \
-//       if (aDlg->exec()) { \
-//     for (int i = 0; i < aData.myNbFrames; i++) \
-//       aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(i))); \
-//       } \
-//       delete aDlg; \
-//     }
-
-
-#define EDITPRS(TYPE, DLG) {\
-        DLG* aDlg = new DLG(this);\
-        aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]));\
-        if (aDlg->exec())\
-        { \
-         for (int i = 0; i < aData.myNbFrames; i++)\
-          aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i]));\
-        } \
-        delete aDlg;}
-
-  switch (myTypeCombo->currentItem()) {
+  int aType = myComboId2TypeId[myTypeCombo->currentItem()];
+  switch (aType) {
   case TSCALARMAP_ITEM: //Scalar Map
     c.suspend();
-    EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
+    EditPrs<VISU::ScalarMap_i,VisuGUI_ScalarBarDlg>(myModule,aData);
     break;
   case TISOSURFACE_ITEM: //Iso Surfaces
     c.suspend();
-    EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
+    EditPrs<VISU::IsoSurfaces_i,VisuGUI_IsoSurfacesDlg>(myModule,aData);
     break;
   case TCUTPLANES_ITEM: //Cut Planes
-    //    EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
-    {
-      c.suspend();
-      VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(false, true);
-      //_CS_PhB :operator [] .at      aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(0)));
-      aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
-
-      if (aDlg->exec()) {
-       for (int i = 0; i < aData.myNbFrames; i++)
-      //_CS_PhB:operator [] .at          aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(i)));
-         aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
-      }
-      delete aDlg;
-    }
+    c.suspend();
+    EditPrs<VISU::CutPlanes_i,VisuGUI_CutPlanesDlg>(myModule,aData);
+    break;
+  case TCUTLINES_ITEM: //Cut Lines
+    c.suspend();
+    EditPrs<VISU::CutLines_i,VisuGUI_CutLinesDlg>(myModule,aData);
     break;
   case TPLOT3D_ITEM: //Plot 3D
     c.suspend();
-    EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg);
+    EditPrs<VISU::Plot3D_i,VisuGUI_Plot3DDlg>(myModule,aData);
     break;
   case TDEFORMEDSHAPE_ITEM: //Deformed Shape
     c.suspend();
-    EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg);
+    EditPrs<VISU::DeformedShape_i,VisuGUI_DeformedShapeDlg>(myModule,aData);
+    break;
+  case TSCALARMAPONDEFORMEDSHAPE_ITEM: //Scalar Map on Deformed Shape
+    c.suspend();
+    {
+      typedef VisuGUI_ScalarMapOnDeformedShapeDlg DLG;
+      typedef VISU::ScalarMapOnDeformedShape_i TYPE;
+      DLG* aDlg = new DLG (myModule);
+      aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]),true);
+      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)
+             aIter=anbFrames;
+           aDlg->storeToPrsObject(aCurrPrs_i,false,aIter);
+         }
+       }
+      delete aDlg;
+    }
     break;
   case TVECTORS_ITEM: //Vectors
     c.suspend();
-    EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
+    EditPrs<VISU::Vectors_i,VisuGUI_VectorsDlg>(myModule,aData);
     break;
   case TSTREAMLINES_ITEM: //Stream Lines
     c.suspend();
-    EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
+    EditPrs<VISU::StreamLines_i,VisuGUI_StreamLinesDlg>(myModule,aData);
+    break;
+  case TGAUSSPOINTS_ITEM: //Gauss Points
+    c.suspend();
+    EditPrs<VISU::GaussPoints_i,VisuGUI_GaussPointsDlg>(myModule,aData);
     break;
   }
-#undef EDITPRS
 }
 
 
-//************************************************************************
+//------------------------------------------------------------------------
 void SetupDlg::onArrangeDlg()
 {
   ArrangeDlg aDlg(this, myAnimator);
   aDlg.exec();
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void SetupDlg::onRangeCheck (bool theCheck)
 {
   for (int i = 0; i < myAnimator->getNbFields(); i++)
@@ -696,7 +830,7 @@ void SetupDlg::onRangeCheck (bool theCheck)
   }
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void SetupDlg::onMinValue (double theVal)
 {
   if (theVal > myAnimator->getMaxRange()) {
@@ -709,7 +843,7 @@ void SetupDlg::onMinValue (double theVal)
   myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void SetupDlg::onMaxValue (double theVal)
 {
   if (theVal < myAnimator->getMinRange()) {
@@ -829,22 +963,22 @@ static const char * pauseIco[] = {
 static QPixmap MYpausePixmap(pauseIco);
 
 
-//VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (QWidget* parent, _PTR(Study) theStudy)
-//     : QDialog(parent, "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
-VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy)
-     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
-               WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
+VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy) :
+  QDialog(VISU::GetDesktop(theModule), 
+         "VisuGUI_TimeAnimationDlg", 
+         false, 
+         WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+  myModule(theModule),
+  myStudy(theStudy),
+  mySetupDlg(NULL)
 {
   setCaption("Animation");
   setSizeGripEnabled( TRUE );
-  myModule = theModule;
-  myStudy = theStudy;
   isClosing = false;
 
-  //myAnimator = new VISU_TimeAnimation (VISU::GetDSStudy(theStudy));
   myAnimator = new VISU_TimeAnimation (theStudy);
   myAnimator->setSpeed(1);
-  myAnimator->setViewer(VISU::GetViewWindow());
+  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()));
 
@@ -942,6 +1076,7 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
   connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
   TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
 
+  // Pictures saving on disk
   QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
   aSaveBox->setColumnLayout(0, Qt::Horizontal );
   QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
@@ -950,20 +1085,39 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
 
   mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
   aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
+
+  QLabel* aFormatLbl = new QLabel("Saving format:", aSaveBox);
+  aFormatLbl->setEnabled(false);
+  connect(mySaveCheck, SIGNAL( toggled(bool)),
+          aFormatLbl, SLOT( setEnabled(bool) ));
+  aSaveLay->addMultiCellWidget(aFormatLbl, 1, 1, 0, 1);
+
+  myPicsFormat = new QComboBox(aSaveBox);
+  QStrList aDumpFormats = QImageIO::outputFormats();
+  for (unsigned int i = 0; i < aDumpFormats.count(); i++) {
+    myPicsFormat->insertItem(aDumpFormats.at(i));
+  }
+  if (aDumpFormats.find("JPEG"))
+    myPicsFormat->setCurrentItem(aDumpFormats.find("JPEG"));
+  else
+    myPicsFormat->setCurrentItem(0);
+  myPicsFormat->setEnabled(false);
+  aSaveLay->addWidget(myPicsFormat, 1, 2);
   connect(mySaveCheck, SIGNAL( toggled(bool)),
-         aWheel, SLOT( setDisabled(bool) ));
+          myPicsFormat, SLOT( setEnabled(bool) ));
 
   QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
   aPathLbl->setEnabled(false);
   connect(mySaveCheck, SIGNAL( toggled(bool)),
-         aPathLbl, SLOT( setEnabled(bool) ));
-  aSaveLay->addWidget(aPathLbl, 1, 0);
+          aPathLbl, SLOT( setEnabled(bool) ));
+  aSaveLay->addWidget(aPathLbl, 2, 0);
 
   myPathEdit = new QLineEdit(aSaveBox);
+  myPathEdit->setReadOnly(true);
   myPathEdit->setEnabled(false);
   connect(mySaveCheck, SIGNAL( toggled(bool)),
-         myPathEdit, SLOT( setEnabled(bool) ));
-  aSaveLay->addWidget(myPathEdit, 1, 1);
+          myPathEdit, SLOT( setEnabled(bool) ));
+  aSaveLay->addWidget(myPathEdit, 2, 1);
 
   QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
   aBrowseBtn->setEnabled(false);
@@ -972,12 +1126,13 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
   connect(aBrowseBtn, SIGNAL( clicked()),
          this, SLOT( onBrowse() ));
   mySaveCheck->setChecked(false);
-  aSaveLay->addWidget(aBrowseBtn, 1, 2);
+  aSaveLay->addWidget(aBrowseBtn, 2, 2);
 
   TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
 
   aMainLayout->addWidget(myPlayFrame);
 
+  // Animation publishing in study
   QHBox* aPublishBox = new QHBox(this);
   aPublishBox->setSpacing(5);
 
@@ -998,18 +1153,27 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
 
+  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);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
 {
-  delete myAnimator;
+  if(myAnimator != NULL){
+    delete myAnimator;
+    myAnimator = NULL;
+  }
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
 {
   stopAnimation();
@@ -1019,14 +1183,14 @@ void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
   myPlayFrame->setEnabled(false);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
 {
   myPlayFrame->setEnabled(false);
-  myAnimator->addField(VISU::GetSObject(theSObject));
+  myAnimator->addField(theSObject);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::createFrames()
 {
   stopAnimation();
@@ -1059,15 +1223,18 @@ void VisuGUI_TimeAnimationDlg::createFrames()
   //myPlayFrame->setEnabled(true);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onPlayPressed()
 {
   if (myPlayBtn->isOn() && (!myAnimator->running())) {
     myPlayBtn->setIconSet(MYpausePixmap);
-    if (mySaveCheck->isChecked())
+    if (mySaveCheck->isChecked()) {
+      QStrList aDumpFormats = QImageIO::outputFormats();
+      myAnimator->setDumpFormat(aDumpFormats.at(myPicsFormat->currentItem()));
       myAnimator->dumpTo(myPathEdit->text());
-    else
+    } else {
       myAnimator->dumpTo("");
+    }
     mySetupBtn->setEnabled(false);
     myGenBtn->setEnabled(false);
     myAnimator->startAnimation();
@@ -1079,64 +1246,82 @@ void VisuGUI_TimeAnimationDlg::onPlayPressed()
   }
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onBackPressed()
 {
   //stopAnimation();
   myAnimator->prevFrame();
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onForvardPressed()
 {
   myAnimator->nextFrame();
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onLastPressed()
 {
   myAnimator->lastFrame();
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onFirstPressed()
 {
   myAnimator->firstFrame();
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::clearView()
 {
   myAnimator->clearView();
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
+void VisuGUI_TimeAnimationDlg::showEvent(QShowEvent* theEvent)
+{
+  mySetupDlg = new SetupDlg(this,myModule, myAnimator);
+}
+
+//------------------------------------------------------------------------
 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);
   }
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
 {
   if (myAnimator->isRunning()) return;
   myAnimator->gotoFrame(index);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
 {
   myAnimator->setSpeed((int)theSpeed);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::stopAnimation()
 {
   myAnimator->stopAnimation();
@@ -1146,32 +1331,31 @@ void VisuGUI_TimeAnimationDlg::stopAnimation()
   myGenBtn->setEnabled(true);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
 {
   myTimeLbl->setText(QString("%1").arg(theTime));
   mySlider->setValue(theNewFrame);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onSetupDlg()
 {
-  if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
-  SetupDlg* aDlg = new SetupDlg(this, myAnimator);
-  aDlg->exec();
+  if (myAnimator->getNbFrames() > 0) 
+    myAnimator->firstFrame();
+  mySetupDlg->exec();
   myPlayFrame->setEnabled(false);
-  delete aDlg;
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onBrowse()
 {
-  QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path");
+  QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/", "Select path");
   if (!aPath.isEmpty())
-    myPathEdit->setText(aPath);
+    myPathEdit->setText(Qtx::addSlash(aPath));
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::onStop()
 {
   if (isClosing) {
@@ -1184,22 +1368,22 @@ void VisuGUI_TimeAnimationDlg::onStop()
   }
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::saveToStudy()
 {
   myAnimator->saveAnimation();
-  myModule->updateObjBrowser( true );
+  VISU::UpdateObjBrowser(myModule, true);
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::publishToStudy()
 {
   myAnimator->publishInStudy();
-  myModule->updateObjBrowser( true );
+  VISU::UpdateObjBrowser(myModule, true);
   mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
 }
 
-//************************************************************************
+//------------------------------------------------------------------------
 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
 {
   myAnimator->restoreFromStudy(theAnimation);