src/ldrawalgorithm.cpp

Sat, 23 Jul 2022 01:38:43 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 23 Jul 2022 01:38:43 +0300
changeset 340
e17e07661f4c
parent 338
719b909a7d2b
permissions
-rw-r--r--

Merge commit

#include <QTextBlock>
#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 QTextDocument* model)
{
	std::vector<ModelAction> actions;
	constexpr int ldrawOrgLinePosition = 3;
	const QTextBlock block = model->findBlockByLineNumber(ldrawOrgLinePosition);
	if (block.isValid()) {
		const QString body = block.text().simplified();
		if (body.startsWith("0 !LDRAW_ORG ") and not body.startsWith("0 !LDRAW_ORG Unofficial_")) {
			// Add Unofficial_ to part type
			QStringList tokens = body.split(" ");
			tokens[2] = "Unofficial_" + tokens[2];
			// Remove the UPDATE tag if it's there
			if (tokens.size() >= 5 && tokens[3] == "UPDATE")
			{
				tokens.removeAt(4);
				tokens.removeAt(3);
			}
			actions.push_back(ModifyModel{
				.position = ldrawOrgLinePosition,
				.newElement = Comment{.text = tokens.mid(1).join(" ")}
			});
		}
	}
	return actions;
}

mercurial