diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index c771af7d6967..dea3c3379740 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -219,7 +219,7 @@ PyTypeObject LinePyOld::Type = { } // ---> -PyMODINIT_FUNC initPart() +PyMOD_INIT_FUNC(Part) { Base::Console().Log("Module: Part\n"); @@ -337,10 +337,14 @@ PyMODINIT_FUNC initPart() ::Type,partModule,"RectangularTrimmedSurface"); Base::Interpreter().addType(&Part::PartFeaturePy ::Type,partModule,"Feature"); - Base::Interpreter().addType(&Attacher::AttachEnginePy ::Type,partModule,"AttachEngine"); +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef BRepOffsetAPIDef = {PyModuleDef_HEAD_INIT,"BRepOffsetAPI", "BRepOffsetAPI", -1, 0}; + PyObject* brepModule = PyModule_Create(&BRepOffsetAPIDef); +#else PyObject* brepModule = Py_InitModule3("BRepOffsetAPI", 0, "BrepOffsetAPI"); +#endif Py_INCREF(brepModule); PyModule_AddObject(partModule, "BRepOffsetAPI", brepModule); Base::Interpreter().addType(&Part::BRepOffsetAPI_MakePipeShellPy::Type,brepModule,"MakePipeShell"); @@ -588,4 +592,6 @@ PyMODINIT_FUNC initPart() Interface_Static::SetCVal("write.step.schema", ap.c_str()); Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product", Interface_Static::CVal("write.step.product.name")).c_str()); + + PyMOD_Return(partModule); } diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 6367229b2cf0..8ab91eec1d40 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1569,8 +1569,14 @@ class Module : public Py::ExtensionModule } } +#if PY_MAJOR_VERSION >= 3 + //FIXME: Test this! + if (PyBytes_Check(intext)) { + PyObject *p = Base::PyAsUnicodeObject(PyBytes_AsString(intext)); +#else if (PyString_Check(intext)) { - PyObject *p = Base::PyAsUnicodeObject(PyString_AsString(intext)); + PyObject *p = Base::PyAsUnicodeObject(PyString_AsString(intext)); +#endif if (!p) { throw Py::TypeError("** makeWireString can't convert PyString."); } @@ -1645,8 +1651,13 @@ class Module : public Py::ExtensionModule PyErr_Clear(); PyObject* index_or_value; if (PyArg_ParseTuple(args.ptr(), "sO", &name, &index_or_value)) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(index_or_value)) { + int ival = (int)PyLong_AsLong(index_or_value); +#else if (PyInt_Check(index_or_value)) { int ival = (int)PyInt_AsLong(index_or_value); +#endif if (!Interface_Static::SetIVal(name, ival)) { std::stringstream str; str << "Failed to set '" << name << "'"; diff --git a/src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp b/src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp index 949f299b6b8f..3052fbf1ff95 100644 --- a/src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp +++ b/src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp @@ -117,7 +117,7 @@ PyObject* BRepOffsetAPI_MakePipeShellPy::setAuxiliarySpine(PyObject *args) PyObject *spine, *curv, *keep; if (!PyArg_ParseTuple(args, "O!O!O!",&Part::TopoShapePy::Type,&spine ,&PyBool_Type,&curv - ,&PyInt_Type,&keep)) + ,&PyLong_Type,&keep)) return 0; const TopoDS_Shape& s = static_cast(spine)->getTopoShapePtr()->getShape(); if (s.IsNull() || s.ShapeType() != TopAbs_WIRE) { @@ -199,7 +199,7 @@ PyObject* BRepOffsetAPI_MakePipeShellPy::getStatus(PyObject *args) if (!PyArg_ParseTuple(args, "")) return 0; Standard_Integer val = this->getBRepOffsetAPI_MakePipeShellPtr()->GetStatus(); - return Py::new_reference_to(Py::Int(val)); + return Py::new_reference_to(Py::Long(val)); } PyObject* BRepOffsetAPI_MakePipeShellPy::makeSolid(PyObject *args) diff --git a/src/Mod/Part/App/BSplineCurvePy.xml b/src/Mod/Part/App/BSplineCurvePy.xml index 60690d624d66..987272884dea 100644 --- a/src/Mod/Part/App/BSplineCurvePy.xml +++ b/src/Mod/Part/App/BSplineCurvePy.xml @@ -19,21 +19,21 @@ Returns the polynomial degree of this B-Spline curve. - + Returns the value of the maximum polynomial degree of any B-Spline curve curve. This value is 25. - + Returns the number of poles of this B-Spline curve. - + @@ -41,7 +41,7 @@ B-Spline curve curve. This value is 25. Returns the number of knots of this B-Spline curve. - + diff --git a/src/Mod/Part/App/BSplineCurvePyImp.cpp b/src/Mod/Part/App/BSplineCurvePyImp.cpp index c39393bdc6a5..e248bc2c6e77 100644 --- a/src/Mod/Part/App/BSplineCurvePyImp.cpp +++ b/src/Mod/Part/App/BSplineCurvePyImp.cpp @@ -225,7 +225,7 @@ PyObject* BSplineCurvePy::insertKnots(PyObject * args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { - Py::Int val(*it); + Py::Long val(*it); m(index++) = (int)val; } @@ -662,7 +662,7 @@ PyObject* BSplineCurvePy::getMultiplicities(PyObject * args) curve->Multiplicities(m); Py::List mults; for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { - mults.append(Py::Int(m(i))); + mults.append(Py::Long(m(i))); } return Py::new_reference_to(mults); } @@ -673,32 +673,32 @@ PyObject* BSplineCurvePy::getMultiplicities(PyObject * args) } } -Py::Int BSplineCurvePy::getDegree(void) const +Py::Long BSplineCurvePy::getDegree(void) const { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->Degree()); + return Py::Long(curve->Degree()); } -Py::Int BSplineCurvePy::getMaxDegree(void) const +Py::Long BSplineCurvePy::getMaxDegree(void) const { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->MaxDegree()); + return Py::Long(curve->MaxDegree()); } -Py::Int BSplineCurvePy::getNbPoles(void) const +Py::Long BSplineCurvePy::getNbPoles(void) const { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->NbPoles()); + return Py::Long(curve->NbPoles()); } -Py::Int BSplineCurvePy::getNbKnots(void) const +Py::Long BSplineCurvePy::getNbKnots(void) const { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->NbKnots()); + return Py::Long(curve->NbKnots()); } Py::Object BSplineCurvePy::getStartPoint(void) const @@ -721,14 +721,14 @@ Py::Object BSplineCurvePy::getFirstUKnotIndex(void) const { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->FirstUKnotIndex()); + return Py::Long(curve->FirstUKnotIndex()); } Py::Object BSplineCurvePy::getLastUKnotIndex(void) const { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->LastUKnotIndex()); + return Py::Long(curve->LastUKnotIndex()); } Py::List BSplineCurvePy::getKnotSequence(void) const @@ -1211,11 +1211,11 @@ PyObject* BSplineCurvePy::buildFromPolesMultsKnots(PyObject *args, PyObject *key Py::Sequence multssq(mults); Standard_Integer index = 1; for (Py::Sequence::iterator it = multssq.begin(); it != multssq.end() && index <= occmults.Length(); ++it) { - Py::Int mult(*it); + Py::Long mult(*it); if (index < occmults.Length() || PyObject_Not(periodic)) { - sum_of_mults += mult; //sum up the mults to compare them against the number of poles later + sum_of_mults += static_cast(mult); //sum up the mults to compare them against the number of poles later } - occmults(index++) = mult; + occmults(index++) = static_cast(mult); } } else { //mults are 1 or degree+1 at the ends diff --git a/src/Mod/Part/App/BSplineSurfacePy.xml b/src/Mod/Part/App/BSplineSurfacePy.xml index 1fb0a985e010..b264bd460458 100644 --- a/src/Mod/Part/App/BSplineSurfacePy.xml +++ b/src/Mod/Part/App/BSplineSurfacePy.xml @@ -21,7 +21,7 @@ Returns the degree of this B-Spline surface in the u parametric direction. - + @@ -29,7 +29,7 @@ Returns the degree of this B-Spline surface in the v parametric direction. - + @@ -39,7 +39,7 @@ This value is 25. - + @@ -47,7 +47,7 @@ Returns the number of poles of this B-Spline surface in the u parametric direction. - + @@ -55,7 +55,7 @@ Returns the number of poles of this B-Spline surface in the v parametric direction. - + @@ -63,7 +63,7 @@ Returns the number of knots of this B-Spline surface in the u parametric direction. - + @@ -71,7 +71,7 @@ Returns the number of knots of this B-Spline surface in the v parametric direction. - + diff --git a/src/Mod/Part/App/BSplineSurfacePyImp.cpp b/src/Mod/Part/App/BSplineSurfacePyImp.cpp index 16ba617f5044..91aa0aab8b3b 100644 --- a/src/Mod/Part/App/BSplineSurfacePyImp.cpp +++ b/src/Mod/Part/App/BSplineSurfacePyImp.cpp @@ -286,7 +286,7 @@ PyObject* BSplineSurfacePy::insertUKnots(PyObject *args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { - Py::Int val(*it); + Py::Long val(*it); m(index++) = (int)val; } @@ -349,7 +349,7 @@ PyObject* BSplineSurfacePy::insertVKnots(PyObject *args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { - Py::Int val(*it); + Py::Long val(*it); m(index++) = (int)val; } @@ -1092,7 +1092,7 @@ PyObject* BSplineSurfacePy::getUMultiplicities(PyObject *args) surf->UMultiplicities(m); Py::List mults; for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { - mults.append(Py::Int(m(i))); + mults.append(Py::Long(m(i))); } return Py::new_reference_to(mults); } @@ -1114,7 +1114,7 @@ PyObject* BSplineSurfacePy::getVMultiplicities(PyObject *args) surf->VMultiplicities(m); Py::List mults; for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { - mults.append(Py::Int(m(i))); + mults.append(Py::Long(m(i))); } return Py::new_reference_to(mults); } @@ -1467,20 +1467,20 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k Py::Sequence umultssq(umults); Standard_Integer index = 1; for (Py::Sequence::iterator it = umultssq.begin(); it != umultssq.end() && index <= occumults.Length(); ++it) { - Py::Int mult(*it); + Py::Long mult(*it); if (index < occumults.Length() || PyObject_Not(uperiodic)) { - sum_of_umults += mult; //sum up the mults to compare them against the number of poles later + sum_of_umults += static_cast(mult); //sum up the mults to compare them against the number of poles later } - occumults(index++) = mult; + occumults(index++) = static_cast(mult); } Py::Sequence vmultssq(vmults); index = 1; for (Py::Sequence::iterator it = vmultssq.begin(); it != vmultssq.end() && index <= occvmults.Length(); ++it) { - Py::Int mult(*it); + Py::Long mult(*it); if (index < occvmults.Length() || PyObject_Not(vperiodic)) { - sum_of_vmults += mult; //sum up the mults to compare them against the number of poles later + sum_of_vmults += static_cast(mult); //sum up the mults to compare them against the number of poles later } - occvmults(index++) = mult; + occvmults(index++) = static_cast(mult); } //copy or generate knots if (uknots != Py_None) { //uknots are given @@ -1537,55 +1537,55 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k } } -Py::Int BSplineSurfacePy::getUDegree(void) const +Py::Long BSplineSurfacePy::getUDegree(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int deg = surf->UDegree(); - return Py::Int(deg); + return Py::Long(deg); } -Py::Int BSplineSurfacePy::getVDegree(void) const +Py::Long BSplineSurfacePy::getVDegree(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int deg = surf->VDegree(); - return Py::Int(deg); + return Py::Long(deg); } -Py::Int BSplineSurfacePy::getMaxDegree(void) const +Py::Long BSplineSurfacePy::getMaxDegree(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->MaxDegree()); + return Py::Long(surf->MaxDegree()); } -Py::Int BSplineSurfacePy::getNbUPoles(void) const +Py::Long BSplineSurfacePy::getNbUPoles(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->NbUPoles()); + return Py::Long(surf->NbUPoles()); } -Py::Int BSplineSurfacePy::getNbVPoles(void) const +Py::Long BSplineSurfacePy::getNbVPoles(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->NbVPoles()); + return Py::Long(surf->NbVPoles()); } -Py::Int BSplineSurfacePy::getNbUKnots(void) const +Py::Long BSplineSurfacePy::getNbUKnots(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->NbUKnots()); + return Py::Long(surf->NbUKnots()); } -Py::Int BSplineSurfacePy::getNbVKnots(void) const +Py::Long BSplineSurfacePy::getNbVKnots(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->NbVKnots()); + return Py::Long(surf->NbVKnots()); } Py::Object BSplineSurfacePy::getFirstUKnotIndex(void) const @@ -1593,7 +1593,7 @@ Py::Object BSplineSurfacePy::getFirstUKnotIndex(void) const Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int index = surf->FirstUKnotIndex(); - return Py::Int(index); + return Py::Long(index); } Py::Object BSplineSurfacePy::getLastUKnotIndex(void) const @@ -1601,7 +1601,7 @@ Py::Object BSplineSurfacePy::getLastUKnotIndex(void) const Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int index = surf->LastUKnotIndex(); - return Py::Int(index); + return Py::Long(index); } Py::Object BSplineSurfacePy::getFirstVKnotIndex(void) const @@ -1609,7 +1609,7 @@ Py::Object BSplineSurfacePy::getFirstVKnotIndex(void) const Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int index = surf->FirstVKnotIndex(); - return Py::Int(index); + return Py::Long(index); } Py::Object BSplineSurfacePy::getLastVKnotIndex(void) const @@ -1617,7 +1617,7 @@ Py::Object BSplineSurfacePy::getLastVKnotIndex(void) const Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int index = surf->LastVKnotIndex(); - return Py::Int(index); + return Py::Long(index); } Py::List BSplineSurfacePy::getUKnotSequence(void) const diff --git a/src/Mod/Part/App/BezierCurvePy.xml b/src/Mod/Part/App/BezierCurvePy.xml index 933ad4a5ac8f..f0d5d37c5ea9 100644 --- a/src/Mod/Part/App/BezierCurvePy.xml +++ b/src/Mod/Part/App/BezierCurvePy.xml @@ -24,21 +24,21 @@ Returns the polynomial degree of this Bezier curve, which is equal to the number of poles minus 1. - + Returns the value of the maximum polynomial degree of any Bezier curve curve. This value is 25. - + Returns the number of poles of this Bezier curve. - + diff --git a/src/Mod/Part/App/BezierCurvePyImp.cpp b/src/Mod/Part/App/BezierCurvePyImp.cpp index 3e5e96caa7fa..68c35d1cbffd 100644 --- a/src/Mod/Part/App/BezierCurvePyImp.cpp +++ b/src/Mod/Part/App/BezierCurvePyImp.cpp @@ -356,25 +356,25 @@ PyObject* BezierCurvePy::getResolution(PyObject* args) } } -Py::Int BezierCurvePy::getDegree(void) const +Py::Long BezierCurvePy::getDegree(void) const { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->Degree()); + return Py::Long(curve->Degree()); } -Py::Int BezierCurvePy::getMaxDegree(void) const +Py::Long BezierCurvePy::getMaxDegree(void) const { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->MaxDegree()); + return Py::Long(curve->MaxDegree()); } -Py::Int BezierCurvePy::getNbPoles(void) const +Py::Long BezierCurvePy::getNbPoles(void) const { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); - return Py::Int(curve->NbPoles()); + return Py::Long(curve->NbPoles()); } Py::Object BezierCurvePy::getStartPoint(void) const diff --git a/src/Mod/Part/App/BezierSurfacePy.xml b/src/Mod/Part/App/BezierSurfacePy.xml index dc00a30aa5b5..4c4882656b38 100644 --- a/src/Mod/Part/App/BezierSurfacePy.xml +++ b/src/Mod/Part/App/BezierSurfacePy.xml @@ -25,7 +25,7 @@ which is equal to the number of poles minus 1. - + @@ -34,7 +34,7 @@ which is equal to the number of poles minus 1. - + @@ -43,7 +43,7 @@ Bezier surface. This value is 25. - + @@ -51,7 +51,7 @@ Returns the number of poles in u direction of this Bezier surface. - + @@ -59,7 +59,7 @@ Returns the number of poles in v direction of this Bezier surface. - + diff --git a/src/Mod/Part/App/BezierSurfacePyImp.cpp b/src/Mod/Part/App/BezierSurfacePyImp.cpp index 5707cb34f290..9d370b483a7c 100644 --- a/src/Mod/Part/App/BezierSurfacePyImp.cpp +++ b/src/Mod/Part/App/BezierSurfacePyImp.cpp @@ -729,39 +729,39 @@ PyObject* BezierSurfacePy::vIso(PyObject * args) } } -Py::Int BezierSurfacePy::getUDegree(void) const +Py::Long BezierSurfacePy::getUDegree(void) const { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->UDegree()); + return Py::Long(surf->UDegree()); } -Py::Int BezierSurfacePy::getVDegree(void) const +Py::Long BezierSurfacePy::getVDegree(void) const { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->VDegree()); + return Py::Long(surf->VDegree()); } -Py::Int BezierSurfacePy::getMaxDegree(void) const +Py::Long BezierSurfacePy::getMaxDegree(void) const { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->MaxDegree()); + return Py::Long(surf->MaxDegree()); } -Py::Int BezierSurfacePy::getNbUPoles(void) const +Py::Long BezierSurfacePy::getNbUPoles(void) const { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->NbUPoles()); + return Py::Long(surf->NbUPoles()); } -Py::Int BezierSurfacePy::getNbVPoles(void) const +Py::Long BezierSurfacePy::getNbVPoles(void) const { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); - return Py::Int(surf->NbVPoles()); + return Py::Long(surf->NbVPoles()); } PyObject *BezierSurfacePy::getCustomAttributes(const char* /*attr*/) const diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index a284e2685677..dd5432c6edc9 100644 --- a/src/Mod/Part/App/GeometryCurvePyImp.cpp +++ b/src/Mod/Part/App/GeometryCurvePyImp.cpp @@ -145,10 +145,17 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) // use no kwds PyObject* dist_or_num; if (PyArg_ParseTuple(args, "O", &dist_or_num)) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(dist_or_num)) { + numPoints = PyLong_AsLong(dist_or_num); + uniformAbscissaPoints = true; + } +#else if (PyInt_Check(dist_or_num)) { numPoints = PyInt_AsLong(dist_or_num); uniformAbscissaPoints = true; } +#endif else if (PyFloat_Check(dist_or_num)) { distance = PyFloat_AsDouble(dist_or_num); uniformAbscissaDistance = true; diff --git a/src/Mod/Part/App/PropertyTopoShape.cpp b/src/Mod/Part/App/PropertyTopoShape.cpp index 433d822e690b..d323ad69b6cf 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -501,7 +501,7 @@ PyObject *PropertyFilletEdges::getPyObject(void) int index = 0; for (it = _lValueList.begin(); it != _lValueList.end(); ++it) { Py::Tuple ent(3); - ent.setItem(0, Py::Int(it->edgeid)); + ent.setItem(0, Py::Long(it->edgeid)); ent.setItem(1, Py::Float(it->radius1)); ent.setItem(2, Py::Float(it->radius2)); list[index++] = ent; @@ -518,7 +518,7 @@ void PropertyFilletEdges::setPyObject(PyObject *value) for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { FilletElement fe; Py::Tuple ent(*it); - fe.edgeid = (int)Py::Int(ent.getItem(0)); + fe.edgeid = (int)Py::Long(ent.getItem(0)); fe.radius1 = (double)Py::Float(ent.getItem(1)); fe.radius2 = (double)Py::Float(ent.getItem(2)); values.push_back(fe); diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index 98a627c38d87..03f764f610ed 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -412,10 +412,17 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) // use no kwds PyObject* dist_or_num; if (PyArg_ParseTuple(args, "O", &dist_or_num)) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(dist_or_num)) { + numPoints = PyLong_AsLong(dist_or_num); + uniformAbscissaPoints = true; + } +#else if (PyInt_Check(dist_or_num)) { numPoints = PyInt_AsLong(dist_or_num); uniformAbscissaPoints = true; } +#endif else if (PyFloat_Check(dist_or_num)) { distance = PyFloat_AsDouble(dist_or_num); uniformAbscissaDistance = true; diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 8463311e0c39..882005f5599d 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -750,7 +750,7 @@ PyObject* TopoShapePy::check(PyObject *args) if (!getTopoShapePtr()->getShape().IsNull()) { std::stringstream str; if (!getTopoShapePtr()->analyze(str)) { - PyErr_SetString(PyExc_StandardError, str.str().c_str()); + PyErr_SetString(PyExc_ValueError, str.str().c_str()); PyErr_Print(); } } @@ -1758,9 +1758,9 @@ PyObject* TopoShapePy::tessellate(PyObject *args) for (std::vector::const_iterator it = Facets.begin(); it != Facets.end(); ++it) { Py::Tuple f(3); - f.setItem(0,Py::Int((int)it->I1)); - f.setItem(1,Py::Int((int)it->I2)); - f.setItem(2,Py::Int((int)it->I3)); + f.setItem(0,Py::Long((long)it->I1)); + f.setItem(1,Py::Long((long)it->I2)); + f.setItem(2,Py::Long((long)it->I3)); facet.append(f); } tuple.setItem(1, facet); @@ -1870,9 +1870,9 @@ PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args) for (Py::Sequence::iterator it = facets.begin(); it != facets.end(); ++it) { Data::ComplexGeoData::Facet face; Py::Tuple f(*it); - face.I1 = (int)Py::Int(f[0]); - face.I2 = (int)Py::Int(f[1]); - face.I3 = (int)Py::Int(f[2]); + face.I1 = (int)Py::Long(f[0]); + face.I2 = (int)Py::Long(f[1]); + face.I3 = (int)Py::Long(f[2]); Facets.push_back(face); } @@ -2245,7 +2245,11 @@ PyObject* _getSupportIndex(char* suppStr, TopoShape* ts, TopoDS_Shape suppShape) break; } } +#if PY_MAJOR_VERSION >= 3 + return PyLong_FromLong(supportIndex); +#else return PyInt_FromLong(supportIndex); +#endif } PyObject* TopoShapePy::proximity(PyObject *args) @@ -2341,20 +2345,32 @@ PyObject* TopoShapePy::distToShape(PyObject *args) suppS1 = extss.SupportOnShape1(i); switch (supportType1) { case BRepExtrema_IsVertex: +#if PY_MAJOR_VERSION >= 3 + pSuppType1 = PyBytes_FromString("Vertex"); +#else pSuppType1 = PyString_FromString("Vertex"); +#endif pSupportIndex1 = _getSupportIndex("Vertex",ts1,suppS1); pParm1 = Py_None; pParm2 = Py_None; break; case BRepExtrema_IsOnEdge: +#if PY_MAJOR_VERSION >= 3 + pSuppType1 = PyBytes_FromString("Edge"); +#else pSuppType1 = PyString_FromString("Edge"); +#endif pSupportIndex1 = _getSupportIndex("Edge",ts1,suppS1); extss.ParOnEdgeS1(i,t1); pParm1 = PyFloat_FromDouble(t1); pParm2 = Py_None; break; case BRepExtrema_IsInFace: +#if PY_MAJOR_VERSION >= 3 + pSuppType1 = PyBytes_FromString("Face"); +#else pSuppType1 = PyString_FromString("Face"); +#endif pSupportIndex1 = _getSupportIndex("Face",ts1,suppS1); extss.ParOnFaceS1(i,u1,v1); pParm1 = PyTuple_New(2); @@ -2364,8 +2380,13 @@ PyObject* TopoShapePy::distToShape(PyObject *args) break; default: Base::Console().Message("distToShape: supportType1 is unknown: %d \n",supportType1); +#if PY_MAJOR_VERSION >= 3 + pSuppType1 = PyBytes_FromString("Unknown"); + pSupportIndex1 = PyLong_FromLong(-1); +#else pSuppType1 = PyString_FromString("Unknown"); pSupportIndex1 = PyInt_FromLong(-1); +#endif pParm1 = Py_None; pParm2 = Py_None; } @@ -2376,18 +2397,30 @@ PyObject* TopoShapePy::distToShape(PyObject *args) suppS2 = extss.SupportOnShape2(i); switch (supportType2) { case BRepExtrema_IsVertex: +#if PY_MAJOR_VERSION >= 3 + pSuppType2 = PyBytes_FromString("Vertex"); +#else pSuppType2 = PyString_FromString("Vertex"); +#endif pSupportIndex2 = _getSupportIndex("Vertex",ts2,suppS2); pParm2 = Py_None; break; case BRepExtrema_IsOnEdge: +#if PY_MAJOR_VERSION >= 3 + pSuppType2 = PyBytes_FromString("Edge"); +#else pSuppType2 = PyString_FromString("Edge"); +#endif pSupportIndex2 = _getSupportIndex("Edge",ts2,suppS2); extss.ParOnEdgeS2(i,t2); pParm2 = PyFloat_FromDouble(t2); break; case BRepExtrema_IsInFace: +#if PY_MAJOR_VERSION >= 3 + pSuppType2 = PyBytes_FromString("Face"); +#else pSuppType2 = PyString_FromString("Face"); +#endif pSupportIndex2 = _getSupportIndex("Face",ts2,suppS2); extss.ParOnFaceS2(i,u2,v2); pParm2 = PyTuple_New(2); @@ -2396,8 +2429,13 @@ PyObject* TopoShapePy::distToShape(PyObject *args) break; default: Base::Console().Message("distToShape: supportType2 is unknown: %d \n",supportType1); +#if PY_MAJOR_VERSION >= 3 + pSuppType2 = PyBytes_FromString("Unknown"); + pSupportIndex2 = PyLong_FromLong(-1); +#else pSuppType2 = PyString_FromString("Unknown"); pSupportIndex2 = PyInt_FromLong(-1); +#endif } pts = PyTuple_New(2); PyTuple_SetItem(pts,0,pPt1); diff --git a/src/Mod/Part/App/TopoShapeWirePyImp.cpp b/src/Mod/Part/App/TopoShapeWirePyImp.cpp index a2f89ca707f6..b46d5d172a94 100644 --- a/src/Mod/Part/App/TopoShapeWirePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeWirePyImp.cpp @@ -362,10 +362,17 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) // use no kwds PyObject* dist_or_num; if (PyArg_ParseTuple(args, "O", &dist_or_num)) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(dist_or_num)) { + numPoints = PyLong_AsLong(dist_or_num); + uniformAbscissaPoints = true; + } +#else if (PyInt_Check(dist_or_num)) { numPoints = PyInt_AsLong(dist_or_num); uniformAbscissaPoints = true; } +#endif else if (PyFloat_Check(dist_or_num)) { distance = PyFloat_AsDouble(dist_or_num); uniformAbscissaDistance = true; diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 450c52b547c9..9888457bb035 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -102,11 +102,11 @@ PyObject* initModule() } // namespace PartGui -PyMODINIT_FUNC initPartGui() +PyMOD_INIT_FUNC(PartGui) { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); - return; + PyMOD_Return(0); } // load needed modules @@ -115,10 +115,11 @@ PyMODINIT_FUNC initPartGui() } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); - return; + PyMOD_Return(0); } PyObject* partGuiModule = PartGui::initModule(); + Base::Console().Log("Loading GUI of Part module... done\n"); PyObject* pAttachEngineTextsModule = Py_InitModule3("AttachEngineResources", AttacherGui::AttacherGuiPy::Methods, @@ -207,4 +208,6 @@ PyMODINIT_FUNC initPartGui() Gui::BitmapFactoryInst& rclBmpFactory = Gui::BitmapFactory(); rclBmpFactory.addXPM("PartFeature",(const char**) PartFeature_xpm); rclBmpFactory.addXPM("PartFeatureImport",(const char**) PartFeatureImport_xpm); + + PyMOD_Return(partGuiModule); } diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index ff3083313a71..7be9dbf6e9f5 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -606,12 +606,12 @@ void CmdPartCompJoinFeatures::languageChange() if (!_pcAction) return; - +#if 0 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); - + Gui::Command* joinConnect = rcCmdMgr.getCommandByName("Part_JoinConnect"); if (joinConnect) { QAction* cmd0 = a[0]; @@ -635,6 +635,7 @@ void CmdPartCompJoinFeatures::languageChange() cmd2->setToolTip(QApplication::translate("Part_JoinFeatures", joinCutout->getToolTipText())); cmd2->setStatusTip(QApplication::translate("Part_JoinFeatures", joinCutout->getStatusTip())); } +#endif } bool CmdPartCompJoinFeatures::isActive(void)