fixed edge display for volume cells
[engrid-github.git] / src / libengrid / edgelengthsourcemanager.cpp
blob23692e90a1ee9ee0d73e887799b4d981ad3905e8
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "edgelengthsourcemanager.h"
24 #include "guiedgelengthsourcesphere.h"
25 #include "guiedgelengthsourcecone.h"
26 #include "guiedgelengthsourcebox.h"
27 #include "guiedgelengthsourcepipe.h"
28 #include "guimainwindow.h"
29 #include "ruleedgelengthsource.h"
31 EdgeLengthSourceManager::EdgeLengthSourceManager()
33 m_Sources.clear();
34 m_Samples.clear();
35 m_Samples.push_back(new GuiEdgeLengthSourceSphere);
36 m_Samples.push_back(new GuiEdgeLengthSourceCone);
37 m_Samples.push_back(new GuiEdgeLengthSourceBox);
38 m_Samples.push_back(new GuiEdgeLengthSourcePipe);
39 m_ListWidget = NULL;
42 EdgeLengthSourceManager::~EdgeLengthSourceManager()
44 clear();
46 foreach (EdgeLengthSource* sample, m_Samples) {
47 //delete sample;
52 void EdgeLengthSourceManager::populateListWidget()
54 if (m_ListWidget) {
55 m_ListWidget->clear();
56 foreach (EdgeLengthSource *source, m_Sources) {
57 m_ListWidget->addItem(source->name());
62 void EdgeLengthSourceManager::read()
64 m_Sources.clear();
65 QString xml_text = GuiMainWindow::pointer()->getXmlSection("engrid/sources");
66 QStringList lines = xml_text.split("\n");
67 foreach (QString line, lines) {
68 foreach (EdgeLengthSource* sample, m_Samples) {
69 if (sample->read(line.trimmed())) {
70 if (dynamic_cast<GuiEdgeLengthSourceSphere*>(sample)) {
71 GuiEdgeLengthSourceSphere *S = new GuiEdgeLengthSourceSphere;
72 S->read(line.trimmed());
73 m_Sources.push_back(S);
74 break;
76 if (dynamic_cast<GuiEdgeLengthSourceCone*>(sample)) {
77 GuiEdgeLengthSourceCone *S = new GuiEdgeLengthSourceCone;
78 S->read(line.trimmed());
79 m_Sources.push_back(S);
80 break;
82 if (dynamic_cast<GuiEdgeLengthSourceBox*>(sample)) {
83 GuiEdgeLengthSourceBox *S = new GuiEdgeLengthSourceBox;
84 S->read(line.trimmed());
85 m_Sources.push_back(S);
86 break;
88 if (dynamic_cast<GuiEdgeLengthSourcePipe*>(sample)) {
89 GuiEdgeLengthSourcePipe *S = new GuiEdgeLengthSourcePipe;
90 S->read(line.trimmed());
91 m_Sources.push_back(S);
92 break;
99 void EdgeLengthSourceManager::write()
101 QString xml_text = "";
102 foreach (EdgeLengthSource* source, m_Sources) {
103 xml_text += source->write();
104 xml_text += "\n";
106 GuiMainWindow::pointer()->setXmlSection("engrid/sources", xml_text);
109 double EdgeLengthSourceManager::minEdgeLength(vec3_t x)
111 double L_min = 1e99;
112 foreach (EdgeLengthSource* source, m_Sources) {
113 double L = source->edgeLength(x);
114 if (L > 0) {
115 L_min = min(L, L_min);
118 return L_min;
121 void EdgeLengthSourceManager::edit()
123 if (m_ListWidget->currentItem()) {
124 QString selected_name = m_ListWidget->currentItem()->text();
125 foreach (EdgeLengthSource* source, m_Sources) {
126 if (source->name() == selected_name) {
127 source->config();
128 break;
131 populateListWidget();
135 void EdgeLengthSourceManager::remove()
137 if (m_ListWidget->currentItem()) {
138 QList<EdgeLengthSource*> new_sources;
139 QString selected_name = m_ListWidget->currentItem()->text();
140 foreach (EdgeLengthSource* source, m_Sources) {
141 if (source->name() == selected_name) {
142 delete source;
143 } else {
144 new_sources.push_back(source);
147 m_Sources = new_sources;
148 populateListWidget();
152 void EdgeLengthSourceManager::addSphere()
154 QString name = "sphere" + timeStamp();
155 GuiEdgeLengthSourceSphere *S = new GuiEdgeLengthSourceSphere;
156 S->setName(name);
157 m_Sources.append(S);
158 populateListWidget();
161 void EdgeLengthSourceManager::addCone()
163 QString name = "cone" + timeStamp();
164 GuiEdgeLengthSourceCone *S = new GuiEdgeLengthSourceCone;
165 S->setName(name);
166 m_Sources.append(S);
167 populateListWidget();
170 void EdgeLengthSourceManager::addPipe()
172 QString name = "pipe" + timeStamp();
173 GuiEdgeLengthSourcePipe *S = new GuiEdgeLengthSourcePipe;
174 S->setName(name);
175 m_Sources.append(S);
176 populateListWidget();
179 void EdgeLengthSourceManager::addBox()
181 QString name = "box" + timeStamp();
182 GuiEdgeLengthSourceBox *S = new GuiEdgeLengthSourceBox;
183 S->setName(name);
184 m_Sources.append(S);
185 populateListWidget();
188 void EdgeLengthSourceManager::readRules(vtkUnstructuredGrid *grid)
190 QString rules_txt = GuiMainWindow::pointer()->getXmlSection("engrid/surface/rules");
191 rules_txt = rules_txt.replace("\n", " ");
192 rules_txt = rules_txt.trimmed();
193 QStringList rules = rules_txt.split(";", QString::SkipEmptyParts);
194 foreach (QString rule, rules) {
195 RuleEdgeLengthSource *S = new RuleEdgeLengthSource(rule.trimmed(), grid);
196 m_Sources.append(S);
200 void EdgeLengthSourceManager::readBoundaryLayerRules(vtkUnstructuredGrid *grid)
202 QString rules_txt = GuiMainWindow::pointer()->getXmlSection("engrid/blayer/rules");
203 rules_txt = rules_txt.replace("\n", " ");
204 rules_txt = rules_txt.trimmed();
205 QStringList rules = rules_txt.split(";", QString::SkipEmptyParts);
206 foreach (QString rule, rules) {
207 RuleEdgeLengthSource *S = new RuleEdgeLengthSource(rule.trimmed(), grid);
208 m_Sources.append(S);
212 void EdgeLengthSourceManager::clear()
214 foreach (EdgeLengthSource* source, m_Sources) {
215 delete source;
217 m_Sources.clear();