src/toolsets/basictoolset.cpp

Fri, 16 Mar 2018 11:50:35 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 16 Mar 2018 11:50:35 +0200
changeset 1288
d1e45f90654b
parent 1269
ec691d9472b3
child 1296
aee618d087ff
permissions
-rw-r--r--

Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.

969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QApplication>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QClipboard>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QDialog>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QDialogButtonBox>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QTextEdit>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QVBoxLayout>
1103
ac7db4c076c3 Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents: 1079
diff changeset
25 #include "../canvas.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
26 #include "../lddocument.h"
1147
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
27 #include "../linetypes/modelobject.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "../ldobjectiterator.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "../mainwindow.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "../dialogs/colorselector.h"
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
31 #include "../grid.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
32 #include "../parser.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "basictoolset.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 BasicToolset::BasicToolset (MainWindow *parent) :
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 Toolset (parent) {}
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
38 int BasicToolset::copyToClipboard()
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 {
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
40 const QSet<LDObject*>& objects = selectedObjects();
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
41 int count = 0;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 qApp->clipboard()->clear();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 QString data;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
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
45 for (LDObject* obj : objects)
969
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 if (not data.isEmpty())
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 data += "\n";
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 data += obj->asText();
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
51 ++count;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 qApp->clipboard()->setText (data);
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
55 return count;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 void BasicToolset::cut()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
60 int num = copyToClipboard();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 m_window->deleteSelection();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 print (tr ("%1 objects cut"), num);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 void BasicToolset::copy()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
67 int num = copyToClipboard();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 print (tr ("%1 objects copied"), num);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 void BasicToolset::paste()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 const QString clipboardText = qApp->clipboard()->text();
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
74 int row = m_window->suggestInsertPoint();
1256
3fea6bc1519b removed LDDocument::clearSelection and replaced it with a MainWindow implementation
Santeri Piippo
parents: 1240
diff changeset
75 mainWindow()->clearSelection();
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: 1075
diff changeset
76 int count = 0;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
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: 1075
diff changeset
78 for (QString line : clipboardText.split("\n"))
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
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
80 Parser::parseFromString(*currentDocument(), row, line);
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
81 mainWindow()->select(currentDocument()->index(row));
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
82 row += 1;
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
83 count += 1;
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
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: 1075
diff changeset
86 print(tr("%1 objects pasted"), count);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 m_window->refresh();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 void BasicToolset::remove()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 int num = m_window->deleteSelection();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 print (tr ("%1 objects deleted"), num);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 void BasicToolset::doInline (bool deep)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 {
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
98 for (LDSubfileReference* reference : filterByType<LDSubfileReference> (selectedObjects()))
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 // Get the index of the subfile so we know where to insert the
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // inlined contents.
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1257
diff changeset
102 QPersistentModelIndex referenceIndex = currentDocument()->indexOf(reference);
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
103 int row = referenceIndex.row();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
105 if (referenceIndex.isValid())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 {
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: 1075
diff changeset
107 Model inlined {m_documents};
1262
f6b253c17643 removed use of model() in LDSubfileReference::inlineContents
Santeri Piippo
parents: 1261
diff changeset
108 reference->inlineContents(m_documents, inlined, deep, false);
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
109
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 // Merge in the inlined objects
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
111 for (LDObject* inlinedObject : inlined.objects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 {
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
113 currentDocument()->insertCopy(row, inlinedObject);
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
114 mainWindow()->select(currentDocument()->index(row));
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
115 row += 1;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
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
117
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 // Delete the subfile now as it's been inlined.
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
119 currentDocument()->removeRow(referenceIndex.row());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 }
1005
a88cf5a32246 Subject Bézier curve fineness to the grid. By default, the coarse grid uses 8 segments, medium 16 and fine 32. Moved rasterization from demoting to inlining, it feels more sensible for it to be there.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
122
a88cf5a32246 Subject Bézier curve fineness to the grid. By default, the coarse grid uses 8 segments, medium 16 and fine 32. Moved rasterization from demoting to inlining, it feels more sensible for it to be there.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
123 for (LDBezierCurve* curve : filterByType<LDBezierCurve> (selectedObjects()))
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
124 {
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: 1075
diff changeset
125 Model curveModel {m_documents};
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
126 curve->rasterize(curveModel, grid()->bezierCurveSegments());
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
127 currentDocument()->replace(curve, curveModel);
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
128 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 void BasicToolset::inlineShallow()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 doInline (false);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 void BasicToolset::inlineDeep()
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 doInline (true);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 void BasicToolset::undo()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
143 currentDocument()->undo();
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 void BasicToolset::redo()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
148 currentDocument()->redo();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 void BasicToolset::uncolor()
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 int num = 0;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
155 for (LDObject* obj : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 if (not obj->isColored())
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 continue;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 obj->setColor (obj->defaultColor());
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 num++;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 print (tr ("%1 objects uncolored"), num);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 void BasicToolset::insertRaw()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 {
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
169 int row = m_window->suggestInsertPoint();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 QDialog* const dlg = new QDialog;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 QVBoxLayout* const layout = new QVBoxLayout;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 QTextEdit* const inputbox = new QTextEdit;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 QDialogButtonBox* const buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 layout->addWidget (inputbox);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 layout->addWidget (buttons);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 dlg->setLayout (layout);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 dlg->setWindowTitle (APPNAME " - Insert Raw");
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 dlg->connect (buttons, SIGNAL (accepted()), dlg, SLOT (accept()));
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 dlg->connect (buttons, SIGNAL (rejected()), dlg, SLOT (reject()));
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 if (dlg->exec() == QDialog::Rejected)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
1256
3fea6bc1519b removed LDDocument::clearSelection and replaced it with a MainWindow implementation
Santeri Piippo
parents: 1240
diff changeset
186 mainWindow()->clearSelection();
969
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 for (QString line : QString (inputbox->toPlainText()).split ("\n"))
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 {
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
190 Parser::parseFromString(*currentDocument(), row, line);
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
191 mainWindow()->select(currentDocument()->index(row));
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
192 row += 1;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 m_window->refresh();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 void BasicToolset::setColor()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
200 if (selectedObjects().isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202
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
203 QSet<LDObject*> objs = selectedObjects();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 // If all selected objects have the same color, said color is our default
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 // value to the color selection dialog.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 LDColor color;
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
208 LDColor defaultcol = m_window->getUniformSelectedColor();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 // Show the dialog to the user now and ask for a color.
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
211 if (ColorSelector::selectColor (m_window, color, defaultcol))
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 for (LDObject* obj : objs)
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 if (obj->isColored())
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 obj->setColor (color);
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 void BasicToolset::invert()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
223 for (LDObject* obj : selectedObjects())
1261
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
224 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
225 if (obj->numPolygonVertices() > 0)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
226 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
227 QVector<Vertex> vertices;
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
228
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
229 for (int i = 0; i < obj->numPolygonVertices(); i += 1)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
230 vertices.append(obj->vertex(i));
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
231
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
232 for (int i = 0; i < vertices.size(); i += 1)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
233 obj->setVertex(i, vertices[vertices.size() - 1 - i]);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
234 }
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
235 else if (obj->type() == LDObjectType::SubfileReference)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
236 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
237 // Check whether subfile is flat
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
238 int axisSet = (1 << X) | (1 << Y) | (1 << Z);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
239 Model model {currentDocument()->documentManager()};
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
240 LDSubfileReference* reference = static_cast<LDSubfileReference*>(obj);
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: 1262
diff changeset
241 reference->fileInfo(m_documents)->inlineContents(model, true, false);
1261
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
242
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
243 for (LDObject* subobj : model.objects())
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
244 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
245 for (int i = 0; i < subobj->numVertices(); ++i)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
246 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
247 Vertex const& vrt = subobj->vertex (i);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
248
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
249 if (axisSet & (1 << X) and vrt.x() != 0.0)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
250 axisSet &= ~(1 << X);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
251
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
252 if (axisSet & (1 << Y) and vrt.y() != 0.0)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
253 axisSet &= ~(1 << Y);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
254
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
255 if (axisSet & (1 << Z) and vrt.z() != 0.0)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
256 axisSet &= ~(1 << Z);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
257 }
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
258
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
259 if (axisSet == 0)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
260 break;
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
261 }
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
262
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
263 if (axisSet != 0)
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
264 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
265 // Subfile has all vertices zero on one specific plane, so it is flat.
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
266 // Let's flip it.
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
267 Matrix matrixModifier = Matrix::identity;
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
268
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
269 if (axisSet & (1 << X))
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
270 matrixModifier(0, 0) = -1;
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
271
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
272 if (axisSet & (1 << Y))
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
273 matrixModifier(1, 1) = -1;
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
274
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
275 if (axisSet & (1 << Z))
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
276 matrixModifier(2, 2) = -1;
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
277
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
278 reference->setTransformationMatrix(reference->transformationMatrix() * matrixModifier);
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
279 }
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
280 else
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
281 {
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
282 // Subfile is not flat. Resort to invertnext.
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
283 reference->setInverted(not reference->isInverted());
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
284 }
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
285 }
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
286 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 void BasicToolset::newSubfile()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
291 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 void BasicToolset::newLine()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
296 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 void BasicToolset::newTriangle()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
301 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 void BasicToolset::newQuadrilateral()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
306 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 void BasicToolset::newConditionalLine()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
311 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 void BasicToolset::newComment()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
316 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 void BasicToolset::newBFC()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 {
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
321 // TODO:
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 void BasicToolset::edit()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
326 if (countof(selectedObjects()) == 1)
1063
1f15c52c11f6 Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents: 1023
diff changeset
327 {
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
328 LDObject* obj = *selectedObjects().begin();
1075
711c5fff384d Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents: 1074
diff changeset
329 // TODO:
1063
1f15c52c11f6 Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents: 1023
diff changeset
330 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 void BasicToolset::modeSelect()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
335 m_window->renderer()->setEditMode (EditModeType::Select);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337
1000
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
338 void BasicToolset::modeCurve()
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
339 {
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
340 m_window->renderer()->setEditMode (EditModeType::Curve);
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
341 }
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
342
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 void BasicToolset::modeDraw()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
345 m_window->renderer()->setEditMode (EditModeType::Draw);
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 void BasicToolset::modeRectangle()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
350 m_window->renderer()->setEditMode (EditModeType::Rectangle);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 }
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 void BasicToolset::modeCircle()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
355 m_window->renderer()->setEditMode (EditModeType::Circle);
969
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 void BasicToolset::modeMagicWand()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
360 m_window->renderer()->setEditMode (EditModeType::MagicWand);
969
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 void BasicToolset::modeLinePath()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
365 m_window->renderer()->setEditMode (EditModeType::LinePath);
1240
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1147
diff changeset
366 }

mercurial