Sun, 10 Jun 2018 23:07:24 +0300
fixed bugs regarding circular primitives
1302 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
1302 | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #include <QDoubleSpinBox> |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "../linetypes/modelobject.h" |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include "vertexobjecteditor.h" |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "ui_vertexobjecteditor.h" |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | #include "../dialogs/colorselector.h" |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1296
diff
changeset
|
24 | #include "../guiutilities.h" |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) : |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | QDialog {parent}, |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | ui {*new Ui_VertexObjectEditor}, |
1392 | 29 | vertexGrid {new QGridLayout}, |
30 | object {object} | |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | this->ui.setupUi(this); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | this->ui.verticesContainer->setLayout(this->vertexGrid); |
1395
23551de3da36
separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
34 | this->ui.colorButton->setColor(object->color()); |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | for (int i : range(0, 1, object->numVertices() - 1)) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | for (Axis axis : {X, Y, Z}) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | QDoubleSpinBox* spinbox = new QDoubleSpinBox; |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | spinbox->setMinimum(-1e6); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | spinbox->setMaximum(1e6); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | spinbox->setDecimals(5); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | this->vertexGrid->addWidget(spinbox, i, axis); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | for (int i : range(0, 1, object->numVertices() - 1)) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | for (Axis axis : {X, Y, Z}) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | QDoubleSpinBox* spinbox = this->spinboxAt(i, axis); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | if (spinbox) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | spinbox->setValue(this->object->vertex(i)[axis]); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | VertexObjectEditor::~VertexObjectEditor() |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | delete &this->ui; |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget(); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | return qobject_cast<QDoubleSpinBox*>(widget); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | void VertexObjectEditor::accept() |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | for (int i : range(0, 1, object->numVertices() - 1)) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | Vertex vertex; |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | for (Axis axis : {X, Y, Z}) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | { |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | QDoubleSpinBox* spinbox = this->spinboxAt(i, axis); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | if (spinbox) |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | vertex.setCoordinate(axis, spinbox->value()); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | this->object->setVertex(i, vertex); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | } |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | |
1395
23551de3da36
separated the color button into a new widget
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
88 | this->object->setColor(ui.colorButton->color()); |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | QDialog::accept(); |
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | } |