src/linetypes/object.h

Tue, 28 Sep 2021 22:17:52 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 28 Sep 2021 22:17:52 +0300
changeset 144
5d73a6717321
parent 141
185eb297dc1e
child 148
e1ced2523cad
permissions
-rw-r--r--

Fix handling of "BFC INVERTNEXT" with multiple inner whitespaces

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"
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 87
diff changeset
8 #include "linetypes/propertygenerics.h"
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 87
diff changeset
9
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 87
diff changeset
10 class Model;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
12 namespace ldraw
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
14 struct GetPolygonsContext;
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
15 class Object;
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
16 class ColoredObject;
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
17 class Empty;
77
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
18 class UnhandledProperty;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
21 class DocumentManager;
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
22
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
23 struct ldraw::GetPolygonsContext
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
24 {
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
25 ::DocumentManager* documents;
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
26 };
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
27
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
28 class ldraw::Object
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 public:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 enum class SetPropertyResult
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 Success = 0,
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
34 PropertyNotHandled
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 };
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
36 /**
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
37 * @brief Enumerates different object types
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
38 */
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
39 enum class Type
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
40 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
41 Empty,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
42 Comment,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
43 MetaCommand,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
44 ErrorLine,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
45 SubfileReference,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
46 EdgeLine,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
47 ConditionalEdge,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
48 Triangle,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
49 Quadrilateral,
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
50 };
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
51 friend bool handled(SetPropertyResult result)
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
52 {
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
53 return result == SetPropertyResult::Success;
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
54 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
55 class BadPointIndex : public std::exception
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
56 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
57 };
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
58 Object();
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
59 Object(const Object&) = delete;
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
60 virtual ~Object();
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
61 const id_t id;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 virtual bool hasColor() const;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 virtual QVariant getProperty(Property id) const;
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
64 template<ldraw::Property property>
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
65 PropertyType<property> getProperty() const;
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
66 template<ldraw::Property property>
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 87
diff changeset
67 SetPropertyResult setProperty(const PropertyType<property>& value);
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
68 SetPropertyResult setProperty(const PropertyKeyValue& pair);
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
69 virtual QString textRepresentation() const = 0;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
70 virtual QBrush textRepresentationForeground() const;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
71 virtual QBrush textRepresentationBackground() const;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
72 virtual QFont textRepresentationFont() const;
21
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
73 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
74 virtual void invert() {}
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
75 virtual int numPoints() const { return 0; }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
76 virtual const glm::vec3& getPoint(int index) const;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
77 virtual QDataStream& serialize(QDataStream& stream) const;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
78 virtual QDataStream& deserialize(QDataStream& stream);
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
79 virtual Type typeIdentifier() const = 0;
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
80 virtual QString toLDrawCode() const = 0;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
81
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
82 protected:
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
83 template<Property property, typename Function>
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
84 void handle(SetPropertyResult* result, const PropertyKeyValue& pair, Function function);
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
85 virtual void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
88 template<ldraw::Property property>
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 87
diff changeset
89 ldraw::Object::SetPropertyResult ldraw::Object::setProperty(const ldraw::PropertyType<property>& value)
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
90 {
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
91 SetPropertyResult result = SetPropertyResult::PropertyNotHandled;
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
92 this->setProperty(&result, PropertyKeyValue{property, QVariant::fromValue(value)});
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
93 return result;
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
94 }
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
95
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
96 template<ldraw::Property property, typename Function>
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
97 void ldraw::Object::handle(SetPropertyResult* result, const PropertyKeyValue& pair, Function function)
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
98 {
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
99 if (pair.key == property)
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
100 {
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 87
diff changeset
101 function(pair.value.value<ldraw::PropertyType<property>>());
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
102 *result = SetPropertyResult::Success;
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
103 }
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
104 }
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
105
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
106 template<ldraw::Property property>
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
107 ldraw::PropertyType<property> ldraw::Object::getProperty() const
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
108 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
109 return this->getProperty(property).value<ldraw::PropertyType<property>>();
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
110 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
111
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 class ldraw::ColoredObject : public Object
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114 public:
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
115 ColoredObject(const Color colorIndex = ldraw::MAIN_COLOR);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 bool hasColor() const override final;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 QVariant getProperty(Property id) const override;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
118 QDataStream &serialize(QDataStream& stream) const override;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
119 QDataStream& deserialize(QDataStream& stream) override;
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
120 Color colorIndex = ldraw::MAIN_COLOR;
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
121 protected:
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
122 void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) override;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123 };
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
124
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
125 /**
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
126 * @brief Represents an empty line.
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
127 */
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
128 class ldraw::Empty : public Object
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
129 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
130 QString textRepresentation() const override;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
131 Type typeIdentifier() const override;
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
132 QString toLDrawCode() const override;
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
133 };

mercurial