OGS
MeshElementRemovalDialog Class Reference

Detailed Description

A dialog window for settung up a database connection.

Definition at line 26 of file MeshElementRemovalDialog.h.

#include <MeshElementRemovalDialog.h>

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

Signals

void meshAdded (MeshLib::Mesh *mesh)

Public Member Functions

 MeshElementRemovalDialog (DataHolderLib::Project const &project, QDialog *parent=nullptr)
 Constructor.
 ~MeshElementRemovalDialog () override

Private Slots

void on_boundingBoxCheckBox_toggled (bool is_checked)
void on_invertBoundingBoxCheckBox_toggled (bool const is_checked)
void on_elementTypeCheckBox_toggled (bool is_checked)
void on_scalarArrayCheckBox_toggled (bool is_checked)
void on_insideButton_toggled (bool is_checked)
void on_meshNameComboBox_currentIndexChanged (int idx)
void on_scalarArrayComboBox_currentIndexChanged (int idx)
void on_xMinEdit_textChanged ()
void on_xMaxEdit_textChanged ()
void on_yMinEdit_textChanged ()
void on_yMaxEdit_textChanged ()
void on_zMinEdit_textChanged ()
void on_zMaxEdit_textChanged ()
void accept () override
void reject () override

Private Member Functions

std::size_t addScalarArrays (MeshLib::Mesh const &mesh) const
void enableScalarArrayWidgets (bool enable) const
template<typename T>
void setRangeValues (MeshLib::PropertyVector< T > const &vec)
void toggleScalarEdits (bool outside) const

Private Attributes

DataHolderLib::Project const & _project
unsigned _currentIndex
unsigned _aabbIndex
unsigned _scalarIndex
std::array< bool, 6 > aabb_edits

Constructor & Destructor Documentation

◆ MeshElementRemovalDialog()

MeshElementRemovalDialog::MeshElementRemovalDialog ( DataHolderLib::Project const & project,
QDialog * parent = nullptr )
explicit

Constructor.

Definition at line 22 of file MeshElementRemovalDialog.cpp.

24 : QDialog(parent),
25 _project(project),
27 _aabbIndex(std::numeric_limits<unsigned>::max()),
28 _scalarIndex(std::numeric_limits<unsigned>::max())
29{
30 setupUi(this);
31
32 auto const& mesh_vec(_project.getMeshObjects());
33
34 const std::size_t nMeshes(mesh_vec.size());
35 for (std::size_t i = 0; i < nMeshes; ++i)
36 {
37 std::string name = mesh_vec[i]->getName();
38 this->meshNameComboBox->addItem(QString::fromStdString(name));
39 }
40
41 if (mesh_vec.empty())
42 {
43 OGSError::box("No meshes available.");
44 QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
45 }
46}
DataHolderLib::Project const & _project
static void box(const QString &e)
Definition OGSError.cpp:13

References _aabbIndex, _currentIndex, _project, _scalarIndex, and OGSError::box().

◆ ~MeshElementRemovalDialog()

MeshElementRemovalDialog::~MeshElementRemovalDialog ( )
overridedefault

Member Function Documentation

◆ accept

void MeshElementRemovalDialog::accept ( )
overrideprivateslot

Definition at line 50 of file MeshElementRemovalDialog.cpp.

