better collision detection
[engrid-github.git] / src / libengrid / guiedgelengthsourcebox.cpp
blob192fd7d15b572c0662eccd07a733ce2d0d57b6f1
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 "guiedgelengthsourcebox.h"
24 GuiEdgeLengthSourceBox::GuiEdgeLengthSourceBox()
26 m_X1 = vec3_t(0,0,0);
27 m_X2 = vec3_t(1,0,0);
28 m_Length = 1;
31 QString GuiEdgeLengthSourceBox::write()
33 QString txt = "box: " + name() + "; ";
34 QString num;
35 num.setNum(m_X1[0]); txt += num + "; ";
36 num.setNum(m_X1[1]); txt += num + "; ";
37 num.setNum(m_X1[2]); txt += num + "; ";
38 num.setNum(m_X2[0]); txt += num + "; ";
39 num.setNum(m_X2[1]); txt += num + "; ";
40 num.setNum(m_X2[2]); txt += num + "; ";
41 num.setNum(m_Length); txt += num + "; ";
42 return txt;
45 bool GuiEdgeLengthSourceBox::read(QString txt)
47 QStringList parts = txt.split(":");
48 if (parts.size() != 2) {
49 return false;
51 if (parts[0].trimmed() == "box") {
52 QStringList words = parts[1].split(";");
53 if (words.size() < 8) {
54 return false;
56 m_Name = words[0].trimmed();
57 m_X1 = vec3_t(words[1].toDouble(), words[2].toDouble(), words[3].toDouble());
58 m_X2 = vec3_t(words[4].toDouble(), words[5].toDouble(), words[6].toDouble());
59 m_Length = words[7].toDouble();
60 } else {
61 return false;
63 return true;
66 void GuiEdgeLengthSourceBox::setDlgFields()
68 ui().lineEditName->setText(name());
69 QString num;
70 num.setNum(m_X1[0]); ui().lineEditX1->setText(num);
71 num.setNum(m_X1[1]); ui().lineEditY1->setText(num);
72 num.setNum(m_X1[2]); ui().lineEditZ1->setText(num);
73 num.setNum(m_X2[0]); ui().lineEditX2->setText(num);
74 num.setNum(m_X2[1]); ui().lineEditY2->setText(num);
75 num.setNum(m_X2[2]); ui().lineEditZ2->setText(num);
76 num.setNum(m_Length); ui().lineEditEL->setText(num);
79 void GuiEdgeLengthSourceBox::readDlgFields()
81 setName(ui().lineEditName->text());
82 m_X1[0] = ui().lineEditX1->text().toDouble();
83 m_X1[1] = ui().lineEditY1->text().toDouble();
84 m_X1[2] = ui().lineEditZ1->text().toDouble();
85 m_X2[0] = ui().lineEditX2->text().toDouble();
86 m_X2[1] = ui().lineEditY2->text().toDouble();
87 m_X2[2] = ui().lineEditZ2->text().toDouble();
88 m_Length = ui().lineEditEL->text().toDouble();
91 double GuiEdgeLengthSourceBox::edgeLength(vec3_t x)
93 bool outside = false;
94 for (int i = 0; i < 3; ++i) {
95 if (x[i] < m_X1[i] || x[i] > m_X2[i]) {
96 outside = true;
97 break;
100 if (outside) {
101 return -1;
103 return m_Length;