Mon, 24 Aug 2020 22:55:37 +0300
add comments
#pragma once #include <QPointF> #include <QString> #include <QStringView> #include "main.h" #include "colors.h" #include "gl/common.h" namespace ldraw { struct GetPolygonsContext; enum class Property; class Object; class ColoredObject; class Empty; class UnhandledProperty; } class DocumentManager; struct ldraw::GetPolygonsContext { ::DocumentManager* documents; }; /** * @brief Different properties that can be queried with getProperty */ enum class ldraw::Property { Color, // Color of the object Text, // Text contained in a comment Point1, // First vertex in a polygon or edge line Point2, // Second vertex in a polygon or edge line Point3, // Third vertex in a polygon Point4, // Fourth vertex in a quadrilateral ControlPoint1, // First control point in a conditional edge line ControlPoint2, // Second control point in a conditional edge line Transformation, // 4x4 transformation matrix of a subfile reference ReferenceName, // Subfile reference name IsInverted, // Whether or not the object has been inverted with BFC INVERTNEXT ErrorMessage // For error lines, why parsing failed }; // Mapping of properties to types #define LDFORGE_DEFINE_PROPERTY_TYPE(PROPERTY, TYPE) \ namespace ldraw { \ template<> struct PropertyType<ldraw::Property::PROPERTY> { using type = TYPE; }; \ } namespace ldraw { template<ldraw::Property property> struct PropertyType { }; template<ldraw::Property property> using PropertyType_t = typename PropertyType<property>::type; } LDFORGE_DEFINE_PROPERTY_TYPE(Color, int) LDFORGE_DEFINE_PROPERTY_TYPE(Text, QString) LDFORGE_DEFINE_PROPERTY_TYPE(Point1, glm::vec3) LDFORGE_DEFINE_PROPERTY_TYPE(Point2, glm::vec3) LDFORGE_DEFINE_PROPERTY_TYPE(Point3, glm::vec3) LDFORGE_DEFINE_PROPERTY_TYPE(Point4, glm::vec3) LDFORGE_DEFINE_PROPERTY_TYPE(ControlPoint1, glm::vec3) LDFORGE_DEFINE_PROPERTY_TYPE(ControlPoint2, glm::vec3) LDFORGE_DEFINE_PROPERTY_TYPE(Transformation, glm::mat4) LDFORGE_DEFINE_PROPERTY_TYPE(ReferenceName, QString) LDFORGE_DEFINE_PROPERTY_TYPE(IsInverted, bool) LDFORGE_DEFINE_PROPERTY_TYPE(ErrorMessage, QString) class ldraw::Object { public: enum class SetPropertyResult { Success = 0, PropertyNotHandled, InvalidValue }; Object(); Object(const Object&) = delete; virtual ~Object(); const id_t id; //virtual void toString(QTextStream &out) = 0; virtual bool hasColor() const; virtual QVariant getProperty(Property id) const; virtual SetPropertyResult setProperty(Property id, const QVariant& value); virtual QString textRepresentation() const = 0; virtual QBrush textRepresentationForeground() const; virtual QBrush textRepresentationBackground() const; virtual QFont textRepresentationFont() const; virtual void getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const; virtual void invert() {} }; class ldraw::ColoredObject : public Object { public: ColoredObject(const Color colorIndex = ldraw::mainColor); bool hasColor() const override final; QVariant getProperty(Property id) const override; SetPropertyResult setProperty(Property id, const QVariant& value) override; Color colorIndex = ldraw::mainColor; }; /** * @brief Represents an empty line. */ class ldraw::Empty : public Object { QString textRepresentation() const override; };