Sat, 05 Mar 2022 17:18:44 +0200
Added the delete action
3 | 1 | #include "subfilereference.h" |
21 | 2 | #include "documentmanager.h" |
26 | 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 | 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 | ) : |
13 | 12 | ColoredObject{color}, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
13 | transformation{transformation}, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
14 | referenceName{referenceName} |
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 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
17 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
18 | QVariant ldraw::SubfileReference::getProperty(Property property) const |
3 | 19 | { |
20 | switch (property) | |
21 | { | |
22 | case Property::Transformation: | |
23 | return QVariant::fromValue(this->transformation); | |
24 | case Property::ReferenceName: | |
25 | return this->referenceName; | |
26 | default: | |
13 | 27 | return ColoredObject::getProperty(property); |
3 | 28 | } |
29 | } | |
6 | 30 | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
31 | 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
|
32 | { |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
33 | LDRAW_OBJECT_HANDLE_SET_PROPERTY(Transformation, {this->transformation = value;}); |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
34 | LDRAW_OBJECT_HANDLE_SET_PROPERTY(ReferenceName, {this->referenceName = value;}); |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
35 | ldraw::ColoredObject::setProperty(result, pair); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
36 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
37 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
38 | QString ldraw::SubfileReference::textRepresentation() const |
6 | 39 | { |
141 | 40 | return this->referenceName + " " + utility::vertexToStringParens(this->position()); |
6 | 41 | } |
21 | 42 | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
43 | void ldraw::SubfileReference::getPolygons |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
44 | ( |
21 | 45 | std::vector<gl::Polygon>& polygons, |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
46 | GetPolygonsContext* context |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
47 | ) const |
21 | 48 | { |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
49 | Model* dependency = this->resolve(context->modelId, context->documents); |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
50 | PolygonCache* referencedModelPolygonBuilder = nullptr; |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
51 | if (dependency != nullptr) |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
52 | { |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
53 | const auto dependencyModelId = context->documents->findIdForModel(dependency); |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
54 | if (dependencyModelId.has_value()) |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
55 | { |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
56 | referencedModelPolygonBuilder = context->documents->getPolygonCacheForModel(dependencyModelId.value()); |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
57 | } |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
58 | } |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
59 | if (referencedModelPolygonBuilder != nullptr) |
21 | 60 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
61 | const bool needInverting = glm::determinant(this->transformation) < 0; |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
62 | const std::vector<gl::Polygon> modelPolygons = referencedModelPolygonBuilder->getPolygons(context->documents); |
21 | 63 | polygons.reserve(polygons.size() + modelPolygons.size()); |
64 | for (gl::Polygon polygon : modelPolygons) | |
65 | { | |
23
3387a84ddaba
fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
66 | for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
21 | 67 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
68 | glm::vec4 vertex {polygon.vertices[i], 1}; |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
69 | vertex = this->transformation * vertex; |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
70 | polygon.vertices[i] = vertex; |
21 | 71 | } |
26 | 72 | if (needInverting != this->isInverted) |
73 | { | |
74 | gl::invert(polygon); | |
75 | } | |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
134
diff
changeset
|
76 | if (polygon.color == ldraw::MAIN_COLOR) |
21 | 77 | { |
78 | polygon.color = this->colorIndex; | |
79 | } | |
80 | polygon.id = this->id; | |
81 | polygons.push_back(polygon); | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
86 | glm::vec3 ldraw::SubfileReference::position() const |
21 | 87 | { |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
88 | return this->transformation[3]; |
21 | 89 | } |
90 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
91 | void ldraw::SubfileReference::invert() |
26 | 92 | { |
93 | this->isInverted = not this->isInverted; | |
94 | } | |
95 | ||
148 | 96 | Model* ldraw::SubfileReference::resolve(const ModelId callingModelId, DocumentManager* documents) const |
21 | 97 | { |
148 | 98 | return documents->findDependencyByName(callingModelId, this->referenceName); |
21 | 99 | } |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
100 | |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
101 | ldraw::Object::Type ldraw::SubfileReference::typeIdentifier() const |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
102 | { |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
103 | return Type::SubfileReference; |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
104 | } |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
105 | |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
106 | QDataStream& ldraw::SubfileReference::serialize(QDataStream &stream) const |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
107 | { |
134
f77d2230e87c
Add remaining serialize methods
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
108 | return ColoredObject::serialize(stream) << this->transformation << this->referenceName << this->isInverted; |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
109 | } |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
110 | |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
111 | QDataStream& ldraw::SubfileReference::deserialize(QDataStream &stream) |
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
112 | { |
134
f77d2230e87c
Add remaining serialize methods
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
113 | return ColoredObject::deserialize(stream) >> this->transformation >> this->referenceName >> this->isInverted; |
132
488d0ba6070b
Begin work with serialization
Teemu Piippo <teemu@hecknology.net>
parents:
86
diff
changeset
|
114 | } |
141 | 115 | |
116 | QString ldraw::SubfileReference::toLDrawCode() const | |
117 | { | |
118 | QString result; | |
119 | if (this->isInverted) | |
120 | { | |
121 | result += "0 BFC INVERTNEXT\r\n"; | |
122 | } | |
123 | result += utility::format( | |
124 | "1 %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14", | |
125 | this->colorIndex.index, | |
126 | this->transformation[3][0], | |
127 | this->transformation[3][1], | |
128 | this->transformation[3][2], | |
129 | this->transformation[0][0], | |
130 | this->transformation[1][0], | |
131 | this->transformation[2][0], | |
132 | this->transformation[0][1], | |
133 | this->transformation[1][1], | |
134 | this->transformation[2][1], | |
135 | this->transformation[0][2], | |
136 | this->transformation[1][2], | |
137 | this->transformation[2][2], | |
138 | this->referenceName); | |
139 | return result; | |
140 | } | |
158
5bd755eaa5a8
Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents:
150
diff
changeset
|
141 | |
5bd755eaa5a8
Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents:
150
diff
changeset
|
142 | QString ldraw::SubfileReference::iconName() const |
5bd755eaa5a8
Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents:
150
diff
changeset
|
143 | { |
5bd755eaa5a8
Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents:
150
diff
changeset
|
144 | return ":/icons/linetype-subfile.png"; |
5bd755eaa5a8
Add icons from ionicons
Teemu Piippo <teemu@hecknology.net>
parents:
150
diff
changeset
|
145 | } |