/* Copyright (c) 2008-2018 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) 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 Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #include "jkqtplotter/jkqtpgraphsparsedfunction.h" #include "jkqtplotter/jkqtpgraphs.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include "jkqtplottertools/jkqtptools.h" #include #include #include #include JKQTPxParsedFunctionLineGraph::JKQTPxParsedFunctionLineGraph(JKQtBasePlotter *parent): JKQTPxFunctionLineGraph(parent) { fdata.parser=new JKQTPMathParser(); fdata.node=nullptr; fdata.varcount=0; function=""; parameterColumn=-1; set_params(&fdata); set_plotFunction(&JKQTPxParsedFunctionLineGraph::JKQTPxParsedFunctionLineGraphFunction); efdata.parser=new JKQTPMathParser(); efdata.node=nullptr; efdata.varcount=0; errorFunction=""; errorParameterColumn=-1; set_errorParams(&efdata); set_errorPlotFunction(&JKQTPxParsedFunctionLineGraph::JKQTPxParsedFunctionLineGraphFunction); } JKQTPxParsedFunctionLineGraph::JKQTPxParsedFunctionLineGraph(JKQtPlotter *parent): JKQTPxFunctionLineGraph(parent) { fdata.parser=new JKQTPMathParser(); fdata.node=nullptr; fdata.varcount=0; function=""; parameterColumn=-1; set_params(&fdata); set_plotFunction(&JKQTPxParsedFunctionLineGraph::JKQTPxParsedFunctionLineGraphFunction); efdata.parser=new JKQTPMathParser(); efdata.node=nullptr; efdata.varcount=0; errorFunction=""; errorParameterColumn=-1; set_errorParams(&efdata); set_errorPlotFunction(&JKQTPxParsedFunctionLineGraph::JKQTPxParsedFunctionLineGraphFunction); } JKQTPxParsedFunctionLineGraph::~JKQTPxParsedFunctionLineGraph() { if (fdata.node) delete fdata.node; delete fdata.parser; if (efdata.node) delete efdata.node; delete efdata.parser; } void JKQTPxParsedFunctionLineGraph::createPlotData(bool /*collectParams*/) { collectParameters(); //QElapsedTimer timer; //timer.start(); for (int i=0; ideleteVariable(std::string("p")+jkqtp_inttostr(i+1)); } fdata.varcount=0; try { QVector* parameters=static_cast*>(params); if (parameters) { for (int i=0; isize(); i++) { fdata.parser->addVariableDouble(std::string("p")+jkqtp_inttostr(fdata.varcount+1), parameters->at(i)); fdata.varcount=fdata.varcount+1; } } fdata.parser->addVariableDouble(std::string("x"), 0.0); if (fdata.node) delete fdata.node; //qint64 t=timer.elapsed(); //qDebug()<<"createPlotData(): adding variables: "<parse(function.toStdString()); //qDebug()<<"createPlotData(): parsing: "<deleteVariable(std::string("p")+jkqtp_inttostr(i+1)); } efdata.varcount=0; try { QVector* errorParameters=static_cast*>(errorParams); if (errorParameters) { for (int i=0; isize(); i++) { efdata.parser->addVariableDouble(std::string("p")+jkqtp_inttostr(efdata.varcount+1), errorParameters->at(i)); efdata.varcount=efdata.varcount+1; } } efdata.parser->addVariableDouble(std::string("x"), 0.0); if (efdata.node) delete efdata.node; //qint64 t=timer.elapsed(); //qDebug()<<"createPlotData(): adding variables: "<parse(errorFunction.toStdString()); //qDebug()<<"createPlotData(): parsing: "<next; } qDebug()<<"refined to "<parser && d->node) { try { d->parser->addVariableDouble("x", x); JKQTPMathParser::jkmpResult r=d->node->evaluate(); if (r.isValid) { if (r.type==JKQTPMathParser::jkmpBool) { return r.boolean?1.0:0.0; } else if (r.type==JKQTPMathParser::jkmpDouble) { return r.num; } } } catch(std::exception& /*E*/) { //qDebug()<getExpression()).arg(E.what()).arg(row).arg(column), QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok)==QMessageBox::Ok;*/ } } return NAN; } JKQTPyParsedFunctionLineGraph::JKQTPyParsedFunctionLineGraph(JKQtBasePlotter *parent): JKQTPyFunctionLineGraph(parent) { fdata.parser=new JKQTPMathParser(); fdata.node=nullptr; fdata.varcount=0; function=""; parameterColumn=-1; set_params(&fdata); set_plotFunction(&JKQTPyParsedFunctionLineGraph::JKQTPyParsedFunctionLineGraphFunction); efdata.parser=new JKQTPMathParser(); efdata.node=nullptr; efdata.varcount=0; errorFunction=""; errorParameterColumn=-1; set_errorParams(&efdata); set_errorPlotFunction(&JKQTPyParsedFunctionLineGraph::JKQTPyParsedFunctionLineGraphFunction); } JKQTPyParsedFunctionLineGraph::JKQTPyParsedFunctionLineGraph(JKQtPlotter *parent): JKQTPyFunctionLineGraph(parent) { fdata.parser=new JKQTPMathParser(); fdata.node=nullptr; fdata.varcount=0; function=""; parameterColumn=-1; set_params(&fdata); set_plotFunction(&JKQTPyParsedFunctionLineGraph::JKQTPyParsedFunctionLineGraphFunction); efdata.parser=new JKQTPMathParser(); efdata.node=nullptr; efdata.varcount=0; errorFunction=""; errorParameterColumn=-1; set_errorParams(&efdata); set_errorPlotFunction(&JKQTPyParsedFunctionLineGraph::JKQTPyParsedFunctionLineGraphFunction); } JKQTPyParsedFunctionLineGraph::~JKQTPyParsedFunctionLineGraph() { if (fdata.node) delete fdata.node; delete fdata.parser; if (efdata.node) delete efdata.node; delete efdata.parser; } void JKQTPyParsedFunctionLineGraph::createPlotData(bool /*collectParams*/) { collectParameters(); //QElapsedTimer timer; //timer.start(); for (int i=0; ideleteVariable(std::string("p")+jkqtp_inttostr(i+1)); } fdata.varcount=0; try { QVector* parameters=static_cast*>(params); if (parameters) { for (int i=0; isize(); i++) { fdata.parser->addVariableDouble(std::string("p")+jkqtp_inttostr(fdata.varcount+1), parameters->at(i)); fdata.varcount=fdata.varcount+1; } } fdata.parser->addVariableDouble(std::string("x"), 0.0); fdata.parser->addVariableDouble(std::string("y"), 0.0); if (fdata.node) delete fdata.node; //qint64 t=timer.elapsed(); //qDebug()<<"createPlotData(): adding variables: "<parse(function.toStdString()); //qDebug()<<"createPlotData(): parsing: "<deleteVariable(std::string("p")+jkqtp_inttostr(i+1)); } efdata.varcount=0; try { QVector* errorParameters=static_cast*>(errorParams); if (errorParameters) { for (int i=0; isize(); i++) { efdata.parser->addVariableDouble(std::string("p")+jkqtp_inttostr(efdata.varcount+1), errorParameters->at(i)); efdata.varcount=efdata.varcount+1; } } efdata.parser->addVariableDouble(std::string("x"), 0.0); efdata.parser->addVariableDouble(std::string("y"), 0.0); if (efdata.node) delete efdata.node; //qint64 t=timer.elapsed(); //qDebug()<<"createPlotData(): adding variables: "<parse(errorFunction.toStdString()); //qDebug()<<"createPlotData(): parsing: "<next; } qDebug()<<"refined to "<parser && d->node) { try { d->parser->addVariableDouble("x", x); d->parser->addVariableDouble("y", x); JKQTPMathParser::jkmpResult r=d->node->evaluate(); if (r.isValid) { if (r.type==JKQTPMathParser::jkmpBool) { return r.boolean?1.0:0.0; } else if (r.type==JKQTPMathParser::jkmpDouble) { return r.num; } } } catch(std::exception& /*E*/) { //qDebug()<getExpression()).arg(E.what()).arg(row).arg(column), QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok)==QMessageBox::Ok;*/ } } return NAN; }