| 1 #include "subfilereference.h" |
1 #include "subfilereference.h" |
| 2 #include "documentmanager.h" |
2 #include "documentmanager.h" |
| |
3 #include "invert.h" |
| 3 |
4 |
| 4 linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation, |
5 linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation, |
| 5 const QString& referenceName, |
6 const QString& referenceName, |
| 6 const Color color) : |
7 const Color color) : |
| 7 ColoredObject{color}, |
8 ColoredObject{color}, |
| 51 GetPolygonsContext* context) const |
52 GetPolygonsContext* context) const |
| 52 { |
53 { |
| 53 Model* model = this->resolve(context->documents); |
54 Model* model = this->resolve(context->documents); |
| 54 if (model != nullptr) |
55 if (model != nullptr) |
| 55 { |
56 { |
| |
57 const bool needInverting = math::det(this->transformation) < 0; |
| 56 const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); |
58 const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); |
| 57 polygons.reserve(polygons.size() + modelPolygons.size()); |
59 polygons.reserve(polygons.size() + modelPolygons.size()); |
| 58 for (gl::Polygon polygon : modelPolygons) |
60 for (gl::Polygon polygon : modelPolygons) |
| 59 { |
61 { |
| 60 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
62 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
| 61 { |
63 { |
| 62 polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation); |
64 polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation); |
| |
65 } |
| |
66 if (needInverting != this->isInverted) |
| |
67 { |
| |
68 gl::invert(polygon); |
| 63 } |
69 } |
| 64 if (polygon.color == colors::main) |
70 if (polygon.color == colors::main) |
| 65 { |
71 { |
| 66 polygon.color = this->colorIndex; |
72 polygon.color = this->colorIndex; |
| 67 } |
73 } |
| 74 Point3D linetypes::SubfileReference::position() const |
80 Point3D linetypes::SubfileReference::position() const |
| 75 { |
81 { |
| 76 return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)}; |
82 return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)}; |
| 77 } |
83 } |
| 78 |
84 |
| |
85 void linetypes::SubfileReference::invert() |
| |
86 { |
| |
87 this->isInverted = not this->isInverted; |
| |
88 } |
| |
89 |
| 79 Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const |
90 Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const |
| 80 { |
91 { |
| 81 return documents->findModelByName(this->referenceName); |
92 return documents->findModelByName(this->referenceName); |
| 82 } |
93 } |