OGS
ProcessModel.cpp
Go to the documentation of this file.
1
11#include "ProcessModel.h"
12
13#include <vtkPolyDataAlgorithm.h>
14
15#include <QFileInfo>
16
18#include "CondItem.h"
19#include "GeoLib/GEOObjects.h"
20#include "GeoLib/GeoObject.h"
21#include "GeoLib/GeoType.h"
22#include "ProcessVarItem.h"
23
25 : TreeModel(parent), _project(project)
26{
27 QList<QVariant> rootData;
28 delete _rootItem;
29 rootData << "Name"
30 << "Value"
31 << ""
32 << ""
33 << "";
34 _rootItem = new TreeItem(rootData, nullptr);
35}
36
37int ProcessModel::columnCount(QModelIndex const& parent) const
38{
39 Q_UNUSED(parent)
40
41 return 2;
42}
43
45 ProcessVarItem* parent)
46{
47 QList<QVariant> item_data;
48
49 item_data << QString::fromStdString(cond->getParamName())
50 << QString::fromStdString(cond->getConditionClassStr());
51
52 auto* cond_item = new CondItem(item_data, parent, cond);
53 parent->appendChild(cond_item);
54}
55
57{
58 QString const name(QString::fromStdString(condition->getProcessVarName()));
59 ProcessVarItem* process_var(getProcessVarItem(name));
60 if (process_var == nullptr)
61 {
62 process_var = addProcessVar(name);
63 }
64 addConditionItem(condition, process_var);
65}
66
68 std::vector<std::unique_ptr<DataHolderLib::BoundaryCondition>> const&
69 conditions)
70{
71 for (auto& cond : conditions)
72 {
73 addCondition(cond.get());
74 }
75}
76
78 std::vector<std::unique_ptr<DataHolderLib::SourceTerm>> const& conditions)
79{
80 for (auto& cond : conditions)
81 {
82 addCondition(cond.get());
83 }
84}
85
87{
88 beginResetModel();
89 QList<QVariant> process_var_data;
90 process_var_data << QVariant(name) << "";
91 auto* process_var = new ProcessVarItem(process_var_data, _rootItem);
92 _rootItem->appendChild(process_var);
93 endResetModel();
94 return process_var;
95}
96
98{
99 int const n_children(_rootItem->childCount());
100 for (int i = 0; i < n_children; ++i)
101 {
102 auto* item(dynamic_cast<ProcessVarItem*>(_rootItem->child(i)));
103 if (item != nullptr && item->getName() == name)
104 {
105 return item;
106 }
107 }
108 return nullptr;
109}
110
112 QString const& param_name)
113{
114 int const n_conditions = process_var->childCount();
115 for (int i = 0; i < n_conditions; ++i)
116 {
117 CondItem const* const cond =
118 dynamic_cast<CondItem*>(process_var->child(i));
119 if (cond->getCondition()->getParamName() != param_name.toStdString())
120 {
121 continue;
122 }
123
124 process_var->removeChildren(i, 1);
125 return;
126 }
127}
128
129void ProcessModel::removeCondition(QString const& process_var,
130 QString const& param)
131{
132 beginResetModel();
133 ProcessVarItem* pv_item(getProcessVarItem(process_var));
134 if (pv_item == nullptr)
135 {
136 return;
137 }
138
139 removeCondition(pv_item, param);
140 _project.removeBoundaryCondition(process_var.toStdString(),
141 param.toStdString());
142 _project.removeSourceTerm(process_var.toStdString(), param.toStdString());
143 endResetModel();
144}
145
146void ProcessModel::removeProcessVariable(QString const& name)
147{
148 beginResetModel();
149 ProcessVarItem* pv_item(getProcessVarItem(name));
150 if (pv_item == nullptr)
151 {
152 return;
153 }
154
155 int const n_conds = pv_item->childCount();
156 for (int i = n_conds - 1; i >= 0; --i)
157 {
158 removeCondition(pv_item,
159 static_cast<CondItem*>(pv_item->child(i))->getName());
160 }
161
162 _project.removePrimaryVariable(name.toStdString());
163 int const idx = pv_item->row();
164 _rootItem->removeChildren(idx, 1);
165 endResetModel();
166}
167
169{
170 int const n_process_vars = _rootItem->childCount();
171 for (int i = n_process_vars; i >= 0; --i)
172 {
173 auto* pv_item = dynamic_cast<ProcessVarItem*>(_rootItem->child(i));
174 removeProcessVariable(pv_item->getName());
175 }
176}
177
Definition of the GEOObjects class.
Base class for classes Point, Polyline, Surface.
Definition of the GEOTYPE enumeration.
Definition of the ProcessModel class.
A TreeItem containing a boundary condition or source term.
Definition CondItem.h:26
DataHolderLib::FemCondition * getCondition() const
Returns the FEM Condition associated with the item.
Definition CondItem.h:36
QString const getName() const
Definition CondItem.h:38
Base class for boundary conditions, initial conditions and source terms.
virtual std::string const getConditionClassStr() const =0
Returns the type of condition for displaying purposes.
std::string const getProcessVarName() const
Returns the name of the associated process variable.
std::string const getParamName() const
Returns the name of the parameter associated with the condition.
void removeSourceTerm(std::string const &primary_var_name, std::string const &param_name)
Remove one source term.
Definition Project.cpp:139
void removePrimaryVariable(std::string const &primary_var_name)
Removes a primary variable incl. all associated conditions.
Definition Project.cpp:100
std::vector< std::unique_ptr< SourceTerm > > const & getSourceTerms() const
Returns the vector of source terms.
Definition Project.h:87
std::vector< std::unique_ptr< BoundaryCondition > > const & getBoundaryConditions() const
Returns the vector of boundary conditions.
Definition Project.h:81
void removeBoundaryCondition(std::string const &primary_var_name, std::string const &param_name)
Removes one boundary condition.
Definition Project.cpp:123
void removeProcessVariable(QString const &name)
Removes a process variable incl all associated conditions from the model.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void updateModel()
Updates the model based on the ProjectData-object.
ProcessVarItem * addProcessVar(QString const &name)
Adds a process to the model.
void addBoundaryConditions(std::vector< std::unique_ptr< DataHolderLib::BoundaryCondition > > const &conditions)
Adds vector of Boundary Conditions to the model.
void clearModel()
Removes the complete content from the model.
void addCondition(DataHolderLib::FemCondition *condition)
Adds a single FEM Conditions to the model.
ProcessVarItem * getProcessVarItem(QString const &process_var_name) const
ProcessModel(DataHolderLib::Project &project, QObject *parent=nullptr)
DataHolderLib::Project & _project
void addConditionItem(DataHolderLib::FemCondition *cond, ProcessVarItem *parent)
Adds a new FEM condition to the condition tree model.
void removeCondition(QString const &process_var, QString const &param)
Removes FEMConditions from the the model.
void addSourceTerms(std::vector< std::unique_ptr< DataHolderLib::SourceTerm > > const &conditions)
Adds vector of Source Terms to the model.
A TreeItem representing process variable information.
Objects nodes for the TreeModel.
Definition TreeItem.h:28
virtual int childCount() const
Definition TreeItem.cpp:65
void appendChild(TreeItem *item)
Definition TreeItem.cpp:42
TreeItem * child(int row) const
Definition TreeItem.cpp:52
int row() const
Definition TreeItem.cpp:73
bool removeChildren(int position, int count)
Definition TreeItem.cpp:124
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30
QModelIndex parent(const QModelIndex &index) const override
Definition TreeModel.cpp:81
TreeItem * _rootItem
Definition TreeModel.h:58