src/linetypes/object.cpp

Fri, 04 Mar 2022 23:41:58 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 04 Mar 2022 23:41:58 +0200
changeset 155
13713fadbf14
parent 153
2f79053c2e9a
child 158
5bd755eaa5a8
permissions
-rw-r--r--

improve rendering of the grid

6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
1 #include <QBrush>
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
2 #include <QFont>
14
20d2ed3af73d renamings
Teemu Piippo <teemu@hecknology.net>
parents: 13
diff changeset
3 #include "object.h"
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
4 #include "widgets/vec3editor.h"
153
2f79053c2e9a Renamed modeleditcontext.cpp -> modeleditor.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 141
diff changeset
5 #include "modeleditor.h"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6
46
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
7 static std::int32_t getIdForNewObject()
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
8 {
46
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
9 static std::int32_t id = 0;
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
10 id += 1;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
11 return id;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
12 }
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
14 ldraw::Object::Object() :
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
15 id {getIdForNewObject()}
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
19 ldraw::Object::~Object()
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
23 bool ldraw::Object::hasColor() const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 return false;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
28 QVariant ldraw::Object::getProperty(Property id) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 Q_UNUSED(id);
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 return {};
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
34 void ldraw::Object::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 {
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
36 Q_UNUSED(result)
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
37 Q_UNUSED(pair)
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
38 }
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
39
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
40 /**
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
41 * @brief public interface to setProperty
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
42 */
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
43 ldraw::Object::SetPropertyResult ldraw::Object::setProperty(const PropertyKeyValue& pair)
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
44 {
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
45 SetPropertyResult result;
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
46 this->setProperty(&result, pair);
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
47 return result;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
50 QBrush ldraw::Object::textRepresentationForeground() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
51 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
52 return {};
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
53 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
54
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
55 QBrush ldraw::Object::textRepresentationBackground() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
56 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
57 return {};
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
58 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
59
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
60 QFont ldraw::Object::textRepresentationFont() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
61 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
62 return {};
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
63 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
64
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
65 void ldraw::Object::getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
66 {
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
67 Q_UNUSED(polygons)
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
68 Q_UNUSED(context)
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
69 }
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
70
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
71 const glm::vec3& ldraw::Object::getPoint(int index) const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
72 {
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
73 Q_UNUSED(index);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
74 throw BadPointIndex{};
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
75 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
76
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
77 /**
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
78 * @brief Serializes the object into a stream of bytes for internal storage.
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
79 * @param stream Data stream to serialize into
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
80 */
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
81 QDataStream& ldraw::Object::serialize(QDataStream &stream) const
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
82 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
83 return stream << static_cast<int>(this->typeIdentifier());
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
84 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
85
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
86 /**
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
87 * @brief Deserializes the object from a stream of bytes coming from internal storage.
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
88 * @param stream Data stream to serialize from.
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
89 * @note @c ldraw::Object::serialize will insert a type enumerator. Before calling this function,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
90 * this enumerator is assumed to have been handled as the object class needs to be initialized based
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
91 * on the value of this enumerator.
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
92 */
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
93 QDataStream& ldraw::Object::deserialize(QDataStream &stream)
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
94 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
95 return stream;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
96 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
97
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
98 ldraw::ColoredObject::ColoredObject(const Color color_index) :
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
99 colorIndex{color_index}
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
103 bool ldraw::ColoredObject::hasColor() const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 return true;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
108 QVariant ldraw::ColoredObject::getProperty(Property id) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
110 switch (id)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 case Property::Color:
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
113 return QVariant::fromValue<Color>(colorIndex);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114 default:
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
115 return Object::getProperty(id);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
119 void ldraw::ColoredObject::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 {
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
121 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Color, {colorIndex = value;});
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
122 Object::setProperty(result, pair);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123 }
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
124
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
125 /**
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
126 * @brief @overload @c ldraw::Object::serialize
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
127 * @param stream
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
128 * @return stream
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
129 */
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
130 QDataStream& ldraw::ColoredObject::serialize(QDataStream& stream) const
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
131 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
132 return Object::serialize(stream) << this->colorIndex;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
133 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
134
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
135 /**
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
136 * @brief @overload @c ldraw::Object::deserialize
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
137 * @param stream
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
138 * @return stream
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
139 */
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
140 QDataStream& ldraw::ColoredObject::deserialize(QDataStream& stream)
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
141 {
134
f77d2230e87c Add remaining serialize methods
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
142 return Object::deserialize(stream) >> this->colorIndex;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
143 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
144
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
145 QString ldraw::Empty::textRepresentation() const
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
146 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
147 return "";
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
148 }
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
149
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
150 ldraw::Object::Type ldraw::Empty::typeIdentifier() const
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
151 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
152 return Type::Empty;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
153 }
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
154
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
155 QString ldraw::Empty::toLDrawCode() const
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
156 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
157 return "";
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
158 }

mercurial