OGS
CondFromRasterDialog.cpp
Go to the documentation of this file.
1
16
17#include <QFileDialog>
18#include <QSettings>
19#include <utility>
20
21#include "Base/OGSError.h"
24#include "MeshLib/Mesh.h"
25
26CondFromRasterDialog::CondFromRasterDialog(std::vector<MeshLib::Mesh*> msh_vec,
27 QDialog* parent)
28 : QDialog(parent), _msh_vec(std::move(msh_vec))
29{
30 setupUi(this);
31
32 this->scalingEdit->setEnabled(false);
33 _scale_validator = new StrictDoubleValidator(-1e+10, 1e+20, 5);
34 this->scalingEdit->setText("1.0");
35 this->scalingEdit->setValidator(_scale_validator);
36
37 for (auto mesh : _msh_vec)
38 {
39 this->meshBox->addItem(QString::fromStdString(mesh->getName()));
40 }
41
42 this->directButton->setChecked(true);
43}
44
49
51{
52 QSettings settings;
53#ifdef GEOTIFF_FOUND
54 QString geotiffExtension(" *.tif");
55#else
56 QString geotiffExtension("");
57#endif
58 QString fileName = QFileDialog::getOpenFileName(
59 this, "Select raster file",
60 settings.value("lastOpenedRasterFileDirectory").toString(),
61 QString("Raster files (*.asc *.grd);;").arg(geotiffExtension));
62
63 if (!fileName.isEmpty())
64 {
65 this->rasterEdit->setText(fileName);
66
67 QFileInfo fi(fileName);
68 settings.setValue("lastOpenedRasterFileDirectory", fi.absolutePath());
69 }
70}
71
73{
74 std::string mesh_name(this->meshBox->currentText().toStdString());
75 std::string raster_name(this->rasterEdit->text().toStdString());
76 double scaling_factor = this->scalingEdit->text().toDouble();
77 std::vector<std::pair<std::size_t, double>> direct_values;
78
79 if (mesh_name.empty())
80 {
81 OGSError::box("No mesh selected.");
82 return;
83 }
84 if (raster_name.empty())
85 {
86 OGSError::box("No raster selected.");
87 return;
88 }
89
90 MeshLib::Mesh* mesh(nullptr);
91 for (auto mesh_ : _msh_vec)
92 {
93 if (mesh_->getName() == mesh_name)
94 {
95 mesh = mesh_;
96 break;
97 }
98 }
99
100 if (this->directButton->isChecked())
101 {
103 direct_values = dcg.directToSurfaceNodes(*mesh, raster_name);
104 // dcg.writeToFile(direct_node_name);
105 }
106 else
107 {
108 if (scaling_factor <= 0)
109 {
110 OGSError::box("No valid scaling factor given.");
111 return;
112 }
113 auto* new_mesh = const_cast<MeshLib::Mesh*>(mesh);
115 direct_values = dcg.directWithSurfaceIntegration(*new_mesh, raster_name,
116 scaling_factor);
117
118 // dcg.writeToFile(direct_node_name);
119 }
120 // emit directNodesWritten(direct_node_name);
121 emit transmitDisValues(direct_values);
122 this->done(QDialog::Accepted);
123}
124
126{
127 this->done(QDialog::Rejected);
128}
129
131{
132 this->scalingEdit->setEnabled(isSelected);
133}
Definition of the CondFromRasterDialog class.
Definition of the DirectConditionGenerator class.
Definition of the Mesh class.
Definition of the OGSError class.
Implementation of the StrictDoubleValidator class.
void accept() override
Instructions if the OK-Button has been pressed.
StrictDoubleValidator * _scale_validator
void reject() override
Instructions if the Cancel-Button has been pressed.
void transmitDisValues(std::vector< std::pair< std::size_t, double > >)
CondFromRasterDialog(std::vector< MeshLib::Mesh * > msh_vec, QDialog *parent=nullptr)
void on_integrateButton_toggled(bool isSelected)
const std::vector< MeshLib::Mesh * > _msh_vec
const std::vector< std::pair< std::size_t, double > > & directToSurfaceNodes(const MeshLib::Mesh &mesh, const std::string &filename)
const std::vector< std::pair< std::size_t, double > > & directWithSurfaceIntegration(MeshLib::Mesh &mesh, const std::string &filename, double scaling)
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