Thu, 19 Mar 2020 21:06:06 +0200
PolygonObjectEditor can now modify the object properly
#include "triangle.h" ldraw::Triangle::Triangle( const glm::vec3& point_1, const glm::vec3& point_2, const glm::vec3& point_3, Color color_index) : ColoredObject{color_index}, points{point_1, point_2, point_3} { } ldraw::Triangle::Triangle(const std::array<glm::vec3, 3>& vertices, const Color color) : ColoredObject{color}, points{vertices[0], vertices[1], vertices[2]} { } ldraw::Triangle::Triangle(const glm::vec3 (&vertices)[3], const Color color) : ColoredObject{color}, points{vertices[0], vertices[1], vertices[2]} { } QVariant ldraw::Triangle::getProperty(const Property id) const { switch (id) { case Property::Point0: return QVariant::fromValue(points[0]); case Property::Point1: return QVariant::fromValue(points[1]); case Property::Point2: return QVariant::fromValue(points[2]); default: return ColoredObject::getProperty(id); } } void ldraw::Triangle::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) { LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point0, {points[0] = value;}) LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point1, {points[1] = value;}) LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point2, {points[2] = value;}) ColoredObject::setProperty(result, pair); } QString ldraw::Triangle::textRepresentation() const { return utility::format("%1 %2 %3", utility::vertexToStringParens(points[0]), utility::vertexToStringParens(points[1]), utility::vertexToStringParens(points[2])); } void ldraw::Triangle::getPolygons( std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const { Q_UNUSED(context) polygons.push_back(gl::triangle( this->points[0], this->points[1], this->points[2], this->colorIndex, this->id)); } void ldraw::Triangle::invert() { // 0 1 2 // -> 1 0 2 std::swap(this->points[0], this->points[1]); } int ldraw::Triangle::numPoints() const { return 3; } const glm::vec3& ldraw::Triangle::getPoint(int index) const { if (index >= 0 and index < 3) { return this->points[index]; } else { return ldraw::ColoredObject::getPoint(index); } }