diff -r 0347e9bc883e -r 5d2c9d36da9d src/toolsets/basictoolset.cpp --- 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 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(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()