src/linetypes/subfilereference.cpp

Sun, 19 Jan 2020 02:54:48 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 19 Jan 2020 02:54:48 +0200
changeset 22
6da867fa5429
parent 21
0133e565e072
child 23
3387a84ddaba
permissions
-rw-r--r--

commit work on GL rendering

#include "subfilereference.h"
#include "documentmanager.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 std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents);
		polygons.reserve(polygons.size() + modelPolygons.size());
		for (gl::Polygon polygon : modelPolygons)
		{
			for (int i = 0; i < polygon.numPolygonVertices(); i += 1)
			{
				polygon.vertices[i] = math::transform(polygon.vertices[1], this->transformation);
			}
			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)};
}

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

mercurial