5 changes: 5 additions & 0 deletions pyKst/demo/testdataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
client=kst.Client("TestPlugins")

v1 = client.new_generated_vector(0, 10, 10)
v4 = client.new_generated_vector(0, 20, 100)

e1 = client.new_equation(v1, "x^2")
e1.set_x(v4)
v2 = e1.Y()
v3 = e1.X()
print v2.name(), v2.value(3), v3.value(3)
15 changes: 15 additions & 0 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,21 @@ def __init__(self, client, xvector, equation, name="", new=True) :
else:
self.handle = name

def Y(self) :
""" a vector containing the equation """
vec = VectorBase(self.client)
vec.handle = self.client.send_si(self.handle, "outputVector(O)")
return vec

def X(self) :
""" a vector containing the x vector """
vec = VectorBase(self.client)
vec.handle = self.client.send_si(self.handle, "outputVector(XO)")
return vec

def set_x(self, xvector):
self.client.send_si(self.handle, "setInputVector(X,"+xvector.handle+")")

# FIT ###################################################################
class Fit(NamedObject) :
""" This is a class which provides some methods common to all fits """
Expand Down
5 changes: 5 additions & 0 deletions src/kst/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ int main(int argc, char *argv[]) {
QSettings& settings = Kst::createSettings("application");
if (settings.value("general/raster", false).toBool()) {
QApplication::setGraphicsSystem("raster");
} else {
// this must be actually set, since raster is now the
// default under linux. Native is strongly prefered
// for remote X, and raster mildly prefered otherwise.
QApplication::setGraphicsSystem("native");
}
#endif

Expand Down
19 changes: 9 additions & 10 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
// _fnMap.insert("newHistogram()",&ScriptServer::newHistogram);

_fnMap.insert("getPSDList()",&ScriptServer::getPSDList);
// _fnMap.insert("newPSD()",&ScriptServer::newPSD);
_fnMap.insert("newPSD()",&ScriptServer::newPSD);

_fnMap.insert("getPluginList()", &ScriptServer::getPluginList);
_fnMap.insert("newPlugin()",&ScriptServer::newPlugin);
Expand Down Expand Up @@ -616,17 +616,16 @@ QByteArray ScriptServer::getPSDList(QByteArray&, QLocalSocket* s,ObjectStore*_st
return outputObjectList<PSD>(s,_store);
}

/*
QByteArray ScriptServer::newPSD(QByteArray&, QLocalSocket* s,ObjectStore*,const int&ifMode,

if(_interface) {
return handleResponse("To access this function, first call endEdit()",s);
} else {
_interface = DialogLauncherSI::self->showPowerSpectrumDialog();
return handleResponse("Ok",s);
}
QByteArray ScriptServer::newPSD(QByteArray&, QLocalSocket* s,ObjectStore*) {

if(_interface) {
return handleResponse("To access this function, first call endEdit()",s);
} else {
_interface = SpectrumSI::newSpectrum(_store); return handleResponse("Ok",s);
}
}
*/


QByteArray ScriptServer::getPluginList(QByteArray&, QLocalSocket* s,ObjectStore*_store) {

Expand Down
2 changes: 1 addition & 1 deletion src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public slots:
//QByteArray newHistogram(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getPSDList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
//QByteArray newPSD(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newPSD(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getPluginList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newPlugin(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
Expand Down
1 change: 0 additions & 1 deletion src/libkstmath/dataobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ StringPtr DataObject::outputString(const QString& string) const {

void DataObject::setInputVector(const QString &type, VectorPtr ptr) {
if (ptr) {
qDebug() << " data object set input vector" << type << "to" << ptr->Name();
_inputVectors[type] = ptr;
} else {
_inputVectors.remove(type);
Expand Down
92 changes: 91 additions & 1 deletion src/libkstmath/dataobjectscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ QByteArray EquationSI::endEditUpdate() {
}

QString EquationSI::doCommand(QString command_in) {
qDebug() << "equation do command" << command_in;
if (isValid()) {

QString command = command_in.left(command_in.indexOf('('));
Expand Down Expand Up @@ -241,5 +240,96 @@ QString EquationSI::setEquation(QString& command) {
}


/***************************/
/* SpectrumSI */
/***************************/
SpectrumSI::SpectrumSI(PSDPtr psd) {
if (psd) {
_psd = psd;
_dataObject = psd;
} else {
_psd = 0;
_dataObject = 0;
}

_fnMap.insert("setInputVector",&SpectrumSI::setInputVector);
_fnMap.insert("setInputScalar",&SpectrumSI::setInputScalar);
_fnMap.insert("outputVector",&SpectrumSI::outputVector);
_fnMap.insert("outputScalar",&SpectrumSI::outputScalar);

}

bool SpectrumSI::isValid() {
return _psd;
}

QByteArray SpectrumSI::endEditUpdate() {
if (_psd) {
_psd->registerChange();
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();

return ("Finished editing "%_psd->Name()).toLatin1();
} else {
return ("Finished editing invalid spectrum");
}
}

QString SpectrumSI::doCommand(QString command_in) {
if (isValid()) {

QString command = command_in.left(command_in.indexOf('('));

SpectrumInterfaceMemberFn fn=_fnMap.value(command,&SpectrumSI::noSuchFn);

if(fn!=&SpectrumSI::noSuchFn) {
return CALL_MEMBER_FN(*this,fn)(command_in);
}


QString v=doNamedObjectCommand(command_in, _psd);
if (!v.isEmpty()) {
return v;
}

return "No such command";
} else {
return "Invalid";
}
}

ScriptInterface* SpectrumSI::newSpectrum(ObjectStore *store) {
PSDPtr psd = store->createObject<PSD>();

return new SpectrumSI(psd);
}


QString SpectrumSI::change(QString& command) {
/*
if (_psd) {
QStringList vars = getArgs(command);
_psd->change(vector,
sampleRate,
interleavedAverage,
FFTLength,
apodize,
removeMean,
vectorUnits,
rateUnits,
apodizeFunction,
sigma,
output,
interpolateOverHoles);
return "done";
} else {
return "Invalid";
}
*/
}


}
29 changes: 29 additions & 0 deletions src/libkstmath/dataobjectscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "scriptinterface.h"
#include "basicplugin.h"
#include "equation.h"
#include "psd.h"
#include "objectstore.h"
#include "updatemanager.h"
#include "updateserver.h"
Expand Down Expand Up @@ -97,5 +98,33 @@ class KSTMATH_EXPORT EquationSI : public DataObjectSI
};


class SpectrumSI;
typedef QString (SpectrumSI::*SpectrumInterfaceMemberFn)(QString& command);

class KSTMATH_EXPORT SpectrumSI : public DataObjectSI
{
Q_OBJECT
public:
explicit SpectrumSI(PSDPtr psd);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newSpectrum(ObjectStore *store);

protected:
QString noSuchFn(QString&) {return ""; }

private:
PSDPtr _psd;

QMap<QString,SpectrumInterfaceMemberFn> _fnMap;

QString change(QString &command);
//QString equation(QString &);
//QString setEquation(QString &eq);
};


}
#endif // DATAOBJECTSCRIPTINTERFACE_H
2 changes: 1 addition & 1 deletion src/libkstmath/equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void Equation::internalUpdate() {

writeLockInputsAndOutputs();

//_xInVector =
_xInVector = _inputVectors[XINVECTOR];
Equations::Context ctx;
ctx.sampleCount = _ns;
ctx.xVector = _xInVector;
Expand Down
8 changes: 8 additions & 0 deletions src/libkstmath/psd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "psdcalculator.h"
#include "objectstore.h"

#include "dataobjectscriptinterface.h"

extern "C" void rdft(int n, int isgn, double *a);

namespace Kst {
Expand Down Expand Up @@ -76,6 +78,12 @@ void PSD::_initializeShortName() {
_psdnum++;
}


ScriptInterface* PSD::createScriptInterface() {
return new SpectrumSI(this);
}


void PSD::change(VectorPtr in_V,
double in_freq, bool in_average, int in_averageLen, bool in_apodize,
bool in_removeMean, const QString& in_VUnits, const QString& in_RUnits,
Expand Down
2 changes: 2 additions & 0 deletions src/libkstmath/psd.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class KSTMATH_EXPORT PSD : public DataObject {

void setChanged() { _changed=true;}

virtual ScriptInterface* createScriptInterface();

protected:

PSD(ObjectStore *store);
Expand Down