diff --git a/src/Mod/Mesh/App/FacetPy.xml b/src/Mod/Mesh/App/FacetPy.xml
index d1229990f..c5c35d04d 100644
--- a/src/Mod/Mesh/App/FacetPy.xml
+++ b/src/Mod/Mesh/App/FacetPy.xml
@@ -50,7 +50,7 @@ Returns true if the facet is degenerated, otherwise false.
The index of this facet in the MeshObject
-
+
diff --git a/src/Mod/Mesh/App/FacetPyImp.cpp b/src/Mod/Mesh/App/FacetPyImp.cpp
index bec2001eb..a58971a54 100644
--- a/src/Mod/Mesh/App/FacetPyImp.cpp
+++ b/src/Mod/Mesh/App/FacetPyImp.cpp
@@ -76,10 +76,15 @@ PyObject* FacetPy::unbound(PyObject *args)
getFacetPtr()->Mesh = 0;
Py_Return;
}
-
+#if PY_MAJOR_VERSION >= 3
+Py::Long FacetPy::getIndex(void) const
+{
+ return Py::Long((long) getFacetPtr()->Index);
+#else
Py::Int FacetPy::getIndex(void) const
{
return Py::Int((long) getFacetPtr()->Index);
+#endif
}
Py::Boolean FacetPy::getBound(void) const
diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp
index 58c97818a..4b353ce39 100644
--- a/src/Mod/Mesh/App/Mesh.cpp
+++ b/src/Mod/Mesh/App/Mesh.cpp
@@ -1465,7 +1465,11 @@ MeshObject* MeshObject::createSphere(float radius, int sampling)
Py::Callable call(dict.getItem("Sphere"));
Py::Tuple args(2);
args.setItem(0, Py::Float(radius));
+#if PY_MAJOR_VERSION >= 3
+ args.setItem(1, Py::Long(sampling));
+#else
args.setItem(1, Py::Int(sampling));
+#endif
Py::List list(call.apply(args));
return createMeshFromList(list);
}
@@ -1487,7 +1491,11 @@ MeshObject* MeshObject::createEllipsoid(float radius1, float radius2, int sampli
Py::Tuple args(3);
args.setItem(0, Py::Float(radius1));
args.setItem(1, Py::Float(radius2));
+#if PY_MAJOR_VERSION >= 3
+ args.setItem(2, Py::Long(sampling));
+#else
args.setItem(2, Py::Int(sampling));
+#endif
Py::List list(call.apply(args));
return createMeshFromList(list);
}
@@ -1509,9 +1517,15 @@ MeshObject* MeshObject::createCylinder(float radius, float length, int closed, f
Py::Tuple args(5);
args.setItem(0, Py::Float(radius));
args.setItem(1, Py::Float(length));
+#if PY_MAJOR_VERSION >= 3
+ args.setItem(2, Py::Long(closed));
+ args.setItem(3, Py::Float(edgelen));
+ args.setItem(4, Py::Long(sampling));
+#else
args.setItem(2, Py::Int(closed));
args.setItem(3, Py::Float(edgelen));
args.setItem(4, Py::Int(sampling));
+#endif
Py::List list(call.apply(args));
return createMeshFromList(list);
}
@@ -1534,9 +1548,15 @@ MeshObject* MeshObject::createCone(float radius1, float radius2, float len, int
args.setItem(0, Py::Float(radius1));
args.setItem(1, Py::Float(radius2));
args.setItem(2, Py::Float(len));
+#if PY_MAJOR_VERSION >= 3
+ args.setItem(3, Py::Long(closed));
+ args.setItem(4, Py::Float(edgelen));
+ args.setItem(5, Py::Long(sampling));
+#else
args.setItem(3, Py::Int(closed));
args.setItem(4, Py::Float(edgelen));
args.setItem(5, Py::Int(sampling));
+#endif
Py::List list(call.apply(args));
return createMeshFromList(list);
}
@@ -1558,7 +1578,11 @@ MeshObject* MeshObject::createTorus(float radius1, float radius2, int sampling)
Py::Tuple args(3);
args.setItem(0, Py::Float(radius1));
args.setItem(1, Py::Float(radius2));
+#if PY_MAJOR_VERSION >= 3
+ args.setItem(2, Py::Long(sampling));
+#else
args.setItem(2, Py::Int(sampling));
+#endif
Py::List list(call.apply(args));
return createMeshFromList(list);
}
diff --git a/src/Mod/Mesh/App/MeshPointPy.xml b/src/Mod/Mesh/App/MeshPointPy.xml
index bc11b410e..5cfda8daf 100644
--- a/src/Mod/Mesh/App/MeshPointPy.xml
+++ b/src/Mod/Mesh/App/MeshPointPy.xml
@@ -46,7 +46,7 @@ have self intersections!
The index of this point in the MeshObject
-
+
diff --git a/src/Mod/Mesh/App/MeshPointPyImp.cpp b/src/Mod/Mesh/App/MeshPointPyImp.cpp
index b13d42891..e58a92d59 100644
--- a/src/Mod/Mesh/App/MeshPointPyImp.cpp
+++ b/src/Mod/Mesh/App/MeshPointPyImp.cpp
@@ -100,9 +100,15 @@ PyObject* MeshPointPy::move(PyObject *args)
Py_Return;
}
+#if PY_MAJOR_VERSION >= 3
+Py::Long MeshPointPy::getIndex(void) const
+{
+ return Py::Long((long) getMeshPointPtr()->Index);
+#else
Py::Int MeshPointPy::getIndex(void) const
{
return Py::Int((long) getMeshPointPtr()->Index);
+#endif
}
Py::Boolean MeshPointPy::getBound(void) const
diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml
index 5be3fd178..578afa197 100644
--- a/src/Mod/Mesh/App/MeshPy.xml
+++ b/src/Mod/Mesh/App/MeshPy.xml
@@ -459,13 +459,13 @@ for p in mesh.Points:
Return the number of vertices of the mesh object.
-
+
Return the number of edges of the mesh object.
-
+
@@ -480,7 +480,7 @@ for p in mesh.Facets:
Return the number of facets of the mesh object.
-
+
diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp
index 37e025336..4172e471c 100644
--- a/src/Mod/Mesh/App/MeshPyImp.cpp
+++ b/src/Mod/Mesh/App/MeshPyImp.cpp
@@ -82,8 +82,18 @@ int MeshPy::PyInit(PyObject* args, PyObject*)
Py_XDECREF(ret);
if (!ok) return -1;
}
+ else if (PyUnicode_Check(pcObj)) {
+#if PY_MAJOR_VERSION >= 3
+ getMeshObjectPtr()->load(PyUnicode_AsUTF8(pcObj));
+#else
+ PyObject* unicode = PyUnicode_AsEncodedString(pcObj, "utf-8", 0);
+ char* pItem = PyString_AsString(unicode);
+ Py_DECREF(unicode);
+ getMeshObjectPtr()->load(pItem);
+ }
else if (PyString_Check(pcObj)) {
getMeshObjectPtr()->load(PyString_AsString(pcObj));
+#endif
}
else {
PyErr_Format(PyExc_TypeError, "Cannot create a mesh out of a '%s'",
@@ -686,9 +696,15 @@ PyObject* MeshPy::addFacets(PyObject *args)
for (Py::List::iterator it = list_f.begin(); it != list_f.end(); ++it) {
Py::Tuple f(*it);
MeshCore::MeshFacet face;
+#if PY_MAJOR_VERSION >= 3
+ face._aulPoints[0] = (long)Py::Long(f.getItem(0));
+ face._aulPoints[1] = (long)Py::Long(f.getItem(1));
+ face._aulPoints[2] = (long)Py::Long(f.getItem(2));
+#else
face._aulPoints[0] = (long)Py::Int(f.getItem(0));
face._aulPoints[1] = (long)Py::Int(f.getItem(1));
face._aulPoints[2] = (long)Py::Int(f.getItem(2));
+#endif
faces.push_back(face);
}
@@ -712,7 +728,11 @@ PyObject* MeshPy::removeFacets(PyObject *args)
std::vector indices;
Py::Sequence ary(list);
for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) {
+#if PY_MAJOR_VERSION >= 3
+ Py::Long f(*it);
+#else
Py::Int f(*it);
+#endif
indices.push_back((long)f);
}
@@ -816,7 +836,11 @@ PyObject* MeshPy::getSegment(PyObject *args)
Py::List ary;
const std::vector& segm = getMeshObjectPtr()->getSegment(index).getIndices();
for (std::vector::const_iterator it = segm.begin(); it != segm.end(); ++it) {
+#if PY_MAJOR_VERSION >= 3
+ ary.append(Py::Long((int)*it));
+#else
ary.append(Py::Int((int)*it));
+#endif
}
return Py::new_reference_to(ary);
@@ -846,7 +870,11 @@ PyObject* MeshPy::getFacetSelection(PyObject *args)
std::vector facets;
getMeshObjectPtr()->getFacetsFromSelection(facets);
for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) {
+#if PY_MAJOR_VERSION >= 3
+ ary.append(Py::Long((int)*it));
+#else
ary.append(Py::Int((int)*it));
+#endif
}
return Py::new_reference_to(ary);
@@ -861,7 +889,11 @@ PyObject* MeshPy::getPointSelection(PyObject *args)
std::vector points;
getMeshObjectPtr()->getPointsFromSelection(points);
for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) {
+#if PY_MAJOR_VERSION >= 3
+ ary.append(Py::Long((int)*it));
+#else
ary.append(Py::Int((int)*it));
+#endif
}
return Py::new_reference_to(ary);
@@ -876,7 +908,11 @@ PyObject* MeshPy::meshFromSegment(PyObject *args)
std::vector segment;
Py::Sequence ary(list);
for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) {
+#if PY_MAJOR_VERSION >= 3
+ Py::Long f(*it);
+#else
Py::Int f(*it);
+#endif
segment.push_back((long)f);
}
@@ -1441,8 +1477,13 @@ PyObject* MeshPy::collapseFacets(PyObject *args)
std::vector facets;
for (int i = 0; i < PyList_Size(pcObj); i++) {
PyObject *idx = PyList_GetItem(pcObj, i);
+#if PY_MAJOR_VERSION >= 3
+ if (PyLong_Check(idx)){
+ unsigned long iIdx = PyLong_AsLong(idx);
+#else
if (PyInt_Check(idx)){
unsigned long iIdx = PyInt_AsLong(idx);
+#endif
facets.push_back(iIdx);
}
else {
@@ -1487,7 +1528,11 @@ PyObject* MeshPy::foraminate(PyObject *args)
tuple.setItem(0, Py::Float(res.x));
tuple.setItem(1, Py::Float(res.y));
tuple.setItem(2, Py::Float(res.z));
+#if PY_MAJOR_VERSION >= 3
+ dict.setItem(Py::Long(index), tuple);
+#else
dict.setItem(Py::Int(index), tuple);
+#endif
}
}
@@ -1615,7 +1660,11 @@ PyObject* MeshPy::nearestFacetOnRay(PyObject *args)
tuple.setItem(0, Py::Float(res.x));
tuple.setItem(1, Py::Float(res.y));
tuple.setItem(2, Py::Float(res.z));
+#if PY_MAJOR_VERSION >= 3
+ dict.setItem(Py::Long((int)index), tuple);
+#else
dict.setItem(Py::Int((int)index), tuple);
+#endif
}
#if 0 // for testing only
@@ -1660,7 +1709,11 @@ PyObject* MeshPy::getPlanarSegments(PyObject *args)
const std::vector& segm = it->getIndices();
Py::List ary;
for (std::vector::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) {
+#if PY_MAJOR_VERSION >= 3
+ ary.append(Py::Long((int)*jt));
+#else
ary.append(Py::Int((int)*jt));
+#endif
}
s.append(ary);
}
@@ -1687,7 +1740,11 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
float c2 = (float)Py::Float(t[1]);
float tol1 = (float)Py::Float(t[2]);
float tol2 = (float)Py::Float(t[3]);
+#if PY_MAJOR_VERSION >= 3
+ int num = (int)Py::Long(t[4]);
+#else
int num = (int)Py::Int(t[4]);
+#endif
segm.push_back(new MeshCore::MeshCurvatureFreeformSegment(meshCurv.GetCurvature(), num, tol1, tol2, c1, c2));
}
@@ -1699,7 +1756,11 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
for (std::vector::const_iterator it = data.begin(); it != data.end(); ++it) {
Py::List ary;
for (MeshCore::MeshSegment::const_iterator jt = it->begin(); jt != it->end(); ++jt) {
+#if PY_MAJOR_VERSION >= 3
+ ary.append(Py::Long((int)*jt));
+#else
ary.append(Py::Int((int)*jt));
+#endif
}
list.append(ary);
}
@@ -1708,7 +1769,22 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
return Py::new_reference_to(list);
}
+#if PY_MAJOR_VERSION >= 3
+Py::Long MeshPy::getCountPoints(void) const
+{
+ return Py::Long((long)getMeshObjectPtr()->countPoints());
+}
+Py::Long MeshPy::getCountEdges(void) const
+{
+ return Py::Long((long)getMeshObjectPtr()->countEdges());
+}
+
+Py::Long MeshPy::getCountFacets(void) const
+{
+ return Py::Long((long)getMeshObjectPtr()->countFacets());
+}
+#else
Py::Int MeshPy::getCountPoints(void) const
{
return Py::Int((long)getMeshObjectPtr()->countPoints());
@@ -1723,6 +1799,7 @@ Py::Int MeshPy::getCountFacets(void) const
{
return Py::Int((long)getMeshObjectPtr()->countFacets());
}
+#endif
Py::Float MeshPy::getArea(void) const
{
@@ -1780,9 +1857,15 @@ Py::Tuple MeshPy::getTopology(void) const
for (std::vector::const_iterator
it = Facets.begin(); it != Facets.end(); ++it) {
Py::Tuple f(3);
+#if PY_MAJOR_VERSION >= 3
+ f.setItem(0,Py::Long((int)it->I1));
+ f.setItem(1,Py::Long((int)it->I2));
+ f.setItem(2,Py::Long((int)it->I3));
+#else
f.setItem(0,Py::Int((int)it->I1));
f.setItem(1,Py::Int((int)it->I2));
f.setItem(2,Py::Int((int)it->I3));
+#endif
facet.append(f);
}
tuple.setItem(1, facet);