src/linetypes/polygonobject.h

Sun, 25 Jul 2021 20:29:14 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 25 Jul 2021 20:29:14 +0300
changeset 111
1f42c03fafca
parent 93
6fe24fd945c0
child 132
488d0ba6070b
permissions
-rw-r--r--

Draw tool actually adds objects now

#pragma once
#include "object.h"
#include "widgets/vec3editor.h"
#include "model.h"
#include "modeleditcontext.h"

namespace ldraw
{
	template<int N, typename>
	class PolygonObject;
}

template<int N, typename = std::enable_if_t<(N > 0 and N <= 4)>>
class ldraw::PolygonObject : public ColoredObject
{
public:
	using BaseClass = ColoredObject;
	PolygonObject(const std::array<glm::vec3, N>& points, const Color color) :
		ColoredObject{color},
		points{points} {}
	int numPoints() const override
	{
		return N;
	}
	const glm::vec3& getPoint(int index) const override
	{
		Q_ASSERT(index >= 0 and index < N);
		return this->points[index];
	}
	QVariant getProperty(const Property id) const override
	{
		switch (id)
		{
		case Property::Point0:
			return QVariant::fromValue(points[0]);
		case Property::Point1:
			return QVariant::fromValue(points[1]);
		case Property::Point2:
			if (N >= 3)
			{
				return QVariant::fromValue(points[2]);
			}
			break;
		case Property::Point3:
			if (N >= 4)
			{
				return QVariant::fromValue(points[3]);
			}
			break;
		default:
			break;
		}
		return BaseClass::getProperty(id);
	}
	void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) override
	{
		LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point0, {points[0] = value;})
		LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point1, {points[1] = value;})
		if constexpr (N >= 3)
		{
			LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point2, {points[2] = value;})
		}
		if constexpr (N >= 4)
		{
			LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point3, {points[3] = value;})
		}
		ColoredObject::setProperty(result, pair);
	}
	std::array<glm::vec3, N> points;
};

mercurial