# HG changeset patch # User Teemu Piippo # Date 1653397870 -10800 # Node ID 64ea7282611e743a3cce9dc31caaa489dc23e4a4 # Parent 30204975694a53d400f32bee1358e2f9e3adec67 more work on circle tool + cleanup diff -r 30204975694a -r 64ea7282611e src/colors.h --- a/src/colors.h Mon May 16 01:40:49 2022 +0300 +++ b/src/colors.h Tue May 24 16:11:10 2022 +0300 @@ -55,6 +55,7 @@ struct ldraw::Color { qint32 index = 0; + constexpr auto operator<=>(const Color&) const = default; }; Q_DECLARE_METATYPE(ldraw::Color) @@ -63,36 +64,6 @@ namespace ldraw { - constexpr bool operator==(Color one, Color other) - { - return one.index == other.index; - } - - constexpr bool operator!=(Color one, Color other) - { - return one.index != other.index; - } - - constexpr bool operator<(Color one, Color other) - { - return one.index < other.index; - } - - constexpr bool operator<=(Color one, Color other) - { - return one.index <= other.index; - } - - constexpr bool operator>(Color one, Color other) - { - return one.index > other.index; - } - - constexpr bool operator>=(Color one, Color other) - { - return one.index >= other.index; - } - static constexpr Color BLACK {0}; static constexpr Color BLUE {1}; static constexpr Color GREEN {2}; diff -r 30204975694a -r 64ea7282611e src/document.cpp --- a/src/document.cpp Mon May 16 01:40:49 2022 +0300 +++ b/src/document.cpp Tue May 24 16:11:10 2022 +0300 @@ -167,7 +167,7 @@ this->tools.push_back(new CircleTool{this}); this->tools.push_back(new PathTool{this}); this->tools.push_back(new TransformTool{this}); - for (BaseTool* const toolInstance : this->tools) + for (BaseTool* toolInstance : this->tools) { QAction* action = new QAction{toolInstance->name(), this}; action->setCheckable(true); @@ -185,6 +185,7 @@ { this->ui.toolWidgetStack->addWidget(new QWidget{this}); } + connect(toolInstance, &BaseTool::desiredGridChange, this->renderer, &Canvas::setGridMatrix); } this->selectTool(this->tools[0]); } @@ -240,6 +241,11 @@ this->renderer->adjustGridToView(); } +const glm::mat4 &Document::currentGrid() const +{ + return this->renderer->getGridMatrix(); +} + const Model &Document::getModel() const { return *this->model; diff -r 30204975694a -r 64ea7282611e src/document.h --- a/src/document.h Mon May 16 01:40:49 2022 +0300 +++ b/src/document.h Tue May 24 16:11:10 2022 +0300 @@ -48,6 +48,7 @@ void applyToVertices(VertexMap::ApplyFunction fn) const; void handleKeyPress(QKeyEvent* event); void adjustGridToView(); + const glm::mat4& currentGrid() const; const Model& getModel() const; const QSet selectedObjects() const; const ldraw::ColorTable& colorTable; diff -r 30204975694a -r 64ea7282611e src/main.h --- a/src/main.h Mon May 16 01:40:49 2022 +0300 +++ b/src/main.h Tue May 24 16:11:10 2022 +0300 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "basics.h" #include "utility.h" diff -r 30204975694a -r 64ea7282611e src/tools/basetool.h --- a/src/tools/basetool.h Mon May 16 01:40:49 2022 +0300 +++ b/src/tools/basetool.h Tue May 24 16:11:10 2022 +0300 @@ -23,6 +23,8 @@ virtual void reset() {} virtual void overpaint(Canvas*, QPainter*) const {} virtual QString iconName() const; +Q_SIGNALS: + void desiredGridChange(const glm::mat4& matrix); protected: QWidget* const parentWidget; Document* const document; diff -r 30204975694a -r 64ea7282611e src/tools/circletool.cpp --- a/src/tools/circletool.cpp Mon May 16 01:40:49 2022 +0300 +++ b/src/tools/circletool.cpp Tue May 24 16:11:10 2022 +0300 @@ -1,4 +1,5 @@ #include "circletool.h" +#include "document.h" CircleTool::CircleTool(Document *document) : AbstractDrawTool{document} @@ -36,7 +37,7 @@ painter->setPen(QPen{Qt::green, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); canvas->drawWorldPolyline(painter, {this->previewPolygon[0], this->previewPolygon[1]}); const float size = glm::distance(this->previewPolygon[1], this->previewPolygon[0]); - glm::mat4 matrix = size * canvas->getGridMatrix(); + glm::mat4 matrix = size * this->baseGridMatrix; matrix[3] = {this->previewPolygon[0], 1}; std::vector points = circle(16); for (std::size_t i = 0; i < points.size(); ++i) { @@ -45,6 +46,10 @@ painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); canvas->drawWorldPolyline(painter, points); } + if (this->previewPolygon.size() >= 3) + { + + } } QString CircleTool::iconName() const @@ -52,7 +57,23 @@ return ":/icons/linetype-circularprimitive.png"; } +void CircleTool::addPoint(const glm::vec3 &pos) +{ + AbstractDrawTool::addPoint(pos); + if (this->polygon.size() >= 2) + { + const glm::mat4& grid = this->document->currentGrid(); + const glm::mat4 newGrid = {grid[1], grid[2], grid[0], {this->polygon[0], 1}}; + Q_EMIT this->desiredGridChange(newGrid); + } +} + void CircleTool::closeShape() { } + +void CircleTool::reset() +{ + this->baseGridMatrix = this->document->currentGrid(); +} diff -r 30204975694a -r 64ea7282611e src/tools/circletool.h --- a/src/tools/circletool.h Mon May 16 01:40:49 2022 +0300 +++ b/src/tools/circletool.h Tue May 24 16:11:10 2022 +0300 @@ -10,5 +10,9 @@ QString toolTip() const override; void overpaint(Canvas *canvas, QPainter *painter) const override; QString iconName() const override; + void addPoint(const glm::vec3& pos) override; void closeShape() override; + void reset() override; +private: + glm::mat4 baseGridMatrix; }; diff -r 30204975694a -r 64ea7282611e src/ui/canvas.cpp --- a/src/ui/canvas.cpp Mon May 16 01:40:49 2022 +0300 +++ b/src/ui/canvas.cpp Tue May 24 16:11:10 2022 +0300 @@ -320,6 +320,7 @@ }; this->gridPlane = geom::planeFromTriangle(triangle); this->gridProgram->setGridMatrix(this->gridMatrix); + this->update(); } /** diff -r 30204975694a -r 64ea7282611e src/ui/canvas.h --- a/src/ui/canvas.h Mon May 16 01:40:49 2022 +0300 +++ b/src/ui/canvas.h Tue May 24 16:11:10 2022 +0300 @@ -24,13 +24,14 @@ void drawWorldPolyline(QPainter* painter, const std::vector& points); void drawWorldPolygon(QPainter* painter, const std::vector& points); Winding worldPolygonWinding(const std::vector& points) const; - const std::optional& getWorldPosition() const; + const std::optional& getWorldPosition() const; void adjustGridToView(); const QSet selectedObjects() const; const glm::mat4& getGridMatrix() const; public Q_SLOTS: void handleSelectionChange(const QSet& selectedIds, const QSet& deselectedIds); void rebuildVertices(Document *document); + void setGridMatrix(const glm::mat4 &newMatrix); protected: void mouseMoveEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override; @@ -43,7 +44,6 @@ void mouseClick(Canvas* canvas, QMouseEvent* event); void mouseMove(Canvas* canvas, QMouseEvent* event); private: - void setGridMatrix(const glm::mat4 &newMatrix); glm::vec3 cameraVector() const; bool isGridPerpendicularToScreen(float threshold) const; QVector convertWorldPointsToScreenPoints(const std::vector& worldPoints) const;