py3: FEM, PyMods, preprocessor conditions, Py::Long vs Py::Int

This commit is contained in:
looooo
2017-02-18 20:58:58 +01:00
committed by wmayer
parent 3fab41f567
commit 5c0bcf611f
6 changed files with 135 additions and 79 deletions

View File

@@ -197,7 +197,7 @@ PyObject* FemMeshPy::addNode(PyObject *args)
SMDS_MeshNode* node = meshDS->AddNode(x,y,z);
if (!node)
throw std::runtime_error("Failed to add node");
return Py::new_reference_to(Py::Int(node->GetID()));
return Py::new_reference_to(Py::Long(node->GetID()));
}
catch (const std::exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
@@ -213,7 +213,7 @@ PyObject* FemMeshPy::addNode(PyObject *args)
SMDS_MeshNode* node = meshDS->AddNodeWithID(x,y,z,i);
if (!node)
throw std::runtime_error("Failed to add node");
return Py::new_reference_to(Py::Int(node->GetID()));
return Py::new_reference_to(Py::Long(node->GetID()));
}
catch (const std::exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
@@ -241,7 +241,7 @@ PyObject* FemMeshPy::addEdge(PyObject *args)
SMDS_MeshEdge* edge = meshDS->AddEdge(node1, node2);
if (!edge)
throw std::runtime_error("Failed to add edge");
return Py::new_reference_to(Py::Int(edge->GetID()));
return Py::new_reference_to(Py::Long(edge->GetID()));
}
catch (const std::exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
@@ -257,7 +257,11 @@ PyObject* FemMeshPy::addEdge(PyObject *args)
Py::List list(obj);
std::vector<const SMDS_MeshNode*> Nodes;
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
Py::Long NoNr(*it);
#else
Py::Int NoNr(*it);
#endif
const SMDS_MeshNode* node = meshDS->FindNode(NoNr);
if (!node)
throw std::runtime_error("Failed to get node of the given indices");
@@ -297,7 +301,11 @@ PyObject* FemMeshPy::addEdge(PyObject *args)
throw std::runtime_error("Unknown node count, [2|3] are allowed"); //unknown edge type
}
}
#if PY_MAJOR_VERSION >= 3
return Py::new_reference_to(Py::Long(edge->GetID()));
#else
return Py::new_reference_to(Py::Int(edge->GetID()));
#endif
}
PyErr_SetString(PyExc_TypeError, "addEdge accepts:\n"
"-- int,int\n"
@@ -323,7 +331,7 @@ PyObject* FemMeshPy::addFace(PyObject *args)
SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3);
if (!face)
throw std::runtime_error("Failed to add face");
return Py::new_reference_to(Py::Int(face->GetID()));
return Py::new_reference_to(Py::Long(face->GetID()));
}
catch (const std::exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
@@ -339,7 +347,11 @@ PyObject* FemMeshPy::addFace(PyObject *args)
Py::List list(obj);
std::vector<const SMDS_MeshNode*> Nodes;
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
Py::Long NoNr(*it);
#else
Py::Int NoNr(*it);
#endif
const SMDS_MeshNode* node = meshDS->FindNode(NoNr);
if (!node)
throw std::runtime_error("Failed to get node of the given indices");
@@ -398,7 +410,9 @@ PyObject* FemMeshPy::addFace(PyObject *args)
throw std::runtime_error("Unknown node count, [4|5|6|8] are allowed"); //unknown face type
}
}
return Py::new_reference_to(Py::Int(face->GetID()));
return Py::new_reference_to(Py::Long(face->GetID()));
}
PyErr_SetString(PyExc_TypeError, "addFace accepts:\n"
"-- int,int,int\n"
@@ -424,7 +438,7 @@ PyObject* FemMeshPy::addQuad(PyObject *args)
SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3, node4);
if (!face)
throw std::runtime_error("Failed to add quad");
return Py::new_reference_to(Py::Int(face->GetID()));
return Py::new_reference_to(Py::Long(face->GetID()));
}
catch (const std::exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
@@ -450,7 +464,7 @@ PyObject* FemMeshPy::addVolume(PyObject *args)
SMDS_MeshVolume* vol = meshDS->AddVolume(node1, node2, node3, node4);
if (!vol)
throw std::runtime_error("Failed to add volume");
return Py::new_reference_to(Py::Int(vol->GetID()));
return Py::new_reference_to(Py::Long(vol->GetID()));
}
catch (const std::exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
@@ -466,7 +480,11 @@ PyObject* FemMeshPy::addVolume(PyObject *args)
Py::List list(obj);
std::vector<const SMDS_MeshNode*> Nodes;
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
Py::Long NoNr(*it);
#else
Py::Int NoNr(*it);
#endif
const SMDS_MeshNode* node = meshDS->FindNode(NoNr);
if (!node)
throw std::runtime_error("Failed to get node of the given indices");
@@ -563,7 +581,9 @@ PyObject* FemMeshPy::addVolume(PyObject *args)
default: throw std::runtime_error("Unknown node count, [4|5|6|8|10|13|15|20] are allowed"); //unknown volume type
}
}
return Py::new_reference_to(Py::Int(vol->GetID()));
return Py::new_reference_to(Py::Long(vol->GetID()));
}
PyErr_SetString(PyExc_TypeError, "addVolume accepts:\n"
"-- int,int,int,int\n"
@@ -671,7 +691,11 @@ PyObject* FemMeshPy::getFacesByFace(PyObject *args)
Py::List ret;
std::list<int> resultSet = getFemMeshPtr()->getFacesByFace(fc);
for (std::list<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it) {
#if PY_MAJOR_VERSION >= 3
ret.append(Py::Long(*it));
#else
ret.append(Py::Int(*it));
#endif
}
return Py::new_reference_to(ret);
@@ -702,8 +726,8 @@ PyObject* FemMeshPy::getVolumesByFace(PyObject *args)
std::list<std::pair<int, int> > resultSet = getFemMeshPtr()->getVolumesByFace(fc);
for (std::list<std::pair<int, int> >::const_iterator it = resultSet.begin();it!=resultSet.end();++it) {
Py::Tuple vol_face(2);
vol_face.setItem(0, Py::Int(it->first));
vol_face.setItem(1, Py::Int(it->second));
vol_face.setItem(0, Py::Long(it->first));
vol_face.setItem(1, Py::Long(it->second));
ret.append(vol_face);
}
@@ -735,8 +759,8 @@ PyObject* FemMeshPy::getccxVolumesByFace(PyObject *args)
std::map<int, int> resultSet = getFemMeshPtr()->getccxVolumesByFace(fc);
for (std::map<int, int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it) {
Py::Tuple vol_face(2);
vol_face.setItem(0, Py::Int(it->first));
vol_face.setItem(1, Py::Int(it->second));
vol_face.setItem(0, Py::Long(it->first));
vol_face.setItem(1, Py::Long(it->second));
ret.append(vol_face);
}
@@ -784,7 +808,7 @@ PyObject* FemMeshPy::getNodesBySolid(PyObject *args)
Py::List ret;
std::set<int> resultSet = getFemMeshPtr()->getNodesBySolid(fc);
for (std::set<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
ret.append(Py::Int(*it));
ret.append(Py::Long(*it));
return Py::new_reference_to(ret);
@@ -812,7 +836,7 @@ PyObject* FemMeshPy::getNodesByFace(PyObject *args)
Py::List ret;
std::set<int> resultSet = getFemMeshPtr()->getNodesByFace(fc);
for (std::set<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
ret.append(Py::Int(*it));
ret.append(Py::Long(*it));
return Py::new_reference_to(ret);
@@ -840,7 +864,7 @@ PyObject* FemMeshPy::getNodesByEdge(PyObject *args)
Py::List ret;
std::set<int> resultSet = getFemMeshPtr()->getNodesByEdge(fc);
for (std::set<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
ret.append(Py::Int(*it));
ret.append(Py::Long(*it));
return Py::new_reference_to(ret);
@@ -868,7 +892,7 @@ PyObject* FemMeshPy::getNodesByVertex(PyObject *args)
Py::List ret;
std::set<int> resultSet = getFemMeshPtr()->getNodesByVertex(fc);
for (std::set<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
ret.append(Py::Int(*it));
ret.append(Py::Long(*it));
return Py::new_reference_to(ret);
@@ -891,7 +915,7 @@ PyObject* FemMeshPy::getElementNodes(PyObject *args)
Py::Tuple ret(resultSet.size());
int index = 0;
for (std::list<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
ret.setItem(index++, Py::Int(*it));
ret.setItem(index++, Py::Long(*it));
return Py::new_reference_to(ret);
}
@@ -907,8 +931,11 @@ PyObject* FemMeshPy::getGroupName(PyObject *args)
int id;
if (!PyArg_ParseTuple(args, "i", &id))
return 0;
#if PY_MAJOR_VERSION >= 3
return PyBytes_FromString(getFemMeshPtr()->getSMesh()->GetGroup(id)->GetName());
#else
return PyString_FromString(getFemMeshPtr()->getSMesh()->GetGroup(id)->GetName());
#endif
}
PyObject* FemMeshPy::getGroupElementType(PyObject *args)
@@ -929,7 +956,11 @@ PyObject* FemMeshPy::getGroupElementType(PyObject *args)
case SMDSAbs_Ball : typeString = "Ball"; break;
default : typeString = "Unknown"; break;
}
#if PY_MAJOR_VERSION >= 3
return PyBytes_FromString(typeString);
#else
return PyString_FromString(typeString);
#endif
}
PyObject* FemMeshPy::getGroupElements(PyObject *args)
@@ -948,7 +979,11 @@ PyObject* FemMeshPy::getGroupElements(PyObject *args)
Py::Tuple tuple(ids.size());
int index = 0;
for (std::set<int>::iterator it = ids.begin(); it != ids.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
tuple.setItem(index++, Py::Long(*it));
#else
tuple.setItem(index++, Py::Int(*it));
#endif
}
return Py::new_reference_to(tuple);
@@ -973,15 +1008,15 @@ Py::Dict FemMeshPy::getNodes(void) const
vec = Mtrx * vec;
int id = aNode->GetID();
dict[Py::Int(id)] = Py::asObject(new Base::VectorPy( vec ));
dict[Py::Long(id)] = Py::asObject(new Base::VectorPy( vec ));
}
return dict;
}
Py::Int FemMeshPy::getNodeCount(void) const
Py::Long FemMeshPy::getNodeCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbNodes());
return Py::Long(getFemMeshPtr()->getSMesh()->NbNodes());
}
Py::Tuple FemMeshPy::getEdges(void) const
@@ -996,15 +1031,15 @@ Py::Tuple FemMeshPy::getEdges(void) const
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));
tuple.setItem(index++, Py::Long(*it));
}
return tuple;
}
Py::Int FemMeshPy::getEdgeCount(void) const
Py::Long FemMeshPy::getEdgeCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbEdges());
return Py::Long(getFemMeshPtr()->getSMesh()->NbEdges());
}
Py::Tuple FemMeshPy::getFaces(void) const
@@ -1019,30 +1054,30 @@ Py::Tuple FemMeshPy::getFaces(void) const
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));
tuple.setItem(index++, Py::Long(*it));
}
return tuple;
}
Py::Int FemMeshPy::getFaceCount(void) const
Py::Long FemMeshPy::getFaceCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbFaces());
return Py::Long(getFemMeshPtr()->getSMesh()->NbFaces());
}
Py::Int FemMeshPy::getTriangleCount(void) const
Py::Long FemMeshPy::getTriangleCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbTriangles());
return Py::Long(getFemMeshPtr()->getSMesh()->NbTriangles());
}
Py::Int FemMeshPy::getQuadrangleCount(void) const
Py::Long FemMeshPy::getQuadrangleCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbQuadrangles());
return Py::Long(getFemMeshPtr()->getSMesh()->NbQuadrangles());
}
Py::Int FemMeshPy::getPolygonCount(void) const
Py::Long FemMeshPy::getPolygonCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbPolygons());
return Py::Long(getFemMeshPtr()->getSMesh()->NbPolygons());
}
Py::Tuple FemMeshPy::getVolumes(void) const
@@ -1057,50 +1092,50 @@ Py::Tuple FemMeshPy::getVolumes(void) const
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));
tuple.setItem(index++, Py::Long(*it));
}
return tuple;
}
Py::Int FemMeshPy::getVolumeCount(void) const
Py::Long FemMeshPy::getVolumeCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbVolumes());
return Py::Long(getFemMeshPtr()->getSMesh()->NbVolumes());
}
Py::Int FemMeshPy::getTetraCount(void) const
Py::Long FemMeshPy::getTetraCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbTetras());
return Py::Long(getFemMeshPtr()->getSMesh()->NbTetras());
}
Py::Int FemMeshPy::getHexaCount(void) const
Py::Long FemMeshPy::getHexaCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbHexas());
return Py::Long(getFemMeshPtr()->getSMesh()->NbHexas());
}
Py::Int FemMeshPy::getPyramidCount(void) const
Py::Long FemMeshPy::getPyramidCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbPyramids());
return Py::Long(getFemMeshPtr()->getSMesh()->NbPyramids());
}
Py::Int FemMeshPy::getPrismCount(void) const
Py::Long FemMeshPy::getPrismCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbPrisms());
return Py::Long(getFemMeshPtr()->getSMesh()->NbPrisms());
}
Py::Int FemMeshPy::getPolyhedronCount(void) const
Py::Long FemMeshPy::getPolyhedronCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbPolyhedrons());
return Py::Long(getFemMeshPtr()->getSMesh()->NbPolyhedrons());
}
Py::Int FemMeshPy::getSubMeshCount(void) const
Py::Long FemMeshPy::getSubMeshCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbSubMesh());
return Py::Long(getFemMeshPtr()->getSMesh()->NbSubMesh());
}
Py::Int FemMeshPy::getGroupCount(void) const
Py::Long FemMeshPy::getGroupCount(void) const
{
return Py::Int(getFemMeshPtr()->getSMesh()->NbGroup());
return Py::Long(getFemMeshPtr()->getSMesh()->NbGroup());
}
Py::Tuple FemMeshPy::getGroups(void) const
@@ -1110,7 +1145,11 @@ Py::Tuple FemMeshPy::getGroups(void) const
Py::Tuple tuple(groupIDs.size());
int index = 0;
for (std::list<int>::iterator it = groupIDs.begin(); it != groupIDs.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
tuple.setItem(index++, Py::Long(*it));
#else
tuple.setItem(index++, Py::Int(*it));
#endif
}
return tuple;
@@ -1121,6 +1160,7 @@ Py::Object FemMeshPy::getVolume(void) const
return Py::Object(new Base::QuantityPy(new Base::Quantity(getFemMeshPtr()->getVolume())));
}
// ===== custom attributes ============================================================
PyObject *FemMeshPy::getCustomAttributes(const char* /*attr*/) const