src/linetypes/subfilereference.cpp

changeset 21
0133e565e072
parent 18
918b6c0f8b5b
child 23
3387a84ddaba
equal deleted inserted replaced
20:cef43609a374 21:0133e565e072
1 #include "subfilereference.h" 1 #include "subfilereference.h"
2 #include "documentmanager.h"
2 3
3 linetypes::SubfileReference::SubfileReference( 4 linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation,
4 const Point3D& position,
5 const Matrix3x3& transformation,
6 const QString& referenceName, 5 const QString& referenceName,
7 const Color color) : 6 const Color color) :
8 ColoredObject{color}, 7 ColoredObject{color},
9 position{position},
10 transformation{transformation}, 8 transformation{transformation},
11 referenceName{referenceName} 9 referenceName{referenceName}
12 { 10 {
13 } 11 }
14 12
15 QVariant linetypes::SubfileReference::getProperty(Property property) const 13 QVariant linetypes::SubfileReference::getProperty(Property property) const
16 { 14 {
17 switch (property) 15 switch (property)
18 { 16 {
19 case Property::Position:
20 return this->position;
21 case Property::Transformation: 17 case Property::Transformation:
22 return QVariant::fromValue(this->transformation); 18 return QVariant::fromValue(this->transformation);
23 case Property::ReferenceName: 19 case Property::ReferenceName:
24 return this->referenceName; 20 return this->referenceName;
25 default: 21 default:
32 const QVariant& value) 28 const QVariant& value)
33 -> SetPropertyResult 29 -> SetPropertyResult
34 { 30 {
35 switch (property) 31 switch (property)
36 { 32 {
37 case Property::Position:
38 this->position = value.value<Point3D>();
39 return SetPropertyResult::Success;
40 case Property::Transformation: 33 case Property::Transformation:
41 this->transformation = value.value<Matrix3x3>(); 34 this->transformation = value.value<Matrix4x4>();
42 return SetPropertyResult::Success; 35 return SetPropertyResult::Success;
43 case Property::ReferenceName: 36 case Property::ReferenceName:
44 this->referenceName = value.toString(); 37 this->referenceName = value.toString();
45 return SetPropertyResult::Success; 38 return SetPropertyResult::Success;
46 default: 39 default:
48 } 41 }
49 } 42 }
50 43
51 QString linetypes::SubfileReference::textRepresentation() const 44 QString linetypes::SubfileReference::textRepresentation() const
52 { 45 {
53 return referenceName + " " + vertexToStringParens(this->position); 46 return referenceName + " " + vertexToStringParens(this->position());
54 } 47 }
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 }

mercurial