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

Adam Treat treat at kde.org
Fri Nov 17 01:10:22 CET 2006


SVN commit 605509 by treat:

* Add keys for eff_bandwidth and crosspowerspectrum plugins
* Don't use Basic Plugin desktop file for now
* Check the key for all plugins and reject if not uptodate
* Add fit util functions
* Convert linear unweighted fit to basic plugin
* Clean up common fit headers


 M  +1 -1      libkst/kstdataplugin.h  
 M  +62 -2     libkstmath/kstbasicplugin.cpp  
 M  +9 -0      libkstmath/kstbasicplugin.h  
 M  +9 -4      libkstmath/kstdataobject.cpp  
 M  +1 -1      plugins/crossspectrum/Makefile.am  
 M  +2 -0      plugins/crossspectrum/crosspowerspectrum.cpp  
 M  +2 -0      plugins/effective_bandwidth/effective_bandwidth.cpp  
 M  +1 -1      plugins/effective_bandwidth/kstobject_effbandwidth.desktop  
 M  +13 -13    plugins/fits/common.h  
 M  +36 -36    plugins/fits/linear.h  
 M  +7 -8      plugins/fits/linear_unweighted/Makefile.am  
 A             plugins/fits/linear_unweighted/kstobject_linear_unweighted.desktop  
 A             plugins/fits/linear_unweighted/linear_unweighted.cpp   [License: GPL (v2+)]
 A             plugins/fits/linear_unweighted/linear_unweighted.h   [License: GPL (v2+)]
 M  +1 -1      plugins/linefit/kstobject_linefit.desktop  
 M  +2 -0      plugins/testplugin/testplugin.cpp  


--- branches/work/kst/pluginify/kst/src/libkst/kstdataplugin.h #605508:605509
@@ -255,7 +255,6 @@
       }
   };
 
-#if 0
   class DataObjectPlugin : public Plugin {
     public:
       DataObjectPlugin(KService::Ptr svc) : Plugin(svc) {
@@ -270,6 +269,7 @@
       }
   };
 
