diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index c771af7d6..f111e19b7 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -163,8 +163,9 @@ public: /// Type structure of LinePyOld PyTypeObject LinePyOld::Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ + // PyObject_HEAD_INIT(&PyType_Type) + // 0, /*ob_size*/ + PyVarObject_HEAD_INIT(&PyType_Type,0) "Part.Line", /*tp_name*/ sizeof(LinePyOld), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -186,7 +187,11 @@ PyTypeObject LinePyOld::Type = { /* --- Functions to access object as input/output buffer ---------*/ 0, /* tp_as_buffer */ /* --- Flags to define presence of optional/expanded features */ - Py_TPFLAGS_HAVE_CLASS, /*tp_flags */ +#if PY_MAJOR_VERSION >= 3 + Py_TPFLAGS_DEFAULT, /*tp_flags */ +#else + Py_TPFLAGS_HAVE_CLASS, /*tp_flags */ +#endif "", 0, /*tp_traverse */ 0, /*tp_clear */ @@ -214,12 +219,15 @@ PyTypeObject LinePyOld::Type = { 0, /*tp_weaklist */ 0, /*tp_del */ 0 /*tp_version_tag */ +#if PY_MAJOR_VERSION >=3 + ,0 /*tp_finalize */ +#endif }; } // ---> -PyMODINIT_FUNC initPart() +PyMOD_INIT_FUNC(Part) { Base::Console().Log("Module: Part\n"); @@ -337,16 +345,25 @@ 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"); // Geom2d package - PyObject* geom2dModule = Py_InitModule3("Geom2d", 0, "Geom2d"); +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef geom2dDef = {PyModuleDef_HEAD_INIT,"Geom2dD", "Geom2d", -1, 0}; + PyObject* geom2dModule = PyModule_Create(&geom2dDef); +#else + PyObject* geom2dModule = Py_InitModule3("Geom2d", 0, "Geom2d"); +#endif Py_INCREF(geom2dModule); PyModule_AddObject(partModule, "Geom2d", geom2dModule); Base::Interpreter().addType(&Part::Geometry2dPy::Type,geom2dModule,"Geometry2d"); @@ -366,7 +383,9 @@ PyMODINIT_FUNC initPart() Base::Interpreter().addType(&Part::Line2dSegmentPy::Type,geom2dModule,"Line2dSegment"); Base::Interpreter().addType(&Part::Line2dPy::Type,geom2dModule,"Line2d"); Base::Interpreter().addType(&Part::OffsetCurve2dPy::Type,geom2dModule,"OffsetCurve2d"); - +#if 0 /* for python3 this isn't working anymore, it's solved by importing the BOPTools + directly. (import BOPTools) */ +// this causes double initialisation of the part modul with python3. try { //import all submodules of BOPTools, to make them easy to browse in Py console. //It's done in this weird manner instead of bt.caMemberFunction("importAll"), @@ -379,6 +398,7 @@ PyMODINIT_FUNC initPart() Base::Console().Error("Failed to import BOPTools package:\n"); err.ReportException(); } +#endif Part::TopoShape ::init(); Part::PropertyPartShape ::init(); @@ -588,4 +608,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 6367229b2..8ab91eec1 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1569,8 +1569,14 @@ private: } } +#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 @@ private: 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/AttachEnginePyImp.cpp b/src/Mod/Part/App/AttachEnginePyImp.cpp index fe2abd3c7..64054f97b 100644 --- a/src/Mod/Part/App/AttachEnginePyImp.cpp +++ b/src/Mod/Part/App/AttachEnginePyImp.cpp @@ -257,8 +257,11 @@ PyObject* AttachEnginePy::getModeInfo(PyObject* args) } Py::Dict ret; ret["ReferenceCombinations"] = pyListOfCombinations; +#if PY_MAJOR_VERSION >= 3 + ret["ModeIndex"] = Py::Long(mmode); +#else ret["ModeIndex"] = Py::Int(mmode); - +#endif try { Py::Module module(PyImport_ImportModule("PartGui"),true); if (!module.hasAttr("AttachEngineResources")) { @@ -269,7 +272,11 @@ PyObject* AttachEnginePy::getModeInfo(PyObject* args) Py::Callable method(submod.getAttr("getModeStrings")); Py::Tuple arg(2); arg.setItem(0, Py::String(this->getAttachEnginePtr()->getTypeId().getName())); +#if PY_MAJOR_VERSION >= 3 + arg.setItem(1, Py::Long(mmode)); +#else arg.setItem(1, Py::Int(mmode)); +#endif Py::List strs = method.apply(arg); assert(strs.size() == 2); ret["UserFriendlyName"] = strs[0]; @@ -342,8 +349,13 @@ PyObject* AttachEnginePy::getRefTypeInfo(PyObject* args) AttachEngine &attacher = *(this->getAttachEnginePtr()); eRefType rt = attacher.getRefTypeByName(typeName); Py::Dict ret; +#if PY_MAJOR_VERSION >= 3 + ret["TypeIndex"] = Py::Long(rt); + ret["Rank"] = Py::Long(AttachEngine::getTypeRank(rt)); +#else ret["TypeIndex"] = Py::Int(rt); ret["Rank"] = Py::Int(AttachEngine::getTypeRank(rt)); +#endif try { Py::Module module(PyImport_ImportModule("PartGui"),true); @@ -354,7 +366,11 @@ PyObject* AttachEnginePy::getRefTypeInfo(PyObject* args) Py::Object submod(module.getAttr("AttachEngineResources")); Py::Callable method(submod.getAttr("getRefTypeUserFriendlyName")); Py::Tuple arg(1); +#if PY_MAJOR_VERSION >= 3 + arg.setItem(0, Py::Long(rt)); +#else arg.setItem(0, Py::Int(rt)); +#endif Py::String st = method.apply(arg); ret["UserFriendlyName"] = st; } catch (Py::Exception& e) { diff --git a/src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp b/src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp index 949f299b6..3052fbf1f 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 60690d624..987272884 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 c39393bdc..5a8a19bcb 100644 --- a/src/Mod/Part/App/BSplineCurvePyImp.cpp +++ b/src/Mod/Part/App/BSplineCurvePyImp.cpp @@ -225,7 +225,11 @@ PyObject* BSplineCurvePy::insertKnots(PyObject * args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + Py::Long val(*it); +#else Py::Int val(*it); +#endif m(index++) = (int)val; } @@ -662,7 +666,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); } @@ -672,33 +676,32 @@ PyObject* BSplineCurvePy::getMultiplicities(PyObject * args) return 0; } } - -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 +724,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 +1214,15 @@ 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) { +#if PY_MAJOR_VERSION >= 3 + Py::Long mult(*it); +#else Py::Int mult(*it); +#endif 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 1fb0a985e..b264bd460 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 16ba617f5..30dd146b9 100644 --- a/src/Mod/Part/App/BSplineSurfacePyImp.cpp +++ b/src/Mod/Part/App/BSplineSurfacePyImp.cpp @@ -286,7 +286,11 @@ PyObject* BSplineSurfacePy::insertUKnots(PyObject *args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + Py::Long val(*it); +#else Py::Int val(*it); +#endif m(index++) = (int)val; } @@ -349,7 +353,11 @@ PyObject* BSplineSurfacePy::insertVKnots(PyObject *args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + Py::Long val(*it); +#else Py::Int val(*it); +#endif m(index++) = (int)val; } @@ -1092,7 +1100,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 +1122,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 +1475,28 @@ 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) { +#if PY_MAJOR_VERSION >= 3 + Py::Long mult(*it); +#else Py::Int mult(*it); +#endif 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) { +#if PY_MAJOR_VERSION >= 3 + Py::Long mult(*it); +#else Py::Int mult(*it); +#endif 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 @@ -1536,56 +1552,55 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k return 0; } } - -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 +1608,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 +1616,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 +1624,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 +1632,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 933ad4a5a..f0d5d37c5 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 3e5e96caa..302468c60 100644 --- a/src/Mod/Part/App/BezierCurvePyImp.cpp +++ b/src/Mod/Part/App/BezierCurvePyImp.cpp @@ -355,26 +355,25 @@ PyObject* BezierCurvePy::getResolution(PyObject* args) return 0; } } - -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 dc00a30aa..4c4882656 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 5707cb34f..973ef8dba 100644 --- a/src/Mod/Part/App/BezierSurfacePyImp.cpp +++ b/src/Mod/Part/App/BezierSurfacePyImp.cpp @@ -728,40 +728,39 @@ PyObject* BezierSurfacePy::vIso(PyObject * args) return 0; } } - -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/Geom2d/BSplineCurve2dPy.xml b/src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml index 33a60260d..162281297 100644 --- a/src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml +++ b/src/Mod/Part/App/Geom2d/BSplineCurve2dPy.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/Geom2d/BSplineCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp index 7e04fe766..7553844d4 100644 --- a/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp +++ b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp @@ -214,7 +214,11 @@ PyObject* BSplineCurve2dPy::insertKnots(PyObject * args) TColStd_Array1OfInteger m(1,mults.size()); index=1; for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + Py::Long val(*it); +#else Py::Int val(*it); +#endif m(index++) = (int)val; } @@ -408,7 +412,7 @@ PyObject* BSplineCurve2dPy::getPoles(PyObject * args) try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); - TColgp_Array1OfPnt2d p(1,curve->NbPoles()); + TColgp_Array1OfPnt2d p(1, (int)curve->NbPoles()); curve->Poles(p); Py::List poles; @@ -645,7 +649,11 @@ PyObject* BSplineCurve2dPy::getMultiplicities(PyObject * args) curve->Multiplicities(m); Py::List mults; for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { +#if PY_MAJOR_VERSION >= 3 + mults.append(Py::Long(m(i))); +#else mults.append(Py::Int(m(i))); +#endif } return Py::new_reference_to(mults); } @@ -656,32 +664,32 @@ PyObject* BSplineCurve2dPy::getMultiplicities(PyObject * args) } } -Py::Int BSplineCurve2dPy::getDegree(void) const +Py::Long BSplineCurve2dPy::getDegree(void) const { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->Degree()); + return Py::Long(curve->Degree()); } -Py::Int BSplineCurve2dPy::getMaxDegree(void) const +Py::Long BSplineCurve2dPy::getMaxDegree(void) const { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->MaxDegree()); + return Py::Long(curve->MaxDegree()); } -Py::Int BSplineCurve2dPy::getNbPoles(void) const +Py::Long BSplineCurve2dPy::getNbPoles(void) const { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->NbPoles()); + return Py::Long(curve->NbPoles()); } -Py::Int BSplineCurve2dPy::getNbKnots(void) const +Py::Long BSplineCurve2dPy::getNbKnots(void) const { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->NbKnots()); + return Py::Long(curve->NbKnots()); } Py::Object BSplineCurve2dPy::getStartPoint(void) const @@ -716,14 +724,22 @@ Py::Object BSplineCurve2dPy::getFirstUKnotIndex(void) const { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); +#if PY_MAJOR_VERSION >= 3 + return Py::Long(curve->FirstUKnotIndex()); +#else return Py::Int(curve->FirstUKnotIndex()); +#endif } Py::Object BSplineCurve2dPy::getLastUKnotIndex(void) const { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->LastUKnotIndex()); +#if PY_MAJOR_VERSION >= 3 + return Py::Long(curve->LastUKnotIndex()); +#else + return Py::Int(curve->FirstUKnotIndex()); +#endif } Py::List BSplineCurve2dPy::getKnotSequence(void) const @@ -733,12 +749,12 @@ Py::List BSplineCurve2dPy::getKnotSequence(void) const Standard_Integer m = 0; if (curve->IsPeriodic()) { // knots=poles+2*degree-mult(1)+2 - m = curve->NbPoles() + 2*curve->Degree() - curve->Multiplicity(1) + 2; + m = (int)(curve->NbPoles() + 2*curve->Degree() - curve->Multiplicity(1) + 2); } else { // knots=poles+degree+1 for (int i=1; i<= curve->NbKnots(); i++) - m += curve->Multiplicity(i); + m += (int)curve->Multiplicity(i); } TColStd_Array1OfReal k(1,m); @@ -1208,9 +1224,13 @@ PyObject* BSplineCurve2dPy::buildFromPolesMultsKnots(PyObject *args, PyObject *k Py::Sequence multssq(mults); Standard_Integer index = 1; for (Py::Sequence::iterator it = multssq.begin(); it != multssq.end() && index <= occmults.Length(); ++it) { +#if PY_MAJOR_VERSION >=3 + Py::Long mult(*it); +#else Py::Int mult(*it); +#endif 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 += (int)mult; //sum up the mults to compare them against the number of poles later } occmults(index++) = mult; } diff --git a/src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml b/src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml index 0f69c0e05..c0bd222a5 100644 --- a/src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml +++ b/src/Mod/Part/App/Geom2d/BezierCurve2dPy.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/Geom2d/BezierCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp index 15d9605e3..002d139d2 100644 --- a/src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp +++ b/src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp @@ -362,26 +362,25 @@ PyObject* BezierCurve2dPy::getResolution(PyObject* args) return 0; } } - -Py::Int BezierCurve2dPy::getDegree(void) const +Py::Long BezierCurve2dPy::getDegree(void) const { Handle_Geom2d_BezierCurve curve = Handle_Geom2d_BezierCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->Degree()); + return Py::Long(curve->Degree()); } -Py::Int BezierCurve2dPy::getMaxDegree(void) const +Py::Long BezierCurve2dPy::getMaxDegree(void) const { Handle_Geom2d_BezierCurve curve = Handle_Geom2d_BezierCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->MaxDegree()); + return Py::Long(curve->MaxDegree()); } -Py::Int BezierCurve2dPy::getNbPoles(void) const +Py::Long BezierCurve2dPy::getNbPoles(void) const { Handle_Geom2d_BezierCurve curve = Handle_Geom2d_BezierCurve::DownCast (getGeometry2dPtr()->handle()); - return Py::Int(curve->NbPoles()); + return Py::Long(curve->NbPoles()); } Py::Object BezierCurve2dPy::getStartPoint(void) const diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index a284e2685..dd5432c6e 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 433d822e6..726e0a69e 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -501,7 +501,11 @@ PyObject *PropertyFilletEdges::getPyObject(void) int index = 0; for (it = _lValueList.begin(); it != _lValueList.end(); ++it) { Py::Tuple ent(3); +#if PY_MAJOR_VERSION >= 3 + ent.setItem(0, Py::Long(it->edgeid)); +#else ent.setItem(0, Py::Int(it->edgeid)); +#endif ent.setItem(1, Py::Float(it->radius1)); ent.setItem(2, Py::Float(it->radius2)); list[index++] = ent; @@ -518,7 +522,11 @@ void PropertyFilletEdges::setPyObject(PyObject *value) for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { FilletElement fe; Py::Tuple ent(*it); +#if PY_MAJOR_VERSION >= 3 + fe.edgeid = (int)Py::Long(ent.getItem(0)); +#else fe.edgeid = (int)Py::Int(ent.getItem(0)); +#endif 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 98a627c38..03f764f61 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 8463311e0..274f1e19b 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,15 @@ PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args) for (Py::Sequence::iterator it = facets.begin(); it != facets.end(); ++it) { Data::ComplexGeoData::Facet face; Py::Tuple f(*it); +#if PY_MAJOR_VERSION >= 3 + face.I1 = (int)Py::Long(f[0]); + face.I2 = (int)Py::Long(f[1]); + face.I3 = (int)Py::Long(f[2]); +#else face.I1 = (int)Py::Int(f[0]); face.I2 = (int)Py::Int(f[1]); face.I3 = (int)Py::Int(f[2]); +#endif Facets.push_back(face); } @@ -2245,7 +2251,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) @@ -2286,11 +2296,19 @@ PyObject* TopoShapePy::proximity(PyObject *args) for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (proximity.OverlapSubShapes1()); anIt1.More(); anIt1.Next()) { //PyList_Append(overlappss1, new TopoShapeFacePy(new TopoShape(proximity.GetSubShape1 (anIt1.Key())))); +#if PY_MAJOR_VERSION >= 3 + PyList_Append(overlappssindex1,PyLong_FromLong(anIt1.Key()+1)); +#else PyList_Append(overlappssindex1,PyInt_FromLong(anIt1.Key()+1)); +#endif } for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (proximity.OverlapSubShapes2()); anIt2.More(); anIt2.Next()) { //PyList_Append(overlappss2, new TopoShapeFacePy(new TopoShape(proximity.GetSubShape2 (anIt2.Key())))); +#if PY_MAJOR_VERSION >= 3 + PyList_Append(overlappssindex2,PyLong_FromLong(anIt2.Key()+1)); +#else PyList_Append(overlappssindex2,PyInt_FromLong(anIt2.Key()+1)); +#endif } //return Py_BuildValue("OO", overlappss1, overlappss2); //subshapes return Py_BuildValue("OO", overlappssindex1, overlappssindex2); //face indexes @@ -2341,20 +2359,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 +2394,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 +2411,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 +2443,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 a2f89ca70..b46d5d172 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/AttachmentEditor/Commands.py b/src/Mod/Part/AttachmentEditor/Commands.py index c88012f85..088d8b55c 100644 --- a/src/Mod/Part/AttachmentEditor/Commands.py +++ b/src/Mod/Part/AttachmentEditor/Commands.py @@ -83,7 +83,7 @@ class CommandEditAttachment: from PySide import QtGui mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(err.message) + mb.setText(str(err)) mb.setWindowTitle("Error") mb.exec_() diff --git a/src/Mod/Part/AttachmentEditor/TaskAttachmentEditor.py b/src/Mod/Part/AttachmentEditor/TaskAttachmentEditor.py index bef4e51d7..e17eddf4d 100644 --- a/src/Mod/Part/AttachmentEditor/TaskAttachmentEditor.py +++ b/src/Mod/Part/AttachmentEditor/TaskAttachmentEditor.py @@ -40,7 +40,7 @@ except ImportError as err: def getAllDependent(feature): return [] App.Console.PrintWarning("AttachmentEditor: Failed to import some code from Show module. Functionality will be limited.\n") - App.Console.PrintWarning(err.message) + App.Console.PrintWarning(str(err)) if App.GuiUp: import FreeCADGui as Gui @@ -583,7 +583,7 @@ class AttachmentEditorTaskPanel(FrozenClass): # when entering and extiting dialog without changing anything self.obj.Placement = new_plm except Exception as err: - self.form.message.setText(_translate('AttachmentEditor',"Error: {err}",None).format(err= err.message)) + self.form.message.setText(_translate('AttachmentEditor',"Error: {err}",None).format(err= str(err))) if new_plm is not None: self.form.groupBox_superplacement.setTitle(_translate('AttachmentEditor',"Extra placement:",None)) diff --git a/src/Mod/Part/BOPTools/JoinFeatures.py b/src/Mod/Part/BOPTools/JoinFeatures.py index 91b41fbb5..eea36bf17 100644 --- a/src/Mod/Part/BOPTools/JoinFeatures.py +++ b/src/Mod/Part/BOPTools/JoinFeatures.py @@ -83,7 +83,7 @@ def cmdCreateJoinFeature(name, mode): mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText(_translate("Part_JoinFeatures","Computing the result failed with an error: \n\n{err}\n\n Click 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= err.message)) + .format(err= str(err))) mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) btnOK = mb.addButton(_translate("Part_JoinFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) @@ -167,7 +167,7 @@ class ViewProviderConnect: for obj in self.claimChildren(): obj.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True class CommandConnect: @@ -261,7 +261,7 @@ class ViewProviderEmbed: self.Object.Base.ViewObject.show() self.Object.Tool.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True class CommandEmbed: @@ -356,7 +356,7 @@ class ViewProviderCutout: self.Object.Base.ViewObject.show() self.Object.Tool.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True diff --git a/src/Mod/Part/BOPTools/SplitFeatures.py b/src/Mod/Part/BOPTools/SplitFeatures.py index 1d639c72a..4c326b431 100644 --- a/src/Mod/Part/BOPTools/SplitFeatures.py +++ b/src/Mod/Part/BOPTools/SplitFeatures.py @@ -119,7 +119,7 @@ class ViewProviderBooleanFragments: for obj in self.claimChildren(): obj.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True def cmdCreateBooleanFragmentsFeature(name, mode): @@ -141,7 +141,7 @@ def cmdCreateBooleanFragmentsFeature(name, mode): mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= err.message)) + .format(err= str(err))) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) @@ -246,7 +246,7 @@ class ViewProviderSlice: for obj in self.claimChildren(): obj.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True def cmdCreateSliceFeature(name, mode): @@ -269,7 +269,7 @@ def cmdCreateSliceFeature(name, mode): mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= err.message)) + .format(err= str(err))) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) @@ -374,7 +374,7 @@ class ViewProviderXOR: for obj in self.claimChildren(): obj.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True def cmdCreateXORFeature(name): @@ -395,7 +395,7 @@ def cmdCreateXORFeature(name): mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= err.message)) + .format(err= str(err))) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 450c52b54..42329b95d 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,14 +115,21 @@ 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"); +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef pAttachEngineTextsModuleDef = {PyModuleDef_HEAD_INIT,"AttachEngineResources", "AttachEngineResources", -1, 0}; + PyObject* pAttachEngineTextsModule = PyModule_Create(&pAttachEngineTextsModuleDef); +#else PyObject* pAttachEngineTextsModule = Py_InitModule3("AttachEngineResources", AttacherGui::AttacherGuiPy::Methods, "AttachEngine Gui resources"); +#endif + Py_INCREF(pAttachEngineTextsModule); PyModule_AddObject(partGuiModule, "AttachEngineResources", pAttachEngineTextsModule); @@ -207,4 +214,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 ff3083313..7be9dbf6e 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) diff --git a/src/Mod/Part/InitGui.py b/src/Mod/Part/InitGui.py index 1d4989448..0bed950fb 100644 --- a/src/Mod/Part/InitGui.py +++ b/src/Mod/Part/InitGui.py @@ -41,14 +41,15 @@ class PartWorkbench ( Workbench ): def Initialize(self): # load the module import PartGui - import Part + import BOPTools import CompoundTools._CommandCompoundFilter try: - Part.BOPTools.addCommands() + BOPTools.importAll() + BOPTools.addCommands() except Exception as err: - FreeCAD.Console.PrintError("Features from BOPTools package cannot be loaded. {err}\n".format(err= err.message)) + FreeCAD.Console.PrintError("Features from BOPTools package cannot be loaded. {err}\n".format(err= str(err))) def GetClassName(self): return "PartGui::Workbench" diff --git a/src/Mod/Part/JoinFeatures.py b/src/Mod/Part/JoinFeatures.py index 06046efa0..ffa74492b 100644 --- a/src/Mod/Part/JoinFeatures.py +++ b/src/Mod/Part/JoinFeatures.py @@ -158,7 +158,7 @@ class _ViewProviderPartJoinFeature: self.Object.Base.ViewObject.show() self.Object.Tool.ViewObject.show() except Exception as err: - FreeCAD.Console.PrintError("Error in onDelete: " + err.message) + FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True # @@ -176,7 +176,7 @@ class _ViewProviderPartJoinFeature: # mb = QtGui.QMessageBox() # mb.setIcon(mb.Icon.Warning) # mb.setText(_translate("Part_JoinFeatures","Computing the result failed with an error: {err}. Click 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) -# .format(err= err.message)) +# .format(err= str(err))) # mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None)) # btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) # btnOK = mb.addButton(_translate("Part_JoinFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) diff --git a/src/Mod/PartDesign/App/AppPartDesign.cpp b/src/Mod/PartDesign/App/AppPartDesign.cpp index f701cb500..5722da092 100644 --- a/src/Mod/PartDesign/App/AppPartDesign.cpp +++ b/src/Mod/PartDesign/App/AppPartDesign.cpp @@ -27,6 +27,7 @@ #endif #include +#include #include #include "FeaturePad.h" @@ -63,7 +64,7 @@ extern PyObject* initModule(); } /* Python entry */ -PyMODINIT_FUNC init_PartDesign() +PyMOD_INIT_FUNC(_PartDesign) { // load dependent module try { @@ -72,10 +73,10 @@ PyMODINIT_FUNC init_PartDesign() } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); - return; + PyMOD_Return(0); } - (void)PartDesign::initModule(); + PyObject* mod = PartDesign::initModule(); Base::Console().Log("Loading PartDesign module... done\n"); @@ -141,4 +142,6 @@ PyMODINIT_FUNC init_PartDesign() PartDesign::Wedge ::init(); PartDesign::AdditiveWedge ::init(); PartDesign::SubtractiveWedge ::init(); + + PyMOD_Return(mod); } diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index fbce447ff..6f1d51c00 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -97,11 +97,11 @@ PyObject* initModule() /* Python entry */ -PyMODINIT_FUNC initPartDesignGui() +PyMOD_INIT_FUNC(PartDesignGui) { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); - return; + PyMOD_Return(0); } try { @@ -110,10 +110,10 @@ PyMODINIT_FUNC initPartDesignGui() } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); - return; + PyMOD_Return(0); } - (void)PartDesignGui::initModule(); + PyObject* mod = PartDesignGui::initModule(); Base::Console().Log("Loading GUI of PartDesign module... done\n"); // instantiating the commands @@ -154,4 +154,6 @@ PyMODINIT_FUNC initPartDesignGui() // add resources and reloads the translators loadPartDesignResource(); + + PyMOD_Return(mod); } diff --git a/src/Mod/PartDesign/InitGui.py b/src/Mod/PartDesign/InitGui.py index 5a6dba048..f47991b6d 100644 --- a/src/Mod/PartDesign/InitGui.py +++ b/src/Mod/PartDesign/InitGui.py @@ -35,29 +35,30 @@ class PartDesignWorkbench ( Workbench ): self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/PartDesign/Resources/icons/PartDesignWorkbench.svg" self.__class__.MenuText = "Part Design" self.__class__.ToolTip = "Part Design workbench" - + def Initialize(self): # load the module try: from WizardShaft import WizardShaft except ImportError: - print "Wizard shaft module cannot be loaded" + print("Wizard shaft module cannot be loaded") try: from FeatureHole import HoleGui except: pass + import PartDesignGui import PartDesign try: import InvoluteGearFeature except ImportError: - print "Involute gear module cannot be loaded" + print("Involute gear module cannot be loaded") #try: # from FeatureHole import HoleGui #except: # pass def GetClassName(self): - return "PartDesignGui::Workbench" + return "PartDesignGui::Workbench" Gui.addWorkbench(PartDesignWorkbench()) diff --git a/src/Mod/PartDesign/Scripts/FilletArc.py b/src/Mod/PartDesign/Scripts/FilletArc.py index 75c177811..63f262ae5 100644 --- a/src/Mod/PartDesign/Scripts/FilletArc.py +++ b/src/Mod/PartDesign/Scripts/FilletArc.py @@ -85,9 +85,9 @@ def makeFilletArc(M1,P,Q,N,r2,ccw): t = t2 br2 = b.mult(r2) - print br2 + print(br2) ut = u.mult(t) - print ut + print(ut) M2 = P.add(ut).add(br2) S1 = M1.mult(r2/(r1+r2)).add(M2.mult(r1/(r1+r2))) S2 = M2.sub(br2) diff --git a/src/Mod/PartDesign/Scripts/RadialCopy.py b/src/Mod/PartDesign/Scripts/RadialCopy.py index d1c93b41c..01bb7885c 100644 --- a/src/Mod/PartDesign/Scripts/RadialCopy.py +++ b/src/Mod/PartDesign/Scripts/RadialCopy.py @@ -47,7 +47,7 @@ def makeRadialCopy(): sel = sel[0] shape = sel.Shape name = sel.Label - except IndexError, AttributeError: + except (IndexError, AttributeError): QtGui.QMessageBox.critical(None,"Wrong selection","Please select a shape object") #raise Exception("Nothing selected") else: diff --git a/src/Mod/PartDesign/WizardShaft/SegmentFunction.py b/src/Mod/PartDesign/WizardShaft/SegmentFunction.py index bb70d9ca7..9cb8ed01a 100644 --- a/src/Mod/PartDesign/WizardShaft/SegmentFunction.py +++ b/src/Mod/PartDesign/WizardShaft/SegmentFunction.py @@ -350,7 +350,7 @@ class TranslationFunction: try: self.boundaries = np.linalg.solve(A, b) # A * self.boundaries = b - except np.linalg.linalg.LinAlgError, e: + except np.linalg.linalg.LinAlgError as e: FreeCAD.Console.PrintMessage(e.message) FreeCAD.Console.PrintMessage(". No solution possible.\n") return diff --git a/src/Mod/PartDesign/WizardShaft/Shaft.py b/src/Mod/PartDesign/WizardShaft/Shaft.py index c3a2c5acc..c06174d77 100644 --- a/src/Mod/PartDesign/WizardShaft/Shaft.py +++ b/src/Mod/PartDesign/WizardShaft/Shaft.py @@ -478,7 +478,7 @@ class Shaft: b = np.array([coefficientsF[ax][0], coefficientsM[ax][0]]) try: solution = np.linalg.solve(A, b) # A * solution = b - except np.linalg.linalg.LinAlgError, e: + except np.linalg.linalg.LinAlgError as e: FreeCAD.Console.PrintMessage(e.message) FreeCAD.Console.PrintMessage(". No solution possible.\n") self.parent.updateButtons(ax, False) diff --git a/src/Mod/PartDesign/fcgear/svggear.py b/src/Mod/PartDesign/fcgear/svggear.py index 14e5d66ff..0752290ec 100644 --- a/src/Mod/PartDesign/fcgear/svggear.py +++ b/src/Mod/PartDesign/fcgear/svggear.py @@ -67,5 +67,5 @@ if __name__ == '__main__': if len(args) != 2: p.error() m, Z = [float(v) for v in args] - print makeGear(m, int(Z), float(opts.angle)) + print(makeGear(m, int(Z), float(opts.angle))) diff --git a/src/Mod/Sketcher/App/AppSketcher.cpp b/src/Mod/Sketcher/App/AppSketcher.cpp index 29b28c793..9bfa4daaa 100644 --- a/src/Mod/Sketcher/App/AppSketcher.cpp +++ b/src/Mod/Sketcher/App/AppSketcher.cpp @@ -43,7 +43,7 @@ extern PyObject* initModule(); } /* Python entry */ -PyMODINIT_FUNC initSketcher() +PyMOD_INIT_FUNC(Sketcher) { // load dependent module try { @@ -51,7 +51,7 @@ PyMODINIT_FUNC initSketcher() } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); - return; + PyMOD_Return(0); } PyObject* sketcherModule = Sketcher::initModule(); @@ -73,4 +73,6 @@ PyMODINIT_FUNC initSketcher() Sketcher::PropertyConstraintList::init(); Base::Console().Log("Loading Sketcher module... done\n"); + + PyMOD_Return(sketcherModule); } diff --git a/src/Mod/Sketcher/App/ConstraintPy.xml b/src/Mod/Sketcher/App/ConstraintPy.xml index 06750f994..32579e9be 100644 --- a/src/Mod/Sketcher/App/ConstraintPy.xml +++ b/src/Mod/Sketcher/App/ConstraintPy.xml @@ -20,13 +20,13 @@ First geometry index the Constraint refers to - + Second geometry index the Constraint refers to - + diff --git a/src/Mod/Sketcher/App/ConstraintPyImp.cpp b/src/Mod/Sketcher/App/ConstraintPyImp.cpp index fb944a153..31f6ad435 100644 --- a/src/Mod/Sketcher/App/ConstraintPyImp.cpp +++ b/src/Mod/Sketcher/App/ConstraintPyImp.cpp @@ -77,8 +77,13 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyArg_ParseTuple(args, "siO", &ConstraintType, &FirstIndex, &index_or_value)) { // ConstraintType, GeoIndex1, GeoIndex2 +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(index_or_value)) { + SecondIndex = PyLong_AsLong(index_or_value); +#else if (PyInt_Check(index_or_value)) { SecondIndex = PyInt_AsLong(index_or_value); +#endif bool valid = false; if (strcmp("Tangent",ConstraintType) == 0) { this->getConstraintPtr()->Type = Tangent; @@ -159,9 +164,15 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyArg_ParseTuple(args, "siiO", &ConstraintType, &FirstIndex, &any_index, &index_or_value)) { // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2 +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(index_or_value)) { + FirstPos = any_index; + SecondIndex = PyLong_AsLong(index_or_value); +#else if (PyInt_Check(index_or_value)) { FirstPos = any_index; SecondIndex = PyInt_AsLong(index_or_value); +#endif bool valid = false; if (strcmp("Perpendicular", ConstraintType) == 0) { this->getConstraintPtr()->Type = Perpendicular; @@ -245,8 +256,13 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyArg_ParseTuple(args, "siiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &oNumArg4)) { // Value, ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2 +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(oNumArg4)) { + intArg4 = PyLong_AsLong(oNumArg4); +#else if (PyInt_Check(oNumArg4)) { intArg4 = PyInt_AsLong(oNumArg4); +#endif bool valid = false; if (strcmp("Coincident", ConstraintType) == 0) { this->getConstraintPtr()->Type = Coincident; @@ -337,8 +353,13 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyArg_ParseTuple(args, "siiiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &intArg4, &oNumArg5)) { // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3 +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(oNumArg5)) { + intArg5 = PyLong_AsLong(oNumArg5); +#else if (PyInt_Check(oNumArg5)) { intArg5 = PyInt_AsLong(oNumArg5); +#endif if (strcmp("Symmetric",ConstraintType) == 0 ) { this->getConstraintPtr()->Type = Symmetric; this->getConstraintPtr()->First = intArg1; @@ -404,8 +425,13 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) PyErr_Clear(); if (PyArg_ParseTuple(args, "siiiiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &SecondPos, &ThirdIndex, &index_or_value)) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(index_or_value)) { + ThirdPos = PyLong_AsLong(index_or_value); +#else if (PyInt_Check(index_or_value)) { ThirdPos = PyInt_AsLong(index_or_value); +#endif // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3, PosIndex3 if (strcmp("Symmetric",ConstraintType) == 0 ) { this->getConstraintPtr()->Type = Symmetric; @@ -495,24 +521,32 @@ std::string ConstraintPy::representation(void) const return result.str(); } -Py::Int ConstraintPy::getFirst(void) const +Py::Long ConstraintPy::getFirst(void) const { - return Py::Int(this->getConstraintPtr()->First); + return Py::Long(this->getConstraintPtr()->First); } -void ConstraintPy::setFirst(Py::Int arg) +void ConstraintPy::setFirst(Py::Long arg) { +#if PY_MAJOR_VERSION < 3 + this->getConstraintPtr()->First = Py::Int(arg); +#else this->getConstraintPtr()->First = arg; +#endif } -Py::Int ConstraintPy::getSecond(void) const +Py::Long ConstraintPy::getSecond(void) const { - return Py::Int(this->getConstraintPtr()->Second); + return Py::Long(this->getConstraintPtr()->Second); } -void ConstraintPy::setSecond(Py::Int arg) +void ConstraintPy::setSecond(Py::Long arg) { +#if PY_MAJOR_VERSION < 3 + this->getConstraintPtr()->Second = Py::Int(arg); +#else this->getConstraintPtr()->Second = arg; +#endif } Py::String ConstraintPy::getName(void) const diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index d09797363..57846b43f 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -228,13 +228,13 @@ Number of Constraints in this sketch - + Number of geometric objects in this sketch - + @@ -242,7 +242,7 @@ return the the number of construction lines in the sketch which can be used as axes - + diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 7ff121fba..2e0e22eae 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -124,7 +124,7 @@ PyObject* SketchObjectPy::addGeometry(PyObject *args) PyErr_SetString(PyExc_TypeError, str.str().c_str()); return 0; } - return Py::new_reference_to(Py::Int(ret)); + return Py::new_reference_to(Py::Long(ret)); } else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { @@ -186,7 +186,7 @@ PyObject* SketchObjectPy::addGeometry(PyObject *args) Py::Tuple tuple(numGeo); for (std::size_t i=0; igetSketchObjectPtr()->noRecomputes) this->getSketchObjectPtr()->setUpSketch(); - return Py::new_reference_to(Py::Int(ret)); + return Py::new_reference_to(Py::Long(ret)); } else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { @@ -302,7 +302,7 @@ PyObject* SketchObjectPy::addConstraint(PyObject *args) Py::Tuple tuple(numCon); for (std::size_t i=0; i geoIdList; Py::Sequence list(pcObj); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check((*it).ptr())) + geoIdList.push_back(PyLong_AsLong((*it).ptr())); +#else if (PyInt_Check((*it).ptr())) geoIdList.push_back(PyInt_AsLong((*it).ptr())); +#endif } int ret = this->getSketchObjectPtr()->addSymmetric(geoIdList,refGeoId,(Sketcher::PointPos) refPosId) + 1; @@ -815,7 +820,7 @@ PyObject* SketchObjectPy::addSymmetric(PyObject *args) Py::Tuple tuple(numGeo); for (std::size_t i=0; i geoIdList; Py::Sequence list(pcObj); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check((*it).ptr())) + geoIdList.push_back(PyLong_AsLong((*it).ptr())); +#else if (PyInt_Check((*it).ptr())) geoIdList.push_back(PyInt_AsLong((*it).ptr())); +#endif } int ret = this->getSketchObjectPtr()->addCopy(geoIdList, vect, PyObject_IsTrue(clone) ? true : false) + 1; @@ -854,7 +864,7 @@ PyObject* SketchObjectPy::addCopy(PyObject *args) Py::Tuple tuple(numGeo); for (std::size_t i=0; i geoIdList; Py::Sequence list(pcObj); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check((*it).ptr())) + geoIdList.push_back(PyLong_AsLong((*it).ptr())); +#else if (PyInt_Check((*it).ptr())) geoIdList.push_back(PyInt_AsLong((*it).ptr())); +#endif } int ret = this->getSketchObjectPtr()->addCopy(geoIdList,vect, PyObject_IsTrue(clone) ? true : false, @@ -961,7 +976,7 @@ PyObject* SketchObjectPy::changeConstraintsLocking(PyObject *args) int naff = obj->changeConstraintsLocking((bool)bLock); - return Py::new_reference_to(Py::Int(naff)); + return Py::new_reference_to(Py::Long(naff)); } //Deprecated @@ -1069,19 +1084,19 @@ PyObject* SketchObjectPy::increaseBSplineDegree(PyObject *args) Py_Return; } -Py::Int SketchObjectPy::getConstraintCount(void) const +Py::Long SketchObjectPy::getConstraintCount(void) const { - return Py::Int(this->getSketchObjectPtr()->Constraints.getSize()); + return Py::Long(this->getSketchObjectPtr()->Constraints.getSize()); } -Py::Int SketchObjectPy::getGeometryCount(void) const +Py::Long SketchObjectPy::getGeometryCount(void) const { - return Py::Int(this->getSketchObjectPtr()->Geometry.getSize()); + return Py::Long(this->getSketchObjectPtr()->Geometry.getSize()); } -Py::Int SketchObjectPy::getAxisCount(void) const +Py::Long SketchObjectPy::getAxisCount(void) const { - return Py::Int(this->getSketchObjectPtr()->getAxisCount()); + return Py::Long(this->getSketchObjectPtr()->getAxisCount()); } PyObject *SketchObjectPy::getCustomAttributes(const char* /*attr*/) const diff --git a/src/Mod/Sketcher/App/SketchPy.xml b/src/Mod/Sketcher/App/SketchPy.xml index 71c5b3f44..bc4599e11 100644 --- a/src/Mod/Sketcher/App/SketchPy.xml +++ b/src/Mod/Sketcher/App/SketchPy.xml @@ -54,7 +54,7 @@ 0: exactly constraint, -1 under-constraint, 1 over-constraint - + diff --git a/src/Mod/Sketcher/App/SketchPyImp.cpp b/src/Mod/Sketcher/App/SketchPyImp.cpp index 07b4b1bf7..eb6311d8a 100644 --- a/src/Mod/Sketcher/App/SketchPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchPyImp.cpp @@ -65,7 +65,7 @@ PyObject* SketchPy::solve(PyObject *args) if (!PyArg_ParseTuple(args, "")) return 0; getSketchPtr()->resetSolver(); - return Py::new_reference_to(Py::Int(getSketchPtr()->solve())); + return Py::new_reference_to(Py::Long(getSketchPtr()->solve())); } PyObject* SketchPy::addGeometry(PyObject *args) @@ -76,7 +76,7 @@ PyObject* SketchPy::addGeometry(PyObject *args) if (PyObject_TypeCheck(pcObj, &(Part::GeometryPy::Type))) { Part::Geometry *geo = static_cast(pcObj)->getGeometryPtr(); - return Py::new_reference_to(Py::Int(this->getSketchPtr()->addGeometry(geo))); + return Py::new_reference_to(Py::Long(this->getSketchPtr()->addGeometry(geo))); } else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { @@ -94,7 +94,7 @@ PyObject* SketchPy::addGeometry(PyObject *args) Py::Tuple tuple(numGeo); for (std::size_t i=0; i(pcObj); int ret = getSketchPtr()->addConstraint(pcObject->getConstraintPtr()); - return Py::new_reference_to(Py::Int(ret)); + return Py::new_reference_to(Py::Long(ret)); } else { std::string error = std::string("type must be 'Constraint' or list of 'Constraint', not "); @@ -160,12 +160,12 @@ PyObject* SketchPy::movePoint(PyObject *args) return 0; Base::Vector3d* toPoint = static_cast(pcObj)->getVectorPtr(); - return Py::new_reference_to(Py::Int(getSketchPtr()->movePoint(index1,(Sketcher::PointPos)index2,*toPoint,(relative>0)))); + return Py::new_reference_to(Py::Long(getSketchPtr()->movePoint(index1,(Sketcher::PointPos)index2,*toPoint,(relative>0)))); } // +++ attributes implementer ++++++++++++++++++++++++++++++++++++++++++++++++ -Py::Int SketchPy::getConstraint(void) const +Py::Long SketchPy::getConstraint(void) const { //return Py::Int(); throw Py::AttributeError("Not yet implemented"); diff --git a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp index 8a2116844..488f62e9f 100644 --- a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp +++ b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp @@ -72,14 +72,20 @@ public: private: }; + +PyObject* initModule() +{ + return (new Module)->module().ptr(); +} + } // namespace SketcherGui /* Python entry */ -PyMODINIT_FUNC initSketcherGui() +PyMOD_INIT_FUNC(SketcherGui) { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); - return; + PyMOD_Return(0); } try { Base::Interpreter().runString("import PartGui"); @@ -87,10 +93,10 @@ PyMODINIT_FUNC initSketcherGui() } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); - return; + PyMOD_Return(0); } - (void)new SketcherGui::Module(); + PyObject* mod = SketcherGui::initModule(); Base::Console().Log("Loading GUI of Sketcher module... done\n"); // instantiating the commands @@ -116,4 +122,6 @@ PyMODINIT_FUNC initSketcherGui() // add resources and reloads the translators loadSketcherResource(); + + PyMOD_Return(mod); } diff --git a/src/Mod/Sketcher/InitGui.py b/src/Mod/Sketcher/InitGui.py index b71b1d75d..b8c7571b0 100644 --- a/src/Mod/Sketcher/InitGui.py +++ b/src/Mod/Sketcher/InitGui.py @@ -32,11 +32,11 @@ class SketcherWorkbench ( Workbench ): - "Sketcher workbench object" + "Sketcher workbench object" def __init__(self): self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Sketcher/Resources/icons/SketcherWorkbench.svg" self.__class__.MenuText = "Sketcher" - self.__class__.ToolTip = "Sketcher workbench" + self.__class__.ToolTip = "Sketcher workbench" def Initialize(self): # load the module @@ -45,7 +45,7 @@ class SketcherWorkbench ( Workbench ): try: import Profiles except ImportError: - print "Error in Profiles module" + print("Error in Profiles module") def GetClassName(self): return "SketcherGui::Workbench"