updated to modern VTK
[engrid-github.git] / src / libengrid / guiedgelengthsourcesphere.cpp
blob275297189ef41c1d9ee98d331e0b0087de6d3241
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 "guiedgelengthsourcesphere.h"
24 GuiEdgeLengthSourceSphere::GuiEdgeLengthSourceSphere()
26 m_Centre = vec3_t(0,0,0);
27 m_Radius = 1;
28 m_Length1 = 1;
29 m_Length2 = 1;
32 QString GuiEdgeLengthSourceSphere::write()
34 QString txt = "sphere: " + name() + "; ";
35 QString num;
36 num.setNum(m_Centre[0]); txt += num + "; ";
37 num.setNum(m_Centre[1]); txt += num + "; ";
38 num.setNum(m_Centre[2]); txt += num + "; ";
39 num.setNum(m_Radius); txt += num + "; ";
40 num.setNum(m_Length1); txt += num + "; ";
41 num.setNum(m_Length2); txt += num + "; ";
42 return txt;
45 bool GuiEdgeLengthSourceSphere::read(QString txt)
47 QStringList parts = txt.split(":");
48 if (parts.size() != 2) {
49 return false;
51 if (parts[0].trimmed() == "sphere") {
52 QStringList words = parts[1].split(";");
53 if (words.size() < 7) {
54 return false;
56 m_Name = words[0].trimmed();
57 m_Centre = vec3_t(words[1].toDouble(), words[2].toDouble(), words[3].toDouble());
58 m_Radius = words[4].toDouble();
59 m_Length1 = words[5].toDouble();
60 m_Length2 = words[6].toDouble();
61 } else {
62 return false;
64 return true;
67 void GuiEdgeLengthSourceSphere::setDlgFields()
69 ui().lineEditName->setText(name());
70 QString num;
71 num.setNum(m_Centre[0]); ui().lineEditX->setText(num);
72 num.setNum(m_Centre[1]); ui().lineEditY->setText(num);
73 num.setNum(m_Centre[2]); ui().lineEditZ->setText(num);
74 num.setNum(m_Radius); ui().lineEditR->setText(num);
75 num.setNum(m_Length1); ui().lineEditEL1->setText(num);
76 num.setNum(m_Length2); ui().lineEditEL2->setText(num);
79 void GuiEdgeLengthSourceSphere::readDlgFields()
81 setName(ui().lineEditName->text());
82 m_Centre[0] = ui().lineEditX->text().toDouble();
83 m_Centre[1] = ui().lineEditY->text().toDouble();
84 m_Centre[2] = ui().lineEditZ->text().toDouble();
85 m_Radius = ui().lineEditR->text().toDouble();
86 m_Length1 = ui().lineEditEL1->text().toDouble();
87 m_Length2 = ui().lineEditEL2->text().toDouble();
90 double GuiEdgeLengthSourceSphere::edgeLength(vec3_t x)
92 double r = (x - m_Centre).abs();
93 if (r > m_Radius) {
94 return -1;
96 return m_Length1 + r/m_Radius*(m_Length2 - m_Length1);