src/linetypes/polygonobject.h

Sat, 24 Jul 2021 01:50:38 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Jul 2021 01:50:38 +0300
changeset 107
02f142b399b1
parent 93
6fe24fd945c0
child 132
488d0ba6070b
permissions
-rw-r--r--

Move selection logic into select tool

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"
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 #include "modeleditcontext.h"
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 }
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 std::array<glm::vec3, N> points;
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 };

mercurial