added methods to convert between Cartesian and spherical coordinates
[engrid-github.git] / src / libengrid / guiedgelengthsourcebox.cpp
blob1cc9aa267438ed859bfef447d6954fdbed500096
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 "guiedgelengthsourcebox.h"
26 GuiEdgeLengthSourceBox::GuiEdgeLengthSourceBox()
28 m_X1 = vec3_t(0,0,0);
29 m_X2 = vec3_t(1,0,0);
30 m_Length = 1;
33 QString GuiEdgeLengthSourceBox::write()
35 QString txt = "box: " + name() + "; ";
36 QString num;
37 num.setNum(m_X1[0]); txt += num + "; ";
38 num.setNum(m_X1[1]); txt += num + "; ";
39 num.setNum(m_X1[2]); txt += num + "; ";
40 num.setNum(m_X2[0]); txt += num + "; ";
41 num.setNum(m_X2[1]); txt += num + "; ";
42 num.setNum(m_X2[2]); txt += num + "; ";
43 num.setNum(m_Length); txt += num + "; ";
44 return txt;
47 bool GuiEdgeLengthSourceBox::read(QString txt)
49 QStringList parts = txt.split(":");
50 if (parts.size() != 2) {
51 return false;
53 if (parts[0].trimmed() == "box") {
54 QStringList words = parts[1].split(";");
55 if (words.size() < 8) {
56 return false;
58 m_Name = words[0].trimmed();
59 m_X1 = vec3_t(words[1].toDouble(), words[2].toDouble(), words[3].toDouble());
60 m_X2 = vec3_t(words[4].toDouble(), words[5].toDouble(), words[6].toDouble());
61 m_Length = words[7].toDouble();
62 } else {
63 return false;
65 return true;
68 void GuiEdgeLengthSourceBox::setDlgFields()
70 ui().lineEditName->setText(name());
71 QString num;
72 num.setNum(m_X1[0]); ui().lineEditX1->setText(num);
73 num.setNum(m_X1[1]); ui().lineEditY1->setText(num);
74 num.setNum(m_X1[2]); ui().lineEditZ1->setText(num);
75 num.setNum(m_X2[0]); ui().lineEditX2->setText(num);
76 num.setNum(m_X2[1]); ui().lineEditY2->setText(num);
77 num.setNum(m_X2[2]); ui().lineEditZ2->setText(num);
78 num.setNum(m_Length); ui().lineEditEL->setText(num);
81 void GuiEdgeLengthSourceBox::readDlgFields()
83 setName(ui().lineEditName->text());
84 m_X1[0] = ui().lineEditX1->text().toDouble();
85 m_X1[1] = ui().lineEditY1->text().toDouble();
86 m_X1[2] = ui().lineEditZ1->text().toDouble();
87 m_X2[0] = ui().lineEditX2->text().toDouble();
88 m_X2[1] = ui().lineEditY2->text().toDouble();
89 m_X2[2] = ui().lineEditZ2->text().toDouble();
90 m_Length = ui().lineEditEL->text().toDouble();
93 double GuiEdgeLengthSourceBox::edgeLength(vec3_t x)
95 bool outside = false;
96 for (int i = 0; i < 3; ++i) {
97 if (x[i] < m_X1[i] || x[i] > m_X2[i]) {
98 outside = true;
99 break;
102 if (outside) {
103 return -1;
105 return m_Length;