Sun, 10 Jun 2018 23:07:24 +0300
fixed bugs regarding circular primitives
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include "matrixeditor.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "ui_matrixeditor.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | MatrixEditor::MatrixEditor(const Matrix& matrix, const Vertex& position, QWidget *parent) : |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | QWidget {parent}, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | ui {*new Ui_MatrixEditor} |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | this->ui.setupUi(this); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | this->setPosition(position); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | this->setMatrix(matrix); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | for (int i : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | for (int j : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | connect( |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | matrixCell(i, j), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | this, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | &MatrixEditor::matrixChanged |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | ); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | for (QDoubleSpinBox* spinbox : {this->ui.scalingX, this->ui.scalingY, this->ui.scalingZ}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | connect( |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | spinbox, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | this, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | &MatrixEditor::scalingChanged |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | ); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | MatrixEditor::MatrixEditor(QWidget* parent) : |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | MatrixEditor {Matrix::identity, {0, 0, 0}, parent} {} |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | MatrixEditor::~MatrixEditor() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | delete &this->ui; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | * Returns a spinbox from the matrix grid at position (row, column). |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | * Row and column must be within [0, 2]. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | QDoubleSpinBox* MatrixEditor::matrixCell(int row, int column) const |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | if (qBound(0, row, 2) != row or qBound(0, column, 2) != column) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | throw std::out_of_range {"bad row and column values"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | else |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(row, column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | return item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | * Returns a spinbox for the vector element at the given position |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | * Index must be within [0, 2] |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | QDoubleSpinBox* MatrixEditor::vectorElement(int index) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | switch (index) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | case 0: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | return this->ui.scalingX; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | case 1: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | return this->ui.scalingY; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | case 2: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | return this->ui.scalingZ; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | default: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | throw std::out_of_range {"bad index"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | double MatrixEditor::matrixScaling(int column) const |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | return sqrt( |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | pow(this->matrixCell(0, column)->value(), 2) + |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | pow(this->matrixCell(1, column)->value(), 2) + |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | pow(this->matrixCell(2, column)->value(), 2) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | ); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | * Updates the appropriate matrix column when a scaling vector element is changed. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | void MatrixEditor::scalingChanged() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | for (int column : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | if (this->sender() == this->vectorElement(column)) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | double oldScaling = this->matrixScaling(column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
100 | double newScaling = static_cast<QDoubleSpinBox*>(this->sender())->value(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | if (not qFuzzyCompare(newScaling, 0.0)) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
103 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
104 | for (int row : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
105 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
106 | double cellValue = this->matrixCell(row, column)->value(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | cellValue *= newScaling / oldScaling; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
108 | QDoubleSpinBox* cellWidget = this->matrixCell(row, column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | withSignalsBlocked(cellWidget, [&]() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
110 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
111 | cellWidget->setValue(cellValue); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
112 | }); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
113 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
114 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
115 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
116 | break; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
117 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
118 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
119 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
120 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
121 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
122 | * Finds the position for the given cell widget. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
123 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
124 | QPair<int, int> MatrixEditor::cellPosition(QDoubleSpinBox* cellWidget) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
125 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
126 | for (int row : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
127 | for (int column : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
128 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
129 | if (this->matrixCell(row, column) == cellWidget) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
130 | return {row, column}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
131 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
132 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
133 | throw std::out_of_range {"widget is not in the matrix"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
134 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
135 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
136 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
137 | * Updates the appropriate scaling vector element when a matrix cell is changed. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
138 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | void MatrixEditor::matrixChanged() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
140 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
141 | QDoubleSpinBox* cellWidget = static_cast<QDoubleSpinBox*>(this->sender()); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
142 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
143 | try |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
144 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
145 | int column = this->cellPosition(cellWidget).second; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
146 | QDoubleSpinBox* spinbox = this->vectorElement(column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
147 | withSignalsBlocked(spinbox, [&]() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
148 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
149 | spinbox->setValue(this->matrixScaling(column)); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
150 | }); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
151 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
152 | catch (const std::out_of_range&) {} |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
153 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
154 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
155 | Vertex MatrixEditor::position() const |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
156 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
157 | return { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
158 | this->ui.positionX->value(), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
159 | this->ui.positionY->value(), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
160 | this->ui.positionZ->value() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
161 | }; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
162 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
163 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
164 | Matrix MatrixEditor::matrix() const |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
165 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
166 | Matrix transformationMatrix; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
167 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
168 | for (int i : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
169 | for (int j : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
170 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
171 | transformationMatrix(i, j) = this->matrixCell(i, j)->value(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
172 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
173 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
174 | return transformationMatrix; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
175 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
176 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
177 | void MatrixEditor::setPosition(const Vertex& position) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
178 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
179 | this->ui.positionX->setValue(position.x); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
180 | this->ui.positionY->setValue(position.y); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
181 | this->ui.positionZ->setValue(position.z); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
182 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
183 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
184 | void MatrixEditor::setMatrix(const Matrix& matrix) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
185 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
186 | for (int i : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
187 | for (int j : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
188 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
189 | QDoubleSpinBox* spinbox = matrixCell(i, j); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
190 | withSignalsBlocked(spinbox, [&](){ spinbox->setValue(matrix(i, j)); }); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
191 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
192 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
193 | // Fill in the initial scaling values |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
194 | for (int column : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
195 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
196 | QDoubleSpinBox* spinbox = this->vectorElement(column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
197 | withSignalsBlocked(spinbox, [&]() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
198 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
199 | spinbox->setValue(this->matrixScaling(column)); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
200 | }); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
201 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
202 | } |