+#if 0
   class BasicPlugin : public DataObjectPlugin {
     public:
       BasicPlugin(KService::Ptr svc) : DataObjectPlugin(svc) {
--- branches/work/kst/pluginify/kst/src/libkstmath/kstbasicplugin.cpp #605508:605509
@@ -31,12 +31,12 @@
 #include "kstdatacollection.h"
 
 KstBasicPlugin::KstBasicPlugin()
-: KstDataObject() {
+: KstDataObject(), _isFit(false) {
 }
 
 
 KstBasicPlugin::KstBasicPlugin(const QDomElement& e)
-: KstDataObject(e) {
+: KstDataObject(e), _isFit(false) {
 }
 
 
@@ -218,6 +218,8 @@
   //Perform update on the outputs
   updateOutput(updateCounter);
 
+  createFitScalars();
+
   return setLastUpdateResult(depUpdated ? UPDATE : NO_CHANGE);
 }
 
@@ -257,6 +259,64 @@
 }
 
 
+// FIXME: KstBasicPlugin should not know about fit scalars!!
+void KstBasicPlugin::createFitScalars() {
+  // Assumes that this is called with a write lock in place on this object
+  if (_isFit && _outputVectors.contains("Parameters")) {
+    KstVectorPtr vectorParam = _outputVectors["Parameters"];
+    if (vectorParam) {
+      QString paramName;
+      int i = 0;
+      int length = vectorParam->length();
+
+      for (paramName = parameterName(i);
+          !paramName.isEmpty() && i < length;
+           paramName = parameterName(++i)) {
+        double scalarValue = vectorParam->value(i);
+        if (!_outputScalars.contains(paramName)) {
+          QString scalarName = i18n("%1-%2").arg(tagName()).arg(paramName);
+          KstScalarPtr s = new KstScalar(scalarName, this, scalarValue);
+          s->KstObject::writeLock();
+          _outputScalars.insert(paramName, s);
+        } else {
+          _outputScalars[paramName]->setValue(scalarValue);
+        }
+      }
+    }
+  }
+}
+
+
+QString KstBasicPlugin::parameterName(int /*index*/) const {
+    return QString::null;
+}
+
+
+QString KstBasicPlugin::label(int precision) const {
+  QString label;
+
+  label = i18n("%1: %2").arg(name()).arg(tagName());
+  if ((outputVectors())["Parameters"]) {
+    QString strParamName;
+    QString strValue;
+    int length = (outputVectors())["Parameters"]->length();
+    int i = 0;
+
+    for (strParamName = parameterName(0);
+        !strParamName.isEmpty() && i < length;
+        strParamName = parameterName(++i)) {
+      KstScalarPtr scalar = outputScalars()[strParamName];
+      if (scalar) {
+        strValue = QString::number(scalar->value(), 'g', precision);
+        label += i18n("\n%1: %2").arg(strParamName).arg(strValue);
+      }
+    }
+  }
+
+  return label;
+}
+
+
 void KstBasicPlugin::save(QTextStream& ts, const QString& indent) {
   QString l2 = indent + "  ";
   //The plugin name _must_ be the same as the entry in the .desktop file
--- branches/work/kst/pluginify/kst/src/libkstmath/kstbasicplugin.h #605508:605509
@@ -81,6 +81,15 @@
     void load(const QDomElement &e);
     void save(QTextStream& ts, const QString& indent = QString::null);
 
+    bool isFit() const { return _isFit; }
+    // FIXME: remove this
+    void createFitScalars();
+    QString label(int precision) const;
+
+  protected:
+    virtual QString parameterName(int index) const;
+    bool _isFit;
+
   private:
     bool inputsExist() const;
     bool updateInput(int updateCounter, bool force) const;
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.cpp #605508:605509
@@ -32,6 +32,8 @@
 #include <klibloader.h>
 #include <kparts/componentfactory.h>
 
+#include "kstdataplugin.h"
+
 //#define LOCKTRACE
 
 KstDataObject::KstDataObject() : KstObject() {
@@ -95,7 +97,10 @@
   KstDataObject *object =
       KParts::ComponentFactory::createInstanceFromService<KstDataObject>(service, 0, "",
       QStringList(), &err);
-  if (object) {
+
+  KstSharedPtr<KST::Plugin> p = new KST::DataObjectPlugin(service);
+
+  if (object && p->key()) {
     const QString name = service->property("Name").toString();
     const QString description = service->property("Comment").toString();
     const QString author = service->property("X-Kst-Plugin-Author").toString();
@@ -110,11 +115,11 @@
     object->setLibrary(library);
 
     KstDebug::self()->log(i18n("Loaded data-object plugin %1.").arg(service->name()));
-  }
-  else {
+    return object;
+  } else {
     KstDebug::self()->log(i18n("Could't load data-object plugin %1.").arg(service->name()), KstDebug::Error);
+    return 0;
   }
-  return object;
 }
 
 
--- branches/work/kst/pluginify/kst/src/plugins/crossspectrum/Makefile.am #605508:605509
@@ -1,4 +1,4 @@
-INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/widgets -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstapp -I$(top_srcdir)/kst/src/libkstmath -I$(top_builddir)/kst -I$(top_builddir)/kst/src/widgets -I$(top_builddir)/kst/src/libkst -I$(top_builddir)/kst/src/libkstapp  -I$(top_builddir)/kst/src/libkstmath $(all_includes)
+INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/widgets -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstapp -I$(top_srcdir)/kst/src/libkstmath -I$(top_srcdir)/kst/src/extdate -I$(top_builddir)/kst -I$(top_builddir)/kst/src/widgets -I$(top_builddir)/kst/src/libkst -I$(top_builddir)/kst/src/libkstapp -I$(top_builddir)/kst/src/libkstmath -I$(top_builddir)/kst/src/extdate $(all_includes)
 
 kde_module_LTLIBRARIES=kstobject_crossspectrum.la
 
--- branches/work/kst/pluginify/kst/src/plugins/crossspectrum/crosspowerspectrum.cpp #605508:605509
@@ -41,6 +41,8 @@
 static const QString& IMAGINARY = KGlobal::staticQString("Cross Spectrum: Imaginary");
 static const QString& FREQUENCY = KGlobal::staticQString("Frequency");
 
+KST_KEY_DATAOBJECT_PLUGIN( crossspectrum )
+
 K_EXPORT_COMPONENT_FACTORY( kstobject_crossspectrum,
     KGenericFactory<CrossPowerSpectrum>( "kstobject_crossspectrum" ) )
 
--- branches/work/kst/pluginify/kst/src/plugins/effective_bandwidth/effective_bandwidth.cpp #605508:605509
@@ -31,6 +31,8 @@
 static const QString& SIGMA = KGlobal::staticQString("White Noise Sigma");
 static const QString& EFF_BANDWIDTH = KGlobal::staticQString("Effective Bandwidth");
 
+KST_KEY_DATAOBJECT_PLUGIN( effbandwidth )
+
 K_EXPORT_COMPONENT_FACTORY( kstobject_effbandwidth,
     KGenericFactory<EffBandwidth>( "kstobject_effbandwidth" ) )
 
--- branches/work/kst/pluginify/kst/src/plugins/effective_bandwidth/kstobject_effbandwidth.desktop #605508:605509
@@ -1,7 +1,7 @@
 [Desktop Entry]
 Encoding=UTF-8
 Type=Service
-ServiceTypes=Kst Basic Plugin
+ServiceTypes=Kst Data Object
 X-KDE-ModuleType=Plugin
 X-KDE-Library=kstobject_effbandwidth
 X-Kst-Plugin-Author=Duncan Hanson
--- branches/work/kst/pluginify/kst/src/plugins/fits/common.h #605508:605509
@@ -18,14 +18,14 @@
 #include <string.h>
 #include <math.h>
 
-#define XVALUES			0
-#define YVALUES			1
-#define WEIGHTS	    2
+#define XVALUES 0
+#define YVALUES 1
+#define WEIGHTS 2
 
-#define	YFIT				0
-#define YRESIDUALS	1
-#define PARAMETERS	2
-#define COVARIANCE	3
+#define YFIT        0
+#define YRESIDUALS  1
+#define PARAMETERS  2
+#define COVARIANCE  3
 #define Y_LOW_VALS  4
 #define Y_HGH_VALS  5
 #define MAX_OUT     6
@@ -39,7 +39,7 @@
   double fj;
   double fdj;
   int j;
-  
+
   if (iLengthDesired == iLengthActual) {
     value =  pArray[iIndex];
   } else {
@@ -48,7 +48,7 @@
     fdj   = fj - (double)j;
     value = pArray[j+1] * fdj + pArray[j+0] * (1.0 - fdj);
   }
-  
+
   return value;
 }
 
@@ -78,7 +78,7 @@
   bool bRetVal = false;
   int  iNumCovar = ( iNumParams * ( iNumParams + 1 ) ) / 2;
   int  i;
-  
+
   pInputs[XVALUES] = 0L;
   pInputs[YVALUES] = 0L;
   pInputs[WEIGHTS] = 0L;
@@ -122,7 +122,7 @@
         }
       }
     }
