src/modeleditcontext.h

Mon, 24 Aug 2020 22:51:01 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 24 Aug 2020 22:51:01 +0300
changeset 90
e234edb5e613
parent 76
7c4a63a02632
child 86
4bec0525ef1b
permissions
-rw-r--r--

remove dependency on glut, fixes

/*
 *  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 "model.h"
#include "linetypes/object.h"
#include "linetypes/quadrilateral.h"
#include "linetypes/triangle.h"

class Model::EditContext
{
public:
	template<typename T, typename... Args>
	ldraw::Id<T> append(Args&&... args);
	ldraw::id_t append(std::unique_ptr<ldraw::Object>&& object);
	template<typename T, typename... Args>
	ldraw::Id<T> insert(int position, Args&&... args);
	void remove(int position);
	void setObjectProperty(
		ldraw::id_t object,
		ldraw::Property property,
		const QVariant &value);
	void invertObject(ldraw::id_t id);
	Model& model();
private:
	EditContext(Model& model);
	friend class Model;
	Model& storedModel;
};

template<typename T, typename... Args>
ldraw::Id<T> Model::EditContext::append(Args&&... args)
{
	return this->storedModel.append<T>(args...);
}

template<typename T, typename... Args>
ldraw::Id<T> Model::EditContext::insert(int position, Args&&... args)
{
	return this->storedModel.insert<T>(position, args...);
}

namespace ldraw
{
	/// Determines how quadrilaterals are split into triangles
	enum class Diagonal
	{
		Diagonal_13,
		Diagonal_24
	};

	// Splits the specified quadrilateral into triangles.
	// If it is not a quadrilateral then no action is performed
	auto splitQuadrilateral(Model::EditContext& editor,
		quadrilateralid_t quadrilateral_id,
		Diagonal splitType = Diagonal::Diagonal_13
	) -> std::optional<std::pair<triangleid_t, triangleid_t>>;
}

mercurial