Tue, 20 Jul 2021 01:22:01 +0300
work on draw preview
103 | 1 | #include <QMessageBox> |
96 | 2 | #include "drawtool.h" |
3 | ||
4 | DrawTool::DrawTool(QObject* parent) : | |
5 | BaseTool{parent} {} | |
6 | ||
7 | QString DrawTool::name() const | |
8 | { | |
9 | static const QString result = tr("Draw"); | |
10 | return result; | |
11 | } | |
12 | ||
13 | QString DrawTool::toolTip() const | |
14 | { | |
15 | static const QString result = tr("Draw new elements into the model."); | |
16 | return result; | |
17 | } | |
103 | 18 | |
104 | 19 | bool DrawTool::mouseClick(const Canvas::MouseClickInfo& info) |
103 | 20 | { |
106 | 21 | if (info.worldPosition.has_value()) |
22 | { | |
23 | const glm::vec3& pos = info.worldPosition.value(); | |
24 | const auto isCloseToPos = [&](const glm::vec3& x){return geom::isclose(x, pos);}; | |
25 | if (any(this->polygon, isCloseToPos)) | |
26 | { | |
27 | QMessageBox::information(nullptr, "test", "close the polygon"); | |
28 | } | |
29 | else | |
30 | { | |
31 | this->polygon.push_back(pos); | |
32 | auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview).polygons; | |
33 | previewLayer.clear(); | |
34 | previewLayer.push_back({this->polygon}); | |
35 | if (this->polygon.size() == 4) | |
36 | { | |
37 | QMessageBox::information(nullptr, "test", "close the polygon"); | |
38 | } | |
39 | } | |
40 | } | |
104 | 41 | return true; |
103 | 42 | } |
106 | 43 | |
44 | void DrawTool::reset() | |
45 | { | |
46 | this->polygon.clear(); | |
47 | } |