src/ldrawalgorithm.cpp

Fri, 01 Jul 2022 16:46:43 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Fri, 01 Jul 2022 16:46:43 +0300
changeset 312
2637134bc37c
parent 264
76a025db4948
child 333
07e65a4c6611
permissions
-rw-r--r--

Fix right click to delete not really working properly
Instead of removing the point that had been added, it would remove
the point that is being drawn, which would cause it to overwrite the
previous point using the new point, causing a bit of a delay

#include "src/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;
}

std::vector<ModelAction> ldraw::makeUnofficial(const Model* model)
{
	std::vector<ModelAction> actions;
	if (model->size() >= 4) {
		if (const Comment* comment = std::get_if<Comment>(&(*model)[3])) {
			const QString& body = comment->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);
				}
				actions.push_back(ModifyModel{
					.position = 3,
					.newElement = Comment{.text = tokens.join(" ")}
				});
			}
		}
	}
	return actions;
}

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