| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "matrixscriptinterface.h" | ||
|
|
||
| #include "objectstore.h" | ||
| #include "datasourcepluginmanager.h" | ||
| #include "updatemanager.h" | ||
| #include "updateserver.h" | ||
|
|
||
| #include <QStringBuilder> | ||
|
|
||
|
|
||
| namespace Kst { | ||
|
|
||
| QString doMatrixScriptCommand(QString command,Matrix *matrix) { | ||
|
|
||
| QString v=ScriptInterface::doNamedObjectCommand(command, matrix); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (command.startsWith("value(")) { | ||
| command.remove("value(").chop(1); | ||
| QStringList p = command.split(','); | ||
| return QString::number(matrix->value(p[0].toDouble(), p[1].toDouble())); | ||
| } else if (command.startsWith("length(")) { | ||
| return QString::number(matrix->sampleCount()); | ||
| } else if (command.startsWith("min(")) { | ||
| return QString::number(matrix->minValue()); | ||
| } else if (command.startsWith("max(")) { | ||
| return QString::number(matrix->maxValue()); | ||
| } else if (command.startsWith("mean(")) { | ||
| return QString::number(matrix->meanValue()); | ||
| } else if (command.startsWith("width(")) { | ||
| return QString::number(matrix->xNumSteps()); | ||
| } else if (command.startsWith("height(")) { | ||
| return QString::number(matrix->yNumSteps()); | ||
| } else if (command.startsWith("dX(")) { | ||
| return QString::number(matrix->xStepSize()); | ||
| } else if (command.startsWith("dY(")) { | ||
| return QString::number(matrix->yStepSize()); | ||
| } else if (command.startsWith("minX(")) { | ||
| return QString::number(matrix->minX()); | ||
| } else if (command.startsWith("minY(")) { | ||
| return QString::number(matrix->minY()); | ||
| } else if (command.startsWith("descriptionTip(")) { | ||
| return matrix->descriptionTip(); | ||
| } | ||
|
|
||
| return QString(); | ||
| } | ||
|
|
||
|
|
||
| /******************************************************/ | ||
| /* Data Matrixs */ | ||
| /******************************************************/ | ||
| MatrixDataSI::MatrixDataSI(DataMatrixPtr it) { | ||
| matrix=it; | ||
| } | ||
|
|
||
| QString MatrixDataSI::doCommand(QString command) { | ||
|
|
||
| QString v=doMatrixScriptCommand(command, matrix); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
|
|
||
| if (command.startsWith(QLatin1String("change("))) { | ||
| command.remove("change(").remove(')'); | ||
| QStringList p = command.split(','); | ||
| DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource( | ||
| matrix->store(), p.at(0)); | ||
|
|
||
| matrix->writeLock(); | ||
| matrix->change(ds, | ||
| p.at(1), // field | ||
| p.at(2).toInt(), // x start | ||
| p.at(3).toInt(), // y start | ||
| p.at(4).toInt(), // num x steps | ||
| p.at(5).toInt(), // num y steps | ||
|
|
||
| false, false, 0, | ||
|
|
||
| p.at(6).toDouble(), // min x | ||
| p.at(7).toDouble(), // min y | ||
| p.at(8).toDouble(), // step x | ||
| p.at(9).toDouble() // step y | ||
| ); | ||
| matrix->unlock(); | ||
| return "Done"; | ||
| } else if (command.startsWith("field(")) { | ||
| return matrix->field(); | ||
| } else if (command.startsWith("filename(")) { | ||
| return matrix->filename(); | ||
| } else if (command.startsWith("startX(")) { | ||
| return QString::number(matrix->reqXStart()); | ||
| } else if (command.startsWith("startY(")) { | ||
| return QString::number(matrix->reqYStart()); | ||
| } | ||
|
|
||
| return "No such command"; | ||
| } | ||
|
|
||
| bool MatrixDataSI::isValid() { | ||
| return matrix.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* MatrixDataSI::newMatrix(ObjectStore *store) { | ||
| DataMatrixPtr matrix; | ||
| matrix = store->createObject<DataMatrix>(); | ||
| return new MatrixDataSI(matrix); | ||
| } | ||
|
|
||
| QByteArray MatrixDataSI::endEditUpdate() { | ||
| matrix->registerChange(); | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+matrix->Name()).toLatin1(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "scalarscriptinterface.h" | ||
|
|
||
| #include "objectstore.h" | ||
| #include "datasourcepluginmanager.h" | ||
| #include "updatemanager.h" | ||
| #include "updateserver.h" | ||
|
|
||
| #include <QStringBuilder> | ||
|
|
||
|
|
||
| namespace Kst { | ||
|
|
||
| /******************************************************/ | ||
| /* Generated Scalars */ | ||
| /******************************************************/ | ||
| ScalarGenSI::ScalarGenSI(ScalarPtr it) { | ||
| scalar=it; | ||
| } | ||
|
|
||
| QString ScalarGenSI::doCommand(QString x) { | ||
|
|
||
| QString v=doNamedObjectCommand(x, scalar); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (x.startsWith(QLatin1String("setValue("))) { | ||
| scalar->writeLock(); | ||
| scalar->setValue(x.remove("setValue(").remove(')').toDouble()); | ||
| scalar->unlock(); | ||
| return "Done"; | ||
| } else if (x.startsWith(QLatin1String("value()"))) { | ||
| return QString::number(scalar->value()); | ||
| } | ||
| return "No such command"; | ||
| } | ||
|
|
||
| bool ScalarGenSI::isValid() { | ||
| return scalar.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* ScalarGenSI::newScalar(ObjectStore *store) { | ||
| ScalarPtr scalar; | ||
| scalar = store->createObject<Scalar>(); | ||
| scalar->setOrphan(true); | ||
| scalar->setEditable(true); | ||
| return new ScalarGenSI(scalar); | ||
| } | ||
|
|
||
| QByteArray ScalarGenSI::endEditUpdate() { | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+scalar->Name()).toLatin1(); | ||
| } | ||
|
|
||
| /******************************************************/ | ||
| /* Data Scalars */ | ||
| /******************************************************/ | ||
| ScalarDataSI::ScalarDataSI(DataScalarPtr it) { | ||
| scalar=it; | ||
| } | ||
|
|
||
| QString ScalarDataSI::doCommand(QString x) { | ||
|
|
||
| QString v=doNamedObjectCommand(x, scalar); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (x.startsWith(QLatin1String("change("))) { | ||
| x.remove("change(").remove(')'); | ||
| QStringList p = x.split(','); | ||
| DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource( | ||
| scalar->store(), p.at(0)); | ||
| scalar->writeLock(); | ||
| scalar->change(ds,p.at(1)); | ||
| scalar->unlock(); | ||
| return "Done"; | ||
| } else if (x.startsWith(QLatin1String("file()"))) { | ||
| return scalar->filename(); | ||
| } else if (x.startsWith(QLatin1String("field()"))) { | ||
| return scalar->field(); | ||
| } else if (x.startsWith(QLatin1String("value()"))) { | ||
| return QString::number(scalar->value()); | ||
| } | ||
| return "No such command"; | ||
| } | ||
|
|
||
| bool ScalarDataSI::isValid() { | ||
| return scalar.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* ScalarDataSI::newScalar(ObjectStore *store) { | ||
| DataScalarPtr scalar; | ||
| scalar = store->createObject<DataScalar>(); | ||
| return new ScalarDataSI(scalar); | ||
| } | ||
|
|
||
| QByteArray ScalarDataSI::endEditUpdate() { | ||
| scalar->registerChange(); | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+scalar->Name()).toLatin1(); | ||
| } | ||
|
|
||
| /******************************************************/ | ||
| /* Vector Scalars */ | ||
| /******************************************************/ | ||
| ScalarVectorSI::ScalarVectorSI(VScalarPtr it) { | ||
| scalar=it; | ||
| } | ||
|
|
||
| QString ScalarVectorSI::doCommand(QString x) { | ||
|
|
||
| QString v=doNamedObjectCommand(x, scalar); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (x.startsWith(QLatin1String("change("))) { | ||
| x.remove("change(").remove(')'); | ||
| QStringList p = x.split(','); | ||
| DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource( | ||
| scalar->store(), p.at(0)); | ||
| scalar->writeLock(); | ||
| scalar->change(ds,p.at(1), p.at(2).toInt()); | ||
| scalar->unlock(); | ||
| return "Done"; | ||
| } else if (x.startsWith(QLatin1String("value()"))) { | ||
| return QString::number(scalar->value()); | ||
| } else if (x.startsWith(QLatin1String("file()"))) { | ||
| return scalar->filename(); | ||
| } else if (x.startsWith(QLatin1String("field()"))) { | ||
| return scalar->field(); | ||
| } else if (x.startsWith(QLatin1String("frame()"))) { | ||
| return QString::number(scalar->F0()); | ||
| } | ||
| return "No such command"; | ||
| } | ||
|
|
||
| bool ScalarVectorSI::isValid() { | ||
| return scalar.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* ScalarVectorSI::newScalar(ObjectStore *store) { | ||
| VScalarPtr scalar; | ||
| scalar = store->createObject<VScalar>(); | ||
| return new ScalarVectorSI(scalar); | ||
| } | ||
|
|
||
| QByteArray ScalarVectorSI::endEditUpdate() { | ||
| scalar->registerChange(); | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+scalar->Name()).toLatin1(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef SCALARSCRIPTINTERFACE_H | ||
| #define SCALARSCRIPTINTERFACE_H | ||
|
|
||
| #include <QString> | ||
|
|
||
| #include "scriptinterface.h" | ||
| #include "datascalar.h" | ||
| #include "vscalar.h" | ||
|
|
||
| namespace Kst { | ||
|
|
||
| class KSTCORE_EXPORT ScalarGenSI : public ScriptInterface | ||
| { | ||
| Q_OBJECT | ||
| ScalarPtr scalar; | ||
| public: | ||
| explicit ScalarGenSI(ScalarPtr it); | ||
| QString doCommand(QString); | ||
| bool isValid(); | ||
| QByteArray endEditUpdate(); | ||
|
|
||
| static ScriptInterface* newScalar(ObjectStore *store); | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| class KSTCORE_EXPORT ScalarDataSI : public ScriptInterface | ||
| { | ||
| Q_OBJECT | ||
| DataScalarPtr scalar; | ||
| public: | ||
| explicit ScalarDataSI(DataScalarPtr it); | ||
| QString doCommand(QString); | ||
| bool isValid(); | ||
| QByteArray endEditUpdate(); | ||
|
|
||
| static ScriptInterface* newScalar(ObjectStore *store); | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| class KSTCORE_EXPORT ScalarVectorSI : public ScriptInterface | ||
| { | ||
| Q_OBJECT | ||
| VScalarPtr scalar; | ||
| public: | ||
| explicit ScalarVectorSI(VScalarPtr it); | ||
| QString doCommand(QString); | ||
| bool isValid(); | ||
| QByteArray endEditUpdate(); | ||
|
|
||
| static ScriptInterface* newScalar(ObjectStore *store); | ||
|
|
||
| }; | ||
|
|
||
| } | ||
| #endif // SCALARSCRIPTINTERFACE_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2011 Joshua Netterfield * | ||
| * joshua.netterfield@gmail.com * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "scriptinterface.h" | ||
|
|
||
| #include "namedobject.h" | ||
|
|
||
| #include <QStringList> | ||
|
|
||
| namespace Kst { | ||
|
|
||
| QString ScriptInterface::doNamedObjectCommand(QString command, NamedObject *n) { | ||
| if (command.startsWith("setName(")) { | ||
| command.remove("setName(").chop(1); | ||
| n->setDescriptiveName(command); | ||
| return QString("Done"); | ||
| } else if (command.startsWith("name(")) { | ||
| return n->Name(); | ||
| } | ||
|
|
||
| return QString(); | ||
| } | ||
|
|
||
| // convenience functions... for parsing commands. | ||
| QStringList ScriptInterface::getArgs(const QString &command) { | ||
| int i0 = command.indexOf('(')+1; | ||
| int i1 = command.lastIndexOf(')'); | ||
| int n = i1-i0; | ||
|
|
||
| QString x = command.mid(i0,n); | ||
| return x.split(','); | ||
| } | ||
|
|
||
| QString ScriptInterface::getArg(const QString &command) { | ||
| int i0 = command.indexOf('(')+1; | ||
| int i1 = command.lastIndexOf(')'); | ||
| int n = i1-i0; | ||
|
|
||
| QString x = command.mid(i0,n); | ||
| return x; | ||
|
|
||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "stringscriptinterface.h" | ||
|
|
||
| #include "objectstore.h" | ||
| #include "datasourcepluginmanager.h" | ||
| #include "updatemanager.h" | ||
| #include "updateserver.h" | ||
|
|
||
| #include <QStringBuilder> | ||
|
|
||
| namespace Kst { | ||
|
|
||
| StringGenSI::StringGenSI(StringPtr it) { | ||
| str=it; | ||
| } | ||
|
|
||
| QString StringGenSI::doCommand(QString x) { | ||
|
|
||
| QString v=doNamedObjectCommand(x, str); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (x.startsWith(QLatin1String("setValue("))) { | ||
| str->writeLock(); | ||
| str->setValue(x.remove("setValue(").remove(')')); | ||
| str->unlock(); | ||
| return "Done"; | ||
| } else if (x.startsWith(QLatin1String("value()"))) { | ||
| return str->value(); | ||
| } | ||
| return "No such command"; | ||
| } | ||
|
|
||
| bool StringGenSI::isValid() { | ||
| return str.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* StringGenSI::newString(ObjectStore *store) { | ||
| StringPtr string; | ||
| string = store->createObject<String>(); | ||
| string->setOrphan(true); | ||
| string->setEditable(true); | ||
| return new StringGenSI(string); | ||
| } | ||
|
|
||
| QByteArray StringGenSI::endEditUpdate() { | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+str->Name()).toLatin1(); | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| StringDataSI::StringDataSI(DataStringPtr it) { | ||
| str=it; | ||
| } | ||
|
|
||
| QString StringDataSI::doCommand(QString x) { | ||
|
|
||
| QString v=doNamedObjectCommand(x, str); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if(x.startsWith(QLatin1String("change("))) { | ||
| x.remove("change(").remove(')'); | ||
| QStringList p = x.split(','); | ||
| DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource( | ||
| str->store(), p.at(0)); | ||
| str->writeLock(); | ||
| str->change(ds,p.at(1)); | ||
| str->unlock(); | ||
| return "Done"; | ||
| } else if (x.startsWith(QLatin1String("value()"))) { | ||
| return str->value(); | ||
| } | ||
| return "No such command"; | ||
| } | ||
|
|
||
| bool StringDataSI::isValid() { | ||
| return str.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* StringDataSI::newString(ObjectStore *store) { | ||
| DataStringPtr string; | ||
| string = store->createObject<DataString>(); | ||
|
|
||
| return new StringDataSI(string); | ||
| } | ||
|
|
||
| QByteArray StringDataSI::endEditUpdate() { | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+str->Name()).toLatin1(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "vectorscriptinterface.h" | ||
|
|
||
| #include "objectstore.h" | ||
| #include "datasourcepluginmanager.h" | ||
| #include "updatemanager.h" | ||
| #include "updateserver.h" | ||
|
|
||
| #include <QStringBuilder> | ||
|
|
||
|
|
||
| namespace Kst { | ||
|
|
||
| QString doVectorScriptCommand(QString command,Vector *vector) { | ||
|
|
||
| QString v=ScriptInterface::doNamedObjectCommand(command, vector); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (command.startsWith("value(")) { | ||
| command.remove("value(").chop(1); | ||
| return QString::number(vector->value(command.toInt())); | ||
| } else if (command.startsWith("length(")) { | ||
| return QString::number(vector->length()); | ||
| } else if (command.startsWith("min(")) { | ||
| return QString::number(vector->min()); | ||
| } else if (command.startsWith("max(")) { | ||
| return QString::number(vector->max()); | ||
| } else if (command.startsWith("mean(")) { | ||
| return QString::number(vector->mean()); | ||
| } else if (command.startsWith("descriptionTip(")) { | ||
| return vector->descriptionTip(); | ||
| } | ||
|
|
||
| return QString(); | ||
| } | ||
|
|
||
|
|
||
| /******************************************************/ | ||
| /* Data Vectors */ | ||
| /******************************************************/ | ||
| VectorDataSI::VectorDataSI(DataVectorPtr it) { | ||
| vector=it; | ||
| } | ||
|
|
||
| QString VectorDataSI::doCommand(QString command) { | ||
|
|
||
| QString v=doVectorScriptCommand(command, vector); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (command.startsWith(QLatin1String("change("))) { | ||
| command.remove("change(").remove(')'); | ||
| QStringList p = command.split(','); | ||
| DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource( | ||
| vector->store(), p.at(0)); | ||
| vector->writeLock(); | ||
| vector->change(ds, | ||
| p.at(1), // field | ||
| p.at(2).toInt(), // f0 | ||
| p.at(3).toInt(), // n | ||
| p.at(4).toInt(), // skip | ||
| p.at(4).toInt() > 0, // do skip | ||
| p.at(5) == "True" // do average | ||
| ); | ||
| vector->unlock(); | ||
| return "Done"; | ||
| } else if (command.startsWith("field(")) { | ||
| return vector->field(); | ||
| } else if (command.startsWith("filename(")) { | ||
| return vector->filename(); | ||
| } else if (command.startsWith("start(")) { | ||
| return QString::number(vector->startFrame()); | ||
| } else if (command.startsWith("NFrames(")) { | ||
| return QString::number(vector->numFrames()); | ||
| } else if (command.startsWith("skip(")) { | ||
| return QString::number(vector->skip()); | ||
| } else if (command.startsWith("boxcarFirst(")) { | ||
| return vector->doAve()?"True":"False"; | ||
| } | ||
|
|
||
| return "No such command"; | ||
| } | ||
|
|
||
| bool VectorDataSI::isValid() { | ||
| return vector.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* VectorDataSI::newVector(ObjectStore *store) { | ||
| DataVectorPtr vector; | ||
| vector = store->createObject<DataVector>(); | ||
| return new VectorDataSI(vector); | ||
| } | ||
|
|
||
| QByteArray VectorDataSI::endEditUpdate() { | ||
| vector->registerChange(); | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+vector->Name()).toLatin1(); | ||
| } | ||
|
|
||
| /******************************************************/ | ||
| /* Generated Vectors */ | ||
| /******************************************************/ | ||
| VectorGenSI::VectorGenSI(GeneratedVectorPtr it) { | ||
| vector=it; | ||
| } | ||
|
|
||
| QString VectorGenSI::doCommand(QString command) { | ||
|
|
||
| QString v=doVectorScriptCommand(command, vector); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (command.startsWith(QLatin1String("change("))) { | ||
| command.remove("change(").remove(')'); | ||
| QStringList p = command.split(','); | ||
|
|
||
| vector->writeLock(); | ||
|
|
||
| vector->changeRange( | ||
| p.at(0).toDouble(), // start | ||
| p.at(1).toDouble(), // end | ||
| p.at(2).toInt() // number of points | ||
| ); | ||
| vector->unlock(); | ||
| return "Done"; | ||
| } | ||
|
|
||
| return "No such command"; | ||
| } | ||
|
|
||
| bool VectorGenSI::isValid() { | ||
| return vector.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* VectorGenSI::newVector(ObjectStore *store) { | ||
| GeneratedVectorPtr vector; | ||
| vector = store->createObject<GeneratedVector>(); | ||
| return new VectorGenSI(vector); | ||
| } | ||
|
|
||
| QByteArray VectorGenSI::endEditUpdate() { | ||
| vector->registerChange(); | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+vector->Name()).toLatin1(); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef VECTORSCRIPTINTERFACE_H | ||
| #define VECTORSCRIPTINTERFACE_H | ||
|
|
||
| #include <QString> | ||
|
|
||
| #include "scriptinterface.h" | ||
| #include "datavector.h" | ||
| #include "generatedvector.h" | ||
|
|
||
| namespace Kst { | ||
|
|
||
| class KSTCORE_EXPORT VectorDataSI : public ScriptInterface | ||
| { | ||
| Q_OBJECT | ||
| DataVectorPtr vector; | ||
| public: | ||
| explicit VectorDataSI(DataVectorPtr it); | ||
| QString doCommand(QString); | ||
| bool isValid(); | ||
| QByteArray endEditUpdate(); | ||
|
|
||
| static ScriptInterface* newVector(ObjectStore *store); | ||
| }; | ||
|
|
||
| class KSTCORE_EXPORT VectorGenSI : public ScriptInterface | ||
| { | ||
| Q_OBJECT | ||
| GeneratedVectorPtr vector; | ||
| public: | ||
| explicit VectorGenSI(GeneratedVectorPtr it); | ||
| QString doCommand(QString); | ||
| bool isValid(); | ||
| QByteArray endEditUpdate(); | ||
|
|
||
| static ScriptInterface* newVector(ObjectStore *store); | ||
| }; | ||
|
|
||
| } | ||
| #endif // VECTORSCRIPTINTERFACE_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "relationscriptinterface.h" | ||
|
|
||
| #include "objectstore.h" | ||
| #include "datasourcepluginmanager.h" | ||
| #include "updatemanager.h" | ||
| #include "updateserver.h" | ||
| #include "vector.h" | ||
| #include "colorsequence.h" | ||
|
|
||
| #include <QStringBuilder> | ||
|
|
||
|
|
||
| namespace Kst { | ||
|
|
||
| QString doRelationScriptCommand(QString command,Relation *relation) { | ||
|
|
||
| QString v=ScriptInterface::doNamedObjectCommand(command, relation); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| if (command.startsWith("maxX(")) { | ||
| return QString::number(relation->maxX()); | ||
| } // FIXME the rest... | ||
|
|
||
| return QString(); | ||
| } | ||
|
|
||
|
|
||
| /******************************************************/ | ||
| /* Curves */ | ||
| /******************************************************/ | ||
| CurveSI::CurveSI(CurvePtr it) { | ||
| curve=it; | ||
|
|
||
| _fnMap.insert("setXVector",&CurveSI::setXVector); | ||
| _fnMap.insert("setYVector",&CurveSI::setYVector); | ||
| _fnMap.insert("setXError",&CurveSI::setXError); | ||
| _fnMap.insert("setYError",&CurveSI::setYError); | ||
| _fnMap.insert("setXMinusError",&CurveSI::setXMinusError); | ||
| _fnMap.insert("setYMinusError",&CurveSI::setYMinusError); | ||
|
|
||
| _fnMap.insert("setColor",&CurveSI::setColor); | ||
| _fnMap.insert("setHeadColor",&CurveSI::setHeadColor); | ||
| _fnMap.insert("setBarFillColor",&CurveSI::setBarFillColor); | ||
| _fnMap.insert("setHasPoints",&CurveSI::setHasPoints); | ||
| _fnMap.insert("setHasLines",&CurveSI::setHasLines); | ||
| _fnMap.insert("setHasBars",&CurveSI::setHasBars); | ||
| _fnMap.insert("setHasHead",&CurveSI::setHasHead); | ||
|
|
||
| _fnMap.insert("setLineWidth",&CurveSI::setLineWidth); | ||
| _fnMap.insert("setPointSize",&CurveSI::setPointSize); | ||
|
|
||
| } | ||
|
|
||
| QString CurveSI::doCommand(QString command_in) { | ||
| QString command = command_in.left(command_in.indexOf('(')); | ||
|
|
||
| CurveInterfaceMemberFn fn=_fnMap.value(command,&CurveSI::noSuchFn); | ||
|
|
||
| if(fn!=&CurveSI::noSuchFn) { | ||
| return CALL_MEMBER_FN(*this,fn)(command_in); | ||
| } | ||
|
|
||
|
|
||
| QString v=doRelationScriptCommand(command_in, curve); | ||
| if (!v.isEmpty()) { | ||
| return v; | ||
| } | ||
|
|
||
| return "No such command"; | ||
| } | ||
|
|
||
| bool CurveSI::isValid() { | ||
| return curve.isPtrValid(); | ||
| } | ||
|
|
||
| ScriptInterface* CurveSI::newCurve(ObjectStore *store) { | ||
| CurvePtr curve; | ||
| curve = store->createObject<Curve>(); | ||
| curve->setColor(ColorSequence::self().next()); | ||
|
|
||
| return new CurveSI(curve); | ||
| } | ||
|
|
||
| QByteArray CurveSI::endEditUpdate() { | ||
| curve->registerChange(); | ||
| UpdateManager::self()->doUpdates(true); | ||
| UpdateServer::self()->requestUpdateSignal(); | ||
| return ("Finished editing "+curve->Name()).toLatin1(); | ||
| } | ||
|
|
||
| /***************************/ | ||
| /* commands */ | ||
| /***************************/ | ||
| QString CurveSI::setXVector(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| VectorPtr v = kst_cast<Vector>(curve->store()->retrieveObject(parameter)); | ||
| if (v) { | ||
| curve->setXVector(v); | ||
| return "Done"; | ||
| } else { | ||
| return QString("Vector %1 not found").arg(parameter); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| QString CurveSI::setYVector(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| VectorPtr v = kst_cast<Vector>(curve->store()->retrieveObject(parameter)); | ||
| if (v) { | ||
| curve->setYVector(v); | ||
| return "Done"; | ||
| } else { | ||
| return QString("Vector %1 not found").arg(parameter); | ||
| } | ||
| } | ||
|
|
||
| QString CurveSI::setXError(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| VectorPtr v = kst_cast<Vector>(curve->store()->retrieveObject(parameter)); | ||
| if (v) { | ||
| curve->setXError(v); | ||
| return "Done"; | ||
| } else { | ||
| return QString("Vector %1 not found").arg(parameter); | ||
| } | ||
| } | ||
|
|
||
| QString CurveSI::setYError(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| VectorPtr v = kst_cast<Vector>(curve->store()->retrieveObject(parameter)); | ||
| if (v) { | ||
| curve->setYError(v); | ||
| return "Done"; | ||
| } else { | ||
| return QString("Vector %1 not found").arg(parameter); | ||
| } | ||
| } | ||
|
|
||
| QString CurveSI::setXMinusError(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| VectorPtr v = kst_cast<Vector>(curve->store()->retrieveObject(parameter)); | ||
| if (v) { | ||
| curve->setXMinusError(v); | ||
| return "Done"; | ||
| } else { | ||
| return QString("Vector %1 not found").arg(parameter); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| QString CurveSI::setYMinusError(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| VectorPtr v = kst_cast<Vector>(curve->store()->retrieveObject(parameter)); | ||
| if (v) { | ||
| curve->setYMinusError(v); | ||
| return "Done"; | ||
| } else { | ||
| return QString("Vector %1 not found").arg(parameter); | ||
| } | ||
| } | ||
|
|
||
| QString CurveSI::setColor(QString& command) { | ||
| QString parameter = getArg(command); | ||
| curve->setColor(QColor(parameter)); | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setHeadColor(QString& command) { | ||
| QString parameter = getArg(command); | ||
| curve->setHeadColor(QColor(parameter)); | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setBarFillColor(QString& command) { | ||
| QString parameter = getArg(command); | ||
| curve->setBarFillColor(QColor(parameter)); | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setHasPoints(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| if (parameter.toLower() == "true") { | ||
| curve->setHasPoints(true); | ||
| } else { | ||
| curve->setHasPoints(false); | ||
| } | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setHasLines(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| if (parameter.toLower() == "true") { | ||
| curve->setHasLines(true); | ||
| } else { | ||
| curve->setHasLines(false); | ||
| } | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setHasBars(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| if (parameter.toLower() == "true") { | ||
| curve->setHasBars(true); | ||
| } else { | ||
| curve->setHasBars(false); | ||
| } | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setHasHead(QString& command) { | ||
| QString parameter = getArg(command); | ||
|
|
||
| if (parameter.toLower() == "true") { | ||
| curve->setHasHead(true); | ||
| } else { | ||
| curve->setHasHead(false); | ||
| } | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setLineWidth(QString& command) { | ||
| QString parameter = getArg(command); | ||
| int x = parameter.toInt(); | ||
|
|
||
| if (x<0) x = 0; | ||
| if (x>100) x = 100; | ||
|
|
||
| curve->setLineWidth(x); | ||
| return "Done"; | ||
| } | ||
|
|
||
| QString CurveSI::setPointSize(QString& command) { | ||
| QString parameter = getArg(command); | ||
| int x = parameter.toInt(); | ||
|
|
||
| if (x<0) x = 0; | ||
| if (x>100) x = 100; | ||
|
|
||
| curve->setPointSize(x); | ||
| return "Done"; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /*************************************************************************** | ||
| * * | ||
| * copyright : (C) 2014 Barth Netterfield * | ||
| * netterfield@astro.utoronto.ca * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef RELATIONSCRIPTINTERFACE_H | ||
| #define RELATIONSCRIPTINTERFACE_H | ||
|
|
||
| #include <QString> | ||
|
|
||
| #include "scriptinterface.h" | ||
| #include "curve.h" | ||
|
|
||
| namespace Kst { | ||
|
|
||
| class CurveSI; | ||
| typedef QString (CurveSI::*CurveInterfaceMemberFn)(QString& command); | ||
|
|
||
| class KSTMATH_EXPORT CurveSI : public ScriptInterface | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit CurveSI(CurvePtr it); | ||
| QString doCommand(QString); | ||
| bool isValid(); | ||
| QByteArray endEditUpdate(); | ||
|
|
||
| static ScriptInterface* newCurve(ObjectStore *store); | ||
|
|
||
| protected: | ||
| QString noSuchFn(QString&) {return ""; } | ||
|
|
||
| private: | ||
| CurvePtr curve; | ||
|
|
||
| QMap<QString,CurveInterfaceMemberFn> _fnMap; | ||
|
|
||
| QString setXVector(QString& command); | ||
| QString setYVector(QString& command); | ||
| QString setXError(QString& command); | ||
| QString setYError(QString& command); | ||
| QString setXMinusError(QString& command); | ||
| QString setYMinusError(QString& command); | ||
|
|
||
| QString setColor(QString& command); | ||
| QString setHeadColor(QString& command); | ||
| QString setBarFillColor(QString& command); | ||
| QString setHasPoints(QString& command); | ||
| QString setHasLines(QString& command); | ||
| QString setHasBars(QString& command); | ||
| QString setHasHead(QString& command); | ||
|
|
||
| QString setLineWidth(QString& command); | ||
| QString setPointSize(QString& command); | ||
|
|
||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif // RELATIONSCRIPTINTERFACE_H |