File indexing completed on 2024-04-21 03:40:38
0001 /************************************************************************************* 0002 * Copyright (C) 2007-2011 by Aleix Pol <aleixpol@kde.org> * 0003 * Copyright (C) 2010-2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU General Public License * 0007 * as published by the Free Software Foundation; either version 2 * 0008 * of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the Free Software * 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0018 *************************************************************************************/ 0019 0020 #ifndef _ABSTRACTFUNCTIONGRAPH_H 0021 #define _ABSTRACTFUNCTIONGRAPH_H 0022 0023 #include "abstractplotitem.h" 0024 #include <analitza/expression.h> 0025 #include <analitza/analyzer.h> 0026 #include <analitza/value.h> 0027 #include <QCoreApplication> 0028 #include <QPair> 0029 0030 namespace Analitza { 0031 class Variables; 0032 class Analyzer; 0033 } 0034 0035 #define TYPE_NAME(name) \ 0036 const QString typeName() const override { return QCoreApplication::tr(TypeName()); } \ 0037 static const char* TypeName() { return name; } 0038 0039 #define EXPRESSION_TYPE(name) \ 0040 static Analitza::ExpressionType ExpressionType() { return Analitza::ExpressionType(name); } 0041 0042 #define COORDDINATE_SYSTEM(name) \ 0043 CoordinateSystem coordinateSystem() const override { return CoordSystem(); }\ 0044 static CoordinateSystem CoordSystem() { return name; } 0045 0046 #define PARAMETERS(name) \ 0047 QStringList parameters() const override { return Parameters(); } \ 0048 static QStringList Parameters() { return (name); } 0049 0050 #define ICON_NAME(name) \ 0051 QString iconName() const override { return IconName(); } \ 0052 static QString IconName() { return (name); } 0053 0054 #define EXAMPLES(exs) \ 0055 static QStringList Examples() { return (exs); } 0056 0057 namespace Analitza { 0058 0059 class AbstractFunctionGraph : public AbstractMappingGraph 0060 { 0061 friend class FunctionGraphFactory; 0062 public: 0063 explicit AbstractFunctionGraph(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = {}); 0064 ~AbstractFunctionGraph() override; 0065 0066 Dimension spaceDimension() const override; 0067 0068 Analitza::Variables *variables() const; 0069 void setVariables(Analitza::Variables *variables); 0070 0071 const Analitza::Expression &expression() const; 0072 0073 QStringList errors() const; 0074 bool isCorrect() const; 0075 0076 QPair<Analitza::Expression, Analitza::Expression> interval(const QString &argname, bool evaluate) const; 0077 virtual bool setInterval(const QString &argname, const Analitza::Expression &min, const Analitza::Expression &max); 0078 0079 QPair<double, double> interval(const QString &argname) const; 0080 virtual bool setInterval(const QString &argname, double min, double max); 0081 void clearIntervals(); 0082 bool hasIntervals() const; 0083 0084 virtual QStringList parameters() const = 0; 0085 0086 void setResolution(int res) { m_resolution = res; } 0087 0088 protected: 0089 void appendError(const QString &error) { m_errors.append(error); } 0090 void flushErrors() { m_errors.clear(); } 0091 0092 void setInternalId(const QString &iid) { m_internalId = iid; } 0093 0094 Analitza::Cn* arg(const QString &argname); 0095 0096 Analitza::Analyzer *analyzer; 0097 int m_resolution; 0098 0099 private: 0100 QString m_internalId; 0101 0102 Analitza::Expression m_e; 0103 Analitza::Variables *m_varsmod; 0104 0105 //BEGIN private types 0106 class EndPoint 0107 { 0108 public: 0109 EndPoint() {} 0110 0111 explicit EndPoint(double value) 0112 { 0113 setValue(value); 0114 } 0115 0116 explicit EndPoint(const Analitza::Expression &expression) 0117 { 0118 if (!setValue(expression)) 0119 setValue(0.0); 0120 } 0121 0122 EndPoint(const EndPoint &other) : m_expressionValue(other.m_expressionValue) 0123 { 0124 0125 } 0126 0127 Analitza::Expression value(Analitza::Analyzer *analyzer) const 0128 { 0129 analyzer->setExpression(m_expressionValue); 0130 return analyzer->calculate(); 0131 } 0132 0133 Analitza::Expression value() const 0134 { 0135 return m_expressionValue; 0136 } 0137 0138 void setValue(double value) 0139 { 0140 m_expressionValue = Analitza::Expression(Analitza::Cn(value)); 0141 } 0142 0143 bool setValue(const Analitza::Expression &expression) 0144 { 0145 if (!expression.isCorrect()) 0146 return false; 0147 else 0148 { 0149 m_expressionValue = expression; 0150 0151 return true; 0152 } 0153 0154 return false; 0155 } 0156 0157 bool operator==(const EndPoint &other) const 0158 { 0159 return m_expressionValue == other.m_expressionValue; 0160 } 0161 0162 EndPoint operator=(const EndPoint& other) 0163 { 0164 m_expressionValue = other.m_expressionValue; 0165 0166 return *this; 0167 } 0168 0169 private: 0170 Analitza::Expression m_expressionValue; 0171 }; 0172 0173 class RealInterval 0174 { 0175 public: 0176 RealInterval() {} 0177 RealInterval(const EndPoint &lEndPoint, const EndPoint &hEndPoint) : m_lowEndPoint(lEndPoint), m_highEndPoint(hEndPoint) {} 0178 RealInterval(const RealInterval &other) : m_lowEndPoint(other.m_lowEndPoint), m_highEndPoint(other.m_highEndPoint) {} 0179 0180 EndPoint lowEndPoint() const { return m_lowEndPoint; } 0181 EndPoint highEndPoint() const { return m_highEndPoint; } 0182 0183 void setEndPoints(const EndPoint &lEndPoint, EndPoint &hEndPoint) 0184 { 0185 m_lowEndPoint = lEndPoint; 0186 m_highEndPoint = hEndPoint; 0187 } 0188 0189 bool operator==(const RealInterval &other) const 0190 { 0191 return (m_lowEndPoint == other.m_lowEndPoint) && (m_highEndPoint == other.m_highEndPoint); 0192 } 0193 0194 RealInterval operator=(const RealInterval& other) 0195 { 0196 m_lowEndPoint = other.m_lowEndPoint; 0197 m_highEndPoint = other.m_highEndPoint; 0198 0199 return *this; 0200 } 0201 0202 private: 0203 EndPoint m_lowEndPoint; 0204 EndPoint m_highEndPoint; 0205 }; 0206 //END private types 0207 QStringList m_errors; 0208 0209 QMap<QString, Analitza::Cn*> m_argumentValues; 0210 QMap<QString, RealInterval > m_argumentIntervals; 0211 }; 0212 0213 } 0214 0215 #endif // ABSTRACTFUNCTIONGRAPH_H