From 1e795e869c9c4dfa5375232d239a51651863c398 Mon Sep 17 00:00:00 2001 From: luz paz Date: Fri, 23 Apr 2021 16:29:53 -0400 Subject: [PATCH] [FEM] remove Py2 code --- src/Mod/Fem/App/FemMeshPyImp.cpp | 56 -------------------------------- src/Mod/Fem/App/HypothesisPy.cpp | 12 ------- 2 files changed, 68 deletions(-) diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index bc9c592d5e..cc2ddde654 100644 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -262,11 +262,7 @@ PyObject* FemMeshPy::addEdge(PyObject *args) Py::List list(obj); std::vector 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"); @@ -306,11 +302,7 @@ 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" @@ -352,11 +344,7 @@ PyObject* FemMeshPy::addFace(PyObject *args) Py::List list(obj); std::vector 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"); @@ -485,11 +473,7 @@ PyObject* FemMeshPy::addVolume(PyObject *args) Py::List list(obj); std::vector 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"); @@ -699,11 +683,7 @@ PyObject* FemMeshPy::getFacesByFace(PyObject *args) Py::List ret; std::list resultSet = getFemMeshPtr()->getFacesByFace(fc); for (std::list::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); @@ -733,11 +713,7 @@ PyObject* FemMeshPy::getEdgesByEdge(PyObject *args) Py::List ret; std::list resultSet = getFemMeshPtr()->getEdgesByEdge(fc); for (std::list::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); @@ -965,11 +941,7 @@ PyObject* FemMeshPy::getGroupName(PyObject *args) int id; if (!PyArg_ParseTuple(args, "i", &id)) return 0; -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromString(getFemMeshPtr()->getSMesh()->GetGroup(id)->GetName()); -#else - return PyString_FromString(getFemMeshPtr()->getSMesh()->GetGroup(id)->GetName()); -#endif } PyObject* FemMeshPy::getGroupElementType(PyObject *args) @@ -995,11 +967,7 @@ PyObject* FemMeshPy::getGroupElementType(PyObject *args) case SMDSAbs_Ball : typeString = "Ball"; break; default : typeString = "Unknown"; break; } -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromString(typeString); -#else - return PyString_FromString(typeString); -#endif } PyObject* FemMeshPy::getGroupElements(PyObject *args) @@ -1024,11 +992,7 @@ PyObject* FemMeshPy::getGroupElements(PyObject *args) Py::Tuple tuple(ids.size()); int index = 0; for (std::set::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); @@ -1061,11 +1025,7 @@ PyObject* FemMeshPy::addGroup(PyObject *args) } std::cout << "Added Group: Name: \'" << EncodedName << "\' Type: \'" << EncodedTypeString << "\' id: " << retId << std::endl; -#if PY_MAJOR_VERSION >= 3 return PyLong_FromLong(retId); -#else - return PyInt_FromLong(retId); -#endif } PyObject* FemMeshPy::addGroupElements(PyObject *args) @@ -1088,19 +1048,11 @@ PyObject* FemMeshPy::addGroupElements(PyObject *args) std::cout << "AddGroupElements: num elements: " << n << " sizeof: " << sizeof(n) << std::endl; for (Py_ssize_t i = 0; i < n; i++) { pItem = PyList_GetItem(pList, i); -#if PY_MAJOR_VERSION >= 3 if(!PyLong_Check(pItem)) { -#else - if(!PyInt_Check(pItem)) { -#endif PyErr_SetString(PyExc_TypeError, "AddGroupElements: List items must be integers."); return 0; } -#if PY_MAJOR_VERSION >= 3 ids.insert(PyLong_AsSsize_t(pItem)); -#else - ids.insert(PyInt_AsSsize_t(pItem)); -#endif // Py_ssize_t transparently handles maximum array lengths on 32bit and 64bit machines // See: https://www.python.org/dev/peps/pep-0353/ } @@ -1157,11 +1109,7 @@ PyObject* FemMeshPy::getElementType(PyObject *args) } } -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromString(typeString); -#else - return PyString_FromString(typeString); -#endif } PyObject* FemMeshPy::getIdByElementType(PyObject *args) @@ -1386,11 +1334,7 @@ Py::Tuple FemMeshPy::getGroups(void) const Py::Tuple tuple(groupIDs.size()); int index = 0; for (std::list::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; diff --git a/src/Mod/Fem/App/HypothesisPy.cpp b/src/Mod/Fem/App/HypothesisPy.cpp index 67651204c6..9dfb45ee34 100755 --- a/src/Mod/Fem/App/HypothesisPy.cpp +++ b/src/Mod/Fem/App/HypothesisPy.cpp @@ -1134,11 +1134,7 @@ StdMeshers_NumberOfSegmentsPy::~StdMeshers_NumberOfSegmentsPy() Py::Object StdMeshers_NumberOfSegmentsPy::setNumSegm(const Py::Tuple& args) { -#if PY_MAJOR_VERSION >= 3 hypothesis()->SetNumberOfSegments((int)Py::Long(args[0])); -#else - hypothesis()->SetNumberOfSegments((int)Py::Int(args[0])); -#endif return Py::None(); } @@ -1178,11 +1174,7 @@ StdMeshers_NumberOfLayersPy::~StdMeshers_NumberOfLayersPy() Py::Object StdMeshers_NumberOfLayersPy::setNumLayers(const Py::Tuple& args) { -#if PY_MAJOR_VERSION >= 3 hypothesis()->SetNumberOfLayers((int)Py::Long(args[0])); -#else - hypothesis()->SetNumberOfLayers((int)Py::Int(args[0])); -#endif return Py::None(); } @@ -1287,11 +1279,7 @@ StdMeshers_LengthFromEdgesPy::~StdMeshers_LengthFromEdgesPy() Py::Object StdMeshers_LengthFromEdgesPy::setMode(const Py::Tuple& args) { -#if PY_MAJOR_VERSION >= 3 hypothesis()->SetMode((int)Py::Long(args[0])); -#else - hypothesis()->SetMode((int)Py::Int(args[0])); -#endif return Py::None(); }