OGS
CreateStructuredGridDialog Class Reference

Detailed Description

A dialog window for managing general Data Explorer settings.

Definition at line 25 of file CreateStructuredGridDialog.h.

#include <CreateStructuredGridDialog.h>

Inheritance diagram for CreateStructuredGridDialog:
[legend]
Collaboration diagram for CreateStructuredGridDialog:
[legend]

Signals

void meshAdded (MeshLib::Mesh *mesh)
 

Public Member Functions

 CreateStructuredGridDialog (QDialog *parent=nullptr)
 

Private Slots

void on_lineButton_toggled () const
 
void on_triButton_toggled () const
 
void on_quadButton_toggled () const
 
void on_prismButton_toggled () const
 
void on_hexButton_toggled () const
 
void on_meshExtentButton_toggled ()
 
void on_elemExtentButton_toggled ()
 
void accept () override
 Instructions if the OK-Button has been pressed.
 
void reject () override
 Instructions if the Cancel-Button has been pressed.
 

Private Member Functions

void enable2dWidgets () const
 
void enable3dWidgets () const
 
void setValidators ()
 
bool inputIsEmpty () const
 Checks if all necessary inputs have been specified.
 

Constructor & Destructor Documentation

◆ CreateStructuredGridDialog()

CreateStructuredGridDialog::CreateStructuredGridDialog ( QDialog * parent = nullptr)
explicit

Definition at line 24 of file CreateStructuredGridDialog.cpp.

25 : QDialog(parent)
26{
27 setupUi(this);
29}

References setValidators().

Member Function Documentation

◆ accept

void CreateStructuredGridDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed.

Definition at line 165 of file CreateStructuredGridDialog.cpp.

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}
void meshAdded(MeshLib::Mesh *mesh)
bool inputIsEmpty() const
Checks if all necessary inputs have been specified.
static void box(const QString &e)
Definition OGSError.cpp:23
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")

References OGSError::box(), MeshLib::Cell, MeshLib::Properties::createNewPropertyVector(), MeshToolsLib::MeshGenerator::generateLineMesh(), MeshToolsLib::MeshGenerator::generateRegularHexMesh(), MeshToolsLib::MeshGenerator::generateRegularPrismMesh(), MeshToolsLib::MeshGenerator::generateRegularQuadMesh(), MeshToolsLib::MeshGenerator::generateRegularTriMesh(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getProperties(), inputIsEmpty(), and meshAdded().

◆ enable2dWidgets()

void CreateStructuredGridDialog::enable2dWidgets ( ) const
private

Definition at line 67 of file CreateStructuredGridDialog.cpp.

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}

Referenced by on_quadButton_toggled(), and on_triButton_toggled().

◆ enable3dWidgets()

void CreateStructuredGridDialog::enable3dWidgets ( ) const
private

Definition at line 79 of file CreateStructuredGridDialog.cpp.

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}

Referenced by on_hexButton_toggled(), and on_prismButton_toggled().

◆ inputIsEmpty()

bool CreateStructuredGridDialog::inputIsEmpty ( ) const
private

Checks if all necessary inputs have been specified.

Definition at line 105 of file CreateStructuredGridDialog.cpp.

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}

References OGSError::box().

Referenced by accept().

◆ meshAdded

void CreateStructuredGridDialog::meshAdded ( MeshLib::Mesh * mesh)
signal

Referenced by accept().

◆ on_elemExtentButton_toggled

void CreateStructuredGridDialog::on_elemExtentButton_toggled ( )
privateslot

Definition at line 98 of file CreateStructuredGridDialog.cpp.

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}

◆ on_hexButton_toggled

void CreateStructuredGridDialog::on_hexButton_toggled ( ) const
inlineprivateslot

Definition at line 37 of file CreateStructuredGridDialog.h.

References enable3dWidgets().

◆ on_lineButton_toggled

void CreateStructuredGridDialog::on_lineButton_toggled ( ) const
privateslot

Definition at line 55 of file CreateStructuredGridDialog.cpp.

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}

◆ on_meshExtentButton_toggled

void CreateStructuredGridDialog::on_meshExtentButton_toggled ( )
privateslot

Definition at line 91 of file CreateStructuredGridDialog.cpp.

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}

◆ on_prismButton_toggled

void CreateStructuredGridDialog::on_prismButton_toggled ( ) const
inlineprivateslot

Definition at line 36 of file CreateStructuredGridDialog.h.

36{ enable3dWidgets(); }

References enable3dWidgets().

◆ on_quadButton_toggled

void CreateStructuredGridDialog::on_quadButton_toggled ( ) const
inlineprivateslot

Definition at line 35 of file CreateStructuredGridDialog.h.

References enable2dWidgets().

◆ on_triButton_toggled

void CreateStructuredGridDialog::on_triButton_toggled ( ) const
inlineprivateslot

Definition at line 34 of file CreateStructuredGridDialog.h.

34{ enable2dWidgets(); }

References enable2dWidgets().

◆ reject

void CreateStructuredGridDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 45 of file CreateStructuredGridDialog.h.

45{ this->done(QDialog::Rejected); };

◆ setValidators()

void CreateStructuredGridDialog::setValidators ( )
private

Definition at line 31 of file CreateStructuredGridDialog.cpp.

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}
A validator for an input field which only accepts decimals. Source code adapted from StackOverflow

Referenced by CreateStructuredGridDialog().


The documentation for this class was generated from the following files: