src/linetypes/subfilereference.cpp

Wed, 22 Jan 2020 22:41:17 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Jan 2020 22:41:17 +0200
changeset 28
c92c1daf735f
parent 26
3a9e761e4faa
child 33
4c41bfe2ec6e
permissions
-rw-r--r--

modelview matrix set up

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"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
5 linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation,
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
6 const QString& referenceName,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
7 const Color color) :
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
8 ColoredObject{color},
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
9 transformation{transformation},
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
10 referenceName{referenceName}
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 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
13
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
14 QVariant linetypes::SubfileReference::getProperty(Property property) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 switch (property)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 case Property::Transformation:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 return QVariant::fromValue(this->transformation);
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 case Property::ReferenceName:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 return this->referenceName;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 default:
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
23 return ColoredObject::getProperty(property);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
26
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
27 auto linetypes::SubfileReference::setProperty(
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
28 Property property,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
29 const QVariant& value)
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
30 -> SetPropertyResult
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
31 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
32 switch (property)
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
33 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
34 case Property::Transformation:
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
35 this->transformation = value.value<Matrix4x4>();
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
36 return SetPropertyResult::Success;
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
37 case Property::ReferenceName:
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
38 this->referenceName = value.toString();
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
39 return SetPropertyResult::Success;
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
40 default:
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
41 return ColoredObject::setProperty(property, value);
8
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 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
44
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
45 QString linetypes::SubfileReference::textRepresentation() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
46 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
47 return referenceName + " " + vertexToStringParens(this->position());
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
48 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
49
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
50 void linetypes::SubfileReference::getPolygons(
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
51 std::vector<gl::Polygon>& polygons,
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
52 GetPolygonsContext* context) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
53 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
54 Model* model = this->resolve(context->documents);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
55 if (model != nullptr)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
56 {
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
57 const bool needInverting = math::det(this->transformation) < 0;
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
58 const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
59 polygons.reserve(polygons.size() + modelPolygons.size());
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
60 for (gl::Polygon polygon : modelPolygons)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
61 {
23
3387a84ddaba fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
62 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
63 {
23
3387a84ddaba fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
64 polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation);
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
65 }
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
66 if (needInverting != this->isInverted)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
67 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
68 gl::invert(polygon);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
69 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
70 if (polygon.color == colors::main)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
71 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
72 polygon.color = this->colorIndex;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
73 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
74 polygon.id = this->id;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
75 polygons.push_back(polygon);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
76 }
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
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
80 Point3D linetypes::SubfileReference::position() const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
81 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
82 return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)};
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
83 }
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
84
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
85 void linetypes::SubfileReference::invert()
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
86 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
87 this->isInverted = not this->isInverted;
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
88 }
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
89
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
90 Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
91 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
92 return documents->findModelByName(this->referenceName);
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
93 }

mercurial