src/layers/edittools.h

Tue, 11 Apr 2023 22:39:18 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 11 Apr 2023 22:39:18 +0300
changeset 376
3cef3b016330
parent 374
75efc3ba5a56
child 379
8d88adffb779
permissions
-rw-r--r--

Split GL preferences that affect GL build to a new build preferences structure, modifying that requires rebuild, modifying render preferences does not

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2020 Teemu Piippo
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include <memory>
#include <QWidget>
#include <QToolBar>
#include "src/model.h"
#include "src/vertexmap.h"
#include "src/gl/common.h"
#include "src/inputvertices.h"

enum class editing_mode_e
{
	select,
	draw,
	circle
};

Q_DECLARE_METATYPE(editing_mode_e)

Q_DECLARE_METATYPE(ModelAction)

class EditTools final : public QObject, public RenderLayer
{
	Q_OBJECT
	InputVertices inputPolygon;
	editing_mode_e mode = editing_mode_e::select;
	glm::mat4 mvpMatrix;
	glm::mat4 gridMatrix{1};
	Plane gridPlane;
	QPointF localPosition;
	opt<glm::vec3> worldPosition;
	CircleToolOptions circleToolOptions = {
		.fraction = {16, 16},
		.type = CircularPrimitive::Circle,
	};
public:
	explicit EditTools(QObject *parent = nullptr);
	~EditTools() override;
	void applyToVertices(VertexMap::ApplyFunction fn) const;
	[[nodiscard]] const QSet<ModelId> selectedObjects() const;
	[[nodiscard]] editing_mode_e currentEditingMode() const;
	Q_SLOT void setEditMode(editing_mode_e mode);
	Q_SLOT void setGridMatrix(const glm::mat4& gridMatrix);
	Q_SLOT void setCircleToolOptions(const CircleToolOptions& options);
Q_SIGNALS:
	void newStatusText(const QString& newStatusText);
	void modelAction(const ModelAction& action);
	void select(const QSet<std::int32_t>& ids, bool retain);
	void suggestCursor(const QCursor& cursor);
protected:
	void mvpMatrixChanged(const glm::mat4& matrix) override;
	void mouseMoved(const QMouseEvent* event) override;
	void mouseClick(const QMouseEvent* event) override;
	void overpaint(QPainter* painter) override;
private:
	[[nodiscard]] const std::vector<ModelAction> modelActions() const;
	[[nodiscard]] const std::vector<ModelAction> circleModeActions() const;
	[[nodiscard]] const std::vector<ModelAction> drawModeActions() const;
	bool usePolygon() const;
	void closeShape();
	void renderPreview(QPainter* painter, const void* pensptr);
	[[nodiscard]] opt<float> cylinderHeight() const;
};

mercurial