OGS
MeshElementRemovalDialog Class Reference

Detailed Description

A dialog window for settung up a database connection.

Definition at line 37 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 33 of file MeshElementRemovalDialog.cpp.

35 : QDialog(parent),
36 _project(project),
38 _aabbIndex(std::numeric_limits<unsigned>::max()),
39 _scalarIndex(std::numeric_limits<unsigned>::max())
40{
41 setupUi(this);
42
43 auto const& mesh_vec(_project.getMeshObjects());
44
45 const std::size_t nMeshes(mesh_vec.size());
46 for (std::size_t i = 0; i < nMeshes; ++i)
47 {
48 std::string name = mesh_vec[i]->getName();
49 this->meshNameComboBox->addItem(QString::fromStdString(name));
50 }
51
52 if (mesh_vec.empty())
53 {
54 OGSError::box("No meshes available.");
55 QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
56 }
57}
const std::vector< std::unique_ptr< MeshLib::Mesh > > & getMeshObjects() const
Returns all the meshes with their respective names.
Definition Project.h:57
DataHolderLib::Project const & _project
static void box(const QString &e)
Definition OGSError.cpp:23

References _project, OGSError::box(), and DataHolderLib::Project::getMeshObjects().

◆ ~MeshElementRemovalDialog()

MeshElementRemovalDialog::~MeshElementRemovalDialog ( )
overridedefault

Member Function Documentation

◆ accept

void MeshElementRemovalDialog::accept ( )
overrideprivateslot

Definition at line 61 of file MeshElementRemovalDialog.cpp.

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

References _project, aabb_edits, OGSError::box(), MeshLib::Properties::existsPropertyVector(), DataHolderLib::Project::getMesh(), getMesh(), 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 192 of file MeshElementRemovalDialog.cpp.

194{
195 for (auto [name, property] : mesh.getProperties())
196 {
197 if (property->getMeshItemType() != MeshLib::MeshItemType::Cell)
198 {
199 continue;
200 }
201 this->scalarArrayComboBox->addItem(
202 QString::fromStdString(std::string(name)));
204 }
205 return this->scalarArrayComboBox->count();
206}
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 208 of file MeshElementRemovalDialog.cpp.

209{
210 this->scalarArrayComboBox->setEnabled(enable);
211 this->outsideButton->setEnabled(enable);
212 this->insideButton->setEnabled(enable);
213 this->outsideScalarMinEdit->setEnabled(enable &&
214 this->outsideButton->isChecked());
215 this->outsideScalarMaxEdit->setEnabled(enable &&
216 this->outsideButton->isChecked());
217 this->insideScalarMinEdit->setEnabled(enable &&
218 this->insideButton->isChecked());
219 this->insideScalarMaxEdit->setEnabled(enable &&
220 this->insideButton->isChecked());
221}

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 236 of file MeshElementRemovalDialog.cpp.

237{
238 this->invertBoundingBoxCheckBox->setEnabled(is_checked);
239 this->xMinEdit->setEnabled(is_checked);
240 this->xMaxEdit->setEnabled(is_checked);
241 this->yMinEdit->setEnabled(is_checked);
242 this->yMaxEdit->setEnabled(is_checked);
243 this->zMinEdit->setEnabled(is_checked);
244 this->zMaxEdit->setEnabled(is_checked);
245
246 if (is_checked && (_currentIndex != _aabbIndex))
247 {
249 std::vector<MeshLib::Node*> const& nodes(
251 .getMesh(this->meshNameComboBox->currentText().toStdString())
252 ->getNodes());
253 GeoLib::AABB aabb(nodes.begin(), nodes.end());
254 auto const& minAABB = aabb.getMinPoint();
255 auto const& maxAABB = aabb.getMaxPoint();
256 this->xMinEdit->setText(QString::number(minAABB[0], 'f'));
257 this->xMaxEdit->setText(QString::number(maxAABB[0], 'f'));
258 this->yMinEdit->setText(QString::number(minAABB[1], 'f'));
259 this->yMaxEdit->setText(QString::number(maxAABB[1], 'f'));
260 this->zMinEdit->setText(QString::number(minAABB[2], 'f'));
261 this->zMaxEdit->setText(QString::number(maxAABB[2], 'f'));
262 aabb_edits.fill(false);
263 }
264}

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

