Skip to content

Commit

Permalink
FEM: python mesh API, add methods to retrieve group data
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach authored and wwmayer committed Oct 1, 2016
1 parent 15ad66a commit efb87dc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Mod/Fem/App/FemMeshPy.xml
Expand Up @@ -129,6 +129,21 @@
<UserDocu>Return a tuple of node IDs to a given element ID</UserDocu>
</Documentation>
</Methode>
<Methode Name="getGroupName" Const="true">
<Documentation>
<UserDocu>Return a string of group name to a given group ID</UserDocu>
</Documentation>
</Methode>
<Methode Name="getGroupElementType" Const="true">
<Documentation>
<UserDocu>Return a string of group element type to a given group ID</UserDocu>
</Documentation>
</Methode>
<Methode Name="getGroupElements" Const="true">
<Documentation>
<UserDocu>Return a tuple of ElementIDs to a given group ID</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Nodes" ReadOnly="true">
<Documentation>
<UserDocu>Dictionary of Nodes by ID (int ID:Vector())</UserDocu>
Expand Down
55 changes: 55 additions & 0 deletions src/Mod/Fem/App/FemMeshPyImp.cpp
Expand Up @@ -25,7 +25,11 @@
#include <stdexcept>

#include <SMESH_Gen.hxx>
#include <SMESH_Group.hxx>
#include <SMESH_Mesh.hxx>
#include <SMESHDS_Group.hxx>
#include <SMDSAbs_ElementType.hxx>
#include <SMDS_MeshElement.hxx>
#include <SMDS_VolumeTool.hxx>

#include <TopoDS_Shape.hxx>
Expand Down Expand Up @@ -898,6 +902,57 @@ PyObject* FemMeshPy::getElementNodes(PyObject *args)
}
}

PyObject* FemMeshPy::getGroupName(PyObject *args)
{
int id;
if (!PyArg_ParseTuple(args, "i", &id))
return 0;

return PyString_FromString(getFemMeshPtr()->getSMesh()->GetGroup(id)->GetName());
}

PyObject* FemMeshPy::getGroupElementType(PyObject *args)
{
int id;
if (!PyArg_ParseTuple(args, "i", &id))
return 0;

SMDSAbs_ElementType aElementType = getFemMeshPtr()->getSMesh()->GetGroup(id)->GetGroupDS()->GetType();
const char* typeString = "";
switch(aElementType) {
case SMDSAbs_All : typeString = "All"; break;
case SMDSAbs_Node : typeString = "Node"; break;
case SMDSAbs_Edge : typeString = "Edge"; break;
case SMDSAbs_Face : typeString = "Face"; break;
case SMDSAbs_Volume : typeString = "Volume"; break;
case SMDSAbs_0DElement : typeString = "0DElement"; break;
case SMDSAbs_Ball : typeString = "Ball"; break;
case SMDSAbs_NbElementTypes : typeString = "NbElementTypes"; break;
}
return PyString_FromString(typeString);
}

PyObject* FemMeshPy::getGroupElements(PyObject *args)
{
int id;
if (!PyArg_ParseTuple(args, "i", &id))
return 0;

std::set<int> ids;
SMDS_ElemIteratorPtr aElemIter = getFemMeshPtr()->getSMesh()->GetGroup(id)->GetGroupDS()->GetElements();
while (aElemIter->more()) {
const SMDS_MeshElement* aElement = aElemIter->next();
ids.insert(aElement->GetID());
}

Py::Tuple tuple(ids.size());
int index = 0;
for (std::set<int>::iterator it = ids.begin(); it != ids.end(); ++it) {
tuple.setItem(index++, Py::Int(*it));
}

return Py::new_reference_to(tuple);
}

// ===== Atributes ============================================================

Expand Down

0 comments on commit efb87dc

Please sign in to comment.