Skip to content

Commit

Permalink
take care of segments in mesh on export
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Sep 8, 2016
1 parent adffaf7 commit 435cc37
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/Mod/Mesh/App/AppMeshPy.cpp
Expand Up @@ -59,6 +59,16 @@ using namespace MeshCore;
namespace Mesh {
class Module : public Py::ExtensionModule<Module>
{
struct add_offset {
unsigned long i;
add_offset(unsigned long i) : i(i)
{
}
void operator()(unsigned long& v)
{
v += i;
}
};
public:
Module() : Py::ExtensionModule<Module>("Mesh")
{
Expand Down Expand Up @@ -307,13 +317,36 @@ class Module : public Py::ExtensionModule<Module>
else
global_mesh.addMesh(kernel);

// now create a segment for the added mesh
std::vector<unsigned long> indices;
indices.resize(global_mesh.countFacets() - countFacets);
std::generate(indices.begin(), indices.end(), Base::iotaGen<unsigned long>(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<numSegm; i++) {
if (mesh.getSegment(i).isSaved())
canSave++;
}

if (canSave > 0) {
for (unsigned long i=0; i<numSegm; i++) {
const Segment& segm = mesh.getSegment(i);
if (segm.isSaved()) {
std::vector<unsigned long> 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<unsigned long> indices;
indices.resize(global_mesh.countFacets() - countFacets);
std::generate(indices.begin(), indices.end(), Base::iotaGen<unsigned long>(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");
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Mesh/App/Mesh.cpp
Expand Up @@ -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<unsigned long>& inds)
Expand Down

0 comments on commit 435cc37

Please sign in to comment.