Skip to content

Commit

Permalink
py3: Part: App: gathering commits relevant for Mod/Part/App
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Mar 1, 2017
1 parent ed23c0d commit a388a9d
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 37 deletions.
26 changes: 21 additions & 5 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -163,8 +163,9 @@ class LinePyOld : public LineSegmentPy

/// 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*/
Expand All @@ -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 */
Expand Down Expand Up @@ -214,6 +219,9 @@ PyTypeObject LinePyOld::Type = {
0, /*tp_weaklist */
0, /*tp_del */
0 /*tp_version_tag */
#if PY_MAJOR_VERSION >=3
,0 /*tp_finalize */
#endif
};

}
Expand Down Expand Up @@ -350,7 +358,12 @@ PyMOD_INIT_FUNC(Part)
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");
Expand All @@ -370,7 +383,9 @@ PyMOD_INIT_FUNC(Part)
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"),
Expand All @@ -383,6 +398,7 @@ PyMOD_INIT_FUNC(Part)
Base::Console().Error("Failed to import BOPTools package:\n");
err.ReportException();
}
#endif

Part::TopoShape ::init();
Part::PropertyPartShape ::init();
Expand Down
18 changes: 17 additions & 1 deletion src/Mod/Part/App/AttachEnginePyImp.cpp
Expand Up @@ -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")) {
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/Mod/Part/App/BSplineCurvePyImp.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -672,7 +676,6 @@ PyObject* BSplineCurvePy::getMultiplicities(PyObject * args)
return 0;
}
}

Py::Long BSplineCurvePy::getDegree(void) const
{
Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
Expand Down Expand Up @@ -1211,7 +1214,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) {
#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 += static_cast<int>(mult); //sum up the mults to compare them against the number of poles later
}
Expand Down
17 changes: 16 additions & 1 deletion src/Mod/Part/App/BSplineSurfacePyImp.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1467,7 +1475,11 @@ 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 += static_cast<int>(mult); //sum up the mults to compare them against the number of poles later
}
Expand All @@ -1476,7 +1488,11 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k
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 += static_cast<int>(mult); //sum up the mults to compare them against the number of poles later
}
Expand Down Expand Up @@ -1536,7 +1552,6 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k
return 0;
}
}

Py::Long BSplineSurfacePy::getUDegree(void) const
{
Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Part/App/BezierCurvePyImp.cpp
Expand Up @@ -355,7 +355,6 @@ PyObject* BezierCurvePy::getResolution(PyObject* args)
return 0;
}
}

Py::Long BezierCurvePy::getDegree(void) const
{
Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Part/App/BezierSurfacePyImp.cpp
Expand Up @@ -728,7 +728,6 @@ PyObject* BezierSurfacePy::vIso(PyObject * args)
return 0;
}
}

Py::Long BezierSurfacePy::getUDegree(void) const
{
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Part/App/Geom2d/BSplineCurve2dPy.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
46 changes: 33 additions & 13 deletions src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a388a9d

Please sign in to comment.