File indexing completed on 2024-12-22 04:17:52

0001 /***************************************************************************
0002                           vcurve.h: defines a curve for kst
0003                              -------------------
0004     begin                : Fri Oct 22 2000
0005     copyright            : (C) 2000 by C. Barth Netterfield
0006     email                : netterfield@astro.utoronto.ca
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #ifndef CURVE_H
0019 #define CURVE_H
0020 
0021 #include "relation.h"
0022 #include "painter.h"
0023 #include "curvepointsymbol.h"
0024 #include "kstmath_export.h"
0025 #include "labelinfo.h"
0026 
0027 #include <QStack>
0028 
0029 /**A class for handling curves for kst
0030  *@author C. Barth Netterfield
0031  */
0032 
0033 #define CURVE_DEFAULT_POINT_SIZE 12
0034 
0035 namespace Kst {
0036 
0037 class KSTMATH_EXPORT Curve: public Relation 
0038 {
0039     Q_OBJECT
0040 
0041   public:
0042     static const QString staticTypeString;
0043     const QString& typeString() const { return staticTypeString; }
0044     static const QString staticTypeTag;
0045 
0046     virtual void internalUpdate();
0047     virtual QString propertyString() const;
0048 
0049     virtual int getIndexNearXY(double x, double dx, double y) const;
0050 
0051     virtual bool hasXError() const;
0052     virtual bool hasYError() const;
0053     virtual bool hasXMinusError() const;
0054     virtual bool hasYMinusError() const;
0055 
0056     // Note: these are -expensive-.  Don't use them on inner loops!
0057     virtual void point(int i, double &x1, double &y1) const;
0058     virtual void getEXPoint(int i, double &x1, double &y1, double &ex1);
0059     virtual void getEYPoint(int i, double &x1, double &y1, double &ey1);
0060     virtual void getEXMinusPoint(int i, double &x1, double &y1, double &ex1);
0061     virtual void getEYMinusPoint(int i, double &x1, double &y1, double &ey1);
0062     virtual void getEXPoints(int i, double &x, double &y, double &ex, double &exminus);
0063     virtual void getEYPoints(int i, double &x, double &y, double &ey, double &eyminus);
0064 
0065     void setXVector(VectorPtr new_vx);
0066     void setYVector(VectorPtr new_vy);
0067     void setXError(VectorPtr new_ex);
0068     void setYError(VectorPtr new_ey);
0069     void setXMinusError(VectorPtr new_ex);
0070     void setYMinusError(VectorPtr new_ey);
0071 
0072     /** Save curve information */
0073     void save(QXmlStreamWriter &s);
0074 
0075     virtual bool xIsRising() const;
0076 
0077     virtual double maxX() const;
0078     virtual double minX() const;
0079 
0080     virtual double meanX() const { return MeanX; }
0081     virtual double meanY() const { return MeanY; }
0082     virtual void yRange(double xFrom, double xTo, double* yMin, double* yMax);
0083 
0084     virtual double ns_maxX(int) const;
0085     virtual double ns_minX(int) const;
0086     virtual double ns_maxY(int) const;
0087     virtual double ns_minY(int) const;
0088 
0089     virtual int samplesPerFrame() const;
0090 
0091     virtual void showNewDialog();
0092     virtual void showEditDialog();
0093 
0094     VectorPtr xVector() const;
0095     VectorPtr yVector() const;
0096     VectorPtr xErrorVector() const;
0097     VectorPtr yErrorVector() const;
0098     VectorPtr xMinusErrorVector() const;
0099     VectorPtr yMinusErrorVector() const;
0100 
0101     virtual bool hasPoints()    const { return HasPoints; }
0102     virtual bool hasLines()     const { return HasLines; }
0103     virtual bool hasBars()      const { return HasBars; }
0104     virtual bool hasHead()      const { return HasHead; }
0105     virtual void setHasPoints(bool in_HasPoints);
0106     virtual void setHasLines(bool in_HasLines);
0107     virtual void setHasBars(bool in_HasBars);
0108     virtual void setHasHead(bool in_HasHead);
0109     virtual void setLineWidth(int in_LineWidth);
0110     virtual void setLineStyle(int in_LineStyle);
0111     virtual void setPointDensity(int in_PointDensity);
0112     virtual void setPointType(int in_PointType);
0113     virtual void setPointSize(double in_PointSize);
0114     virtual void setHeadType(int in_HeadType);
0115 
0116     virtual int lineWidth()     const { return LineWidth; }
0117     static double lineDim(const QRectF &R, double linewidth);
0118     virtual int lineStyle()     const { return LineStyle; }
0119     virtual int pointDensity()  const { return PointDensity; }
0120     virtual int pointType()  const { return PointType; }
0121     virtual int headType()  const { return HeadType; }
0122     virtual double pointSize() const { return PointSize; }
0123     virtual double pointDim(QRectF w) const;
0124 
0125     virtual QColor color() const { return Color; }
0126     virtual void setColor(const QColor& new_c);
0127 
0128     virtual QColor barFillColor() const { return BarFillColor; }
0129     virtual void setBarFillColor(const QColor& new_c);
0130 
0131     virtual QColor headColor() const { return HeadColor; }
0132     virtual void setHeadColor(const QColor& new_c);
0133 
0134 #if 0
0135     void pushColor(const QColor& c) { _colorStack.push(color()); setColor(c); }
0136     void popColor() { setColor(_colorStack.pop()); }
0137     void pushLineWidth(int w) { _widthStack.push(lineWidth()); setLineWidth(w); }
0138     void popLineWidth() { setLineWidth(_widthStack.pop()); }
0139     void pushLineStyle(int s) { _lineStyleStack.push(lineStyle()); setLineStyle(s); }
0140     void popLineStyle() { setLineStyle(_lineStyleStack.pop()); }
0141     void pushPointStyle(int s) { _pointStyleStack.push(PointType); PointType = s; }
0142     void popPointStyle() { PointType = _pointStyleStack.pop(); }
0143     void pushHasPoints(bool h) { _hasPointsStack.push(hasPoints()); setHasPoints(h); }
0144     void popHasPoints() { setHasPoints(_hasPointsStack.pop()); }
0145     void pushHasLines(bool h) { _hasLinesStack.push(hasLines()); setHasLines(h); }
0146     void popHasLines() { setHasLines(_hasLinesStack.pop()); }
0147     void pushPointDensity(int d) { _pointDensityStack.push(pointDensity()); setPointDensity(d); }
0148     void popPointDensity() { setPointDensity(_pointDensityStack.pop()); }
0149 #endif
0150 
0151     //virtual RelationPtr makeDuplicate(QMap<RelationPtr, RelationPtr> &duplicatedRelations);
0152     virtual RelationPtr makeDuplicate() const;
0153 
0154     // render this curve
0155     virtual void paintObjects(const CurveRenderContext& context);
0156 
0157     // Update the curve details.
0158     void updatePaintObjects(const CurveRenderContext& context);
0159 
0160     // render the legend symbol for this curve
0161     virtual QSize legendSymbolSize(QPainter *p);
0162     virtual void paintLegendSymbol(QPainter *p, const QSize &size);
0163     virtual bool symbolLabelOnTop() {return false;}
0164 
0165     // see KstRelation::distanceToPoint
0166     virtual double distanceToPoint(double xpos, double dx, double ypos) const;
0167 
0168     virtual QString descriptionTip() const;
0169 
0170     // labels for plots
0171     virtual LabelInfo xLabelInfo() const;
0172     virtual LabelInfo yLabelInfo() const;
0173     virtual LabelInfo titleInfo() const;
0174 
0175     virtual ScriptInterface* createScriptInterface();
0176 
0177   protected:
0178     Curve(ObjectStore *store);
0179 
0180     virtual ~Curve();
0181 
0182     friend class ObjectStore;
0183 
0184     virtual QString _automaticDescriptiveName() const;
0185     virtual void _initializeShortName();
0186 
0187   private:
0188     double MeanY;
0189 
0190     int LineWidth;
0191     int LineStyle;
0192     int PointDensity;
0193     int PointType;
0194     double PointSize;
0195     int HeadType;
0196 
0197     bool HasPoints;
0198     bool HasLines;
0199     bool HasBars;
0200     bool HasHead;
0201 
0202     QColor Color;
0203     QColor HeadColor;
0204     QColor BarFillColor;
0205 
0206 #if 0
0207     QStack<int> _widthStack;
0208     QStack<QColor> _colorStack;
0209     QStack<int> _pointStyleStack;
0210     QStack<int> _lineStyleStack;
0211     QStack<bool> _hasPointsStack;
0212     QStack<bool> _hasLinesStack;
0213     QStack<int> _pointDensityStack;
0214 #endif
0215 
0216     QVector<QPolygonF> _polygons;
0217     QVector<QLineF> _lines;
0218     QVector<QPointF> _points;
0219     QVector<QRectF> _filledRects;
0220     QVector<QRectF> _rects;
0221     QPointF _head;
0222     bool _head_valid;
0223 
0224     int _width;
0225 };
0226 
0227 typedef SharedPtr<Curve> CurvePtr;
0228 typedef ObjectList<Curve> CurveList;
0229 
0230 }
0231 
0232 Q_DECLARE_METATYPE(Kst::Curve*)
0233 
0234 #endif
0235 // vim: ts=2 sw=2 et