OGS
CreateStructuredGridDialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <QIntValidator>
7
8#include "Base/OGSError.h"
10#include "GeoLib/Point.h"
12
14 : QDialog(parent)
15{
16 setupUi(this);
18}
19
21{
22 auto* origin_x_validator = new StrictDoubleValidator(this);
23 this->xOriginEdit->setValidator(origin_x_validator);
24 auto* origin_y_validator = new StrictDoubleValidator(this);
25 this->yOriginEdit->setValidator(origin_y_validator);
26 auto* origin_z_validator = new StrictDoubleValidator(this);
27 this->zOriginEdit->setValidator(origin_z_validator);
28
29 auto* x_length_validator = new StrictDoubleValidator(0, 10000000, 10, this);
30 this->xLengthEdit->setValidator(x_length_validator);
31 auto* y_length_validator = new StrictDoubleValidator(0, 10000000, 10, this);
32 this->yLengthEdit->setValidator(y_length_validator);
33 auto* z_length_validator = new StrictDoubleValidator(0, 10000000, 10, this);
34 this->zLengthEdit->setValidator(z_length_validator);
35
36 auto* x_n_elem_validator = new QIntValidator(1, 10000000, this);
37 this->xElemEdit->setValidator(x_n_elem_validator);
38 auto* y_n_elem_validator = new QIntValidator(1, 10000000, this);
39 this->yElemEdit->setValidator(y_n_elem_validator);
40 auto* z_n_elem_validator = new QIntValidator(1, 10000000, this);
41 this->zElemEdit->setValidator(z_n_elem_validator);
42}
43
45{
46 this->yLengthLabel->setEnabled(false);
47 this->yLengthEdit->setEnabled(false);
48 this->zLengthLabel->setEnabled(false);
49 this->zLengthEdit->setEnabled(false);
50 this->yElemLabel->setEnabled(false);
51 this->yElemEdit->setEnabled(false);
52 this->zElemLabel->setEnabled(false);
53 this->zElemEdit->setEnabled(false);
54}
55
57{
58 this->yLengthLabel->setEnabled(true);
59 this->yLengthEdit->setEnabled(true);
60 this->zLengthLabel->setEnabled(false);
61 this->zLengthEdit->setEnabled(false);
62 this->yElemLabel->setEnabled(true);
63 this->yElemEdit->setEnabled(true);
64 this->zElemLabel->setEnabled(false);
65 this->zElemEdit->setEnabled(false);
66}
67
69{
70 this->yLengthLabel->setEnabled(true);
71 this->yLengthEdit->setEnabled(true);
72 this->zLengthLabel->setEnabled(true);
73 this->zLengthEdit->setEnabled(true);
74 this->yElemLabel->setEnabled(true);
75 this->yElemEdit->setEnabled(true);
76 this->zElemLabel->setEnabled(true);
77 this->zElemEdit->setEnabled(true);
78}
79
81{
82 this->xLengthLabel->setText("Mesh size in x");
83 this->yLengthLabel->setText("Mesh size in y");
84 this->zLengthLabel->setText("Mesh size in z");
85}
86
88{
89 this->xLengthLabel->setText("Element size in x");
90 this->yLengthLabel->setText("Element size in y");
91 this->zLengthLabel->setText("Element size in z");
92}
93
95{
96 QString const type_str =
97 (this->meshExtentButton->isChecked()) ? "mesh" : "element";
98 if (this->xLengthEdit->text().isEmpty())
99 {
100 OGSError::box("Please specify " + type_str +
101 "\nextent in x-direction.");
102 return true;
103 }
104 if (this->xElemEdit->text().isEmpty())
105 {
106 OGSError::box("Please specify number of\nelements in x-direction.");
107 return true;
108 }
109 if (this->xOriginEdit->text().isEmpty() ||
110 this->yOriginEdit->text().isEmpty() ||
111 this->zOriginEdit->text().isEmpty())
112 {
113 OGSError::box("Please specify coordinates\nof mesh origin.");
114 return true;
115 }
116 if (this->meshNameEdit->text().isEmpty())
117 {
118 OGSError::box("Please specify mesh name.");
119 return true;
120 }
121
122 if (!this->lineButton->isChecked())
123 {
124 if (this->yLengthEdit->text().isEmpty())
125 {
126 OGSError::box("Please specify " + type_str +
127 "\nextent in y-direction.");
128 return true;
129 }
130 if (this->yElemEdit->text().isEmpty())
131 {
132 OGSError::box("Please specify number of\nelements in y-direction.");
133 return true;
134 }
135 }
136
137 if (this->prismButton->isChecked() || this->hexButton->isChecked())
138 {
139 if (this->zLengthEdit->text().isEmpty())
140 {
141 OGSError::box("Please specify " + type_str +
142 "\nextent in z-direction.");
143 return true;
144 }
145 if (this->zElemEdit->text().isEmpty())
146 {
147 OGSError::box("Please specify number of\nelements in z-direction.");
148 return true;
149 }
150 }
151 return false;
152}
153
155{
156 if (inputIsEmpty())
157 {
158 return;
159 }
160
161 if ((this->xLengthEdit->text().toDouble() <= 0) ||
162 (this->yLengthEdit->text().toDouble() <= 0) ||
163 (this->zLengthEdit->text().toDouble() <= 0))
164 {
165 OGSError::box("Length needs to be larger than 0.");
166 return;
167 }
168
169 if ((this->xElemEdit->text().toDouble() <= 0) ||
170 (this->yElemEdit->text().toDouble() <= 0) ||
171 (this->zElemEdit->text().toDouble() <= 0))
172 {
173 OGSError::box("Number of elements needs to be larger than 0.");
174 return;
175 }
176
177 GeoLib::Point const origin(this->xOriginEdit->text().toDouble(),
178 this->yOriginEdit->text().toDouble(),
179 this->zOriginEdit->text().toDouble());
180 std::string const name(this->meshNameEdit->text().toStdString());
181 MeshLib::Mesh* mesh(nullptr);
182 if (this->lineButton->isChecked())
183 {
184 if (this->meshExtentButton->isChecked())
185 {
187 this->xLengthEdit->text().toDouble(),
188 this->xElemEdit->text().toInt(), origin, name);
189 }
190 else
191 {
193 this->xElemEdit->text().toInt(),
194 this->xLengthEdit->text().toDouble(), origin, name);
195 }
196 }
197 else if (this->triButton->isChecked())
198 {
199 if (this->meshExtentButton->isChecked())
200 {
202 this->xLengthEdit->text().toDouble(),
203 this->yLengthEdit->text().toDouble(),
204 this->xElemEdit->text().toInt(),
205 this->yElemEdit->text().toInt(), origin, name);
206 }
207 else
208 {
210 this->xElemEdit->text().toInt(),
211 this->yElemEdit->text().toInt(),
212 this->xLengthEdit->text().toDouble(),
213 this->yLengthEdit->text().toDouble(), origin, name);
214 }
215 }
216 else if (this->quadButton->isChecked())
217 {
218 if (this->meshExtentButton->isChecked())
219 {
221 this->xLengthEdit->text().toDouble(),
222 this->yLengthEdit->text().toDouble(),
223 this->xElemEdit->text().toInt(),
224 this->yElemEdit->text().toInt(), origin, name);
225 }
226 else
227 {
229 this->xElemEdit->text().toInt(),
230 this->yElemEdit->text().toInt(),
231 this->xLengthEdit->text().toDouble(),
232 this->yLengthEdit->text().toDouble(), origin, name);
233 }
234 }
235 else if (this->prismButton->isChecked())
236 {
237 if (this->meshExtentButton->isChecked())
238 {
240 this->xLengthEdit->text().toDouble(),
241 this->yLengthEdit->text().toDouble(),
242 this->zLengthEdit->text().toDouble(),
243 this->xElemEdit->text().toInt(),
244 this->yElemEdit->text().toInt(),
245 this->zElemEdit->text().toInt(), origin, name);
246 }
247 else
248 {
250 this->xLengthEdit->text().toDouble(),
251 this->yLengthEdit->text().toDouble(),
252 this->zLengthEdit->text().toDouble(),
253 this->xElemEdit->text().toInt(),
254 this->yElemEdit->text().toInt(),
255 this->zElemEdit->text().toInt(), origin, name);
256 }
257 }
258 else if (this->hexButton->isChecked())
259 {
260 if (this->meshExtentButton->isChecked())
261 {
263 this->xLengthEdit->text().toDouble(),
264 this->yLengthEdit->text().toDouble(),
265 this->zLengthEdit->text().toDouble(),
266 this->xElemEdit->text().toInt(),
267 this->yElemEdit->text().toInt(),
268 this->zElemEdit->text().toInt(), origin, name);
269 }
270 else
271 {
273 this->xElemEdit->text().toInt(),
274 this->yElemEdit->text().toInt(),
275 this->zElemEdit->text().toInt(),
276 this->xLengthEdit->text().toDouble(),
277 this->yLengthEdit->text().toDouble(),
278 this->zLengthEdit->text().toDouble(), origin, name);
279 }
280 }
281
282 if (mesh == nullptr)
283 {
284 OGSError::box("Error creating mesh.");
285 return;
286 }
287
288 auto* const mat_ids = mesh->getProperties().createNewPropertyVector<int>(
289 "MaterialIDs", MeshLib::MeshItemType::Cell);
290 assert(mat_ids != nullptr);
291 mat_ids->resize(mesh->getNumberOfElements());
292 emit meshAdded(mesh);
293 this->done(QDialog::Accepted);
294}
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:125
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
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:13
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")