--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tools/pathtool.cpp Tue Mar 15 19:48:07 2022 +0200 @@ -0,0 +1,48 @@ +#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(); +}