src/layers/edittools.h

changeset 263
59b6027b9843
parent 262
dc33f8a707c4
child 264
76a025db4948
equal deleted inserted replaced
262:dc33f8a707c4 263:59b6027b9843
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 - 2020 Teemu Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #pragma once
20 #include <memory>
21 #include <QWidget>
22 #include <QToolBar>
23 #include "model.h"
24 #include "vertexmap.h"
25 #include "gl/common.h"
26
27 enum EditingMode
28 {
29 SelectMode,
30 DrawMode,
31 CircleMode
32 };
33
34 Q_DECLARE_METATYPE(EditingMode)
35
36 Q_DECLARE_METATYPE(ModelAction)
37
38 class EditTools final : public QObject, public RenderLayer
39 {
40 Q_OBJECT
41 std::vector<glm::vec3> polygon = {{0, 0, 0}};
42 std::size_t numpoints = 1;
43 EditingMode mode = SelectMode;
44 glm::mat4 mvpMatrix;
45 glm::mat4 gridMatrix{1};
46 Plane gridPlane;
47 opt<glm::vec3> worldPosition;
48 CircleToolOptions circleToolOptions = {
49 .fraction = {16, 16},
50 .type = CircularPrimitive::Circle,
51 };
52 public:
53 explicit EditTools(QObject *parent = nullptr);
54 ~EditTools() override;
55 void applyToVertices(VertexMap::ApplyFunction fn) const;
56 const QSet<ModelId> selectedObjects() const;
57 EditingMode currentEditingMode() const;
58 Q_SLOT void setEditMode(EditingMode mode);
59 Q_SLOT void setGridMatrix(const glm::mat4& gridMatrix);
60 Q_SLOT void setCircleToolOptions(const CircleToolOptions& options);
61 Q_SIGNALS:
62 void newStatusText(const QString& newStatusText);
63 void modelAction(const ModelAction& action);
64 void select(const QSet<ModelId>& ids, bool retain);
65 protected:
66 void mvpMatrixChanged(const glm::mat4& matrix) override;
67 void mouseMoved(const QMouseEvent* event) override;
68 void mouseClick(const QMouseEvent* event) override;
69 void overpaint(QPainter* painter) override;
70 private:
71 const std::vector<ModelAction> modelActions() const;
72 const std::vector<ModelAction> circleModeActions() const;
73 const std::vector<ModelAction> drawModeActions() const;
74 void closeShape();
75 void renderPreview(QPainter* painter, const void* pensptr);
76 void removeLastPoint();
77 bool isCloseToExistingPoints() const;
78 };

mercurial