Skip to content

Commit

Permalink
Part.EdgePy : get access to stored Pcurves
Browse files Browse the repository at this point in the history
  • Loading branch information
tomate44 authored and wwmayer committed Aug 29, 2020
1 parent 30c0708 commit 7d3ff63
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Mod/Part/App/TopoShapeEdgePy.xml
Expand Up @@ -528,6 +528,15 @@ coordinate system.</UserDocu>
</Documentation>
<Parameter Name="Continuity" Type="String"/>
</Attribute>
<Methode Name="curveOnSurface" Const="true">
<Documentation>
<UserDocu>curveOnSurface(idx) -> None or tuple
Returns the 2D curve, the surface and the parameter range of index idx.
Returns None if index idx is out of range.
Returns a 4-items tuple of a curve, a surface, first parameter and last parameter.
</UserDocu>
</Documentation>
</Methode>
<ClassDeclarations>
</ClassDeclarations>
</PythonExport>
Expand Down
40 changes: 40 additions & 0 deletions src/Mod/Part/App/TopoShapeEdgePyImp.cpp
Expand Up @@ -44,6 +44,9 @@
# include <Geom_BezierCurve.hxx>
# include <Geom_BSplineCurve.hxx>
# include <Geom_OffsetCurve.hxx>
# include <Geom_Surface.hxx>
# include <Geom2d_Curve.hxx>
# include <TopLoc_Location.hxx>
# include <gp_Circ.hxx>
# include <gp_Elips.hxx>
# include <gp_Hypr.hxx>
Expand Down Expand Up @@ -86,6 +89,7 @@
#include <Mod/Part/App/TopoShapeEdgePy.h>
#include <Mod/Part/App/TopoShapeEdgePy.cpp>

#include "Geometry2d.h"
#include "Geometry.h"
#include <Mod/Part/App/GeometryPy.h>
#include <Mod/Part/App/LinePy.h>
Expand Down Expand Up @@ -1045,6 +1049,42 @@ Py::Boolean TopoShapeEdgePy::getDegenerated(void) const
return Py::Boolean(ok ? true : false);
}

PyObject* TopoShapeEdgePy::curveOnSurface(PyObject *args)
{
int idx;
if (!PyArg_ParseTuple(args, "i", &idx))
return 0;

try {
TopoDS_Edge edge = TopoDS::Edge(getTopoShapePtr()->getShape());
Handle(Geom2d_Curve) curve;
Handle(Geom_Surface) surf;
TopLoc_Location loc;
Standard_Real first, last;

BRep_Tool::CurveOnSurface(edge, curve, surf, loc, first, last, idx+1);
if (curve.IsNull())
Py_Return;
std::unique_ptr<Part::Geom2dCurve> geo2d = getCurve2dFromGeom2d(curve);
if (!geo2d)
Py_Return;
Part::GeomSurface* geosurf = makeFromSurface(surf);
if (!geosurf)
Py_Return;

Py::Tuple tuple(4);
tuple.setItem(0, Py::asObject(geo2d->getPyObject()));
tuple.setItem(1, Py::asObject(geosurf->getPyObject()));
tuple.setItem(2, Py::Float(first));
tuple.setItem(3, Py::Float(last));
return Py::new_reference_to(tuple);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
}

PyObject *TopoShapeEdgePy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
Expand Down

0 comments on commit 7d3ff63

Please sign in to comment.