-    
+
     if( *piLength > iNumParams + 1 ) {
       alloc( outArrays, outArrayLens, pResult, YFIT, *piLength );
       alloc( outArrays, outArrayLens, pResult, YRESIDUALS, *piLength );
@@ -153,7 +153,7 @@
       }
     }
   }
-  
+
   return bRetVal;
 }
 
@@ -175,5 +175,5 @@
         pInputs[WEIGHTS] != 0L ) {
       free( pInputs[WEIGHTS] );
     }
-  }  
+  }
 }
--- branches/work/kst/pluginify/kst/src/plugins/fits/linear.h #605508:605509
@@ -10,20 +10,20 @@
 double calculate_matrix_entry( double dX, int iPos );
 
 extern "C" int kstfit_linear_unweighted(
-  const double *const inArrays[], 
+  const double *const inArrays[],
   const int inArrayLens[],
   double *outArrays[], int outArrayLens[],
   double outScalars[], int iNumParams);
 
 int kstfit_linear_unweighted(
-  const double *const inArrays[], 
+  const double *const inArrays[],
   const int inArrayLens[],
-	double *outArrays[], int outArrayLens[],
-	double outScalars[], int iNumParams)
+    double *outArrays[], int outArrayLens[],
+    double outScalars[], int iNumParams)
 {
-  gsl_matrix*	pMatrixX = NULL;
+  gsl_matrix* pMatrixX = NULL;
   gsl_matrix* pMatrixCovariance = NULL;
-  gsl_vector*	pVectorY = NULL;
+  gsl_vector* pVectorY = NULL;
   gsl_vector* pVectorParameters = NULL;
   gsl_multifit_linear_workspace* pWork = NULL;
   double dXInterpolated;
@@ -33,16 +33,16 @@
   double dChiSq = 0.0;
   int i = 0;
   int j;
-  int	iStatus = 0;
-  int	iLength;
+  int iStatus = 0;
+  int iLength;
   int iReturn = -1;
-  
+
   if (inArrayLens[YVALUES] >= 2 && inArrayLens[XVALUES] >= 2) {
     iLength = inArrayLens[YVALUES];
     if( inArrayLens[XVALUES] > iLength ) {
       iLength = inArrayLens[XVALUES];
     }
-        
+
     //
     // first do some sanity checks...
     //
@@ -58,7 +58,7 @@
           pResult[i] = outArrays[i];
         }
       }
