2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "edgelengthsourcemanager.h"
26 #include "guiedgelengthsourcesphere.h"
27 #include "guiedgelengthsourcecone.h"
28 #include "guiedgelengthsourcebox.h"
29 #include "guiedgelengthsourcepipe.h"
30 #include "guimainwindow.h"
32 EdgeLengthSourceManager::EdgeLengthSourceManager()
36 m_Samples
.push_back(new GuiEdgeLengthSourceSphere
);
37 m_Samples
.push_back(new GuiEdgeLengthSourceCone
);
38 m_Samples
.push_back(new GuiEdgeLengthSourceBox
);
39 m_Samples
.push_back(new GuiEdgeLengthSourcePipe
);
43 EdgeLengthSourceManager::~EdgeLengthSourceManager()
45 foreach (EdgeLengthSource
* source
, m_Sources
) {
48 foreach (EdgeLengthSource
* sample
, m_Samples
) {
53 void EdgeLengthSourceManager::populateListWidget()
56 m_ListWidget
->clear();
57 foreach (EdgeLengthSource
*source
, m_Sources
) {
58 m_ListWidget
->addItem(source
->name());
63 void EdgeLengthSourceManager::read()
65 foreach (EdgeLengthSource
* source
, m_Sources
) {
69 QString xml_text
= GuiMainWindow::pointer()->getXmlSection("engrid/sources");
70 QStringList lines
= xml_text
.split("\n");
71 foreach (QString line
, lines
) {
72 foreach (EdgeLengthSource
* sample
, m_Samples
) {
73 if (sample
->read(line
.trimmed())) {
74 if (dynamic_cast<GuiEdgeLengthSourceSphere
*>(sample
)) {
75 GuiEdgeLengthSourceSphere
*S
= new GuiEdgeLengthSourceSphere
;
76 S
->read(line
.trimmed());
77 m_Sources
.push_back(S
);
80 if (dynamic_cast<GuiEdgeLengthSourceCone
*>(sample
)) {
81 GuiEdgeLengthSourceCone
*S
= new GuiEdgeLengthSourceCone
;
82 S
->read(line
.trimmed());
83 m_Sources
.push_back(S
);
86 if (dynamic_cast<GuiEdgeLengthSourceBox
*>(sample
)) {
87 GuiEdgeLengthSourceBox
*S
= new GuiEdgeLengthSourceBox
;
88 S
->read(line
.trimmed());
89 m_Sources
.push_back(S
);
92 if (dynamic_cast<GuiEdgeLengthSourcePipe
*>(sample
)) {
93 GuiEdgeLengthSourcePipe
*S
= new GuiEdgeLengthSourcePipe
;
94 S
->read(line
.trimmed());
95 m_Sources
.push_back(S
);
103 void EdgeLengthSourceManager::write()
105 QString xml_text
= "";
106 foreach (EdgeLengthSource
* source
, m_Sources
) {
107 xml_text
+= source
->write();
110 GuiMainWindow::pointer()->setXmlSection("engrid/sources", xml_text
);
113 double EdgeLengthSourceManager::minEdgeLength(vec3_t x
)
116 foreach (EdgeLengthSource
* source
, m_Sources
) {
117 double L
= source
->edgeLength(x
);
119 L_min
= min(L
, L_min
);
125 void EdgeLengthSourceManager::edit()
127 if (m_ListWidget
->currentItem()) {
128 QString selected_name
= m_ListWidget
->currentItem()->text();
129 foreach (EdgeLengthSource
* source
, m_Sources
) {
130 if (source
->name() == selected_name
) {
135 populateListWidget();
139 void EdgeLengthSourceManager::remove()
141 if (m_ListWidget
->currentItem()) {
142 QList
<EdgeLengthSource
*> new_sources
;
143 QString selected_name
= m_ListWidget
->currentItem()->text();
144 foreach (EdgeLengthSource
* source
, m_Sources
) {
145 if (source
->name() == selected_name
) {
148 new_sources
.push_back(source
);
151 m_Sources
= new_sources
;
152 populateListWidget();
156 void EdgeLengthSourceManager::addSphere()
158 QString name
= "sphere" + timeStamp();
159 GuiEdgeLengthSourceSphere
*S
= new GuiEdgeLengthSourceSphere
;
162 populateListWidget();
165 void EdgeLengthSourceManager::addCone()
167 QString name
= "cone" + timeStamp();
168 GuiEdgeLengthSourceCone
*S
= new GuiEdgeLengthSourceCone
;
171 populateListWidget();
174 void EdgeLengthSourceManager::addPipe()
176 QString name
= "pipe" + timeStamp();
177 GuiEdgeLengthSourcePipe
*S
= new GuiEdgeLengthSourcePipe
;
180 populateListWidget();
183 void EdgeLengthSourceManager::addBox()
185 QString name
= "box" + timeStamp();
186 GuiEdgeLengthSourceBox
*S
= new GuiEdgeLengthSourceBox
;
189 populateListWidget();