add method to extract pcurve from an edge
This commit is contained in:
parent
420761df75
commit
d3e0f03650
|
@ -51,6 +51,8 @@
|
|||
# include <ShapeConstruct_Curve.hxx>
|
||||
# include <GeomAPI_IntCS.hxx>
|
||||
# include <Geom2dAPI_ExtremaCurveCurve.hxx>
|
||||
# include <BRepBuilderAPI_MakeEdge2d.hxx>
|
||||
# include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
|
@ -113,22 +115,76 @@ extern Py::Object shape2pyshape(const TopoDS_Shape &shape);
|
|||
|
||||
PyObject* Curve2dPy::toShape(PyObject *args)
|
||||
{
|
||||
PyObject* p;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(Part::GeometrySurfacePy::Type), &p))
|
||||
return 0;
|
||||
try {
|
||||
Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast(
|
||||
static_cast<GeometrySurfacePy*>(p)->getGeomSurfacePtr()->handle());
|
||||
TopoDS_Shape sh = getGeometry2dPtr()->toShape(surf);
|
||||
return Py::new_reference_to(shape2pyshape(sh));
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return 0;
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
try {
|
||||
Handle_Geom2d_Curve curv = Handle_Geom2d_Curve::DownCast(getGeometry2dPtr()->handle());
|
||||
|
||||
BRepBuilderAPI_MakeEdge2d mkBuilder(curv);
|
||||
TopoDS_Shape edge = mkBuilder.Shape();
|
||||
return Py::new_reference_to(shape2pyshape(edge));
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve");
|
||||
PyErr_Clear();
|
||||
double u1, u2;
|
||||
if (PyArg_ParseTuple(args, "dd", &u1, &u2)) {
|
||||
try {
|
||||
Handle_Geom2d_Curve curv = Handle_Geom2d_Curve::DownCast(getGeometry2dPtr()->handle());
|
||||
|
||||
BRepBuilderAPI_MakeEdge2d mkBuilder(curv, u1, u2);
|
||||
TopoDS_Shape edge = mkBuilder.Shape();
|
||||
return Py::new_reference_to(shape2pyshape(edge));
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
PyObject* p;
|
||||
if (PyArg_ParseTuple(args, "O!", &(Part::GeometrySurfacePy::Type), &p)) {
|
||||
try {
|
||||
Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast(
|
||||
static_cast<GeometrySurfacePy*>(p)->getGeomSurfacePtr()->handle());
|
||||
Handle_Geom2d_Curve curv = Handle_Geom2d_Curve::DownCast(getGeometry2dPtr()->handle());
|
||||
|
||||
BRepBuilderAPI_MakeEdge mkBuilder(curv, surf);
|
||||
TopoDS_Shape edge = mkBuilder.Shape();
|
||||
return Py::new_reference_to(shape2pyshape(edge));
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args, "O!dd", &(Part::GeometrySurfacePy::Type), &p, &u1, &u2)) {
|
||||
try {
|
||||
Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast(
|
||||
static_cast<GeometrySurfacePy*>(p)->getGeomSurfacePtr()->handle());
|
||||
Handle_Geom2d_Curve curv = Handle_Geom2d_Curve::DownCast(getGeometry2dPtr()->handle());
|
||||
|
||||
BRepBuilderAPI_MakeEdge mkBuilder(curv, surf, u1, u2);
|
||||
TopoDS_Shape edge = mkBuilder.Shape();
|
||||
return Py::new_reference_to(shape2pyshape(edge));
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "empty parameter list, parameter range or surface expected");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,39 +95,10 @@ Py::Object OffsetCurve2dPy::getBasisCurve(void) const
|
|||
Handle_Geom2d_Curve basis = curve->BasisCurve();
|
||||
if (basis.IsNull())
|
||||
return Py::None();
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Parabola))) {
|
||||
Geom2dParabola c(Handle_Geom2d_Parabola::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) {
|
||||
Geom2dHyperbola c(Handle_Geom2d_Hyperbola::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) {
|
||||
Geom2dEllipse c(Handle_Geom2d_Ellipse::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Circle))) {
|
||||
Geom2dCircle c(Handle_Geom2d_Circle::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Line))) {
|
||||
Geom2dLine c(Handle_Geom2d_Line::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) {
|
||||
Geom2dBSplineCurve c(Handle_Geom2d_BSplineCurve::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) {
|
||||
Geom2dBezierCurve c(Handle_Geom2d_BezierCurve::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_TrimmedCurve))) {
|
||||
Geom2dTrimmedCurve c(Handle_Geom2d_TrimmedCurve::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
throw Py::RuntimeError("Unknown curve type");
|
||||
std::unique_ptr<Geom2dCurve> geo2d = getCurve2dFromGeom2d(basis);
|
||||
if (!geo2d)
|
||||
throw Py::RuntimeError("Unknown curve type");
|
||||
return Py::asObject(geo2d->getPyObject());
|
||||
}
|
||||
|
||||
void OffsetCurve2dPy::setBasisCurve(Py::Object arg)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
# include <BRepBuilderAPI_MakeEdge2d.hxx>
|
||||
# include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
# include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
|
||||
# include <Geom2dAPI_Interpolate.hxx>
|
||||
|
@ -135,11 +135,13 @@ Geom2dPoint::~Geom2dPoint()
|
|||
{
|
||||
}
|
||||
|
||||
TopoDS_Shape Geom2dPoint::toShape(const Handle_Geom_Surface& hSurface) const
|
||||
TopoDS_Shape Geom2dPoint::toShape() const
|
||||
{
|
||||
Handle_Geom2d_CartesianPoint c = Handle_Geom2d_CartesianPoint::DownCast(handle());
|
||||
gp_Pnt2d xy = c->Pnt2d();
|
||||
gp_Pnt pnt = hSurface->Value(xy.X(), xy.Y());
|
||||
gp_Pnt pnt;
|
||||
pnt.SetX(xy.X());
|
||||
pnt.SetY(xy.Y());
|
||||
BRepBuilderAPI_MakeVertex mkBuilder(pnt);
|
||||
return mkBuilder.Shape();
|
||||
}
|
||||
|
@ -223,10 +225,10 @@ Geom2dCurve::~Geom2dCurve()
|
|||
{
|
||||
}
|
||||
|
||||
TopoDS_Shape Geom2dCurve::toShape(const Handle_Geom_Surface& hSurface) const
|
||||
TopoDS_Shape Geom2dCurve::toShape() const
|
||||
{
|
||||
Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle());
|
||||
BRepBuilderAPI_MakeEdge mkBuilder(c, hSurface);
|
||||
BRepBuilderAPI_MakeEdge2d mkBuilder(c);
|
||||
return mkBuilder.Shape();
|
||||
}
|
||||
|
||||
|
@ -2271,3 +2273,40 @@ PyObject *Geom2dTrimmedCurve::getPyObject(void)
|
|||
PyErr_SetString(PyExc_RuntimeError, "Unknown curve type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
namespace Part {
|
||||
std::unique_ptr<Geom2dCurve> getCurve2dFromGeom2d(Handle_Geom2d_Curve curve)
|
||||
{
|
||||
std::unique_ptr<Geom2dCurve> geo2d;
|
||||
if (curve.IsNull())
|
||||
return geo2d;
|
||||
if (curve->IsKind(STANDARD_TYPE (Geom2d_Parabola))) {
|
||||
geo2d.reset(new Geom2dParabola(Handle_Geom2d_Parabola::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) {
|
||||
geo2d.reset(new Geom2dHyperbola(Handle_Geom2d_Hyperbola::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) {
|
||||
geo2d.reset(new Geom2dEllipse(Handle_Geom2d_Ellipse::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Circle))) {
|
||||
geo2d.reset(new Geom2dCircle(Handle_Geom2d_Circle::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Line))) {
|
||||
geo2d.reset(new Geom2dLine(Handle_Geom2d_Line::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) {
|
||||
geo2d.reset(new Geom2dBSplineCurve(Handle_Geom2d_BSplineCurve::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) {
|
||||
geo2d.reset(new Geom2dBezierCurve(Handle_Geom2d_BezierCurve::DownCast(curve)));
|
||||
}
|
||||
else if (curve->IsKind(STANDARD_TYPE (Geom2d_TrimmedCurve))) {
|
||||
geo2d.reset(new Geom2dTrimmedCurve(Handle_Geom2d_TrimmedCurve::DownCast(curve)));
|
||||
}
|
||||
|
||||
return geo2d;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <gp_Ax22d.hxx>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <Base/Persistence.h>
|
||||
#include <Base/Tools2D.h>
|
||||
|
||||
|
@ -50,7 +51,7 @@ class PartExport Geometry2d : public Base::Persistence
|
|||
public:
|
||||
virtual ~Geometry2d();
|
||||
|
||||
virtual TopoDS_Shape toShape(const Handle_Geom_Surface&) const = 0;
|
||||
virtual TopoDS_Shape toShape() const = 0;
|
||||
virtual const Handle_Geom2d_Geometry& handle() const = 0;
|
||||
// Persistence implementer ---------------------
|
||||
virtual unsigned int getMemSize(void) const;
|
||||
|
@ -76,7 +77,7 @@ public:
|
|||
Geom2dPoint(const Base::Vector2d&);
|
||||
virtual ~Geom2dPoint();
|
||||
virtual Geometry2d *clone(void) const;
|
||||
virtual TopoDS_Shape toShape(const Handle_Geom_Surface&) const;
|
||||
virtual TopoDS_Shape toShape() const;
|
||||
|
||||
// Persistence implementer ---------------------
|
||||
virtual unsigned int getMemSize(void) const;
|
||||
|
@ -101,7 +102,7 @@ public:
|
|||
Geom2dCurve();
|
||||
virtual ~Geom2dCurve();
|
||||
|
||||
virtual TopoDS_Shape toShape(const Handle_Geom_Surface&) const;
|
||||
virtual TopoDS_Shape toShape() const;
|
||||
bool tangent(double u, gp_Dir2d&) const;
|
||||
Base::Vector2d pointAtParameter(double u) const;
|
||||
Base::Vector2d firstDerivativeAtParameter(double u) const;
|
||||
|
@ -563,6 +564,8 @@ private:
|
|||
Handle_Geom2d_TrimmedCurve myCurve;
|
||||
};
|
||||
|
||||
std::unique_ptr<Geom2dCurve> getCurve2dFromGeom2d(Handle_Geom2d_Curve);
|
||||
|
||||
}
|
||||
|
||||
#endif // PART_GEOMETRY2D_H
|
||||
|
|
|
@ -64,7 +64,18 @@
|
|||
<UserDocu>Validate the face.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setTolerance">
|
||||
<Methode Name="curveOnSurface">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
curveonSurface(Edge) -> None or tuple
|
||||
Returns the curve associated to the edge in the
|
||||
parametric space of the face. Returns None if this
|
||||
curve does not exist. If this curve exists then a tuple
|
||||
of curve and and parameter range is returned.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setTolerance">
|
||||
<Documentation>
|
||||
<UserDocu>Set the tolerance for the face.</UserDocu>
|
||||
</Documentation>
|
||||
|
|
|
@ -42,9 +42,11 @@
|
|||
# include <Geom_SphericalSurface.hxx>
|
||||
# include <Geom_ToroidalSurface.hxx>
|
||||
# include <Geom_Surface.hxx>
|
||||
# include <Geom2d_Curve.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Face.hxx>
|
||||
# include <TopoDS_Wire.hxx>
|
||||
# include <TopoDS_Edge.hxx>
|
||||
# include <gp_Pnt2d.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <gp_Cylinder.hxx>
|
||||
|
@ -66,27 +68,30 @@
|
|||
#include <BRepLProp_SurfaceTool.hxx>
|
||||
#include <BRepGProp_Face.hxx>
|
||||
#include <GeomLProp_SLProps.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
|
||||
#include "TopoShape.h"
|
||||
#include "TopoShapeSolidPy.h"
|
||||
#include "TopoShapeWirePy.h"
|
||||
#include "TopoShapeFacePy.h"
|
||||
#include "TopoShapeFacePy.cpp"
|
||||
#include "TopoShapeCompoundPy.h"
|
||||
#include "Geometry2d.h"
|
||||
#include <Mod/Part/App/TopoShapeSolidPy.h>
|
||||
#include <Mod/Part/App/TopoShapeEdgePy.h>
|
||||
#include <Mod/Part/App/TopoShapeWirePy.h>
|
||||
#include <Mod/Part/App/TopoShapeFacePy.h>
|
||||
#include <Mod/Part/App/TopoShapeFacePy.cpp>
|
||||
#include <Mod/Part/App/TopoShapeCompoundPy.h>
|
||||
|
||||
#include "BezierSurfacePy.h"
|
||||
#include "BSplineSurfacePy.h"
|
||||
#include "PlanePy.h"
|
||||
#include "CylinderPy.h"
|
||||
#include "ConePy.h"
|
||||
#include "SpherePy.h"
|
||||
#include "OffsetSurfacePy.h"
|
||||
#include "SurfaceOfRevolutionPy.h"
|
||||
#include "SurfaceOfExtrusionPy.h"
|
||||
#include "ToroidPy.h"
|
||||
#include <Mod/Part/App/BezierSurfacePy.h>
|
||||
#include <Mod/Part/App/BSplineSurfacePy.h>
|
||||
#include <Mod/Part/App/PlanePy.h>
|
||||
#include <Mod/Part/App/CylinderPy.h>
|
||||
#include <Mod/Part/App/ConePy.h>
|
||||
#include <Mod/Part/App/SpherePy.h>
|
||||
#include <Mod/Part/App/OffsetSurfacePy.h>
|
||||
#include <Mod/Part/App/SurfaceOfRevolutionPy.h>
|
||||
#include <Mod/Part/App/SurfaceOfExtrusionPy.h>
|
||||
#include <Mod/Part/App/ToroidPy.h>
|
||||
#include "OCCError.h"
|
||||
#include "Tools.h"
|
||||
#include "FaceMaker.h"
|
||||
|
@ -631,6 +636,41 @@ PyObject* TopoShapeFacePy::validate(PyObject *args)
|
|||
}
|
||||
}
|
||||
|
||||
PyObject* TopoShapeFacePy::curveOnSurface(PyObject *args)
|
||||
{
|
||||
PyObject* e;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(TopoShapeEdgePy::Type), &e))
|
||||
return 0;
|
||||
|
||||
try {
|
||||
TopoDS_Shape shape = static_cast<TopoShapeEdgePy*>(e)->getTopoShapePtr()->getShape();
|
||||
if (shape.IsNull()) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "invalid shape");
|
||||
return 0;
|
||||
}
|
||||
|
||||
TopoDS_Edge edge = TopoDS::Edge(shape);
|
||||
const TopoDS_Face& face = TopoDS::Face(getTopoShapePtr()->getShape());
|
||||
|
||||
Standard_Real first, last;
|
||||
Handle_Geom2d_Curve curve = BRep_Tool::CurveOnSurface(edge, face, first, last);
|
||||
std::unique_ptr<Part::Geom2dCurve> geo2d = getCurve2dFromGeom2d(curve);
|
||||
if (!geo2d)
|
||||
Py_Return;
|
||||
|
||||
Py::Tuple tuple(3);
|
||||
tuple.setItem(0, Py::asObject(geo2d->getPyObject()));
|
||||
tuple.setItem(1, Py::Float(first));
|
||||
tuple.setItem(2, Py::Float(last));
|
||||
return Py::new_reference_to(tuple);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object TopoShapeFacePy::getSurface() const
|
||||
{
|
||||
const TopoDS_Face& f = TopoDS::Face(getTopoShapePtr()->getShape());
|
||||
|
|
Loading…
Reference in New Issue
Block a user