OGS
CondFromRasterDialog.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
5
6#include <QFileDialog>
7#include <QSettings>
8#include <utility>
9
10#include "Base/OGSError.h"
13#include "MeshLib/Mesh.h"
14
15CondFromRasterDialog::CondFromRasterDialog(std::vector<MeshLib::Mesh*> msh_vec,
16 QDialog* parent)
17 : QDialog(parent), _msh_vec(std::move(msh_vec))
18{
19 setupUi(this);
20
21 this->scalingEdit->setEnabled(false);
22 _scale_validator = new StrictDoubleValidator(-1e+10, 1e+20, 5);
23 this->scalingEdit->setText("1.0");
24 this->scalingEdit->setValidator(_scale_validator);
25
26 for (auto mesh : _msh_vec)
27 {
28 this->meshBox->addItem(QString::fromStdString(mesh->getName()));
29 }
30
31 this->directButton->setChecked(true);
32}
33
38
40{
41 QSettings settings;
42#ifdef GEOTIFF_FOUND
43 QString geotiffExtension(" *.tif");
44#else
45 QString geotiffExtension("");
46#endif
47 QString fileName = QFileDialog::getOpenFileName(
48 this, "Select raster file",
49 settings.value("lastOpenedRasterFileDirectory").toString(),
50 QString("Raster files (*.asc *.grd);;").arg(geotiffExtension));
51
52 if (!fileName.isEmpty())
53 {
54 this->rasterEdit->setText(fileName);
55
56 QFileInfo fi(fileName);
57 settings.setValue("lastOpenedRasterFileDirectory", fi.absolutePath());
58 }
59}
60
62{
63 std::string mesh_name(this->meshBox->currentText().toStdString());
64 std::string raster_name(this->rasterEdit->text().toStdString());
65 double scaling_factor = this->scalingEdit->text().toDouble();
66 std::vector<std::pair<std::size_t, double>> direct_values;
67
68 if (mesh_name.empty())
69 {
70 OGSError::box("No mesh selected.");
71 return;
72 }
73 if (raster_name.empty())
74 {
75 OGSError::box("No raster selected.");
76 return;
77 }
78
79 MeshLib::Mesh* mesh(nullptr);
80 for (auto mesh_ : _msh_vec)
81 {
82 if (mesh_->getName() == mesh_name)
83 {
84 mesh = mesh_;
85 break;
86 }
87 }
88
89 if (this->directButton->isChecked())
90 {
92 direct_values = dcg.directToSurfaceNodes(*mesh, raster_name);
93 // dcg.writeToFile(direct_node_name);
94 }
95 else
96 {
97 if (scaling_factor <= 0)
98 {
99 OGSError::box("No valid scaling factor given.");
100 return;
101 }
102 auto* new_mesh = const_cast<MeshLib::Mesh*>(mesh);
104 direct_values = dcg.directWithSurfaceIntegration(*new_mesh, raster_name,
105 scaling_factor);
106
107 // dcg.writeToFile(direct_node_name);
108 }
109 // emit directNodesWritten(direct_node_name);
110 emit transmitDisValues(direct_values);
111 this->done(QDialog::Accepted);
112}
113
115{
116 this->done(QDialog::Rejected);
117}
118
120{
121 this->scalingEdit->setEnabled(isSelected);
122}
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:13
A validator for an input field which only accepts decimals. Source code adapted from StackOverflow