Sun, 29 Jan 2017 15:39:35 +0200
Replaced uses of LDSpawn with the Model class in edit modes
--- a/src/editmodes/abstractEditMode.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/abstractEditMode.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -165,17 +165,14 @@ return false; } -void AbstractDrawMode::finishDraw(LDObjectList const& objs) +void AbstractDrawMode::finishDraw(Model& model) { int pos = m_window->suggestInsertPoint(); - if (countof(objs) > 0) + if (countof(model.objects()) > 0) { - for (LDObject* obj : objs) - { + for (LDObject* obj : model) renderer()->document()->insertObject (pos++, obj); - renderer()->compileObject (obj); - } m_window->refresh(); m_window->endAction();
--- a/src/editmodes/abstractEditMode.h Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/abstractEditMode.h Sun Jan 29 15:39:35 2017 +0200 @@ -18,6 +18,7 @@ #pragma once #include "../main.h" +#include "../model.h" class QPainter; class GLRenderer; @@ -87,7 +88,7 @@ void drawLineLength (QPainter& painter, const Vertex& v0, const Vertex& v1, const QPointF& v0p, const QPointF& v1p) const; - void finishDraw (const LDObjectList& objs); + void finishDraw (Model& model); Vertex getCursorVertex() const; bool keyReleased (QKeyEvent* ev) override; virtual int maxVertices() const { return 0; }
--- a/src/editmodes/circleMode.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/circleMode.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -86,11 +86,11 @@ void CircleMode::endDraw() { - LDObjectList objs; - PrimitiveModel model; - model.segments = m_window->ringToolSegments(); - model.divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution; - model.ringNumber = 0; + Model model; + PrimitiveModel primitiveModel; + primitiveModel.segments = m_window->ringToolSegments(); + primitiveModel.divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution; + primitiveModel.ringNumber = 0; double dist0 (getCircleDrawDist (0)); double dist1 (getCircleDrawDist (1)); LDDocument* primitiveFile; @@ -103,34 +103,32 @@ if (dist0 == dist1) { // If the radii are the same, there's no ring space to fill. Use a circle. - model.type = PrimitiveModel::Circle; - primitiveFile = primitives()->getPrimitive(model); + primitiveModel.type = PrimitiveModel::Circle; + primitiveFile = primitives()->getPrimitive(primitiveModel); transform = getCircleDrawMatrix (dist0); circleOrDisc = true; } else if (dist0 == 0 or dist1 == 0) { // If either radii is 0, use a disc. - model.type = PrimitiveModel::Disc; - primitiveFile = primitives()->getPrimitive(model); + primitiveModel.type = PrimitiveModel::Disc; + primitiveFile = primitives()->getPrimitive(primitiveModel); transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1); circleOrDisc = true; } else if (g_RingFinder.findRings (dist0, dist1)) { // The ring finder found a solution, use that. Add the component rings to the file. - model.type = PrimitiveModel::Ring; + primitiveModel.type = PrimitiveModel::Ring; for (const RingFinder::Component& component : g_RingFinder.bestSolution()->getComponents()) { - model.ringNumber = component.num; - primitiveFile = primitives()->getPrimitive(model); - LDSubfileReference* ref = LDSpawn<LDSubfileReference>(); - ref->setFileInfo (primitiveFile); - ref->setTransformationMatrix (getCircleDrawMatrix (component.scale)); - ref->setPosition (m_drawedVerts[0]); - ref->setColor (MainColor); - objs << ref; + primitiveModel.ringNumber = component.num; + primitiveFile = primitives()->getPrimitive(primitiveModel); + LDSubfileReference* ref = model.emplace<LDSubfileReference>(); + ref->setFileInfo(primitiveFile); + ref->setTransformationMatrix(getCircleDrawMatrix(component.scale)); + ref->setPosition(m_drawedVerts[0]); } } else @@ -148,10 +146,10 @@ templ.setCoordinate (localz, renderer()->getDepthValue()); // Calculate circle coords - QVector<QLineF> c0 = makeCircle(model.segments, model.divisions, dist0); - QVector<QLineF> c1 = makeCircle(model.segments, model.divisions, dist1); + QVector<QLineF> c0 = makeCircle(primitiveModel.segments, primitiveModel.divisions, dist0); + QVector<QLineF> c1 = makeCircle(primitiveModel.segments, primitiveModel.divisions, dist1); - for (int i = 0; i < model.segments; ++i) + for (int i = 0; i < primitiveModel.segments; ++i) { Vertex v0, v1, v2, v3; v0 = v1 = v2 = v3 = templ; @@ -164,37 +162,34 @@ v3.setCoordinate (localx, v3[localx] + c1[i].x1()); v3.setCoordinate (localy, v3[localy] + c1[i].y1()); - LDQuad* quad (LDSpawn<LDQuad> (v0, v1, v2, v3)); + LDQuad* quad = model.emplace<LDQuad>(v0, v1, v2, v3); quad->setColor (MainColor); // Ensure the quads always are BFC-front towards the camera if (renderer()->camera() % 3 <= 0) quad->invert(); - - objs << quad; } } if (circleOrDisc and primitiveFile) { - LDSubfileReference* ref = LDSpawn<LDSubfileReference>(); + LDSubfileReference* ref = model.emplace<LDSubfileReference>(); ref->setFileInfo (primitiveFile); ref->setTransformationMatrix (transform); ref->setPosition (m_drawedVerts[0]); ref->setColor (MainColor); - objs << ref; } - if (not objs.isEmpty()) + if (not model.isEmpty()) { Axis relZ = renderer()->getRelativeZ();; int l = (relZ == X ? 1 : 0); int m = (relZ == Y ? 1 : 0); int n = (relZ == Z ? 1 : 0); - math()->rotateObjects (l, m, n, -m_angleOffset, objs.toVector()); + math()->rotateObjects(l, m, n, -m_angleOffset, model.objects()); } - finishDraw (objs); + finishDraw (model); }
--- a/src/editmodes/curvemode.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/curvemode.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -86,8 +86,8 @@ { if (countof(m_drawedVerts) == 4) { - LDObjectList objs; - objs << LDSpawn<LDBezierCurve> (m_drawedVerts[0], m_drawedVerts[1], m_drawedVerts[2], m_drawedVerts[3]); - finishDraw (objs); + Model model; + model.emplace<LDBezierCurve>(m_drawedVerts[0], m_drawedVerts[1], m_drawedVerts[2], m_drawedVerts[3]); + finishDraw(model); } }
--- a/src/editmodes/drawMode.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/drawMode.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -65,35 +65,30 @@ { // Clean the selection and create the object QList<Vertex>& verts = m_drawedVerts; - LDObjectList objs; + Model model; switch (countof(verts)) { case 2: { // 2 verts - make a line - LDLine* obj = LDSpawn<LDLine> (verts[0], verts[1]); - obj->setColor (EdgeColor); - objs << obj; + LDLine* obj = model.emplace<LDLine>(verts[0], verts[1]); break; } case 3: case 4: { - LDObject* obj = (countof(verts) == 3) ? - static_cast<LDObject*> (LDSpawn<LDTriangle>()) : - static_cast<LDObject*> (LDSpawn<LDQuad>()); - - obj->setColor (MainColor); + LDObject* obj = (countof(verts) == 3) ? + static_cast<LDObject*>(model.emplace<LDTriangle>()) : + static_cast<LDObject*>(model.emplace<LDQuad>()); for (int i = 0; i < countof(verts); ++i) obj->setVertex (i, verts[i]); - objs << obj; break; } } - finishDraw (objs); + finishDraw (model); }
--- a/src/editmodes/linePathMode.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/linePathMode.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -80,17 +80,12 @@ void LinePathMode::endDraw() { - LDObjectList objs; + Model model; for (int i = 0; i < countof(m_drawedVerts) - 1; ++i) - { - LDLine* line = LDSpawn<LDLine>(); - line->setVertex (0, m_drawedVerts[i]); - line->setVertex (1, m_drawedVerts[i + 1]); - objs << line; - } + LDLine* line = model.emplace<LDLine>(m_drawedVerts[i], m_drawedVerts[i + 1]); - finishDraw (objs); + finishDraw(model); } bool LinePathMode::keyReleased (QKeyEvent* ev)
--- a/src/editmodes/rectangleMode.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/editmodes/rectangleMode.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -41,14 +41,14 @@ { if (countof(m_drawedVerts) == 2) { - LDQuad* quad = LDSpawn<LDQuad>(); + Model model; + LDQuad* quad = model.emplace<LDQuad>(); updateRectVerts(); for (int i = 0; i < quad->numVertices(); ++i) - quad->setVertex (i, m_rectangleVerts[i]); + quad->setVertex(i, m_rectangleVerts[i]); - quad->setColor (MainColor); - finishDraw (LDObjectList ({quad})); + finishDraw(model); } }
--- a/src/ldObject.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/ldObject.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -249,8 +249,8 @@ // ============================================================================= // -LDLine::LDLine (Vertex v1, Vertex v2, LDDocument* document) : - LDObject (document) +LDLine::LDLine (Vertex v1, Vertex v2, Model* model) : + LDObject {model} { setVertex (0, v1); setVertex (1, v2); @@ -258,8 +258,8 @@ // ============================================================================= // -LDTriangle::LDTriangle (const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* document) : - LDObject (document) +LDTriangle::LDTriangle (const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : + LDObject {model} { setVertex (0, v1); setVertex (1, v2); @@ -268,8 +268,8 @@ // ============================================================================= // -LDQuad::LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document) : - LDObject (document) +LDQuad::LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model) : + LDObject {model} { setVertex (0, v1); setVertex (1, v2); @@ -279,8 +279,8 @@ // ============================================================================= // -LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) : - LDLine (document) +LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : + LDLine {model} { setVertex (0, v0); setVertex (1, v1); @@ -290,9 +290,8 @@ // ============================================================================= // -LDBezierCurve::LDBezierCurve(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, - LDDocument* document) : - LDObject (document) +LDBezierCurve::LDBezierCurve(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : + LDObject {model} { setVertex (0, v0); setVertex (1, v1);
--- a/src/ldObject.h Sun Jan 29 15:28:48 2017 +0200 +++ b/src/ldObject.h Sun Jan 29 15:39:35 2017 +0200 @@ -345,7 +345,7 @@ LDOBJ_NO_MATRIX public: - LDLine (Vertex v1, Vertex v2, LDDocument* model = nullptr); + LDLine (Vertex v1, Vertex v2, Model* model = nullptr); }; // @@ -364,7 +364,7 @@ LDOBJ_NO_MATRIX public: - LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* model = nullptr); + LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); LDLine* becomeEdgeLine(); }; @@ -407,7 +407,7 @@ LDOBJ_NO_MATRIX public: - LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* model = nullptr); + LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr); int triangleCount() const override; }; @@ -460,8 +460,7 @@ LDOBJ_NO_MATRIX public: - LDBezierCurve (const Vertex& v0, const Vertex& v1, - const Vertex& v2, const Vertex& v3, LDDocument* model = nullptr); + LDBezierCurve (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); Vertex pointAt (qreal t) const; void rasterize(Model& model, int segments); QVector<LDPolygon> rasterizePolygons (int segments);
--- a/src/model.cpp Sun Jan 29 15:28:48 2017 +0200 +++ b/src/model.cpp Sun Jan 29 15:39:35 2017 +0200 @@ -192,3 +192,8 @@ _needsTriangleRecount = true; return object; } + +bool Model::isEmpty() const +{ + return _objects.isEmpty(); +}
--- a/src/model.h Sun Jan 29 15:28:48 2017 +0200 +++ b/src/model.h Sun Jan 29 15:39:35 2017 +0200 @@ -26,6 +26,7 @@ int triangleCount() const; QVector<LDObject*>::iterator begin(); QVector<LDObject*>::iterator end(); + bool isEmpty() const; template<typename T, typename... Args> T* emplace(Args&& ...args)