Sat, 17 Mar 2018 11:35:07 +0200
removed the old Add History Line tool
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
1 | /* |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
4 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
8 | * (at your option) any later version. |
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
9 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
13 | * GNU General Public License for more details. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
14 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
17 | */ |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
18 | |
827 | 19 | #include <QMouseEvent> |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <stdexcept> |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
21 | #include "abstractEditMode.h" |
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
22 | #include "selectMode.h" |
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
23 | #include "drawMode.h" |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
24 | #include "rectangleMode.h" |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
25 | #include "circleMode.h" |
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
26 | #include "magicWandMode.h" |
876
f040f0fb3795
- renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents:
875
diff
changeset
|
27 | #include "linePathMode.h" |
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:
986
diff
changeset
|
28 | #include "curvemode.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
29 | #include "../mainwindow.h" |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
30 | #include "../lddocument.h" |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
31 | #include "../canvas.h" |
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:
986
diff
changeset
|
32 | #include "../miscallenous.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
|
33 | #include "../grid.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
35 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
36 | * Base class constructor of the abstract editing mode. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
37 | */ |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
38 | AbstractEditMode::AbstractEditMode(Canvas* canvas) : |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
39 | QObject(canvas), |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
40 | HierarchyElement(canvas), |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
41 | m_canvas(canvas) {} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
43 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
44 | * Constructs an edit mode by type. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
45 | */ |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
46 | AbstractEditMode* AbstractEditMode::createByType(Canvas* canvas, EditModeType type) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | switch (type) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | { |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
50 | case EditModeType::Select: return new SelectMode (canvas); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
51 | case EditModeType::Draw: return new DrawMode (canvas); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
52 | case EditModeType::Rectangle: return new RectangleMode (canvas); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
53 | case EditModeType::Circle: return new CircleMode (canvas); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
54 | case EditModeType::MagicWand: return new MagicWandMode (canvas); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
55 | case EditModeType::LinePath: return new LinePathMode (canvas); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
56 | case EditModeType::Curve: return new CurveMode (canvas); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
1042 | 59 | throw std::logic_error("bad type given to AbstractEditMode::createByType"); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
62 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
63 | * Returns the edit mode's corresponding renderer pointer. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
64 | */ |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
65 | Canvas* AbstractEditMode::renderer() const |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | { |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
67 | return m_canvas; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
70 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
71 | * Base class constructor of the abstract drwaing mode. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
72 | */ |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
73 | AbstractDrawMode::AbstractDrawMode(Canvas* canvas) : |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
74 | AbstractEditMode {canvas}, |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
75 | m_polybrush {QBrush {QColor {64, 192, 0, 128}}} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | { |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
77 | canvas->setContextMenuPolicy(Qt::NoContextMenu); // We need the right mouse button for removing vertices |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
78 | canvas->setCursor(Qt::CrossCursor); |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1180
diff
changeset
|
79 | canvas->selectionModel()->clear(); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
850
diff
changeset
|
80 | m_drawedVerts.clear(); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
83 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
84 | * Base class constructor of the abstract selection mode. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
85 | */ |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
86 | AbstractSelectMode::AbstractSelectMode(Canvas* canvas) : |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
87 | AbstractEditMode {canvas} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | { |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
89 | canvas->unsetCursor(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1099
diff
changeset
|
90 | canvas->setContextMenuPolicy (Qt::DefaultContextMenu); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
93 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
94 | * Possibly adds this vertex into the list of drawn vertices. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
95 | */ |
1042 | 96 | void AbstractDrawMode::addDrawnVertex(const Vertex& position) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | { |
1042 | 98 | if (preAddVertex(position)) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | return; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
1042 | 101 | m_drawedVerts << position; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
104 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
105 | * Handles mouse relese events. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
106 | */ |
1042 | 107 | bool AbstractDrawMode::mouseReleased(MouseEventData const& data) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | { |
1042 | 109 | if (Super::mouseReleased(data)) |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
110 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
111 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
112 | // If the user presses the middle mouse button, seek the closest existing vertex to the cursor and clamp to that. |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
113 | if ((data.releasedButtons & Qt::MidButton) and (countof(m_drawedVerts) < 4) and (not data.mouseMoved)) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | // Find the closest vertex to our cursor |
1042 | 116 | double minimumDistance = 1024.0; |
117 | const Vertex* closest = nullptr; | |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
118 | Vertex cursorPosition = renderer()->currentCamera().convert2dTo3d(data.ev->pos()); |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
119 | QPoint cursorPosition2D = data.ev->pos(); |
1042 | 120 | const Axis depthAxis = renderer()->getRelativeZ(); |
1098
0b837bed121d
LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents:
1088
diff
changeset
|
121 | QList<Vertex> vertices = currentDocument()->inlineVertices().toList(); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | // Sort the vertices in order of distance to camera |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
124 | std::sort(vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | { |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
126 | if (renderer()->currentCamera().isAxisNegated(Z)) |
1042 | 127 | return a[depthAxis] > b[depthAxis]; |
128 | else | |
129 | return a[depthAxis] < b[depthAxis]; | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | }); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
132 | for (const Vertex& vertex : vertices) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | { |
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:
986
diff
changeset
|
134 | // If the vertex in 2d space is very close to the cursor then we use it regardless of depth. |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
135 | QPoint vect2d = renderer()->currentCamera().convert3dTo2d(vertex) - cursorPosition2D; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
136 | double distance2DSquared = std::pow(vect2d.x(), 2) + std::pow(vect2d.y(), 2); |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
137 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | if (distance2DSquared < 16.0 * 16.0) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | { |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
140 | closest = &vertex; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | break; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // Check if too far away from the cursor. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | if (distance2DSquared > 64.0 * 64.0) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | continue; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | // Not very close to the cursor. Compare using true distance, |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | // including depth. |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
150 | double distanceSquared = (vertex - cursorPosition).lengthSquared(); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | if (distanceSquared < minimumDistance) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | minimumDistance = distanceSquared; |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
155 | closest = &vertex; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
159 | if (closest) |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
160 | addDrawnVertex(*closest); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | return true; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
165 | // If the user presses the right mouse button, remove the previously drawn vertex. |
1042 | 166 | if ((data.releasedButtons & Qt::RightButton) and not m_drawedVerts.isEmpty()) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
167 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
850
diff
changeset
|
168 | m_drawedVerts.removeLast(); |
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:
986
diff
changeset
|
169 | return true; |
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:
986
diff
changeset
|
170 | } |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
171 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
172 | // If the user presses the left mouse button, insert the vertex or stop drawing, whichever is appropriate. |
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:
986
diff
changeset
|
173 | if (data.releasedButtons & Qt::LeftButton) |
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:
986
diff
changeset
|
174 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
175 | if (maxVertices() and countof(m_drawedVerts) >= maxVertices()) |
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:
986
diff
changeset
|
176 | endDraw(); |
1042 | 177 | else |
178 | addDrawnVertex (getCursorVertex()); | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
179 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
180 | return true; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
181 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
182 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
183 | // Otherwise we did not handle this mouse event. |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | return false; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | } |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
186 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
187 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
188 | * Finalises the draw operation. The provided model is merged into the main document. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
189 | */ |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
190 | void AbstractDrawMode::finishDraw(Model& model) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
191 | { |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
192 | int position = m_window->suggestInsertPoint(); |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
193 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
194 | if (countof(model) > 0) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
195 | { |
1099
14276e435640
GLRenderer no longer exposes the model pointer.
Teemu Piippo <teemu@hecknology.net>
parents:
1098
diff
changeset
|
196 | currentDocument()->merge(model, position); |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
197 | m_window->refresh(); |
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
198 | m_window->endAction(); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
199 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
200 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
850
diff
changeset
|
201 | m_drawedVerts.clear(); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
202 | } |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
203 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
204 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
205 | * Renders the length of the provided line. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
206 | * - v0 and v1 are the line vertices in 3D space. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
207 | * - v0p and v1p are the line vertices in 2D space (so that this function does not have to calculate them separately) |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
208 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
209 | void AbstractDrawMode::drawLineLength(QPainter &painter, const Vertex &v0, const Vertex &v1, const QPointF& v0p, const QPointF& v1p) const |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
210 | { |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
211 | if (not m_config->drawLineLengths()) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
212 | return; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
213 | |
1064
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
214 | const QString label = QString::number(abs(v1 - v0), 'f', 2); |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
215 | QPoint origin = QLineF {v0p, v1p}.pointAt(0.5).toPoint(); |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
216 | painter.drawText (origin, label); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
217 | } |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
218 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
219 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
220 | * Renders a polygon preview. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
221 | * |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
222 | * painter: QPainter instance that is currently being rendered to. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
223 | * polygon3d: The polygon as a vector of 3D vertices. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
224 | * drawLineLengths: if true, lengths of polygon sides are also previewed, assuming the user has enabled the relevant option. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
225 | * drawAngles: if true, the angles between polygon sides are also previewed, assuming the user has enabled the relevant option. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
226 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
227 | void AbstractDrawMode::renderPolygon(QPainter& painter, const QVector<Vertex>& polygon3d, bool drawLineLengths, bool drawAngles) const |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
228 | { |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
229 | QVector<QPoint> polygon2d {countof(polygon3d)}; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
230 | QFontMetrics metrics {QFont {}}; |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
231 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
232 | // Convert to 2D |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
233 | for (int i = 0; i < countof(polygon3d); ++i) |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
234 | polygon2d[i] = renderer()->currentCamera().convert3dTo2d(polygon3d[i]); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
235 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
236 | // Draw the polygon-to-be |
1042 | 237 | painter.setBrush(m_polybrush); |
238 | painter.drawPolygon(QPolygonF{polygon2d}); | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
239 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
240 | // Draw vertex blips |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
241 | for (int i = 0; i < countof(polygon3d); ++i) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
242 | { |
1056
27b7991b3bea
Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents:
1042
diff
changeset
|
243 | renderer()->drawPoint(painter, polygon2d[i]); |
1042 | 244 | renderer()->drawBlipCoordinates(painter, polygon3d[i], polygon2d[i]); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
245 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
246 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
247 | // Draw line lenghts and angle info if appropriate |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
248 | if (countof(polygon3d) >= 2 and (drawLineLengths or drawAngles)) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
249 | { |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
250 | painter.setPen(renderer()->textPen()); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
251 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
252 | for (int i = 0; i < countof(polygon3d); ++i) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
253 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
254 | int j = (i + 1) % countof(polygon3d); |
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
255 | int prior = (i - 1 >= 0) ? (i - 1) : (countof(polygon3d) - 1); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
256 | |
1042 | 257 | if (drawLineLengths) |
258 | drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]); | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
259 | |
1042 | 260 | if (drawAngles and m_config->drawAngles()) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
261 | { |
1042 | 262 | QLineF line0 = {polygon2d[prior], polygon2d[i]}; |
263 | QLineF line1 = {polygon2d[i], polygon2d[j]}; | |
264 | double angle = 180 - line0.angleTo(line1); | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
265 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
266 | if (angle < 0) |
1042 | 267 | angle = 180 - line1.angleTo(line0); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
268 | |
1042 | 269 | QString label = QString::number(angle) + "°"; |
270 | QPoint textPosition = polygon2d[i]; | |
271 | textPosition.setY(textPosition.y() + metrics.height()); | |
272 | painter.drawText(textPosition, label); | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
273 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
274 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
275 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
276 | } |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
277 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
278 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
279 | * Key release event handler |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
280 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
281 | bool AbstractDrawMode::keyReleased(QKeyEvent *event) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
282 | { |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
283 | if (Super::keyReleased(event)) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
284 | return true; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
285 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
286 | // Map backspace to removing the previously drawn vertex. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
287 | if (not m_drawedVerts.isEmpty() and event->key() == Qt::Key_Backspace) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
288 | { |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
289 | m_drawedVerts.removeLast(); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
290 | return true; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
291 | } |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
292 | |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
293 | return false; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
294 | } |
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:
986
diff
changeset
|
295 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
296 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
297 | * Computes the position for the vertex currently being drawn. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
298 | */ |
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:
986
diff
changeset
|
299 | Vertex AbstractDrawMode::getCursorVertex() const |
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:
986
diff
changeset
|
300 | { |
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:
986
diff
changeset
|
301 | Vertex result = renderer()->position3D(); |
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:
986
diff
changeset
|
302 | |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
303 | // If the Ctrl key is pressed, then the vertex is locked to 45 degree angles relative to the previously drawn vertex. |
1042 | 304 | if ((renderer()->keyboardModifiers() & Qt::ControlModifier) and not m_drawedVerts.isEmpty()) |
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:
986
diff
changeset
|
305 | { |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
306 | const Vertex& vertex0 = m_drawedVerts.last(); |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
307 | const Vertex& vertex1 = result; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
308 | Axis relativeX; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
309 | Axis relativeY; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
310 | renderer()->getRelativeAxes(relativeX, relativeY); |
1042 | 311 | QLineF line = {vertex0[relativeX], vertex0[relativeY], vertex1[relativeX], vertex1[relativeY]}; |
312 | line.setAngle(roundToInterval<int>(line.angle(), 45)); | |
1180
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
313 | QPointF point = grid()->snap(line.p2()); |
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
314 | result.setCoordinate(relativeX, point.x()); |
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
315 | result.setCoordinate(relativeY, point.y()); |
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:
986
diff
changeset
|
316 | } |
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:
986
diff
changeset
|
317 | |
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:
986
diff
changeset
|
318 | return result; |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
319 | } |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
320 | |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
321 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
322 | * No draw mode can operate on the free camera, since 3D ⟷ 2D point conversions are not possible with it. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
323 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
324 | bool AbstractDrawMode::allowFreeCamera() const |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
325 | { |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
326 | return false; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
327 | } |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
328 | |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
329 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
330 | * This virtual method allows drawing modes to specify how many vertices at most can be drawn. Returning 0 means unlimited. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
331 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
332 | int AbstractDrawMode::maxVertices() const |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
333 | { |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
334 | return 0; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
335 | } |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
336 | |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
337 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
338 | * This virtual method is a hook that allows drawing modes to veto vertex insertion. Returning true means that the vertex insertion |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
339 | * was handled separately and the vertex will not be added. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
340 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
341 | bool AbstractDrawMode::preAddVertex (Vertex const&) |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
342 | { |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
343 | return false; |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
344 | } |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
345 | |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
346 | /* |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
347 | * This virtual method is overridden by subclasses to implement the actions taken by the edit mode. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
348 | * The editing mode is to call finishDraw with the prepared model. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
349 | * |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
350 | * TODO: the two method names are too similar and should be renamed. |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
351 | */ |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
352 | void AbstractDrawMode::endDraw() {} |