Revision: 1255
http://scidavis.svn.sourceforge.net/scidavis/?rev=1255&view=rev
Author: knut_f
Date: 2009-09-13 15:39:46 +0000 (Sun, 13 Sep 2009)
Log Message:
-----------
- Applied patch by markc (quantumeer) fixing analysis operations on data where X
values are not monotonically increasing. Closes bug #2831634.
- Did some related code cleanup and fixed code duplication between
Filter::sortedCurveData() and Interpolation::sortedCurveData().
- Removed lots of unused files, which were either obsolete, redundant copies in
src/future or future code not yet being used. This should make it somewhat
easier for people to grasp the current code base.
Modified Paths:
--------------
branches/current_stable/scidavis/sourcefiles.pri
branches/current_stable/scidavis/src/Filter.cpp
branches/current_stable/scidavis/src/Filter.h
branches/current_stable/scidavis/src/Interpolation.cpp
branches/current_stable/scidavis/src/Interpolation.h
branches/current_stable/scidavis/src/Table.cpp
branches/current_stable/scidavis/src/future/core/AbstractColumn.h
branches/current_stable/scidavis/src/future/core/Project.cpp
branches/current_stable/scidavis/src/future/matrix/MatrixView.h
branches/current_stable/scidavis/src/future/matrix/future_Matrix.cpp
branches/current_stable/scidavis/src/future/table/future_Table.cpp
branches/current_stable/scidavis/src/scidavis.sip
Removed Paths:
-------------
branches/current_stable/scidavis/src/SortDialog.cpp
branches/current_stable/scidavis/src/SortDialog.h
branches/current_stable/scidavis/src/future/core/AbstractExportFilter.h
branches/current_stable/scidavis/src/future/core/AbstractFit.cpp
branches/current_stable/scidavis/src/future/core/AbstractFit.h
branches/current_stable/scidavis/src/future/core/AbstractScript.cpp
branches/current_stable/scidavis/src/future/core/AbstractScript.h
branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.cpp
branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.h
branches/current_stable/scidavis/src/future/core/CopyThroughFilter.h
branches/current_stable/scidavis/src/future/core/Filter.cpp
branches/current_stable/scidavis/src/future/core/Filter.h
branches/current_stable/scidavis/src/future/core/FilterDialog.cpp
branches/current_stable/scidavis/src/future/core/FilterDialog.h
branches/current_stable/scidavis/src/future/core/MyParser.cpp
branches/current_stable/scidavis/src/future/core/MyParser.h
branches/current_stable/scidavis/src/future/core/ScriptEdit.cpp
branches/current_stable/scidavis/src/future/core/ScriptEdit.h
branches/current_stable/scidavis/src/future/core/ScriptingEngineManager.cpp
branches/current_stable/scidavis/src/future/core/ScriptingEngineManager.h
branches/current_stable/scidavis/src/future/core/ScriptingLangDialog.cpp
branches/current_stable/scidavis/src/future/core/ScriptingLangDialog.h
branches/current_stable/scidavis/src/future/core/core.pro
branches/current_stable/scidavis/src/future/core/customevents.h
branches/current_stable/scidavis/src/future/core/globals.h
branches/current_stable/scidavis/src/future/matrix/MatrixConfigPage.ui
branches/current_stable/scidavis/src/future/matrix/MatrixModule.cpp
branches/current_stable/scidavis/src/future/matrix/MatrixModule.h
branches/current_stable/scidavis/src/future/matrix/matrix.pro
branches/current_stable/scidavis/src/future/table/ExportTableDialog.cpp
branches/current_stable/scidavis/src/future/table/ExportTableDialog.h
branches/current_stable/scidavis/src/future/table/ImportTableDialog.cpp
branches/current_stable/scidavis/src/future/table/ImportTableDialog.h
branches/current_stable/scidavis/src/future/table/TableModule.cpp
branches/current_stable/scidavis/src/future/table/TableModule.h
branches/current_stable/scidavis/src/future/table/table.pro
Modified: branches/current_stable/scidavis/sourcefiles.pri
===================================================================
--- branches/current_stable/scidavis/sourcefiles.pri 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/sourcefiles.pri 2009-09-13 15:39:46 UTC (rev 1255)
@@ -127,7 +127,6 @@
src/MultiLayer.h\
src/LayerDialog.h \
src/IntDialog.h \
- src/SortDialog.h\
src/Bar.h \
src/Cone3D.h \
src/ConfigDialog.h \
@@ -231,7 +230,6 @@
src/MultiLayer.cpp\
src/LayerDialog.cpp \
src/IntDialog.cpp \
- src/SortDialog.cpp\
src/Bar.cpp \
src/Cone3D.cpp \
src/DataSetDialog.cpp \
@@ -364,6 +362,7 @@
src/future/table/future_SortDialog.h \
src/future/table/AsciiTableImportFilter.h \
src/future/core/AbstractImportFilter.h \
+ src/future/core/interfaces.h \
SOURCES += src/future/core/AbstractAspect.cpp \
src/future/core/AbstractPart.cpp \
Modified: branches/current_stable/scidavis/src/Filter.cpp
===================================================================
--- branches/current_stable/scidavis/src/Filter.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/Filter.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -97,25 +97,24 @@
else
d_n = curveData(d_curve, start, end, &d_x, &d_y);
- if (d_n == -1)
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
- tr("Several data points have the same x value causing divisions by zero, operation aborted!"));
+ if (!isDataAcceptable()) {
d_init_err = true;
- return;
+ return;
}
- else if (d_n < d_min_points)
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
- tr("You need at least %1 points in order to perform this operation!").arg(d_min_points));
- d_init_err = true;
- return;
- }
d_from = start;
d_to = end;
}
+bool Filter::isDataAcceptable() {
+ if (d_n < d_min_points) {
+ QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
+ tr("You need at least %1 points in order to perform this operation!").arg(d_min_points));
+ return false;
+ }
+ return true;
+}
+
int Filter::curveIndex(const QString& curveTitle, Graph *g)
{
if (curveTitle.isEmpty())
@@ -229,74 +228,61 @@
int Filter::sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
{
- if (!c)
+ if (!c || c->rtti() != QwtPlotItem::Rtti_PlotCurve)
return 0;
-
- int i_start = 0, i_end = c->dataSize();
- for (int i = 0; i < i_end; i++)
- if (c->x(i) >= start)
- {
- i_start = i;
+
+ // start/end finding only works on nondecreasing data, so sort first
+ int datasize = c->dataSize();
+ double *xtemp = new double[datasize];
+ for (int i = 0; i < datasize; i++) {
+ xtemp[i] = c->x(i);
+ }
+ size_t *p = new size_t[datasize];
+ gsl_sort_index(p, xtemp, 1, datasize);
+ delete[] xtemp;
+
+ // find indices that, when permuted by the sort result, give start and end
+ int i_start, i_end;
+ for (i_start = 0; i_start < datasize; i_start++)
+ if (c->x(p[i_start]) >= start)
break;
- }
- for (int i = i_end-1; i >= 0; i--)
- if (c->x(i) <= end)
- {
- i_end = i;
+ for (i_end = datasize-1; i_end >= 0; i_end--)
+ if (c->x(p[i_end]) <= end)
break;
- }
+
+ // make result arrays
int n = i_end - i_start + 1;
(*x) = new double[n];
(*y) = new double[n];
- double *xtemp = new double[n];
- double *ytemp = new double[n];
-
- int j=0;
- for (int i = i_start; i <= i_end; i++)
- {
- xtemp[j] = c->x(i);
- ytemp[j++] = c->y(i);
+ for (int j = 0, i = i_start; i <= i_end; i++, j++) {
+ (*x)[j] = c->x(p[i]);
+ (*y)[j] = c->y(p[i]);
}
- size_t *p = new size_t[n];
- gsl_sort_index(p, xtemp, 1, n);
- for (int i=0; i<n; i++)
- {
- (*x)[i] = xtemp[p[i]];
- (*y)[i] = ytemp[p[i]];
- }
- delete[] xtemp;
- delete[] ytemp;
delete[] p;
return n;
}
int Filter::curveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
{
- if (!c)
+ if (!c || c->rtti() != QwtPlotItem::Rtti_PlotCurve)
return 0;
+ int datasize = c->dataSize();
int i_start = 0, i_end = c->dataSize();
- for (int i = 0; i < i_end; i++)
- if (c->x(i) >= start)
- {
- i_start = i;
+ for (i_start = 0; i_start < datasize; i_start++)
+ if (c->x(i_start) >= start)
break;
- }
- for (int i = i_end-1; i >= 0; i--)
- if (c->x(i) <= end)
- {
- i_end = i;
+ for (i_end = datasize-1; i_end >= 0; i_end--)
+ if (c->x(i_end) <= end)
break;
- }
+
int n = i_end - i_start + 1;
(*x) = new double[n];
(*y) = new double[n];
- int j=0;
- for (int i = i_start; i <= i_end; i++)
- {
+ for (int j = 0, i = i_start; i <= i_end; i++, j++) {
(*x)[j] = c->x(i);
- (*y)[j++] = c->y(i);
+ (*y)[j] = c->y(i);
}
return n;
}
Modified: branches/current_stable/scidavis/src/Filter.h
===================================================================
--- branches/current_stable/scidavis/src/Filter.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/Filter.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -89,12 +89,18 @@
protected:
void init();
- //! Sets x and y to the curve points between start and end. Memory will be allocated with new double[].
- //! Returns the number of points within range == size of x and y arrays.
- virtual int curveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
+ /**
+ * \brief Sets x and y to the curve points between start and end.
+ *
+ * \returns the number of points within range == size of x and y arrays.
+ * Memory will be allocated with new double[].
+ */
+ int curveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
//! Same as curveData, but sorts the points by their x value.
- virtual int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
+ int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
+ virtual bool isDataAcceptable();
+
//! Adds the result curve to the target output plot window. Creates a hidden table and frees the input data from memory.
QwtPlotCurve* addResultCurve(double *x, double *y);
Modified: branches/current_stable/scidavis/src/Interpolation.cpp
===================================================================
--- branches/current_stable/scidavis/src/Interpolation.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/Interpolation.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -131,53 +131,15 @@
gsl_interp_accel_free (acc);
}
-int Interpolation::sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
+bool Interpolation::isDataAcceptable()
{
- if (!c || c->rtti() != QwtPlotItem::Rtti_PlotCurve)
- return 0;
+ // GSL interpolation routines fail with division by zero on such data
+ for (int i=1; i<d_n; i++)
+ if (d_x[i-1] == d_x[i]) {
+ QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
+ tr("Several data points have the same x value causing divisions by zero, operation aborted!"));
+ return false;
+ }
- int i_start = 0, i_end = c->dataSize();
- for (int i = 0; i < i_end; i++)
- if (c->x(i) > start && i)
- {
- i_start = i - 1;
- break;
- }
- for (int i = i_end-1; i >= 0; i--)
- if (c->x(i) < end && i < c->dataSize())
- {
- i_end = i + 1;
- break;
- }
- int n = i_end - i_start + 1;
- (*x) = new double[n];
- (*y) = new double[n];
- double *xtemp = new double[n];
- double *ytemp = new double[n];
-
- double pr_x;
- int j=0;
- for (int i = i_start; i <= i_end; i++)
- {
- xtemp[j] = c->x(i);
- if (xtemp[j] == pr_x)
- {
- delete (*x);
- delete (*y);
- return -1;//this kind of data causes division by zero in GSL interpolation routines
- }
- pr_x = xtemp[j];
- ytemp[j++] = c->y(i);
- }
- size_t *p = new size_t[n];
- gsl_sort_index(p, xtemp, 1, n);
- for (int i=0; i<n; i++)
- {
- (*x)[i] = xtemp[p[i]];
- (*y)[i] = ytemp[p[i]];
- }
- delete[] xtemp;
- delete[] ytemp;
- delete[] p;
- return n;
+ return Filter::isDataAcceptable();
}
Modified: branches/current_stable/scidavis/src/Interpolation.h
===================================================================
--- branches/current_stable/scidavis/src/Interpolation.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/Interpolation.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -46,10 +46,12 @@
void setMethod(int m);
void setMethod(InterpolationMethod m){setMethod((int)m);};
+protected:
+ virtual bool isDataAcceptable();
+
private:
void init(int m);
void calculateOutputData(double *x, double *y);
- int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
//! the interpolation method
int d_method;
Deleted: branches/current_stable/scidavis/src/SortDialog.cpp
===================================================================
--- branches/current_stable/scidavis/src/SortDialog.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/SortDialog.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,103 +0,0 @@
-/***************************************************************************
- File : SortDialog.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
- Description : Sorting options dialog
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "SortDialog.h"
-
-#include <QPushButton>
-#include <QLabel>
-#include <QComboBox>
-#include <QGroupBox>
-#include <QLayout>
-#include <QApplication>
-
-SortDialog::SortDialog( QWidget* parent, Qt::WFlags fl )
- : QDialog( parent, fl )
-{
- setWindowIcon(qApp->windowIcon());
- setWindowTitle(tr("Sorting Options"));
- setSizeGripEnabled(true);
-
- QGroupBox *groupBox1 = new QGroupBox();
- QGridLayout * topLayout = new QGridLayout(groupBox1);
- QHBoxLayout * hl = new QHBoxLayout();
- hl->addStretch();
-
- topLayout->addWidget( new QLabel(tr("Sort columns")), 0, 0 );
- boxType = new QComboBox();
- boxType->addItem(tr("Separately"));
- boxType->addItem(tr("Together"));
- topLayout->addWidget(boxType, 0, 1 );
-
- topLayout->addWidget( new QLabel( tr("Order")), 1, 0 );
- boxOrder = new QComboBox();
- boxOrder->addItem(tr("Ascending"));
- boxOrder->addItem(tr("Descending"));
- topLayout->addWidget(boxOrder, 1, 1 );
-
- topLayout->addWidget( new QLabel(tr("Leading column")), 2, 0 );
- columnsList = new QComboBox();
- topLayout->addWidget(columnsList, 2, 1);
- topLayout->setRowStretch(3, 1);
-
- buttonOk = new QPushButton(tr("&Sort"));
- buttonOk->setDefault( true );
- hl->addWidget(buttonOk);
-
- buttonCancel = new QPushButton(tr("&Close"));
- hl->addWidget(buttonCancel);
-
- QVBoxLayout * mainlayout = new QVBoxLayout(this);
- mainlayout->addWidget(groupBox1);
- mainlayout->addLayout(hl);
-
- connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
- connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
- connect( boxType, SIGNAL( activated(int) ), this, SLOT(changeType(int)));
-}
-
-void SortDialog::accept()
-{
- emit sort(boxType->currentIndex(),boxOrder->currentIndex(),columnsList->currentText());
-}
-
-void SortDialog::insertColumnsList(const QStringList& cols)
-{
- columnsList->addItems(cols);
- columnsList->setCurrentIndex(0);
-
- boxType->setCurrentIndex(1);
-}
-
-void SortDialog::changeType(int Type)
-{
- boxType->setCurrentIndex(Type);
- if(Type==1)
- columnsList->setEnabled(true);
- else
- columnsList->setEnabled(false);
-}
Deleted: branches/current_stable/scidavis/src/SortDialog.h
===================================================================
--- branches/current_stable/scidavis/src/SortDialog.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/SortDialog.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,62 +0,0 @@
-/***************************************************************************
- File : SortDialog.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
- Description : Superscript extension of QwtScaleDraw
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef SORTDIALOG_H
-#define SORTDIALOG_H
-
-#include <QDialog>
-
-class QPushButton;
-class QComboBox;
-
-//! Sorting options dialog
-class SortDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- SortDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
- void insertColumnsList(const QStringList& cols);
-
-private slots:
- void accept();
- void changeType(int index);
-
-signals:
- void sort(int, int, const QString&);
-
-private:
- QPushButton* buttonOk;
- QPushButton* buttonCancel;
- QPushButton* buttonHelp;
- QComboBox* boxType;
- QComboBox* boxOrder;
- QComboBox *columnsList;
-};
-
-#endif
Modified: branches/current_stable/scidavis/src/Table.cpp
===================================================================
--- branches/current_stable/scidavis/src/Table.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/Table.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -29,7 +29,6 @@
* *
***************************************************************************/
#include "Table.h"
-#include "SortDialog.h"
#include "core/column/Column.h"
#include "lib/Interval.h"
#include "table/TableModel.h"
Modified: branches/current_stable/scidavis/src/future/core/AbstractColumn.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractColumn.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractColumn.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -36,7 +36,7 @@
#include <QDate>
#include <QTime>
#include "lib/Interval.h"
-#include "core/globals.h"
+#include "globals.h"
#include "core/AbstractAspect.h"
class Column;
Deleted: branches/current_stable/scidavis/src/future/core/AbstractExportFilter.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractExportFilter.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractExportFilter.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,60 +0,0 @@
-/***************************************************************************
- File : AbstractExportFilter.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2008-2009 Knut Franke
- Email (use @ for *) : Knut.Franke*gmx.net
- Description : Interface for export operations.
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-
-#ifndef ABSTRACT_EXPORT_FILTER_H
-#define ABSTRACT_EXPORT_FILTER_H
-
-class AbstractAspect;
-class QIODevice;
-class QStringList;
-
-//! Interface for export operations.
-/**
- * This is analogous to AbstractImportFilter.
- */
-class AbstractExportFilter
-{
- public:
- virtual ~AbstractExportFilter() {}
- //! Export object to output.
- /**
- * \return true if export was sucessfull, false otherwise
- */
- virtual bool exportAspect(AbstractAspect * object, QIODevice * output) = 0;
- //! The file extension(s) typically associated with the handled format.
- virtual QStringList fileExtensions() const = 0;
- //! A (localized) name for the filter.
- virtual QString name() const = 0;
- //! Uses name() and fileExtensions() to produce a filter specification as used by QFileDialog.
- QString nameAndPatterns() const {
- return name() + " (*." + fileExtensions().join(" *.") + ")";
- }
-};
-
-#endif // ifndef ABSTRACT_EXPORT_FILTER_H
Deleted: branches/current_stable/scidavis/src/future/core/AbstractFit.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractFit.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractFit.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,79 +0,0 @@
-/***************************************************************************
- File : AbstractFit.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2008-2009 by Knut Franke
- Email (use @ for *) : knut.franke*gmx.de
- Description : Base class for doing fits using the algorithms
- provided by GSL.
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-
-#include "AbstractFit.h"
-#include <QUndoCommand>
-#include <gsl/gsl_multifit_nlin.h>
-#include <gsl/gsl_multimin.h>
-
-class FitSetAlgorithmCmd : public QUndoCommand
-{
- public:
- FitSetAlgorithCmd(AbstractFit *target, AbstractFit::Algorithm algo)
- : d_target(target), d_other_algo(algo) {
- setText(QObject::tr("%1: change fit algorithm to %2.").arg(d_target->name()).arg(AbstractFit::nameOf(d_algo)));
- }
-
- virtual void undo() {
- AbstractFit::Algorithm tmp = d_target->d_algorithm;
- d_target->d_algorithm = d_other_algo;
- d_other_algo = tmp;
- }
-
- virtual void redo() { undo(); }
-
- private:
- AbstractFit *d_target;
- AbstractFit::Algorithm d_other_algo;
-};
-
-class FitSetAutoRefitCmd : public QUndoCommand
-{
- public:
- FitSetAutoRefitCmd(AbstractFit *target, bool refit)
- : d_target(target), d_backup(refit) {
- setText((refit ?
- QObject::tr("%1: switch auto-refit on.", "label of AbstractFit's undo action") :
- QObject::tr("%1: switch auto-refit off.", "label of AbstractFit's undo action")).
- arg(d_target->name()));
- }
-
- virtual void undo() {
- bool tmp = d_target->d_auto_refit;
- d_target->d_auto_refit = d_backup;
- d_backup = tmp;
- }
-
- virtual void redo() { undo(); }
-
- private:
- AbstractFit *d_target;
- bool d_backup;
-};
Deleted: branches/current_stable/scidavis/src/future/core/AbstractFit.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractFit.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractFit.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,129 +0,0 @@
-/***************************************************************************
- File : AbstractFit.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2007-2009 by Knut Franke
- Email (use @ for *) : knut.franke*gmx.de
- Description : Base class for doing fits using the algorithms
- provided by GSL.
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef ABSTRACT_FIT_H
-#define ABSTRACT_FIT_H
-
-#include "AbstractFilter.h"
-
-class gsl_vector;
-class gsl_matrix;
-
-class FitSetAlgorithmCmd;
-
-/**
- * \brief Base class for doing fits using the algorithms provided by GSL.
- *
- * Implementations of AbstractFit essentially provide methods to compute a specific function to be
- * fitted, its derivatives with respect to the fit parameters and sensible estimates for the
- * parameters (given the data to be fitted).
- *
- * Input is accepted on two ports: X and Y. Y is assumed to be a function of X, which is
- * approximated by the function specified by the implementation of AbstractFit being used.
- *
- * On its output ports, AbstractFit provides (in order) the current values of the parameters,
- * their names, and textual descriptions. Current values can be initial values specified by
- * the user, automated estimates made by the implementation, or the results of the fit.
- * You only ever get to see the first two when you haven't connected the input ports of
- * AbstractFit yet, because after the first connect (and possibly subsequent calls to
- * setInitialValue()), the fit is automatically recomputed. After calling setAutoRefit(),
- * it is also recomputed whenever the input data changes.
- */
-class AbstractFit : public AbstractFilter
-{
- public:
- enum Algorithm { ScaledLevenbergMarquardt, UnscaledLevenbergMarquardt, NelderMeadSimplex };
- //! Possible sources for weighting data.
- enum Weighting {
- NoWeighting, //!< Use 1.0 as weight for all points (=> cannot produce sensible error estimates)
- Poisson, //!< Assume data follows Poisson distribution (weight with sqrt(N)).
- Dataset //!< Use weighting data from a user-specified data source.
- };
- static QString nameOf(Algorithm algo) {
- switch(algo) {
- case ScaledLevenbergMarquardt: return tr("scaled Levenberg-Marquardt");
- case UnscaledLevenbergMarquardt: return tr("unscaled Levenberg-Marquardt");
- case NelderMeadSimplex: return tr("Nelder-Mead / simplex");
- }
- };
- static QString nameOf(Weighting weighting) {
- switch(weighting) {
- case NoWeighting: return tr("no weighting");
- case Poisson: return tr("Poisson / sqrt(N)");
- case Dataset: return tr("user-supplied");
- }
- }
- AbstractFit() : d_algorithm(ScaledLevenbergMarquardt), d_tolerance(1e-8), d_maxiter(1000), d_auto_refit(false), d_outdated(true) {}
- virtual ~AbstractFit() {}
- bool isOutdated() const { return d_outdated; }
- void setAlgorithm(Algorithm a) { d_algorithm = a; }
- void setAutoRefit(bool auto_refit = true) { d_auto_refit = auto_refit; }
-
- //!\name Handling of fit parameters
- //@{
- void setInitialValue(int parameter, double value);
- virtual void guessInitialValues() = 0;
- //@}
-
- //!\name Reimplemented from AbstractFilter
- //@{
- public:
- virtual int inputCount() const { return 2; }
- virtual QString inputName(int port) const { return port==0 ? "X" : "Y"; }
- virtual int outputCount() const { return 3; }
- protected:
- virtual void dataChanged(AbstractDataSource*) {
- }
- //@}
-
- protected:
- static virtual double fitFunctionSimplex(const gsl_vector*, void*) = 0;
- static virtual int fitFunction(const gsl_vector*, void*, gsl_vector*) = 0;
- static virtual int fitFunctionDf(const gsl_vector*, void*, gsl_matrix*) = 0;
- static virtual int fitFunctionFdf(const gsl_vector*, void*, gsl_vector*, gsl_matrix*) {
- }
-
- private:
- //! Fit algorithm to use.
- Algorithm d_algorithm;
- //! Where to take weights from.
- WeightingMethod d_weighting;
- //! The tolerance ("epsilon") to be used for deciding when the fit was successful.
- double d_tolerance;
- //! The maximum number of iterations to do before declaring the fit to have failed.
- int d_maxiter;
- //! Whether to redo the fit each time input data changes.
- bool d_auto_refit;
- //! If #d_auto_refit is false, this is true when the input data has changed since the last fit.
- bool d_outdated;
-
- friend class FitSetAlgorithmCmd;
-};
-
-#endif // ifndef ABSTRACT_FIT_H
Deleted: branches/current_stable/scidavis/src/future/core/AbstractScript.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractScript.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractScript.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,42 +0,0 @@
-/***************************************************************************
- File : AbstractScript.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Knut Franke
- Email (use @ for *) : knut.franke*gmx.de
- Description : A chunk of scripting code.
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "AbstractScript.h"
-#include "AbstractScriptingEngine.h"
-
-AbstractScript::AbstractScript(AbstractScriptingEngine *engine, const QString &code, QObject *context, const QString &name)
- : d_engine(engine), d_code(code), d_name(name), d_compiled(notCompiled), d_context(context), d_emit_errors(true)
-{
- d_engine->incref();
-}
-
-AbstractScript::~AbstractScript()
-{
- d_engine->decref();
-}
-
Deleted: branches/current_stable/scidavis/src/future/core/AbstractScript.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractScript.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractScript.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,111 +0,0 @@
-/***************************************************************************
- File : AbstractScript.h
- Project : SciDAVis
- Description : A chunk of scripting code.
- --------------------------------------------------------------------
- Copyright : (C) 2006-2009 Knut Franke (knut.franke*gmx.de)
- Copyright : (C) 2006-2009 Tilman Benkert (thzs*gmx.net)
- Copyright : (C) 2006-2007 Ion Vasilief (ion_vasilief*yahoo.fr)
- (replace * with @ in the email addresses)
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef ABSTRACT_SCRIPT_H
-#define ABSTRACT_SCRIPT_H
-
-#include <QVariant>
-#include <QString>
-#include <QObject>
-
-class ApplicationWindow;
-class AbstractScriptingEngine;
-
-//! A chunk of scripting code.
- /**
- * AbstractScript objects represent a chunk of code, possibly together with local
- * variables. The code may be changed and executed multiple times during the
- * lifetime of an object.
- */
-class AbstractScript : public QObject
-{
- Q_OBJECT
-
- public:
- AbstractScript(AbstractScriptingEngine *env, const QString &code, QObject *context=0, const QString &name="<input>");
- ~AbstractScript();
-
- //! Return the code that will be executed/evaluated when calling exec() or eval()
- const QString code() const { return d_code; }
- //! Return the context in which the code is to be executed.
- const QObject* context() const { return d_context; }
- //! Like QObject::name, but with unicode support.
- const QString name() const { return d_name; }
- //! Return whether errors / exceptions are to be emitted or silently ignored
- const bool emitErrors() const { return d_emit_errors; }
- //! Append to the code that will be executed when calling exec() or eval()
- virtual void addCode(const QString &code) { d_code.append(code); d_compiled = notCompiled; emit codeChanged(); }
- //! Set the code that will be executed when calling exec() or eval()
- virtual void setCode(const QString &code) { d_code=code; d_compiled = notCompiled; emit codeChanged(); }
- //! Set the context in which the code is to be executed.
- virtual void setContext(QObject *context) { d_context = context; d_compiled = notCompiled; }
- //! Like QObject::setName, but with unicode support.
- void setName(const QString &name) { d_name = name; d_compiled = notCompiled; }
- //! Set whether errors / exceptions are to be emitted or silently ignored
- void setEmitErrors(bool value) { d_emit_errors = value; }
-
- public slots:
- //! Compile the content of #d_code.
- /**
- * \param for_eval whether the code is to be evaluated later on (as opposed to executed)
- * \return True iff compilation was successful or the implementation doesn't support compilation.
- */
- virtual bool compile(bool for_eval=true) { Q_UNUSED(for_eval); return true; }
- //! Evaluate #d_code, returning QVariant() on an error / exception.
- virtual QVariant eval() = 0;
- //! Execute #d_code, returning false on an error / exception.
- virtual bool exec() = 0;
-
- // local variables
- virtual bool setQObject(const QObject*, const char*) { return false; }
- virtual bool setInt(int, const char*) { return false; }
- virtual bool setDouble(double, const char*) { return false; }
-
- signals:
- //! This is emitted whenever the code to be executed by exec() and eval() is changed.
- void codeChanged();
- //! signal an error condition / exception
- void error(const QString & message, const QString & scriptName, int lineNumber);
- //! output generated by the code
- void print(const QString & output);
-
- protected:
- AbstractScriptingEngine *d_engine;
- QString d_code, d_name;
- QObject *d_context;
- enum compileStatus { notCompiled, isCompiled, compileErr } d_compiled;
- bool d_emit_errors;
-
- void emit_error(const QString & message, int line_number)
- { if(d_emit_errors) emit error(message, d_name, line_number); }
-};
-
-#endif
-
Deleted: branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,81 +0,0 @@
-/***************************************************************************
- File : AbstractScriptingEngine.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006-2009 by Knut Franke
- Email (use @ for *) : knut.franke*gmx.de
- Description : Implementations of generic scripting classes
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "AbstractScriptingEngine.h"
-
-AbstractScriptingEngine::AbstractScriptingEngine(const char *lang_name)
-{
- setObjectName(lang_name);
- d_initialized=false;
- d_refcount=0;
-}
-
-const QString AbstractScriptingEngine::nameAndPatterns() const
-{
- QStringList extensions = fileExtensions();
- if (extensions.isEmpty())
- return "";
- else
- return tr("%1 Source (*.%2)").arg(objectName()).arg(extensions.join(" *."));
-}
-
-void AbstractScriptingEngine::incref()
-{
- d_refcount++;
-}
-
-void AbstractScriptingEngine::decref()
-{
- d_refcount--;
- if (d_refcount==0)
- delete this;
-}
-
-/******************************************************************************\
- *Helper classes for managing instances of AbstractScriptingEngine subclasses.*
-\******************************************************************************/
-
-scripted::scripted(AbstractScriptingEngine *engine)
-{
- if (engine)
- engine->incref();
- d_scripting_engine = engine;
-}
-
-scripted::~scripted()
-{
- if (d_scripting_engine)
- d_scripting_engine->decref();
-}
-
-void scripted::scriptingChangeEvent(ScriptingChangeEvent *sce)
-{
- d_scripting_engine->decref();
- sce->scriptingEngine()->incref();
- d_scripting_engine = sce->scriptingEngine();
-}
Deleted: branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/AbstractScriptingEngine.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,171 +0,0 @@
-/***************************************************************************
- File : AbstractScriptingEngine.h
- Project : SciDAVis
- Description : Scripting abstraction layer
- --------------------------------------------------------------------
- Copyright : (C) 2006-2009 Knut Franke (knut.franke*gmx.de)
- Copyright : (C) 2006-2009 Tilman Benkert (thzs*gmx.net)
- Copyright : (C) 2006-2007 Ion Vasilief (ion_vasilief*yahoo.fr)
- (replace * with @ in the email addresses)
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef ABSTRACT_SCRIPTING_ENGINE_H
-#define ABSTRACT_SCRIPTING_ENGINE_H
-
-#include <QObject>
-#include <QEvent>
-#include <QtPlugin>
-#include <QStringList>
-
-#include "customevents.h"
-
-class AbstractScript;
-class QString;
-
-//! An interpreter for evaluating scripting code.
- /**
- * AbstractScriptingEngine objects represent a running interpreter, possibly with global
- * variables, and are responsible for generating AbstractScript objects (which do
- * the actual evaluation of code).
- *
- * The class also keeps a static list of available interpreters and instantiates
- * them on demand.
- */
-class AbstractScriptingEngine : public QObject
-{
- Q_OBJECT
-
- public:
- //! Only initialize general information here.
- /**
- * All AbstractScriptingEngine subclasses are instantiated at startup (more precisely: when
- * instantiating ScriptingEngineManager). Therefor, loading the actual interpreter is done
- * in initialize().
- */
- AbstractScriptingEngine(const char *lang_name);
- //! Initialize the scripting environment.
- /**
- * Don't forget to set d_initialized to true in implemenations after a successfull
- * initialization.
- */
- virtual void initialize() = 0;
- //! initialization of the interpreter may fail; or there could be other errors setting up the environment
- bool initialized() const { return d_initialized; }
- //! whether asynchronuous execution is enabled (if supported by the implementation)
- virtual bool isRunning() const { return false; }
-
- //! Instantiate the AbstractScript subclass matching the AbstractScriptingEngine subclass.
- virtual AbstractScript *makeScript(const QString&, QObject*, const QString&) = 0;
-
- //! If an exception / error occured, return a nicely formated stack backtrace.
- virtual QString stackTraceString() { return QString::null; }
-
- //! Return a list of supported mathematical functions.
- /**
- * These should be imported into the global namespace.
- */
- virtual const QStringList mathFunctions() const { return QStringList(); }
- //! Return a documentation string for the given mathematical function.
- virtual const QString mathFunctionDoc(const QString&) const { return QString::null; }
- //! Return a list of file extensions commonly used for this language.
- virtual const QStringList fileExtensions() const { return QStringList(); };
- //! Construct a filter expression from fileExtensions(), suitable for QFileDialog.
- const QString nameAndPatterns() const;
-
-// virtual QSyntaxHighlighter syntaxHighlighter(QTextEdit *textEdit) const;
-
- public slots:
- // global variables
- virtual bool setQObject(QObject*, const char*) { return false; }
- virtual bool setInt(int, const char*) { return false; }
- virtual bool setDouble(double, const char*) { return false; }
-
- //! Clear the global environment.
- /**
- * What exactly happens depends on the implementation.
- */
- virtual void clear() {}
- //! If the implementation supports asynchronuos execution, deactivate it.
- virtual void stopExecution() {}
- //! If the implementation supports asynchronuos execution, activate it.
- virtual void startExecution() {}
-
- //! Increase the reference count.
- /**
- * This should only be called by scripted and Script to avoid memory leaks.
- */
- void incref();
- //! Decrease the reference count.
- /**
- * This should only be called by scripted and Script to avoid segfaults.
- */
- void decref();
-
- signals:
- //! signal an error condition / exception
- void error(const QString & message, const QString & scriptName, int lineNumber);
- //! output that is not handled by a Script
- void print(const QString & output);
-
- protected:
- //! whether the interpreter has been successfully initialized
- bool d_initialized;
-
- private:
- //! the reference counter
- int d_refcount;
-};
-
-Q_DECLARE_INTERFACE(AbstractScriptingEngine, "net.sf.scidavis.scriptingengine/0.1")
-
-/******************************************************************************\
- *Helper classes for managing instances of AbstractScriptingEngine subclasses.*
-\******************************************************************************/
-
-//! notify an object that it should update its scripting environment (see class scripted)
-class ScriptingChangeEvent : public QEvent
-{
- public:
- ScriptingChangeEvent(AbstractScriptingEngine *engine) : QEvent(SCRIPTING_CHANGE_EVENT), d_scripting_engine(engine) {}
- AbstractScriptingEngine *scriptingEngine() const { return d_scripting_engine; }
- Type type() const { return SCRIPTING_CHANGE_EVENT; }
- private:
- AbstractScriptingEngine *d_scripting_engine;
-};
-
-//! Interface for maintaining a reference to the current AbstractScriptingEngine
- /**
- * Every class that wants to use a AbstractScriptingEngine should subclass this one and
- * implement slot customEvent(QEvent*) such that it forwards any
- * AbstractScriptingChangeEvents to scripted::scriptingChangeEvent.
- */
-class scripted
-{
- public:
- scripted(AbstractScriptingEngine* engine);
- ~scripted();
- void scriptingChangeEvent(ScriptingChangeEvent*);
- protected:
- AbstractScriptingEngine *d_scripting_engine;
-};
-
-#endif // ifndef ABSTRACT_SCRIPTING_ENGINE_H
Deleted: branches/current_stable/scidavis/src/future/core/CopyThroughFilter.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/CopyThroughFilter.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/CopyThroughFilter.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,54 +0,0 @@
-/***************************************************************************
- File : CopyThroughFilter.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2007 by Knut Franke
- Email (use @ for *) : knut.franke*gmx.de
- Description : Filter which copies all provided inputs unaltered
- to an equal number of outputs.
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef COPY_THROUGH_FILTER_H
-#define COPY_THROUGH_FILTER_H
-
-#include "AbstractFilter.h"
-
-/**
- * \brief Filter which copies all provided inputs unaltered to an equal number of outputs.
- *
- * This is probably the simplest filter you can possibly write.
- * It accepts an arbitrary number of inputs and provides the same AbstractColumn objects
- * as outputs again.
- */
-class CopyThroughFilter : public AbstractFilter
-{
- public:
- //! Accept any number of inputs.
- virtual int inputCount() const { return -1; }
- //! Provide as many output ports as inputs have been connected.
- virtual int outputCount() const { return d_inputs.size(); }
- //! When asked for an output port, just return the corresponding input port.
- virtual AbstractColumn* output(int port) const { return d_inputs.value(port); }
-};
-
-#endif // ifndef COPY_THROUGH_FILTER_H
-
Deleted: branches/current_stable/scidavis/src/future/core/Filter.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/Filter.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/Filter.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,334 +0,0 @@
-/***************************************************************************
- File : Fit.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2007 by Ion Vasilief
- Email (use @ for *) : ion_vasilief*yahoo.fr
- Description : Abstract base class for data analysis operations
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "Filter.h"
-#include "lib/ColorBox.h"
-
-#include "graph/TextEnrichment.h"
-#include "table/Table.h"
-#include "graph/FunctionCurve.h"
-#include "graph/PlotCurve.h"
-#include "graph/Layer.h"
-
-#include <QApplication>
-#include <QMessageBox>
-#include <QLocale>
-
-#include <gsl/gsl_sort.h>
-
-Filter::Filter( ApplicationWindow *parent, Layer *g, const char * name)
-: QObject( parent, name)
-{
- init();
- d_layer = g;
-}
-
-Filter::Filter( ApplicationWindow *parent, Table *t, const char * name)
-: QObject( parent, name)
-{
- init();
- d_table = t;
-}
-
-void Filter::init()
-{
- d_n = 0;
- d_curveColorIndex = 1;
- d_tolerance = 1e-4;
- d_points = 100;
- d_max_iterations = 1000;
- d_curve = 0;
- d_prec = ((ApplicationWindow *)parent())->fit_output_precision;
- d_init_err = false;
- d_sort_data = false;
- d_min_points = 2;
- d_explanation = QString(name());
- d_layer = 0;
- d_table = 0;
-}
-
-void Filter::setInterval(double from, double to)
-{
- if (!d_curve)
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
- tr("Please assign a curve first!"));
- return;
- }
- setDataFromCurve (d_curve->title().text(), from, to);
-}
-
-void Filter::setDataCurve(int curve, double start, double end)
-{
- if (d_n > 0)
- {//delete previousely allocated memory
- delete[] d_x;
- delete[] d_y;
- }
-
- d_init_err = false;
- d_curve = d_layer->curve(curve);
- if (d_sort_data)
- d_n = sortedCurveData(d_curve, start, end, &d_x, &d_y);
- else
- d_n = curveData(d_curve, start, end, &d_x, &d_y);
-
- if (d_n == -1)
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
- tr("Several data points have the same x value causing divisions by zero, operation aborted!"));
- d_init_err = true;
- return;
- }
- else if (d_n < d_min_points)
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
- tr("You need at least %1 points in order to perform this operation!").arg(d_min_points));
- d_init_err = true;
- return;
- }
-
- d_from = start;
- d_to = end;
-}
-
-int Filter::curveIndex(const QString& curveTitle, Layer *g)
-{
- if (curveTitle.isEmpty())
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("Filter Error"),
- tr("Please enter a valid curve name!"));
- d_init_err = true;
- return -1;
- }
-
- if (g)
- d_layer = g;
-
- if (!d_layer)
- {
- d_init_err = true;
- return -1;
- }
-
- return d_layer->curveIndex(curveTitle);
-}
-
-bool Filter::setDataFromCurve(const QString& curveTitle, Layer *g)
-{
- int index = curveIndex(curveTitle, g);
- if (index < 0)
- {
- d_init_err = true;
- return false;
- }
-
- d_layer->range(index, &d_from, &d_to);
- setDataCurve(index, d_from, d_to);
- return true;
-}
-
-bool Filter::setDataFromCurve(const QString& curveTitle, double from, double to, Layer *g)
-{
- int index = curveIndex(curveTitle, g);
- if (index < 0)
- {
- d_init_err = true;
- return false;
- }
-
- setDataCurve(index, from, to);
- return true;
-}
-
-void Filter::setColor(const QString& colorName)
-{
- QColor c = QColor(colorName);
- if (colorName == "green")
- c = QColor(Qt::green);
- else if (colorName == "darkYellow")
- c = QColor(Qt::darkYellow);
- if (!ColorBox::isValidColor(c))
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("Color Name Error"),
- tr("The color name '%1' is not valid, a default color (red) will be used instead!").arg(colorName));
- d_curveColorIndex = 1;
- return;
- }
-
- d_curveColorIndex = ColorBox::colorIndex(c);
-}
-
-void Filter::showLegend()
-{
- TextEnrichment* mrk = d_layer->newLegend(legendInfo());
- if (d_layer->hasLegend())
- {
- TextEnrichment* legend = d_layer->legend();
- QPoint p = legend->rect().bottomLeft();
- mrk->setOrigin(QPoint(p.x(), p.y()+20));
- }
- d_layer->replot();
-}
-
-bool Filter::run()
-{
- if (d_init_err)
- return false;
-
- if (d_n < 0)
- {
- QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") + " - " + tr("Error"),
- tr("You didn't specify a valid data set for this operation!"));
- return false;
- }
-
- QApplication::setOverrideCursor(Qt::WaitCursor);
-
- output();//data analysis and output
- ((ApplicationWindow *)parent())->updateLog(logInfo());
-
- QApplication::restoreOverrideCursor();
- return true;
-}
-
-void Filter::output()
-{
- double *X = new double[d_points];
- double *Y = new double[d_points];
-
- //do the data analysis
- calculateOutputData(X, Y);
-
- addResultCurve(X, Y);
-}
-
-int Filter::sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
-{
- if (!c)
- return 0;
-
- int i_start = 0, i_end = c->dataSize();
- for (int i = 0; i < i_end; i++)
- if (c->x(i) >= start)
- {
- i_start = i;
- break;
- }
- for (int i = i_end-1; i >= 0; i--)
- if (c->x(i) <= end)
- {
- i_end = i;
- break;
- }
- int n = i_end - i_start + 1;
- (*x) = new double[n];
- (*y) = new double[n];
- double *xtemp = new double[n];
- double *ytemp = new double[n];
-
- int j=0;
- for (int i = i_start; i <= i_end; i++)
- {
- xtemp[j] = c->x(i);
- ytemp[j++] = c->y(i);
- }
- size_t *p = new size_t[n];
- gsl_sort_index(p, xtemp, 1, n);
- for (int i=0; i<n; i++)
- {
- (*x)[i] = xtemp[p[i]];
- (*y)[i] = ytemp[p[i]];
- }
- delete[] xtemp;
- delete[] ytemp;
- delete[] p;
- return n;
-}
-
-int Filter::curveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
-{
- if (!c)
- return 0;
-
- int i_start = 0, i_end = c->dataSize();
- for (int i = 0; i < i_end; i++)
- if (c->x(i) >= start)
- {
- i_start = i;
- break;
- }
- for (int i = i_end-1; i >= 0; i--)
- if (c->x(i) <= end)
- {
- i_end = i;
- break;
- }
- int n = i_end - i_start + 1;
- (*x) = new double[n];
- (*y) = new double[n];
-
- int j=0;
- for (int i = i_start; i <= i_end; i++)
- {
- (*x)[j] = c->x(i);
- (*y)[j++] = c->y(i);
- }
- return n;
-}
-
-QwtPlotCurve* Filter::addResultCurve(double *x, double *y)
-{
- ApplicationWindow *app = (ApplicationWindow *)parent();
- const QString tableName = app->generateUniqueName(QString(this->name()));
- Table *t = app->newHiddenTable(tableName, d_explanation + " " + tr("of") + " " + d_curve->title().text(), d_points, 2);
- for (int i=0; i<d_points; i++)
- {
- t->setText(i, 0, QLocale().toString(x[i], 'g', app->d_decimal_digits));
- t->setText(i, 1, QLocale().toString(y[i], 'g', app->d_decimal_digits));
- }
-
- DataCurve *c = new DataCurve(t, tableName + "_1", tableName + "_2");
- c->setData(x, y, d_points);
- c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1));
- d_layer->insertPlotItem(c, Layer::Line);
- d_layer->updatePlot();
-
- delete[] x;
- delete[] y;
- return (QwtPlotCurve*)c;
-}
-
-Filter::~Filter()
-{
- if (d_n > 0)
- {//delete the memory allocated for the data
- delete[] d_x;
- delete[] d_y;
- }
-}
Deleted: branches/current_stable/scidavis/src/future/core/Filter.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/Filter.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/Filter.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,162 +0,0 @@
-/***************************************************************************
- File : Filter.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2007 by Ion Vasilief
- Email (use @ for *) : ion_vasilief*yahoo.fr
- Description : Abstract base class for data analysis operations
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef FILTER_H
-#define FILTER_H
-
-#include <QObject>
-
-#include "ApplicationWindow.h"
-
-class QwtPlotCurve;
-class Layer;
-class Table;
-
-//! Abstract base class for data analysis operations
-class Filter : public QObject
-{
- Q_OBJECT
-
- public:
- Filter(ApplicationWindow *parent, Table *t = 0, const char * name = 0);
- Filter(ApplicationWindow *parent, Layer *layer = 0, const char * name = 0);
- ~Filter();
-
- //! Actually does the job. Should be reimplemented in derived classes.
- virtual bool run();
-
- virtual void setDataCurve(int curve, double start, double end);
- bool setDataFromCurve(const QString& curveTitle, Layer *layer = 0);
- bool setDataFromCurve(const QString& curveTitle, double from, double to, Layer *layer = 0);
-
- //! Changes the data range if the source curve was already assigned. Provided for convenience.
- void setInterval(double from, double to);
-
- //! Sets the tolerance used by the GSL routines
- void setTolerance(double eps){d_tolerance = eps;};
-
- //! Sets the color of the output fit curve.
- void setColor(int colorId){d_curveColorIndex = colorId;};
-
- //! Sets the color of the output fit curve. Provided for convenience. To be used in scripts only!
- void setColor(const QString& colorName);
-
- //! Sets the number of points in the output curve
- void setOutputPoints(int points){d_points = points;};
-
- //! Sets the precision used for the output
- void setOutputPrecision(int digits){d_prec = digits;};
-
- //! Sets the maximum number of iterations to be performed during an iterative session
- void setMaximumIterations(int iter){d_max_iterations = iter;};
-
- //! Adds a new legend to the plot. Calls virtual legendInfo()
- virtual void showLegend();
-
- //! Output string added to the plot as a new legend
- virtual QString legendInfo(){return QString();};
-
- //! Returns the size of the fitted data set
- int dataSize(){return d_n;};
-
- bool error(){return d_init_err;};
-
- protected:
- void init();
-
- //! Sets x and y to the curve points between start and end. Memory will be allocated with new double[].
- //! Returns the number of points within range == size of x and y arrays.
- virtual int curveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
- //! Same as curveData, but sorts the points by their x value.
- virtual int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
-
- //! Adds the result curve to the target output plot window. Creates a hidden table and frees the input data from memory.
- QwtPlotCurve* addResultCurve(double *x, double *y);
-
- //! Performs checks and returns the index of the source data curve if OK, -1 otherwise
- int curveIndex(const QString& curveTitle, Layer *layer);
-
- //! Output string added to the log pannel of the application
- virtual QString logInfo(){return QString();};
-
- //! Performs the data analysis and takes care of the output
- virtual void output();
-
- //! Calculates the data for the output curve and store it in the X an Y vectors
- virtual void calculateOutputData(double *X, double *Y) { Q_UNUSED(X) Q_UNUSED(Y) };
-
- //! The graph where the result curve should be displayed
- Layer *d_layer;
-
- //! A table source of data
- Table *d_table;
-
- //! Size of the data arrays
- int d_n;
-
- //! x data set to be analysed
- double *d_x;
-
- //! y data set to be analysed
- double *d_y;
-
- //! GSL Tolerance, if ever needed...
- double d_tolerance;
-
- //! Number of result points to de calculated and displayed in the output curve
- int d_points;
-
- //! Color index of the result curve
- int d_curveColorIndex;
-
- //! Maximum number of iterations per fit
- int d_max_iterations;
-
- //! The curve to be analysed
- QwtPlotCurve *d_curve;
-
- //! Precision (number of significant digits) used for the results output
- int d_prec;
-
- //! Error flag telling if something went wrong during the initialization phase.
- bool d_init_err;
-
- //! Data interval
- double d_from, d_to;
-
- //! Specifies if the filter needs sorted data as input
- bool d_sort_data;
-
- //! Minimum number of data points necessary to perform the operation
- int d_min_points;
-
- //! String explaining the operation in the comment of the result table and in the project explorer
- QString d_explanation;
-};
-
-#endif
Deleted: branches/current_stable/scidavis/src/future/core/FilterDialog.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/FilterDialog.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/FilterDialog.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,191 +0,0 @@
-/***************************************************************************
- File : FilterDialog.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
- Description : Filter options dialog
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "FilterDialog.h"
-#include "MyParser.h"
-#include "lib/ColorBox.h"
-#include "analysis/FFTFilter.h"
-#include "graph/Layer.h"
-
-#include <QGroupBox>
-#include <QCheckBox>
-#include <QMessageBox>
-#include <QLayout>
-#include <QPushButton>
-#include <QLabel>
-#include <QLineEdit>
-#include <QComboBox>
-
-FilterDialog::FilterDialog(int type, QWidget* parent, Qt::WFlags fl )
- : QDialog( parent, fl )
-{
- setWindowTitle(tr("Filter options"));
- filter_type = type;
-
- QGroupBox *gb1 = new QGroupBox();
- QGridLayout *gl1 = new QGridLayout(gb1);
- gl1->addWidget(new QLabel(tr("Filter curve: ")), 0, 0);
-
- boxName = new QComboBox();
- gl1->addWidget(boxName, 0, 1);
-
- if (type <= FFTFilter::HighPass)
- gl1->addWidget(new QLabel(tr("Frequency cutoff (Hz)")), 1, 0);
- else
- gl1->addWidget(new QLabel(tr("Low Frequency (Hz)")), 1, 0);
-
- boxStart = new QLineEdit();
- boxStart->setText(tr("0"));
- gl1->addWidget(boxStart, 1, 1);
-
- boxColor = new ColorBox(false);
- boxColor->setColor(QColor(Qt::red));
- if (type >= FFTFilter::BandPass)
- {
- gl1->addWidget(new QLabel(tr("High Frequency (Hz)")), 2, 0);
-
- boxEnd = new QLineEdit();
- boxEnd->setText(tr("0"));
- gl1->addWidget(boxEnd, 2, 1);
-
- if (type == FFTFilter::BandPass)
- gl1->addWidget(new QLabel(tr("Add DC Offset")), 3, 0);
- else
- gl1->addWidget(new QLabel(tr("Substract DC Offset")), 3, 0);
-
- boxOffset = new QCheckBox();
- gl1->addWidget(boxOffset, 3, 1);
-
- gl1->addWidget(new QLabel(tr("Color")), 4, 0);
- gl1->addWidget(boxColor, 4, 1);
- gl1->setRowStretch(5, 1);
- }
- else
- {
- gl1->addWidget(new QLabel(tr("Color")), 2, 0);
- gl1->addWidget(boxColor, 2, 1);
- gl1->setRowStretch(3, 1);
- }
-
- buttonFilter = new QPushButton(tr( "&Filter" ));
- buttonFilter->setDefault( true );
- buttonCancel = new QPushButton(tr( "&Close" ));
-
- QVBoxLayout *vl = new QVBoxLayout();
- vl->addWidget(buttonFilter);
- vl->addWidget(buttonCancel);
- vl->addStretch();
-
- QHBoxLayout *hb = new QHBoxLayout(this);
- hb->addWidget(gb1);
- hb->addLayout(vl);
-
- connect( buttonFilter, SIGNAL( clicked() ), this, SLOT( filter() ) );
- connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
-}
-
-void FilterDialog::filter()
-{
-double from = 0.0, to = 0.0;
-try
- {
- MyParser parser;
- parser.SetExpr(boxStart->text().replace(",", ".").toAscii().constData());
- from = parser.Eval();
- }
-catch(mu::ParserError &e)
- {
- QMessageBox::critical(this, tr("Frequency input error"), QString::fromStdString(e.GetMsg()));
- boxStart->setFocus();
- return;
- }
-
-if (from < 0)
- {
- QMessageBox::critical(this, tr("Frequency input error"),
- tr("Please enter positive frequency values!"));
- boxStart->setFocus();
- return;
- }
-
-if (filter_type >= FFTFilter::BandPass)
- {
- try
- {
- MyParser parser;
- parser.SetExpr(boxEnd->text().replace(",", ".").toAscii().constData());
- to=parser.Eval();
- }
- catch(mu::ParserError &e)
- {
- QMessageBox::critical(this, tr("High Frequency input error"), QString::fromStdString(e.GetMsg()));
- boxEnd->setFocus();
- return;
- }
-
- if (to < 0)
- {
- QMessageBox::critical(this, tr("High Frequency input error"),
- tr("Please enter positive frequency values!"));
- boxEnd->setFocus();
- return;
- }
-
- if (from>=to)
- {
- QMessageBox::critical(this, tr("Frequency input error"),
- tr("Please enter frequency limits that satisfy: Low < High !"));
- boxEnd->setFocus();
- return;
- }
- }
-
-FFTFilter *f = new FFTFilter((ApplicationWindow *)this->parent(), d_layer, boxName->currentText(), filter_type);
-if (filter_type == FFTFilter::BandPass)
- {
- f->setBand(from, to);
- f->enableOffset(boxOffset->isChecked());
- }
-else if (filter_type == FFTFilter::BandBlock)
- {
- f->setBand(from, to);
- f->enableOffset(!boxOffset->isChecked());
- }
-else
- f->setCutoff(from);
-
-f->setColor(boxColor->currentIndex());
-f->run();
-delete f;
-}
-
-void FilterDialog::setLayer(Layer *layer)
-{
-layer = layer;
-boxName->addItems (layer->analysableCurvesList());
-};
Deleted: branches/current_stable/scidavis/src/future/core/FilterDialog.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/FilterDialog.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/FilterDialog.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,70 +0,0 @@
-/***************************************************************************
- File : FilterDialog.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
- Description : Filter options dialog
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef FILTERDIALOG_H
-#define FILTERDIALOG_H
-
-#include <QDialog>
-
-class QPushButton;
-class QLineEdit;
-class QComboBox;
-class QCheckBox;
-class Layer;
-class ColorBox;
-
-//! Filter options dialog
-class FilterDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- FilterDialog(int type, QWidget* parent = 0, Qt::WFlags fl = 0 );
- ~FilterDialog(){};
-
- QPushButton* buttonFilter;
- QPushButton* buttonCancel;
- QComboBox* boxName;
- QCheckBox* boxOffset;
- QLineEdit* boxStart;
- QLineEdit* boxEnd;
- ColorBox* boxColor;
-
-public slots:
- void setLayer(Layer *g);
- void filter();
-
-private:
- Layer *d_layer;
- int filter_type;
-};
-
-#endif
-
-
-
Deleted: branches/current_stable/scidavis/src/future/core/MyParser.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/MyParser.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/MyParser.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,192 +0,0 @@
-/***************************************************************************
- File : MyParser.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
- Description : Parser class based on muParser
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "MyParser.h"
-
-MyParser::MyParser()
-:Parser()
-{
-DefineConst("pi", M_PI);
-DefineConst("Pi", M_PI);
-DefineConst("PI", M_PI);
-
-DefineFun("bessel_j0", bessel_J0);
-DefineFun("bessel_j1", bessel_J1);
-DefineFun("bessel_jn", bessel_Jn);
-DefineFun("bessel_y0", bessel_Y0);
-DefineFun("bessel_y1", bessel_Y1);
-DefineFun("bessel_yn", bessel_Yn);
-DefineFun("beta", beta);
-DefineFun("erf", erf);
-DefineFun("erfc", erfc);
-DefineFun("erfz", erfz);
-DefineFun("erfq", erfq);
-DefineFun("gamma", gamma);
-DefineFun("gammaln", gammaln);
-DefineFun("hazard", hazard);
-}
-
-QStringList MyParser::functionsList()
-{
-QStringList l;
-l << "abs()" << "acos()" << "acosh()" << "asin()" << "asinh()" << "atan()";
-l << "atanh()" << "avg(,)" << "bessel_j0()" << "bessel_j1()" << "bessel_jn(,)";
-l << "bessel_y0()" << "bessel_y1()" << "bessel_yn(,)" << "beta(,)";
-l << "cos()" << "cosh()" << "erf()" << "erfc()" << "erfz()" << "erfq()";
-l << "exp()" << "gamma()" << "gammaln()" << "hazard()";
-l << "if( , , )" << "ln()" << "log()" << "log2()" << "min()" << "max()";
-l << "rint()" << "sign()" << "sin()" << "sinh()" << "sqrt()" << "tan()" << "tanh()";
-return l;
-}
-
-QString MyParser::explainFunction(int index)
-{
-QString blabla;
-switch (index)
- {
-case 0:
- blabla="abs(x):\n Absolute value of x.";
-break;
-
-case 1:
- blabla="acos(x):\n Inverse cos function.";
-break;
-
-case 2:
- blabla="acosh(x):\n Hyperbolic inverse cos function.";
-break;
-
-case 3:
- blabla="asin(x):\n Inverse sin function.";
-break;
-
-case 4:
- blabla="asinh(x):\n Hyperbolic inverse sin function.";
-break;
-case 5:
- blabla="atan(x):\n Inverse tan function.";
-break;
-case 6:
- blabla="atanh(x):\n Hyperbolic inverse tan function.";
-break;
-case 7:
- blabla="avg(x,y,...):\n Mean value of all arguments.";
-break;
-case 8:
- blabla="bessel_j0(x):\n Regular cylindrical Bessel function of zeroth order, J_0(x).";
-break;
-case 9:
- blabla="bessel_j1(x):\n Regular cylindrical Bessel function of first order, J_1(x).";
-break;
-case 10:
- blabla="bessel_j1(double x, int n):\n Regular cylindrical Bessel function of order n, J_n(x).";
-break;
-case 11:
- blabla="bessel_y0(x):\n Irregular cylindrical Bessel function of zeroth order, Y_0(x), for x>0.";
-break;
-case 12:
- blabla="bessel_y1(x):\n Irregular cylindrical Bessel function of first order, Y_1(x), for x>0.";
-break;
-case 13:
- blabla="bessel_yn(double x, int n):\n Irregular cylindrical Bessel function of order n, Y_n(x), for x>0.";
-break;
-case 14:
- blabla="beta (a,b):\n Computes the Beta Function, B(a,b) = Gamma(a)*Gamma(b)/Gamma(a+b) for a > 0, b > 0.";
-break;
-case 15:
- blabla="cos (x):\n Calculate cosine.";
-break;
-case 16:
- blabla="cosh(x):\n Hyperbolic cos function.";
-break;
-case 17:
- blabla="erf(x):\n The error function.";
-break;
-case 18:
- blabla="erfc(x):\n Complementary error function erfc(x) = 1 - erf(x).";
-break;
-case 19:
- blabla="erfz(x):\n The Gaussian probability density function Z(x).";
-break;
-case 20:
- blabla="erfq(x):\n The upper tail of the Gaussian probability function Q(x).";
-break;
-case 21:
- blabla="exp(x):\n Exponential function: e raised to the power of x.";
-break;
-case 22:
- blabla="gamma(x):\n Computes the Gamma function, subject to x not being a negative integer.";
-break;
-case 23:
- blabla="gammaln(x):\n Computes the logarithm of the Gamma function, subject to x not a being negative integer. For x<0, log(|Gamma(x)|) is returned.";
-break;
-case 24:
- blabla="hazard(x):\n Computes the hazard function for the normal distribution h(x) = erfz(x)/erfq(x).";
-break;
-case 25:
- blabla="if(e1, e2, e3): if e1 then e2 else e3.";
-break;
-case 26:
- blabla="ln(x):\n Calculate natural logarithm.";
-break;
-case 27:
- blabla="log(x):\n Calculate decimal logarithm.";
-break;
-case 28:
- blabla="log2(x):\n Calculate logarithm to the base 2.";
-break;
-case 29:
- blabla="min(x,y,...):\n Calculate minimum of all arguments.";
-break;
-case 30:
- blabla="max(x,y,...):\n Calculate maximum of all arguments.";
-break;
-case 31:
- blabla="rint(x):\n Round to nearest integer.";
-break;
-case 32:
- blabla="sign(x):\n Sign function: -1 if x<0; 1 if x>0.";
-break;
-case 33:
- blabla="sin(x):\n Calculate sine.";
-break;
-case 34:
- blabla="sinh(x):\n Hyperbolic sin function.";
-break;
-case 35:
- blabla="sqrt(x):\n Square root function.";
-break;
-case 36:
- blabla="tan(x):\n Calculate tangent function.";
-break;
-case 37:
- blabla="tanh(x):\n Hyperbolic tan function.";
-break;
- }
-return blabla;
-}
Deleted: branches/current_stable/scidavis/src/future/core/MyParser.h
===================================================================
--- branches/current_stable/scidavis/src/future/core/MyParser.h 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/MyParser.h 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,119 +0,0 @@
-/***************************************************************************
- File : MyParser.h
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
- Description : Parser class based on muParser
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#ifndef MYPARSER_H
-#define MYPARSER_H
-
-#include <muParser.h>
-#include <gsl/gsl_math.h>
-#include <gsl/gsl_sf.h>
-
-#include <qstringlist.h>
-
-using namespace mu;
-
-/*!\brief Mathematical parser class based on muParser.
- *
- * \section future_plans Future Plans
- * Eliminate in favour of Script/ScriptingEnv.
- * This will allow you to use e.g. Python's global variables and functions everywhere.
- * Before this happens, a cleaner and more generic solution for accessing the current ScriptingEnv
- * should be implemented (maybe by making it a property of Project; see ApplicationWindow).
- * [ assigned to knut ]
- */
-class MyParser : public Parser
-{
-public:
- MyParser();
-
- static QStringList functionsList();
- static QString explainFunction(int index);
-
- static double bessel_J0(double x)
- {
- return gsl_sf_bessel_J0 (x);
- }
-
- static double bessel_J1(double x)
- {
- return gsl_sf_bessel_J1 (x);
- }
-
- static double bessel_Jn(double x, double n)
- {
- return gsl_sf_bessel_Jn ((int)n, x);
- }
-
- static double bessel_Y0(double x)
- {
- return gsl_sf_bessel_Y0 (x);
- }
-
- static double bessel_Y1(double x)
- {
- return gsl_sf_bessel_Y1 (x);
- }
- static double bessel_Yn(double x, double n)
- {
- return gsl_sf_bessel_Yn ((int)n, x);
- }
- static double beta(double a, double b)
- {
- return gsl_sf_beta (a, b);
- }
- static double erf(double x)
- {
- return gsl_sf_erf (x);
- }
- static double erfc(double x)
- {
- return gsl_sf_erfc (x);
- }
- static double erfz(double x)
- {
- return gsl_sf_erf_Z (x);
- }
- static double erfq(double x)
- {
- return gsl_sf_erf_Q (x);
- }
- static double gamma(double x)
- {
- return gsl_sf_gamma (x);
- }
- static double gammaln(double x)
- {
- return gsl_sf_lngamma (x);
- }
- static double hazard(double x)
- {
- return gsl_sf_hazard (x);
- }
-};
-
-#endif
Modified: branches/current_stable/scidavis/src/future/core/Project.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/Project.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/Project.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -33,7 +33,7 @@
#include "core/ScriptingEngineManager.h"
#endif
#include "core/interfaces.h"
-#include "core/globals.h"
+#include "globals.h"
#include "lib/XmlStreamReader.h"
#include "core/ProjectConfigPage.h"
#include <QUndoStack>
Deleted: branches/current_stable/scidavis/src/future/core/ScriptEdit.cpp
===================================================================
--- branches/current_stable/scidavis/src/future/core/ScriptEdit.cpp 2009-09-12 16:26:18 UTC (rev 1254)
+++ branches/current_stable/scidavis/src/future/core/ScriptEdit.cpp 2009-09-13 15:39:46 UTC (rev 1255)
@@ -1,370 +0,0 @@
-/***************************************************************************
- File : ScriptEdit.cpp
- Project : SciDAVis
- --------------------------------------------------------------------
- Copyright : (C) 2006 by Ion Vasilief,
- Tilman Benkert,
- Knut Franke
- Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net,
- knut.franke*gmx.de
- Description : Editor widget for scripting code
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- ***************************************************************************/
-#include "ScriptEdit.h"
-#include "AbstractScriptingEngine.h"
-#include "AbstractScript.h"
-
-#include <QAction>
-#include <QMenu>
-#include <QPrintDialog>
-#include <QPrinter>
-#include <QMessageBox>
-#include <QFileDialog>
-#include <QTextStream>
-#include <QKeyEvent>
-#include <QContextMenuEvent>
-#include <QTextBlock>
-
-ScriptEdit::ScriptEdit(AbstractScriptingEngine *engine, QWidget *parent, const char *name)
- : QTextEdit(parent), scripted(engine)
-{
- setObjectName(name);
-
- d_script = d_scripting_engine->makeScript("", this, name);
- connect(d_script, SIGNAL(error(const QString&,const QString&,int)), this, SLOT(insertErrorMsg(const QString&)));
- connect(d_script, SIGNAL(print(const QString&)), this, SLOT(scriptPrint(const QString&)));
-
- setLineWrapMode(NoWrap);
- setAcceptRichText(false);
- setFontFamily("Monospace");
-
- printCursor = textCursor();
-
- actionExecute = new QAction(tr("E&xecute"), this);
- actionExecute->setShortcut( tr("Ctrl+J") );
- connect(actionExecute, SIGNAL(activated()), this, SLOT(execute()));
-
- actionExecuteAll = new QAction(tr("Execute &All"), this);
- actionExecuteAll->setShortcut( tr("Ctrl+Shift+J") );
- connect(actionExecuteAll, SIGNAL(activated()), this, SLOT(executeAll()));
-
- actionEval = new QAction(tr("&Evaluate Expression"), this);
- actionEval->setShortcut( tr("Ctrl+Return") );
- connect(actionEval, SIGNAL(activated()), this, SLOT(evaluate()));
-
- actionPrint = new QAction(tr("&Print"), this);
- connect(actionPrint, SIGNAL(activated()), this, SLOT(print()));
-
- actionImport = new QAction(tr("&Import"), this);
- connect(actionImport, SIGNAL(activated()), this, SLOT(importASCII()));
-
- actionExport = new QAction(tr("&Export"), this);
- connect(actionExport, SIGNAL(activated()), this, SLOT(exportASCII()));
-
- functionsMenu = new QMenu(this);
- Q_CHECK_PTR(functionsMenu);
- connect(functionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(insertFunction(QAction *)));
-}
-
-void ScriptEdit::customEvent(QEvent *e)
-{
- if (e->type() == SCRIPTING_CHANGE_EVENT)
- {
- scriptingChangeEvent((ScriptingChangeEvent*)e);
- delete d_script;
- d_script = d_scripting_engine->makeScript("", this, objectName());
- connect(d_script, SIGNAL(error(const QString&,const QString&,int)), this, SLOT(insertErrorMsg(const QString&)));
- connect(d_script, SIGNAL(print(const QString&)), this, SLOT(scriptPrint(const QString&)));
- }
-}
-
-void ScriptEdit::keyPressEvent(QKeyEvent *e)
-{
- QTextEdit::keyPressEvent(e);
- if (e->key() == Qt::Key_Return)
- updateIndentation();
-}
-
-void ScriptEdit::contextMenuEvent(QContextMenuEvent *e)
-{
- QMenu *menu = createStandardContextMenu();
- Q_CHECK_PTR(menu);
-
- menu->addAction(actionPrint);
- menu->addAction(actionImport);
- menu->addAction(actionExport);
- menu->addSeparator();
-
- menu->addAction(actionExecute);
- menu->addAction(actionExecuteAll);
- menu->addAction(actionEval);
-
- /* TODO
- if (parent()->inherits("Note"))
- {
- Note *sp = (Note*) parent();
- QAction *actionAutoexec = new QAction( tr("Auto&exec"), menu );
- actionAutoexec->setToggleAction(true);
- actionAutoexec->setOn(sp->autoexec());
- connect(actionAutoexec, SIGNAL(toggled(bool)), sp, SLOT(setAutoexec(bool)));
- menu->addAction(actionAutoexec);
- }
- */
-
- functionsMenu->clear();
- functionsMenu->setTearOffEnabled(true);
- QStringList flist = d_scripting_engine->mathFunctions();
- QMenu *submenu=NULL;
- for (int i=0; i<flist.size(); i++)
- {
- QAction *newAction;
- QString menupart;
- // group by text before "_" (would make sense if we renamed several functions...)
- /*if (flist[i].contains("_") || (i<flist.size()-1 && flist[i+1].split("_")[0]==flist[i]))
- menupart = flist[i].split("_")[0];
- else
- menupart = "";*/
- // group by first letter, avoiding submenus with only one entry
- if ((i==0 || flist[i-1][0] != flist[i][0]) && (i==flist.size()-1 || flist[i+1][0] != flist[i][0]))
- menupart = "";
- else
- menupart = flist[i].left(1);
- if (!menupart.isEmpty()) {
- if (!submenu || menupart != submenu->title())
- submenu = functionsMenu->addMenu(menupart);
- newAction = submenu->addAction(flist[i]);
- } else
- newAction = functionsMenu->addAction(flist[i]);
- newAction->setData(i);
- newAction->setWhatsThis(d_scripting_engine->mathFunctionDoc(flist[i]));
- }
- functionsMenu->setTitle(tr("&Functions"));
- menu->addMenu(functionsMenu);
-
- menu->exec(e->globalPos());
- delete menu;
-}
-
-void ScriptEdit::insertErrorMsg(const QString &message)
-{
- QString err = message;
- err.prepend("\n").replace("\n","\n#> ");
- int start = printCursor.position();
- printCursor.insertText(err);
- printCursor.setPosition(start, QTextCursor::KeepAnchor);
- setTextCursor(printCursor);
-}
-
-void ScriptEdit::scriptPrint(const QString &text)
-{
- if(lineNumber(printCursor.position()) == lineNumber(textCursor().selectionEnd()))
- printCursor.insertText("\n");
- printCursor.insertText(text);
-}
-
-void ScriptEdit::insertFunction(const QString &fname)
-{
- QTextCursor cursor = textCursor();
- QString markedText = cursor.selectedText();
- cursor.insertText(fname+"("+markedText+")");
- if(markedText.isEmpty()){
- // if no text is selected, place cursor inside the ()
- // instead of after it
- cursor.movePosition(QTextCursor::PreviousCharacter,QTextCursor::MoveAnchor,1);
- // the next line makes the selection visible to the user
- // (the line above only changes the selection in the
- // underlying QTextDocument)
- setTextCursor(cursor);
- }
-}
-
-void ScriptEdit::insertFunction(QAction *action)
-{
- insertFunction(d_scripting_engine->mathFunctions()[action->data().toInt()]);
-}
-
-int ScriptEdit::lineNumber(int pos) const
-{
- int n=1;
- for(QTextBlock i=document()->begin(); !i.contains(pos) && i!=document()->end(); i=i.next())
- n++;
- return n;
-}
-
-void ScriptEdit::execute()
-{
- QString fname = "<%1:%2>";
- fname = fname.arg(objectName());
- QTextCursor codeCursor = textCursor();
- if (codeCursor.selectedText().isEmpty()){
- codeCursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
- codeCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
- }
- fname = fname.arg(lineNumber(codeCursor.selectionStart()));
-
- d_script->setName(fname);
- d_script->setCode(codeCursor.selectedText().replace(QChar::ParagraphSeparator,"\n"));
- printCursor.setPosition(codeCursor.selectionEnd(), QTextCursor::MoveAnchor);
- printCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor);
- d_script->exec();
-}
-
-void ScriptEdit::executeAll()
-{
- QString fname = "<%1>";
- fname = fname.arg(objectName());
- d_script->setName(fname);
- d_script->setCode(toPlainText());
- printCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
- d_script->exec();
-}
-
-void ScriptEdit::evaluate()
-{
- QString fname = "<%1:%2>";
- fname = fname.arg(objectName());
- QTextCursor codeCursor = textCursor();
- if (codeCursor.selectedText().isEmpty()){
- codeCursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
- codeCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
- }
- fname = fname.arg(lineNumber(codeCursor.selectionStart()));
-
- d_script->setName(fname);
- d_script->setCode(codeCursor.selectedText().replace(QChar::ParagraphSeparator,"\n"));
- printCursor.setPosition(codeCursor.selectionEnd(), QTextCursor::MoveAnchor);
- printCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor);
- QVariant res = d_script->eval();
- if (res.isValid())
- if (!res.isNull() && res.canConvert(QVariant::String)){
- QString strVal = res.toString();
- strVal.replace("\n", "\n#> ");
- if (!strVal.isEmpty())
- printCursor.insertText("\n#> "+strVal+"\n");
- else
- printCursor.insertText("\n");
- }
-
- setTextCursor(printCursor);
-}
-
-void ScriptEdit::exportPDF(const QString& fileName)
-{
- QTextDocument *doc = document();
- QPrinter printer;
- printer.setColorMode(QPrinter::GrayScale);
- printer.setCreator("SciDAVis");
- printer.setOutputFormat(QPrinter::PdfFormat);
- printer.setOutputFileName(fileName);
- doc->print(&printer);
-}
-
-void ScriptEdit::print()
-{
- QTextDocument *doc = document();
- QPrinter printer;
- printer.setColorMode(QPrinter::GrayScale);
- QPrintDialog printDialog(&printer);
- // TODO: Write a dialog to use more features of Qt4's QPrinter class
- if (printDialog.exec() == QDialog::Accepted)
- doc->print(&printer);
-}
-
-QString ScriptEdit::importASCII(const QString &filename)
-{
- QStringList filters;
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|