29 changes: 29 additions & 0 deletions src/libkstapp/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace Kst {
"Position:\n"
" -P <plot name>: Place curves in one plot.\n"
" -A Place future curves in individual plots.\n"
" -T <tab name> Place future curves a new tab.\n"
"Appearance\n"
" -d: use points for the next curve\n"
" -l: use lines for the next curve\n"
Expand Down Expand Up @@ -330,6 +331,25 @@ void CommandLineParser::createImageInPlot(MatrixPtr m) {
_plotItem->update();
}

void CommandLineParser::createOrFindTab(const QString name) {
bool found = false;
int i;
int n_tabs = _mainWindow->tabWidget()->count();

for (i=0; i<n_tabs; i++) {
if (_mainWindow->tabWidget()->tabText(i) == name) {
found = true;
_mainWindow->tabWidget()->setCurrentIndex(i);
return;
}
}

if (!found) {
_mainWindow->tabWidget()->createView();
_mainWindow->tabWidget()->setCurrentViewName(name);
}
}

void CommandLineParser::createOrFindPlot( const QString plot_name ) {
bool found = false;
PlotItem *pi;
Expand Down Expand Up @@ -436,6 +456,15 @@ bool CommandLineParser::processCommandLine(bool *ok) {
createOrFindPlot(plot_name);
} else if (arg == "-A") {
_doConsecutivePlots = true;
} else if (arg == "-T") {
QString tab_name;
_doConsecutivePlots = true;
*ok = _setStringArg(tab_name,i18n("Usage: -T <tab name>\n"));
if (dataPlotted) {
createOrFindTab(tab_name);
} else {
_mainWindow->tabWidget()->setCurrentViewName(tab_name);
}
} else if (arg == "-d") {
_useBargraph=false;
_useLines = false;
Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/commandlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CommandLineParser
bool _setStringArg(QString &arg, QString Message);
DataVectorPtr createOrFindDataVector(QString field, DataSourcePtr ds);
void createOrFindPlot(const QString name);
void createOrFindTab(const QString name);
void createCurveInPlot(VectorPtr xv, VectorPtr yv, VectorPtr ev=0);
void createImageInPlot(MatrixPtr m);
void addCurve(CurvePtr curve);
Expand Down
10 changes: 10 additions & 0 deletions src/libkstapp/equationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,24 @@ void EquationTab::populateFunctionList() {
Operators.push_back("SQRT()");
Operators.push_back("CBRT()");
Operators.push_back("SIN()");
Operators.push_back("SIND()");
Operators.push_back("COS()");
Operators.push_back("COSD()");
Operators.push_back("TAN()");
Operators.push_back("TAND()");
Operators.push_back("ASIN()");
Operators.push_back("ASIND()");
Operators.push_back("ACOS()");
Operators.push_back("ACOSD()");
Operators.push_back("ATAN()");
Operators.push_back("ATAND()");
Operators.push_back("ATAN2()");
Operators.push_back("SEC()");
Operators.push_back("SECD()");
Operators.push_back("CSC()");
Operators.push_back("CSCD()");
Operators.push_back("COT()");
Operators.push_back("COTD()");
Operators.push_back("SINH()");
Operators.push_back("COSH()");
Operators.push_back("TANH()");
Expand Down
2 changes: 1 addition & 1 deletion src/libkstapp/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TabWidget : public QTabWidget
QTabBar *tabBar() const { return QTabWidget::tabBar(); }

Q_SIGNALS:
void currentViewModeChanged();
void currentViewModeChanged();

public Q_SLOTS:
View *createView();
Expand Down
3 changes: 2 additions & 1 deletion src/libkstapp/vectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ QVariant VectorModel::data(const QModelIndex& index, int role) const {
switch (_digitNbList.at(index.column())) {
case 0:
// Cast to long int if not too big
if (value < (double) LLONG_MAX && value > (double) -LLONG_MIN) {
if (value < (double) LLONG_MAX && value > (double) LLONG_MIN) {
qDebug() << "print as int";
return QVariant(QString::number((qlonglong) value));
}
else {
Expand Down
78 changes: 73 additions & 5 deletions src/libkstmath/enodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,46 @@ static double sec(double x) {
return 1.0/cos(x);
}

static double acosd(double x) {
return 180.0/M_PI*acos(x);
}

static double asind(double x) {
return 180.0/M_PI*asin(x);
}

static double atand(double x) {
return 180.0/M_PI*atan(x);
}

static double cosd(double x) {
return cos(fmod(x, 360.0)*M_PI/180.0);
}

static double cotd(double x) {
return cot(fmod(x, 360.0)*M_PI/180.0);
}

static double cscd(double x) {
return csc(fmod(x, 360.0)*M_PI/180.0);
}

static double secd(double x) {
return sec(fmod(x, 360.0)*M_PI/180.0);
}

static double sind(double x) {
return sin(fmod(x, 360.0)*M_PI/180.0);
}

static double tand(double x) {
return tan(fmod(x, 360.0)*M_PI/180.0);
}

static double atanx(double *x) {
return atan2(x[0],x[1]);
}

static double step(double x) {
if (x>0.0) {
return 1.0;
Expand All @@ -391,30 +431,48 @@ static struct {
const char *name;
double (*func)(double);
} FTable[] = {
{"abs", &fabs},
{"acos", &acos},
{"asin", &asin},
{"atan", &atan},
{"abs", &fabs},
{"acos", &acos},
{"acosd", &acosd},
{"asin", &asin},
{"asind", &asind},
{"atan", &atan},
{"atand", &atand},
#ifndef Q_OS_WIN32
{"cbrt", &cbrt},
#endif
{"cos", &cos},
{"cosd", &cosd},
{"cosh", &cosh},
{"cot", &cot},
{"cotd", &cotd},
{"csc", &csc},
{"cscd", &cscd},
{"exp", &exp},
{"log", &log10},
{"ln", &log},
{"sec", &sec},
{"secd", &secd},
{"sin", &sin},
{"sind", &sind},
{"sinh", &sinh},
{"sqrt", &sqrt},
{"step", &step},
{"tan", &tan},
{"tand", &tand},
{"tanh", &tanh},
{0, 0}
};

static struct {
const char *name;
double (*func)(double*);
} F2Table[] = {

{"atanx", &atanx},
//{"atan2d", &atand2d},
{0, 0}
};

Function::Function(char *name, ArgumentList *args)
: Node(), _name(name), _args(args), _f(0L) {
Expand All @@ -437,6 +495,15 @@ Function::Function(char *name, ArgumentList *args)
break;
}
}
if (!_f) {
for (int i = 0; F2Table[i].name; ++i) {
if (strcasecmp(F2Table[i].name, name) == 0) {
_f = (void*)F2Table[i].func;
_argCount = 2;
break;
}
}
}
}


Expand Down Expand Up @@ -477,8 +544,9 @@ double Function::value(Context *ctx) {
for (int i = 0; i < _argCount; ++i) {
x[i] = _args->at(i, ctx);
}
double r = ((double (*)(double*))_f)(x);
delete[] x;
return ((double (*)(double*))_f)(x);
return r;
} else {
return ((double (*)())_f)();
}
Expand Down
33 changes: 28 additions & 5 deletions src/libkstmath/equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const QString Equation::reparsedEquation() const {
}

yylex_destroy();
yy_scan_string(_equation.toLatin1());
yy_scan_string(parseableEquation());
ParsedEquation = 0L;
int rc = yyparse(store());
Equations::Node *en = static_cast<Equations::Node*>(ParsedEquation);
Expand All @@ -156,8 +156,30 @@ const QString Equation::reparsedEquation() const {
delete en;
ParsedEquation = 0L;
Equations::mutex().unlock();
//etext.replace("atanx(", "atan2(");
//etext.replace("atanxd(", "atan2d(");
}
return (etext);
return (readableEquation(etext));
}

/** function names can't have numerals in them, but
* the best name for atan2 is ... atan2. So...
* special case it is :-( */
QByteArray Equation::parseableEquation() const {
QString eq = _equation;

eq.replace("atan2(", "atanx(", Qt::CaseInsensitive);
eq.replace("atan2d(", "atanxd(", Qt::CaseInsensitive);

return eq.toAscii();
}
QString Equation::readableEquation(const QString &equation) const {
QString eq = equation;

eq.replace("atanx(", "atan2(", Qt::CaseInsensitive);
eq.replace("atanxd(", "atan2d(", Qt::CaseInsensitive);

return eq;
}

void Equation::save(QXmlStreamWriter &s) {
Expand All @@ -168,7 +190,7 @@ void Equation::save(QXmlStreamWriter &s) {
if (!_equation.isEmpty()) {
QMutexLocker ml(&Equations::mutex());
yylex_destroy();
yy_scan_string(_equation.toLatin1());
yy_scan_string(parseableEquation());
ParsedEquation = 0L;
int rc = yyparse(store());
Equations::Node *en = static_cast<Equations::Node*>(ParsedEquation);
Expand Down Expand Up @@ -209,7 +231,7 @@ void Equation::setEquation(const QString& in_fn) {
if (!_equation.isEmpty()) {
Equations::mutex().lock();
yylex_destroy();
yy_scan_string(_equation.toLatin1());
yy_scan_string(parseableEquation());
int rc = yyparse(store());
_pe = static_cast<Equations::Node*>(ParsedEquation);
if (rc == 0 && _pe) {
Expand Down Expand Up @@ -455,7 +477,8 @@ bool Equation::FillY(bool force) {

QMutexLocker ml(&Equations::mutex());
yylex_destroy();
yy_scan_string(_equation.toLatin1());
QString eq = _equation;
yy_scan_string(parseableEquation());
int rc = yyparse(store());
_pe = static_cast<Equations::Node*>(ParsedEquation);
if (_pe && rc == 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/libkstmath/equation.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class KSTMATH_EXPORT Equation : public DataObject {
virtual qint64 minInputSerial() const;
virtual qint64 maxInputSerialOfLastChange() const;

QString readableEquation(const QString &equation) const;
QByteArray parseableEquation() const;

private:
QString _equation;

Expand Down