Repository navigation
Expand file tree
/
Copy pathItem2D.cpp
More file actions
235 lines (217 loc) · 6.43 KB
/
Copy pathItem2D.cpp
File metadata and controls
235 lines (217 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "wplot/Item2D.h"
#include "wplot/Plot2D.h"
namespace WPlot {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
Item2D::Item2D() :
Layer2D(),
m_positionAxisType(AXIS_BOTH),
m_dimensionsAxisType(AXIS_BOTH),
m_positionCoordinateType(COORDINATE_WIDGET),
m_dimensionsCoordinateType(COORDINATE_WIDGET)
{}
/**
* Set the coordinate system for both axes.
*
* @param[in] type Coordiante type.
* @param[in] axisType Axis type.
*/
void Item2D::setCoordinates(const Item2D::CoordinateType &type, const Item2D::AxisType &axisType) {
setPivotCoordinates(type, axisType);
setDimensionCoordinates(type, axisType);
}
/**
* Set the coordinate sistem for item position.
*
* @param[in] type Coordiante type.
* @param[in] axisType Axis type.
*/
void Item2D::setPivotCoordinates(const Item2D::CoordinateType &type, const Item2D::AxisType &axisType) {
m_positionCoordinateType = type;
m_positionAxisType = axisType;
}
/**
* Set the coordinate sistem for item dimensions.
*
* @param[in] type Coordiante type.
* @param[in] axisType Axis type.
*/
void Item2D::setDimensionCoordinates(const Item2D::CoordinateType &type, const Item2D::AxisType &axisType) {
m_dimensionsCoordinateType = type;
m_dimensionsAxisType = axisType;
}
/**
* Set the item pivot. This is used in order to place the item inside the plot.
*
* @param[in] pivot Pivot coordinates.
*/
void Item2D::setPivot(const QPointF &pivot) {
m_pivot = pivot;
}
/**
* Set the item pivot. This is used in order to place the item inside the plot.
*
* @param[in] x \f$X\f$ coordinate.
* @param[in] y \f$Y\f$ coordinate.
*/
void Item2D::setPivot(const double &x, const double &y) {
m_pivot.setX(x);
m_pivot.setY(y);
}
/**
* Retrieve the position in scaled coordinates, that are widget ones.
*
* @param[in] coords Coordinates in specified system.
* @param[in] plot Plot.
*
* @return Coordinates in widget system.
*/
QPointF Item2D::getScaledPosition(const QPointF &coords, const Plot2D *plot) const {
return getScaledPosition(coords.x(), coords.y(), plot);
}
/**
* Retrieve the position in scaled coordinates, that are widget ones.
*
* @param[in] x \f$X\f$ coordinate.
* @param[in] y \f$Y\f$ coordinate.
* @param[in] plot Plot.
*
* @return Coordinates in widget system.
*/
QPointF Item2D::getScaledPosition(const double &x, const double &y, const Plot2D *plot) const {
return QPointF(getScaledPositionX(x, plot), getScaledPositionY(y, plot));
}
/**
* Retrieve the \f$X\f$ coordinate in scaled coordinates, that are widget ones.
*
* @param[in] x \f$X\f$ coordinate.
* @param[in] plot Plot.
*
* @return Coordinates in widget system.
*/
double Item2D::getScaledPositionX(const double &x, const Plot2D *plot) const {
switch(m_positionCoordinateType) {
case COORDINATE_PLOT : {
return m_positionAxisType == AXIS_Y ? plot->scalePointY(x) : plot->scalePointX(x);
} break;
case COORDINATE_SCALED : {
const int dim = m_positionAxisType == AXIS_Y ? plot->height() : plot->width();
return static_cast<double>(dim) * x;
} break;
case COORDINATE_WIDGET :
default : {
return x;
}
}
return double();
}
/**
* Retrieve the \f$Y\f$ coordinate in scaled coordinates, that are widget ones.
*
* @param[in] y \f$Y\f$ coordinate.
* @param[in] plot Plot.
*
* @return Coordinates in widget system.
*/
double Item2D::getScaledPositionY(const double &y, const Plot2D *plot) const {
switch(m_positionCoordinateType) {
case COORDINATE_PLOT : {
return m_positionAxisType == AXIS_X ? plot->scalePointX(y) : plot->scalePointY(y);
} break;
case COORDINATE_SCALED : {
const int dim = m_positionAxisType == AXIS_X ? plot->width() : plot->height();
return static_cast<double>(dim) * y;
} break;
case COORDINATE_WIDGET :
default : {
return y;
}
}
return double();
}
/**
* Retrieve the dimensions in scaled coordinates, that are widget ones.
*
* @param[in] dimensions Dimensions in specified system.
* @param[in] plot Plot.
*
* @return Dimensions in widget system.
*/
QPointF Item2D::getScaledDimensions(const QPointF &dimensions, const Plot2D *plot) const {
return getScaledDimensions(dimensions.x(), dimensions.y(), plot);
}
/**
* Retrieve the dimensions in scaled coordinates, that are widget ones.
*
* @param[in] dimensions Dimensions in specified system.
* @param[in] plot Plot.
*
* @return Dimensions in widget system.
*/
QPointF Item2D::getScaledDimensions(const QSizeF &dimensions, const Plot2D *plot) const {
return getScaledDimensions(dimensions.width(), dimensions.height(), plot);
}
/**
* Retrieve the dimensions in scaled coordinates, that are widget ones.
*
* @param[in] x \f$X\f$ dimension.
* @param[in] y \f$Y\f$ dimension.
* @param[in] plot Plot.
*
* @return Dimensions in widget system.
*/
QPointF Item2D::getScaledDimensions(const double &x, const double &y, const Plot2D *plot) const {
return QPointF(getScaledDimensionX(x, plot), getScaledDimensionY(y, plot));
}
/**
* Retrieve the \f$X\f$ dimension in scaled coordinates, that are widget ones.
*
* @param[in] x \f$X\f$ dimension.
* @param[in] plot Plot.
*
* @return Dimension.
*/
double Item2D::getScaledDimensionX(const double &x, const Plot2D *plot) const {
switch(m_dimensionsCoordinateType) {
case COORDINATE_PLOT : {
const auto origin = plot->getScreenOrigin();
return m_dimensionsAxisType == AXIS_Y ? plot->scalePointY(x) - origin.y() : plot->scalePointX(x) - origin.x();
} break;
case COORDINATE_SCALED : {
const int dim = m_dimensionsAxisType == AXIS_Y ? plot->height() : plot->width();
return static_cast<double>(dim) * x;
} break;
case COORDINATE_WIDGET :
default : {
return x;
}
}
return double();
}
/**
* Retrieve the \f$Y\f$ dimension in scaled coordinates, that are widget ones.
*
* @param[in] y \f$Y\f$ dimension.
* @param[in] plot Plot.
*
* @return Dimension.
*/
double Item2D::getScaledDimensionY(const double &y, const Plot2D *plot) const {
switch(m_dimensionsCoordinateType) {
case COORDINATE_PLOT : {
const auto origin = plot->getScreenOrigin();
return m_dimensionsAxisType == AXIS_X ? plot->scalePointX(y) - origin.x() : plot->scalePointY(y) - origin.y();
} break;
case COORDINATE_SCALED : {
const int dim = m_dimensionsAxisType == AXIS_X ? plot->width() : plot->height();
return static_cast<double>(dim) * y;
} break;
case COORDINATE_WIDGET :
default : {
return y;
}
}
return double();
}
} // namespace WPlot