Thu, 10 May 2018 14:57:23 +0300
added scaling vector editing into the subfile editing dialog
1326 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2018 Teemu Piippo | |
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 | ||
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #include "subfilereferenceeditor.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "ui_subfilereferenceeditor.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include "../linetypes/modelobject.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "../primitives.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | #include "../guiutilities.h" |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
24 | #include "../dialogs/colorselector.h" |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) : |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | QDialog {parent}, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | reference {reference}, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | ui {*new Ui::SubfileReferenceEditor} |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | this->ui.setupUi(this); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | this->ui.referenceName->setText(reference->referenceName()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | this->color = reference->color(); |
1299 | 34 | ::setColorButton(this->ui.colorButton, this->color); |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1299
diff
changeset
|
35 | this->ui.positionX->setValue(reference->position().x); |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1299
diff
changeset
|
36 | this->ui.positionY->setValue(reference->position().y); |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1299
diff
changeset
|
37 | this->ui.positionZ->setValue(reference->position().z); |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
38 | connect( |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
39 | this->ui.colorButton, |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
40 | &QPushButton::clicked, |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
41 | [&]() |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
42 | { |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
43 | if (ColorSelector::selectColor(this, this->color, this->color)) |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
44 | ::setColorButton(this->ui.colorButton, this->color); |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
45 | } |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
46 | ); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | for (int i : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | for (int j : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
52 | spinbox->blockSignals(true); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | spinbox->setValue(reference->transformationMatrix()(i, j)); |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
54 | spinbox->blockSignals(false); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
55 | connect( |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
56 | spinbox, |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
57 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
58 | this, |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
59 | &SubfileReferenceEditor::matrixChanged |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
60 | ); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | connect( |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | this->ui.primitivesTreeView, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | &QTreeView::clicked, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | [&](const QModelIndex& index) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | QAbstractItemModel* model = this->ui.primitivesTreeView->model(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | if (primitiveName.isValid()) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | this->ui.referenceName->setText(primitiveName.toString()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | ); |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
74 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
75 | for (QDoubleSpinBox* spinbox : {this->ui.scalingX, this->ui.scalingY, this->ui.scalingZ}) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
76 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
77 | connect( |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
78 | spinbox, |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
79 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
80 | this, |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
81 | &SubfileReferenceEditor::scalingChanged |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
82 | ); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
83 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
84 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
85 | // Fill in the initial scaling values |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
86 | for (int column : {0, 1, 2}) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
87 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
88 | QDoubleSpinBox* spinbox = this->vectorElement(column); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
89 | spinbox->blockSignals(true); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
90 | spinbox->setValue(this->matrixScaling(column)); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
91 | spinbox->blockSignals(false); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
92 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
93 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
94 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
95 | SubfileReferenceEditor::~SubfileReferenceEditor() |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
96 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
97 | delete &this->ui; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
98 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
99 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
100 | /* |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
101 | * Returns a spinbox from the matrix grid at position (row, column). |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
102 | * Row and column must be within [0, 2]. |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
103 | */ |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
104 | QDoubleSpinBox* SubfileReferenceEditor::matrixCell(int row, int column) const |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
105 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
106 | if (qBound(0, row, 2) != row or qBound(0, column, 2) != column) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
107 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
108 | throw std::out_of_range {"bad row and column values"}; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
109 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
110 | else |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
111 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
112 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(row, column); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
113 | return item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
114 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
115 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
116 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
117 | /* |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
118 | * Returns a spinbox for the vector element at the given position |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
119 | * Index must be within [0, 2] |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
120 | */ |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
121 | QDoubleSpinBox* SubfileReferenceEditor::vectorElement(int index) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
122 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
123 | switch (index) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
124 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
125 | case 0: |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
126 | return this->ui.scalingX; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
127 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
128 | case 1: |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
129 | return this->ui.scalingY; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
130 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
131 | case 2: |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
132 | return this->ui.scalingZ; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
133 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
134 | default: |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
135 | throw std::out_of_range {"bad index"}; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
136 | } |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
137 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
138 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | void SubfileReferenceEditor::accept() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
140 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
141 | this->reference->setReferenceName(this->ui.referenceName->text()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
142 | Matrix transformationMatrix; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
143 | for (int i : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
144 | for (int j : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
145 | { |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
146 | transformationMatrix(i, j) = this->matrixCell(i, j)->value(); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
147 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
148 | this->reference->setTransformationMatrix(transformationMatrix); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
149 | this->reference->setPosition({ |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
150 | this->ui.positionX->value(), |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
151 | this->ui.positionY->value(), |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
152 | this->ui.positionZ->value() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
153 | }); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
154 | this->reference->setColor(this->color); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
155 | QDialog::accept(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
156 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
157 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
158 | void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
159 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
160 | this->ui.primitivesTreeView->setModel(primitives); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
161 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
162 | |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
163 | double SubfileReferenceEditor::matrixScaling(int column) const |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
164 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
165 | return sqrt( |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
166 | pow(this->matrixCell(0, column)->value(), 2) + |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
167 | pow(this->matrixCell(1, column)->value(), 2) + |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
168 | pow(this->matrixCell(2, column)->value(), 2) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
169 | ); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
170 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
171 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
172 | /* |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
173 | * Updates the appropriate matrix column when a scaling vector element is changed. |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
174 | */ |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
175 | void SubfileReferenceEditor::scalingChanged() |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
176 | { |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
177 | for (int column : {0, 1, 2}) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
178 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
179 | if (this->sender() == this->vectorElement(column)) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
180 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
181 | double oldScaling = this->matrixScaling(column); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
182 | double newScaling = static_cast<QDoubleSpinBox*>(this->sender())->value(); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
183 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
184 | if (not qFuzzyCompare(newScaling, 0.0)) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
185 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
186 | for (int row : {0, 1, 2}) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
187 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
188 | double cellValue = abs(this->matrixCell(row, column)->value()); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
189 | cellValue *= newScaling / oldScaling; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
190 | QDoubleSpinBox* cellWidget = this->matrixCell(row, column); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
191 | cellWidget->blockSignals(true); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
192 | cellWidget->setValue(cellValue); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
193 | cellWidget->blockSignals(false); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
194 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
195 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
196 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
197 | break; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
198 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
199 | } |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
200 | } |
1386
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
201 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
202 | /* |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
203 | * Finds the position for the given cell widget. |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
204 | */ |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
205 | QPair<int, int> SubfileReferenceEditor::cellPosition(QDoubleSpinBox* cellWidget) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
206 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
207 | for (int row : {0, 1, 2}) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
208 | for (int column : {0, 1, 2}) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
209 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
210 | if (this->matrixCell(row, column) == cellWidget) |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
211 | return {row, column}; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
212 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
213 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
214 | throw std::out_of_range {"widget is not in the matrix"}; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
215 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
216 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
217 | /* |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
218 | * Updates the appropriate scaling vector element when a matrix cell is changed. |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
219 | */ |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
220 | void SubfileReferenceEditor::matrixChanged() |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
221 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
222 | QDoubleSpinBox* cellWidget = static_cast<QDoubleSpinBox*>(this->sender()); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
223 | |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
224 | try |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
225 | { |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
226 | int column = this->cellPosition(cellWidget).second; |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
227 | QDoubleSpinBox* spinbox = this->vectorElement(column); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
228 | spinbox->blockSignals(true); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
229 | spinbox->setValue(this->matrixScaling(column)); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
230 | spinbox->blockSignals(false); |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
231 | } |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
232 | catch (const std::out_of_range&) {} |
c59dac18b06b
added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
233 | } |