-      
+
       //
       // now the output parameter array...
       //
@@ -69,7 +69,7 @@
           pResult[i] = outArrays[i];
         }
       }
-      
+
       //
       // now the covariance matrix...
       //
@@ -79,26 +79,26 @@
         } else {
           pResult[i] = outArrays[i];
         }
-      }      
-      
+      }
+
       if( pResult[0] != NULL && 
           pResult[1] != NULL && 
           pResult[2] != NULL && 
           pResult[3] != NULL )
      {
         for( i=0; i<2; i++ ) {
-          outArrays[i] 		= pResult[i];
+          outArrays[i]    = pResult[i];
           outArrayLens[i] = iLength;
         }
         for( ; i<3; i++ ) {
-          outArrays[i] 		= pResult[i];
+          outArrays[i]    = pResult[i];
           outArrayLens[i] = iNumParams;
         }
         for( ; i<4; i++ ) {
-          outArrays[i] 		= pResult[i];
+          outArrays[i]    = pResult[i];
           outArrayLens[i] = iNumParams * iNumParams;
         }
-        
+
         //
         // create the matrices and vectors...
         //
@@ -112,7 +112,7 @@
               if( pMatrixCovariance != NULL ) {
                 pWork = gsl_multifit_linear_alloc( iLength, iNumParams );
                 if( pWork != NULL ) {
-                  
+
                   //
                   // fill in the matrices and vectors...
                   //
@@ -124,13 +124,13 @@
                       gsl_matrix_set( pMatrixX, i, j, dX );
                     }
                   }
-                  
-                  
-                  iStatus = gsl_multifit_linear( pMatrixX, 
-                                                 pVectorY, 
-                                                 pVectorParameters, 
-                                                 pMatrixCovariance, 
-                                                 &dChiSq, 
+
+
+                  iStatus = gsl_multifit_linear( pMatrixX,
+                                                 pVectorY,
+                                                 pVectorParameters,
+                                                 pMatrixCovariance,
+                                                 &dChiSq,
                                                  pWork );
                   if( iStatus == 0 ) {
                     //
@@ -139,38 +139,38 @@
                     for( i=0; i<iLength; i++ ) {
                       dY = 0.0;
                       for( j=0; j<iNumParams; j++ ) {
-                        dY += gsl_matrix_get( pMatrixX, i, j ) * 
+                        dY += gsl_matrix_get( pMatrixX, i, j ) *
                               gsl_vector_get( pVectorParameters, j );
                       }
                       outArrays[YFIT][i] = dY;
                       outArrays[YRESIDUALS][i] = interpolate(i, iLength, inArrays[YVALUES], inArrayLens[YVALUES]) - dY;
                     }
-                    
+
                     for( i=0; i<iNumParams; i++ ) {
                       outArrays[PARAMETERS][i] = gsl_vector_get( pVectorParameters, i );
                       for( j=0; j<iNumParams; j++ ) {
                         outArrays[COVARIANCE][(i*iNumParams)+j] = gsl_matrix_get( pMatrixCovariance, i, j );
                       }
                     }
-                    
+
                     outScalars[0] = dChiSq / ( (double)iLength - (double)iNumParams );
-                    
+
                     iReturn = 0;
                   }
-                  
+
                   gsl_multifit_linear_free( pWork );
                 }
-                gsl_matrix_free( pMatrixCovariance );          
+                gsl_matrix_free( pMatrixCovariance );
               }
