src/linetypes/object.h

Mon, 24 Aug 2020 22:51:01 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 24 Aug 2020 22:51:01 +0300
changeset 90
e234edb5e613
parent 77
028798a72591
child 81
62373840e33a
permissions
-rw-r--r--

remove dependency on glut, fixes

3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include <QPointF>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include <QString>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include <QStringView>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 #include "main.h"
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 #include "colors.h"
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
7 #include "gl/common.h"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
11 struct GetPolygonsContext;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 enum class Property;
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
13 class Object;
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
19 class DocumentManager;
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
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
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
22 {
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
23 ::DocumentManager* documents;
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
24 };
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
25
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
26 /**
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
27 * @brief Different properties that can be queried with getProperty
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 {
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
31 Color, // Color of the object
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
32 Text, // Text contained in a comment
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
33 Point1, // First vertex in a polygon or edge line
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
34 Point2, // Second vertex in a polygon or edge line
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
35 Point3, // Third vertex in a polygon
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
36 Point4, // Fourth vertex in a quadrilateral
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
37 ControlPoint1, // First control point in a conditional edge line
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
38 ControlPoint2, // Second control point in a conditional edge line
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
39 Transformation, // 4x4 transformation matrix of a subfile reference
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
40 ReferenceName, // Subfile reference name
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
41 IsInverted, // Whether or not the object has been inverted with BFC INVERTNEXT
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
42 ErrorMessage // For error lines, why parsing failed
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 public:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 enum class SetPropertyResult
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 Success = 0,
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 PropertyNotHandled,
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 InvalidValue
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 };
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
84 Object();
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
85 Object(const Object&) = delete;
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 //virtual void toString(QTextStream &out) = 0;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 virtual bool hasColor() const;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 virtual QVariant getProperty(Property id) const;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 virtual SetPropertyResult setProperty(Property id, const QVariant& value);
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
92 virtual QString textRepresentation() const = 0;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
93 virtual QBrush textRepresentationForeground() const;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
94 virtual QBrush textRepresentationBackground() const;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
95 virtual QFont textRepresentationFont() const;
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
96 virtual void getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const;
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
97 virtual void invert() {}
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 bool hasColor() const override final;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 QVariant getProperty(Property id) const override;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108 };
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
109
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
110 /**
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
111 * @brief Represents an empty line.
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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 };

mercurial