src/linetypes/edge.cpp

Sat, 29 Feb 2020 23:43:38 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 29 Feb 2020 23:43:38 +0200
changeset 64
f99d52b1646b
parent 35
98906a94732f
child 77
028798a72591
permissions
-rw-r--r--

grid snapping now also works with transformed grids

#include "edge.h"

ldraw::Edge::Edge(
	const glm::vec3& point_1,
	const glm::vec3& point_2,
	const Color color_index) :
	ColoredObject{color_index},
	point_1{point_1},
	point_2{point_2} {}

ldraw::Edge::Edge(const QVector<glm::vec3>& vertices, const Color color) :
	ColoredObject{color},
	point_1{vertices[0]},
	point_2{vertices[1]}
{
}

QVariant ldraw::Edge::getProperty(Property property) const
{
	switch (property)
	{
	case Property::Point1:
		return QVariant::fromValue(point_1);
	case Property::Point2:
		return QVariant::fromValue(point_2);
	default:
		return BaseClass::getProperty(property);
	}
}

auto ldraw::Edge::setProperty(Property property, const QVariant& value)
	-> SetPropertyResult
{
	switch (property)
	{
	case Property::Point1:
		point_1 = value.value<glm::vec3>();
		return SetPropertyResult::Success;
	case Property::Point2:
		point_2 = value.value<glm::vec3>();
		return SetPropertyResult::Success;
	default:
		return BaseClass::setProperty(property, value);
	}
}

QString ldraw::Edge::textRepresentation() const
{
	return utility::format("%1 %2", utility::vertexToStringParens(point_1), utility::vertexToStringParens(point_2));
}

void ldraw::Edge::getPolygons(
	std::vector<gl::Polygon>& polygons,
	GetPolygonsContext* context) const
{
	Q_UNUSED(context)
	polygons.push_back(gl::edgeLine(this->point_1, this->point_2, this->colorIndex, this->id));
}

mercurial