Wed, 25 May 2022 17:42:02 +0300
Simplify PolygonCache
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" |
89 | 8 | #include "linetypes/propertygenerics.h" |
9 | ||
10 | class Model; | |
3 | 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 | 13 | { |
21 | 14 | struct GetPolygonsContext; |
13 | 15 | class Object; |
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 | 19 | } |
20 | ||
21 | 21 | class DocumentManager; |
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 | 24 | { |
148 | 25 | ::ModelId modelId; |
21 | 26 | ::DocumentManager* documents; |
27 | }; | |
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 | class ldraw::Object |
3 | 30 | { |
31 | public: | |
32 | enum class SetPropertyResult | |
33 | { | |
34 | Success = 0, | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
35 | PropertyNotHandled |
3 | 36 | }; |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
37 | /** |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
38 | * @brief Enumerates different object types |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
39 | */ |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
40 | enum class Type |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
41 | { |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
42 | Empty, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
43 | Comment, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
44 | MetaCommand, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
45 | ErrorLine, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
46 | SubfileReference, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
47 | EdgeLine, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
48 | ConditionalEdge, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
49 | Triangle, |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
50 | Quadrilateral, |
186 | 51 | CircularPrimitive, |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
52 | }; |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
53 | friend bool handled(SetPropertyResult result) |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
54 | { |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
55 | return result == SetPropertyResult::Success; |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
56 | } |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
57 | class BadPointIndex : public std::exception |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
58 | { |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
59 | }; |
13 | 60 | Object(); |
61 | Object(const Object&) = delete; | |
62 | virtual ~Object(); | |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
63 | const id_t id; |
3 | 64 | virtual bool hasColor() const; |
65 | virtual QVariant getProperty(Property id) const; | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
66 | template<ldraw::Property property> |
141 | 67 | PropertyType<property> getProperty() const; |
68 | template<ldraw::Property property> | |
89 | 69 | SetPropertyResult setProperty(const PropertyType<property>& value); |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
70 | SetPropertyResult setProperty(const PropertyKeyValue& pair); |
6 | 71 | virtual QString textRepresentation() const = 0; |
72 | virtual QBrush textRepresentationForeground() const; | |
73 | virtual QBrush textRepresentationBackground() const; | |
74 | virtual QFont textRepresentationFont() const; | |
21 | 75 | virtual void getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const; |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
177
diff
changeset
|
76 | virtual void invert(GetPolygonsContext*) {} |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
77 | virtual int numPoints() const { return 0; } |
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
78 | virtual const glm::vec3& getPoint(int index) const; |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
79 | virtual QDataStream& serialize(QDataStream& stream) const; |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
80 | virtual QDataStream& deserialize(QDataStream& stream); |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
81 | virtual Type typeIdentifier() const = 0; |
141 | 82 | virtual QString toLDrawCode() const = 0; |
158
5bd755eaa5a8
Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents:
150
diff
changeset
|
83 | virtual QString iconName() const; |
177
f69d53c053df
Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents:
158
diff
changeset
|
84 | virtual QString typeName() const = 0; |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
85 | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
86 | protected: |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
87 | template<Property property, typename Function> |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
88 | 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
|
89 | virtual void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair); |
3 | 90 | }; |
91 | ||
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
92 | /** |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
93 | * @brief Tests whether the object is exactly of the specified type |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
94 | * @tparam R Type of LDraw line type object to test for |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
95 | * @param object Object to test |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
96 | * @returns whether the type of the object specified by @c id is the same type as R. Returns false if it is a subclass. |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
97 | */ |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
98 | template<typename R> |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
99 | bool isA(const ldraw::Object* object) |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
100 | { |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
101 | const std::type_info& a = typeid(*object); |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
102 | const std::type_info& b = typeid(R); |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
103 | return a == b; |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
104 | } |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
105 | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
106 | template<ldraw::Property property> |
89 | 107 | 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
|
108 | { |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
109 | SetPropertyResult result = SetPropertyResult::PropertyNotHandled; |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
110 | 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
|
111 | return result; |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
112 | } |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
113 | |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
114 | template<ldraw::Property property, typename Function> |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
115 | 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
|
116 | { |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
117 | if (pair.key == property) |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
118 | { |
89 | 119 | 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
|
120 | *result = SetPropertyResult::Success; |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
121 | } |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
122 | } |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
123 | |
141 | 124 | template<ldraw::Property property> |
125 | ldraw::PropertyType<property> ldraw::Object::getProperty() const | |
126 | { | |
127 | return this->getProperty(property).value<ldraw::PropertyType<property>>(); | |
128 | } | |
129 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
130 | class ldraw::ColoredObject : public Object |
3 | 131 | { |
132 | public: | |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
133 | ColoredObject(const Color colorIndex = ldraw::MAIN_COLOR); |
3 | 134 | bool hasColor() const override final; |
135 | QVariant getProperty(Property id) const override; | |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
136 | QDataStream &serialize(QDataStream& stream) const override; |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
137 | QDataStream& deserialize(QDataStream& stream) override; |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
138 | Color colorIndex = ldraw::MAIN_COLOR; |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
139 | protected: |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
140 | void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) override; |
3 | 141 | }; |
6 | 142 | |
13 | 143 | /** |
144 | * @brief Represents an empty line. | |
145 | */ | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
146 | class ldraw::Empty : public Object |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
147 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
148 | QString textRepresentation() const override; |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
149 | Type typeIdentifier() const override; |
141 | 150 | QString toLDrawCode() const override; |
177
f69d53c053df
Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents:
158
diff
changeset
|
151 | QString typeName() const override; |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
152 | }; |