1 /****************************************************************************
2 **  Copyright (c) 2019, Adel Kara Slimane <adel.ks@zegrapher.com>
3 **
4 **  This file is part of ZeGrapher's source code.
5 **
6 **  ZeGrapher is free software: you may copy, redistribute and/or modify it
7 **  under the terms of the GNU General Public License as published by the
8 **  Free Software Foundation, either version 3 of the License, or (at your
9 **  option) any later version.
10 **
11 **  This file is distributed in the hope that it will be useful, but
12 **  WITHOUT ANY WARRANTY; without even the implied warranty of
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 **  General Public License for more details.
15 **
16 **  You should have received a copy of the GNU General Public License
17 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 **
19 ****************************************************************************/
20 
21 #ifndef GRAPHVIEW_H
22 #define GRAPHVIEW_H
23 
24 #include <QObject>
25 #include <QWidget>
26 #include <QRectF>
27 #include <QPair>
28 
29 #define TARGET_TICKS_NUM 20
30 
31 #include "structures.h"
32 
33 
34 struct ZeLogAxisTick
35 {
36     double pos;
37     QString baseStr, globalConstantStr;
38     double base, globalConstant;
39     long multiplier, subMultiplier, powerNumerator, powerDenominator;
40 };
41 
42 struct ZeLinAxisTick
43 {
44     double pos, multiplier;
45 };
46 
47 struct ZeAxisSubTick
48 {
49     double pos;
50     int numerator, denominator;
51 };
52 
53 struct ZeOffset
54 {
55     double sumOffset, powerOffset;
56 };
57 
58 struct ZeLogAxisTicks
59 {
60     QList<ZeLogAxisTick> ticks;
61     QList<ZeAxisSubTick> axisSubticks;
62 };
63 
64 struct ZeLinAxisTicks
65 {
66     ZeOffset offset;
67     QList<ZeLinAxisTick> ticks;
68     QList<ZeAxisSubTick> axisSubticks;
69 };
70 
71 class ZeViewMapper : public QObject
72 {
73     Q_OBJECT
74 
75 public:
76     explicit ZeViewMapper(QObject *parent = nullptr);
77 
78     ZeViewMapper(const ZeViewMapper &other,
79                 QObject *parent = nullptr);
80 
81     ZeViewMapper& operator=(const ZeViewMapper &other);
82 
83     void zoomYview(double ratio);
84     void zoomXview(double ratio);
85     void zoomView(QPointF center, double ratio);
86     void translateView(QPointF vec);
87 
88     void setViewSettings(const ZeViewSettings &viewSettings);
89 
90     void setViewXmin(double val);
91     void setViewXmax(double val);
92     void setViewYmin(double val);
93     void setViewYmax(double val);
94 
95     void setlgXmin(double val);
96     void setlgXmax(double val);
97     void setlgYmin(double val);
98     void setlgYmax(double val);
99 
100     void setXmin(double val);
101     void setXmax(double val);
102     void setYmin(double val);
103     void setYmax(double val);
104 
105     void setGraphRange(const GraphRange &range);
106     GraphRange getGraphRange();
107 
108     double getXmin();
109     double getXmax();
110     double getYmin();
111     double getYmax();
112 
113     double viewToUnitY(double viewY) const;
114     double unitToViewY(double unitY) const ;
115 
116     double viewToUnitX(double viewX) const ;
117     double unitToViewX(double unitX) const ;
118 
119     ZeLinAxisTicks getLinearAxisTicks(double pxWidth,
120                                    ZeAxisRange range,
121                                    ZeAxisName axisName,
122                                    QFontMetrics metrics);
123 
124     QRectF getRect() const ;
125     QRectF getLogRect() const ;
126     QRectF getViewRect() const ;
127     void setViewRect(QRectF getRect);
128 
129 signals:
130 
131 public slots:
132 
133 protected:
134 
135     void verifyOrthonormality();
136 
137     double Xmin, Xmax, Ymin, Ymax;
138     double lgXmin, lgXmax, lgYmin, lgYmax;
139 
140     QSizeF viewPxSize;
141     double targetTicksNum;
142 
143     ZeAxesSettings axesSettings;
144     ZeGridSettings gridSettings;
145 };
146 
147 #endif // GRAPHVIEW_H
148