src/document.cpp

Sun, 12 Jun 2022 23:59:37 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 12 Jun 2022 23:59:37 +0300
changeset 215
34c6e7bc4ee1
parent 214
8e1fe64ce4e3
child 217
6d95c1a41e6e
permissions
-rw-r--r--

Reimplement the axes program as a layer that can be added to PartRenderer

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
6 * it under the terms of the GNU General Public License as published by
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
18
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
19 #include <QMouseEvent>
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
20 #include <QMessageBox>
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
21 #include <QVBoxLayout>
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include "document.h"
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include "model.h"
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
24 #include "ui/objecteditor.h"
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
25
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
26 EditTools::EditTools(
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
27 Model* model,
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
28 const ColorTable& colorTable,
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
29 QObject* parent) :
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
30 QObject{parent},
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
31 colorTable{colorTable},
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 model{model},
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
33 vertexMap{model}
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
35 #if 0
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
36 connect(this->canvas, &Canvas::mouseClick, this, &EditTools::canvasMouseClick);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
37 connect(this->canvas, &Canvas::mouseMove, this, &EditTools::canvasMouseMove);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
38 connect(this->canvas, &Canvas::newStatusText, this, &EditTools::newStatusText);
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
39 connect(this->model, &Model::dataChanged, this->canvas, qOverload<>(&Canvas::update));
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
40 connect(&this->vertexMap, &VertexMap::verticesChanged, [&]()
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
41 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
42 this->canvas->rebuildVertices(&this->vertexMap);
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
43 });
198
eb9d900dc79a fix up things and remove unnecessary code
Teemu Piippo <teemu@hecknology.net>
parents: 197
diff changeset
44 this->canvas->drawState = &this->drawState;
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
45 #endif
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
48 EditTools::~EditTools()
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 {
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
50 }
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
51
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
52 void EditTools::applyToVertices(VertexMap::ApplyFunction fn) const
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
53 {
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
54 this->vertexMap.apply(fn);
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
55 }
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
56
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
57 void EditTools::setEditMode(EditingMode mode)
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
58 {
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
59 this->drawState.mode = mode;
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
60 }
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
61
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
62 void updatePreviewPolygon(DrawState* drawState)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
63 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
64 drawState->previewPolygon = drawState->polygon;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
65 drawState->previewPolygon.resize(drawState->polygon.size() + 1);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
66 drawState->previewPolygon.back() = drawState->previewPoint;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
67 if (drawState->previewPolygon.size() > 2)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
68 {
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
69 drawState->isconcave = not isConvex(drawState->previewPolygon);
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
70 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
71 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
72
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
73 void removeLastPoint(DrawState* drawState)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
74 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
75 if (drawState->polygon.size() > 0)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
76 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
77 drawState->polygon.erase(drawState->polygon.end() - 1);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
78 updatePreviewPolygon(drawState);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
79 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
80 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
81
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
82 bool isCloseToExistingPoints(const std::vector<glm::vec3>& points, const glm::vec3 &pos)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
83 {
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
84 return any(points, std::bind(isclose, std::placeholders::_1, pos));
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
85 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
86
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
87 void EditTools::canvasMouseClick(QMouseEvent*)
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
88 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
89 #if 0
198
eb9d900dc79a fix up things and remove unnecessary code
Teemu Piippo <teemu@hecknology.net>
parents: 197
diff changeset
90 switch(this->drawState.mode)
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
91 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
92 case SelectMode:
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
93 if (event->button() == Qt::LeftButton)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
94 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
95 const ModelId highlighted = this->canvas->getHighlightedObject();
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
96 QSet<ModelId> selected;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
97 if (highlighted != ModelId{0}) {
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
98 selected.insert(highlighted);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
99 }
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
100 //this->select(selected);
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
101 event->accept();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
102 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
103 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
104 case DrawMode:
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
105 if (event->button() == Qt::LeftButton) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
106 if (isCloseToExistingPoints(this->drawState.polygon, worldPosition)) {
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
107 this->closeShape();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
108 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
109 else {
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
110 this->drawState.polygon.push_back(pos);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
111 updatePreviewPolygon(&this->drawState);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
112 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
113 event->accept();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
114 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
115 else if (true
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
116 and event->button() == Qt::RightButton
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
117 and this->drawState.polygon.size() > 0
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
118 ) {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
119 this->drawState.polygon.erase(this->drawState.polygon.end() - 1);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
120 updatePreviewPolygon(&this->drawState);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
121 event->accept();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
122 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
123 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
124 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
125 #endif
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
126 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
127 void EditTools::canvasMouseMove(QMouseEvent*)
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
128 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
129 #if 0
198
eb9d900dc79a fix up things and remove unnecessary code
Teemu Piippo <teemu@hecknology.net>
parents: 197
diff changeset
130 switch(this->drawState.mode)
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
131 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
132 case SelectMode:
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
133 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
134 case DrawMode:
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
135 if (this->canvas->worldPosition.has_value())
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
136 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
137 this->drawState.previewPoint = this->canvas->worldPosition.value();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
138 updatePreviewPolygon(&this->drawState);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
139 this->update();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
140 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
141 event->accept();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
142 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
143 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
144 #endif
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
145 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
146 #if 0
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
147 /*
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
148
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
149 void EditorTabWidget::select(const QSet<ModelId> &selected)
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
150 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
151 QItemSelectionModel* selectionModel = this->ui.listView->selectionModel();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
152 QItemSelection itemSelection;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
153 for (const ModelId id : selected)
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
154 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
155 const std::optional<int> row = this->model->find(id);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
156 if (row.has_value())
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
157 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
158 const QModelIndex qindex = this->model->index(*row);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 198
diff changeset
159 itemSelection.select(qindex, qindex);
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
160 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
161 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
162 selectionModel->select(itemSelection, QItemSelectionModel::ClearAndSelect);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
163 }
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
164 */
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
165 const QSet<ModelId> EditTools::selectedObjects() const
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
166 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
167 return this->canvas->selectedObjects();
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
168 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
169 #endif
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
170 EditingMode EditTools::currentEditingMode() const
203
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
171 {
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
172 return this->drawState.mode;
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
173 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
174 #if 0
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
175 void EditTools::closeShape()
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
176 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
177 if (this->drawState.polygon.size() >= 2 and this->drawState.polygon.size() <= 4)
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
178 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
179 switch (this->drawState.polygon.size())
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
180 {
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
181 case 2:
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
182 Q_EMIT this->modelAction(AppendToModel{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
183 .newElement = Colored<LineSegment>{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
184 LineSegment{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
185 .p1 = this->drawState.polygon[0],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
186 .p2 = this->drawState.polygon[1],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
187 },
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
188 EDGE_COLOR,
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
189 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
190 });
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
191 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
192 case 3:
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
193 Q_EMIT this->modelAction(AppendToModel{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
194 .newElement = Colored<Triangle>{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
195 Triangle{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
196 .p1 = this->drawState.polygon[0],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
197 .p2 = this->drawState.polygon[1],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
198 .p3 = this->drawState.polygon[2],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
199 },
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
200 MAIN_COLOR,
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
201 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
202 });
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
203 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
204 case 4:
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
205 Q_EMIT this->modelAction(AppendToModel{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
206 .newElement = Colored<Quadrilateral>{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
207 Quadrilateral{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
208 .p1 = this->drawState.polygon[0],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
209 .p2 = this->drawState.polygon[1],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
210 .p3 = this->drawState.polygon[2],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
211 .p4 = this->drawState.polygon[3],
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
212 },
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
213 MAIN_COLOR,
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
214 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
215 });
197
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
216 break;
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
217 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
218 }
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
219 this->drawState.polygon.clear();
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
220 updatePreviewPolygon(&this->drawState);
0e729e681a2c move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
221 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
222
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 205
diff changeset
223 #endif

mercurial