Referenced by on_meshNameComboBox_currentIndexChanged().

◆ on_elementTypeCheckBox_toggled

void MeshElementRemovalDialog::on_elementTypeCheckBox_toggled ( bool is_checked)
privateslot

Definition at line 283 of file MeshElementRemovalDialog.cpp.

284{
285 this->elementTypeListWidget->setEnabled(is_checked);
286}

◆ on_insideButton_toggled

void MeshElementRemovalDialog::on_insideButton_toggled ( bool is_checked)
privateslot

Definition at line 231 of file MeshElementRemovalDialog.cpp.

232{
233 toggleScalarEdits(!this->insideButton->isChecked());
234}
void toggleScalarEdits(bool outside) const

References toggleScalarEdits().

◆ on_invertBoundingBoxCheckBox_toggled

void MeshElementRemovalDialog::on_invertBoundingBoxCheckBox_toggled ( bool const is_checked)
privateslot

Definition at line 266 of file MeshElementRemovalDialog.cpp.

268{
269 if (is_checked == true)
270 {
271 this->xOutsideLabel->setText("X between");
272 this->yOutsideLabel->setText("Y between");
273 this->zOutsideLabel->setText("Z between");
274 }
275 else
276 {
277 this->xOutsideLabel->setText("X outside of");
278 this->yOutsideLabel->setText("Y outside of");
279 this->zOutsideLabel->setText("Z outside of");
280 }
281}

◆ on_meshNameComboBox_currentIndexChanged

void MeshElementRemovalDialog::on_meshNameComboBox_currentIndexChanged ( int idx)
privateslot

Definition at line 310 of file MeshElementRemovalDialog.cpp.

311{
312 Q_UNUSED(idx);
313 this->_currentIndex = this->meshNameComboBox->currentIndex();
314 this->newMeshNameEdit->setText(this->meshNameComboBox->currentText() +
315 "_new");
316 this->elementTypeListWidget->clearSelection();
317 this->scalarArrayComboBox->clear();
318 this->outsideScalarMinEdit->setText("");
319 this->outsideScalarMaxEdit->setText("");
320 this->insideScalarMinEdit->setText("");
321 this->insideScalarMaxEdit->setText("");
322 on_scalarArrayCheckBox_toggled(this->scalarArrayCheckBox->isChecked());
323 on_boundingBoxCheckBox_toggled(this->boundingBoxCheckBox->isChecked());
324}
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 288 of file MeshElementRemovalDialog.cpp.

289{
290 if (!is_checked)
291 {
293 return;
294 }
295
296 MeshLib::Mesh const* const mesh =
297 _project.getMesh(meshNameComboBox->currentText().toStdString());
298 if (addScalarArrays(*mesh) > 0)
299 {
301 }
302 else
303 {
305 OGSError::box("No scalar arrays found");
307 }
308}
std::size_t addScalarArrays(MeshLib::Mesh const &mesh) const

References _project, addScalarArrays(), OGSError::box(), enableScalarArrayWidgets(), DataHolderLib::Project::getMesh(), 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 326 of file MeshElementRemovalDialog.cpp.

328{
329 Q_UNUSED(idx);
330 std::string const vec_name(
331 scalarArrayComboBox->currentText().toStdString());
332 if (vec_name.empty())
333 {
334 return;
335 }
336
337 MeshLib::Mesh const* const mesh =
338 _project.getMesh(meshNameComboBox->currentText().toStdString());
339 if (mesh == nullptr)
340 {
341 return;
342 }
343 MeshLib::Properties const& properties = mesh->getProperties();
344
345 if (properties.existsPropertyVector<int>(vec_name))
346 {
347 setRangeValues<int>(*properties.getPropertyVector<int>(vec_name));
348 }
349 else if (properties.existsPropertyVector<double>(vec_name))
350 {
351 setRangeValues<double>(*properties.getPropertyVector<double>(vec_name));
352 }
353}
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
PropertyVector< T > const * getPropertyVector(std::string_view name) const

