various improvements to speed up surface meshing of BRL-CAD geometries
[engrid.git] / src / libengrid / edgelengthsourcemanager.cpp
blobc44f513f999bf01b8f8201f7f80afaf5c8948989
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
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()
34 m_Sources.clear();
35 m_Samples.clear();
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);
40 m_ListWidget = NULL;
43 EdgeLengthSourceManager::~EdgeLengthSourceManager()
45 foreach (EdgeLengthSource* source, m_Sources) {
46 //delete source;
48 foreach (EdgeLengthSource* sample, m_Samples) {
49 //delete sample;
53 void EdgeLengthSourceManager::populateListWidget()
55 if (m_ListWidget) {
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) {
66 //delete source;
68 m_Sources.clear();
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);
78 break;
80 if (dynamic_cast<GuiEdgeLengthSourceCone*>(sample)) {
81 GuiEdgeLengthSourceCone *S = new GuiEdgeLengthSourceCone;
82 S->read(line.trimmed());
83 m_Sources.push_back(S);
84 break;
86 if (dynamic_cast<GuiEdgeLengthSourceBox*>(sample)) {
87 GuiEdgeLengthSourceBox *S = new GuiEdgeLengthSourceBox;
88 S->read(line.trimmed());
89 m_Sources.push_back(S);
90 break;
92 if (dynamic_cast<GuiEdgeLengthSourcePipe*>(sample)) {
93 GuiEdgeLengthSourcePipe *S = new GuiEdgeLengthSourcePipe;
94 S->read(line.trimmed());
95 m_Sources.push_back(S);
96 break;
103 void EdgeLengthSourceManager::write()
105 QString xml_text = "";
106 foreach (EdgeLengthSource* source, m_Sources) {
107 xml_text += source->write();
108 xml_text += "\n";
110 GuiMainWindow::pointer()->setXmlSection("engrid/sources", xml_text);
113 double EdgeLengthSourceManager::minEdgeLength(vec3_t x)
115 double L_min = 1e99;
116 foreach (EdgeLengthSource* source, m_Sources) {
117 double L = source->edgeLength(x);
118 if (L > 0) {
119 L_min = min(L, L_min);
122 return 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) {
131 source->config();
132 break;
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) {
146 delete source;
147 } else {
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;
160 S->setName(name);
161 m_Sources.append(S);
162 populateListWidget();
165 void EdgeLengthSourceManager::addCone()
167 QString name = "cone" + timeStamp();
168 GuiEdgeLengthSourceCone *S = new GuiEdgeLengthSourceCone;
169 S->setName(name);
170 m_Sources.append(S);
171 populateListWidget();
174 void EdgeLengthSourceManager::addPipe()
176 QString name = "pipe" + timeStamp();
177 GuiEdgeLengthSourcePipe *S = new GuiEdgeLengthSourcePipe;
178 S->setName(name);
179 m_Sources.append(S);
180 populateListWidget();
183 void EdgeLengthSourceManager::addBox()
185 QString name = "box" + timeStamp();
186 GuiEdgeLengthSourceBox *S = new GuiEdgeLengthSourceBox;
187 S->setName(name);
188 m_Sources.append(S);
189 populateListWidget();