Bug 145289 - Equations do not always update
Summary: Equations do not always update
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-11 00:32 UTC by Andrew Walker
Modified: 2007-07-04 01:36 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Walker 2007-05-11 00:32:54 UTC
Version:           1.4.0 (using KDE KDE 3.5.1)
Installed from:    Compiled From Sources
OS:                Linux

PROBLEM:

When a scalar is used in an equation and the scalar is later changed by the user the equation does not update to reflect the change.

STEPS TO REPRODUCE:

Start Kst
Select Data... New Vector...
Select Generate as the Source option, leave the other values at their default, and hit OK
Select Data... New Equation...
Click on the create scalar button and create a new scalar named 'two' and set its value to 2.0
Create a new equation '[two]*[vector]' where vector is the vector created earlier
Hit OK
Select Data... New Equation...
Click on the edit scalar button and change the value of 'two' from 2.0 to 5.0
Hit OK in the Edit Scalar dialog

RESULTS:
The curve does not update

EXPECTED RESULTS:
The curve should update to reflect the changed scalar value
Comment 1 Andrew Walker 2007-07-03 21:50:12 UTC
This is not a problem when the vector is read from file.
Comment 2 Andrew Walker 2007-07-04 01:21:02 UTC
The problem is directly caused by KstEquation::FillY(...) line 500:

  for (ctx.i = i0; ctx.i < _ns; ++ctx.i) {

as i0 and _ns are the same value for KstSVector but different for KstRVector. Thus, the equation is recalculated in the latter case, but not the former.

An effort is made to avoid recalculating the equation as much as possible, but for when using a KstRVector as the x-axis this optimisation is avoided - and so the equation is updated.

In the case of a KstSVector though the optimisation is utilised - and nothing is recalculated. This optimisation is incorrect as it ignores the possibility that a scalar in the equation may have been updated.
Comment 3 Andrew Walker 2007-07-04 01:36:06 UTC
SVN commit 683027 by arwalker:

BUG:145289 Ensure that equations always update by avoiding optimisation when necessary

 M  +9 -5      kstequation.cpp  
 M  +9 -12     kstequation.h  


--- branches/work/kst/1.5/kst/src/libkstmath/kstequation.cpp #683026:683027
@@ -219,7 +219,7 @@
 
   KstObject::UpdateType rc = NO_CHANGE; // if force, rc = UPDATE anyway.
   if (force || xUpdated || usedUpdated) {
-    _isValid = FillY(force);
+    _isValid = FillY(force, usedUpdated);
     rc = UPDATE;
   }
   v = *_yOutVector;
@@ -381,9 +381,10 @@
 /*                      Fill Y: Evaluates the equation                  */
 /*                                                                      */
 /************************************************************************/
-bool KstEquation::FillY(bool force) {
-  int v_shift=0, v_new;
-  int i0=0;
+bool KstEquation::FillY(bool force, bool usedUpdated) {
+  int v_shift = 0;
+  int v_new;
+  int i0 = 0;
   int ns;
 
   writeLockInputsAndOutputs();
@@ -409,7 +410,7 @@
     if (!xv->resize(_ns)) {
       // FIXME: handle error?
       unlockInputsAndOutputs();
-      return false;    
+      return false;
     }
     if (!yv->resize(_ns)) {
       // FIXME: handle error?
@@ -419,6 +420,9 @@
     yv->zero();
     i0 = 0; // other vectors may have diffent lengths, so start over
     v_shift = _ns;
+  } else if (usedUpdated) {
+    i0 = 0;
+    v_shift = _ns;
   } else {
     // calculate shift and new samples
     // only do shift optimization if all used vectors are same size and shift
--- branches/work/kst/1.5/kst/src/libkstmath/kstequation.h #683026:683027
@@ -67,9 +67,9 @@
     virtual QString yVTag() const { return (*_yOutVector)->tagName(); }
 
     const KstCurveHintList *curveHints() const;
-    
+
     virtual KstDataObjectPtr makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap);
-    
+
     virtual void replaceDependency(KstDataObjectPtr oldObject, KstDataObjectPtr newObject);
 
     virtual void replaceDependency(KstVectorPtr oldVector, KstVectorPtr newVector);
@@ -81,25 +81,22 @@
     void reParse();
 
   private:
-    QString _equation;
-
+    KstVectorMap::Iterator _xInVector, _xOutVector, _yOutVector;
+    Equation::Node *_pe;
     KstVectorMap VectorsUsed;
     KstScalarMap ScalarsUsed;
-    void setupConnections();
-
-    void commonConstructor(const QString& in_tag, const QString& equation);
-
-    bool FillY(bool force = false);
+    QString _equation;
     bool _isValid : 1;
     bool _doInterp : 1;
-
     int _numNew, _numShifted, _interp, _ns;
 
+    void setupConnections();
+    void commonConstructor(const QString& in_tag, const QString& equation);
+    bool FillY(bool force, bool usedUpdated);
+
     static const QString XINVECTOR;
     static const QString XOUTVECTOR;
     static const QString YOUTVECTOR;
-    KstVectorMap::Iterator _xInVector, _xOutVector, _yOutVector;
-    Equation::Node *_pe;
 };
 
 typedef KstSharedPtr<KstEquation> KstEquationPtr;