src/ldrawalgorithm.cpp

Wed, 22 Jun 2022 23:51:06 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 22 Jun 2022 23:51:06 +0300
changeset 258
fe094d0687ad
parent 248
29986dfd1750
child 262
dc33f8a707c4
permissions
-rw-r--r--

Add widgets to object editor

#include "ldrawalgorithm.h"

std::pair<Triangle, Triangle> splitTriangles(
	const Quadrilateral& q,
	ldraw::Diagonal diagonal)
{
	std::pair<Triangle, Triangle> result;
	switch (diagonal)
	{
	case ldraw::Diagonal::Diagonal_13:
		result = {Triangle{q.p1, q.p2, q.p3}, {q.p1, q.p3, q.p4}};
		break;
	case ldraw::Diagonal::Diagonal_24:
		result = {Triangle{q.p1, q.p2, q.p3}, {q.p2, q.p3, q.p4}};
		break;
	}
	return result;
}

/**
 * @brief Modifies the !LDRAW_ORG line so that it becomes unofficial
 */
/*
void ldraw::makeUnofficial(ModelEditor& editor)
{
	if (editor.model().size() >= 4)
	{
		const ldraw::Object* ldrawOrgLine = editor.model()[3];
		if (isA<ldraw::MetaCommand>(ldrawOrgLine))
		{
			const QString& body = ldrawOrgLine->getProperty<ldraw::Property::Text>();
			if (body.startsWith("!LDRAW_ORG ") and not body.startsWith("!LDRAW_ORG Unofficial_"))
			{
				// Add Unofficial_ to part type
				QStringList tokens = body.split(" ");
				tokens[1] = "Unofficial_" + tokens[1];
				// Remove the UPDATE tag if it's there
				if (tokens.size() >= 4 && tokens[2] == "UPDATE")
				{
					tokens.removeAt(3);
					tokens.removeAt(2);
				}
				editor.setObjectProperty<ldraw::Property::Text>(ldrawOrgLine->id, tokens.join(" "));
			}
		}
	}
}
*/

ModelElement inverted(const ModelElement& element)
{
	return std::visit(overloaded{
		[](Colored<SubfileReference> ref) -> ModelElement {
			ref.inverted = not ref.inverted;
			return ref;
		},
		[](Colored<CircularPrimitive> circ) -> ModelElement {
			circ.inverted = not circ.inverted;
			return circ;
		},
		[](Colored<Triangle> triangle) -> ModelElement {
			std::swap(triangle.p1, triangle.p2);
			return triangle;
		},
		[](Colored<Quadrilateral> quad) -> ModelElement {
			std::swap(quad.p2, quad.p4);
			return quad;
		},
		[](const ModelElement& x) { return x; }
	}, element);
}

mercurial