Mon, 02 Apr 2018 13:21:15 +0300
automatically center the model in the renderer
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
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:
968
diff
changeset
|
8 | * (at your option) any later version. |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QPainter> |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QMouseEvent> |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
21 | #include "../canvas.h" |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "rectangleMode.h" |
1147
a26568aa3cce
Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
23 | #include "../linetypes/modelobject.h" |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
24 | #include "../linetypes/quadrilateral.h" |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
26 | RectangleMode::RectangleMode (Canvas* canvas) : |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
27 | Super (canvas), |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
28 | m_rectangleVerts (QVector<Vertex>(4)) {} |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | EditModeType RectangleMode::type() const |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | { |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | return EditModeType::Rectangle; |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | void RectangleMode::render (QPainter& painter) const |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
37 | renderPolygon (painter, (countof(m_drawedVerts) > 0) ? m_rectangleVerts : |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
38 | QVector<Vertex> ({renderer()->position3D()}), true, false); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
1009
85fd352bae45
Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
41 | void RectangleMode::endDraw() |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
43 | if (countof(m_drawedVerts) == 2) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | { |
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
|
45 | Model model {m_documents}; |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
46 | LDQuadrilateral* quad = model.emplace<LDQuadrilateral>(); |
1009
85fd352bae45
Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
47 | updateRectVerts(); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
1009
85fd352bae45
Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
49 | for (int i = 0; i < quad->numVertices(); ++i) |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
50 | quad->setVertex(i, m_rectangleVerts[i]); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
52 | finishDraw(model); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // Update rect vertices when the mouse moves since the 3d position likely has changed |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | bool RectangleMode::mouseMoved (QMouseEvent*) |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | { |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | updateRectVerts(); |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | return false; |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | void RectangleMode::updateRectVerts() |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
67 | if (m_drawedVerts.isEmpty()) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | { |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | for (int i = 0; i < 4; ++i) |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
70 | m_rectangleVerts[i] = renderer()->position3D(); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | return; |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | } |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
75 | Vertex v0 = m_drawedVerts[0], |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
76 | v1 = (countof(m_drawedVerts) >= 2) ? m_drawedVerts[1] : renderer()->position3D(); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
78 | Axis localx, localy, localz; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
79 | renderer()->getRelativeAxes(localx, localy); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
80 | localz = renderer()->getRelativeZ(); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | for (int i = 0; i < 4; ++i) |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
83 | m_rectangleVerts[i].setCoordinate (localz, renderer()->getDepthValue()); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
85 | m_rectangleVerts[0].setCoordinate (localx, v0[localx]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
86 | m_rectangleVerts[0].setCoordinate (localy, v0[localy]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
87 | m_rectangleVerts[1].setCoordinate (localx, v1[localx]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
88 | m_rectangleVerts[1].setCoordinate (localy, v0[localy]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
89 | m_rectangleVerts[2].setCoordinate (localx, v1[localx]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
90 | m_rectangleVerts[2].setCoordinate (localy, v1[localy]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
91 | m_rectangleVerts[3].setCoordinate (localx, v0[localx]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
92 | m_rectangleVerts[3].setCoordinate (localy, v1[localy]); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | } |