Sat, 13 Jan 2018 00:06:56 +0200
disable lighting in the selection scene
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <limits> |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QDir> |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QInputDialog> |
1156
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
22 | #include <QMessageBox> |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "../mainwindow.h" |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "../main.h" |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1144
diff
changeset
|
25 | #include "../lddocument.h" |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "../miscallenous.h" |
1144
4f226fd97826
Renamed glRenderer.cpp → glrenderer.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1143
diff
changeset
|
27 | #include "../glrenderer.h" |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | #include "../colors.h" |
1025
4949da3fb4b3
Renamed ldObjectMath.cpp/.h to mathfunctions.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1017
diff
changeset
|
29 | #include "../mathfunctions.h" |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "../ldobjectiterator.h" |
998 | 31 | #include "../documentmanager.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1116
diff
changeset
|
32 | #include "../linetypes/comment.h" |
1141
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
33 | #include "../linetypes/conditionaledge.h" |
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
34 | #include "../linetypes/edgeline.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1116
diff
changeset
|
35 | #include "../linetypes/empty.h" |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1148
diff
changeset
|
36 | #include "../linetypes/quadrilateral.h" |
1148
96cb15a7611f
Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1145
diff
changeset
|
37 | #include "../linetypes/triangle.h" |
1164
eabcd749759a
Moved all UI files from ui/ into src/dialogs/.
Teemu Piippo <teemu@hecknology.net>
parents:
1163
diff
changeset
|
38 | #include "ui_replacecoordinatesdialog.h" |
eabcd749759a
Moved all UI files from ui/ into src/dialogs/.
Teemu Piippo <teemu@hecknology.net>
parents:
1163
diff
changeset
|
39 | #include "ui_editrawdialog.h" |
eabcd749759a
Moved all UI files from ui/ into src/dialogs/.
Teemu Piippo <teemu@hecknology.net>
parents:
1163
diff
changeset
|
40 | #include "ui_flipdialog.h" |
eabcd749759a
Moved all UI files from ui/ into src/dialogs/.
Teemu Piippo <teemu@hecknology.net>
parents:
1163
diff
changeset
|
41 | #include "ui_addhistorylinedialog.h" |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | #include "algorithmtoolset.h" |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | AlgorithmToolset::AlgorithmToolset (MainWindow* parent) : |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | Toolset (parent) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | void AlgorithmToolset::splitQuads() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | { |
1074
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
51 | int count = 0; |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
52 | |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
53 | for (LDObject* object : selectedObjects().toList()) |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
54 | { |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
55 | if (object->numVertices() != 4) |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
56 | continue; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
1074
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
58 | Vertex v0 = object->vertex(0); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
59 | Vertex v1 = object->vertex(1); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
60 | Vertex v2 = object->vertex(2); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
61 | Vertex v3 = object->vertex(3); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
62 | LDColor color = object->color(); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
63 | |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | // Find the index of this quad |
1074
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
65 | int index = object->lineNumber(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | if (index == -1) |
1074
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
67 | continue; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
1074
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
69 | // Create the two triangles based on this quadrilateral: |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
70 | // 0───3 0───3 3 |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
71 | // │ │ --→ │ ╱ ╱│ |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
72 | // │ │ --→ │ ╱ ╱ │ |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
73 | // │ │ --→ │╱ ╱ │ |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
74 | // 1───2 1 1───2 |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
75 | LDTriangle* triangle1 = currentDocument()->emplaceReplacementAt<LDTriangle>(index, v0, v1, v3); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
76 | LDTriangle* triangle2 = currentDocument()->emplaceAt<LDTriangle>(index + 1, v1, v2, v3); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
77 | |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
78 | // The triangles also inherit the quad's color |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
79 | triangle1->setColor(color); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
80 | triangle2->setColor(color); |
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
81 | count += 1; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | |
1074
a62f810ca26f
Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
84 | print ("%1 quadrilaterals split", count); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | void AlgorithmToolset::editRaw() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
89 | if (countof(selectedObjects()) != 1) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
1142
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
92 | LDObject* object = *(selectedObjects().begin()); |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
93 | QDialog dialog; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | Ui::EditRawUI ui; |
1142
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
95 | ui.setupUi(&dialog); |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
96 | ui.code->setText (object->asText()); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
1142
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
98 | if (object->type() == LDObjectType::Error) |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
99 | { |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
100 | ui.errorDescription->setText(static_cast<LDError*>(object)->reason()); |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
101 | } |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | else |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | ui.errorDescription->hide(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | ui.errorIcon->hide(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
1142
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
108 | if (dialog.exec() == QDialog::Accepted) |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
109 | { |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
110 | // Reinterpret it from the text of the input field |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
111 | currentDocument()->replaceWithFromString(object, ui.code->text()); |
19fe87c796f8
Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
112 | } |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | void AlgorithmToolset::makeBorders() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | { |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
117 | int count = 0; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
119 | for (LDObject* object : selectedObjects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | { |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
121 | const LDObjectType type = object->type(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
123 | if (type != LDObjectType::Quadrilateral and type != LDObjectType::Triangle) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | continue; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
1079
67c6e5d32e68
More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents:
1078
diff
changeset
|
126 | Model lines {m_documents}; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
128 | if (type == LDObjectType::Quadrilateral) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | { |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
130 | LDQuadrilateral* quad = static_cast<LDQuadrilateral*>(object); |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
131 | lines.emplace<LDEdgeLine>(quad->vertex (0), quad->vertex (1)); |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
132 | lines.emplace<LDEdgeLine>(quad->vertex (1), quad->vertex (2)); |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
133 | lines.emplace<LDEdgeLine>(quad->vertex (2), quad->vertex (3)); |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
134 | lines.emplace<LDEdgeLine>(quad->vertex (3), quad->vertex (0)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | else |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | { |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
138 | LDTriangle* triangle = static_cast<LDTriangle*>(object); |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
139 | lines.emplace<LDEdgeLine>(triangle->vertex (0), triangle->vertex (1)); |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
140 | lines.emplace<LDEdgeLine>(triangle->vertex (1), triangle->vertex (2)); |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
141 | lines.emplace<LDEdgeLine>(triangle->vertex (2), triangle->vertex (0)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
144 | count += countof(lines.objects()); |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
145 | currentDocument()->merge(lines, object->lineNumber() + 1); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
148 | print(tr("Added %1 border lines"), count); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | void AlgorithmToolset::roundCoordinates() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | setlocale (LC_ALL, "C"); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | int num = 0; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
156 | for (LDObject* obj : selectedObjects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
160 | if (mo) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | Vertex v = mo->position(); |
1045
f726f8f49c7e
Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents:
1028
diff
changeset
|
163 | Matrix t = mo->transformationMatrix(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
165 | v.apply ([&](Axis, double& a) |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
166 | { |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
167 | roundToDecimals (a, m_config->roundPositionPrecision()); |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
168 | }); |
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
169 | |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1012
diff
changeset
|
170 | applyToMatrix (t, [&](int, double& a) |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
171 | { |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
172 | roundToDecimals (a, m_config->roundMatrixPrecision()); |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
173 | }); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | mo->setPosition (v); |
1045
f726f8f49c7e
Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents:
1028
diff
changeset
|
176 | mo->setTransformationMatrix (t); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | num += 12; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | else |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | for (int i = 0; i < obj->numVertices(); ++i) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | Vertex v = obj->vertex (i); |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
184 | v.apply ([&](Axis, double& a) |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
185 | { |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
186 | roundToDecimals (a, m_config->roundPositionPrecision()); |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
187 | }); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | obj->setVertex (i, v); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | num += 3; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | print (tr ("Rounded %1 values"), num); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | m_window->refreshObjectList(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | void AlgorithmToolset::replaceCoordinates() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | { |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
200 | QDialog dialog {m_window}; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | Ui::ReplaceCoordsUI ui; |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
202 | ui.setupUi (&dialog); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
204 | if (not dialog.exec()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
207 | const double needle = ui.search->value(); |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
208 | const double replacement = ui.replacement->value(); |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
209 | const bool replaceAllValues= ui.any->isChecked(); |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
210 | const bool relative = ui.relative->isChecked(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
212 | QList<Axis> selectedAxes; |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
213 | int count = 0; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
215 | if (ui.x->isChecked()) |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
216 | selectedAxes << X; |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
217 | if (ui.y->isChecked()) |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
218 | selectedAxes << Y; |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
219 | if (ui.z->isChecked()) |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
220 | selectedAxes << Z; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
222 | for (LDObject* obj : selectedObjects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | for (int i = 0; i < obj->numVertices(); ++i) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | { |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
226 | Vertex vertex = obj->vertex(i); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
228 | vertex.apply([&](Axis axis, double& coordinate) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | { |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
230 | if (selectedAxes.contains(axis) and (replaceAllValues or isZero(coordinate - needle))) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | { |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
232 | if (relative) |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
233 | coordinate += replacement; |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
234 | else |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
235 | coordinate = replacement; |
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
236 | count += 1; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | }); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
240 | obj->setVertex(i, vertex); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | |
1143
2008959603c9
Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents:
1142
diff
changeset
|
244 | print(tr("Altered %1 values"), count); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | void AlgorithmToolset::flip() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | { |
1165
e6974c4d9e55
Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents:
1164
diff
changeset
|
249 | QDialog dialog {m_window}; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | Ui::FlipUI ui; |
1165
e6974c4d9e55
Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents:
1164
diff
changeset
|
251 | ui.setupUi(&dialog); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | |
1165
e6974c4d9e55
Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents:
1164
diff
changeset
|
253 | if (not dialog.exec()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | QList<Axis> sel; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | if (ui.x->isChecked()) sel << X; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | if (ui.y->isChecked()) sel << Y; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | if (ui.z->isChecked()) sel << Z; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
262 | for (LDObject* obj : selectedObjects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | for (int i = 0; i < obj->numVertices(); ++i) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | Vertex v = obj->vertex (i); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | v.apply ([&](Axis ax, double& a) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | if (sel.contains (ax)) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | a = -a; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | }); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | obj->setVertex (i, v); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | void AlgorithmToolset::demote() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | int num = 0; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
283 | for (LDConditionalEdge* line : filterByType<LDConditionalEdge>(selectedObjects())) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | { |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
285 | line->becomeEdgeLine(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | ++num; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | |
1005
a88cf5a32246
Subject Bézier curve fineness to the grid. By default, the coarse grid uses 8 segments, medium 16 and fine 32. Moved rasterization from demoting to inlining, it feels more sensible for it to be there.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1002
diff
changeset
|
289 | print (tr ("Converted %1 conditional lines"), num); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
292 | bool AlgorithmToolset::isColorUsed (LDColor color) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | { |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
294 | for (LDObject* obj : currentDocument()->objects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | if (obj->isColored() and obj->color() == color) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | return true; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | return false; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | void AlgorithmToolset::autocolor() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | LDColor color; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | for (color = 0; color.isLDConfigColor(); ++color) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | if (color.isValid() and not isColorUsed (color)) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | break; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | if (not color.isLDConfigColor()) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | print (tr ("Cannot auto-color: all colors are in use!")); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
319 | for (LDObject* obj : selectedObjects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | if (not obj->isColored()) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | continue; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | obj->setColor (color); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | print (tr ("Auto-colored: new color is [%1] %2"), color.index(), color.name()); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | void AlgorithmToolset::addHistoryLine() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | LDObject* obj; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | bool ishistory = false; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | bool prevIsHistory = false; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | |
1165
e6974c4d9e55
Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents:
1164
diff
changeset
|
336 | QDialog dialog {m_window}; |
1112
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
337 | Ui_AddHistoryLine ui; |
1165
e6974c4d9e55
Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents:
1164
diff
changeset
|
338 | ui.setupUi(&dialog); |
1112
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
339 | ui.m_username->setText (m_config->defaultUser()); |
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
340 | ui.m_date->setDate (QDate::currentDate()); |
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
341 | ui.m_comment->setFocus(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | |
1165
e6974c4d9e55
Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents:
1164
diff
changeset
|
343 | if (not dialog.exec()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
346 | // Find a spot to place the new comment |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
347 | for (obj = currentDocument()->getObject (0); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | obj and obj->next() and not obj->next()->isScemantic(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | obj = obj->next()) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | LDComment* comment = dynamic_cast<LDComment*> (obj); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
352 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | if (comment and comment->text().startsWith ("!HISTORY ")) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | ishistory = true; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | if (prevIsHistory and not ishistory) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
357 | break; // Last line was history, this isn't, thus insert the new history line here. |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | prevIsHistory = ishistory; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
360 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
361 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | int idx = obj ? obj->lineNumber() : 0; |
1081
47cde4087cc5
Made all LDObject constructors protected. Emplacement is now the only way to create objects.
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
363 | |
47cde4087cc5
Made all LDObject constructors protected. Emplacement is now the only way to create objects.
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
364 | // Create the comment object based on input |
47cde4087cc5
Made all LDObject constructors protected. Emplacement is now the only way to create objects.
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
365 | currentDocument()->emplaceAt<LDComment>(idx++, format("!HISTORY %1 [%2] %3", |
1112
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
366 | ui.m_date->date().toString ("yyyy-MM-dd"), |
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
367 | ui.m_username->text(), |
d1d8be74275b
Fixed potential memory leak
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
368 | ui.m_comment->text())); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | // If we're adding a history line right before a scemantic object, pad it |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | // an empty line |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | if (obj and obj->next() and obj->next()->isScemantic()) |
1081
47cde4087cc5
Made all LDObject constructors protected. Emplacement is now the only way to create objects.
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
373 | currentDocument()->emplaceAt<LDEmpty>(idx); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
374 | |
981
5d5d84ab2c48
Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
979
diff
changeset
|
375 | m_window->buildObjectList(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
378 | void AlgorithmToolset::splitLines() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
380 | bool ok; |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
381 | int numSegments = QInputDialog::getInt (m_window, APPNAME, "Amount of segments:", |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
382 | m_config->splitLinesSegments(), 0, std::numeric_limits<int>::max(), 1, &ok); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
383 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | if (not ok) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
387 | m_config->setSplitLinesSegments (numSegments); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
388 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
972
diff
changeset
|
389 | for (LDObject* obj : selectedObjects()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
390 | { |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
391 | if (not isOneOf (obj->type(), LDObjectType::EdgeLine, LDObjectType::ConditionalEdge)) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | continue; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | |
1079
67c6e5d32e68
More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents:
1078
diff
changeset
|
394 | Model segments {m_documents}; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
396 | for (int i = 0; i < numSegments; ++i) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
397 | { |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
398 | Vertex v0; |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
399 | Vertex v1; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
400 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
401 | v0.apply ([&](Axis ax, double& a) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
403 | double len = obj->vertex (1)[ax] - obj->vertex (0)[ax]; |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
404 | a = (obj->vertex (0)[ax] + ((len * i) / numSegments)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
405 | }); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
406 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | v1.apply ([&](Axis ax, double& a) |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
408 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
409 | double len = obj->vertex (1)[ax] - obj->vertex (0)[ax]; |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
410 | a = (obj->vertex (0)[ax] + ((len * (i + 1)) / numSegments)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
411 | }); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
412 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
413 | if (obj->type() == LDObjectType::EdgeLine) |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
414 | segments.emplace<LDEdgeLine>(v0, v1); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
415 | else |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
416 | segments.emplace<LDConditionalEdge>(v0, v1, obj->vertex (2), obj->vertex (3)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
417 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
418 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
419 | currentDocument()->replace(obj, segments); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
420 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
421 | |
981
5d5d84ab2c48
Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
979
diff
changeset
|
422 | m_window->buildObjectList(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | m_window->refresh(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
424 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
425 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
426 | void AlgorithmToolset::subfileSelection() |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | { |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
428 | if (selectedObjects().isEmpty()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
430 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
431 | // Determine the title of the new subfile |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
432 | QString subfileTitle; |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
433 | LDComment* titleObject = dynamic_cast<LDComment*>(currentDocument()->getObject(0)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
435 | if (titleObject) |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
436 | subfileTitle = "~" + titleObject->text(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
437 | else |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
438 | subfileTitle = "~subfile"; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
439 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | // Remove duplicate tildes |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
441 | while (subfileTitle.startsWith("~~")) |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
442 | subfileTitle.remove(0, 1); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
443 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
444 | // If this the parent document isn't already in s/, we need to stuff it into |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
445 | // a subdirectory named s/. Ensure it exists! |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
446 | QString topDirectoryName = Basename(Dirname(currentDocument()->fullPath())); |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
447 | QString parentDocumentPath = currentDocument()->fullPath(); |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
448 | QString subfileDirectory = Dirname(parentDocumentPath); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
449 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
450 | if (topDirectoryName != "s") |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
451 | { |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
452 | QString desiredPath = subfileDirectory + "/s"; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
453 | QString title = tr ("Create subfile directory?"); |
1156
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
454 | QString text = format(tr("The directory <b>%1</b> is suggested for subfiles. " |
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
455 | "This directory does not exist, do you want to create it?"), desiredPath); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
456 | |
1156
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
457 | if (QDir(desiredPath).exists() |
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
458 | or QMessageBox::question(m_window, title, text, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
459 | { |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
460 | subfileDirectory = desiredPath; |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
461 | QDir().mkpath(subfileDirectory); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
462 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
463 | else |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | return; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
465 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | // Determine the body of the name of the subfile |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
468 | QString fullSubfileName; |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
469 | |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
470 | if (not parentDocumentPath.isEmpty()) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
472 | // Chop existing '.dat' suffix |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
473 | if (parentDocumentPath.endsWith (".dat")) |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
474 | parentDocumentPath.chop (4); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | // Remove the s?? suffix if it's there, otherwise we'll get filenames |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
477 | // like s01s01.dat when subfiling subfiles. |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
478 | QRegExp subfilesuffix {"s[0-9][0-9]$"}; |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
479 | if (subfilesuffix.indexIn(parentDocumentPath) != -1) |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
480 | parentDocumentPath.chop(subfilesuffix.matchedLength()); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
481 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
482 | int subfileIndex = 1; |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | QString digits; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
484 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
485 | // Now find the appropriate filename. Increase the number of the subfile until we find a name which isn't already taken. |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
486 | do |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | { |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
488 | digits.setNum(subfileIndex++); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
489 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
490 | // Pad it with a zero |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
491 | if (countof(digits) == 1) |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
492 | digits.prepend("0"); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
493 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
494 | fullSubfileName = subfileDirectory + "/" + Basename(parentDocumentPath) + "s" + digits + ".dat"; |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
495 | } while (m_documents->findDocumentByName("s\\" + Basename(fullSubfileName)) != nullptr or QFile {fullSubfileName}.exists()); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
496 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
498 | // Determine the BFC winding type used in the main document. It will be carried over to the subfile. |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
499 | BfcStatement winding = BfcStatement::NoCertify; |
988
ac4a2ae54f76
Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
500 | for (LDObjectIterator<LDBfc> it (currentDocument()); it.isValid(); ++it) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
501 | { |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
502 | if (isOneOf(it->statement(), BfcStatement::CertifyCCW, BfcStatement::CertifyCW, BfcStatement::NoCertify)) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
503 | { |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
504 | winding = it->statement(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
505 | break; |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
506 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
507 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
508 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
509 | // Create the new subfile document |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
510 | LDDocument* subfile = m_window->newDocument(); |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
511 | subfile->setFullPath(fullSubfileName); |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
512 | subfile->setName(LDDocument::shortenName(fullSubfileName)); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
513 | |
1079
67c6e5d32e68
More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents:
1078
diff
changeset
|
514 | Model header {m_documents}; |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
515 | header.emplace<LDComment>(subfileTitle); |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
516 | header.emplace<LDComment>("Name: "); // This gets filled in when the subfile is saved |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
517 | header.emplace<LDComment>(format("Author: %1 [%2]", m_config->defaultName(), m_config->defaultUser())); |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
518 | header.emplace<LDComment>("!LDRAW_ORG Unofficial_Subpart"); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
519 | |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
520 | QString license = preferredLicenseText(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
521 | if (not license.isEmpty()) |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
522 | header.emplace<LDComment>(license); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
523 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
524 | header.emplace<LDEmpty>(); |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
525 | header.emplace<LDBfc>(winding); |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
526 | header.emplace<LDEmpty>(); |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
527 | subfile->merge(header); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
528 | |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
529 | // Copy the body over to the new document |
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
530 | for (LDObject* object : selectedObjects()) |
1079
67c6e5d32e68
More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents:
1078
diff
changeset
|
531 | subfile->addFromString(object->asText()); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
532 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
533 | // Try save it |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
534 | if (m_window->save(subfile, true)) |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
535 | { |
1166
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
536 | // Where to insert the subfile reference? |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
537 | // TODO: the selection really should be sorted by position... |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
538 | int referencePosition = (*selectedObjects().begin())->lineNumber(); |
d2e78bb77763
Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents:
1165
diff
changeset
|
539 | |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
540 | // Save was successful. Delete the original selection now from the |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
541 | // main document. |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
542 | for (LDObject* object : selectedObjects().toList()) |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
543 | currentDocument()->remove(object); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
544 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
545 | // Add a reference to the new subfile to where the selection was |
1161
e6a5ff67c057
Removed the Origin and axes global constants.
Teemu Piippo <teemu@hecknology.net>
parents:
1156
diff
changeset
|
546 | currentDocument()->emplaceAt<LDSubfileReference>(referencePosition, subfile, Matrix::identity, Vertex {0, 0, 0}); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
547 | |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
548 | // Refresh stuff |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
549 | m_window->updateDocumentList(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
550 | m_window->doFullRefresh(); |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
551 | } |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
552 | else |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
553 | { |
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
554 | // Failed to save. |
1078
c72e3115a297
Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents:
1074
diff
changeset
|
555 | subfile->close(); |
969
b1742ee91d5b
Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
556 | } |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
557 | } |