OGS
CreateStructuredGridDialog.cpp
Go to the documentation of this file.
1
16
17#include <QIntValidator>
18
19#include "Base/OGSError.h"
21#include "GeoLib/Point.h"
23
25 : QDialog(parent)
26{
27 setupUi(this);
29}
30
32{
33 auto* origin_x_validator = new StrictDoubleValidator(this);
34 this->xOriginEdit->setValidator(origin_x_validator);
35 auto* origin_y_validator = new StrictDoubleValidator(this);
36 this->yOriginEdit->setValidator(origin_y_validator);
37 auto* origin_z_validator = new StrictDoubleValidator(this);
38 this->zOriginEdit->setValidator(origin_z_validator);
39
40 auto* x_length_validator = new StrictDoubleValidator(0, 10000000, 10, this);
41 this->xLengthEdit->setValidator(x_length_validator);
42 auto* y_length_validator = new StrictDoubleValidator(0, 10000000, 10, this);
43 this->yLengthEdit->setValidator(y_length_validator);
44 auto* z_length_validator = new StrictDoubleValidator(0, 10000000, 10, this);
45 this->zLengthEdit->setValidator(z_length_validator);
46
47 auto* x_n_elem_validator = new QIntValidator(1, 10000000, this);
48 this->xElemEdit->setValidator(x_n_elem_validator);
49 auto* y_n_elem_validator = new QIntValidator(1, 10000000, this);
50 this->yElemEdit->setValidator(y_n_elem_validator);
51 auto* z_n_elem_validator = new QIntValidator(1, 10000000, this);
52 this->zElemEdit->setValidator(z_n_elem_validator);
53}
54
56{
57 this->yLengthLabel->setEnabled(false);
58 this->yLengthEdit->setEnabled(false);
59 this->zLengthLabel->setEnabled(false);
60 this->zLengthEdit->setEnabled(false);
61 this->yElemLabel->setEnabled(false);
62 this->yElemEdit->setEnabled(false);
63 this->zElemLabel->setEnabled(false);
64 this->zElemEdit->setEnabled(false);
65}
66
68{
69 this->yLengthLabel->setEnabled(true);
70 this->yLengthEdit->setEnabled(true);
71 this->zLengthLabel->setEnabled(false);
72 this->zLengthEdit->setEnabled(false);
73 this->yElemLabel->setEnabled(true);
74 this->yElemEdit->setEnabled(true);
75 this->zElemLabel->setEnabled(false);
76 this->zElemEdit->setEnabled(false);
77}
78
80{
81 this->yLengthLabel->setEnabled(true);
82 this->yLengthEdit->setEnabled(true);
83 this->zLengthLabel->setEnabled(true);
84 this->zLengthEdit->setEnabled(true);
85 this->yElemLabel->setEnabled(true);
86 this->yElemEdit->setEnabled(true);
87 this->zElemLabel->setEnabled(true);
88 this->zElemEdit->setEnabled(true);
89}
90
92{
93 this->xLengthLabel->setText("Mesh size in x");
94 this->yLengthLabel->setText("Mesh size in y");
95 this->zLengthLabel->setText("Mesh size in z");
96}
97
99{
100 this->xLengthLabel->setText("Element size in x");
101 this->yLengthLabel->setText("Element size in y");
102 this->zLengthLabel->setText("Element size in z");
103}
104
106{
107 QString const type_str =
108 (this->meshExtentButton->isChecked()) ? "mesh" : "element";
109 if (this->xLengthEdit->text().isEmpty())
110 {
111 OGSError::box("Please specify " + type_str +
112 "\nextent in x-direction.");
113 return true;
114 }
115 if (this->xElemEdit->text().isEmpty())
116 {
117 OGSError::box("Please specify number of\nelements in x-direction.");
118 return true;
119 }
120 if (this->xOriginEdit->text().isEmpty() ||
121 this->yOriginEdit->text().isEmpty() ||
122 this->zOriginEdit->text().isEmpty())
123 {
124 OGSError::box("Please specify coordinates\nof mesh origin.");
125 return true;
126 }
127 if (this->meshNameEdit->text().isEmpty())
128 {
129 OGSError::box("Please specify mesh name.");
130 return true;
131 }
132
133 if (!this->lineButton->isChecked())
134 {
135 if (this->yLengthEdit->text().isEmpty())
136 {
137 OGSError::box("Please specify " + type_str +
138 "\nextent in y-direction.");
139 return true;
140 }
141 if (this->yElemEdit->text().isEmpty())
142 {
143 OGSError::box("Please specify number of\nelements in y-direction.");
144 return true;
145 }
146 }
147
148 if (this->prismButton->isChecked() || this->hexButton->isChecked())
149 {
150 if (this->zLengthEdit->text().isEmpty())
151 {
152 OGSError::box("Please specify " + type_str +
153 "\nextent in z-direction.");
154 return true;
155 }
156 if (this->zElemEdit->text().isEmpty())
157 {
158 OGSError::box("Please specify number of\nelements in z-direction.");
159 return true;
160 }
161 }
162 return false;
163}
164
166{
167 if (inputIsEmpty())
168 {
169 return;
170 }
171
172 if ((this->xLengthEdit->text().toDouble() <= 0) ||
173 (this->yLengthEdit->text().toDouble() <= 0) ||
174 (this->zLengthEdit->text().toDouble() <= 0))
175 {
176 OGSError::box("Length needs to be larger than 0.");
177 return;
178 }
179
180 if ((this->xElemEdit->text().toDouble() <= 0) ||
181 (this->yElemEdit->text().toDouble() <= 0) ||
182 (this->zElemEdit->text().toDouble() <= 0))
183 {
184 OGSError::box("Number of elements needs to be larger than 0.");
185 return;
186 }
187
188 GeoLib::Point const origin(this->xOriginEdit->text().toDouble(),
189 this->yOriginEdit->text().toDouble(),
190 this->zOriginEdit->text().toDouble());
191 std::string const name(this->meshNameEdit->text().toStdString());
192 MeshLib::Mesh* mesh(nullptr);
193 if (this->lineButton->isChecked())
194 {
195 if (this->meshExtentButton->isChecked())
196 {
198 this->xLengthEdit->text().toDouble(),
199 this->xElemEdit->text().toInt(), origin, name);
200 }
201 else
202 {
204 this->xElemEdit->text().toInt(),
205 this->xLengthEdit->text().toDouble(), origin, name);
206 }
207 }
208 else if (this->triButton->isChecked())
209 {
210 if (this->meshExtentButton->isChecked())
211 {
213 this->xLengthEdit->text().toDouble(),
214 this->yLengthEdit->text().toDouble(),
215 this->xElemEdit->text().toInt(),
216 this->yElemEdit->text().toInt(), origin, name);
217 }
218 else
219 {
221 this->xElemEdit->text().toInt(),
222 this->yElemEdit->text().toInt(),
223 this->xLengthEdit->text().toDouble(),
224 this->yLengthEdit->text().toDouble(), origin, name);
225 }
226 }
227 else if (this->quadButton->isChecked())
228 {
229 if (this->meshExtentButton->isChecked())
230 {
232 this->xLengthEdit->text().toDouble(),
233 this->yLengthEdit->text().toDouble(),
234 this->xElemEdit->text().toInt(),
235 this->yElemEdit->text().toInt(), origin, name);
236 }
237 else
238 {
240 this->xElemEdit->text().toInt(),
241 this->yElemEdit->text().toInt(),
242 this->xLengthEdit->text().toDouble(),
243 this->yLengthEdit->text().toDouble(), origin, name);
244 }
245 }
246 else if (this->prismButton->isChecked())
247 {
248 if (this->meshExtentButton->isChecked())
249 {
251 this->xLengthEdit->text().toDouble(),
252 this->yLengthEdit->text().toDouble(),
253 this->zLengthEdit->text().toDouble(),
254 this->xElemEdit->text().toInt(),
255 this->yElemEdit->text().toInt(),
256 this->zElemEdit->text().toInt(), origin, name);
257 }
258 else
259 {
261 this->xLengthEdit->text().toDouble(),
262 this->yLengthEdit->text().toDouble(),
263 this->zLengthEdit->text().toDouble(),
264 this->xElemEdit->text().toInt(),
265 this->yElemEdit->text().toInt(),
266 this->zElemEdit->text().toInt(), origin, name);
267 }
268 }
269 else if (this->hexButton->isChecked())
270 {
271 if (this->meshExtentButton->isChecked())
272 {
274 this->xLengthEdit->text().toDouble(),
275 this->yLengthEdit->text().toDouble(),
276 this->zLengthEdit->text().toDouble(),
277 this->xElemEdit->text().toInt(),
278 this->yElemEdit->text().toInt(),
279 this->zElemEdit->text().toInt(), origin, name);
280 }
281 else
282 {
284 this->xElemEdit->text().toInt(),
285 this->yElemEdit->text().toInt(),
286 this->zElemEdit->text().toInt(),
287 this->xLengthEdit->text().toDouble(),
288 this->yLengthEdit->text().toDouble(),
289 this->zLengthEdit->text().toDouble(), origin, name);
290 }
291 }
292
293 if (mesh == nullptr)
294 {
295 OGSError::box("Error creating mesh.");
296 return;
297 }
298
299 auto* const mat_ids = mesh->getProperties().createNewPropertyVector<int>(
300 "MaterialIDs", MeshLib::MeshItemType::Cell);
301 assert(mat_ids != nullptr);
302 mat_ids->resize(mesh->getNumberOfElements());
303 emit meshAdded(mesh);
304 this->done(QDialog::Accepted);
305}
Definition of the CreateStructuredGridDialog class.
Definition of the Point class.
Definition of the OGSError class.
Implementation of the StrictDoubleValidator class.
void accept() override
Instructions if the OK-Button has been pressed.
CreateStructuredGridDialog(QDialog *parent=nullptr)
void meshAdded(MeshLib::Mesh *mesh)
bool inputIsEmpty() const
Checks if all necessary inputs have been specified.
Properties & getProperties()
Definition Mesh.h:134
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
static void box(const QString &e)
Definition OGSError.cpp:23
A validator for an input field which only accepts decimals. Source code adapted from StackOverflow
MeshLib::Mesh * generateLineMesh(const BaseLib::ISubdivision &div, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
MeshLib::Mesh * generateRegularQuadMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
MeshLib::Mesh * generateRegularPrismMesh(const double x_length, const double y_length, const double z_length, const std::size_t x_subdivision, const std::size_t y_subdivision, const std::size_t z_subdivision, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
MeshLib::Mesh * generateRegularTriMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
MeshLib::Mesh * generateRegularHexMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")