src/linetypes/subfilereference.cpp

Sun, 26 Jan 2020 01:06:27 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 26 Jan 2020 01:06:27 +0200
changeset 32
767592024ec5
parent 26
3a9e761e4faa
child 33
4c41bfe2ec6e
permissions
-rw-r--r--

fix default angle

#include "subfilereference.h"
#include "documentmanager.h"
#include "invert.h"

linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation,
	const QString& referenceName,
	const Color color) :
	ColoredObject{color},
	transformation{transformation},
	referenceName{referenceName}
{
}

QVariant linetypes::SubfileReference::getProperty(Property property) const
{
	switch (property)
	{
	case Property::Transformation:
		return QVariant::fromValue(this->transformation);
	case Property::ReferenceName:
		return this->referenceName;
	default:
		return ColoredObject::getProperty(property);
	}
}

auto linetypes::SubfileReference::setProperty(
	Property property,
	const QVariant& value)
	-> SetPropertyResult
{
	switch (property)
	{
	case Property::Transformation:
		this->transformation = value.value<Matrix4x4>();
		return SetPropertyResult::Success;
	case Property::ReferenceName:
		this->referenceName = value.toString();
		return SetPropertyResult::Success;
	default:
		return ColoredObject::setProperty(property, value);
	}
}

QString linetypes::SubfileReference::textRepresentation() const
{
	return referenceName + " " + vertexToStringParens(this->position());
}

void linetypes::SubfileReference::getPolygons(
	std::vector<gl::Polygon>& polygons,
	GetPolygonsContext* context) const
{
	Model* model = this->resolve(context->documents);
	if (model != nullptr)
	{
		const bool needInverting = math::det(this->transformation) < 0;
		const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents);
		polygons.reserve(polygons.size() + modelPolygons.size());
		for (gl::Polygon polygon : modelPolygons)
		{
			for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
			{
				polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation);
			}
			if (needInverting != this->isInverted)
			{
				gl::invert(polygon);
			}
			if (polygon.color == colors::main)
			{
				polygon.color = this->colorIndex;
			}
			polygon.id = this->id;
			polygons.push_back(polygon);
		}
	}
}

Point3D linetypes::SubfileReference::position() const
{
	return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)};
}

void linetypes::SubfileReference::invert()
{
	this->isInverted = not this->isInverted;
}

Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const
{
	return documents->findModelByName(this->referenceName);
}

mercurial