src/linetypes/subfilereference.cpp

Wed, 25 May 2022 18:33:38 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 25 May 2022 18:33:38 +0300
changeset 198
eb9d900dc79a
parent 193
b4beff48bb7a
permissions
-rw-r--r--

fix up things and remove unnecessary code

3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "subfilereference.h"
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
2 #include "documentmanager.h"
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
3 #include "invert.h"
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
4 #include "polygoncache.h"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
6 ldraw::SubfileReference::SubfileReference
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
7 (
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
8 const glm::mat4& transformation,
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
9 const QString& referenceName,
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
10 const Color color
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
11 ) :
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
12 CompoundObject{transformation, color},
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
13 referenceName{referenceName}
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
14 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
15 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
16
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
17 QVariant ldraw::SubfileReference::getProperty(Property property) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 switch (property)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 case Property::ReferenceName:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 return this->referenceName;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 default:
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
24 return CompoundObject::getProperty(property);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
27
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
28 void ldraw::SubfileReference::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
29 {
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
30 LDRAW_OBJECT_HANDLE_SET_PROPERTY(ReferenceName, {this->referenceName = value;});
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
31 ldraw::CompoundObject::setProperty(result, pair);
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
32 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
33
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
34 QString ldraw::SubfileReference::textRepresentation() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
35 {
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
36 return this->referenceName + " " + utility::vertexToStringParens(this->position());
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
37 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
38
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
39 void ldraw::SubfileReference::getPolygons
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
40 (
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
41 std::vector<gl::Polygon>& polygons,
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
42 GetPolygonsContext* context
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
43 ) const
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
44 {
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
45 Model* dependency = this->resolve(context->modelId, context->documents);
193
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
46 PolygonCache* cache = nullptr;
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
47 if (dependency != nullptr)
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
48 {
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
49 const auto dependencyModelId = context->documents->findIdForModel(dependency);
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
50 if (dependencyModelId.has_value())
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
51 {
193
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
52 cache = context->documents->getPolygonCacheForModel(dependencyModelId.value());
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
53 }
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
54 }
193
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
55 if (cache != nullptr)
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
56 {
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
57 const bool needInverting = glm::determinant(this->transformation) < 0;
193
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
58 const std::vector<gl::Polygon> modelPolygons = getCachedPolygons(
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
59 cache,
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
60 dependency,
b4beff48bb7a Simplify PolygonCache
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
61 context->documents);
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
62 polygons.reserve(polygons.size() + modelPolygons.size());
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
63 for (gl::Polygon polygon : modelPolygons)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
64 {
23
3387a84ddaba fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
65 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
66 {
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
67 glm::vec4 vertex {polygon.vertices[i], 1};
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
68 vertex = this->transformation * vertex;
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
69 polygon.vertices[i] = vertex;
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
70 }
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
71 if (needInverting != this->isInverted)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
72 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
73 gl::invert(polygon);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
74 }
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 134
diff changeset
75 if (polygon.color == ldraw::MAIN_COLOR)
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
76 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
77 polygon.color = this->colorIndex;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
78 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
79 polygon.id = this->id;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
80 polygons.push_back(polygon);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
81 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
82 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
83 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
84
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 141
diff changeset
85 Model* ldraw::SubfileReference::resolve(const ModelId callingModelId, DocumentManager* documents) const
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
86 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 141
diff changeset
87 return documents->findDependencyByName(callingModelId, this->referenceName);
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
88 }
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
89
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
90 ldraw::Object::Type ldraw::SubfileReference::typeIdentifier() const
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
91 {
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
92 return Type::SubfileReference;
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
93 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
94
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
95 QDataStream& ldraw::SubfileReference::serialize(QDataStream &stream) const
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
96 {
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
97 return CompoundObject::serialize(stream) << this->referenceName;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
98 }
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
99
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
100 QDataStream& ldraw::SubfileReference::deserialize(QDataStream &stream)
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
101 {
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
102 return CompoundObject::deserialize(stream) >> this->referenceName;
132
488d0ba6070b Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents: 86
diff changeset
103 }
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
104
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
105 QString ldraw::SubfileReference::toLDrawCode() const
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
106 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
107 QString result;
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
108 if (this->isInverted)
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
109 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
110 result += "0 BFC INVERTNEXT\r\n";
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
111 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
112 result += utility::format(
186
922662adb72a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
113 "1 %1 %2 %3",
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
114 this->colorIndex.index,
186
922662adb72a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
115 this->transformToBareString(),
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
116 this->referenceName);
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
117 return result;
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
118 }
158
5bd755eaa5a8 Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
119
5bd755eaa5a8 Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
120 QString ldraw::SubfileReference::iconName() const
5bd755eaa5a8 Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
121 {
5bd755eaa5a8 Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
122 return ":/icons/linetype-subfile.png";
5bd755eaa5a8 Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
123 }
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
124
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
125 QString ldraw::SubfileReference::typeName() const
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
126 {
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
127 return QObject::tr("subfile reference");
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
128 }

mercurial