src/linetypes/polygonobject.h

Sat, 05 Mar 2022 13:59:54 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Mar 2022 13:59:54 +0200
changeset 166
8857351912d0
parent 153
2f79053c2e9a
permissions
-rw-r--r--

Fix rendering of cursor coordinates on bright background

89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "object.h"
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "widgets/vec3editor.h"
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "model.h"
153
2f79053c2e9a Renamed modeleditcontext.cpp -> modeleditor.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
5 #include "modeleditor.h"
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 namespace ldraw
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 template<int N, typename>
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 class PolygonObject;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 template<int N, typename = std::enable_if_t<(N > 0 and N <= 4)>>
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 class ldraw::PolygonObject : public ColoredObject
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 public:
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 using BaseClass = ColoredObject;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 PolygonObject(const std::array<glm::vec3, N>& points, const Color color) :
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 ColoredObject{color},
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 points{points} {}
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 int numPoints() const override
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 return N;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 const glm::vec3& getPoint(int index) const override
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 Q_ASSERT(index >= 0 and index < N);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 return this->points[index];
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 QVariant getProperty(const Property id) const override
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 switch (id)
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 case Property::Point0:
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 return QVariant::fromValue(points[0]);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 case Property::Point1:
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 return QVariant::fromValue(points[1]);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 case Property::Point2:
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 if (N >= 3)
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 return QVariant::fromValue(points[2]);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 break;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 case Property::Point3:
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 if (N >= 4)
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 return QVariant::fromValue(points[3]);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 break;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 default:
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 break;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 return BaseClass::getProperty(id);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 }
93
6fe24fd945c0 fix warnings
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
55 void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) override
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point0, {points[0] = value;})
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point1, {points[1] = value;})
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 if constexpr (N >= 3)
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point2, {points[2] = value;})
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 if constexpr (N >= 4)
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 {
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point3, {points[3] = value;})
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 ColoredObject::setProperty(result, pair);
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 }
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
69 QDataStream &serialize(QDataStream& stream) const override
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
70 {
134
f77d2230e87c Add remaining serialize methods
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
71 ColoredObject::serialize(stream);
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
72 for (const glm::vec3& point : this->points)
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
73 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
74 stream << point;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
75 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
76 return stream;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
77 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
78 QDataStream& deserialize(QDataStream& stream) override
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
79 {
134
f77d2230e87c Add remaining serialize methods
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
80 ColoredObject::deserialize(stream);
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
81 for (glm::vec3& point : this->points)
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
82 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
83 stream >> point;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
84 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
85 return stream;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 93
diff changeset
86 }
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 std::array<glm::vec3, N> points;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 };

mercurial