51{
52 if (this->newMeshNameEdit->text().size() == 0)
53 {
54 OGSError::box("Please enter name for new mesh.");
55 return;
56 }
57
58 bool anything_checked(false);
59
60 const MeshLib::Mesh* msh =
61 _project.getMesh(this->meshNameComboBox->currentText().toStdString());
62 MeshLib::ElementSearch ex(*msh);
63 if (this->elementTypeCheckBox->isChecked())
64 {
65 QList<QListWidgetItem*> items =
66 this->elementTypeListWidget->selectedItems();
67 for (auto& item : items)
68 {
69 ex.searchByElementType(
70 MeshLib::String2MeshElemType(item->text().toStdString()));
71 }
72 anything_checked = true;
73 }
74 if (this->scalarArrayCheckBox->isChecked())
75 {
76 std::string const array_name =
77 this->scalarArrayComboBox->currentText().toStdString();
78 double min_val;
79 double max_val;
80 bool outside = this->outsideButton->isChecked();
81 if (outside)
82 {
83 min_val = this->outsideScalarMinEdit->text().toDouble();
84 max_val = this->outsideScalarMaxEdit->text().toDouble();
85 }
86 else
87 {
88 min_val = this->insideScalarMinEdit->text().toDouble();
89 max_val = this->insideScalarMaxEdit->text().toDouble();
90 }
91
92 std::size_t n_marked_elements(0);
93 if (msh->getProperties().existsPropertyVector<double>(array_name))
94 {
95 n_marked_elements = ex.searchByPropertyValueRange<double>(
96 array_name, min_val, max_val, outside);
97 }
98 if (msh->getProperties().existsPropertyVector<int>(array_name))
99 {
100 int const lbound = static_cast<int>(min_val);
101 int const rbound = static_cast<int>(max_val);
102 n_marked_elements = ex.searchByPropertyValueRange<int>(
103 array_name, lbound, rbound, outside);
104 }
105
106 if (n_marked_elements > 0)
107 {
108 anything_checked = true;
109 }
110 }
111 if (this->boundingBoxCheckBox->isChecked())
112 {
113 std::vector<MeshLib::Node*> const& nodes(
115 .getMesh(this->meshNameComboBox->currentText().toStdString())
116 ->getNodes());
117 GeoLib::AABB const aabb(nodes.begin(), nodes.end());
118 auto [minAABB, maxAABB] = aabb.getMinMaxPoints();
119
120 // only extract bounding box parameters that have been edited (otherwise
121 // there will be rounding errors!)
122 minAABB[0] =
123 (aabb_edits[0]) ? this->xMinEdit->text().toDouble() : (minAABB[0]);
124 maxAABB[0] =
125 (aabb_edits[1]) ? this->xMaxEdit->text().toDouble() : (maxAABB[0]);
126 minAABB[1] =
127 (aabb_edits[2]) ? this->yMinEdit->text().toDouble() : (minAABB[1]);
128 maxAABB[1] =
129 (aabb_edits[3]) ? this->yMaxEdit->text().toDouble() : (maxAABB[1]);
130 minAABB[2] =
131 (aabb_edits[4]) ? this->zMinEdit->text().toDouble() : (minAABB[2]);
132 maxAABB[2] =
133 (aabb_edits[5]) ? this->zMaxEdit->text().toDouble() : (maxAABB[2]);
134 std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>
135 extent{minAABB, maxAABB};
136 const GeoLib::AABB updated_aabb(extent.begin(), extent.end());
137 ex.searchByBoundingBox(updated_aabb,
138 this->invertBoundingBoxCheckBox->isChecked());
139 anything_checked = true;
140 }
141
142 if (this->zeroVolumeCheckBox->isChecked())
143 {
144 ex.searchByContent();
145 anything_checked = true;
146 }
147
148 if (anything_checked)
149 {
150 MeshLib::Mesh* new_mesh = MeshToolsLib::removeElements(
151 *msh, ex.getSearchedElementIDs(),
152 this->newMeshNameEdit->text().toStdString());
153 if (new_mesh)
154 {
155 emit meshAdded(new_mesh);
156 }
157 else
158 {
159 if (ex.getSearchedElementIDs().empty())
160 {
162 "The current selection removes NO mesh elements.");
163 }
164 return;
165 }
166 }
167 else
168 {
169 OGSError::box("No condition set for elements to remove.");
170 return;
171 }
172
173 this->done(QDialog::Accepted);
174}
void meshAdded(MeshLib::Mesh *mesh)
Properties & getProperties()
Definition Mesh.h:125
bool existsPropertyVector(std::string_view name) const
MeshElemType String2MeshElemType(const std::string &s)
Given a string of the shortened name of the element type, this returns the corresponding MeshElemType...
Definition MeshEnums.cpp:84
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)

References _project, aabb_edits, OGSError::box(), MeshLib::Properties::existsPropertyVector(), GeoLib::AABB::getMinMaxPoints(), MeshLib::Mesh::getProperties(), MeshLib::ElementSearch::getSearchedElementIDs(), meshAdded(), MeshToolsLib::removeElements(), MeshLib::ElementSearch::searchByBoundingBox(), MeshLib::ElementSearch::searchByContent(), MeshLib::ElementSearch::searchByElementType(), MeshLib::ElementSearch::searchByPropertyValueRange(), and MeshLib::String2MeshElemType().

