OGS
GMSHPrefsDialog.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
4// Base
6
7// Qt/Base
8#include <QStringList>
9#include <QStringListModel>
10
11#include "Base/OGSError.h"
14#include "Base/Utils.h"
15#include "GMSHPrefsDialog.h"
16#include "GeoLib/GEOObjects.h"
17
19 QDialog* parent)
20 : QDialog(parent),
21 _allGeo(new QStringListModel),
22 _selGeo(new QStringListModel)
23{
24 setupUi(this);
25
26 // default parameters
27 this->param1->setText("2");
28 this->param2->setText("0.3");
29 this->param3->setText("0.05");
30 this->param4->setText("0");
31
32 // object will be deleted by Qt
33 auto* max_number_of_points_in_quadtree_leaf_validator(
34 new StrictIntValidator(1, 1000, this->param1));
35 param1->setValidator(max_number_of_points_in_quadtree_leaf_validator);
36 // object will be deleted by Qt
37 auto* mesh_density_scaling_pnts_validator(
38 new StrictDoubleValidator(0, 1, 5, this->param2));
39 param2->setValidator(mesh_density_scaling_pnts_validator);
40 // object will be deleted by Qt#
41 auto* mesh_density_scaling_stations_validator(
42 new StrictDoubleValidator(0, 1, 5, this->param3));
43 param3->setValidator(mesh_density_scaling_stations_validator);
44
45 auto geoNames = geoObjects.getGeometryNames();
46
47 // get station names
48 std::vector<std::string> geo_station_names;
49 geoObjects.getStationVectorNames(geo_station_names);
50
51 std::copy(geo_station_names.begin(), geo_station_names.end(),
52 std::back_inserter(geoNames));
53
54 std::size_t nGeoObjects(geoNames.size());
55
56 QStringList list;
57 for (unsigned i = 0; i < nGeoObjects; ++i)
58 {
59 list.append(QString::fromStdString(geoNames[i]));
60 }
61
62 if (list.empty())
63 {
64 this->selectGeoButton->setDisabled(true);
65 this->deselectGeoButton->setDisabled(true);
66 list.append("[No geometry available.]");
67 }
68 _allGeo->setStringList(list);
69 this->allGeoView->setModel(_allGeo);
70 this->selectedGeoView->setModel(_selGeo);
71 this->radioAdaptive->toggle(); // default is adaptive meshing
72 this->on_radioAdaptive_toggled(true);
73}
74
76{
77 delete _allGeo;
78 delete _selGeo;
79}
80
82{
83 QModelIndexList selected =
84 this->allGeoView->selectionModel()->selectedIndexes();
85 QStringList list = _selGeo->stringList();
86
87 for (auto& index : selected)
88 {
89 list.append(index.data().toString());
90
91 _allGeo->removeRow(index.row());
92 }
93 _selGeo->setStringList(list);
94}
95
97{
98 QModelIndexList selected =
99 this->selectedGeoView->selectionModel()->selectedIndexes();
100 QStringList list = _allGeo->stringList();
101
102 for (auto& index : selected)
103 {
104 list.append(index.data().toString());
105
106 _selGeo->removeRow(index.row());
107 }
108 _allGeo->setStringList(list);
109}
110
112{
113 if (isTrue) // meshing set to adaptive
114 {
115 this->param1->setEnabled(true);
116 this->param2->setEnabled(true);
117 this->param3->setEnabled(true);
118 this->param4->setEnabled(false);
119 }
120 else // meshing set to homogeneous
121 {
122 this->param1->setEnabled(false);
123 this->param2->setEnabled(false);
124 this->param3->setEnabled(false);
125 this->param4->setEnabled(true);
126 }
127}
128
130{
131 if (this->_selGeo->stringList().empty())
132 {
134 "No geometry selected. Geometric data\n is necessary for mesh "
135 "generation.");
136 return;
137 }
138
139 std::vector<std::string> selectedObjects =
140 Utils::getSelectedObjects(_selGeo->stringList());
141 unsigned max_number_of_points_in_quadtree_leaf(10);
142 double mesh_density_scaling_pnts(0.5);
143 double mesh_density_scaling_stations(0.05);
144 double val4(-1);
145
146 if (this->radioAdaptive->isChecked())
147 {
148 double const min_scaling_factor(1e-10);
149 max_number_of_points_in_quadtree_leaf =
150 BaseLib::str2number<unsigned>(param1->text().toStdString());
151 if (max_number_of_points_in_quadtree_leaf == 0)
152 {
153 max_number_of_points_in_quadtree_leaf = 10;
154 }
155 mesh_density_scaling_pnts = fabs(param2->text().toDouble());
156 if (mesh_density_scaling_pnts < min_scaling_factor)
157 {
158 mesh_density_scaling_pnts = min_scaling_factor;
159 }
160 mesh_density_scaling_stations = param3->text().toDouble();
161 if (mesh_density_scaling_stations < min_scaling_factor)
162 {
163 mesh_density_scaling_stations = min_scaling_factor;
164 }
165 }
166 else
167 {
168 val4 = param4->text().toDouble();
169 }
170
171 bool delete_geo_file = this->geoFileDelete->isChecked();
172 emit requestMeshing(selectedObjects,
173 max_number_of_points_in_quadtree_leaf,
174 mesh_density_scaling_pnts,
175 mesh_density_scaling_stations,
176 val4,
177 delete_geo_file);
178 this->done(QDialog::Accepted);
179}
180
182{
183 this->done(QDialog::Rejected);
184}
void on_selectGeoButton_pressed()
void reject() override
Instructions if the Cancel-Button has been pressed.
void on_radioAdaptive_toggled(bool isTrue)
QStringListModel * _selGeo
QStringListModel * _allGeo
GMSHPrefsDialog(GeoLib::GEOObjects const &geoObjects, QDialog *parent=nullptr)
void accept() override
Instructions if the OK-Button has been pressed.
~GMSHPrefsDialog() override
void on_deselectGeoButton_pressed()
void requestMeshing(std::vector< std::string > &, unsigned, double, double, double, bool)
Container class for geometric objects.
Definition GEOObjects.h:46
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
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
A validator for an input field which only accepts integers. Source code adapted from Qt developer faq...
T str2number(const std::string &str)
Definition StringTools.h:53
std::vector< std::string > getSelectedObjects(QStringList const &list)