Tue, 14 Feb 2017 15:11:33 +0200
Moved LDTriangle into its own source pair.
--- a/CMakeLists.txt Tue Feb 14 14:59:26 2017 +0200 +++ b/CMakeLists.txt Tue Feb 14 15:11:33 2017 +0200 @@ -76,6 +76,7 @@ src/linetypes/edgeline.cpp src/linetypes/empty.cpp src/linetypes/modelobject.cpp + src/linetypes/triangle.cpp src/toolsets/algorithmtoolset.cpp src/toolsets/basictoolset.cpp src/toolsets/extprogramtoolset.cpp @@ -140,6 +141,7 @@ src/linetypes/edgeline.h src/linetypes/empty.h src/linetypes/modelobject.h + src/linetypes/triangle.h src/toolsets/algorithmtoolset.h src/toolsets/basictoolset.h src/toolsets/extprogramtoolset.h
--- a/src/editmodes/drawMode.cpp Tue Feb 14 14:59:26 2017 +0200 +++ b/src/editmodes/drawMode.cpp Tue Feb 14 15:11:33 2017 +0200 @@ -22,6 +22,7 @@ #include "../linetypes/modelobject.h" #include "../glrenderer.h" #include "../linetypes/edgeline.h" +#include "../linetypes/triangle.h" DrawMode::DrawMode (Canvas* canvas) : Super (canvas) {}
--- a/src/linetypes/modelobject.cpp Tue Feb 14 14:59:26 2017 +0200 +++ b/src/linetypes/modelobject.cpp Tue Feb 14 15:11:33 2017 +0200 @@ -65,7 +65,6 @@ LDMatrixObject (model) {} LDOBJ_DEFAULT_CTOR (LDError, LDObject) -LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject) LDOBJ_DEFAULT_CTOR (LDQuadrilateral, LDObject) LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject) @@ -93,18 +92,6 @@ // ============================================================================= // -QString LDTriangle::asText() const -{ - QString val = format ("3 %1", color()); - - for (int i = 0; i < 3; ++i) - val += format (" %1", vertex (i)); - - return val; -} - -// ============================================================================= -// QString LDQuadrilateral::asText() const { QString val = format ("4 %1", color()); @@ -160,11 +147,6 @@ return fileInfo()->triangleCount(); } -int LDTriangle::triangleCount() const -{ - return 1; -} - int LDQuadrilateral::triangleCount() const { return 2; @@ -177,16 +159,6 @@ // ============================================================================= // -LDTriangle::LDTriangle (const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : - LDObject {model} -{ - setVertex (0, v1); - setVertex (1, v2); - setVertex (2, v3); -} - -// ============================================================================= -// LDQuadrilateral::LDQuadrilateral (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model) : LDObject {model} { @@ -439,19 +411,6 @@ // ============================================================================= // -void LDTriangle::invert() -{ - // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. - // Thus, we swap 1 and 2. - Vertex tmp = vertex (1); - setVertex (1, vertex (2)); - setVertex (2, tmp); - - return; -} - -// ============================================================================= -// void LDQuadrilateral::invert() { // Quad: 0 -> 1 -> 2 -> 3
--- a/src/linetypes/modelobject.h Tue Feb 14 14:59:26 2017 +0200 +++ b/src/linetypes/modelobject.h Tue Feb 14 15:11:33 2017 +0200 @@ -29,7 +29,7 @@ /* * Object type codes. */ -enum LDObjectType +enum class LDObjectType { SubfileReference, // Object represents a sub-file reference Quadrilateral, // Object represents a quadrilateral @@ -46,6 +46,11 @@ MAKE_ITERABLE_ENUM(LDObjectType) +inline int qHash(LDObjectType type) +{ + return qHash(static_cast<int>(type)); +} + /* * Represents one line of code in an LDraw model file. */ @@ -253,31 +258,6 @@ }; /* - * Represents a single code-3 triangle in the LDraw code file. - */ -class LDTriangle : public LDObject -{ -public: - static constexpr LDObjectType SubclassType = LDObjectType::Triangle; - - virtual LDObjectType type() const override - { - return SubclassType; - } - - virtual QString asText() const override; - virtual void invert() override; - int triangleCount() const override; - int numVertices() const override { return 3; } - QString typeName() const override { return "triangle"; } - -protected: - friend class Model; - LDTriangle (Model* model); - LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, Model* model = nullptr); -}; - -/* * Represents a single code-4 quadrilateral. */ class LDQuadrilateral : public LDObject
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/triangle.cpp Tue Feb 14 15:11:33 2017 +0200 @@ -0,0 +1,54 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2017 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "triangle.h" + +LDTriangle::LDTriangle(Model *model) : + LDObject {model} {} + +LDTriangle::LDTriangle(const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : + LDObject {model} +{ + setVertex(0, v1); + setVertex(1, v2); + setVertex(2, v3); +} + +int LDTriangle::triangleCount() const +{ + return 1; +} + +QString LDTriangle::asText() const +{ + QString result = format("3 %1", color()); + + for (int i = 0; i < 3; ++i) + result += format(" %1", vertex (i)); + + return result; +} + +void LDTriangle::invert() +{ + // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. + // Thus, we swap 1 and 2. + Vertex temp = vertex(1); + setVertex(1, vertex(2)); + setVertex(2, temp); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/triangle.h Tue Feb 14 15:11:33 2017 +0200 @@ -0,0 +1,45 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2017 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include "modelobject.h" + +/* + * Represents a single code-3 triangle in the LDraw code file. + */ +class LDTriangle : public LDObject +{ +public: + static constexpr LDObjectType SubclassType = LDObjectType::Triangle; + + virtual LDObjectType type() const override + { + return SubclassType; + } + + virtual QString asText() const override; + virtual void invert() override; + int triangleCount() const override; + int numVertices() const override { return 3; } + QString typeName() const override { return "triangle"; } + +protected: + friend class Model; + LDTriangle (Model* model); + LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, Model* model = nullptr); +}; \ No newline at end of file
--- a/src/model.cpp Tue Feb 14 14:59:26 2017 +0200 +++ b/src/model.cpp Tue Feb 14 15:11:33 2017 +0200 @@ -23,6 +23,7 @@ #include "linetypes/conditionaledge.h" #include "linetypes/edgeline.h" #include "linetypes/empty.h" +#include "linetypes/triangle.h" Model::Model(DocumentManager* manager) : QObject {manager},
--- a/src/primitives.cpp Tue Feb 14 14:59:26 2017 +0200 +++ b/src/primitives.cpp Tue Feb 14 15:11:33 2017 +0200 @@ -28,7 +28,7 @@ #include "linetypes/conditionaledge.h" #include "linetypes/edgeline.h" #include "linetypes/empty.h" - +#include "linetypes/triangle.h" PrimitiveManager::PrimitiveManager(QObject* parent) : QObject(parent),
--- a/src/toolsets/algorithmtoolset.cpp Tue Feb 14 14:59:26 2017 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Tue Feb 14 15:11:33 2017 +0200 @@ -36,6 +36,7 @@ #include "../linetypes/conditionaledge.h" #include "../linetypes/edgeline.h" #include "../linetypes/empty.h" +#include "../linetypes/triangle.h" #include "ui_replcoords.h" #include "ui_editraw.h" #include "ui_flip.h"