Wed, 01 Jan 2020 17:45:56 +0200
things
3 | 1 | #include "subfilereference.h" |
21 | 2 | #include "documentmanager.h" |
3 | 3 | |
21 | 4 | linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
5 | const QString& referenceName, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
6 | const Color color) : |
13 | 7 | ColoredObject{color}, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
8 | transformation{transformation}, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
9 | referenceName{referenceName} |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
10 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
11 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
12 | |
13 | 13 | QVariant linetypes::SubfileReference::getProperty(Property property) const |
3 | 14 | { |
15 | switch (property) | |
16 | { | |
17 | case Property::Transformation: | |
18 | return QVariant::fromValue(this->transformation); | |
19 | case Property::ReferenceName: | |
20 | return this->referenceName; | |
21 | default: | |
13 | 22 | return ColoredObject::getProperty(property); |
3 | 23 | } |
24 | } | |
6 | 25 | |
13 | 26 | auto linetypes::SubfileReference::setProperty( |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
27 | Property property, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
28 | const QVariant& value) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
29 | -> SetPropertyResult |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
30 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
31 | switch (property) |
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 | case Property::Transformation: |
21 | 34 | this->transformation = value.value<Matrix4x4>(); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
35 | return SetPropertyResult::Success; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
36 | case Property::ReferenceName: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
37 | this->referenceName = value.toString(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
38 | return SetPropertyResult::Success; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
39 | default: |
13 | 40 | return ColoredObject::setProperty(property, value); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
41 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
42 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
43 | |
13 | 44 | QString linetypes::SubfileReference::textRepresentation() const |
6 | 45 | { |
21 | 46 | return referenceName + " " + vertexToStringParens(this->position()); |
6 | 47 | } |
21 | 48 | |
49 | void linetypes::SubfileReference::getPolygons( | |
50 | std::vector<gl::Polygon>& polygons, | |
51 | GetPolygonsContext* context) const | |
52 | { | |
53 | Model* model = this->resolve(context->documents); | |
54 | if (model != nullptr) | |
55 | { | |
56 | const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); | |
57 | polygons.reserve(polygons.size() + modelPolygons.size()); | |
58 | for (gl::Polygon polygon : modelPolygons) | |
59 | { | |
60 | for (int i = 0; i < polygon.numPolygonVertices(); i += 1) | |
61 | { | |
62 | polygon.vertices[i] = math::transform(polygon.vertices[1], this->transformation); | |
63 | } | |
64 | if (polygon.color == colors::main) | |
65 | { | |
66 | polygon.color = this->colorIndex; | |
67 | } | |
68 | polygon.id = this->id; | |
69 | polygons.push_back(polygon); | |
70 | } | |
71 | } | |
72 | } | |
73 | ||
74 | Point3D linetypes::SubfileReference::position() const | |
75 | { | |
76 | return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)}; | |
77 | } | |
78 | ||
79 | Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const | |
80 | { | |
81 | return documents->findModelByName(this->referenceName); | |
82 | } |