Wed, 11 Mar 2020 17:19:38 +0200
added a render style for pick scene
3 | 1 | #pragma once |
2 | #include <QPointF> | |
3 | #include <QString> | |
4 | #include <QStringView> | |
5 | #include "main.h" | |
6 | #include "colors.h" | |
21 | 7 | #include "gl/common.h" |
3 | 8 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
9 | namespace ldraw |
3 | 10 | { |
21 | 11 | struct GetPolygonsContext; |
3 | 12 | enum class Property; |
13 | 13 | class Object; |
14 | class ColoredObject; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
15 | class Empty; |
77
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
16 | class UnhandledProperty; |
3 | 17 | } |
18 | ||
21 | 19 | class DocumentManager; |
20 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
21 | struct ldraw::GetPolygonsContext |
21 | 22 | { |
23 | ::DocumentManager* documents; | |
24 | }; | |
25 | ||
13 | 26 | /** |
27 | * @brief Different properties that can be queried with getProperty | |
28 | */ | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
29 | enum class ldraw::Property |
3 | 30 | { |
13 | 31 | Color, // Color of the object |
32 | Text, // Text contained in a comment | |
33 | Point1, // First vertex in a polygon or edge line | |
34 | Point2, // Second vertex in a polygon or edge line | |
35 | Point3, // Third vertex in a polygon | |
36 | Point4, // Fourth vertex in a quadrilateral | |
37 | ControlPoint1, // First control point in a conditional edge line | |
38 | ControlPoint2, // Second control point in a conditional edge line | |
21 | 39 | Transformation, // 4x4 transformation matrix of a subfile reference |
13 | 40 | ReferenceName, // Subfile reference name |
41 | IsInverted, // Whether or not the object has been inverted with BFC INVERTNEXT | |
42 | ErrorMessage // For error lines, why parsing failed | |
3 | 43 | }; |
44 | ||
77
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
45 | // Mapping of properties to types |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
46 | #define LDFORGE_DEFINE_PROPERTY_TYPE(PROPERTY, TYPE) \ |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
47 | namespace ldraw { \ |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
48 | template<> struct PropertyType<ldraw::Property::PROPERTY> { using type = TYPE; }; \ |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
49 | } |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
50 | |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
51 | namespace ldraw |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
52 | { |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
53 | template<ldraw::Property property> |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
54 | struct PropertyType |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
55 | { |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
56 | }; |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
57 | |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
58 | template<ldraw::Property property> |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
59 | using PropertyType_t = typename PropertyType<property>::type; |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
60 | } |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
61 | |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
62 | LDFORGE_DEFINE_PROPERTY_TYPE(Color, int) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
63 | LDFORGE_DEFINE_PROPERTY_TYPE(Text, QString) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
64 | LDFORGE_DEFINE_PROPERTY_TYPE(Point1, glm::vec3) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
65 | LDFORGE_DEFINE_PROPERTY_TYPE(Point2, glm::vec3) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
66 | LDFORGE_DEFINE_PROPERTY_TYPE(Point3, glm::vec3) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
67 | LDFORGE_DEFINE_PROPERTY_TYPE(Point4, glm::vec3) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
68 | LDFORGE_DEFINE_PROPERTY_TYPE(ControlPoint1, glm::vec3) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
69 | LDFORGE_DEFINE_PROPERTY_TYPE(ControlPoint2, glm::vec3) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
70 | LDFORGE_DEFINE_PROPERTY_TYPE(Transformation, glm::mat4) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
71 | LDFORGE_DEFINE_PROPERTY_TYPE(ReferenceName, QString) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
72 | LDFORGE_DEFINE_PROPERTY_TYPE(IsInverted, bool) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
73 | LDFORGE_DEFINE_PROPERTY_TYPE(ErrorMessage, QString) |
028798a72591
added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
74 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
75 | class ldraw::Object |
3 | 76 | { |
77 | public: | |
78 | enum class SetPropertyResult | |
79 | { | |
80 | Success = 0, | |
81 | PropertyNotHandled, | |
82 | InvalidValue | |
83 | }; | |
13 | 84 | Object(); |
85 | Object(const Object&) = delete; | |
86 | virtual ~Object(); | |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
87 | const id_t id; |
3 | 88 | //virtual void toString(QTextStream &out) = 0; |
89 | virtual bool hasColor() const; | |
90 | virtual QVariant getProperty(Property id) const; | |
91 | virtual SetPropertyResult setProperty(Property id, const QVariant& value); | |
6 | 92 | virtual QString textRepresentation() const = 0; |
93 | virtual QBrush textRepresentationForeground() const; | |
94 | virtual QBrush textRepresentationBackground() const; | |
95 | virtual QFont textRepresentationFont() const; | |
21 | 96 | virtual void getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const; |
26 | 97 | virtual void invert() {} |
3 | 98 | }; |
99 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
100 | class ldraw::ColoredObject : public Object |
3 | 101 | { |
102 | public: | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
103 | ColoredObject(const Color colorIndex = ldraw::mainColor); |
3 | 104 | bool hasColor() const override final; |
105 | QVariant getProperty(Property id) const override; | |
106 | SetPropertyResult setProperty(Property id, const QVariant& value) override; | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
107 | Color colorIndex = ldraw::mainColor; |
3 | 108 | }; |
6 | 109 | |
13 | 110 | /** |
111 | * @brief Represents an empty line. | |
112 | */ | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
113 | class ldraw::Empty : public Object |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
114 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
115 | QString textRepresentation() const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
116 | }; |