src/editmodes/abstractEditMode.cpp

Tue, 15 Nov 2016 17:37:31 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 15 Nov 2016 17:37:31 +0200
changeset 1046
f4a7b56c7eb2
parent 1042
b54b78ac41a5
child 1056
27b7991b3bea
permissions
-rw-r--r--

Cleanup PartDownloader

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
1014
f0a8ecb6a357 Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1013
diff changeset
3 * Copyright (C) 2013 - 2016 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
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"
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"
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
30 #include "../glRenderer.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
31 #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
32 #include "../grid.h"
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
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
34 ConfigOption (bool DrawLineLengths = true)
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
35 ConfigOption (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
36
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
37 AbstractEditMode::AbstractEditMode(GLRenderer* renderer) :
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
38 QObject(renderer),
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
39 HierarchyElement(renderer),
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
40 m_renderer(renderer) {}
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
42 AbstractEditMode::~AbstractEditMode() {}
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
43
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
44 AbstractEditMode* AbstractEditMode::createByType(GLRenderer* renderer, EditModeType type)
823
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 switch (type)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 {
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
48 case EditModeType::Select: return new SelectMode (renderer);
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
49 case EditModeType::Draw: return new DrawMode (renderer);
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
50 case EditModeType::Rectangle: return new RectangleMode (renderer);
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
51 case EditModeType::Circle: return new CircleMode (renderer);
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
52 case EditModeType::MagicWand: return new MagicWandMode (renderer);
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
53 case EditModeType::LinePath: return new LinePathMode (renderer);
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
54 case EditModeType::Curve: return new CurveMode (renderer);
823
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
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
57 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
58 }
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 GLRenderer* AbstractEditMode::renderer() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
62 return m_renderer;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
65 AbstractDrawMode::AbstractDrawMode(GLRenderer* renderer) :
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
66 AbstractEditMode(renderer),
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
67 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
68 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
69 renderer->setContextMenuPolicy (Qt::NoContextMenu); // We need the right mouse button for removing vertices
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 renderer->setCursor (Qt::CrossCursor);
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
71 m_window->currentDocument()->clearSelection();
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
72 m_window->updateSelection();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
73 m_drawedVerts.clear();
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
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 AbstractSelectMode::AbstractSelectMode (GLRenderer* renderer) :
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 AbstractEditMode (renderer)
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 renderer->unsetCursor();
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 renderer->setContextMenuPolicy (Qt::DefaultContextMenu);
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
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 //
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
85 void AbstractDrawMode::addDrawnVertex(const Vertex& position)
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
87 if (preAddVertex(position))
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 return;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
90 m_drawedVerts << position;
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
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
93 bool AbstractDrawMode::mouseReleased(MouseEventData const& data)
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
95 if (Super::mouseReleased(data))
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
96 return true;
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
97
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
98 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
99 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 // Find the closest vertex to our cursor
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
101 double minimumDistance = 1024.0;
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
102 const Vertex* closest = nullptr;
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
103 Vertex cursorPosition = renderer()->convert2dTo3d (data.ev->pos(), false);
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
104 QPoint cursorPosition2D (data.ev->pos());
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
105 const Axis depthAxis = renderer()->getRelativeZ();
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
106 QList<Vertex> vertices = renderer()->document()->inlineVertices().toList();
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 // 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
109 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
110 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
111 if (renderer()->cameraInfo (renderer()->camera()).negatedDepth)
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
112 return a[depthAxis] > b[depthAxis];
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
113 else
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
114 return a[depthAxis] < b[depthAxis];
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 });
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 for (const Vertex& vrt : vertices)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 {
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
119 // If the vertex in 2d space is very close to the cursor then we use it regardless of depth.
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
120 QPoint vect2d = renderer()->convert3dTo2d (vrt) - cursorPosition2D;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 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
122 if (distance2DSquared < 16.0 * 16.0)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 closest = &vrt;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 break;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 // Check if too far away from the cursor.
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 if (distance2DSquared > 64.0 * 64.0)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 continue;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 // 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
133 // including depth.
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 const double distanceSquared = (vrt - cursorPosition).lengthSquared();
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 if (distanceSquared < minimumDistance)
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 minimumDistance = distanceSquared;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 closest = &vrt;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
143 if (closest)
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 addDrawnVertex (*closest);
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 return true;
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
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
149 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
150 {
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
151 // Remove the last vertex
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
152 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
153 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
154 }
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
155
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
156 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
157 {
1008
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
158 if (maxVertices() and m_drawedVerts.size() >= 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
159 endDraw();
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
160 else
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
161 addDrawnVertex (getCursorVertex());
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
162 return true;
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
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 return false;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
167
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
168 void AbstractDrawMode::finishDraw(LDObjectList const& objs)
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
169 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
170 int pos = m_window->suggestInsertPoint();
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
171
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
172 if (objs.size() > 0)
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
173 {
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 876
diff changeset
174 for (LDObject* obj : objs)
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
175 {
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
176 renderer()->document()->insertObject (pos++, obj);
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
177 renderer()->compileObject (obj);
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
178 }
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
179
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
180 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
181 m_window->endAction();
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
182 }
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
183
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
184 m_drawedVerts.clear();
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
185 }
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
186
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
187 void AbstractDrawMode::drawLineLength(QPainter &painter, const Vertex &v0, const Vertex &v1,
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
188 const QPointF& v0p, const QPointF& v1p) const
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
189 {
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
190 if (not m_config->drawLineLengths())
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
191 return;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
192
1041
9fc08b73b8c4 Draw line lengths to 2 decimal points only.
Teemu Piippo <teemu@hecknology.net>
parents: 1033
diff changeset
193 const QString label = QString::number ((v1 - v0).length(), 'f', 2);
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
194 QPoint origin = QLineF (v0p, v1p).pointAt (0.5).toPoint();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
195 painter.drawText (origin, label);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
196 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
197
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
198 void AbstractDrawMode::renderPolygon(QPainter& painter, const QVector<Vertex>& polygon3d,
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
199 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
200 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
201 QVector<QPoint> polygon2d (polygon3d.size());
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
202 QFontMetrics metrics = QFontMetrics(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
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 // Convert to 2D
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
205 for (int i = 0; i < polygon3d.size(); ++i)
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
206 polygon2d[i] = renderer()->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
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 // Draw the polygon-to-be
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
209 painter.setBrush(m_polybrush);
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
210 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
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 // Draw vertex blips
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
213 for (int i = 0; i < polygon3d.size(); ++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
214 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
215 renderer()->drawBlip(painter, polygon2d[i]);
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
216 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
217 }
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
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 // Draw line lenghts and angle info if appropriate
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
220 if (polygon3d.size() >= 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
221 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
222 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
223
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
224 for (int i = 0; i < polygon3d.size(); ++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
225 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
226 int j = (i + 1) % polygon3d.size();
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
227 int prior = (i - 1 >= 0) ? (i - 1) : (polygon3d.size() - 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
228
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
229 if (drawLineLengths)
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
230 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
231
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
232 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
233 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
234 QLineF line0 = {polygon2d[prior], polygon2d[i]};
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
235 QLineF line1 = {polygon2d[i], polygon2d[j]};
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
236 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
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 if (angle < 0)
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
239 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
240
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
241 QString label = QString::number(angle) + "°";
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
242 QPoint textPosition = polygon2d[i];
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
243 textPosition.setY(textPosition.y() + metrics.height());
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
244 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
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 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
248 }
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
249
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
250 bool AbstractDrawMode::keyReleased (QKeyEvent *ev)
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
251 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
252 if (Super::keyReleased (ev))
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
253 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
254
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
255 if (not m_drawedVerts.isEmpty() and ev->key() == Qt::Key_Backspace)
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
256 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
257 m_drawedVerts.removeLast();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
258 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
259 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
260
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
261 return false;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
262 }
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
263
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
264 //
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
265 // roundToInterval
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
266 //
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
267 // Rounds 'a' to the nearest multiple of 'interval'.
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
268 //
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
269 template<typename T>
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
270 T roundToInterval (T a, T interval)
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
271 {
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
272 T remainder = a % interval;
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
273
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
274 if (remainder >= interval / 2.0)
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
275 a += interval;
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
276
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
277 a -= remainder;
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
278 return a;
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
279 }
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
280
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
281 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
282 {
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
283 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
284
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
285 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
286 {
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
287 Vertex const& vertex0 = m_drawedVerts.last();
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
288 Vertex const& vertex1 = result;
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
289 Axis relativeX, relativeY;
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
290
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
291 renderer()->getRelativeAxes (relativeX, relativeY);
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
292 QLineF line = {vertex0[relativeX], vertex0[relativeY], vertex1[relativeX], vertex1[relativeY]};
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
293 line.setAngle(roundToInterval<int>(line.angle(), 45));
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
294 result.setCoordinate(relativeX, grid()->snap(line.x2(), Grid::Coordinate));
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1041
diff changeset
295 result.setCoordinate(relativeY, grid()->snap(line.y2(), Grid::Coordinate));
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
296 }
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
297
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
298 return result;
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 }

mercurial