Tue, 14 Feb 2017 13:25:43 +0200
Split LDConditionalEdge and LDEdgeLine into new source pairs
--- a/CMakeLists.txt Tue Feb 14 13:02:05 2017 +0200 +++ b/CMakeLists.txt Tue Feb 14 13:25:43 2017 +0200 @@ -73,6 +73,8 @@ src/editmodes/rectangleMode.cpp src/editmodes/selectMode.cpp src/linetypes/comment.cpp + src/linetypes/conditionaledge.cpp + src/linetypes/edgeline.cpp src/linetypes/empty.cpp src/toolsets/algorithmtoolset.cpp src/toolsets/basictoolset.cpp @@ -135,6 +137,8 @@ src/editmodes/rectangleMode.h src/editmodes/selectMode.h src/linetypes/comment.h + src/linetypes/conditionaledge.h + src/linetypes/edgeline.h src/linetypes/empty.h src/toolsets/algorithmtoolset.h src/toolsets/basictoolset.h
--- a/src/editmodes/drawMode.cpp Tue Feb 14 13:02:05 2017 +0200 +++ b/src/editmodes/drawMode.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -21,6 +21,7 @@ #include "drawMode.h" #include "../ldObject.h" #include "../glRenderer.h" +#include "../linetypes/edgeline.h" DrawMode::DrawMode (Canvas* canvas) : Super (canvas) {}
--- a/src/editmodes/linePathMode.cpp Tue Feb 14 13:02:05 2017 +0200 +++ b/src/editmodes/linePathMode.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -20,6 +20,7 @@ #include "linePathMode.h" #include "../canvas.h" #include "../mainwindow.h" +#include "../linetypes/edgeline.h" LinePathMode::LinePathMode (Canvas* canvas) : Super (canvas) {}
--- a/src/ldObject.cpp Tue Feb 14 13:02:05 2017 +0200 +++ b/src/ldObject.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -26,6 +26,7 @@ #include "canvas.h" #include "colors.h" #include "glCompiler.h" +#include "linetypes/edgeline.h" // List of all LDObjects QMap<qint32, LDObject*> g_allObjects; @@ -64,9 +65,7 @@ LDMatrixObject (model) {} LDOBJ_DEFAULT_CTOR (LDError, LDObject) -LDOBJ_DEFAULT_CTOR (LDEdgeLine, LDObject) LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject) -LDOBJ_DEFAULT_CTOR (LDConditionalEdge, LDEdgeLine) LDOBJ_DEFAULT_CTOR (LDQuadrilateral, LDObject) LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject) @@ -94,18 +93,6 @@ // ============================================================================= // -QString LDEdgeLine::asText() const -{ - QString val = format ("2 %1", color()); - - for (int i = 0; i < 2; ++i) - val += format (" %1", vertex (i)); - - return val; -} - -// ============================================================================= -// QString LDTriangle::asText() const { QString val = format ("3 %1", color()); @@ -128,19 +115,6 @@ return val; } -// ============================================================================= -// -QString LDConditionalEdge::asText() const -{ - QString val = format ("5 %1", color()); - - // Add the coordinates - for (int i = 0; i < 4; ++i) - val += format (" %1", vertex (i)); - - return val; -} - QString LDBezierCurve::asText() const { QString result = format ("0 !LDFORGE BEZIER_CURVE %1", color()); @@ -203,15 +177,6 @@ // ============================================================================= // -LDEdgeLine::LDEdgeLine (Vertex v1, Vertex v2, Model* model) : - LDObject {model} -{ - setVertex (0, v1); - setVertex (1, v2); -} - -// ============================================================================= -// LDTriangle::LDTriangle (const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : LDObject {model} { @@ -233,17 +198,6 @@ // ============================================================================= // -LDConditionalEdge::LDConditionalEdge (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : - LDEdgeLine {model} -{ - setVertex (0, v0); - setVertex (1, v1); - setVertex (2, v2); - setVertex (3, v3); -} - -// ============================================================================= -// LDBezierCurve::LDBezierCurve(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : LDObject {model} { @@ -580,26 +534,6 @@ // ============================================================================= // -void LDEdgeLine::invert() -{ - // For lines, we swap the vertices. - Vertex tmp = vertex (0); - setVertex (0, vertex (1)); - setVertex (1, tmp); -} - -// ============================================================================= -// -void LDConditionalEdge::invert() -{ - // I don't think that a conditional line's control points need to be swapped, do they? - Vertex tmp = vertex (0); - setVertex (0, vertex (1)); - setVertex (1, tmp); -} - -// ============================================================================= -// void LDBezierCurve::invert() { // A Bézier curve's control points probably need to be, though. @@ -613,19 +547,6 @@ // ============================================================================= // -LDEdgeLine* LDConditionalEdge::becomeEdgeLine() -{ - LDEdgeLine* replacement = model()->emplaceReplacement<LDEdgeLine>(this); - - for (int i = 0; i < replacement->numVertices(); ++i) - replacement->setVertex (i, vertex (i)); - - replacement->setColor (color()); - return replacement; -} - -// ============================================================================= -// LDObject* LDObject::fromID(qint32 id) { return g_allObjects.value(id);
--- a/src/ldObject.h Tue Feb 14 13:02:05 2017 +0200 +++ b/src/ldObject.h Tue Feb 14 13:25:43 2017 +0200 @@ -253,57 +253,6 @@ }; /* - * Represents a single code-2 line in the LDraw code file. - */ -class LDEdgeLine : public LDObject -{ -public: - static constexpr LDObjectType SubclassType = LDObjectType::EdgeLine; - - virtual LDObjectType type() const override - { - return SubclassType; - } - - virtual QString asText() const override; - virtual void invert() override; - int numVertices() const override { return 2; } - LDColor defaultColor() const override { return EdgeColor; } - QString typeName() const override { return "line"; } - -protected: - friend class Model; - LDEdgeLine (Model* model); - LDEdgeLine (Vertex v1, Vertex v2, Model* model = nullptr); -}; - -/* - * Represents a single code-5 conditional line. - */ -class LDConditionalEdge : public LDEdgeLine -{ -public: - static constexpr LDObjectType SubclassType = LDObjectType::ConditionalEdge; - - virtual LDObjectType type() const override - { - return SubclassType; - } - - virtual QString asText() const override; - virtual void invert() override; - int numVertices() const override { return 4; } - LDColor defaultColor() const override { return EdgeColor; } - LDEdgeLine* becomeEdgeLine(); - QString typeName() const override { return "condline"; } - -protected: - friend class Model; - LDConditionalEdge (Model* model); - LDConditionalEdge (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); -}; - -/* * Represents a single code-3 triangle in the LDraw code file. */ class LDTriangle : public LDObject
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/conditionaledge.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -0,0 +1,62 @@ +/* + * 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 "../model.h" +#include "conditionaledge.h" + +LDConditionalEdge::LDConditionalEdge(Model* model) : + LDEdgeLine {model} {} + +LDConditionalEdge::LDConditionalEdge (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : + LDEdgeLine {model} +{ + setVertex (0, v0); + setVertex (1, v1); + setVertex (2, v2); + setVertex (3, v3); +} + +QString LDConditionalEdge::asText() const +{ + QString result = format("5 %1", color()); + + // Add the coordinates + for (int i = 0; i < 4; ++i) + result += format(" %1", vertex(i)); + + return result; +} + +void LDConditionalEdge::invert() +{ + // I don't think that a conditional line's control points need to be swapped, do they? + Vertex temp = vertex(0); + setVertex(0, vertex(1)); + setVertex(1, temp); +} + +LDEdgeLine* LDConditionalEdge::becomeEdgeLine() +{ + LDEdgeLine* replacement = model()->emplaceReplacement<LDEdgeLine>(this); + + for (int i = 0; i < replacement->numVertices(); ++i) + replacement->setVertex (i, vertex (i)); + + replacement->setColor (color()); + return replacement; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/conditionaledge.h Tue Feb 14 13:25:43 2017 +0200 @@ -0,0 +1,46 @@ +/* + * 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 "edgeline.h" + +/* + * Represents a single code-5 conditional line. + */ +class LDConditionalEdge : public LDEdgeLine +{ +public: + static constexpr LDObjectType SubclassType = LDObjectType::ConditionalEdge; + + virtual LDObjectType type() const override + { + return SubclassType; + } + + virtual QString asText() const override; + virtual void invert() override; + int numVertices() const override { return 4; } + LDColor defaultColor() const override { return EdgeColor; } + LDEdgeLine* becomeEdgeLine(); + QString typeName() const override { return "condline"; } + +protected: + friend class Model; + LDConditionalEdge (Model* model); + LDConditionalEdge (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/edgeline.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -0,0 +1,58 @@ +/* + * 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 "edgeline.h" + +/* + * Default-constructs this edge line. + */ +LDEdgeLine::LDEdgeLine(Model* model) : + LDObject {model} {} + +/* + * Constructs this edge line from two vertices. + */ +LDEdgeLine::LDEdgeLine (Vertex v1, Vertex v2, Model* model) : + LDObject {model} +{ + setVertex(0, v1); + setVertex(1, v2); +} + +/* + * Turns this edge line into LDraw code. + */ +QString LDEdgeLine::asText() const +{ + QString result = format("2 %1", color()); + + for (int i = 0; i < 2; ++i) + result += format(" %1", vertex (i)); + + return result; +} + +/* + * Inverting an edge line swaps the vertices. + */ +void LDEdgeLine::invert() +{ + Vertex temp = vertex(0); + setVertex(0, vertex(1)); + setVertex(1, temp); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/edgeline.h Tue Feb 14 13:25:43 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 "../ldObject.h" + +/* + * Represents a single code-2 line in the LDraw code file. + */ +class LDEdgeLine : public LDObject +{ +public: + static constexpr LDObjectType SubclassType = LDObjectType::EdgeLine; + + virtual LDObjectType type() const override + { + return SubclassType; + } + + virtual QString asText() const override; + virtual void invert() override; + int numVertices() const override { return 2; } + LDColor defaultColor() const override { return EdgeColor; } + QString typeName() const override { return "line"; } + +protected: + friend class Model; + LDEdgeLine (Model* model); + LDEdgeLine (Vertex v1, Vertex v2, Model* model = nullptr); +};
--- a/src/model.cpp Tue Feb 14 13:02:05 2017 +0200 +++ b/src/model.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -19,8 +19,10 @@ #include "model.h" #include "ldObject.h" #include "documentmanager.h" +#include "linetypes/comment.h" +#include "linetypes/conditionaledge.h" +#include "linetypes/edgeline.h" #include "linetypes/empty.h" -#include "linetypes/comment.h" Model::Model(DocumentManager* manager) : QObject {manager},
--- a/src/primitives.cpp Tue Feb 14 13:02:05 2017 +0200 +++ b/src/primitives.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -25,6 +25,8 @@ #include "ldpaths.h" #include "documentmanager.h" #include "linetypes/comment.h" +#include "linetypes/conditionaledge.h" +#include "linetypes/edgeline.h" #include "linetypes/empty.h"
--- a/src/toolsets/algorithmtoolset.cpp Tue Feb 14 13:02:05 2017 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Tue Feb 14 13:25:43 2017 +0200 @@ -33,6 +33,8 @@ #include "../ldobjectiterator.h" #include "../documentmanager.h" #include "../linetypes/comment.h" +#include "../linetypes/conditionaledge.h" +#include "../linetypes/edgeline.h" #include "../linetypes/empty.h" #include "ui_replcoords.h" #include "ui_editraw.h"