OGS
AddFaultsToVoxelGridDialog.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#include <QStringListModel>
8#include <algorithm>
9#include <string>
10
11#include "Base/OGSError.h"
12#include "Base/Utils.h"
13#include "MeshLib/Mesh.h"
14#include "MeshModel.h"
16
17QString no_voxel_str = "[No voxel grid available.]";
18
20 QDialog* parent)
21 : QDialog(parent), _mesh_model(mesh_model)
22{
23 setupUi(this);
24 QStringList voxelGridList;
25 QStringList faultsList;
26
27 for (int model_index = 0; model_index < mesh_model.rowCount();
28 ++model_index)
29 {
30 auto const* mesh = mesh_model.getMesh(mesh_model.index(model_index, 0));
31 assert(mesh);
33 *mesh))
34 {
35 voxelGridList.append(QString::fromStdString(mesh->getName()));
36 }
37 if (mesh->getDimension() == 2)
38 {
39 faultsList.append(QString::fromStdString(mesh->getName()));
40 }
41 }
42 if (voxelGridList.empty())
43 {
44 voxelGridList.append(no_voxel_str);
45 }
46
47 if (faultsList.empty())
48 {
49 faultsList.append("[No 2D faults available.]");
50 }
51
52 _voxelGrids.setStringList(voxelGridList);
53 _meshes2D.setStringList(faultsList);
54 this->voxelGridListBox->addItems(_voxelGrids.stringList());
55 this->all2Dmeshes->setModel(&_meshes2D);
56 this->selectedFaults->setModel(&_selFaults);
57}
58
63
68
70{
71 using namespace MeshToolsLib::MeshGenerator;
72 if (this->voxelGridListBox->currentText() == no_voxel_str)
73 {
74 OGSError::box("Please specify the input voxel grid.");
75 return;
76 }
77
78 auto* input_voxelgrid = _mesh_model.getMesh(
79 this->voxelGridListBox->currentText().toStdString());
80 assert(input_voxelgrid);
81 std::unique_ptr<MeshLib::Mesh> voxelgrid(
82 new MeshLib::Mesh(*input_voxelgrid));
83 assert(voxelgrid);
84
85 auto const* mat_ids = MeshLib::materialIDs(*voxelgrid);
86
87 if (mat_ids == nullptr)
88 {
89 OGSError::box("Input mesh has no material IDs");
90 return;
91 }
92
93 std::vector<std::string> const selected_faults =
95
96 if (this->_selFaults.rowCount() == 0)
97 {
98 OGSError::box("Please specify the fault(s) to be added to the mesh.");
99 return;
100 }
101
102 auto max_mat_id = std::max_element(mat_ids->cbegin(), mat_ids->cend());
103 assert(max_mat_id);
104 auto fault_id = *max_mat_id;
105 for (auto const& fault_name : selected_faults)
106 {
107 fault_id++;
108 auto const* fault = _mesh_model.getMesh(fault_name);
109 if (AddFaultToVoxelGrid::addFaultToVoxelGrid(voxelgrid.get(), fault,
110 fault_id))
111 {
112 INFO("The fault '{}' was added.", fault_name);
113 continue;
114 }
115 OGSError::box("The fault " + QString::fromStdString(fault_name) +
116 " could not be added.");
117 }
118
119 _mesh_model.addMesh(voxelgrid.release());
120 this->done(QDialog::Accepted);
121}
QString no_voxel_str
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
AddFaultsToVoxelGridDialog(MeshModel &mesh_model, QDialog *parent=nullptr)
void on_selectDataButton_pressed()
Instructions if the ">>-button" has been pressed.
void accept() override
Instructions if the OK-Button has been pressed.
void on_deselectDataButton_pressed()
Instructions if the "<<-button" has been pressed.
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
Definition MeshModel.cpp:85
static void box(const QString &e)
Definition OGSError.cpp:13
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:93
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:39
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:258
bool addFaultToVoxelGrid(MeshLib::Mesh *mesh, MeshLib::Mesh const *fault, int const fault_id)
std::vector< std::string > getSelectedObjects(QStringList const &list)
void moveSelectedItems(QListView *sourceView, QStringListModel &sourceModel, QStringListModel &targetModel)