src/linetypes/subfilereference.cpp

Sun, 19 Jan 2020 02:54:48 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 19 Jan 2020 02:54:48 +0200
changeset 22
6da867fa5429
parent 21
0133e565e072
child 23
3387a84ddaba
permissions
-rw-r--r--

commit work on GL rendering

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"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
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
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
13 QVariant linetypes::SubfileReference::getProperty(Property property) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 switch (property)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 case Property::Transformation:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 return QVariant::fromValue(this->transformation);
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 case Property::ReferenceName:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 return this->referenceName;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 default:
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
22 return ColoredObject::getProperty(property);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
25
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
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
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
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
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
44 QString linetypes::SubfileReference::textRepresentation() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
45 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
46 return referenceName + " " + vertexToStringParens(this->position());
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
47 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
48
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
49 void linetypes::SubfileReference::getPolygons(
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
50 std::vector<gl::Polygon>& polygons,
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
51 GetPolygonsContext* context) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
52 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
53 Model* model = this->resolve(context->documents);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
54 if (model != nullptr)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
55 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
56 const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
57 polygons.reserve(polygons.size() + modelPolygons.size());
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
58 for (gl::Polygon polygon : modelPolygons)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
59 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
60 for (int i = 0; i < polygon.numPolygonVertices(); i += 1)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
61 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
62 polygon.vertices[i] = math::transform(polygon.vertices[1], this->transformation);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
63 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
64 if (polygon.color == colors::main)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
65 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
66 polygon.color = this->colorIndex;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
67 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
68 polygon.id = this->id;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
69 polygons.push_back(polygon);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
70 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
71 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
72 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
73
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
74 Point3D linetypes::SubfileReference::position() const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
75 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
76 return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)};
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
77 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
78
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
79 Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
80 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
81 return documents->findModelByName(this->referenceName);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
82 }

mercurial