[Kst] extragear/graphics/kst/src/libkstmath

Eli Fidler eli at staikos.net
Wed Mar 14 16:20:06 CET 2007


SVN commit 642505 by fidler:

fix equations for bug 142622

update scalar references in addition to vector references


 M  +27 -13    enodes.cpp  
 M  +5 -5      enodes.h  
 M  +10 -6     kstequation.cpp  


--- trunk/extragear/graphics/kst/src/libkstmath/enodes.cpp #642504:642505
@@ -107,7 +107,7 @@
 }
 
 
-bool Node::takeVectors(const KstVectorMap&) {
+bool Node::takeVectorsAndScalars(const KstVectorMap&, const KstScalarMap&) {
   return true;
 }
 
@@ -146,9 +146,9 @@
 }
 
 
-bool BinaryNode::takeVectors(const KstVectorMap& c) {
-  bool rc = _left->takeVectors(c);
-  rc = _right->takeVectors(c) && rc;
+bool BinaryNode::takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm) {
+  bool rc = _left->takeVectorsAndScalars(vm, sm);
+  rc = _right->takeVectorsAndScalars(vm, sm) && rc;
   return rc;
 }
 
@@ -618,8 +618,8 @@
 }
 
 
-bool Function::takeVectors(const KstVectorMap& c) {
-  return _args->takeVectors(c);
+bool Function::takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm) {
+  return _args->takeVectorsAndScalars(vm, sm);
 }
 
 
@@ -673,10 +673,10 @@
 }
 
 
-bool ArgumentList::takeVectors(const KstVectorMap& c) {
+bool ArgumentList::takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm) {
   bool rc = true;
   for (Node *i = _args.first(); i; i = _args.next()) {
-    rc = i->takeVectors(c) && rc;
+    rc = i->takeVectorsAndScalars(vm, sm) && rc;
   }
   return rc;
 }
@@ -887,19 +887,33 @@
 }
 
 
-bool Data::takeVectors(const KstVectorMap& c) {
+bool Data::takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm) {
   if (_isEquation) {
     if (_equation) {
-      return _equation->takeVectors(c);
+      return _equation->takeVectorsAndScalars(vm, sm);
     }
     return false;
   }
-  if (!_scalar) {
-    if (c.contains(_tagName)) {
-      _vector = c[_tagName];
+  if (_vector) {
+    if (vm.contains(_tagName)) {
+      _vector = vm[_tagName];
     } else {
       return false;
     }
+  } else if (_scalar) {
+    if (sm.contains(_tagName)) {
+      _scalar = sm[_tagName];
+    } else {
+      return false;
+    }
+  } else {
+    if (vm.contains(_tagName)) {
+      _vector = vm[_tagName];
+    } else if (sm.contains(_tagName)) {
+      _scalar = sm[_tagName];
+    } else {
+      return false;
+    }
   }
   return true;
 }
--- trunk/extragear/graphics/kst/src/libkstmath/enodes.h #642504:642505
@@ -58,7 +58,7 @@
 
       virtual bool isConst() = 0; // can't be const
       virtual bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
-      virtual bool takeVectors(const KstVectorMap& c);
+      virtual bool takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm);
       virtual double value(Context*) = 0;
       virtual void visit(NodeVisitor*);
       virtual KstObject::UpdateType update(int counter, Context *ctx);
@@ -76,7 +76,7 @@
       virtual ~BinaryNode();
 
       virtual bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
-      virtual bool takeVectors(const KstVectorMap& c);
+      virtual bool takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm);
       virtual void visit(NodeVisitor*);
       virtual KstObject::UpdateType update(int counter, Context *ctx);
 
@@ -103,7 +103,7 @@
 
       bool isConst();
       bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
-      bool takeVectors(const KstVectorMap& c);
+      bool takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm);
       double at(int, Context*);
       Node *node(int idx);
       KstObject::UpdateType update(int counter, Context *ctx);
@@ -125,7 +125,7 @@
       bool isConst();
       double value(Context*);
       bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
-      bool takeVectors(const KstVectorMap& c);
+      bool takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm);
       KstObject::UpdateType update(int counter, Context *ctx);
       QString text() const;
 
@@ -187,7 +187,7 @@
       bool isConst();
       double value(Context*);
       bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
-      bool takeVectors(const KstVectorMap& c);
+      bool takeVectorsAndScalars(const KstVectorMap& vm, const KstScalarMap& sm);
       KstObject::UpdateType update(int counter, Context *ctx);
       QString text() const;
 
--- trunk/extragear/graphics/kst/src/libkstmath/kstequation.cpp #642504:642505
@@ -240,10 +240,11 @@
     int rc = yyparse();
     Equation::Node *en = static_cast<Equation::Node*>(ParsedEquation);
     if (rc == 0 && en) {
-      if (!en->takeVectors(VectorsUsed)) {
-        kstdWarning() << "Equation [" << _equation << "] failed to find its vectors when re-parsing." << endl;
+      if (en->takeVectorsAndScalars(VectorsUsed, ScalarsUsed)) {
+        _equation = en->text();
+      } else {
+        kstdWarning() << "Equation [" << _equation << "] failed to find its vectors/scalars when re-parsing." << endl;
       }
-      _equation = en->text();
     }
     delete en;
     ParsedEquation = 0L;
@@ -266,10 +267,13 @@
     int rc = yyparse();
     Equation::Node *en = static_cast<Equation::Node*>(ParsedEquation);
     if (rc == 0 && en) {
-      if (!en->takeVectors(VectorsUsed)) {
-        KstDebug::self()->log(i18n("Equation [%1] failed to find its vectors when saving.  Resulting Kst file may have issues.").arg(_equation), KstDebug::Warning);
+      QString etext;
+      if (en->takeVectorsAndScalars(VectorsUsed, ScalarsUsed)) {
+        etext = en->text();
+      } else {
+        kstdWarning() << "Equation [" << _equation << "] failed to find its vectors/scalars when saving. The resulting Kst file may have issues." << endl;
+        etext = _equation;
       }
-      QString etext = en->text();
       ts << l2 << "<equation>" << QStyleSheet::escape(etext) << "</equation>" << endl;
     }
     delete en;


More information about the Kst mailing list