◆ addScalarArrays()

std::size_t MeshElementRemovalDialog::addScalarArrays ( MeshLib::Mesh const & mesh) const
private

Definition at line 181 of file MeshElementRemovalDialog.cpp.

183{
184 for (auto [name, property] : mesh.getProperties())
185 {
186 if (property->getMeshItemType() != MeshLib::MeshItemType::Cell)
187 {
188 continue;
189 }
190 this->scalarArrayComboBox->addItem(
191 QString::fromStdString(std::string(name)));
193 }
194 return this->scalarArrayComboBox->count();
195}
void enableScalarArrayWidgets(bool enable) const

References MeshLib::Cell, enableScalarArrayWidgets(), and MeshLib::Mesh::getProperties().

Referenced by on_scalarArrayCheckBox_toggled().

◆ enableScalarArrayWidgets()

void MeshElementRemovalDialog::enableScalarArrayWidgets ( bool enable) const
private

Definition at line 197 of file MeshElementRemovalDialog.cpp.

198{
199 this->scalarArrayComboBox->setEnabled(enable);
200 this->outsideButton->setEnabled(enable);
201 this->insideButton->setEnabled(enable);
202 this->outsideScalarMinEdit->setEnabled(enable &&
203 this->outsideButton->isChecked());
204 this->outsideScalarMaxEdit->setEnabled(enable &&
205 this->outsideButton->isChecked());
206 this->insideScalarMinEdit->setEnabled(enable &&
207 this->insideButton->isChecked());
208 this->insideScalarMaxEdit->setEnabled(enable &&
209 this->insideButton->isChecked());
210}

Referenced by addScalarArrays(), and on_scalarArrayCheckBox_toggled().

◆ meshAdded

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

Referenced by accept().

◆ on_boundingBoxCheckBox_toggled

void MeshElementRemovalDialog::on_boundingBoxCheckBox_toggled ( bool is_checked)
privateslot

Definition at line 225 of file MeshElementRemovalDialog.cpp.

226{
227 this->invertBoundingBoxCheckBox->setEnabled(is_checked);
228 this->xMinEdit->setEnabled(is_checked);
229 this->xMaxEdit->setEnabled(is_checked);
230 this->yMinEdit->setEnabled(is_checked);
231 this->yMaxEdit->setEnabled(is_checked);
232 this->zMinEdit->setEnabled(is_checked);
233 this->zMaxEdit->setEnabled(is_checked);
234
235 if (is_checked && (_currentIndex != _aabbIndex))
236 {
238 std::vector<MeshLib::Node*> const& nodes(
240 .getMesh(this->meshNameComboBox->currentText().toStdString())
241 ->getNodes());
242 GeoLib::AABB aabb(nodes.begin(), nodes.end());
243 auto const& minAABB = aabb.getMinPoint();
244 auto const& maxAABB = aabb.getMaxPoint();
245 this->xMinEdit->setText(QString::number(minAABB[0], 'f'));
246 this->xMaxEdit->setText(QString::number(maxAABB[0], 'f'));
247 this->yMinEdit->setText(QString::number(minAABB[1], 'f'));
248 this->yMaxEdit->setText(QString::number(maxAABB[1], 'f'));
249 this->zMinEdit->setText(QString::number(minAABB[2], 'f'));
250 this->zMaxEdit->setText(QString::number(maxAABB[2], 'f'));
251 aabb_edits.fill(false);
252 }
253}

References _aabbIndex, _currentIndex, _project, aabb_edits, GeoLib::AABB::getMaxPoint(), and GeoLib::AABB::getMinPoint().

Referenced by on_meshNameComboBox_currentIndexChanged().

◆ on_elementTypeCheckBox_toggled

void MeshElementRemovalDialog::on_elementTypeCheckBox_toggled ( bool is_checked)
privateslot

Definition at line 272 of file MeshElementRemovalDialog.cpp.

273{
274 this->elementTypeListWidget->setEnabled(is_checked);
275}

