Sat, 05 Mar 2022 16:57:28 +0200
Draw tool now renders the winding of the new polygon
#include <QHBoxLayout> #include "model.h" #include "modeleditor.h" #include "linetypes/object.h" #include "transformtool.h" #include "document.h" TransformTool::TransformTool(Document* document) : BaseTool{document}, matrixEditor{new MatrixEditor{document}}, button{new QPushButton{"Apply", document}}, widget{new QWidget{document}} { widget->setLayout(new QHBoxLayout{widget}); widget->layout()->addWidget(this->matrixEditor); widget->layout()->addWidget(button); connect(button, &QPushButton::clicked, this, &TransformTool::applyButtonClicked); } QString TransformTool::name() const { return "Transform"; } QString TransformTool::toolTip() const { return "Transforms the selection using a matrix"; } void TransformTool::selectionChanged(const QSet<ldraw::id_t> &newSelection) { this->selection = newSelection; } QWidget* TransformTool::toolWidget() { return this->widget; } QString TransformTool::iconName() const { return ":/icons/grid-outline.png"; } void TransformTool::applyButtonClicked() { std::unique_ptr<ModelEditor> editor = this->document->editModel(); const glm::mat4 matrix = this->matrixEditor->value(); for (ldraw::id_t id : this->selection) { editor->modifyObject(id, [&](ldraw::Object* object){ for (int i = 0; i < object->numPoints(); i += 1) { const ldraw::Property property = ldraw::pointProperty(i); const glm::vec3& vec = matrix * glm::vec4{object->getPoint(i), 1}; object->setProperty({property, QVariant::fromValue(vec)}); } QVariant transformMatrix = object->getProperty(ldraw::Property::Transformation); if (not transformMatrix.isNull()) { object->setProperty<ldraw::Property::Transformation>(matrix * transformMatrix.value<glm::mat4>()); } }); } }