src/tools/pathtool.cpp

Wed, 25 May 2022 12:01:58 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 25 May 2022 12:01:58 +0300
changeset 189
815fbaae9cb2
parent 185
a38a0eb007b0
permissions
-rw-r--r--

cleanup, gl::Compiler changed to gl::ModelShaders

#include "pathtool.h"
#include "modeleditor.h"
#include "linetypes/edge.h"
#include "document.h"

PathTool::PathTool(Document *document) :
	AbstractDrawTool{document}
{
}

QString PathTool::name() const
{
	return tr("Draw path");
}

QString PathTool::toolTip() const
{
	return tr("Draw paths");
}

void PathTool::overpaint(Canvas* canvas, QPainter* painter) const
{
	painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin});
	if (this->previewPolygon.size() >= 2)
	{
		canvas->drawWorldPolyline(painter, this->previewPolygon);
	}
	for (const glm::vec3& point : this->polygon)
	{
		canvas->drawWorldPoint(painter, point);
	}
	canvas->drawWorldPoint(painter, this->previewPoint);
}

QString PathTool::iconName() const
{
	return ":/icons/polyline.png";
}

void PathTool::closeShape()
{
	std::unique_ptr<ModelEditor> modelEditor = this->document->editModel();
	for (std::size_t i = 0; i < this->polygon.size() - 1; i += 1)
	{
		modelEditor->append<ldraw::Edge>(std::array{this->polygon[i], this->polygon[i + 1]}, ldraw::EDGE_COLOR);
	}
	this->clearPoints();
}

mercurial