From 435cc3786de79aca689d7521a3ae9a67db8636b0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 8 Sep 2016 13:32:30 +0200 Subject: [PATCH] take care of segments in mesh on export --- src/Mod/Mesh/App/AppMeshPy.cpp | 47 +++++++++++++++++++++++++++++----- src/Mod/Mesh/App/Mesh.cpp | 1 + 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index c09c29316..12ef3b188 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -59,6 +59,16 @@ using namespace MeshCore; namespace Mesh { class Module : public Py::ExtensionModule { + struct add_offset { + unsigned long i; + add_offset(unsigned long i) : i(i) + { + } + void operator()(unsigned long& v) + { + v += i; + } + }; public: Module() : Py::ExtensionModule("Mesh") { @@ -307,13 +317,36 @@ private: else global_mesh.addMesh(kernel); - // now create a segment for the added mesh - std::vector indices; - indices.resize(global_mesh.countFacets() - countFacets); - std::generate(indices.begin(), indices.end(), Base::iotaGen(countFacets)); - Segment segm(&global_mesh, indices, true); - segm.setName(obj->Label.getValue()); - global_mesh.addSegment(segm); + // if the mesh already has persistent segments then use them instead + unsigned long numSegm = mesh.countSegments(); + unsigned long canSave = 0; + for (unsigned long i=0; i 0) { + for (unsigned long i=0; i indices = segm.getIndices(); + std::for_each(indices.begin(), indices.end(), add_offset(countFacets)); + Segment new_segm(&global_mesh, indices, true); + new_segm.setName(segm.getName()); + global_mesh.addSegment(new_segm); + } + } + + } + else { + // now create a segment for the added mesh + std::vector indices; + indices.resize(global_mesh.countFacets() - countFacets); + std::generate(indices.begin(), indices.end(), Base::iotaGen(countFacets)); + Segment segm(&global_mesh, indices, true); + segm.setName(obj->Label.getValue()); + global_mesh.addSegment(segm); + } } else if (obj->getTypeId().isDerivedFrom(partId)) { App::Property* shape = obj->getPropertyByName("Shape"); diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index c7ed5e7a3..2933068e7 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -1619,6 +1619,7 @@ void MeshObject::addSegment(const Segment& s) addSegment(s.getIndices()); this->_segments.back().setName(s.getName()); this->_segments.back().save(s.isSaved()); + this->_segments.back()._modifykernel = s._modifykernel; } void MeshObject::addSegment(const std::vector& inds)