src/editmodes/abstractEditMode.cc

Tue, 02 Sep 2014 13:34:01 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 02 Sep 2014 13:34:01 +0300
changeset 874
ba75c789667e
parent 866
4951b737f8cb
child 875
ce8e9b37d44f
permissions
-rw-r--r--

- added line loop mode (doesn't actually create anything yet)

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
844
11587d419d2f - changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents: 841
diff changeset
3 * Copyright (C) 2013, 2014 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
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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"
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
27 #include "lineLoopMode.h"
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "../mainWindow.h"
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
29 #include "../glRenderer.h"
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
31 CFGENTRY (Bool, DrawLineLengths, true)
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
32 CFGENTRY (Bool, DrawAngles, false)
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
33
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 AbstractEditMode::AbstractEditMode (GLRenderer* renderer) :
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
35 m_renderer (renderer) {}
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
37 AbstractEditMode::~AbstractEditMode() {}
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
38
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 AbstractEditMode* AbstractEditMode::createByType (GLRenderer* renderer, EditModeType type)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 switch (type)
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 case EditModeType::Select: return new SelectMode (renderer);
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 case EditModeType::Draw: return new DrawMode (renderer);
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
45 case EditModeType::Rectangle: return new RectangleMode (renderer);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 case EditModeType::Circle: return new CircleMode (renderer);
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 case EditModeType::MagicWand: return new MagicWandMode (renderer);
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
48 case EditModeType::LineLoop: return new LineLoopMode (renderer);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 }
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 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
52 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 GLRenderer* AbstractEditMode::renderer() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
56 return m_renderer;
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
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 AbstractDrawMode::AbstractDrawMode (GLRenderer* renderer) :
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 AbstractEditMode (renderer),
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
61 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
62 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 // 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
64 // for removing vertices.
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 renderer->setContextMenuPolicy (Qt::NoContextMenu);
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 // Use the crosshair cursor when drawing.
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 renderer->setCursor (Qt::CrossCursor);
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 // Clear the selection when beginning to draw.
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
71 CurrentDocument()->clearSelection();
823
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 g_win->updateSelection();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
74 m_drawedVerts.clear();
823
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 AbstractSelectMode::AbstractSelectMode (GLRenderer* renderer) :
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 AbstractEditMode (renderer)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 renderer->unsetCursor();
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 renderer->setContextMenuPolicy (Qt::DefaultContextMenu);
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 // =============================================================================
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 void AbstractDrawMode::addDrawnVertex (Vertex const& pos)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 if (preAddVertex (pos))
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 return;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
91 m_drawedVerts << pos;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
94 bool AbstractDrawMode::mouseReleased (MouseEventData const& data)
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
96 if (Super::mouseReleased (data))
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
97 return true;
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
98
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
99 if ((data.releasedButtons & Qt::MidButton) and (m_drawedVerts.size() < 4) and (not data.mouseMoved))
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // Find the closest vertex to our cursor
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 double minimumDistance = 1024.0;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 const Vertex* closest = null;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 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
105 QPoint cursorPosition2D (data.ev->pos());
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 const Axis relZ = renderer()->getRelativeZ();
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 830
diff changeset
107 QVector<Vertex> vertices = renderer()->document()->inlineVertices();
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
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
151 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
152 {
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
153 // Remove the last vertex
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
154 m_drawedVerts.removeLast();
825
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
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
162 void AbstractDrawMode::finishDraw (LDObjectList const& objs)
825
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
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
176 m_drawedVerts.clear();
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
177 }
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
178
866
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
179 void AbstractDrawMode::renderPolygon (QPainter& painter, const QVector<Vertex>& poly3d,
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
180 bool withlengths, bool withangles) 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
181 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
182 QVector<QPoint> poly (poly3d.size());
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
183 QFontMetrics metrics = QFontMetrics (QFont());
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
184
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
185 // Convert to 2D
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
186 for (int i = 0; i < poly3d.size(); ++i)
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
187 poly[i] = renderer()->coordconv3_2 (poly3d[i]);
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
188
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
189 // Draw the polygon-to-be
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
190 painter.setBrush (m_polybrush);
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
191 painter.drawPolygon (QPolygonF (poly));
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
192
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
193 // Draw vertex blips
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
194 for (int i = 0; i < poly3d.size(); ++i)
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
195 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
196 QPoint& blip = poly[i];
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
197 painter.setPen (renderer()->linePen());
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
198 renderer()->drawBlip (painter, blip);
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
199
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
200 // Draw their coordinates
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
201 painter.setPen (renderer()->textPen());
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
202 painter.drawText (blip.x(), blip.y() - 8, poly3d[i].toString (true));
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 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
204
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
205 // Draw line lenghts and angle info if appropriate
866
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
206 if (poly3d.size() >= 2 and (withlengths or withangles))
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
207 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
208 painter.setPen (renderer()->textPen());
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
209
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
210 for (int i = 0; i < poly3d.size(); ++i)
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
211 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
212 const int j = (i + 1) % poly3d.size();
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
213 const int h = (i - 1 >= 0) ? (i - 1) : (poly3d.size() - 1);
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
214
866
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
215 if (withlengths and cfg::DrawLineLengths)
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
216 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
217 const QString label = QString::number ((poly3d[j] - poly3d[i]).length());
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
218 QPoint origin = QLineF (poly[i], poly[j]).pointAt (0.5).toPoint();
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
219 painter.drawText (origin, label);
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
220 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
221
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
222 if (withangles and cfg::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
223 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
224 QLineF l0 (poly[h], poly[i]),
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
225 l1 (poly[i], poly[j]);
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
226
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
227 double angle = 180 - l0.angleTo (l1);
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
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
229 if (angle < 0)
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
230 angle = 180 - l1.angleTo (l0);
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 QString label = QString::number (angle) + QString::fromUtf8 (QByteArray ("\302\260"));
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
233 QPoint pos = poly[i];
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
234 pos.setY (pos.y() + metrics.height());
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 painter.drawText (pos, label);
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
237 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
238 }
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 }

mercurial