src/ldrawalgorithm.cpp

Sat, 08 Apr 2023 15:08:19 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 08 Apr 2023 15:08:19 +0300
changeset 346
3e3784c4cd3e
parent 338
719b909a7d2b
permissions
-rw-r--r--

Change color edit coloring to use only stylesheets to colorise the line edit only

#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