src/tools/transformtool.cpp

changeset 191
d355d4c52d51
parent 190
3dbdc243f053
child 192
e6faeffed1d1
--- a/src/tools/transformtool.cpp	Wed May 25 13:49:45 2022 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-#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>());
-			}
-		});
-	}
-}

mercurial