Sat, 03 Mar 2018 17:25:12 +0200
Removed LDObject::invert, inversion code moved to basic toolset
--- a/src/editmodes/circleMode.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/editmodes/circleMode.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -139,12 +139,12 @@ v3.setCoordinate (localx, v3[localx] + c1[i].x1()); v3.setCoordinate (localy, v3[localy] + c1[i].y1()); + // Ensure the quads always are BFC-front towards the camera + if (static_cast<int>(renderer()->camera()) % 3 <= 0) + qSwap(v1, v3); + LDQuadrilateral* quad = model.emplace<LDQuadrilateral>(v0, v1, v2, v3); quad->setColor(MainColor); - - // Ensure the quads always are BFC-front towards the camera - if (static_cast<int>(renderer()->camera()) % 3 <= 0) - quad->invert(); } }
--- a/src/linetypes/conditionaledge.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/conditionaledge.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -41,10 +41,3 @@ return result; } - -void LDConditionalEdge::invert() -{ - Vertex temp = vertex(0); - setVertex(0, vertex(1)); - setVertex(1, temp); -}
--- a/src/linetypes/conditionaledge.h Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/conditionaledge.h Sat Mar 03 17:25:12 2018 +0200 @@ -33,7 +33,6 @@ } virtual QString asText() const override; - virtual void invert() override; int numVertices() const override { return 4; } int numPolygonVertices() const override { return 2; } LDColor defaultColor() const override { return EdgeColor; }
--- a/src/linetypes/edgeline.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/edgeline.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -46,13 +46,3 @@ return result; } - -/* - * Inverting an edge line swaps the vertices. - */ -void LDEdgeLine::invert() -{ - Vertex temp = vertex(0); - setVertex(0, vertex(1)); - setVertex(1, temp); -}
--- a/src/linetypes/edgeline.h Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/edgeline.h Sat Mar 03 17:25:12 2018 +0200 @@ -33,7 +33,6 @@ } 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"; }
--- a/src/linetypes/modelobject.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/modelobject.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -314,80 +314,6 @@ // ============================================================================= // -void LDObject::invert() {} -void LDBfc::invert() {} -void LDError::invert() {} - -// ============================================================================= -// -void LDSubfileReference::invert() -{ - if (model() == nullptr) - return; - - // Check whether subfile is flat - int axisSet = (1 << X) | (1 << Y) | (1 << Z); - Model model {this->model()->documentManager()}; - fileInfo()->inlineContents(model, true, false); - - for (LDObject* obj : model.objects()) - { - for (int i = 0; i < obj->numVertices(); ++i) - { - Vertex const& vrt = obj->vertex (i); - - if (axisSet & (1 << X) and vrt.x() != 0.0) - axisSet &= ~(1 << X); - - if (axisSet & (1 << Y) and vrt.y() != 0.0) - axisSet &= ~(1 << Y); - - if (axisSet & (1 << Z) and vrt.z() != 0.0) - axisSet &= ~(1 << Z); - } - - if (axisSet == 0) - break; - } - - if (axisSet != 0) - { - // Subfile has all vertices zero on one specific plane, so it is flat. - // Let's flip it. - Matrix matrixModifier = Matrix::identity; - - if (axisSet & (1 << X)) - matrixModifier(0, 0) = -1; - - if (axisSet & (1 << Y)) - matrixModifier(1, 1) = -1; - - if (axisSet & (1 << Z)) - matrixModifier(2, 2) = -1; - - setTransformationMatrix (transformationMatrix() * matrixModifier); - return; - } - - // Subfile is not flat. Resort to invertnext. - setInverted(not this->isInverted()); -} - -// ============================================================================= -// -void LDBezierCurve::invert() -{ - // A Bézier curve's control points probably need to be, though. - Vertex tmp = vertex (1); - setVertex (1, vertex (0)); - setVertex (0, tmp); - tmp = vertex (3); - setVertex (3, vertex (2)); - setVertex (2, tmp); -} - -// ============================================================================= -// LDObject* LDObject::fromID(qint32 id) { return g_allObjects.value(id); @@ -598,9 +524,6 @@ { changeProperty(&m_fileInfo, newReferee); - if (model()) - model()->recountTriangles(); - // If it's an immediate subfile reference (i.e. this subfile is in an opened document), we need to pre-compile the // GL polygons for the document if they don't exist already. if (newReferee and
--- a/src/linetypes/modelobject.h Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/modelobject.h Sat Mar 03 17:25:12 2018 +0200 @@ -67,7 +67,6 @@ virtual void getVertices (QSet<Vertex>& verts) const; virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject) qint32 id() const; - virtual void invert(); // Inverts this object (winding is reversed) virtual bool isColored() const; bool isHidden() const; virtual bool isScemantic() const; // Does this object have meaning in the part model? @@ -150,7 +149,6 @@ } virtual QString asText() const override; - virtual void invert() override; QString reason() const; QString contents() const; QString fileReferenced() const; @@ -201,7 +199,6 @@ } virtual QString asText() const override; - virtual void invert() override; protected: friend class Model; LDBfc (Model* model); @@ -238,7 +235,6 @@ } virtual QString asText() const override; - virtual void invert() override; LDDocument* fileInfo() const; virtual void getVertices (QSet<Vertex>& verts) const override; void inlineContents(Model& model, bool deep, bool render); @@ -272,7 +268,6 @@ } virtual QString asText() const override; - virtual void invert() override; Vertex pointAt (qreal t) const; void rasterize(Model& model, int segments); QVector<LDPolygon> rasterizePolygons (int segments);
--- a/src/linetypes/quadrilateral.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/quadrilateral.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -55,17 +55,7 @@ return 2; } -void LDQuadrilateral::invert() -{ - // Quad: 0 -> 1 -> 2 -> 3 - // reversed: 0 -> 3 -> 2 -> 1 - // Thus, we swap 1 and 3. - Vertex temp = vertex(1); - setVertex(1, vertex(3)); - setVertex(3, temp); -} - LDObjectType LDQuadrilateral::type() const { return SubclassType; -} \ No newline at end of file +}
--- a/src/linetypes/quadrilateral.h Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/quadrilateral.h Sat Mar 03 17:25:12 2018 +0200 @@ -28,7 +28,6 @@ static constexpr LDObjectType SubclassType = LDObjectType::Quadrilateral; QString asText() const override; - void invert() override; int numVertices() const override; int triangleCount() const override; LDObjectType type() const override;
--- a/src/linetypes/triangle.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/triangle.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -43,12 +43,3 @@ 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); -}
--- a/src/linetypes/triangle.h Sat Mar 03 16:59:03 2018 +0200 +++ b/src/linetypes/triangle.h Sat Mar 03 17:25:12 2018 +0200 @@ -33,7 +33,6 @@ } 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"; } @@ -42,4 +41,4 @@ 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 Sat Mar 03 16:59:03 2018 +0200 +++ b/src/model.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -65,6 +65,8 @@ */ void Model::insertObject(int position, LDObject* object) { + connect(object, SIGNAL(codeChanged(QString,QString)), this, SLOT(recountTriangles())); + if (object->model() and object->model() != this) object->model()->withdraw(object);
--- a/src/model.h Sat Mar 03 16:59:03 2018 +0200 +++ b/src/model.h Sat Mar 03 17:25:12 2018 +0200 @@ -103,7 +103,7 @@ int size() const; const QVector<LDObject*>& objects() const; LDObject* getObject(int position) const; - void recountTriangles(); + Q_SLOT void recountTriangles(); int triangleCount() const; QVector<LDObject*>::iterator begin(); QVector<LDObject*>::iterator end();
--- a/src/primitives.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/primitives.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -316,12 +316,13 @@ Vertex v1 = {x1, y1, z1}; Vertex v2 = {x2, y2, z2}; Vertex v3 = {x3, y3, z3}; + + if (type == Cylinder) + qSwap(v1, v3); + LDQuadrilateral* quad = model.emplace<LDQuadrilateral>(v0, v1, v2, v3); quad->setColor(MainColor); - if (type == Cylinder) - quad->invert(); - if (type == Cylinder or type == Cone) conditionalLineSegments.append(i); }
--- a/src/toolsets/basictoolset.cpp Sat Mar 03 16:59:03 2018 +0200 +++ b/src/toolsets/basictoolset.cpp Sat Mar 03 17:25:12 2018 +0200 @@ -220,7 +220,69 @@ void BasicToolset::invert() { for (LDObject* obj : selectedObjects()) - obj->invert(); + { + if (obj->numPolygonVertices() > 0) + { + QVector<Vertex> vertices; + + for (int i = 0; i < obj->numPolygonVertices(); i += 1) + vertices.append(obj->vertex(i)); + + for (int i = 0; i < vertices.size(); i += 1) + obj->setVertex(i, vertices[vertices.size() - 1 - i]); + } + else if (obj->type() == LDObjectType::SubfileReference) + { + // Check whether subfile is flat + int axisSet = (1 << X) | (1 << Y) | (1 << Z); + Model model {currentDocument()->documentManager()}; + LDSubfileReference* reference = static_cast<LDSubfileReference*>(obj); + reference->fileInfo()->inlineContents(model, true, false); + + for (LDObject* subobj : model.objects()) + { + for (int i = 0; i < subobj->numVertices(); ++i) + { + Vertex const& vrt = subobj->vertex (i); + + if (axisSet & (1 << X) and vrt.x() != 0.0) + axisSet &= ~(1 << X); + + if (axisSet & (1 << Y) and vrt.y() != 0.0) + axisSet &= ~(1 << Y); + + if (axisSet & (1 << Z) and vrt.z() != 0.0) + axisSet &= ~(1 << Z); + } + + if (axisSet == 0) + break; + } + + if (axisSet != 0) + { + // Subfile has all vertices zero on one specific plane, so it is flat. + // Let's flip it. + Matrix matrixModifier = Matrix::identity; + + if (axisSet & (1 << X)) + matrixModifier(0, 0) = -1; + + if (axisSet & (1 << Y)) + matrixModifier(1, 1) = -1; + + if (axisSet & (1 << Z)) + matrixModifier(2, 2) = -1; + + reference->setTransformationMatrix(reference->transformationMatrix() * matrixModifier); + } + else + { + // Subfile is not flat. Resort to invertnext. + reference->setInverted(not reference->isInverted()); + } + } + } } void BasicToolset::newSubfile()