feature magic defaults to 1 now
[engrid.git] / src / libengrid / guiedgelengthsourcepipe.cpp
blobdb2e741323d7b3cede1f2174703e8706ccf284c4
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2012 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 "guiedgelengthsourcepipe.h"
26 GuiEdgeLengthSourcePipe::GuiEdgeLengthSourcePipe()
28 m_X1 = vec3_t(0,0,0);
29 m_X2 = vec3_t(1,0,0);
30 m_R1 = 1;
31 m_R2 = 1;
32 m_Length1 =1;
33 m_Length2 =1;
36 QString GuiEdgeLengthSourcePipe::write()
38 QString txt = "pipe: " + name() + "; ";
39 QString num;
40 num.setNum(m_X1[0]); txt += num + "; ";
41 num.setNum(m_X1[1]); txt += num + "; ";
42 num.setNum(m_X1[2]); txt += num + "; ";
43 num.setNum(m_X2[0]); txt += num + "; ";
44 num.setNum(m_X2[1]); txt += num + "; ";
45 num.setNum(m_X2[2]); txt += num + "; ";
46 num.setNum(m_R1); txt += num + "; ";
47 num.setNum(m_R2); txt += num + "; ";
48 num.setNum(m_Length1); txt += num + "; ";
49 num.setNum(m_Length2); txt += num + "; ";
50 return txt;
53 bool GuiEdgeLengthSourcePipe::read(QString txt)
55 QStringList parts = txt.split(":");
56 if (parts.size() != 2) {
57 return false;
59 if (parts[0].trimmed() == "pipe") {
60 QStringList words = parts[1].split(";");
61 if (words.size() < 11) {
62 return false;
64 m_Name = words[0].trimmed();
65 m_X1 = vec3_t(words[1].toDouble(), words[2].toDouble(), words[3].toDouble());
66 m_X2 = vec3_t(words[4].toDouble(), words[5].toDouble(), words[6].toDouble());
67 m_R1 = words[7].toDouble();
68 m_R2 = words[8].toDouble();
69 m_Length1 = words[9].toDouble();
70 m_Length2 = words[10].toDouble();
71 } else {
72 return false;
74 return true;
77 void GuiEdgeLengthSourcePipe::setDlgFields()
79 ui().lineEditName->setText(name());
80 QString num;
81 num.setNum(m_X1[0]); ui().lineEditX1->setText(num);
82 num.setNum(m_X1[1]); ui().lineEditY1->setText(num);
83 num.setNum(m_X1[2]); ui().lineEditZ1->setText(num);
84 num.setNum(m_X2[0]); ui().lineEditX2->setText(num);
85 num.setNum(m_X2[1]); ui().lineEditY2->setText(num);
86 num.setNum(m_X2[2]); ui().lineEditZ2->setText(num);
87 num.setNum(m_R1); ui().lineEditRi->setText(num);
88 num.setNum(m_R2); ui().lineEditRo->setText(num);
89 num.setNum(m_Length1); ui().lineEditELi->setText(num);
90 num.setNum(m_Length2); ui().lineEditELo->setText(num);
93 void GuiEdgeLengthSourcePipe::readDlgFields()
95 setName(ui().lineEditName->text());
96 m_X1[0] = ui().lineEditX1->text().toDouble();
97 m_X1[1] = ui().lineEditY1->text().toDouble();
98 m_X1[2] = ui().lineEditZ1->text().toDouble();
99 m_X2[0] = ui().lineEditX2->text().toDouble();
100 m_X2[1] = ui().lineEditY2->text().toDouble();
101 m_X2[2] = ui().lineEditZ2->text().toDouble();
102 m_R1 = ui().lineEditRi->text().toDouble();
103 m_R2 = ui().lineEditRo->text().toDouble();
104 m_Length1 = ui().lineEditELi->text().toDouble();
105 m_Length2 = ui().lineEditELo->text().toDouble();
108 double GuiEdgeLengthSourcePipe::edgeLength(vec3_t x)
110 vec3_t n = m_X2 - m_X1;
111 double L = n.abs();
112 n.normalise();
113 x -= m_X1;
114 double l = x*n;
115 vec3_t a = l*n;
116 double r = (x - a).abs();
117 if (r > m_R2 || r < m_R1 || l < 0 || l > L) {
118 return -1;
120 double w = (r - m_R1)/(m_R2 - m_R1);
121 return (1 - w)*m_Length1 + w*m_Length2;