Wed, 18 Mar 2020 15:54:30 +0200
fix
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 | }; | |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
84 | class BadPointIndex : public std::exception |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
85 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
86 | }; |
13 | 87 | Object(); |
88 | Object(const Object&) = delete; | |
89 | virtual ~Object(); | |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
90 | const id_t id; |
3 | 91 | //virtual void toString(QTextStream &out) = 0; |
92 | virtual bool hasColor() const; | |
93 | virtual QVariant getProperty(Property id) const; | |
94 | virtual SetPropertyResult setProperty(Property id, const QVariant& value); | |
6 | 95 | virtual QString textRepresentation() const = 0; |
96 | virtual QBrush textRepresentationForeground() const; | |
97 | virtual QBrush textRepresentationBackground() const; | |
98 | virtual QFont textRepresentationFont() const; | |
21 | 99 | virtual void getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const; |
26 | 100 | virtual void invert() {} |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
101 | virtual int numPoints() const { return 0; } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
102 | virtual const glm::vec3& getPoint(int index) const; |
3 | 103 | }; |
104 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
105 | class ldraw::ColoredObject : public Object |
3 | 106 | { |
107 | 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
|
108 | ColoredObject(const Color colorIndex = ldraw::mainColor); |
3 | 109 | bool hasColor() const override final; |
110 | QVariant getProperty(Property id) const override; | |
111 | 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
|
112 | Color colorIndex = ldraw::mainColor; |
3 | 113 | }; |
6 | 114 | |
13 | 115 | /** |
116 | * @brief Represents an empty line. | |
117 | */ | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
118 | class ldraw::Empty : public Object |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
119 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
120 | QString textRepresentation() const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
121 | }; |