src/tools/drawtool.cpp

Sat, 24 Jul 2021 01:50:38 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Jul 2021 01:50:38 +0300
changeset 107
02f142b399b1
parent 106
128efb9d148b
child 108
94c92c923713
permissions
-rw-r--r--

Move selection logic into select tool

#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