src/editmodes/abstractEditMode.cpp

Sun, 04 Oct 2015 04:26:11 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 04 Oct 2015 04:26:11 +0300
changeset 1000
c064cc048f14
parent 986
525921eae58c
child 1006
a6b462051ae0
permissions
-rw-r--r--

Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.

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
968
4b93b7963456 Happy new year 2015
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
3 * Copyright (C) 2013 - 2015 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"
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"
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
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
33 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
34 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
35
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 AbstractEditMode::AbstractEditMode (GLRenderer* renderer) :
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
37 QObject (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
38 HierarchyElement (renderer),
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
39 m_renderer (renderer) {}
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
41 AbstractEditMode::~AbstractEditMode() {}
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
42
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 AbstractEditMode* AbstractEditMode::createByType (GLRenderer* renderer, EditModeType type)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 switch (type)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 {
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
47 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
48 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
49 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
50 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
51 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
52 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
53 case EditModeType::Curve: return new CurveMode (renderer);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 }
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 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
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 GLRenderer* AbstractEditMode::renderer() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
61 return m_renderer;
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
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 AbstractDrawMode::AbstractDrawMode (GLRenderer* renderer) :
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 AbstractEditMode (renderer),
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
66 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
67 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
68 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
69 renderer->setCursor (Qt::CrossCursor);
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
70 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
71 m_window->updateSelection();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
72 m_drawedVerts.clear();
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
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 AbstractSelectMode::AbstractSelectMode (GLRenderer* renderer) :
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 AbstractEditMode (renderer)
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 renderer->unsetCursor();
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 renderer->setContextMenuPolicy (Qt::DefaultContextMenu);
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
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 void AbstractDrawMode::addDrawnVertex (Vertex const& pos)
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 if (preAddVertex (pos))
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 return;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
89 m_drawedVerts << pos;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
92 bool AbstractDrawMode::mouseReleased (MouseEventData const& data)
823
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 if (Super::mouseReleased (data))
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
95 return true;
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
96
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
97 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
98 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 // Find the closest vertex to our cursor
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 double minimumDistance = 1024.0;
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
101 const Vertex* closest = nullptr;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
102 Vertex cursorPosition = renderer()->convert2dTo3d (data.ev->pos(), false);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 QPoint cursorPosition2D (data.ev->pos());
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 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
105 QVector<Vertex> vertices = renderer()->document()->inlineVertices();
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 // 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
108 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
109 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 if (renderer()->getFixedCamera (renderer()->camera()).negatedDepth)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 return a[relZ] > b[relZ];
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
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
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 for (const Vertex& vrt : vertices)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 {
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
118 // 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
119 QPoint vect2d = renderer()->convert3dTo2d (vrt) - cursorPosition2D;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 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
121 if (distance2DSquared < 16.0 * 16.0)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 closest = &vrt;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 break;
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
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 // Check if too far away from the cursor.
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 if (distance2DSquared > 64.0 * 64.0)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 continue;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 // 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
132 // including depth.
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 const double distanceSquared = (vrt - cursorPosition).lengthSquared();
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 if (distanceSquared < minimumDistance)
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 minimumDistance = distanceSquared;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 closest = &vrt;
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 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
142 if (closest)
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 addDrawnVertex (*closest);
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 return true;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
148 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
149 {
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
150 // Remove the last vertex
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
151 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
152 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
153 }
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
154
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
155 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
156 {
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 if (m_drawedVerts.size() >= maxVertices())
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
158 {
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();
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
160 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
161 }
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
162
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
163 addDrawnVertex (getCursorVertex());
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
164 return true;
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
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 return false;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 }
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
169
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
170 void AbstractDrawMode::finishDraw (LDObjectList const& objs)
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
171 {
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
172 int pos = m_window->suggestInsertPoint();
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
173
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
174 if (objs.size() > 0)
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
175 {
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 876
diff changeset
176 for (LDObject* obj : objs)
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
177 {
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
178 renderer()->document()->insertObj (pos++, obj);
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
179 renderer()->compileObject (obj);
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
180 }
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
181
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
182 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
183 m_window->endAction();
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
184 }
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
185
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
186 m_drawedVerts.clear();
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
187 }
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
188
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
189 void AbstractDrawMode::drawLength (QPainter &painter, const Vertex &v0, const Vertex &v1,
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
190 const QPointF& v0p, const QPointF& v1p) const
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
191 {
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
192 if (not m_config->drawLineLengths())
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
193 return;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
194
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
195 const QString label = QString::number ((v1 - v0).length());
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
196 QPoint origin = QLineF (v0p, v1p).pointAt (0.5).toPoint();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
197 painter.drawText (origin, label);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
198 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
199
866
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
200 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
201 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
202 {
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 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
204 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
205
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
206 // 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
207 for (int i = 0; i < poly3d.size(); ++i)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
208 poly[i] = renderer()->convert3dTo2d (poly3d[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
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 // Draw the polygon-to-be
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
211 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
212 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
213
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 // 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
215 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
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 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
218 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
219 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
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 // 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
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 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
224 }
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
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 // 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
227 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
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 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
230
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 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
232 {
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 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
234 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
235
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
236 if (withlengths)
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
237 drawLength (painter, poly3d[i], poly3d[j], poly[i], poly[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
238
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
239 if (withangles 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
240 {
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
241 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
242 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
243
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
244 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
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 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
247 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
248
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
249 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
250 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
251 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
252
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
253 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
254 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
255 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
256 }
1243abd47381 - split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
257 }
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
258
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
259 bool AbstractDrawMode::keyReleased (QKeyEvent *ev)
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 if (Super::keyReleased (ev))
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
262 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
263
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
264 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
265 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
266 m_drawedVerts.removeLast();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
267 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
268 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
269
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
270 return false;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
271 }
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
272
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 template<typename T>
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
274 T intervalClamp (T a, T 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
275 {
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 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
277
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 if (remainder >= float (interval / 2))
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 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
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 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
282 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
283 }
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
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
285 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
286 {
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
287 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
288
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
289 if (renderer()->keyboardModifiers() & Qt::ControlModifier
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 and not m_drawedVerts.isEmpty())
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
291 {
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
292 Vertex const& v0 = m_drawedVerts.last();
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
293 Vertex const& v1 = 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
294 Axis relX, relY;
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
295
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 renderer()->getRelativeAxes (relX, relY);
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 QLineF ln (v0[relX], v0[relY], v1[relX], v1[relY]);
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 ln.setAngle (intervalClamp<int> (ln.angle(), 45));
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 result.setCoordinate (relX, Grid::Snap (ln.x2(), Grid::Coordinate));
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
300 result.setCoordinate (relY, Grid::Snap (ln.y2(), Grid::Coordinate));
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
301 }
c064cc048f14 Begin work on Bézier curve support. They can be drawn but don't render in 3D and they load as comments.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
302
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
303 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
304 }

mercurial