◆ on_insideButton_toggled

void MeshElementRemovalDialog::on_insideButton_toggled ( bool is_checked)
privateslot

Definition at line 220 of file MeshElementRemovalDialog.cpp.

221{
222 toggleScalarEdits(!this->insideButton->isChecked());
223}
void toggleScalarEdits(bool outside) const

References toggleScalarEdits().

◆ on_invertBoundingBoxCheckBox_toggled

void MeshElementRemovalDialog::on_invertBoundingBoxCheckBox_toggled ( bool const is_checked)
privateslot

Definition at line 255 of file MeshElementRemovalDialog.cpp.

257{
258 if (is_checked == true)
259 {
260 this->xOutsideLabel->setText("X between");
261 this->yOutsideLabel->setText("Y between");
262 this->zOutsideLabel->setText("Z between");
263 }
264 else
265 {
266 this->xOutsideLabel->setText("X outside of");
267 this->yOutsideLabel->setText("Y outside of");
268 this->zOutsideLabel->setText("Z outside of");
269 }
270}

◆ on_meshNameComboBox_currentIndexChanged

void MeshElementRemovalDialog::on_meshNameComboBox_currentIndexChanged ( int idx)
privateslot

Definition at line 299 of file MeshElementRemovalDialog.cpp.

300{
301 Q_UNUSED(idx);
302 this->_currentIndex = this->meshNameComboBox->currentIndex();
303 this->newMeshNameEdit->setText(this->meshNameComboBox->currentText() +
304 "_new");
305 this->elementTypeListWidget->clearSelection();
306 this->scalarArrayComboBox->clear();
307 this->outsideScalarMinEdit->setText("");
308 this->outsideScalarMaxEdit->setText("");
309 this->insideScalarMinEdit->setText("");
310 this->insideScalarMaxEdit->setText("");
311 on_scalarArrayCheckBox_toggled(this->scalarArrayCheckBox->isChecked());
312 on_boundingBoxCheckBox_toggled(this->boundingBoxCheckBox->isChecked());
313}
void on_scalarArrayCheckBox_toggled(bool is_checked)
void on_boundingBoxCheckBox_toggled(bool is_checked)

References _currentIndex, on_boundingBoxCheckBox_toggled(), and on_scalarArrayCheckBox_toggled().

◆ on_scalarArrayCheckBox_toggled

void MeshElementRemovalDialog::on_scalarArrayCheckBox_toggled ( bool is_checked)
privateslot

Definition at line 277 of file MeshElementRemovalDialog.cpp.

278{
279 if (!is_checked)
280 {
282 return;
283 }
284
285 MeshLib::Mesh const* const mesh =
286 _project.getMesh(meshNameComboBox->currentText().toStdString());
287 if (addScalarArrays(*mesh) > 0)
288 {
290 }
291 else
292 {
294 OGSError::box("No scalar arrays found");
296 }
297}
std::size_t addScalarArrays(MeshLib::Mesh const &mesh) const

References _project, addScalarArrays(), OGSError::box(), enableScalarArrayWidgets(), and on_scalarArrayCheckBox_toggled().

Referenced by on_meshNameComboBox_currentIndexChanged(), and on_scalarArrayCheckBox_toggled().

◆ on_scalarArrayComboBox_currentIndexChanged

void MeshElementRemovalDialog::on_scalarArrayComboBox_currentIndexChanged ( int idx)
privateslot

Definition at line 315 of file MeshElementRemovalDialog.cpp.

317{
318 Q_UNUSED(idx);
319 std::string const vec_name(
320 scalarArrayComboBox->currentText().toStdString());
321 if (vec_name.empty())
322 {
323 return;
324 }
325
326 MeshLib::Mesh const* const mesh =
327 _project.getMesh(meshNameComboBox->currentText().toStdString());
328 if (mesh == nullptr)
329 {
330 return;
331 }
332 MeshLib::Properties const& properties = mesh->getProperties();
333
334 if (properties.existsPropertyVector<int>(vec_name))
335 {
336 setRangeValues<int>(*properties.getPropertyVector<int>(vec_name));
337 }
338 else if (properties.existsPropertyVector<double>(vec_name))
339 {
340 setRangeValues<double>(*properties.getPropertyVector<double>(vec_name));
341 }
342}
void setRangeValues(MeshLib::PropertyVector< T > const &vec)
PropertyVector< T > const * getPropertyVector(std::string_view name) const

