Sat, 05 Jul 2014 01:45:32 +0300
- now with license headers
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 |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
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 |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
8 | * (at your option) any later version. |
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> |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "abstracteditmode.h" |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "selectmode.h" |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "drawmode.h" |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "circlemode.h" |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "magicwandmode.h" |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "../mainWindow.h" |
827 | 27 | #include "../glRenderer.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | AbstractEditMode::AbstractEditMode (GLRenderer* renderer) : |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | _renderer (renderer) {} |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
827 | 32 | AbstractEditMode::~AbstractEditMode() {} |
33 | ||
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | AbstractEditMode* AbstractEditMode::createByType (GLRenderer* renderer, EditModeType type) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | switch (type) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | case EditModeType::Select: return new SelectMode (renderer); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | case EditModeType::Draw: return new DrawMode (renderer); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | case EditModeType::Circle: return new CircleMode (renderer); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | case EditModeType::MagicWand: return new MagicWandMode (renderer); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | throw std::logic_error ("bad type given to AbstractEditMode::createByType"); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | GLRenderer* AbstractEditMode::renderer() const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | return _renderer; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | AbstractDrawMode::AbstractDrawMode (GLRenderer* renderer) : |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | AbstractEditMode (renderer), |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | _polybrush (QBrush (QColor (64, 192, 0, 128))) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // Disable the context menu - we need the right mouse button |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // for removing vertices. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | renderer->setContextMenuPolicy (Qt::NoContextMenu); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | // Use the crosshair cursor when drawing. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | renderer->setCursor (Qt::CrossCursor); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | // Clear the selection when beginning to draw. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | getCurrentDocument()->clearSelection(); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | g_win->updateSelection(); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
67 | _drawedVerts.clear(); |
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 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | AbstractSelectMode::AbstractSelectMode (GLRenderer* renderer) : |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | AbstractEditMode (renderer) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | renderer->unsetCursor(); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | renderer->setContextMenuPolicy (Qt::DefaultContextMenu); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | // ============================================================================= |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | // |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | void AbstractDrawMode::addDrawnVertex (Vertex const& pos) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | if (preAddVertex (pos)) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | return; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
84 | _drawedVerts << pos; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
87 | bool AbstractDrawMode::mouseReleased (MouseEventData const& data) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | { |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
89 | if (Super::mouseReleased (data)) |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
90 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
91 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
92 | if ((data.releasedButtons & Qt::MidButton) && (_drawedVerts.size() < 4) && (not data.mouseMoved)) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | // Find the closest vertex to our cursor |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | double minimumDistance = 1024.0; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | const Vertex* closest = null; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | Vertex cursorPosition = renderer()->coordconv2_3 (data.ev->pos(), false); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | QPoint cursorPosition2D (data.ev->pos()); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | const Axis relZ = renderer()->getRelativeZ(); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
100 | QVector<Vertex> vertices; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
102 | for (auto it = renderer()->document()->vertices().begin(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
103 | it != renderer()->document()->vertices().end(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
104 | ++it) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
105 | { |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | vertices << it.key(); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
107 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | // Sort the vertices in order of distance to camera |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | std::sort (vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | if (renderer()->getFixedCamera (renderer()->camera()).negatedDepth) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | return a[relZ] > b[relZ]; |
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 | return a[relZ] < b[relZ]; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | }); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | for (const Vertex& vrt : vertices) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | // If the vertex in 2d space is very close to the cursor then we use |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | // it regardless of depth. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | QPoint vect2d = renderer()->coordconv3_2 (vrt) - cursorPosition2D; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | const double distance2DSquared = std::pow (vect2d.x(), 2) + std::pow (vect2d.y(), 2); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | if (distance2DSquared < 16.0 * 16.0) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | closest = &vrt; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | break; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | // Check if too far away from the cursor. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | if (distance2DSquared > 64.0 * 64.0) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | continue; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | // 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
|
135 | // including depth. |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | const double distanceSquared = (vrt - cursorPosition).lengthSquared(); |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | if (distanceSquared < minimumDistance) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | minimumDistance = distanceSquared; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | closest = &vrt; |
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 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | if (closest != null) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | addDrawnVertex (*closest); |
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 | return true; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
151 | if ((data.releasedButtons & Qt::RightButton) && (not _drawedVerts.isEmpty())) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
152 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
153 | // Remove the last vertex |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
154 | _drawedVerts.removeLast(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
155 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
156 | return true; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
157 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
158 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | return false; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
161 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
162 | void AbstractDrawMode::finishDraw (LDObjectList& objs) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
163 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
164 | if (objs.size() > 0) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
165 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
166 | for (LDObjectPtr obj : objs) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
167 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
168 | renderer()->document()->addObject (obj); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
169 | renderer()->compileObject (obj); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
170 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
171 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
172 | g_win->refresh(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
173 | g_win->endAction(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
174 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
175 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
176 | _drawedVerts.clear(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
177 | } |