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