OGS
TranslateDataDialog.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 <QStringList>
7
8#include "Base/OGSError.h"
10#include "Base/Utils.h"
11#include "GEOModels.h"
12#include "GeoLib/AABB.h"
13#include "MeshLib/Mesh.h"
14#include "MeshLib/Node.h"
15#include "MeshModel.h"
17
19 GEOModels* geo_models,
20 QDialog* parent)
21 : QDialog(parent), _mesh_model(mesh_model), _geo_models(geo_models)
22{
23 setupUi(this);
24 assert(_geo_models != nullptr);
25 assert(_mesh_model != nullptr);
26 auto const geoNames = _geo_models->getGeometryNames();
27
28 QStringList dataList;
29 for (auto const& name : geoNames)
30 {
31 dataList.append(QString::fromStdString(name));
32 }
33
34 for (int model_index = 0; model_index < _mesh_model->rowCount();
35 ++model_index)
36 {
37 auto const* mesh =
38 _mesh_model->getMesh(_mesh_model->index(model_index, 0));
39 dataList.append(QString::fromStdString(mesh->getName()));
40 }
41
42 if (dataList.empty())
43 {
44 this->selectDataButton->setDisabled(true);
45 this->deselectDataButton->setDisabled(true);
46 dataList.append("[No data available.]");
47 }
48
49 _allData.setStringList(dataList);
50 this->allDataView->setModel(&_allData);
51 this->selectedDataView->setModel(&_selData);
52}
53
58
63
64void TranslateDataDialog::moveGeometry(Eigen::Vector3d const& displacement,
65 std::string const& name)
66{
67 std::vector<GeoLib::Point*> const* point_vec =
68 _geo_models->getPointVec(name);
69 if (point_vec == nullptr)
70 {
71 OGSError::box("The geometry is faulty.");
72 return;
73 }
74
75 MeshToolsLib::moveMeshNodes(point_vec->begin(), point_vec->end(),
76 displacement);
77
78 _geo_models->updateGeometry(name);
79}
80
81void TranslateDataDialog::moveMesh(Eigen::Vector3d const& displacement,
82 std::string const& name)
83{
84 MeshLib::Mesh const* mesh(_mesh_model->getMesh(name));
85 if (mesh == nullptr)
86 {
87 OGSError::box("The mesh is faulty.");
88 return;
89 }
90
92 mesh->getNodes().end(), displacement);
93 _mesh_model->updateMesh(const_cast<MeshLib::Mesh*>(mesh));
94}
95
97{
98 if (this->_selData.rowCount() == 0)
99 {
100 OGSError::box("Please specify the input data.");
101 return;
102 }
103
104 QString const xinput = this->xlineEdit->text();
105 QString const yinput = this->ylineEdit->text();
106 QString const zinput = this->zlineEdit->text();
107
108 bool ok;
109 if (!xinput.toDouble(&ok) or !yinput.toDouble(&ok) or !zinput.toDouble(&ok))
110 {
111 INFO(
112 "If the x/y/z-input is 0, not specified or not a real number, it "
113 "is used as 0.");
114 }
115
116 Eigen::Vector3d const displacement{xinput.toDouble(), yinput.toDouble(),
117 zinput.toDouble()};
118
119 INFO("translate model ({:f}, {:f}, {:f}).",
120 displacement[0],
121 displacement[1],
122 displacement[2]);
123
124 std::vector<std::string> const selectedData =
126
127 auto const geoNames = _geo_models->getGeometryNames();
128
129 for (auto const& data_name : selectedData)
130 {
131 if (std::find(std::begin(geoNames), std::end(geoNames), data_name) !=
132 std::end(geoNames))
133 {
134 moveGeometry(displacement, data_name);
135 continue;
136 }
137 moveMesh(displacement, data_name);
138 }
139
140 this->done(QDialog::Accepted);
141}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
GEOModels connects the data management class GEOObjects and the GUI. It inherits from GeoLib::GEOObje...
Definition GEOModels.h:26
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:97
static void box(const QString &e)
Definition OGSError.cpp:13
void accept() override
Instructions if the OK-Button has been pressed.
QStringListModel _allData
QStringListModel _selData
void moveGeometry(Eigen::Vector3d const &displacement, std::string const &name)
TranslateDataDialog(MeshModel *mesh_model, GEOModels *geo_models, QDialog *parent=nullptr)
void moveMesh(Eigen::Vector3d const &displacement, std::string const &name)
void on_deselectDataButton_pressed()
Instructions if the "<<-button" has been pressed.
void on_selectDataButton_pressed()
Instructions if the ">>-button" has been pressed.
void moveMeshNodes(Iterator begin, Iterator end, Eigen::Vector3d const &displacement)
std::vector< std::string > getSelectedObjects(QStringList const &list)
void moveSelectedItems(QListView *sourceView, QStringListModel &sourceModel, QStringListModel &targetModel)