OGS
TranslateDataDialog.cpp
Go to the documentation of this file.
1
15#include "TranslateDataDialog.h"
16
17#include <QStringList>
18
20#include "Base/Utils.h"
21#include "GEOModels.h"
22#include "GeoLib/AABB.h"
23#include "MeshLib/Mesh.h"
24#include "MeshLib/Node.h"
25#include "MeshModel.h"
27
29 GEOModels* geo_models,
30 QDialog* parent)
31 : QDialog(parent), _mesh_model(mesh_model), _geo_models(geo_models)
32{
33 setupUi(this);
34 assert(_geo_models != nullptr);
35 assert(_mesh_model != nullptr);
36 auto const geoNames = _geo_models->getGeometryNames();
37
38 QStringList dataList;
39 for (auto const& name : geoNames)
40 {
41 dataList.append(QString::fromStdString(name));
42 }
43
44 for (int model_index = 0; model_index < _mesh_model->rowCount();
45 ++model_index)
46 {
47 auto const* mesh =
48 _mesh_model->getMesh(_mesh_model->index(model_index, 0));
49 dataList.append(QString::fromStdString(mesh->getName()));
50 }
51
52 if (dataList.empty())
53 {
54 this->selectDataButton->setDisabled(true);
55 this->deselectDataButton->setDisabled(true);
56 dataList.append("[No data available.]");
57 }
58
59 _allData.setStringList(dataList);
60 this->allDataView->setModel(&_allData);
61 this->selectedDataView->setModel(&_selData);
62}
63
68
73
74void TranslateDataDialog::moveGeometry(Eigen::Vector3d const& displacement,
75 std::string const& name)
76{
77 std::vector<GeoLib::Point*> const* point_vec =
79 if (point_vec == nullptr)
80 {
81 OGSError::box("The geometry is faulty.");
82 return;
83 }
84
85 MeshToolsLib::moveMeshNodes(point_vec->begin(), point_vec->end(),
86 displacement);
87
89}
90
91void TranslateDataDialog::moveMesh(Eigen::Vector3d const& displacement,
92 std::string const& name)
93{
94 MeshLib::Mesh const* mesh(_mesh_model->getMesh(name));
95 if (mesh == nullptr)
96 {
97 OGSError::box("The mesh is faulty.");
98 return;
99 }
100
102 mesh->getNodes().end(), displacement);
103 _mesh_model->updateMesh(const_cast<MeshLib::Mesh*>(mesh));
104}
105
107{
108 if (this->_selData.rowCount() == 0)
109 {
110 OGSError::box("Please specify the input data.");
111 return;
112 }
113
114 QString const xinput = this->xlineEdit->text();
115 QString const yinput = this->ylineEdit->text();
116 QString const zinput = this->zlineEdit->text();
117
118 bool ok;
119 if (!xinput.toDouble(&ok) or !yinput.toDouble(&ok) or !zinput.toDouble(&ok))
120 {
121 INFO(
122 "If the x/y/z-input is 0, not specified or not a real number, it "
123 "is used as 0.");
124 }
125
126 Eigen::Vector3d const displacement{xinput.toDouble(), yinput.toDouble(),
127 zinput.toDouble()};
128
129 INFO("translate model ({:f}, {:f}, {:f}).",
130 displacement[0],
131 displacement[1],
132 displacement[2]);
133
134 std::vector<std::string> const selectedData =
136
137 auto const geoNames = _geo_models->getGeometryNames();
138
139 for (auto const& data_name : selectedData)
140 {
141 if (std::find(std::begin(geoNames), std::end(geoNames), data_name) !=
142 std::end(geoNames))
143 {
144 moveGeometry(displacement, data_name);
145 continue;
146 }
147 moveMesh(displacement, data_name);
148 }
149
150 this->done(QDialog::Accepted);
151}
Definition of the AABB class.
Definition of the GEOModels class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the MeshModel class.
Definition of the Mesh class.
Definition of the Node class.
Implementation of the StrictDoubleValidator class.
Definition of the TranslateDataDialog class.
GEOModels connects the data management class GEOObjects and the GUI. It inherits from GeoLib::GEOObje...
Definition GEOModels.h:37
std::vector< std::string > getGeometryNames() const
const std::vector< GeoLib::Point * > * getPointVec(const std::string &name) const
void updateGeometry(const std::string &geo_name)
Definition GEOModels.cpp:40
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
Definition MeshModel.cpp:96
void updateMesh(MeshLib::Mesh *)
Updates the model/view for a mesh.
static void box(const QString &e)
Definition OGSError.cpp:23
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.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:50
Functionality to move mesh nodes using a given displacement vec.
void moveMeshNodes(Iterator begin, Iterator end, Eigen::Vector3d const &displacement)
std::vector< std::string > getSelectedObjects(QStringList const &list)
Definition Utils.cpp:15
void moveSelectedItems(QListView *sourceView, QStringListModel &sourceModel, QStringListModel &targetModel)
Definition Utils.cpp:23