[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Thu Oct 21 20:33:52 CEST 2004


CVS commit by staikos: 

fix several of the broken/unimplemented portions of plugin calling from
equations


  M +47 -28    enodes.cpp   1.22
  M +2 -0      enodes.h   1.15


--- kdeextragear-2/kst/kst/enodes.cpp  #1.21:1.22
@@ -17,4 +17,5 @@
 
 #include <kdebug.h>
+#include <klocale.h>
 #include <math.h>
 //#include <stdio.h>
@@ -25,4 +26,5 @@
 #include "enodes.h"
 #include "kstdatacollection.h"
+#include "kstdebug.h"
 #include "kstmath.h"
 #include "plugincollection.h"
@@ -263,4 +265,6 @@ Function::Function(char *name, ArgumentL
   _inArrayLens = 0L;
   _outArrayLens = 0L;
+  _outputIndex = -424242;
+  _localData = 0L;
   //printf("%p: New Function: %s - %p\n", (void*)this, name, (void*)args);
   if (strcasecmp("plugin", name) == 0) {
@@ -304,5 +308,5 @@ Function::~Function() {
   delete[] _inVectors;
   delete[] _outScalars;
-  for (int i = 0; i < _outputVectorCnt; ++i) {
+  for (uint i = 0; i < _outputVectorCnt; ++i) {
     delete[] _outVectors[i];
   }
@@ -310,4 +314,8 @@ Function::~Function() {
   delete[] _inArrayLens;
   delete[] _outArrayLens;
+  if (_localData) {
+    free(_localData);
+    _localData = 0L;
+  }
 }
 
@@ -327,6 +335,8 @@ double Function::evaluatePlugin(Context 
           _inVectors[vitcnt] = d->_vector->value();
           _inArrayLens[vitcnt++] = d->_vector->length();
-        } else { // Crashes the plugin in most cases (FIXME)
-          _inVectors[vitcnt++] = 0L;
+        } else {
+          _outputIndex = -424242;
+          KstDebug::self()->log(i18n("Plugin %2 failed when called from equation.  Argument %1 was not found.").arg(cnt + 1).arg(_plugin->data()._name), KstDebug::Warning);
+          return ctx->noPoint;
         }
         ++cnt;
@@ -342,21 +352,18 @@ double Function::evaluatePlugin(Context 
     int rc;
     if (_plugin->data()._localdata) {
-      // FIXME
-      //rc = _plugin->call(inVectors,  inArrayLens,  inScalars,
-      //                   outVectors, outArrayLens, outScalars, &_localData);
+      rc = _plugin->call(_inVectors, _inArrayLens, _inScalars, _outVectors, _outArrayLens, _outScalars, &_localData);
     } else {
       rc = _plugin->call(_inVectors, _inArrayLens, _inScalars, _outVectors, _outArrayLens, _outScalars);
     }
 
+    _outputIndex = -424242;
     if (rc != 0) {
-      // FIXME: make state inconsistent
+      KstDebug::self()->log(i18n("Plugin %1 failed when called from equation.").arg(_plugin->data()._name), KstDebug::Warning);
       return ctx->noPoint;
     }
-  }
 
   if (!_plugin->data()._filterOutputVector.isEmpty()) {
     int loc = 0;
     bool found = false;
-    // FIXME: cache this for efficiency
     const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
     for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
@@ -370,15 +377,27 @@ double Function::evaluatePlugin(Context 
     }
     if (found) {
-      return ::interpolate(_outVectors[loc], _outArrayLens[loc], ctx->i, ctx->sampleCount);
+        _outputIndex = loc;
     }
   }
   
+    if (_outputIndex == -424242) {
   if (_outputVectorCnt > 0) {
     if (_outVectors[0] && _outArrayLens[0] > 1) {
-      return ::interpolate(_outVectors[0], _outArrayLens[0], ctx->i, ctx->sampleCount);
+          _outputIndex = 0;
     }
   } else if (_outputScalarCnt > 0 && _outScalars) { // make sense?
-    return _outScalars[0];
+          _outputIndex = -1;
+      }
   }
+  }
+
+  if (_outputIndex >= 0) {
+    return ::interpolate(_outVectors[_outputIndex], _outArrayLens[_outputIndex], ctx->i, ctx->sampleCount);
+  } else if (_outputIndex == -424242) {
+    return ctx->noPoint;
+  } else { // make sense?
+    return _outScalars[abs(_outputIndex) - 1];
+  }
+  
   return ctx->noPoint;
 }

--- kdeextragear-2/kst/kst/enodes.h  #1.14:1.15
@@ -111,4 +111,6 @@ namespace Equation {
       double *_inScalars, *_outScalars;
       double **_inVectors, **_outVectors;
+      int _outputIndex; // -1 = scalar 0, -424242 = none/error, +0...n = vector
+      void *_localData;
   };
  





More information about the Kst mailing list