src/linetypes/modelobject.cpp

Tue, 14 Feb 2017 15:21:34 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 14 Feb 2017 15:21:34 +0200
changeset 1149
502c866b8512
parent 1148
96cb15a7611f
child 1158
35ceb74fe53e
permissions
-rw-r--r--

Moved LDQuadrilateral into its own source pair.

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1070
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
1082
1738bdaf36d6 The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
Teemu Piippo <teemu@hecknology.net>
parents: 1081
diff changeset
19 #include <assert.h>
1147
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
20 #include "../documentmanager.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
21 #include "../linetypes/modelobject.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
22 #include "../lddocument.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
23 #include "../miscallenous.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
24 #include "../mainwindow.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
25 #include "../editHistory.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
26 #include "../canvas.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
27 #include "../colors.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
28 #include "../glcompiler.h"
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
29 #include "edgeline.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 // List of all LDObjects
1135
8e0691be0b6f Removed the intXX type aliases and removed uses of intXX_t in favor of qintXX
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
32 QMap<qint32, LDObject*> g_allObjects;
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
33
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
34 enum { MAX_LDOBJECT_IDS = (1 << 24) };
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
35
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
36 #define LDOBJ_DEFAULT_CTOR(T,BASE) \
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
37 T :: T (Model* model) : \
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
38 BASE {model} {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 // LDObject constructors
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 //
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
43 LDObject::LDObject (Model* model) :
1082
1738bdaf36d6 The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
Teemu Piippo <teemu@hecknology.net>
parents: 1081
diff changeset
44 m_isHidden {false},
1738bdaf36d6 The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
Teemu Piippo <teemu@hecknology.net>
parents: 1081
diff changeset
45 m_isSelected {false},
1738bdaf36d6 The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
Teemu Piippo <teemu@hecknology.net>
parents: 1081
diff changeset
46 _model {model},
1738bdaf36d6 The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
Teemu Piippo <teemu@hecknology.net>
parents: 1081
diff changeset
47 m_coords {Origin}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
1082
1738bdaf36d6 The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
Teemu Piippo <teemu@hecknology.net>
parents: 1081
diff changeset
49 assert(_model != nullptr);
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
50
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
51 // Let's hope that nobody goes to create 17 million objects anytime soon...
1135
8e0691be0b6f Removed the intXX type aliases and removed uses of intXX_t in favor of qintXX
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
52 static qint32 nextId = 1; // 0 shalt be null
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
53 if (nextId < MAX_LDOBJECT_IDS)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
54 m_id = nextId++;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
55 else
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
56 m_id = 0;
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
57
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
58 if (m_id != 0)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
59 g_allObjects[m_id] = this;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
60
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
61 m_randomColor = QColor::fromHsv (rand() % 360, rand() % 256, rand() % 96 + 128);
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
62 }
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
63
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
64 LDSubfileReference::LDSubfileReference (Model* model) :
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
65 LDMatrixObject (model) {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
67 LDOBJ_DEFAULT_CTOR (LDError, LDObject)
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
68 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject)
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: 998
diff changeset
69 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject)
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
70
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
71 LDObject::~LDObject()
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
72 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
73 // Delete the GL lists
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
74 if (g_win)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
75 g_win->renderer()->forgetObject(this);
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
76
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
77 // Remove this object from the list of LDObjects
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
78 g_allObjects.erase(g_allObjects.find(id()));
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
79 }
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
80
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 //
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1008
diff changeset
83 QString LDSubfileReference::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
85 QString val = format ("1 %1 %2 ", color(), position());
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
86 val += transformationMatrix().toString();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 val += ' ';
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 val += fileInfo()->name();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 return val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
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: 998
diff changeset
92 QString LDBezierCurve::asText() 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: 998
diff changeset
93 {
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: 998
diff changeset
94 QString result = format ("0 !LDFORGE BEZIER_CURVE %1", color());
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
95
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: 998
diff changeset
96 // Add the coordinates
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: 998
diff changeset
97 for (int i = 0; i < 4; ++i)
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: 998
diff changeset
98 result += format (" %1", vertex (i));
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: 998
diff changeset
99
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: 998
diff changeset
100 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: 998
diff changeset
101 }
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: 998
diff changeset
102
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
105 QString LDError::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 return contents();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
112 QString LDBfc::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 {
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
114 return format ("0 BFC %1", statementToString());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
119 // Swap this object with another.
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
120 //
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
121 void LDObject::swap (LDObject* other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
123 if (model() == other->model())
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
124 model()->swapObjects (this, other);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
127 int LDObject::triangleCount() const
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
128 {
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
129 return 0;
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
130 }
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
131
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
132 int LDSubfileReference::triangleCount() const
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
133 {
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
134 return fileInfo()->triangleCount();
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
135 }
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
136
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
137 int LDObject::numVertices() const
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
138 {
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
139 return 0;
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
140 }
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
141
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 //
1077
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1076
diff changeset
144 LDBezierCurve::LDBezierCurve(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) :
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1076
diff changeset
145 LDObject {model}
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: 998
diff changeset
146 {
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: 998
diff changeset
147 setVertex (0, v0);
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: 998
diff changeset
148 setVertex (1, v1);
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: 998
diff changeset
149 setVertex (2, v2);
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: 998
diff changeset
150 setVertex (3, v3);
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: 998
diff changeset
151 }
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: 998
diff changeset
152
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: 998
diff changeset
153 // =============================================================================
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: 998
diff changeset
154 //
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
155 void LDObject::setDocument (Model* model)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
157 _model = model;
880
5dcd2e741d1c - fixed documentless objects being selected on document close
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
158 }
5dcd2e741d1c - fixed documentless objects being selected on document close
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
159
5dcd2e741d1c - fixed documentless objects being selected on document close
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
160 // =============================================================================
5dcd2e741d1c - fixed documentless objects being selected on document close
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
161 //
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
162 static void TransformObject (LDObject* obj, Matrix transform, Vertex pos, LDColor parentcolor)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 switch (obj->type())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 {
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
166 case LDObjectType::EdgeLine:
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
167 case LDObjectType::ConditionalEdge:
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1117
diff changeset
168 case LDObjectType::Triangle:
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
169 case LDObjectType::Quadrilateral:
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
170 for (int i = 0; i < obj->numVertices(); ++i)
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
171 {
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
172 Vertex v = obj->vertex (i);
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
173 v.transform (transform, pos);
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
174 obj->setVertex (i, v);
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
175 }
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
176 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1117
diff changeset
178 case LDObjectType::SubfileReference:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1008
diff changeset
180 LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj);
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
181 Matrix newMatrix = transform * ref->transformationMatrix();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 Vertex newpos = ref->position();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 newpos.transform (transform, pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 ref->setPosition (newpos);
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
185 ref->setTransformationMatrix (newMatrix);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
187 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
189 default:
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
190 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
193 if (obj->color() == MainColor)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 obj->setColor (parentcolor);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 // =============================================================================
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
198 // -----------------------------------------------------------------------------
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
199 void LDSubfileReference::inlineContents(Model& model, bool deep, bool render)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 {
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: 1078
diff changeset
201 Model inlined {this->model()->documentManager()};
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
202 fileInfo()->inlineContents(inlined, deep, render);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 // Transform the objects
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
205 for (LDObject* object : inlined)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
206 TransformObject(object, transformationMatrix(), position(), color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
208 model.merge(inlined);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 //
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
213 LDPolygon* LDObject::getPolygon()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
214 {
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
215 LDObjectType ot = type();
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
216 int num = (ot == LDObjectType::EdgeLine) ? 2
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1117
diff changeset
217 : (ot == LDObjectType::Triangle) ? 3
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
218 : (ot == LDObjectType::Quadrilateral) ? 4
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
219 : (ot == LDObjectType::ConditionalEdge) ? 5
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 846
diff changeset
220 : 0;
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 846
diff changeset
221
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
222 if (num == 0)
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 983
diff changeset
223 return nullptr;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
224
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
225 LDPolygon* data = new LDPolygon;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
226 data->id = id();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
227 data->num = num;
806
4240f47aa2d4 - moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 805
diff changeset
228 data->color = color().index();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
229
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
230 for (int i = 0; i < data->numVertices(); ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
231 data->vertices[i] = vertex (i);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
232
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
233 return data;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
234 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
235
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
236 LDColor LDObject::defaultColor() const
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
237 {
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
238 return MainColor;
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
239 }
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
240
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
241 bool LDObject::isColored() const
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
242 {
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
243 return true;
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
244 }
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
245
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
246 bool LDObject::isScemantic() const
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
247 {
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
248 return true;
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
249 }
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
250
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
251 bool LDObject::hasMatrix() const
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
252 {
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
253 return false;
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
254 }
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
255
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
256 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
257 //
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1008
diff changeset
258 QList<LDPolygon> LDSubfileReference::inlinePolygons()
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
259 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
260 QList<LDPolygon> data = fileInfo()->inlinePolygons();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
261
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
262 for (LDPolygon& entry : data)
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 846
diff changeset
263 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
264 for (int i = 0; i < entry.numVertices(); ++i)
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
265 entry.vertices[i].transform (transformationMatrix(), position());
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 846
diff changeset
266 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
267
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
268 return data;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
269 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
270
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
271 // =============================================================================
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
272 //
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
273 // Index (i.e. line number) of this object
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
274 //
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
275 int LDObject::lineNumber() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
277 if (model())
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 846
diff changeset
278 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
279 for (int i = 0; i < model()->size(); ++i)
949
a9ba8ffd9534 actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
280 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
281 if (model()->getObject(i) == this)
949
a9ba8ffd9534 actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
282 return i;
a9ba8ffd9534 actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
283 }
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 846
diff changeset
284 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 return -1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
291 // Object after this in the current file
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
292 //
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
293 LDObject* LDObject::next() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
295 return model()->getObject(lineNumber() + 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
300 // Object prior to this in the current file
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
301 //
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
302 LDObject* LDObject::previous() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
304 return model()->getObject(lineNumber() - 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
309 // Is the previous object INVERTNEXT?
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
310 //
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
311 bool LDObject::previousIsInvertnext (LDBfc*& ptr)
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
312 {
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
313 LDObject* prev = previous();
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
314
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1117
diff changeset
315 if (prev and prev->type() == LDObjectType::Bfc and static_cast<LDBfc*> (prev)->statement() == BfcStatement::InvertNext)
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
316 {
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
317 ptr = static_cast<LDBfc*> (prev);
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
318 return true;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
319 }
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
320
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
321 return false;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
322 }
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
323
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
324 // =============================================================================
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
325 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
326 // Moves this object using the given vertex as a movement List
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
327 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 void LDObject::move (Vertex vect)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 if (hasMatrix())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 {
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
332 LDMatrixObject* mo = static_cast<LDMatrixObject*> (this);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 mo->setPosition (mo->position() + vect);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 {
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
337 for (int i = 0; i < numVertices(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 setVertex (i, vertex (i) + vect);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
342 bool LDObject::isHidden() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
343 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
344 return m_isHidden;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
345 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
346
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
347 void LDObject::setHidden (bool value)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
348 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
349 m_isHidden = value;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
350 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
351
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
352 bool LDObject::isSelected() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
353 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
354 return m_isSelected;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
355 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
356
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
357 qint32 LDObject::id() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
358 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
359 return m_id;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
360 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
361
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
362 LDColor LDObject::color() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
363 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
364 return m_color;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
365 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
366
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
367 QColor LDObject::randomColor() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
368 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
369 return m_randomColor;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
370 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
371
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
372 Model* LDObject::model() const
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
373 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
374 return _model;
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
375 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
376
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 void LDObject::invert() {}
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
380 void LDBfc::invert() {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 void LDError::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 //
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1008
diff changeset
385 void LDSubfileReference::invert()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
387 if (model() == nullptr)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
388 return;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
389
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
390 // Check whether subfile is flat
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
391 int axisSet = (1 << X) | (1 << Y) | (1 << Z);
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: 1078
diff changeset
392 Model model {this->model()->documentManager()};
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
393 fileInfo()->inlineContents(model, true, false);
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
394
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
395 for (LDObject* obj : model.objects())
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
396 {
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
397 for (int i = 0; i < obj->numVertices(); ++i)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
398 {
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
399 Vertex const& vrt = obj->vertex (i);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
400
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 835
diff changeset
401 if (axisSet & (1 << X) and vrt.x() != 0.0)
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
402 axisSet &= ~(1 << X);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
403
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 835
diff changeset
404 if (axisSet & (1 << Y) and vrt.y() != 0.0)
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
405 axisSet &= ~(1 << Y);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
406
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 835
diff changeset
407 if (axisSet & (1 << Z) and vrt.z() != 0.0)
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
408 axisSet &= ~(1 << Z);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
409 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
411 if (axisSet == 0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
412 break;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
413 }
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
414
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
415 if (axisSet != 0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
416 {
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
417 // Subfile has all vertices zero on one specific plane, so it is flat.
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
418 // Let's flip it.
1070
292c64cb2a75 Moved the identity matrix constant into Matrix's namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1068
diff changeset
419 Matrix matrixModifier = Matrix::identity;
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
420
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
421 if (axisSet & (1 << X))
1068
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
422 matrixModifier(0, 0) = -1;
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
423
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
424 if (axisSet & (1 << Y))
1068
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
425 matrixModifier(1, 1) = -1;
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
426
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
427 if (axisSet & (1 << Z))
1068
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
428 matrixModifier(2, 2) = -1;
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
429
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
430 setTransformationMatrix (transformationMatrix() * matrixModifier);
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
431 return;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
432 }
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
433
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
434 // Subfile is not flat. Resort to invertnext.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 int idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 if (idx > 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 {
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
439 LDBfc* bfc = dynamic_cast<LDBfc*> (previous());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
441 if (bfc and bfc->statement() == BfcStatement::InvertNext)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 // This is prefixed with an invertnext, thus remove it.
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
444 this->model()->remove(bfc);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 // Not inverted, thus prefix it with a new invertnext.
1081
47cde4087cc5 Made all LDObject constructors protected. Emplacement is now the only way to create objects.
Teemu Piippo <teemu@hecknology.net>
parents: 1080
diff changeset
450 this->model()->emplaceAt<LDBfc>(idx, BfcStatement::InvertNext);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 //
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: 998
diff changeset
455 void LDBezierCurve::invert()
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: 998
diff changeset
456 {
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: 998
diff changeset
457 // A Bézier curve's control points probably need to be, though.
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: 998
diff changeset
458 Vertex tmp = vertex (1);
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: 998
diff changeset
459 setVertex (1, vertex (0));
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: 998
diff changeset
460 setVertex (0, tmp);
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: 998
diff changeset
461 tmp = vertex (3);
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: 998
diff changeset
462 setVertex (3, vertex (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: 998
diff changeset
463 setVertex (2, tmp);
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: 998
diff changeset
464 }
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: 998
diff changeset
465
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: 998
diff changeset
466 // =============================================================================
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: 998
diff changeset
467 //
1135
8e0691be0b6f Removed the intXX type aliases and removed uses of intXX_t in favor of qintXX
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
468 LDObject* LDObject::fromID(qint32 id)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
470 return g_allObjects.value(id);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
475 void LDObject::setColor (LDColor color)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 {
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
477 changeProperty(&m_color, color);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
482 // Get a vertex by index
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
483 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
484 const Vertex& LDObject::vertex (int i) const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 {
805
d88c0354de97 - refactor. got rid of the LDSharedVertex nonsense, fixed up split lines action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
486 return m_coords[i];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 //
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
491 // Set a vertex to the given value
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
492 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 void LDObject::setVertex (int i, const Vertex& vert)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 {
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
495 changeProperty(&m_coords[i], vert);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
498 LDMatrixObject::LDMatrixObject (Model* model) :
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
499 LDObject (model),
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
500 m_position (Origin) {}
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
501
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
502 LDMatrixObject::LDMatrixObject (const Matrix& transform, const Vertex& pos, Model* model) :
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
503 LDObject (model),
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
504 m_position (pos),
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
505 m_transformationMatrix (transform) {}
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
506
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
507 void LDMatrixObject::setCoordinate (const Axis ax, double value)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
508 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
509 Vertex v = position();
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
510
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
511 switch (ax)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
512 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
513 case X: v.setX (value); break;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
514 case Y: v.setY (value); break;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
515 case Z: v.setZ (value); break;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
516 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
517
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
518 setPosition (v);
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
519 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
520
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
521 const Vertex& LDMatrixObject::position() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
522 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
523 return m_position;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
524 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
525
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528 void LDMatrixObject::setPosition (const Vertex& a)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529 {
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
530 changeProperty(&m_position, a);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
533 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534 //
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
535 const Matrix& LDMatrixObject::transformationMatrix() const
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
536 {
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
537 return m_transformationMatrix;
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
538 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
539
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
540 void LDMatrixObject::setTransformationMatrix (const Matrix& val)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 {
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
542 changeProperty(&m_transformationMatrix, val);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
545 LDError::LDError (QString contents, QString reason, Model* model) :
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
546 LDObject (model),
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
547 m_contents (contents),
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
548 m_reason (reason) {}
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
549
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
550 QString LDError::reason() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
551 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
552 return m_reason;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
553 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
554
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
555 QString LDError::contents() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
556 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
557 return m_contents;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
558 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
559
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
560 QString LDError::fileReferenced() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
561 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
562 return m_fileReferenced;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
563 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
564
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
565 void LDError::setFileReferenced (QString value)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
566 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
567 m_fileReferenced = value;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
568 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
569
1078
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
570 LDBfc::LDBfc (const BfcStatement type, Model* model) :
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
571 LDObject {model},
c72e3115a297 Removed uses of LDSpawn in the algorithm toolset
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
572 m_statement {type} {}
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
573
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
574 BfcStatement LDBfc::statement() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
575 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
576 return m_statement;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
577 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
578
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
579 void LDBfc::setStatement (BfcStatement value)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
580 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
581 m_statement = value;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
582 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
583
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
584 QString LDBfc::statementToString() const
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
585 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
586 return LDBfc::statementToString (statement());
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
587 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
588
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
589 QString LDBfc::statementToString (BfcStatement statement)
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
590 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
591 static const char* statementStrings[] =
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
592 {
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
593 "CERTIFY CCW",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
594 "CCW",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
595 "CERTIFY CW",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
596 "CW",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
597 "NOCERTIFY",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
598 "INVERTNEXT",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
599 "CLIP",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
600 "CLIP CCW",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
601 "CLIP CW",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
602 "NOCLIP",
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
603 };
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
604
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
605 if ((int) statement >= 0 and (int) statement < countof (statementStrings))
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
606 return QString::fromLatin1 (statementStrings[(int) statement]);
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
607 else
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
608 return "";
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
609 }
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
610
1002
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
611 Vertex LDBezierCurve::pointAt (qreal t) const
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
612 {
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
613 if (t >= 0.0 and t <= 1.0)
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
614 {
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
615 Vertex result;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
616 result += pow (1.0 - t, 3) * vertex (0);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
617 result += (3 * pow (1.0 - t, 2) * t) * vertex (2);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
618 result += (3 * (1.0 - t) * pow (t, 2)) * vertex (3);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
619 result += pow (t, 3) * vertex (1);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
620 return result;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
621 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
622 else
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
623 return Vertex();
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
624 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
625
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
626 void LDBezierCurve::rasterize(Model& model, int segments)
1002
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
627 {
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
628 QVector<LDPolygon> polygons = rasterizePolygons(segments);
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
629
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
630 for (LDPolygon& poly : polygons)
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
631 {
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
632 LDEdgeLine* line = model.emplace<LDEdgeLine>(poly.vertices[0], poly.vertices[1]);
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
633 line->setColor (poly.color);
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
634 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
635 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
636
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
637 QVector<LDPolygon> LDBezierCurve::rasterizePolygons(int segments)
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
638 {
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
639 QVector<LDPolygon> result;
1002
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
640 QVector<Vertex> parms;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
641 parms.append (pointAt (0.0));
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
642
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
643 for (int i = 1; i < segments; ++i)
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
644 parms.append (pointAt (double (i) / segments));
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
645
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
646 parms.append (pointAt (1.0));
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
647 LDPolygon poly;
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
648 poly.color = color().index();
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
649 poly.id = id();
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
650 poly.num = 2;
1002
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
651
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
652 for (int i = 0; i < segments; ++i)
1003
31873c3cbdbc Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
653 {
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
654 poly.vertices[0] = parms[i];
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
655 poly.vertices[1] = parms[i + 1];
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1003
diff changeset
656 result << poly;
1003
31873c3cbdbc Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
657 }
1002
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
658
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
659 return result;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
660 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
661
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
662 LDSubfileReference::LDSubfileReference(LDDocument* reference, const Matrix& transformationMatrix,
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
663 const Vertex& position, Model* model) :
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
664 LDMatrixObject {transformationMatrix, position, model},
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
665 m_fileInfo {reference} {}
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
666
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
667 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
668 //
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1008
diff changeset
669 LDDocument* LDSubfileReference::fileInfo() const
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
670 {
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
671 return m_fileInfo;
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
672 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
673
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
674 void LDSubfileReference::setFileInfo (LDDocument* newReferee)
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
675 {
1117
efcb47c64a72 Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
676 changeProperty(&m_fileInfo, newReferee);
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
677
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
678 if (model())
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
679 model()->recountTriangles();
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
680
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
681 // If it's an immediate subfile reference (i.e. this subfile is in an opened document), we need to pre-compile the
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
682 // GL polygons for the document if they don't exist already.
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
683 if (newReferee and
1090
ed73c4f48ca4 The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
684 newReferee->isFrozen() == false and
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
685 newReferee->polygonData().isEmpty())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
686 {
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
687 newReferee->initializeCachedData();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
688 }
1084
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
689 }
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
690
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1028
diff changeset
691 void LDObject::getVertices (QSet<Vertex>& verts) const
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
692 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
693 for (int i = 0; i < numVertices(); ++i)
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1028
diff changeset
694 verts.insert(vertex(i));
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
695 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
696
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1028
diff changeset
697 void LDSubfileReference::getVertices (QSet<Vertex>& verts) const
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
698 {
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1028
diff changeset
699 verts.unite(fileInfo()->inlineVertices());
1045
f726f8f49c7e Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
700 }
1084
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
701
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
702 QString LDObject::objectListText() const
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
703 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
704 if (numVertices() > 0)
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
705 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
706 QString result;
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
707
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
708 for (int i = 0; i < numVertices(); ++i)
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
709 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
710 if (i != 0)
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
711 result += ", ";
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
712
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
713 result += vertex(i).toString (true);
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
714 }
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
715
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
716 return result;
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
717 }
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
718 else
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
719 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
720 return typeName();
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
721 }
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
722 }
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
723
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
724 QString LDError::objectListText() const
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
725 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
726 return "ERROR: " + asText();
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
727 }
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
728
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
729 QString LDSubfileReference::objectListText() const
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
730 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
731 QString result = format ("%1 %2, (", fileInfo()->getDisplayName(), position().toString(true));
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
732
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
733 for (int i = 0; i < 9; ++i)
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
734 result += format("%1%2", transformationMatrix().value(i), (i != 8) ? " " : "");
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
735
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
736 result += ')';
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
737 return result;
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
738 }
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
739
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
740 QString LDBfc::objectListText() const
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
741 {
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
742 return statementToString();
63daaf652454 Split object list representation into virtual methods
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
743 }

mercurial