Salome HOME
Fix a regression
[modules/visu.git] / src / VISUGUI / VisuGUI_TimeAnimation.cxx
index 1bae73cc5b17319169c07763503abd578a1870f3..0598764e379343b0ef5915d9b230453c50914dfd 100644 (file)
@@ -278,7 +278,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 +294,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 +337,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 +347,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 +372,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] = (aBounds[1] < aBounds[0]) ? -aBounds[1] : -aBounds[0];
+        aOffset[1] = (aBounds[3] < aBounds[2]) ? -aBounds[3] : -aBounds[2];
+        aOffset[2] = (aBounds[5] < aBounds[4]) ? -aBounds[5] : -aBounds[4];
+
+        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;
       }
     }
   }
@@ -594,7 +655,6 @@ void SetupDlg::onTypeChanged (int theIndex)
 //************************************************************************
 void SetupDlg::onPreferencesDlg()
 {
-  MESSAGE("SetupDlg::onPreferencesDlg() is not implemented");
   SUIT_OverrideCursor c;
   FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
   if (aData.myPrs.empty())
@@ -633,10 +693,10 @@ void SetupDlg::onPreferencesDlg()
     EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
     break;
   case TCUTPLANES_ITEM: //Cut Planes
-    //    EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
-    {
-      c.suspend();
-      VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(false, true);
+    c.suspend();
+    EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
+    /*{
+      VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg (myModule);
       //_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]));
 
@@ -646,7 +706,7 @@ void SetupDlg::onPreferencesDlg()
          aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
       }
       delete aDlg;
-    }
+    }*/
     break;
   case TPLOT3D_ITEM: //Plot 3D
     c.suspend();
@@ -832,15 +892,14 @@ static QPixmap MYpausePixmap(pauseIco);
 
 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)
+               WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+       myModule(theModule),
+       myStudy(theStudy)
 {
   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());
@@ -997,6 +1056,9 @@ 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()));
+
   aMainLayout->addWidget(aBtnBox);
 
   myPlayFrame->setEnabled(false);
@@ -1022,7 +1084,7 @@ void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
 {
   myPlayFrame->setEnabled(false);
-  myAnimator->addField(VISU::GetSObject(theSObject));
+  myAnimator->addField(theSObject);
 }
 
 //************************************************************************
@@ -1187,14 +1249,14 @@ 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());
 }