Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
py3: ported Part to python3
  • Loading branch information
wwmayer authored and looooo committed Mar 1, 2017
1 parent e594ade commit ed23c0d
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 97 deletions.
10 changes: 8 additions & 2 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -219,7 +219,7 @@ PyTypeObject LinePyOld::Type = {
}
// --->

PyMODINIT_FUNC initPart()
PyMOD_INIT_FUNC(Part)
{
Base::Console().Log("Module: Part\n");

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
13 changes: 12 additions & 1 deletion src/Mod/Part/App/AppPartPy.cpp
Expand Up @@ -1569,8 +1569,14 @@ class Module : public Py::ExtensionModule<Module>
}
}

#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.");
}
Expand Down Expand Up @@ -1645,8 +1651,13 @@ class Module : public Py::ExtensionModule<Module>
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 << "'";
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Part/App/BRepOffsetAPI_MakePipeShellPyImp.cpp
Expand Up @@ -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<Part::TopoShapePy*>(spine)->getTopoShapePtr()->getShape();
if (s.IsNull() || s.ShapeType() != TopAbs_WIRE) {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Part/App/BSplineCurvePy.xml
Expand Up @@ -19,29 +19,29 @@
<Documentation>
<UserDocu>Returns the polynomial degree of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="Degree" Type="Int"/>
<Parameter Name="Degree" Type="Long"/>
</Attribute>
<Attribute Name="MaxDegree" ReadOnly="true">
<Documentation>
<UserDocu>Returns the value of the maximum polynomial degree of any
B-Spline curve curve. This value is 25.</UserDocu>
</Documentation>
<Parameter Name="MaxDegree" Type="Int"/>
<Parameter Name="MaxDegree" Type="Long"/>
</Attribute>
<Attribute Name="NbPoles" ReadOnly="true">
<Documentation>
<UserDocu>Returns the number of poles of this B-Spline curve.
</UserDocu>
</Documentation>
<Parameter Name="NbPoles" Type="Int"/>
<Parameter Name="NbPoles" Type="Long"/>
</Attribute>
<Attribute Name="NbKnots" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the number of knots of this B-Spline curve.
</UserDocu>
</Documentation>
<Parameter Name="NbPoles" Type="Int"/>
<Parameter Name="NbPoles" Type="Long"/>
</Attribute>
<Attribute Name="StartPoint" ReadOnly="true">
<Documentation>
Expand Down
30 changes: 15 additions & 15 deletions src/Mod/Part/App/BSplineCurvePyImp.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<int>(mult); //sum up the mults to compare them against the number of poles later
}
occmults(index++) = mult;
occmults(index++) = static_cast<int>(mult);
}
}
else { //mults are 1 or degree+1 at the ends
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/Part/App/BSplineSurfacePy.xml
Expand Up @@ -21,15 +21,15 @@
Returns the degree of this B-Spline surface in the u parametric direction.
</UserDocu>
</Documentation>
<Parameter Name="UDegree" Type="Int"/>
<Parameter Name="UDegree" Type="Long"/>
</Attribute>
<Attribute Name="VDegree" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the degree of this B-Spline surface in the v parametric direction.
</UserDocu>
</Documentation>
<Parameter Name="VDegree" Type="Int"/>
<Parameter Name="VDegree" Type="Long"/>
</Attribute>
<Attribute Name="MaxDegree" ReadOnly="true">
<Documentation>
Expand All @@ -39,39 +39,39 @@
This value is 25.
</UserDocu>
</Documentation>
<Parameter Name="MaxDegree" Type="Int"/>
<Parameter Name="MaxDegree" Type="Long"/>
</Attribute>
<Attribute Name="NbUPoles" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the number of poles of this B-Spline surface in the u parametric direction.
</UserDocu>
</Documentation>
<Parameter Name="NbUPoles" Type="Int"/>
<Parameter Name="NbUPoles" Type="Long"/>
</Attribute>
<Attribute Name="NbVPoles" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the number of poles of this B-Spline surface in the v parametric direction.
</UserDocu>
</Documentation>
<Parameter Name="NbVPoles" Type="Int"/>
<Parameter Name="NbVPoles" Type="Long"/>
</Attribute>
<Attribute Name="NbUKnots" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the number of knots of this B-Spline surface in the u parametric direction.
</UserDocu>
</Documentation>
<Parameter Name="NbUKnots" Type="Int"/>
<Parameter Name="NbUKnots" Type="Long"/>
</Attribute>
<Attribute Name="NbVKnots" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the number of knots of this B-Spline surface in the v parametric direction.
</UserDocu>
</Documentation>
<Parameter Name="NbVKnots" Type="Int"/>
<Parameter Name="NbVKnots" Type="Long"/>
</Attribute>
<Attribute Name="FirstUKnotIndex" ReadOnly="true">
<Documentation>
Expand Down

0 comments on commit ed23c0d

Please sign in to comment.