# HG changeset patch # User Teemu Piippo # Date 1580404811 -7200 # Node ID 98906a94732f61088c37e561eac472a52c0cb155 # Parent 1de2b8d64e9fb3c108fbd40d46b5a7ba7965fae0 renamed the linetypes namespace to ldraw namespace and added more structures to it diff -r 1de2b8d64e9f -r 98906a94732f locale/fi.ts --- a/locale/fi.ts Tue Jan 28 23:34:49 2020 +0200 +++ b/locale/fi.ts Thu Jan 30 19:20:11 2020 +0200 @@ -189,7 +189,7 @@ PartRenderer - + Rendering error diff -r 1de2b8d64e9f -r 98906a94732f src/colors.cpp --- a/src/colors.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/colors.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -18,14 +18,14 @@ #include "colors.h" -const ColorTable::ColorDefinition ColorTable::unknownColor{{}, {}, "Unknown"}; +const ldraw::ColorTable::ColorDefinition ldraw::ColorTable::unknownColor{{}, {}, "Unknown"}; -void ColorTable::clear() +void ldraw::ColorTable::clear() { definitions = {}; } -Result ColorTable::load(QIODevice& device, QTextStream& errors) +Result ldraw::ColorTable::load(QIODevice& device, QTextStream& errors) { this->clear(); if (device.isReadable()) @@ -45,7 +45,7 @@ } } -const ColorTable::ColorDefinition& ColorTable::operator[](Color color) const +const ldraw::ColorTable::ColorDefinition& ldraw::ColorTable::operator[](Color color) const { auto it = this->definitions.find(color.index); if (it != this->definitions.end()) @@ -58,7 +58,7 @@ } } -void ColorTable::loadColorFromString(const QString& string) +void ldraw::ColorTable::loadColorFromString(const QString& string) { const QRegExp pattern{ R"(^\s*0 \!COLOUR\s+([^\s]+)\s+)"_q + diff -r 1de2b8d64e9f -r 98906a94732f src/colors.h --- a/src/colors.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/colors.h Thu Jan 30 19:20:11 2020 +0200 @@ -20,12 +20,18 @@ #include #include "main.h" -struct Color +namespace ldraw +{ + struct Color; + class ColorTable; +} + +struct ldraw::Color { qint32 index; }; -class ColorTable +class ldraw::ColorTable { public: struct ColorDefinition @@ -43,37 +49,37 @@ QMap definitions; }; -inline bool operator==(const Color& one, const Color& other) +inline bool operator==(const ldraw::Color& one, const ldraw::Color& other) { return one.index == other.index; } -inline bool operator!=(const Color& one, const Color& other) +inline bool operator!=(const ldraw::Color& one, const ldraw::Color& other) { return one.index != other.index; } -inline bool operator<(const Color& one, const Color& other) +inline bool operator<(const ldraw::Color& one, const ldraw::Color& other) { return one.index < other.index; } -inline bool operator<=(const Color& one, const Color& other) +inline bool operator<=(const ldraw::Color& one, const ldraw::Color& other) { return one.index <= other.index; } -inline bool operator>(const Color& one, const Color& other) +inline bool operator>(const ldraw::Color& one, const ldraw::Color& other) { return one.index > other.index; } -inline bool operator>=(const Color& one, const Color& other) +inline bool operator>=(const ldraw::Color& one, const ldraw::Color& other) { return one.index >= other.index; } -namespace colors +namespace ldraw { static constexpr Color black {0}; static constexpr Color blue {1}; @@ -81,6 +87,6 @@ static constexpr Color red {4}; static constexpr Color yellow {14}; static constexpr Color white {15}; - static constexpr Color main {16}; - static constexpr Color edge {24}; + static constexpr Color mainColor {16}; + static constexpr Color edgeColor {24}; } diff -r 1de2b8d64e9f -r 98906a94732f src/document.cpp --- a/src/document.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/document.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -20,7 +20,11 @@ #include "ui_document.h" #include "model.h" -Document::Document(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget* parent) : +Document::Document( + Model* model, + DocumentManager* documents, + const ldraw::ColorTable& colorTable, + QWidget* parent) : QWidget{parent}, model{model}, documents{documents}, diff -r 1de2b8d64e9f -r 98906a94732f src/document.h --- a/src/document.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/document.h Thu Jan 30 19:20:11 2020 +0200 @@ -32,7 +32,11 @@ { Q_OBJECT public: - explicit Document(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget *parent = nullptr); + explicit Document( + Model* model, + DocumentManager* documents, + const ldraw::ColorTable& colorTable, + QWidget *parent = nullptr); ~Document(); QByteArray saveSplitterState() const; void restoreSplitterState(const QByteArray& state); @@ -41,7 +45,7 @@ private: Model* model; DocumentManager* const documents; - const ColorTable& colorTable; + const ldraw::ColorTable& colorTable; PartRenderer* renderer; Ui::Document& ui; }; diff -r 1de2b8d64e9f -r 98906a94732f src/documentmanager.cpp --- a/src/documentmanager.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/documentmanager.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -161,7 +161,7 @@ Model* model = this->findModelByName(modelName); for (int i = 0; i < model->size(); i += 1) { - const QString referenceName = model->getObjectProperty(i, linetypes::Property::ReferenceName).toString(); + const QString referenceName = model->getObjectProperty(i, ldraw::Property::ReferenceName).toString(); if (not referenceName.isEmpty() and openModels.find(referenceName) == std::end(openModels) and not missing.contains(referenceName)) diff -r 1de2b8d64e9f -r 98906a94732f src/gl/common.h --- a/src/gl/common.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/gl/common.h Thu Jan 30 19:20:11 2020 +0200 @@ -47,8 +47,8 @@ }; Type type; glm::vec3 vertices[4]; - Color color; - linetypes::Id id; + ldraw::Color color; + ldraw::Id id; /** * @return amount of vertices used for geometry @@ -84,7 +84,7 @@ namespace gl { - inline Polygon edgeLine(const glm::vec3& v_1, const glm::vec3& v_2, Color color, linetypes::Id id) + inline Polygon edgeLine(const glm::vec3& v_1, const glm::vec3& v_2, ldraw::Color color, ldraw::Id id) { return {Polygon::EdgeLine, {v_1, v_2}, color, id}; } @@ -93,8 +93,8 @@ const glm::vec3& v_1, const glm::vec3& v_2, const glm::vec3& v_3, - Color color, - linetypes::Id id) + ldraw::Color color, + ldraw::Id id) { return {Polygon::Triangle, {v_1, v_2, v_3}, color, id}; } @@ -104,8 +104,8 @@ const glm::vec3& v_2, const glm::vec3& v_3, const glm::vec3& v_4, - Color color, - linetypes::Id id) + ldraw::Color color, + ldraw::Id id) { return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id}; } @@ -115,8 +115,8 @@ const glm::vec3& v_2, const glm::vec3& control_1, const glm::vec3& control_2, - Color color, - linetypes::Id id) + ldraw::Color color, + ldraw::Id id) { return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id}; } @@ -129,6 +129,7 @@ Quads, ConditionalLines }; + constexpr ArrayClass ARRAY_CLASSES[] = {ArrayClass::Lines, ArrayClass::Triangles, ArrayClass::Quads, ArrayClass::ConditionalLines}; constexpr int NUM_ARRAY_CLASSES = countof(ARRAY_CLASSES); constexpr int FLOATS_PER_VERTEX = 7; diff -r 1de2b8d64e9f -r 98906a94732f src/gl/compiler.cpp --- a/src/gl/compiler.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/gl/compiler.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -68,7 +68,7 @@ } )"; -gl::Compiler::Compiler(const ColorTable& colorTable, QObject* parent) : +gl::Compiler::Compiler(const ldraw::ColorTable& colorTable, QObject* parent) : QObject{parent}, colorTable{colorTable} { @@ -163,7 +163,7 @@ } [[maybe_unused]] -static QColor colorFromId(linetypes::Id id) +static QColor colorFromId(ldraw::Id id) { // Calculate a color based from this index. This method caters for // 16777216 objects. I don't think that will be exceeded anytime soon. @@ -197,11 +197,11 @@ { QColor color; // For normal colors, use the polygon's color. - if (polygon.color == colors::main) + if (polygon.color == ldraw::mainColor) { color = {255, 255, 64}; // mainColorRepresentation(); } - else if (polygon.color == colors::edge) + else if (polygon.color == ldraw::edgeColor) { // Edge color is black, unless we have a dark background, in which case lines need to be bright. color = Qt::black; //luma(config::backgroundColor()) > 40 ? Qt::black : Qt::white; diff -r 1de2b8d64e9f -r 98906a94732f src/gl/compiler.h --- a/src/gl/compiler.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/gl/compiler.h Thu Jan 30 19:20:11 2020 +0200 @@ -46,7 +46,7 @@ { Q_OBJECT public: - Compiler(const ColorTable& colorTable, QObject* parent); + Compiler(const ldraw::ColorTable& colorTable, QObject* parent); ~Compiler(); void build(Model* model, DocumentManager* context); void buildPolygon(Polygon polygon, std::vector* vboData); @@ -83,7 +83,7 @@ std::size_t storedVertexCounts[gl::NUM_ARRAY_CLASSES] = {0_z}; bool initialized = false; BoundingBox boundingBox; - const ColorTable& colorTable; + const ldraw::ColorTable& colorTable; struct { QOpenGLShaderProgram* program = nullptr; diff -r 1de2b8d64e9f -r 98906a94732f src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/gl/partrenderer.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -23,7 +23,11 @@ #include #include "partrenderer.h" -PartRenderer::PartRenderer(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget* parent) : +PartRenderer::PartRenderer( + Model* model, + DocumentManager* documents, + const ldraw::ColorTable& colorTable, + QWidget* parent) : QOpenGLWidget{parent}, model{model}, documents{documents}, diff -r 1de2b8d64e9f -r 98906a94732f src/gl/partrenderer.h --- a/src/gl/partrenderer.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/gl/partrenderer.h Thu Jan 30 19:20:11 2020 +0200 @@ -15,7 +15,11 @@ { Q_OBJECT public: - PartRenderer(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget* parent = nullptr); + PartRenderer( + Model* model, + DocumentManager* documents, + const ldraw::ColorTable& colorTable, + QWidget* parent = nullptr); ~PartRenderer() override; protected: void initializeGL() override; @@ -30,7 +34,7 @@ void updateViewMatrix(); Model* const model; DocumentManager* const documents; - const ColorTable& colorTable; + const ldraw::ColorTable& colorTable; QPointF lastMousePosition; gl::Compiler* compiler; gl::RenderStyle renderStyle = gl::RenderStyle::Normal; diff -r 1de2b8d64e9f -r 98906a94732f src/libraries.cpp --- a/src/libraries.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/libraries.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -220,9 +220,9 @@ * @param errors Where to stream any encountered errors * @return color table */ -ColorTable LibraryManager::loadColorTable(QTextStream& errors) +ldraw::ColorTable LibraryManager::loadColorTable(QTextStream& errors) { - ColorTable result; + ldraw::ColorTable result; for (const Library& library : this->libraries) { const QString path = library.path.filePath("LDConfig.ldr"); diff -r 1de2b8d64e9f -r 98906a94732f src/libraries.h --- a/src/libraries.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/libraries.h Thu Jan 30 19:20:11 2020 +0200 @@ -74,7 +74,7 @@ int rowCount(const QModelIndex&) const override; int columnCount(const QModelIndex&) const override; bool isValidIndex(const int libraryIndex) const; - ColorTable loadColorTable(QTextStream& errors); + ldraw::ColorTable loadColorTable(QTextStream& errors); private: enum Column { diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/comment.cpp --- a/src/linetypes/comment.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/comment.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,7 +1,7 @@ #include #include "comment.h" -QFont linetypes::Comment::textRepresentationFont() const +QFont ldraw::Comment::textRepresentationFont() const { QFont font; font.setItalic(true); diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/comment.h --- a/src/linetypes/comment.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/comment.h Thu Jan 30 19:20:11 2020 +0200 @@ -2,12 +2,12 @@ #include "object.h" #include "metacommand.h" -namespace linetypes +namespace ldraw { class Comment; } -class linetypes::Comment : public MetaCommand +class ldraw::Comment : public MetaCommand { using MetaCommand::MetaCommand; QFont textRepresentationFont() const override; diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/conditionaledge.cpp --- a/src/linetypes/conditionaledge.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/conditionaledge.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,6 +1,6 @@ #include "conditionaledge.h" -linetypes::ConditionalEdge::ConditionalEdge( +ldraw::ConditionalEdge::ConditionalEdge( const glm::vec3& point_1, const glm::vec3& point_2, const glm::vec3& controlPoint_1, @@ -12,14 +12,14 @@ { } -linetypes::ConditionalEdge::ConditionalEdge(const QVector& vertices, const Color color) : +ldraw::ConditionalEdge::ConditionalEdge(const QVector& vertices, const Color color) : Edge{vertices[0], vertices[1], color}, controlPoint_1{vertices[2]}, controlPoint_2{vertices[3]} { } -QVariant linetypes::ConditionalEdge::getProperty(Property property) const +QVariant ldraw::ConditionalEdge::getProperty(Property property) const { switch (property) { @@ -32,7 +32,7 @@ } } -auto linetypes::ConditionalEdge::setProperty( +auto ldraw::ConditionalEdge::setProperty( Property property, const QVariant& value) -> SetPropertyResult @@ -48,7 +48,7 @@ } } -QString linetypes::ConditionalEdge::textRepresentation() const +QString ldraw::ConditionalEdge::textRepresentation() const { return Edge::textRepresentation() + utility::format("%1 %2", utility::vertexToStringParens(controlPoint_1), diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/conditionaledge.h --- a/src/linetypes/conditionaledge.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/conditionaledge.h Thu Jan 30 19:20:11 2020 +0200 @@ -1,12 +1,12 @@ #pragma once #include "edge.h" -namespace linetypes +namespace ldraw { class ConditionalEdge; } -class linetypes::ConditionalEdge : public Edge +class ldraw::ConditionalEdge : public Edge { public: ConditionalEdge() = default; @@ -15,7 +15,7 @@ const glm::vec3& point_2, const glm::vec3& controlPoint_1, const glm::vec3& controlPoint_2, - const Color colorIndex = colors::edge); + const Color colorIndex = ldraw::edgeColor); ConditionalEdge(const QVector& vertices, const Color color); QVariant getProperty(Property property) const override; SetPropertyResult setProperty( diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/edge.cpp --- a/src/linetypes/edge.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/edge.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,6 +1,6 @@ #include "edge.h" -linetypes::Edge::Edge( +ldraw::Edge::Edge( const glm::vec3& point_1, const glm::vec3& point_2, const Color color_index) : @@ -8,14 +8,14 @@ point_1{point_1}, point_2{point_2} {} -linetypes::Edge::Edge(const QVector& vertices, const Color color) : +ldraw::Edge::Edge(const QVector& vertices, const Color color) : ColoredObject{color}, point_1{vertices[0]}, point_2{vertices[1]} { } -QVariant linetypes::Edge::getProperty(Property property) const +QVariant ldraw::Edge::getProperty(Property property) const { switch (property) { @@ -28,7 +28,7 @@ } } -auto linetypes::Edge::setProperty(Property property, const QVariant& value) +auto ldraw::Edge::setProperty(Property property, const QVariant& value) -> SetPropertyResult { switch (property) @@ -44,12 +44,12 @@ } } -QString linetypes::Edge::textRepresentation() const +QString ldraw::Edge::textRepresentation() const { return utility::format("%1 %2", utility::vertexToStringParens(point_1), utility::vertexToStringParens(point_2)); } -void linetypes::Edge::getPolygons( +void ldraw::Edge::getPolygons( std::vector& polygons, GetPolygonsContext* context) const { diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/edge.h --- a/src/linetypes/edge.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/edge.h Thu Jan 30 19:20:11 2020 +0200 @@ -1,18 +1,18 @@ #pragma once #include "object.h" -namespace linetypes +namespace ldraw { class Edge; } -class linetypes::Edge : public ColoredObject +class ldraw::Edge : public ColoredObject { public: using BaseClass = ColoredObject; Edge() = default; Edge(const glm::vec3& point_1, const glm::vec3& point_2, - const Color colorIndex = colors::edge); + const Color colorIndex = ldraw::edgeColor); Edge(const QVector& vertices, const Color color); QVariant getProperty(Property property) const override; SetPropertyResult setProperty( diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/errorline.cpp --- a/src/linetypes/errorline.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/errorline.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,13 +1,13 @@ #include #include "errorline.h" -linetypes::ErrorLine::ErrorLine(QStringView text, QStringView message) : +ldraw::ErrorLine::ErrorLine(QStringView text, QStringView message) : text{text.toString()}, message{message.toString()} { } -QVariant linetypes::ErrorLine::getProperty(Property property) const +QVariant ldraw::ErrorLine::getProperty(Property property) const { switch (property) { @@ -20,7 +20,7 @@ } } -auto linetypes::ErrorLine::setProperty( +auto ldraw::ErrorLine::setProperty( Property property, const QVariant& value) -> SetPropertyResult @@ -38,17 +38,17 @@ } } -QString linetypes::ErrorLine::textRepresentation() const +QString ldraw::ErrorLine::textRepresentation() const { return this->text; } -QBrush linetypes::ErrorLine::textRepresentationForeground() const +QBrush ldraw::ErrorLine::textRepresentationForeground() const { return QBrush{Qt::yellow}; } -QBrush linetypes::ErrorLine::textRepresentationBackground() const +QBrush ldraw::ErrorLine::textRepresentationBackground() const { return QBrush{Qt::red}; } diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/errorline.h --- a/src/linetypes/errorline.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/errorline.h Thu Jan 30 19:20:11 2020 +0200 @@ -1,12 +1,12 @@ #pragma once #include "object.h" -namespace linetypes +namespace ldraw { class ErrorLine; } -class linetypes::ErrorLine : public Object +class ldraw::ErrorLine : public Object { public: ErrorLine(QStringView text = u"", QStringView message = u""); diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/metacommand.cpp --- a/src/linetypes/metacommand.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/metacommand.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,10 +1,10 @@ #include "metacommand.h" -linetypes::MetaCommand::MetaCommand(QStringView text) : +ldraw::MetaCommand::MetaCommand(QStringView text) : Object{}, storedText{text.toString()} {} -QVariant linetypes::MetaCommand::getProperty(Property property) const +QVariant ldraw::MetaCommand::getProperty(Property property) const { switch (property) { @@ -15,7 +15,7 @@ } } -auto linetypes::MetaCommand::setProperty(Property property, const QVariant& value) +auto ldraw::MetaCommand::setProperty(Property property, const QVariant& value) -> SetPropertyResult { switch (property) @@ -28,7 +28,7 @@ } } -QString linetypes::MetaCommand::textRepresentation() const +QString ldraw::MetaCommand::textRepresentation() const { return this->storedText; } diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/metacommand.h --- a/src/linetypes/metacommand.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/metacommand.h Thu Jan 30 19:20:11 2020 +0200 @@ -1,11 +1,11 @@ #pragma once #include "object.h" -namespace linetypes +namespace ldraw { class MetaCommand; } -class linetypes::MetaCommand : public Object +class ldraw::MetaCommand : public Object { public: MetaCommand() = default; diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/object.cpp --- a/src/linetypes/object.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/object.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -9,27 +9,27 @@ return id; } -linetypes::Object::Object() : +ldraw::Object::Object() : id {getIdForNewObject()} { } -linetypes::Object::~Object() +ldraw::Object::~Object() { } -bool linetypes::Object::hasColor() const +bool ldraw::Object::hasColor() const { return false; } -QVariant linetypes::Object::getProperty(Property id) const +QVariant ldraw::Object::getProperty(Property id) const { Q_UNUSED(id); return {}; } -auto linetypes::Object::setProperty(Property id, const QVariant& value) +auto ldraw::Object::setProperty(Property id, const QVariant& value) -> SetPropertyResult { Q_UNUSED(id) @@ -37,38 +37,38 @@ return SetPropertyResult::PropertyNotHandled; } -QBrush linetypes::Object::textRepresentationForeground() const +QBrush ldraw::Object::textRepresentationForeground() const { return {}; } -QBrush linetypes::Object::textRepresentationBackground() const +QBrush ldraw::Object::textRepresentationBackground() const { return {}; } -QFont linetypes::Object::textRepresentationFont() const +QFont ldraw::Object::textRepresentationFont() const { return {}; } -void linetypes::Object::getPolygons(std::vector& polygons, GetPolygonsContext* context) const +void ldraw::Object::getPolygons(std::vector& polygons, GetPolygonsContext* context) const { Q_UNUSED(polygons) Q_UNUSED(context) } -linetypes::ColoredObject::ColoredObject(const Color color_index) : +ldraw::ColoredObject::ColoredObject(const Color color_index) : colorIndex{color_index} { } -bool linetypes::ColoredObject::hasColor() const +bool ldraw::ColoredObject::hasColor() const { return true; } -QVariant linetypes::ColoredObject::getProperty(Property id) const +QVariant ldraw::ColoredObject::getProperty(Property id) const { switch (id) { @@ -79,7 +79,7 @@ } } -auto linetypes::ColoredObject::setProperty(Property id, const QVariant& value) +auto ldraw::ColoredObject::setProperty(Property id, const QVariant& value) -> SetPropertyResult { switch (id) @@ -103,7 +103,7 @@ } } -QString linetypes::Empty::textRepresentation() const +QString ldraw::Empty::textRepresentation() const { return ""; } diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/object.h --- a/src/linetypes/object.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/object.h Thu Jan 30 19:20:11 2020 +0200 @@ -6,7 +6,7 @@ #include "colors.h" #include "gl/common.h" -namespace linetypes +namespace ldraw { struct GetPolygonsContext; enum class Property; @@ -17,7 +17,7 @@ class DocumentManager; -struct linetypes::GetPolygonsContext +struct ldraw::GetPolygonsContext { ::DocumentManager* documents; }; @@ -25,7 +25,7 @@ /** * @brief Different properties that can be queried with getProperty */ -enum class linetypes::Property +enum class ldraw::Property { Color, // Color of the object Text, // Text contained in a comment @@ -41,7 +41,7 @@ ErrorMessage // For error lines, why parsing failed }; -class linetypes::Object +class ldraw::Object { public: enum class SetPropertyResult @@ -66,21 +66,21 @@ virtual void invert() {} }; -class linetypes::ColoredObject : public Object +class ldraw::ColoredObject : public Object { public: - ColoredObject(const Color colorIndex = colors::main); + 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; protected: - Color colorIndex = colors::main; + Color colorIndex = ldraw::mainColor; }; /** * @brief Represents an empty line. */ -class linetypes::Empty : public Object +class ldraw::Empty : public Object { QString textRepresentation() const override; }; diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/quadrilateral.cpp --- a/src/linetypes/quadrilateral.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/quadrilateral.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,6 +1,6 @@ #include "quadrilateral.h" -linetypes::Quadrilateral::Quadrilateral( +ldraw::Quadrilateral::Quadrilateral( const glm::vec3& point_1, const glm::vec3& point_2, const glm::vec3& point_3, @@ -11,13 +11,13 @@ { } -linetypes::Quadrilateral::Quadrilateral(const QVector& vertices, const Color color) : +ldraw::Quadrilateral::Quadrilateral(const QVector& vertices, const Color color) : ColoredObject{color}, points{vertices[0], vertices[1], vertices[2], vertices[3]} { } -QVariant linetypes::Quadrilateral::getProperty(const Property id) const +QVariant ldraw::Quadrilateral::getProperty(const Property id) const { switch (id) { @@ -34,7 +34,7 @@ } } -auto linetypes::Quadrilateral::setProperty( +auto ldraw::Quadrilateral::setProperty( const Property id, const QVariant& value) -> SetPropertyResult @@ -58,7 +58,7 @@ } } -QString linetypes::Quadrilateral::textRepresentation() const +QString ldraw::Quadrilateral::textRepresentation() const { return utility::format("%1 %2 %3 %4", utility::vertexToStringParens(points[0]), @@ -67,7 +67,7 @@ utility::vertexToStringParens(points[3])); } -void linetypes::Quadrilateral::getPolygons( +void ldraw::Quadrilateral::getPolygons( std::vector& polygons, GetPolygonsContext* context) const { @@ -81,7 +81,7 @@ this->id)); } -void linetypes::Quadrilateral::invert() +void ldraw::Quadrilateral::invert() { // 0 1 2 3 // -> 2 1 0 3 diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/quadrilateral.h --- a/src/linetypes/quadrilateral.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/quadrilateral.h Thu Jan 30 19:20:11 2020 +0200 @@ -1,21 +1,21 @@ #pragma once #include "object.h" -namespace linetypes +namespace ldraw { class Quadrilateral; } -class linetypes::Quadrilateral : public ColoredObject +class ldraw::Quadrilateral : public ColoredObject { public: Quadrilateral() = default; Quadrilateral( - const glm::vec3 &point_1, - const glm::vec3 &point_2, - const glm::vec3 &point_3, - const glm::vec3 &point_4, - Color colorIndex = colors::main); + const glm::vec3 &point_1, + const glm::vec3 &point_2, + const glm::vec3 &point_3, + const glm::vec3 &point_4, + Color colorIndex = ldraw::mainColor); Quadrilateral(const QVector& vertices, const Color color); QVariant getProperty(Property id) const override; SetPropertyResult setProperty(Property id, const QVariant& value) override; diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/subfilereference.cpp --- a/src/linetypes/subfilereference.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/subfilereference.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -2,7 +2,7 @@ #include "documentmanager.h" #include "invert.h" -linetypes::SubfileReference::SubfileReference(const glm::mat4& transformation, +ldraw::SubfileReference::SubfileReference(const glm::mat4& transformation, const QString& referenceName, const Color color) : ColoredObject{color}, @@ -11,7 +11,7 @@ { } -QVariant linetypes::SubfileReference::getProperty(Property property) const +QVariant ldraw::SubfileReference::getProperty(Property property) const { switch (property) { @@ -24,7 +24,7 @@ } } -auto linetypes::SubfileReference::setProperty( +auto ldraw::SubfileReference::setProperty( Property property, const QVariant& value) -> SetPropertyResult @@ -42,12 +42,12 @@ } } -QString linetypes::SubfileReference::textRepresentation() const +QString ldraw::SubfileReference::textRepresentation() const { return referenceName + " " + utility::vertexToStringParens(this->position()); } -void linetypes::SubfileReference::getPolygons( +void ldraw::SubfileReference::getPolygons( std::vector& polygons, GetPolygonsContext* context) const { @@ -69,7 +69,7 @@ { gl::invert(polygon); } - if (polygon.color == colors::main) + if (polygon.color == ldraw::mainColor) { polygon.color = this->colorIndex; } @@ -79,17 +79,17 @@ } } -glm::vec3 linetypes::SubfileReference::position() const +glm::vec3 ldraw::SubfileReference::position() const { return {this->transformation[3][0], this->transformation[3][1], this->transformation[3][2]}; } -void linetypes::SubfileReference::invert() +void ldraw::SubfileReference::invert() { this->isInverted = not this->isInverted; } -Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const +Model* ldraw::SubfileReference::resolve(DocumentManager* documents) const { return documents->findModelByName(this->referenceName); } diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/subfilereference.h --- a/src/linetypes/subfilereference.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/subfilereference.h Thu Jan 30 19:20:11 2020 +0200 @@ -3,19 +3,19 @@ class Model; -namespace linetypes +namespace ldraw { class SubfileReference; } -class linetypes::SubfileReference : public ColoredObject +class ldraw::SubfileReference : public ColoredObject { public: SubfileReference() = default; SubfileReference( const glm::mat4& transformation, const QString &referenceName, - const Color color = colors::main); + const Color color = ldraw::mainColor); QVariant getProperty(Property property) const override; SetPropertyResult setProperty(Property property, const QVariant& value) override; QString textRepresentation() const override; diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/triangle.cpp --- a/src/linetypes/triangle.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/triangle.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -1,6 +1,6 @@ #include "triangle.h" -linetypes::Triangle::Triangle( +ldraw::Triangle::Triangle( const glm::vec3& point_1, const glm::vec3& point_2, const glm::vec3& point_3, @@ -10,13 +10,13 @@ { } -linetypes::Triangle::Triangle(const QVector& vertices, const Color color) : +ldraw::Triangle::Triangle(const QVector& vertices, const Color color) : ColoredObject{color}, points{vertices[0], vertices[1], vertices[2]} { } -QVariant linetypes::Triangle::getProperty(const Property id) const +QVariant ldraw::Triangle::getProperty(const Property id) const { switch (id) { @@ -31,7 +31,7 @@ } } -auto linetypes::Triangle::setProperty(Property id, const QVariant& value) +auto ldraw::Triangle::setProperty(Property id, const QVariant& value) -> SetPropertyResult { switch (id) @@ -50,7 +50,7 @@ } } -QString linetypes::Triangle::textRepresentation() const +QString ldraw::Triangle::textRepresentation() const { return utility::format("%1 %2 %3", utility::vertexToStringParens(points[0]), @@ -58,7 +58,7 @@ utility::vertexToStringParens(points[2])); } -void linetypes::Triangle::getPolygons( +void ldraw::Triangle::getPolygons( std::vector& polygons, GetPolygonsContext* context) const { @@ -71,7 +71,7 @@ this->id)); } -void linetypes::Triangle::invert() +void ldraw::Triangle::invert() { // 0 1 2 // -> 1 0 2 diff -r 1de2b8d64e9f -r 98906a94732f src/linetypes/triangle.h --- a/src/linetypes/triangle.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/linetypes/triangle.h Thu Jan 30 19:20:11 2020 +0200 @@ -1,11 +1,11 @@ #include "object.h" -namespace linetypes +namespace ldraw { class Triangle; } -class linetypes::Triangle : public ColoredObject +class ldraw::Triangle : public ColoredObject { public: Triangle() = default; @@ -13,7 +13,7 @@ const glm::vec3 &point_1, const glm::vec3 &point_2, const glm::vec3 &point_3, - Color colorIndex = colors::main); + Color colorIndex = ldraw::mainColor); Triangle(const QVector& vertices, const Color color); QVariant getProperty(Property id) const override; SetPropertyResult setProperty(Property id, const QVariant& value) override; diff -r 1de2b8d64e9f -r 98906a94732f src/main.cpp --- a/src/main.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/main.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -23,6 +23,7 @@ int main(int argc, char *argv[]) { + ldraw::Color color = ldraw::red; ::glutInit(&argc, argv); QCoreApplication::setApplicationName(::appName); QCoreApplication::setOrganizationName("hecknology.net"); diff -r 1de2b8d64e9f -r 98906a94732f src/main.h --- a/src/main.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/main.h Thu Jan 30 19:20:11 2020 +0200 @@ -31,13 +31,13 @@ constexpr char mainwindow[] = "mainwindow"; } -namespace linetypes +namespace ldraw { // Uniquely identifies a model body object struct Id { unsigned int value; - constexpr bool operator<(linetypes::Id other) const + constexpr bool operator<(ldraw::Id other) const { return this->value < other.value; } diff -r 1de2b8d64e9f -r 98906a94732f src/mainwindow.h --- a/src/mainwindow.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/mainwindow.h Thu Jan 30 19:20:11 2020 +0200 @@ -54,7 +54,7 @@ uiutilities::KeySequenceMap defaultKeyboardShortcuts; static constexpr int maxRecentlyOpenedFiles = 10; QStringList recentlyOpenedFiles; - ColorTable colorTable; + ldraw::ColorTable colorTable; void updateTitle(); void saveSettings(); void restoreSettings(); diff -r 1de2b8d64e9f -r 98906a94732f src/model.cpp --- a/src/model.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/model.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -42,7 +42,7 @@ QVariant Model::data(const QModelIndex& index, int role) const { const int row = index.row(); - linetypes::Object* object = this->body[row].get(); + ldraw::Object* object = this->body[row].get(); switch(role) { case Qt::DisplayRole: @@ -69,9 +69,9 @@ } } -QVariant Model::getObjectProperty(const int index, const linetypes::Property property) const +QVariant Model::getObjectProperty(const int index, const ldraw::Property property) const { - const linetypes::Object* object = this->body[index].get(); + const ldraw::Object* object = this->body[index].get(); return object->getProperty(property); } @@ -80,7 +80,7 @@ if (this->needRecache) { this->cachedPolygons.clear(); - linetypes::GetPolygonsContext context{documents}; + ldraw::GetPolygonsContext context{documents}; for (int i = 0; i < this->size(); i += 1) { this->getObjectPolygons(i, this->cachedPolygons, &context); @@ -93,9 +93,9 @@ void Model::getObjectPolygons( const int index, std::vector& polygons_out, - linetypes::GetPolygonsContext* context) const + ldraw::GetPolygonsContext* context) const { - const linetypes::Object* object = this->body[index].get(); + const ldraw::Object* object = this->body[index].get(); object->getPolygons(polygons_out, context); } diff -r 1de2b8d64e9f -r 98906a94732f src/model.h --- a/src/model.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/model.h Thu Jan 30 19:20:11 2020 +0200 @@ -42,33 +42,33 @@ QVariant data(const QModelIndex& index, int role) const override; QVariant getHeaderProperty(const HeaderProperty property); const QString& getName() const; - QVariant getObjectProperty(const int index, const linetypes::Property property) const; + QVariant getObjectProperty(const int index, const ldraw::Property property) const; std::vector getPolygons(class DocumentManager* documents) const; - void getObjectPolygons(const int index, std::vector& polygons_out, linetypes::GetPolygonsContext* context) const; + void getObjectPolygons(const int index, std::vector& polygons_out, ldraw::GetPolygonsContext* context) const; signals: - void objectAdded(linetypes::Id id, int position); + void objectAdded(ldraw::Id id, int position); private: - using ModelObjectPointer = std::unique_ptr; + using ModelObjectPointer = std::unique_ptr; template - linetypes::Id append(Args&&... args); + ldraw::Id append(Args&&... args); void append(ModelObjectPointer&& object); template - linetypes::Id insert(int position, Args&&... args); + ldraw::Id insert(int position, Args&&... args); bool modified = false; QString path; LDHeader header; std::vector body; - std::map objectsById; + std::map objectsById; mutable std::vector cachedPolygons; mutable bool needRecache = true; }; template -linetypes::Id Model::append(Args&&... args) +ldraw::Id Model::append(Args&&... args) { emit layoutAboutToBeChanged(); this->body.push_back(std::make_unique(args...)); - linetypes::Object* pointer = this->body.back().get(); + ldraw::Object* pointer = this->body.back().get(); this->objectsById[pointer->id] = pointer; emit objectAdded(pointer->id, this->body.size() - 1); emit layoutChanged(); @@ -76,11 +76,11 @@ } template -linetypes::Id Model::insert(int position, Args&&... args) +ldraw::Id Model::insert(int position, Args&&... args) { emit layoutAboutToBeChanged(); this->body.insert(position, std::make_unique(args...)); - linetypes::Object* pointer = this->body[position].get(); + ldraw::Object* pointer = this->body[position].get(); this->objectsById[pointer->id] = pointer; emit objectAdded(pointer->id, position); emit layoutChanged(); diff -r 1de2b8d64e9f -r 98906a94732f src/modeleditcontext.cpp --- a/src/modeleditcontext.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/modeleditcontext.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -23,28 +23,28 @@ { } -linetypes::Id Model::EditContext::append(std::unique_ptr&& object) +ldraw::Id Model::EditContext::append(std::unique_ptr&& object) { - const linetypes::Id id = object->id; + const ldraw::Id id = object->id; this->model.objectsById[id] = object.get(); this->model.append(std::move(object)); return id; } void Model::EditContext::setObjectProperty( - linetypes::Object* object, - linetypes::Property property, + ldraw::Object* object, + ldraw::Property property, const QVariant& value) { object->setProperty(property, value); } -void Model::EditContext::invertObject(linetypes::Id id) +void Model::EditContext::invertObject(ldraw::Id id) { auto it = this->model.objectsById.find(id); if (it != this->model.objectsById.end()) { - linetypes::Object* object = it->second; + ldraw::Object* object = it->second; object->invert(); } } diff -r 1de2b8d64e9f -r 98906a94732f src/modeleditcontext.h --- a/src/modeleditcontext.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/modeleditcontext.h Thu Jan 30 19:20:11 2020 +0200 @@ -24,15 +24,15 @@ { public: template - linetypes::Id append(Args&&... args); - linetypes::Id append(std::unique_ptr&& object); + ldraw::Id append(Args&&... args); + ldraw::Id append(std::unique_ptr&& object); template - linetypes::Id insert(int position, Args&&... args); + ldraw::Id insert(int position, Args&&... args); void setObjectProperty( - linetypes::Object* object, - linetypes::Property property, + ldraw::Object* object, + ldraw::Property property, const QVariant &value); - void invertObject(linetypes::Id id); + void invertObject(ldraw::Id id); private: EditContext(Model& model); friend class Model; @@ -40,13 +40,13 @@ }; template -linetypes::Id Model::EditContext::append(Args&&... args) +ldraw::Id Model::EditContext::append(Args&&... args) { return this->model.append(args...); } template -linetypes::Id Model::EditContext::insert(int position, Args&&... args) +ldraw::Id Model::EditContext::insert(int position, Args&&... args) { return this->model.insert(position, args...); } diff -r 1de2b8d64e9f -r 98906a94732f src/parser.cpp --- a/src/parser.cpp Tue Jan 28 23:34:49 2020 +0200 +++ b/src/parser.cpp Thu Jan 30 19:20:11 2020 +0200 @@ -255,7 +255,7 @@ invertNext = true; continue; } - std::unique_ptr object = parseFromString(line); + std::unique_ptr object = parseFromString(line); auto id = editor.append(std::move(object)); if (invertNext) { @@ -265,10 +265,10 @@ } } -static Color colorFromString(const QString& colorString) +static ldraw::Color colorFromString(const QString& colorString) { bool colorSucceeded; - const Color color = {colorString.toInt(&colorSucceeded)}; + const ldraw::Color color = {colorString.toInt(&colorSucceeded)}; if (colorSucceeded) { return color; @@ -329,22 +329,22 @@ return result; } -static std::unique_ptr parseType0Line( +static std::unique_ptr parseType0Line( const QString& line, const QStringList& tokens) { Q_UNUSED(tokens) if (line.startsWith("0 //")) { - return std::make_unique(line.mid(std::strlen("0 //")).simplified()); + return std::make_unique(line.mid(std::strlen("0 //")).simplified()); } else { - return std::make_unique(line.mid(1).simplified()); + return std::make_unique(line.mid(1).simplified()); } } -static std::unique_ptr parseType1Line( +static std::unique_ptr parseType1Line( const QString& line, const QStringList& tokens) { @@ -357,10 +357,10 @@ { throw BodyParseError{"wrong amount of tokens in a type-1 line"}; } - const Color color = colorFromString(tokens[colorPosition]); + const ldraw::Color color = colorFromString(tokens[colorPosition]); const glm::mat4 transform = matrixFromStrings(tokens, transformPosition, positionPosition); const QString& name = tokens[namePosition]; - return std::make_unique(transform, name, color); + return std::make_unique(transform, name, color); } template @@ -375,7 +375,7 @@ { throw BodyParseError{"wrong amount of tokens"}; } - const Color color = colorFromString(tokens[colorPosition]); + const ldraw::Color color = colorFromString(tokens[colorPosition]); QVector vertices; vertices.reserve(NumVertices); for (int i = 0; i < NumVertices; i += 1) @@ -385,7 +385,7 @@ return std::make_unique(vertices, color); } -std::unique_ptr Parser::parseFromString(QString line) +std::unique_ptr Parser::parseFromString(QString line) { line = line.simplified(); try @@ -393,7 +393,7 @@ const QStringList tokens = line.split(QRegExp{R"(\s+)"}); if (tokens.empty() or tokens == QStringList{{""}}) { - return std::make_unique(); + return std::make_unique(); } bool ok_code; const int code = tokens[0].toInt(&ok_code); @@ -408,19 +408,19 @@ case 1: return parseType1Line(line, tokens); case 2: - return parsePolygon(line, tokens); + return parsePolygon(line, tokens); case 3: - return parsePolygon(line, tokens); + return parsePolygon(line, tokens); case 4: - return parsePolygon(line, tokens); + return parsePolygon(line, tokens); case 5: - return parsePolygon(line, tokens); + return parsePolygon(line, tokens); default: throw BodyParseError{utility::format("bad line type '%1'", code)}; } } catch(const BodyParseError& error) { - return std::make_unique(line, error.message); + return std::make_unique(line, error.message); } } diff -r 1de2b8d64e9f -r 98906a94732f src/parser.h --- a/src/parser.h Tue Jan 28 23:34:49 2020 +0200 +++ b/src/parser.h Thu Jan 30 19:20:11 2020 +0200 @@ -31,7 +31,7 @@ Parser(QIODevice& device, QObject* parent = nullptr); LDHeader parseHeader(Winding& winding); void parseBody(Model::EditContext& editor); - static std::unique_ptr parseFromString(QString line); + static std::unique_ptr parseFromString(QString line); private: enum HeaderParseResult {ParseSuccess, ParseFailure, StopParsing}; QString readLine();