References _project, MeshLib::Properties::existsPropertyVector(), DataHolderLib::Project::getMesh(), MeshLib::Mesh::getProperties(), and MeshLib::Properties::getPropertyVector().

◆ on_xMaxEdit_textChanged

void MeshElementRemovalDialog::on_xMaxEdit_textChanged ( )
inlineprivateslot

Definition at line 55 of file MeshElementRemovalDialog.h.

55{ aabb_edits[1] = true; }

References aabb_edits.

◆ on_xMinEdit_textChanged

void MeshElementRemovalDialog::on_xMinEdit_textChanged ( )
inlineprivateslot

Definition at line 54 of file MeshElementRemovalDialog.h.

54{ aabb_edits[0] = true; }

References aabb_edits.

◆ on_yMaxEdit_textChanged

void MeshElementRemovalDialog::on_yMaxEdit_textChanged ( )
inlineprivateslot

Definition at line 57 of file MeshElementRemovalDialog.h.

57{ aabb_edits[3] = true; }

References aabb_edits.

◆ on_yMinEdit_textChanged

void MeshElementRemovalDialog::on_yMinEdit_textChanged ( )
inlineprivateslot

Definition at line 56 of file MeshElementRemovalDialog.h.

56{ aabb_edits[2] = true; }

References aabb_edits.

◆ on_zMaxEdit_textChanged

void MeshElementRemovalDialog::on_zMaxEdit_textChanged ( )
inlineprivateslot

Definition at line 59 of file MeshElementRemovalDialog.h.

59{ aabb_edits[5] = true; }

References aabb_edits.

◆ on_zMinEdit_textChanged

void MeshElementRemovalDialog::on_zMinEdit_textChanged ( )
inlineprivateslot

Definition at line 58 of file MeshElementRemovalDialog.h.

58{ aabb_edits[4] = true; }

References aabb_edits.

◆ reject

void MeshElementRemovalDialog::reject ( )
overrideprivateslot

Definition at line 187 of file MeshElementRemovalDialog.cpp.

188{
189 this->done(QDialog::Rejected);
190}

◆ setRangeValues()

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

Definition at line 356 of file MeshElementRemovalDialog.cpp.

358{
359 auto min = std::min_element(vec.cbegin(), vec.cend());
360 auto max = std::max_element(vec.cbegin(), vec.cend());
361 this->outsideScalarMinEdit->setText(QString::number(*min));
362 this->outsideScalarMaxEdit->setText(QString::number(*max));
363 this->insideScalarMinEdit->setText(QString::number(*min));
364 this->insideScalarMaxEdit->setText(QString::number(*max));
365}

◆ toggleScalarEdits()

void MeshElementRemovalDialog::toggleScalarEdits ( bool outside) const
private

Definition at line 223 of file MeshElementRemovalDialog.cpp.

224{
225 this->outsideScalarMinEdit->setEnabled(outside);
226 this->outsideScalarMaxEdit->setEnabled(outside);
227 this->insideScalarMinEdit->setEnabled(!outside);
228 this->insideScalarMaxEdit->setEnabled(!outside);
229}

Referenced by on_insideButton_toggled().

Member Data Documentation

◆ _aabbIndex

unsigned MeshElementRemovalDialog::_aabbIndex
private

Definition at line 73 of file MeshElementRemovalDialog.h.

Referenced by on_boundingBoxCheckBox_toggled().

◆ _currentIndex

unsigned MeshElementRemovalDialog::_currentIndex
private

◆ _project

◆ _scalarIndex

unsigned MeshElementRemovalDialog::_scalarIndex
private

Definition at line 73 of file MeshElementRemovalDialog.h.

◆ aabb_edits


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