Method Part.Edge.split added

This commit is contained in:
wmayer 2012-06-05 11:55:45 +02:00
parent a589b39872
commit fac54a4306
2 changed files with 114 additions and 1 deletions

View File

@ -24,7 +24,12 @@
<UserDocu>Vector = valueAt(pos) - Get the point at the given parameter [0|Length] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="normalAt">
<Methode Name="parameterAt">
<Documentation>
<UserDocu>Float = parameterAt(Vertex) - Get the parameter at the given vertex if lying on the edge</UserDocu>
</Documentation>
</Methode>
<Methode Name="normalAt">
<Documentation>
<UserDocu>Vector = normalAt(pos) - Get the normal vector at the given parameter [0|Length] if defined</UserDocu>
</Documentation>
@ -64,6 +69,11 @@
<UserDocu>Discretizes the edge using a given deflection or number of points and returns a list of points</UserDocu>
</Documentation>
</Methode>
<Methode Name="split">
<Documentation>
<UserDocu>Splits the edge at the given parameter values and builds a wire out of it</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Tolerance">
<Documentation>
<UserDocu>Set or get the tolerance of the vertex</UserDocu>

View File

@ -23,10 +23,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <BRep_Builder.hxx>
# include <BRep_Tool.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <BRepLProp_CLProps.hxx>
# include <BRepLProp_CurveTool.hxx>
# include <GProp_GProps.hxx>
@ -47,6 +50,7 @@
# include <TopoDS.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Vertex.hxx>
# include <Standard_Failure.hxx>
#endif
@ -55,12 +59,14 @@
#include <GCPnts_AbscissaPoint.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <Base/Vector3D.h>
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include "TopoShape.h"
#include "TopoShapeFacePy.h"
#include "TopoShapeVertexPy.h"
#include "TopoShapeWirePy.h"
#include "TopoShapeEdgePy.h"
#include "TopoShapeEdgePy.cpp"
@ -185,6 +191,35 @@ PyObject* TopoShapeEdgePy::valueAt(PyObject *args)
return new Base::VectorPy(new Base::Vector3d(V.X(),V.Y(),V.Z()));
}
PyObject* TopoShapeEdgePy::parameterAt(PyObject *args)
{
PyObject* pnt;
PyObject* face=0;
if (!PyArg_ParseTuple(args, "O!|O!",&TopoShapeVertexPy::Type,&pnt,
&TopoShapeFacePy::Type,&face))
return 0;
try {
const TopoDS_Shape& v = static_cast<TopoShapePy*>(pnt)->getTopoShapePtr()->_Shape;
const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->_Shape);
if (face) {
const TopoDS_Shape& f = static_cast<TopoShapeFacePy*>(face)->getTopoShapePtr()->_Shape;
Standard_Real par = BRep_Tool::Parameter(TopoDS::Vertex(v), e, TopoDS::Face(f));
return PyFloat_FromDouble(par);
}
else {
Standard_Real par = BRep_Tool::Parameter(TopoDS::Vertex(v), e);
return PyFloat_FromDouble(par);
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* TopoShapeEdgePy::tangentAt(PyObject *args)
{
double u;
@ -443,6 +478,74 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args)
return 0;
}
PyObject* TopoShapeEdgePy::split(PyObject *args)
{
PyObject* float_or_list;
if (!PyArg_ParseTuple(args, "O", &float_or_list))
return 0;
try {
BRepAdaptor_Curve adapt(TopoDS::Edge(getTopoShapePtr()->_Shape));
Standard_Real f = adapt.FirstParameter();
Standard_Real l = adapt.LastParameter();
std::vector<Standard_Real> par;
par.push_back(f);
if (PyFloat_Check(float_or_list)) {
double val = PyFloat_AsDouble(float_or_list);
if (val == f || val == l) {
PyErr_SetString(PyExc_ValueError, "Cannot split edge at start or end point");
return 0;
}
else if (val < f || val > l) {
PyErr_SetString(PyExc_ValueError, "Value out of parameter range");
return 0;
}
par.push_back(val);
}
else if (PyList_Check(float_or_list)) {
Py::List list(float_or_list);
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
double val = (double)Py::Float(*it);
if (val == f || val == l) {
PyErr_SetString(PyExc_ValueError, "Cannot split edge at start or end point");
return 0;
}
else if (val < f || val > l) {
PyErr_SetString(PyExc_ValueError, "Value out of parameter range");
return 0;
}
par.push_back(val);
}
}
else {
PyErr_SetString(PyExc_TypeError, "Either float or list of floats expected");
return 0;
}
par.push_back(l);
std::sort(par.begin(), par.end());
BRepBuilderAPI_MakeWire mkWire;
Handle_Geom_Curve c = adapt.Curve().Curve();
std::vector<Standard_Real>::iterator end = par.end() - 1;
for (std::vector<Standard_Real>::iterator it = par.begin(); it != end; ++it) {
BRepBuilderAPI_MakeEdge mkBuilder(c, it[0], it[1]);
mkWire.Add(mkBuilder.Edge());
}
return new TopoShapeWirePy(new TopoShape(mkWire.Shape()));
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
PyErr_SetString(PyExc_Exception, "Geometry is not a curve");
return 0;
}
PyObject* TopoShapeEdgePy::setTolerance(PyObject *args)
{
double tol;