src/toolsets/algorithmtoolset.cpp

Tue, 27 Mar 2018 14:13:58 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 27 Mar 2018 14:13:58 +0300
changeset 1350
eb2d3bc4fc73
parent 1331
f10b0c32a85d
child 1403
7a2d84112983
permissions
-rw-r--r--

better representation of fractions and large numbers

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
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1324
diff changeset
3 * Copyright (C) 2013 - 2018 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>
1294
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
23 #include <QPushButton>
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "../mainwindow.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "../main.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1144
diff changeset
26 #include "../lddocument.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"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "../ldobjectiterator.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
30 #include "../documentmanager.h"
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
31 #include "../linetypes/comment.h"
1141
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents: 1139
diff changeset
32 #include "../linetypes/conditionaledge.h"
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents: 1139
diff changeset
33 #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
34 #include "../linetypes/empty.h"
1149
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents: 1148
diff changeset
35 #include "../linetypes/quadrilateral.h"
1148
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
36 #include "../linetypes/triangle.h"
1288
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
37 #include "../parser.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"
1294
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
41 #include "ui_fixroundingerrors.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
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1242
diff changeset
53 for (LDObject* object : selectedObjects())
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
54 {
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1242
diff changeset
55 QModelIndex index = currentDocument()->indexOf(object);
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1242
diff changeset
56
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
57 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
58 continue;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
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
60 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
61 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
62 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
63 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
64 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
65
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
66 // 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
67 // 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
68 // │ │ --→ │ ╱ ╱│
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 // │ │ --→ │ ╱ ╱ │
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 // │ │ --→ │╱ ╱ │
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 // 1───2 1 1───2
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
72 int row = index.row();
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
73 currentDocument()->removeAt(index);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
74 LDTriangle* triangle1 = currentDocument()->emplaceAt<LDTriangle>(row, v0, v1, v3);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
75 LDTriangle* triangle2 = currentDocument()->emplaceAt<LDTriangle>(row + 1, v1, v2, v3);
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
76
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 // 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
78 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
79 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
80 count += 1;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
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
83 print ("%1 quadrilaterals split", count);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
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 void AlgorithmToolset::editRaw()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 {
1288
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
88 if (countof(m_window->selectedIndexes()) != 1)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
1288
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
91 QModelIndex index = *(m_window->selectedIndexes().begin());
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
92 LDObject* object = currentDocument()->lookup(index);
1142
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
1288
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
111 int row = index.row();
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
112 currentDocument()->removeAt(row);
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
113 Parser::parseFromString(*currentDocument(), row, ui.code->text());
1142
19fe87c796f8 Fixed possible memory leak in AlgorithmToolset::editRaw().
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
114 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 void AlgorithmToolset::makeBorders()
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 int count = 0;
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 for (LDObject* object : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
123 const LDObjectType type = object->type();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
125 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
126 continue;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
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
128 Model lines {m_documents};
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 if (type == LDObjectType::Quadrilateral)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 {
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
132 LDQuadrilateral* quad = static_cast<LDQuadrilateral*>(object);
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
133 lines.emplace<LDEdgeLine>(quad->vertex (0), quad->vertex (1));
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
134 lines.emplace<LDEdgeLine>(quad->vertex (1), quad->vertex (2));
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
135 lines.emplace<LDEdgeLine>(quad->vertex (2), quad->vertex (3));
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
136 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
137 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 else
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 {
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
140 LDTriangle* triangle = static_cast<LDTriangle*>(object);
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
141 lines.emplace<LDEdgeLine>(triangle->vertex (0), triangle->vertex (1));
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
142 lines.emplace<LDEdgeLine>(triangle->vertex (1), triangle->vertex (2));
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
143 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
144 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
146 count += countof(lines.objects());
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1242
diff changeset
147 currentDocument()->merge(lines, currentDocument()->indexOf(object).row() + 1);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
150 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
151 }
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 void AlgorithmToolset::roundCoordinates()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 setlocale (LC_ALL, "C");
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 int num = 0;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
158 for (LDObject* object : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 {
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
160 LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (object);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
162 if (mo)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 {
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
164 Vertex position = mo->position();
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
165 Matrix matrix = mo->transformationMatrix();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
167 for (Axis axis : {X, Y, Z})
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
168 position[axis] = roundToDecimals(position[axis], 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
169
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
170 for (int i : {0, 1, 2})
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
171 for (int j : {0, 1, 2})
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
172 matrix(i, j) = roundToDecimals(matrix(i, j), config::roundMatrixPrecision());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
174 mo->setPosition(position);
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
175 mo->setTransformationMatrix(matrix);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 num += 12;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 else
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 {
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
180 for (int i = 0; i < object->numVertices(); ++i)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 {
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
182 Vertex vertex = object->vertex (i);
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
183 for (Axis axis : {X, Y, Z})
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
184 vertex[axis] = roundToDecimals(vertex[axis], config::roundPositionPrecision());
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
185 object->setVertex(i, vertex);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 num += 3;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 }
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 print (tr ("Rounded %1 values"), num);
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
1294
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
194 void AlgorithmToolset::fixRoundingErrors()
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
195 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
196 QDialog dialog {m_window};
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
197 Ui::FixRoundingErrors ui;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
198 ui.setupUi(&dialog);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
199 auto updateDialogButtonBox = [&]()
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
200 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
201 QPushButton* button = ui.buttonBox->button(QDialogButtonBox::Ok);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
202
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
203 if (button)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
204 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
205 button->setEnabled(
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
206 ui.checkboxX->isChecked()
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
207 or ui.checkboxY->isChecked()
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
208 or ui.checkboxZ->isChecked()
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
209 );
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
210 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
211 };
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
212 updateDialogButtonBox();
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
213 connect(ui.checkboxX, &QCheckBox::clicked, updateDialogButtonBox);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
214 connect(ui.checkboxY, &QCheckBox::clicked, updateDialogButtonBox);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
215 connect(ui.checkboxZ, &QCheckBox::clicked, updateDialogButtonBox);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
216 const int result = dialog.exec();
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
217
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
218 if (result == QDialog::Accepted)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
219 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
220 const Vertex referencePoint = {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
221 ui.valueX->value(),
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
222 ui.valueY->value(),
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
223 ui.valueZ->value()
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
224 };
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
225
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
226 // Find out which axes to consider
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
227 QSet<Axis> axes;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
228 if (ui.checkboxX->isChecked())
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
229 axes << X;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
230 if (ui.checkboxY->isChecked())
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
231 axes << Y;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
232 if (ui.checkboxZ->isChecked())
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
233 axes << Z;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
234
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
235 // Make a reference distance from the threshold value.
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
236 // If we're only comparing one dimension, this is the square of the threshold.
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
237 // If we're comparing multiple dimensions, the distance is multiplied to adjust.
1320
bdb4804bc09c Moved includes, added squared() function
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
238 double thresholdDistanceSquared = countof(axes) * pow(ui.threshold->value(), 2);
1294
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
239 // Add some tiny leeway to fix rounding errors in the rounding error fixer.
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
240 thresholdDistanceSquared += 1e-10;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
241
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
242 auto fixVertex = [&](Vertex& vertex)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
243 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
244 double distanceSquared = 0.0;
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
245
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
246 for (Axis axis : axes)
1320
bdb4804bc09c Moved includes, added squared() function
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
247 distanceSquared += pow(vertex[axis] - referencePoint[axis], 2);
1294
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
248
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
249 if (distanceSquared < thresholdDistanceSquared)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
250 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
251 // It's close enough, so clamp it
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
252 for (Axis axis : axes)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
253 vertex.setCoordinate(axis, referencePoint[axis]);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
254 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
255 };
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
256
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
257 for (const QModelIndex& index : m_window->selectedIndexes())
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
258 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
259 LDObject* object = currentDocument()->lookup(index);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
260
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
261 if (object)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
262 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
263 for (int i : range(0, 1, object->numVertices() - 1))
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
264 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
265 Vertex point = object->vertex(i);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
266 fixVertex(point);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
267 object->setVertex(i, point);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
268 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
269 if (object->type() == LDObjectType::SubfileReference)
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
270 {
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
271 LDSubfileReference* reference = static_cast<LDSubfileReference*>(object);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
272 Vertex point = reference->position();
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
273 fixVertex(point);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
274 reference->setPosition(point);
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
275 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
276 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
277 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
278 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
279 }
adaad0b329e2 Added a new tool for clamping vertices
Teemu Piippo <teemu@hecknology.net>
parents: 1293
diff changeset
280
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 void AlgorithmToolset::replaceCoordinates()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 {
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
283 QDialog dialog {m_window};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 Ui::ReplaceCoordsUI ui;
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
285 ui.setupUi (&dialog);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
287 if (not dialog.exec())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
290 const double needle = ui.search->value();
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
291 const double replacement = ui.replacement->value();
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
292 const bool replaceAllValues= ui.any->isChecked();
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
293 const bool relative = ui.relative->isChecked();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
295 QList<Axis> selectedAxes;
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
296 int count = 0;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
298 if (ui.x->isChecked())
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
299 selectedAxes << X;
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
300 if (ui.y->isChecked())
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
301 selectedAxes << Y;
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
302 if (ui.z->isChecked())
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
303 selectedAxes << Z;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
305 for (LDObject* obj : selectedObjects())
969
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 (int i = 0; i < obj->numVertices(); ++i)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 {
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
309 Vertex vertex = obj->vertex(i);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
311 vertex.apply([&](Axis axis, double& coordinate)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 {
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
313 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
314 {
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
315 if (relative)
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
316 coordinate += replacement;
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
317 else
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
318 coordinate = replacement;
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
319 count += 1;
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 });
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
323 obj->setVertex(i, vertex);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
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
1143
2008959603c9 Cleanup AlgorithmToolset::replaceCoordinates()
Teemu Piippo <teemu@hecknology.net>
parents: 1142
diff changeset
327 print(tr("Altered %1 values"), count);
969
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::flip()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 {
1165
e6974c4d9e55 Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents: 1164
diff changeset
332 QDialog dialog {m_window};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 Ui::FlipUI ui;
1165
e6974c4d9e55 Fixed more dialog instances in AlgorithmToolset.
Teemu Piippo <teemu@hecknology.net>
parents: 1164
diff changeset
334 ui.setupUi(&dialog);
969
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 if (not dialog.exec())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 QList<Axis> sel;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 if (ui.x->isChecked()) sel << X;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 if (ui.y->isChecked()) sel << Y;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 if (ui.z->isChecked()) sel << Z;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
345 for (LDObject* obj : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 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
348 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 Vertex v = obj->vertex (i);
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 v.apply ([&](Axis ax, double& a)
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 (sel.contains (ax))
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 a = -a;
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 obj->setVertex (i, v);
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 }
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 void AlgorithmToolset::demote()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 {
1242
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
364 int count = 0;
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
365
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
366 for (int i = 0; i < currentDocument()->size(); ++i)
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
367 {
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
368 LDObject* object = currentDocument()->objects()[i];
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369
1242
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
370 if (object->type() == LDObjectType::ConditionalEdge)
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
371 {
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
372 Vertex v1 = object->vertex(0);
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
373 Vertex v2 = object->vertex(1);
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
374 LDColor color = object->color();
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
375 currentDocument()->removeAt(i);
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
376 LDEdgeLine* edge = currentDocument()->emplaceAt<LDEdgeLine>(i, v1, v2);
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
377 edge->setColor(color);
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
378 count += 1;
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
379 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381
1242
725cb1084044 Removed LDConditionalEdge::becomeEdgeLine
Santeri Piippo
parents: 1240
diff changeset
382 print (tr ("Converted %1 conditional lines"), count);
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
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
385 bool AlgorithmToolset::isColorUsed (LDColor color)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
387 for (LDObject* obj : currentDocument()->objects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 if (obj->isColored() and obj->color() == color)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 return true;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 return false;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395
1259
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
396 LDObject* AlgorithmToolset::next(LDObject* object)
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
397 {
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
398 QModelIndex index = currentDocument()->indexOf(object);
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
399
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
400 if (index.isValid())
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
401 return currentDocument()->getObject(index.row() + 1);
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
402 else
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
403 return nullptr;
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
404 }
0384b1d49786 moved LDObject::next to the algorithm toolset
Santeri Piippo
parents: 1258
diff changeset
405
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 void AlgorithmToolset::autocolor()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 LDColor color;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 for (color = 0; color.isLDConfigColor(); ++color)
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 if (color.isValid() and not isColorUsed (color))
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 break;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 if (not color.isLDConfigColor())
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 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
419 return;
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
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
422 for (LDObject* obj : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 if (not obj->isColored())
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 continue;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 obj->setColor (color);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 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
431 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 void AlgorithmToolset::splitLines()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 bool ok;
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
436 int numSegments = QInputDialog::getInt (m_window, APPNAME, "Amount of segments:",
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1320
diff changeset
437 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
438
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 if (not ok)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1320
diff changeset
442 config::setSplitLinesSegments (numSegments);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
444 for (LDObject* obj : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 {
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
446 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
447 continue;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448
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
449 Model segments {m_documents};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
451 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
452 {
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
453 Vertex v0;
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
454 Vertex v1;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 v0.apply ([&](Axis ax, double& a)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 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
459 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
460 });
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 v1.apply ([&](Axis ax, double& a)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 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
465 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
466 });
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
468 if (obj->type() == LDObjectType::EdgeLine)
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
469 segments.emplace<LDEdgeLine>(v0, v1);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 else
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
471 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
472 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
474 currentDocument()->replace(obj, segments);
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 m_window->refresh();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 void AlgorithmToolset::subfileSelection()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 {
1063
1f15c52c11f6 Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents: 1062
diff changeset
482 if (selectedObjects().isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483 return;
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 // Determine the title of the new subfile
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
486 QString subfileTitle;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
488 if (currentDocument()->header.type != LDHeader::NoHeader)
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
489 subfileTitle = "~" + currentDocument()->header.description;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 else
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
491 subfileTitle = "~Untitled subfile";
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 // Remove duplicate tildes
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
494 while (subfileTitle.startsWith("~~"))
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
495 subfileTitle.remove(0, 1);
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 // 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
498 // a subdirectory named s/. Ensure it exists!
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
499 QFileInfo path = currentDocument()->fullPath();
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
500 QString parentDocumentPath = currentDocument()->fullPath();
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
501 QDir subfileDirectory = path.absoluteDir();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
503 if (path.dir().dirName() != "s")
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
504 {
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
505 QDir desiredPath = subfileDirectory.filePath("s");
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
507 if (desiredPath.exists())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
508 {
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
509 subfileDirectory = desiredPath;
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
510 } else if (QMessageBox::question(
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
511 m_window,
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
512 tr("Create subfile directory?"),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
513 format(tr("The directory <b>%1</b> is suggested for subfiles. "
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
514 "This directory does not exist, do you want to create it?"),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
515 desiredPath.absolutePath()
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
516 ),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
517 (QMessageBox::Yes | QMessageBox::No),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
518 QMessageBox::No
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
519 ) == QMessageBox::Yes
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
520 ) {
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
521 if (subfileDirectory.mkdir("s"))
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
522 {
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
523 subfileDirectory = desiredPath;
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
524 }
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
525 else
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
526 {
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
527 QMessageBox::critical(
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
528 m_window,
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
529 tr("Error"),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
530 format(tr("Unable to create directory %1: %2!"),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
531 subfileDirectory.absolutePath(),
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
532 strerror(errno)
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
533 )
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
534 );
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
535 return;
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
536 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 else
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
539 {
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 return;
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
541 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 // Determine the body of the name of the subfile
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
545 QString fullSubfilePath;
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
546
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
547 if (not parentDocumentPath.isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 {
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
549 QString subfileRoot = QFileInfo(parentDocumentPath).baseName();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 // 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
552 // like s01s01.dat when subfiling subfiles.
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
553 QRegExp subfilesuffix {"s[0-9][0-9]$"};
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
554 if (subfilesuffix.indexIn(subfileRoot) != -1)
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
555 subfileRoot.chop(subfilesuffix.matchedLength());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
557 int subfileIndex = 1;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 QString digits;
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
559 QString subfileName;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
561 // Now find the appropriate filename. Increase the number of the subfile until we find a
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
562 // name which isn't already taken.
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 do
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 {
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
565 digits.setNum(subfileIndex);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
567 // 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
568 if (countof(digits) == 1)
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
569 digits.prepend("0");
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
571 subfileName = subfileRoot + "s" + digits + ".dat";
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
572 fullSubfilePath = subfileDirectory.filePath(subfileName);
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
573 subfileIndex += 1;
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
574 } while (
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
575 m_documents->findDocumentByName("s\\" + subfileName) != nullptr
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
576 or QFileInfo {fullSubfilePath}.exists()
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
577 );
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
580 // Create the new subfile document
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
581 LDDocument* subfile = m_window->newDocument();
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
582 subfile->setFullPath(fullSubfilePath);
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1294
diff changeset
583 subfile->header.description = subfileTitle;
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1294
diff changeset
584 subfile->header.type = LDHeader::Subpart;
1331
f10b0c32a85d used Qt file info stuff in the auto-subfiler
Teemu Piippo <teemu@hecknology.net>
parents: 1328
diff changeset
585 subfile->header.name = LDDocument::shortenName(fullSubfilePath);
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1320
diff changeset
586 subfile->header.author = format("%1 [%2]", config::defaultName(), config::defaultUser());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1320
diff changeset
588 if (config::useCaLicense())
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1294
diff changeset
589 subfile->header.license = LDHeader::CaLicense;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1294
diff changeset
591 subfile->setWinding(currentDocument()->winding());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
593 // 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
594 for (LDObject* object : selectedObjects())
1288
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
595 Parser::parseFromString(*subfile, Parser::EndOfModel, object->asText());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 // Try save it
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
598 if (m_window->save(subfile, true))
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 {
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
600 // Where to insert the subfile reference?
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
601 // TODO: the selection really should be sorted by position...
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1242
diff changeset
602 int referencePosition = m_window->selectedIndexes().begin()->row();
1166
d2e78bb77763 Cleanup AlgorithmToolset::subfileSelection.
Teemu Piippo <teemu@hecknology.net>
parents: 1165
diff changeset
603
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
604 // 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
605 // main document.
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
606 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
607 currentDocument()->remove(object);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
608
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 // Add a reference to the new subfile to where the selection was
1263
0256edecda54 LDSubfileReference now contains the name of the subfile and not a pointer anymore. Some methods now require a DocumentManager* for context on resolving the name.
Santeri Piippo
parents: 1259
diff changeset
610 currentDocument()->emplaceAt<LDSubfileReference>(referencePosition, subfile->name(), Matrix::identity, Vertex {0, 0, 0});
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
611
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612 // Refresh stuff
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 m_window->updateDocumentList();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 m_window->doFullRefresh();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616 else
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 // Failed to save.
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
619 subfile->close();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
620 }
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
621 }

mercurial