src/editmodes/linePathMode.cpp

Mon, 02 Apr 2018 10:33:17 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 02 Apr 2018 10:33:17 +0300
changeset 1369
1e2391b78d17
parent 1326
69a90bd2dba2
child 1419
f7c53002a990
permissions
-rw-r--r--

added cull depth support

1006
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
1 /*
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1006
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
4 *
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
5 * This program is free software: you can redistribute it and/or modify
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
6 * it under the terms of the GNU General Public License as published by
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
8 * (at your option) any later version.
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
9 *
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
10 * This program is distributed in the hope that it will be useful,
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
13 * GNU General Public License for more details.
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
14 *
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
15 * You should have received a copy of the GNU General Public License
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
17 */
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
18
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
19 #include <QKeyEvent>
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
20 #include "linePathMode.h"
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1079
diff changeset
21 #include "../canvas.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
22 #include "../mainwindow.h"
1141
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents: 1139
diff changeset
23 #include "../linetypes/edgeline.h"
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1079
diff changeset
25 LinePathMode::LinePathMode (Canvas* canvas) :
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1079
diff changeset
26 Super (canvas) {}
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
28 void LinePathMode::render (QPainter& painter) const
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 {
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 QVector<QPointF> points;
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
31 QList<Vertex> points3d = m_drawedVerts;
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
32 points3d << renderer()->position3D();
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
34 for (Vertex const& vrt : points3d)
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1104
diff changeset
35 points << renderer()->currentCamera().convert3dTo2d(vrt);
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 painter.setPen (renderer()->textPen());
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
39 if (countof(points) == countof(points3d))
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
40 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
41 for (int i = 0; i < countof(points) - 1; ++i)
958
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
42 {
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
43 painter.drawLine (QLineF (points[i], points[i + 1]));
1042
b54b78ac41a5 Some cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 1014
diff changeset
44 drawLineLength (painter, points3d[i], points3d[i + 1], points[i], points[i + 1]);
958
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
45 }
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
46
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
47 for (int i = 0; i < countof(points); ++i)
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
48 {
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
49 const QPointF& point = points[i];
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1042
diff changeset
50 renderer()->drawPoint (painter, point);
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
51 renderer()->drawBlipCoordinates (painter, points3d[i], point);
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
52 }
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
53 }
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 }
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
56 bool LinePathMode::mouseReleased (MouseEventData const& data)
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 {
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 if (Super::mouseReleased (data))
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 return true;
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 if (data.releasedButtons & Qt::LeftButton)
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 addDrawnVertex (renderer()->position3D());
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 return true;
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 }
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 return false;
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 }
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
69
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
70 bool LinePathMode::preAddVertex (Vertex const& pos)
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
71 {
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
72 // If we picked the vertex we last drew, stop drawing
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
73 if (not m_drawedVerts.isEmpty() and pos == m_drawedVerts.last())
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
74 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
75 endDraw();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
76 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
77 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
78
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
79 return false;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
80 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
81
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
82 void LinePathMode::endDraw()
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
83 {
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
84 Model model {m_documents};
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
85
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
86 for (int i = 0; i < countof(m_drawedVerts) - 1; ++i)
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
87 model.emplace<LDEdgeLine>(m_drawedVerts[i], m_drawedVerts[i + 1]);
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
88
1077
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
89 finishDraw(model);
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
90 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
91
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
92 bool LinePathMode::keyReleased (QKeyEvent* ev)
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
93 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
94 if (Super::keyReleased (ev))
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
95 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
96
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
97 if (ev->key() == Qt::Key_Enter or ev->key() == Qt::Key_Return)
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
98 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
99 endDraw();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
100 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
101 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
102
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
103 return false;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
104 }

mercurial