1 #include "circletool.h" |
|
2 #include "document.h" |
|
3 |
|
4 CircleTool::CircleTool(Document *document) : |
|
5 AbstractDrawTool{document} |
|
6 { |
|
7 } |
|
8 |
|
9 QString CircleTool::name() const |
|
10 { |
|
11 return tr("Circle"); |
|
12 } |
|
13 |
|
14 QString CircleTool::toolTip() const |
|
15 { |
|
16 return tr("Draw circular primitives like circles or discs"); |
|
17 } |
|
18 |
|
19 std::vector<glm::vec3> circle(int divisions) |
|
20 { |
|
21 std::vector<glm::vec3> points; |
|
22 points.reserve(divisions + 1); |
|
23 for (int i = 0; i <= divisions; ++i) { |
|
24 float ang = i * 2.0f * glm::pi<float>() / divisions; |
|
25 points.push_back({std::sin(ang), std::cos(ang), 0.0f}); |
|
26 } |
|
27 return points; |
|
28 } |
|
29 |
|
30 void CircleTool::overpaint(Canvas *canvas, QPainter *painter) const |
|
31 { |
|
32 if (this->previewPolygon.size() >= 2) |
|
33 { |
|
34 for (int i : {0, 1}) { |
|
35 canvas->drawWorldPoint(painter, this->previewPolygon[i]); |
|
36 } |
|
37 painter->setPen(QPen{Qt::green, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); |
|
38 canvas->drawWorldPolyline(painter, {this->previewPolygon[0], this->previewPolygon[1]}); |
|
39 const float size = glm::distance(this->previewPolygon[1], this->previewPolygon[0]); |
|
40 glm::mat4 matrix = size * this->baseGridMatrix; |
|
41 matrix[3] = {this->previewPolygon[0], 1}; |
|
42 std::vector<glm::vec3> points = circle(16); |
|
43 for (std::size_t i = 0; i < points.size(); ++i) { |
|
44 points[i] = matrix * glm::vec4{points[i], 1.0f}; |
|
45 } |
|
46 painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); |
|
47 canvas->drawWorldPolyline(painter, points); |
|
48 } |
|
49 if (this->previewPolygon.size() >= 3) |
|
50 { |
|
51 |
|
52 } |
|
53 } |
|
54 |
|
55 QString CircleTool::iconName() const |
|
56 { |
|
57 return ":/icons/linetype-circularprimitive.png"; |
|
58 } |
|
59 |
|
60 void CircleTool::addPoint(const glm::vec3 &pos) |
|
61 { |
|
62 AbstractDrawTool::addPoint(pos); |
|
63 if (this->polygon.size() >= 2) |
|
64 { |
|
65 const glm::mat4& grid = this->document->currentGrid(); |
|
66 const glm::mat4 newGrid = {grid[1], grid[2], grid[0], {this->polygon[0], 1}}; |
|
67 Q_EMIT this->desiredGridChange(newGrid); |
|
68 } |
|
69 } |
|
70 |
|
71 void CircleTool::closeShape() |
|
72 { |
|
73 |
|
74 } |
|
75 |
|
76 void CircleTool::reset() |
|
77 { |
|
78 this->baseGridMatrix = this->document->currentGrid(); |
|
79 } |
|