[Kst] branches/work/kst/portto4/kst/src

Barth Netterfield netterfield at astro.utoronto.ca
Tue Jun 17 17:52:11 CEST 2008


SVN commit 821488 by netterfield:

Fix bugs in equation names (in particular, make scalar and vector 
references in equations dynamic).

Take Mike's advice on names, and rely more heavily on the short name.



 M  +11 -3     libkst/objectstore.cpp  
 M  +1 -1      libkstmath/enodes.cpp  
 M  +34 -3     libkstmath/equation.cpp  
 M  +2 -0      libkstmath/equation.h  


--- branches/work/kst/portto4/kst/src/libkst/objectstore.cpp #821487:821488
@@ -85,14 +85,22 @@
     return NULL;
   }
 
+  QString shortName;
+  QRegExp rx("(\\(|^)([A-Z]\\d+)(\\)$|$)");
+  //QRegExp rx("\\(([A-Z]\\d+)\\)$|^(\\d+)$");
+  rx.indexIn(name);
+  shortName = rx.cap(2);
+
+qDebug() << "---- short name retrieved: " << shortName << "from" << name;
+
   // 1) search for exact names
-  for (int i = 0; i < _list.size(); ++i) {
+/*  for (int i = 0; i < _list.size(); ++i) {
     if (_list.at(i)->Name()==name)
       return _list.at(i);
-  }
+  }*/
   // 2) search for short names
   for (int i = 0; i < _list.size(); ++i) {
-    if (_list.at(i)->shortName()==name) 
+    if (_list.at(i)->shortName()==shortName) 
       return _list.at(i);
   }
   // 3) search for descriptive names: must be unique
--- branches/work/kst/portto4/kst/src/libkstmath/enodes.cpp #821487:821488
@@ -795,7 +795,7 @@
   if (_isEquation) {
     return QString("[=") + _tagName + "]";
   } else if (_vector) {
-    return _vector->Name();
+    return QString("[") + _vector->Name() + QString("]");
   } else if (_scalar) {
     return _scalar->Name();
   } else {
--- branches/work/kst/portto4/kst/src/libkstmath/equation.cpp #821487:821488
@@ -180,7 +180,34 @@
   return rc;
 }
 
+const QString Equation::reparsedEquation() const {
+  QString etext;
 
+  qDebug() << "Equation: " << _equation << "\n";
+  if (!_equation.isEmpty()) {
+    if (!Equations::mutex().tryLock()) {
+      qDebug() << "Don't reparse equation while it is being reparsed...";
+      return (_equation);
+    }
+
+    yy_scan_string(_equation.toLatin1());
+    ParsedEquation = 0L;
+    int rc = yyparse(store());
+    Equations::Node *en = static_cast<Equations::Node*>(ParsedEquation);
+    if (rc == 0 && en) {
+      if (!en->takeVectors(VectorsUsed)) {
+        Debug::self()->log(i18n("Equation [%1] failed to find its vectors when reparsing.").arg(_equation), Debug::Warning);
+      }
+      etext = en->text();
+    }
+    delete en;
+    ParsedEquation = 0L;
+    Equations::mutex().unlock();
+  }
+  qDebug() << "reparsed Equation: " << etext << "\n";
+  return (etext);
+}
+
 void Equation::save(QXmlStreamWriter &s) {
   s.writeStartElement(staticTypeTag);
   // Reparse the equation, then write it back out in text so that we can update
@@ -213,6 +240,7 @@
 
 
 void Equation::setEquation(const QString& in_fn) {
+  qDebug() << "Enter setEquation\n";
   // assert(*_xVector); - ugly, we have to allow this here due to
   // document loading with vector lazy-loading
   setDirty();
@@ -227,7 +255,7 @@
   if (!_equation.isEmpty()) {
     Equations::mutex().lock();
     yy_scan_string(_equation.toLatin1());
-    int rc = yyparse(store());
+    int rc = yyparse(store()); 
     _pe = static_cast<Equations::Node*>(ParsedEquation);
     if (rc == 0 && _pe) {
       ParsedEquation = 0L;
@@ -245,7 +273,7 @@
         Debug::self()->log(i18n("Equation [%1] references non-existent objects.").arg(_equation), Debug::Error);
         delete (Equations::Node*)ParsedEquation;
         ParsedEquation = 0L;
-        Equations::mutex().unlock();
+        //Equations::mutex().unlock();
       }
     } else {
       // Parse error
@@ -262,6 +290,7 @@
   _isValid = _pe != 0L;
 
   if (_isValid) {
+    _equation = reparsedEquation(); // update the string
     foreach (VectorPtr vector, VectorsUsed) {
       connect(vector, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
     }
@@ -269,6 +298,8 @@
       connect(scalar, SIGNAL(scalarUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
     }
   }
+    qDebug() << "leave setEquation\n";
+
 }
 
 
@@ -580,7 +611,7 @@
 }
 
 QString Equation::_automaticDescriptiveName() const {
-  return equation();
+  return reparsedEquation();
 }
 
 QString Equation::descriptionTip() const {
--- branches/work/kst/portto4/kst/src/libkstmath/equation.h #821487:821488
@@ -56,6 +56,8 @@
     void setExistingXVector(VectorPtr xvector, bool do_interp);
 
     const QString& equation() const { return _equation; }
+    const QString reparsedEquation() const;
+
     VectorPtr vXIn() const { return _xInVector; }
     VectorPtr vX() const { return _xOutVector; }
     VectorPtr vY() const { return _yOutVector; }


More information about the Kst mailing list