API Documentation
Loading...
Searching...
No Matches
CustomDesignChart.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/NDEVRChart.h>
3#include <NDEVR/QTDesignObject.h>
4#include <NDEVR/QCustomCombobox.h>
5#include <NDEVR/QCustomLabel.h>
6#include <NDEVR/DesignParameter.h>
7#include <NDEVR/DesignParameterAccumulator.h>
8#include <NDEVR/SnapLocation.h>
9#include <NDEVR/DesignObjectLookup.h>
10#include <NDEVR/FeatureOptions.h>
11#include <NDEVR/Translator.h>
12#include <QHBoxLayout>
13namespace NDEVR
14{
16 {
17 public:
18 CustomDesignChart(DesignObjectLookup* lookup, QWidget* parent = nullptr)
19 : NDEVRChart(parent)
20 , m_manager(lookup)
21 {
22 m_locked_axes = false;
23 }
25 {
26 if (m_parameters[X].column_name.size() == 0)
27 return;
28 if (m_parameters[Y].column_name.size() == 0)
29 return;
31
32 BitFlag flag(0);
37 DesignParameterAccumulator h_accumulator(m_parameters[X], flag);
38 h_accumulator.use_unit = false;
39 h_accumulator.parseAll(models);
40 DesignParameterAccumulator v_accumulator(m_parameters[Y], flag);
41 v_accumulator.use_unit = false;
42 v_accumulator.parseAll(models);
43 setTitle(_td("custom_plot_title", "[X] Vs [Y]").replace("[X]", m_parameters[X].displayName()).replace("[Y]", m_parameters[Y].displayName()));
44
45 if (v_accumulator.float_values.size() != h_accumulator.float_values.size() || h_accumulator.float_values.size() == 0)
46 {
47 clearAll();
48 }
49 else
50 {
51 Buffer<Vector<2, fltp04>> initial_data;
52 for (uint04 i = 0; i < h_accumulator.float_values.size(); i++)
53 {
54 if (isNaN(h_accumulator.float_values[i]))
55 continue;
56 if (isNaN(v_accumulator.float_values[i]))
57 continue;
58 if (m_bounds[MIN][X] > h_accumulator.float_values[i])
59 continue;
60 if (m_bounds[MAX][X] < h_accumulator.float_values[i])
61 continue;
62 if (m_bounds[MIN][Y] > v_accumulator.float_values[i])
63 continue;
64 if (m_bounds[MAX][Y] < v_accumulator.float_values[i])
65 continue;
66 initial_data.add(Vector<2, fltp04>(h_accumulator.float_values[i], v_accumulator.float_values[i]));
67
68 }
69
70 PlotData plot_data;
71 //plot_data.point_data;
72 plot_data.pen = QPen(QTTools::convert(RGBColor(200, 200, 200)));
73 uint04 jump = (initial_data.size() / 10000) + 1;
74 for (uint04 i = 0; i < initial_data.size(); i += jump)
75 {
76 Vertex<3, fltp08> vert(initial_data[i][X], 0.0, initial_data[i][Y]);
77 plot_data.point_data.add(vert);
78 }
79 setData(plot_data);
81
82 }
83 }
85 {
86 m_parameters[X] = param;
87 setSideAxes(m_parameters[X].displayName().translation(), m_parameters[Y].displayName().translation());
88 }
90 {
91 m_parameters[Y] = param;
92 setSideAxes(m_parameters[X].displayName().translation(), m_parameters[Y].displayName().translation());
93 }
94 void setUUID(const UUID& id)
95 {
96 m_object_ids = { id };
97 }
98 Bounds<2, fltp08> bounds() const { return m_bounds; }
100 protected:
105
106 };
107
108 class CustomDesignChartDialog : public QWidget
109 {
110 public:
111 CustomDesignChartDialog(const DynamicPointer<QTDesignObject>& object, QWidget* parent = nullptr)
112 : QWidget(parent)
113 , m_chart(new CustomDesignChart(object->manager()))
120 {
121 m_chart->setUUID(object->uuid());
122 setWindowTitle(_tqs("Plot Data"));
123 QVBoxLayout* layout = new QVBoxLayout();
124 layout->addWidget(m_chart);
125
126
127 setupCombo(_t("Horizontal Axis"), m_h_combo);
128 setupCombo(_t("Vertical Axis"), m_v_combo);
129
130 connect(m_h_combo, &QCustomComboBox::edited, this, [this]
131 {
135 m_h_min_edit->clear();
137 m_h_max_edit->clear();
139 });
140 connect(m_v_combo, &QCustomComboBox::edited, this, [this]
141 {
145 m_v_min_edit->clear();
147 m_v_max_edit->clear();
149 });
150
151 setupLineEdit(_t("X Min"), m_h_min_edit, MIN, X);
152 setupLineEdit(_t("X Max"), m_h_max_edit, MAX, X);
153 setupLineEdit(_t("Y Min"), m_v_min_edit, MIN, Y);
154 setupLineEdit(_t("Y Max"), m_v_max_edit, MAX, Y);
155 QHBoxLayout* h_layout = new QHBoxLayout();
156
157 h_layout->addWidget(new QCustomLabel(_t("Vertical")));
158 h_layout->addWidget(m_v_combo);
159 h_layout->addWidget(m_v_min_edit);
160 h_layout->addWidget(m_v_max_edit);
161
162 h_layout->addWidget(new QCustomLabel(_t("Horizontal")));
163 h_layout->addWidget(m_h_combo);
164 h_layout->addWidget(m_h_min_edit);
165 h_layout->addWidget(m_h_max_edit);
166 layout->addLayout(h_layout);
167 setLayout(layout);
168
169
170 }
171 void setupLineEdit(const TranslatedString& label, QCustomLineEdit* edit, uint01 min_max, uint01 axis)
172 {
173 edit->setup<fltp08>(label);
174 edit->customValidator().setAllowEmpty(true);
175 connect(edit, &QCustomLineEdit::editingFinishedSignal, this, [this, min_max, axis, edit]
176 {
177 Bounds<2, fltp08> axis_scale = m_chart->bounds();
178 axis_scale[min_max][axis] = edit->getUnitValue();
179 m_chart->setBounds(axis_scale);
181 });
182 edit->setPlaceholderText(label.translation().getAs<QString>());
183 edit->setAllowPlaceholderAsValue(false);
184 }
186 {
188
189 m_h_min_edit->clear();
190 m_v_min_edit->clear();
191 m_h_max_edit->clear();
192 m_v_max_edit->clear();
193 }
194 void setupCombo(const TranslatedString& title, QCustomComboBox* combo)
195 {
198 {
199 params.add(DesignParameter("intensity"));
200 params.add(DesignParameter("distance"));
201 params.add(DesignParameter("scan_time"));
202 params.add(DesignParameter("pitch"));
203 params.add(DesignParameter("roll"));
204 }
205#if true
206 params.add(DesignParameter("real"));
207 params.add(DesignParameter("imaginary"));
208#endif
215 if (!m_object.isNull() && m_object->is<Model>())
216 {
217 //Model model = m_target->getAs<Model>();
219 finder.parseAll(m_object->getAs<Model>());
220 for (uint04 i = params.size() - 1; !isNaN(i); i--)
221 {
222 if (!finder.parameters.contains(params[i]))
223 params.removeIndex(i);
224 }
225 }
226 Buffer<TranslatedString> display_items(params.size());
227 Buffer<String> items(params.size());
228 for (uint04 i = 0; i < params.size(); i++)
229 {
230 display_items.add(params[i].displayName());
231 items.add(params[i].stringID());
232 }
233 combo->setup(title, items, display_items);
234 }
235 protected:
244 };
245
246}
#define _tqs(var)
Definition QTTools.h:193
#define _t(english_string)
Definition Translator.h:87
#define _td(def, english_string)
Definition Translator.h:91
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
Definition BitFlag.hpp:68
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void removeIndex(t_index_type location)
Definition Buffer.hpp:1037
Definition GraphicsPipeline.h:42
Definition CustomDesignChart.h:109
QCustomLineEdit * m_v_max_edit
Definition CustomDesignChart.h:243
CustomDesignChart * m_chart
Definition CustomDesignChart.h:237
QCustomLineEdit * m_h_max_edit
Definition CustomDesignChart.h:241
QCustomComboBox * m_v_combo
Definition CustomDesignChart.h:239
DynamicPointer< QTDesignObject > m_object
Definition CustomDesignChart.h:236
void setupLineEdit(const TranslatedString &label, QCustomLineEdit *edit, uint01 min_max, uint01 axis)
Definition CustomDesignChart.h:171
QCustomLineEdit * m_h_min_edit
Definition CustomDesignChart.h:240
void clearBounds()
Definition CustomDesignChart.h:185
QCustomComboBox * m_h_combo
Definition CustomDesignChart.h:238
QCustomLineEdit * m_v_min_edit
Definition CustomDesignChart.h:242
void setupCombo(const TranslatedString &title, QCustomComboBox *combo)
Definition CustomDesignChart.h:194
CustomDesignChartDialog(const DynamicPointer< QTDesignObject > &object, QWidget *parent=nullptr)
Definition CustomDesignChart.h:111
Definition CustomDesignChart.h:16
Bounds< 2, fltp08 > m_bounds
Definition CustomDesignChart.h:104
void updateChart()
Definition CustomDesignChart.h:24
void setHorizontalParameter(const DesignParameter &param)
Definition CustomDesignChart.h:84
void setVerticalParameter(const DesignParameter &param)
Definition CustomDesignChart.h:89
Buffer< UUID > m_object_ids
Definition CustomDesignChart.h:102
DesignObjectLookup * m_manager
Definition CustomDesignChart.h:103
CustomDesignChart(DesignObjectLookup *lookup, QWidget *parent=nullptr)
Definition CustomDesignChart.h:18
DesignParameter m_parameters[2]
Definition CustomDesignChart.h:101
Bounds< 2, fltp08 > bounds() const
Definition CustomDesignChart.h:98
void setUUID(const UUID &id)
Definition CustomDesignChart.h:94
void setBounds(const Bounds< 2, fltp08 > &bounds)
Definition CustomDesignChart.h:99
Definition DesignObjectLookup.h:61
Buffer< Model > getModelsByID(const Buffer< UUID > &ids) const
Definition DesignObjectLookup.cpp:1588
Definition DesignParameterAccumulator.h:57
Buffer< fltp08 > float_values
Definition DesignParameterAccumulator.h:120
@ e_get_floats
Definition DesignParameterAccumulator.h:68
Definition DesignParameterAccumulator.h:45
Buffer< DesignParameter > parameters
Definition DesignParameterAccumulator.h:52
Definition DesignParameter.h:42
ConstPointer< Unit > defaultUnit() const
Definition DesignParameter.cpp:175
Definition Pointer.hpp:303
static String supports_scanner
Definition FeatureOptions.h:21
static bool IsFeatureEnabled(const String &resource)
Definition FeatureOptions.cpp:112
Definition Model.h:54
bool use_unit
Definition ModelIterator.h:77
void parseAll(const Model &model)
Definition ModelIterator.cpp:27
Definition NDEVRChart.h:14
ConstPointer< Unit > m_unit[2]
Definition NDEVRChart.h:81
void updateAxisScale(Bounds< 3, fltp08 > override_bounds=Constant< Bounds< 3, fltp08 > >::NaN)
Definition NDEVRChart.cpp:423
void setTitle(const TranslatedString &title)
Definition NDEVRChart.cpp:108
bool m_locked_axes
Definition NDEVRChart.h:79
void setSideAxes(const String &x_name, const String &y_name)
Definition NDEVRChart.cpp:65
void clearAll()
Definition NDEVRChart.cpp:408
void setData(const PlotData &value)
Definition NDEVRChart.cpp:123
ConstPointer< Unit > m_coordinate_unit
Definition NDEVRChart.h:80
Definition QCustomCombobox.h:47
void setup(const TranslatedString &title, const Buffer< TranslatedString > &values)
Definition QCustomCombobox.cpp:198
t_type getAs() const
Definition QCustomCombobox.h:191
Definition QCustomLabel.h:42
Definition QCustomLineEdit.h:118
void setup(const TranslatedString &title)
Definition QCustomLineEdit.h:156
fltp08 getUnitValue(bool allow_placeholder=true) const
Definition QCustomLineEdit.cpp:300
void setPlaceholderText(const QString &value)
Definition QCustomLineEdit.cpp:670
void setAllowPlaceholderAsValue(bool allow)
Definition QCustomLineEdit.cpp:445
QCustomValidator & customValidator()
Definition QCustomLineEdit.cpp:56
void setConstantUnit(const ConstPointer< Unit > &unit, uint01 dimension=Constant< uint01 >::NaN)
Definition QCustomLineEdit.cpp:64
void setAllowEmpty(bool allow_empty)
Definition QCustomValidator.h:76
static QColor convert(const RGBColor &color)
Definition QTTools.cpp:144
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
Definition String.h:40
t_type getAs() const
Definition String.h:334
Definition TranslatedString.h:9
NDEVR_BASE_API const String & translation() const
Definition TranslatedString.cpp:104
Definition UUID.h:66
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
A vertex.
Definition Vertex.hpp:54
Definition ACIColor.h:37
@ MIN
Definition BaseValues.hpp:226
@ MAX
Definition BaseValues.hpp:227
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ Z
Definition BaseValues.hpp:204
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272
Definition NDEVRChart.h:18
QPen pen
Definition NDEVRChart.h:22
Buffer< Vertex< 3, fltp08 > > point_data
Definition NDEVRChart.h:21