1 /* 2 KmPlot - a math. function plotter for the KDE-Desktop 3 4 SPDX-FileCopyrightText: 1998, 1999, 2000, 2002 Klaus-Dieter Möller <kd.moeller@t-online.de> 5 6 This file is part of the KDE Project. 7 KmPlot is part of the KDE-EDU Project. 8 9 SPDX-License-Identifier: GPL-2.0-or-later 10 11 */ 12 13 #ifndef xparser_included 14 #define xparser_included 15 16 #define SLIDER_COUNT 4 17 18 // Qt includes 19 #include <QDebug> 20 21 // local includes 22 #include "parser.h" 23 #include "settings.h" 24 #include "vector.h" 25 26 /** 27 * @short Extended parser class. 28 * 29 * This class extends the parser class to support derivatives, 30 * draw options like color and line width and so on. 31 */ 32 class XParser : public Parser 33 { 34 public: 35 static XParser * self(); 36 37 ~XParser(); 38 /** 39 * Evaluates the \p n th derivative of the equation using numerical 40 * stepsize \p h. 41 */ 42 double derivative( int n, Equation * eq, DifferentialState * state, double x, double h ); 43 /** 44 * For use with functions of two variables. 45 */ 46 double partialDerivative( int n1, int n2, Equation * eq, DifferentialState * state, double x, double y, double h1, double h2 ); 47 /** 48 * For differential equations - uses numerical integration to 49 * calculate value for the given x. Differential equations often have 50 * the annoying habit of diverging to infinity rapidly. If this 51 * happens while trying to calculate the value, then 52 * XParser::differentialFinite will be set to false, and 53 * XParserdifferentialDiverge will be set to the last point where the 54 * differential value was finite. 55 */ 56 double differential( Equation * eq, DifferentialState * state, double x, double max_dx ); 57 bool differentialFinite; 58 double differentialDiverge; 59 /** 60 * The settings contain 10 default function colors. This returns the 61 * (function % 10)th color. 62 */ 63 QColor defaultColor(int function); 64 65 /// finds a free function name 66 QString findFunctionName( const QString & preferredName, int id, const QStringList& neededPatterns = QStringList(QStringLiteral("%1")) ); 67 68 ///Returns an unused function name if it is needed 69 void fixFunctionName(QString &, Equation::Type const = Equation::Cartesian, int const=-1); 70 71 /// Interpretates the extended function string (only used by the old file format) 72 bool getext( Function *, const QString &); 73 74 /// Functions for the D-BUS interface: 75 public Q_SLOTS: 76 /// Returns a list with all functions 77 Q_SCRIPTABLE QStringList listFunctionNames(); 78 79 /// Returns true if the graph is visible, otherwise false. 80 Q_SCRIPTABLE bool functionFVisible(uint id); 81 Q_SCRIPTABLE bool functionF1Visible(uint id); 82 Q_SCRIPTABLE bool functionF2Visible(uint id); 83 Q_SCRIPTABLE bool functionIntVisible(uint id); 84 /// Set the visible of the function. Returns true if it succeeds, otherwise false. 85 Q_SCRIPTABLE bool setFunctionFVisible(uint id, bool visible); 86 Q_SCRIPTABLE bool setFunctionF1Visible(uint id, bool visible); 87 Q_SCRIPTABLE bool setFunctionF2Visible(uint id, bool visible); 88 Q_SCRIPTABLE bool setFunctionIntVisible(uint id, bool visible); 89 90 /// Returns the function expression, or an empty string if the function couldn't be found 91 Q_SCRIPTABLE QString functionStr(uint id, uint eq); 92 /// Returns the complete function string including the extensions of a function, or an empty string if the function couldn't be found 93 94 /// Get the color of a graph 95 Q_SCRIPTABLE QColor functionFColor(uint id); 96 Q_SCRIPTABLE QColor functionF1Color(uint id); 97 Q_SCRIPTABLE QColor functionF2Color(uint id); 98 Q_SCRIPTABLE QColor functionIntColor(uint id); 99 /// Set the color of a graph. Returns true if it succeeds, otherwise false. 100 Q_SCRIPTABLE bool setFunctionFColor(uint id, const QColor &color); 101 Q_SCRIPTABLE bool setFunctionF1Color(uint id, const QColor &color); 102 Q_SCRIPTABLE bool setFunctionF2Color(uint id, const QColor &color); 103 Q_SCRIPTABLE bool setFunctionIntColor(uint id, const QColor &color); 104 105 /// Get the line width of a graph 106 Q_SCRIPTABLE double functionFLineWidth(uint id); 107 Q_SCRIPTABLE double functionF1LineWidth(uint id); 108 Q_SCRIPTABLE double functionF2LineWidth(uint id); 109 Q_SCRIPTABLE double functionIntLineWidth(uint id); 110 /// Set the line width of a graph. Returns true if it succeeds, otherwise false. 111 Q_SCRIPTABLE bool setFunctionFLineWidth(uint id, double linewidth); 112 Q_SCRIPTABLE bool setFunctionF1LineWidth(uint id, double linewidth); 113 Q_SCRIPTABLE bool setFunctionF2LineWidth(uint id, double linewidth); 114 Q_SCRIPTABLE bool setFunctionIntLineWidth(uint id, double linewidth); 115 116 /// Returns the function's parameter list 117 Q_SCRIPTABLE QStringList functionParameterList(uint id); 118 Q_SCRIPTABLE bool functionAddParameter(uint id, const QString &new_parameter); 119 Q_SCRIPTABLE bool functionRemoveParameter(uint id, const QString &remove_parameter); 120 Q_SCRIPTABLE int addFunction(const QString &f_str0, const QString &f_str1); 121 Q_SCRIPTABLE bool addFunction(const QString &extstr0, const QString &extstr1, bool f_mode, bool f1_mode, bool f2_mode, bool integral_mode, double linewidth, double f1linewidth, double f2linewidth, double integrallinewidth, const QString &str_dmin, const QString &str_dmax, const QString &str_startx, const QString &str_starty, double integral_precision, const QColor &color, const QColor &f1_color, const QColor &f2_color, const QColor &integral_color, const QStringList & str_parameter, int use_slider); 122 Q_SCRIPTABLE bool setFunctionExpression(uint id, uint eq, const QString &f_str); 123 124 /// Get the min and max value of a graph 125 Q_SCRIPTABLE QString functionMinValue(uint id); 126 Q_SCRIPTABLE QString functionMaxValue(uint id); 127 /// Set the min and max values of a graph. Returns true if it succeeds, otherwise false. 128 Q_SCRIPTABLE bool setFunctionMinValue(uint id, const QString &min); 129 Q_SCRIPTABLE bool setFunctionMaxValue(uint id, const QString &max); 130 131 /// Get the startx and starty value of a graph 132 Q_SCRIPTABLE QString functionStartXValue(uint id); 133 Q_SCRIPTABLE QString functionStartYValue(uint id); 134 /// Set the startx and starty values of a graph. Returns true if it succeeds, otherwise false. 135 Q_SCRIPTABLE bool setFunctionStartValue(uint id, const QString &x, const QString &y); 136 137 private: 138 Vector rk4_f( int order, Equation * eq, double x, const Vector & y ); 139 /// for use in differential 140 Vector m_k1, m_k2, m_k3, m_k4, m_y_temp, m_y, m_result, m_arg; 141 142 143 private: 144 XParser(); 145 static XParser * m_self; 146 }; 147 148 #endif //xparser_included 149