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