src/modeleditcontext.h

Sat, 07 Mar 2020 01:25:37 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 07 Mar 2020 01:25:37 +0200
changeset 75
204dc77e5654
parent 73
97df974b5ed5
child 76
7c4a63a02632
permissions
-rw-r--r--

document AbstractBasicShaderProgram

/*
 *  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 setObjectProperty(
		ldraw::Object* 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 QuadrilateralSplit
	{
		Split123_134,
		Split124_234
	};

	// 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,
		QuadrilateralSplit splitType = QuadrilateralSplit::Split123_134
	) -> std::optional<std::pair<triangleid_t, triangleid_t>>;
}

mercurial