File indexing completed on 2023-09-24 03:53:07
0001 /* 0002 KmPlot - a math. function plotter for the KDE-Desktop 0003 0004 SPDX-FileCopyrightText: 1998, 1999, 2000, 2002 Klaus-Dieter Möller <kd.moeller@t-online.de> 0005 0006 This file is part of the KDE Project. 0007 KmPlot is part of the KDE-EDU Project. 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 0011 */ 0012 0013 #ifndef xparser_included 0014 #define xparser_included 0015 0016 #define SLIDER_COUNT 4 0017 0018 // Qt includes 0019 #include <QDebug> 0020 0021 // local includes 0022 #include "parser.h" 0023 #include "settings.h" 0024 #include "vector.h" 0025 0026 /** 0027 * @short Extended parser class. 0028 * 0029 * This class extends the parser class to support derivatives, 0030 * draw options like color and line width and so on. 0031 */ 0032 class XParser : public Parser 0033 { 0034 public: 0035 static XParser *self(); 0036 0037 ~XParser(); 0038 /** 0039 * Evaluates the \p n th derivative of the equation using numerical 0040 * stepsize \p h. 0041 */ 0042 double derivative(int n, Equation *eq, DifferentialState *state, double x, double h); 0043 /** 0044 * For use with functions of two variables. 0045 */ 0046 double partialDerivative(int n1, int n2, Equation *eq, DifferentialState *state, double x, double y, double h1, double h2); 0047 /** 0048 * For differential equations - uses numerical integration to 0049 * calculate value for the given x. Differential equations often have 0050 * the annoying habit of diverging to infinity rapidly. If this 0051 * happens while trying to calculate the value, then 0052 * XParser::differentialFinite will be set to false, and 0053 * XParserdifferentialDiverge will be set to the last point where the 0054 * differential value was finite. 0055 */ 0056 double differential(Equation *eq, DifferentialState *state, double x, double max_dx); 0057 bool differentialFinite; 0058 double differentialDiverge; 0059 /** 0060 * The settings contain 10 default function colors. This returns the 0061 * (function % 10)th color. 0062 */ 0063 QColor defaultColor(int function); 0064 0065 /// finds a free function name 0066 QString findFunctionName(const QString &preferredName, int id, const QStringList &neededPatterns = QStringList(QStringLiteral("%1"))); 0067 0068 /// Returns an unused function name if it is needed 0069 void fixFunctionName(QString &, Equation::Type const = Equation::Cartesian, int const = -1); 0070 0071 /// Interpretates the extended function string (only used by the old file format) 0072 bool getext(Function *, const QString &); 0073 0074 /// Functions for the D-BUS interface: 0075 public Q_SLOTS: 0076 /// Returns a list with all functions 0077 Q_SCRIPTABLE QStringList listFunctionNames(); 0078 0079 /// Returns true if the graph is visible, otherwise false. 0080 Q_SCRIPTABLE bool functionFVisible(uint id); 0081 Q_SCRIPTABLE bool functionF1Visible(uint id); 0082 Q_SCRIPTABLE bool functionF2Visible(uint id); 0083 Q_SCRIPTABLE bool functionIntVisible(uint id); 0084 /// Set the visible of the function. Returns true if it succeeds, otherwise false. 0085 Q_SCRIPTABLE bool setFunctionFVisible(uint id, bool visible); 0086 Q_SCRIPTABLE bool setFunctionF1Visible(uint id, bool visible); 0087 Q_SCRIPTABLE bool setFunctionF2Visible(uint id, bool visible); 0088 Q_SCRIPTABLE bool setFunctionIntVisible(uint id, bool visible); 0089 0090 /// Returns the function expression, or an empty string if the function couldn't be found 0091 Q_SCRIPTABLE QString functionStr(uint id, uint eq); 0092 /// Returns the complete function string including the extensions of a function, or an empty string if the function couldn't be found 0093 0094 /// Get the color of a graph 0095 Q_SCRIPTABLE QColor functionFColor(uint id); 0096 Q_SCRIPTABLE QColor functionF1Color(uint id); 0097 Q_SCRIPTABLE QColor functionF2Color(uint id); 0098 Q_SCRIPTABLE QColor functionIntColor(uint id); 0099 /// Set the color of a graph. Returns true if it succeeds, otherwise false. 0100 Q_SCRIPTABLE bool setFunctionFColor(uint id, const QColor &color); 0101 Q_SCRIPTABLE bool setFunctionF1Color(uint id, const QColor &color); 0102 Q_SCRIPTABLE bool setFunctionF2Color(uint id, const QColor &color); 0103 Q_SCRIPTABLE bool setFunctionIntColor(uint id, const QColor &color); 0104 0105 /// Get the line width of a graph 0106 Q_SCRIPTABLE double functionFLineWidth(uint id); 0107 Q_SCRIPTABLE double functionF1LineWidth(uint id); 0108 Q_SCRIPTABLE double functionF2LineWidth(uint id); 0109 Q_SCRIPTABLE double functionIntLineWidth(uint id); 0110 /// Set the line width of a graph. Returns true if it succeeds, otherwise false. 0111 Q_SCRIPTABLE bool setFunctionFLineWidth(uint id, double linewidth); 0112 Q_SCRIPTABLE bool setFunctionF1LineWidth(uint id, double linewidth); 0113 Q_SCRIPTABLE bool setFunctionF2LineWidth(uint id, double linewidth); 0114 Q_SCRIPTABLE bool setFunctionIntLineWidth(uint id, double linewidth); 0115 0116 /// Returns the function's parameter list 0117 Q_SCRIPTABLE QStringList functionParameterList(uint id); 0118 Q_SCRIPTABLE bool functionAddParameter(uint id, const QString &new_parameter); 0119 Q_SCRIPTABLE bool functionRemoveParameter(uint id, const QString &remove_parameter); 0120 Q_SCRIPTABLE int addFunction(const QString &f_str0, const QString &f_str1); 0121 Q_SCRIPTABLE bool addFunction(const QString &extstr0, 0122 const QString &extstr1, 0123 bool f_mode, 0124 bool f1_mode, 0125 bool f2_mode, 0126 bool integral_mode, 0127 double linewidth, 0128 double f1linewidth, 0129 double f2linewidth, 0130 double integrallinewidth, 0131 const QString &str_dmin, 0132 const QString &str_dmax, 0133 const QString &str_startx, 0134 const QString &str_starty, 0135 double integral_precision, 0136 const QColor &color, 0137 const QColor &f1_color, 0138 const QColor &f2_color, 0139 const QColor &integral_color, 0140 const QStringList &str_parameter, 0141 int use_slider); 0142 Q_SCRIPTABLE bool setFunctionExpression(uint id, uint eq, const QString &f_str); 0143 0144 /// Get the min and max value of a graph 0145 Q_SCRIPTABLE QString functionMinValue(uint id); 0146 Q_SCRIPTABLE QString functionMaxValue(uint id); 0147 /// Set the min and max values of a graph. Returns true if it succeeds, otherwise false. 0148 Q_SCRIPTABLE bool setFunctionMinValue(uint id, const QString &min); 0149 Q_SCRIPTABLE bool setFunctionMaxValue(uint id, const QString &max); 0150 0151 /// Get the startx and starty value of a graph 0152 Q_SCRIPTABLE QString functionStartXValue(uint id); 0153 Q_SCRIPTABLE QString functionStartYValue(uint id); 0154 /// Set the startx and starty values of a graph. Returns true if it succeeds, otherwise false. 0155 Q_SCRIPTABLE bool setFunctionStartValue(uint id, const QString &x, const QString &y); 0156 0157 private: 0158 Vector rk4_f(int order, Equation *eq, double x, const Vector &y); 0159 /// for use in differential 0160 Vector m_k1, m_k2, m_k3, m_k4, m_y_temp, m_y, m_result, m_arg; 0161 0162 private: 0163 XParser(); 0164 static XParser *m_self; 0165 }; 0166 0167 #endif // xparser_included