src/tools/circletool.cpp

changeset 188
64ea7282611e
parent 187
30204975694a
equal deleted inserted replaced
187:30204975694a 188:64ea7282611e
1 #include "circletool.h" 1 #include "circletool.h"
2 #include "document.h"
2 3
3 CircleTool::CircleTool(Document *document) : 4 CircleTool::CircleTool(Document *document) :
4 AbstractDrawTool{document} 5 AbstractDrawTool{document}
5 { 6 {
6 } 7 }
34 canvas->drawWorldPoint(painter, this->previewPolygon[i]); 35 canvas->drawWorldPoint(painter, this->previewPolygon[i]);
35 } 36 }
36 painter->setPen(QPen{Qt::green, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); 37 painter->setPen(QPen{Qt::green, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin});
37 canvas->drawWorldPolyline(painter, {this->previewPolygon[0], this->previewPolygon[1]}); 38 canvas->drawWorldPolyline(painter, {this->previewPolygon[0], this->previewPolygon[1]});
38 const float size = glm::distance(this->previewPolygon[1], this->previewPolygon[0]); 39 const float size = glm::distance(this->previewPolygon[1], this->previewPolygon[0]);
39 glm::mat4 matrix = size * canvas->getGridMatrix(); 40 glm::mat4 matrix = size * this->baseGridMatrix;
40 matrix[3] = {this->previewPolygon[0], 1}; 41 matrix[3] = {this->previewPolygon[0], 1};
41 std::vector<glm::vec3> points = circle(16); 42 std::vector<glm::vec3> points = circle(16);
42 for (std::size_t i = 0; i < points.size(); ++i) { 43 for (std::size_t i = 0; i < points.size(); ++i) {
43 points[i] = matrix * glm::vec4{points[i], 1.0f}; 44 points[i] = matrix * glm::vec4{points[i], 1.0f};
44 } 45 }
45 painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); 46 painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin});
46 canvas->drawWorldPolyline(painter, points); 47 canvas->drawWorldPolyline(painter, points);
47 } 48 }
49 if (this->previewPolygon.size() >= 3)
50 {
51
52 }
48 } 53 }
49 54
50 QString CircleTool::iconName() const 55 QString CircleTool::iconName() const
51 { 56 {
52 return ":/icons/linetype-circularprimitive.png"; 57 return ":/icons/linetype-circularprimitive.png";
53 } 58 }
54 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
55 void CircleTool::closeShape() 71 void CircleTool::closeShape()
56 { 72 {
57 73
58 } 74 }
75
76 void CircleTool::reset()
77 {
78 this->baseGridMatrix = this->document->currentGrid();
79 }

mercurial