1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
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()
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
);
42 EdgeLengthSourceManager::~EdgeLengthSourceManager()
46 foreach (EdgeLengthSource* sample, m_Samples) {
52 void EdgeLengthSourceManager::populateListWidget()
55 m_ListWidget
->clear();
56 foreach (EdgeLengthSource
*source
, m_Sources
) {
57 m_ListWidget
->addItem(source
->name());
62 void EdgeLengthSourceManager::read()
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
);
76 if (dynamic_cast<GuiEdgeLengthSourceCone
*>(sample
)) {
77 GuiEdgeLengthSourceCone
*S
= new GuiEdgeLengthSourceCone
;
78 S
->read(line
.trimmed());
79 m_Sources
.push_back(S
);
82 if (dynamic_cast<GuiEdgeLengthSourceBox
*>(sample
)) {
83 GuiEdgeLengthSourceBox
*S
= new GuiEdgeLengthSourceBox
;
84 S
->read(line
.trimmed());
85 m_Sources
.push_back(S
);
88 if (dynamic_cast<GuiEdgeLengthSourcePipe
*>(sample
)) {
89 GuiEdgeLengthSourcePipe
*S
= new GuiEdgeLengthSourcePipe
;
90 S
->read(line
.trimmed());
91 m_Sources
.push_back(S
);
99 void EdgeLengthSourceManager::write()
101 QString xml_text
= "";
102 foreach (EdgeLengthSource
* source
, m_Sources
) {
103 xml_text
+= source
->write();
106 GuiMainWindow::pointer()->setXmlSection("engrid/sources", xml_text
);
109 double EdgeLengthSourceManager::minEdgeLength(vec3_t x
)
112 foreach (EdgeLengthSource
* source
, m_Sources
) {
113 double L
= source
->edgeLength(x
);
115 L_min
= min(L
, 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
) {
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
) {
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
;
158 populateListWidget();
161 void EdgeLengthSourceManager::addCone()
163 QString name
= "cone" + timeStamp();
164 GuiEdgeLengthSourceCone
*S
= new GuiEdgeLengthSourceCone
;
167 populateListWidget();
170 void EdgeLengthSourceManager::addPipe()
172 QString name
= "pipe" + timeStamp();
173 GuiEdgeLengthSourcePipe
*S
= new GuiEdgeLengthSourcePipe
;
176 populateListWidget();
179 void EdgeLengthSourceManager::addBox()
181 QString name
= "box" + timeStamp();
182 GuiEdgeLengthSourceBox
*S
= new GuiEdgeLengthSourceBox
;
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
);
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
);
212 void EdgeLengthSourceManager::clear()
214 foreach (EdgeLengthSource
* source
, m_Sources
) {