src/linetypes/polygonobject.h

changeset 89
7abaf1d64719
child 93
6fe24fd945c0
equal deleted inserted replaced
88:14e51640c189 89:7abaf1d64719
1 #pragma once
2 #include "object.h"
3 #include "widgets/vec3editor.h"
4 #include "model.h"
5 #include "modeleditcontext.h"
6
7 namespace ldraw
8 {
9 template<int N, typename>
10 class PolygonObject;
11 }
12
13 template<int N, typename = std::enable_if_t<(N > 0 and N <= 4)>>
14 class ldraw::PolygonObject : public ColoredObject
15 {
16 public:
17 using BaseClass = ColoredObject;
18 PolygonObject(const std::array<glm::vec3, N>& points, const Color color) :
19 ColoredObject{color},
20 points{points} {}
21 int numPoints() const override
22 {
23 return N;
24 }
25 const glm::vec3& getPoint(int index) const override
26 {
27 Q_ASSERT(index >= 0 and index < N);
28 return this->points[index];
29 }
30 QVariant getProperty(const Property id) const override
31 {
32 switch (id)
33 {
34 case Property::Point0:
35 return QVariant::fromValue(points[0]);
36 case Property::Point1:
37 return QVariant::fromValue(points[1]);
38 case Property::Point2:
39 if (N >= 3)
40 {
41 return QVariant::fromValue(points[2]);
42 }
43 break;
44 case Property::Point3:
45 if (N >= 4)
46 {
47 return QVariant::fromValue(points[3]);
48 }
49 break;
50 default:
51 break;
52 }
53 return BaseClass::getProperty(id);
54 }
55 void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
56 {
57 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point0, {points[0] = value;})
58 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point1, {points[1] = value;})
59 if constexpr (N >= 3)
60 {
61 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point2, {points[2] = value;})
62 }
63 if constexpr (N >= 4)
64 {
65 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point3, {points[3] = value;})
66 }
67 ColoredObject::setProperty(result, pair);
68 }
69 std::array<glm::vec3, N> points;
70 };

mercurial