diff -r cef43609a374 -r 0133e565e072 src/linetypes/subfilereference.cpp --- a/src/linetypes/subfilereference.cpp Sat Dec 14 23:00:01 2019 +0200 +++ b/src/linetypes/subfilereference.cpp Wed Jan 01 17:45:56 2020 +0200 @@ -1,12 +1,10 @@ #include "subfilereference.h" +#include "documentmanager.h" -linetypes::SubfileReference::SubfileReference( - const Point3D& position, - const Matrix3x3& transformation, +linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation, const QString& referenceName, const Color color) : ColoredObject{color}, - position{position}, transformation{transformation}, referenceName{referenceName} { @@ -16,8 +14,6 @@ { switch (property) { - case Property::Position: - return this->position; case Property::Transformation: return QVariant::fromValue(this->transformation); case Property::ReferenceName: @@ -34,11 +30,8 @@ { switch (property) { - case Property::Position: - this->position = value.value(); - return SetPropertyResult::Success; case Property::Transformation: - this->transformation = value.value(); + this->transformation = value.value(); return SetPropertyResult::Success; case Property::ReferenceName: this->referenceName = value.toString(); @@ -50,5 +43,40 @@ QString linetypes::SubfileReference::textRepresentation() const { - return referenceName + " " + vertexToStringParens(this->position); + return referenceName + " " + vertexToStringParens(this->position()); } + +void linetypes::SubfileReference::getPolygons( + std::vector& polygons, + GetPolygonsContext* context) const +{ + Model* model = this->resolve(context->documents); + if (model != nullptr) + { + const std::vector modelPolygons = model->getPolygons(context->documents); + polygons.reserve(polygons.size() + modelPolygons.size()); + for (gl::Polygon polygon : modelPolygons) + { + for (int i = 0; i < polygon.numPolygonVertices(); i += 1) + { + polygon.vertices[i] = math::transform(polygon.vertices[1], this->transformation); + } + if (polygon.color == colors::main) + { + polygon.color = this->colorIndex; + } + polygon.id = this->id; + polygons.push_back(polygon); + } + } +} + +Point3D linetypes::SubfileReference::position() const +{ + return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)}; +} + +Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const +{ + return documents->findModelByName(this->referenceName); +}