-              gsl_vector_free( pVectorParameters );          
+              gsl_vector_free( pVectorParameters );
             }
-            gsl_vector_free( pVectorY );          
+            gsl_vector_free( pVectorY );
           }
-          gsl_matrix_free( pMatrixX );          
+          gsl_matrix_free( pMatrixX );
         }
       }
     }
   }
-  
+
   return iReturn;
 }
--- branches/work/kst/pluginify/kst/src/plugins/fits/linear_unweighted/Makefile.am #605508:605509
@@ -1,12 +1,11 @@
-installdir=$(kde_moduledir)/kstplugins
-INCLUDES=-I$(srcdir)/../../../kst $(all_includes)
+INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstmath $(all_includes)
 
-install_LTLIBRARIES = kstfit_linear_unweighted.la
+kde_module_LTLIBRARIES=kstobject_linear_unweighted.la
 
-kstfit_linear_unweighted_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
-kstfit_linear_unweighted_la_LIBADD = $(GSL_LIBS)
-kstfit_linear_unweighted_la_SOURCES = kstfit_linear_unweighted.cpp
+kstobject_linear_unweighted_la_LDFLAGS=$(all_libraries) -module -avoid-version
+kstobject_linear_unweighted_la_SOURCES=linear_unweighted.cpp
 
-METASOURCES=AUTO
+services_DATA=kstobject_linear_unweighted.desktop
+servicesdir=$(kde_servicesdir)/kst
 
-install_DATA=kstfit_linear_unweighted.xml
+METASOURCES=AUTO
--- branches/work/kst/pluginify/kst/src/plugins/linefit/kstobject_linefit.desktop #605508:605509
@@ -1,7 +1,7 @@
 [Desktop Entry]
 Encoding=UTF-8
 Type=Service
-ServiceTypes=Kst Basic Plugin
+ServiceTypes=Kst Data Object
 X-KDE-ModuleType=Plugin
 X-KDE-Library=kstobject_linefit
 X-Kst-Plugin-Author=George Staikos
--- branches/work/kst/pluginify/kst/src/plugins/testplugin/testplugin.cpp #605508:605509
@@ -25,6 +25,8 @@
 static const QString& SCALAR_OUT = KGlobal::staticQString("Scalar Out");
 static const QString& STRING_OUT = KGlobal::staticQString("String Out");
 
+KST_KEY_DATAOBJECT_PLUGIN( testplugin )
+
 K_EXPORT_COMPONENT_FACTORY( kstobject_testplugin,
     KGenericFactory<TestPlugin>( "kstobject_testplugin" ) )
 


More information about the Kst mailing list