src/tools/drawtool.cpp

Tue, 20 Jul 2021 01:22:01 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 20 Jul 2021 01:22:01 +0300
changeset 106
128efb9d148b
parent 104
cd4df75924b7
child 108
94c92c923713
permissions
-rw-r--r--

work on draw preview

#include <QMessageBox>
#include "drawtool.h"

DrawTool::DrawTool(QObject* parent) :
	BaseTool{parent} {}

QString DrawTool::name() const
{
	static const QString result = tr("Draw");
	return result;
}

QString DrawTool::toolTip() const
{
	static const QString result = tr("Draw new elements into the model.");
	return result;
}

bool DrawTool::mouseClick(const Canvas::MouseClickInfo& info)
{
	if (info.worldPosition.has_value())
	{
		const glm::vec3& pos = info.worldPosition.value();
		const auto isCloseToPos = [&](const glm::vec3& x){return geom::isclose(x, pos);};
		if (any(this->polygon, isCloseToPos))
		{
			QMessageBox::information(nullptr, "test", "close the polygon");
		}
		else
		{
			this->polygon.push_back(pos);
			auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview).polygons;
			previewLayer.clear();
			previewLayer.push_back({this->polygon});
			if (this->polygon.size() == 4)
			{
				QMessageBox::information(nullptr, "test", "close the polygon");
			}
		}
	}
	return true;
}

void DrawTool::reset()
{
	this->polygon.clear();
}

mercurial