References _project, MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), and setRangeValues().

◆ on_xMaxEdit_textChanged

void MeshElementRemovalDialog::on_xMaxEdit_textChanged ( )
inlineprivateslot

Definition at line 44 of file MeshElementRemovalDialog.h.

44{ aabb_edits[1] = true; }

References aabb_edits.

◆ on_xMinEdit_textChanged

void MeshElementRemovalDialog::on_xMinEdit_textChanged ( )
inlineprivateslot

Definition at line 43 of file MeshElementRemovalDialog.h.

43{ aabb_edits[0] = true; }

References aabb_edits.

◆ on_yMaxEdit_textChanged

void MeshElementRemovalDialog::on_yMaxEdit_textChanged ( )
inlineprivateslot

Definition at line 46 of file MeshElementRemovalDialog.h.

46{ aabb_edits[3] = true; }

References aabb_edits.

◆ on_yMinEdit_textChanged

void MeshElementRemovalDialog::on_yMinEdit_textChanged ( )
inlineprivateslot

Definition at line 45 of file MeshElementRemovalDialog.h.

45{ aabb_edits[2] = true; }

References aabb_edits.

◆ on_zMaxEdit_textChanged

void MeshElementRemovalDialog::on_zMaxEdit_textChanged ( )
inlineprivateslot

Definition at line 48 of file MeshElementRemovalDialog.h.

48{ aabb_edits[5] = true; }

References aabb_edits.

◆ on_zMinEdit_textChanged

void MeshElementRemovalDialog::on_zMinEdit_textChanged ( )
inlineprivateslot

Definition at line 47 of file MeshElementRemovalDialog.h.

47{ aabb_edits[4] = true; }

References aabb_edits.

◆ reject

void MeshElementRemovalDialog::reject ( )
overrideprivateslot

Definition at line 176 of file MeshElementRemovalDialog.cpp.

177{
178 this->done(QDialog::Rejected);
179}

◆ setRangeValues()

template<typename T>
void MeshElementRemovalDialog::setRangeValues ( MeshLib::PropertyVector< T > const & vec)
private

Definition at line 345 of file MeshElementRemovalDialog.cpp.

347{
348 auto min = std::min_element(vec.cbegin(), vec.cend());
349 auto max = std::max_element(vec.cbegin(), vec.cend());
350 this->outsideScalarMinEdit->setText(QString::number(*min));
351 this->outsideScalarMaxEdit->setText(QString::number(*max));
352 this->insideScalarMinEdit->setText(QString::number(*min));
353 this->insideScalarMaxEdit->setText(QString::number(*max));
354}
constexpr const PROP_VAL_TYPE * cbegin() const
constexpr const PROP_VAL_TYPE * cend() const

References MeshLib::PropertyVector< PROP_VAL_TYPE >::cbegin(), and MeshLib::PropertyVector< PROP_VAL_TYPE >::cend().

Referenced by on_scalarArrayComboBox_currentIndexChanged().

◆ toggleScalarEdits()

void MeshElementRemovalDialog::toggleScalarEdits ( bool outside) const
private

Definition at line 212 of file MeshElementRemovalDialog.cpp.

213{
214 this->outsideScalarMinEdit->setEnabled(outside);
215 this->outsideScalarMaxEdit->setEnabled(outside);
216 this->insideScalarMinEdit->setEnabled(!outside);
217 this->insideScalarMaxEdit->setEnabled(!outside);
218}

Referenced by on_insideButton_toggled().

Member Data Documentation

◆ _aabbIndex

unsigned MeshElementRemovalDialog::_aabbIndex
private

◆ _currentIndex

unsigned MeshElementRemovalDialog::_currentIndex
private

◆ _project

◆ _scalarIndex

unsigned MeshElementRemovalDialog::_scalarIndex
private

Definition at line 62 of file MeshElementRemovalDialog.h.

Referenced by MeshElementRemovalDialog().

◆ aabb_edits


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