--- a/src/tools/transformtool.cpp Thu Mar 03 21:13:16 2022 +0200 +++ b/src/tools/transformtool.cpp Fri Mar 04 11:37:50 2022 +0200 @@ -3,13 +3,13 @@ #include "modeleditcontext.h" #include "linetypes/object.h" #include "transformtool.h" +#include "document.h" -TransformTool::TransformTool(Model* model, QWidget* parent) : - BaseTool{model, parent}, - model{model}, - matrixEditor{new MatrixEditor{parent}}, - button{new QPushButton{"Apply", parent}}, - widget{new QWidget{parent}} +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); @@ -39,25 +39,22 @@ void TransformTool::applyButtonClicked() { - Model::EditContext editcontext = this->model->edit(); + std::unique_ptr<ModelEditor> editor = this->document->editModel(); const glm::mat4 matrix = this->matrixEditor->value(); for (ldraw::id_t id : this->selection) { - const ldraw::Object* object = model->get(id); - 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}; - editcontext.setObjectProperty(id, property, QVariant::fromValue(vec)); - } - QVariant transformMatrix = object->getProperty(ldraw::Property::Transformation); - if (not transformMatrix.isNull()) - { - editcontext.setObjectProperty( - id, - ldraw::Property::Transformation, - QVariant::fromValue(matrix * transformMatrix.value<glm::mat4>()) - ); - } + 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>()); + } + }); } }