+ add toShape() to Part.Point, allow to pass Part.Point in Part.Vertex

This commit is contained in:
wmayer 2015-01-15 11:39:53 +01:00
parent 17099d0545
commit ee4436b2c0
3 changed files with 48 additions and 1 deletions

View File

@ -23,6 +23,11 @@ Part.Point(Point)
Part.Point(Vector)
Creates a line for the given coordinates</UserDocu>
</Documentation>
<Methode Name="toShape" Const="true">
<Documentation>
<UserDocu>Create a vertex from this point.</UserDocu>
</Documentation>
</Methode>
<Attribute Name="X" ReadOnly="false">
<Documentation>
<UserDocu>X component of this point.</UserDocu>

View File

@ -23,11 +23,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <gp.hxx>
# include <Geom_CartesianPoint.hxx>
# include <GC_MakeLine.hxx>
# include <GC_MakeSegment.hxx>
# include <Precision.hxx>
# include <TopoDS_Vertex.hxx>
#endif
#include <Base/VectorPy.h>
@ -36,6 +38,9 @@
#include "Geometry.h"
#include "PointPy.h"
#include "PointPy.cpp"
#include "OCCError.h"
#include "TopoShape.h"
#include "TopoShapeVertexPy.h"
using namespace Part;
@ -99,6 +104,30 @@ int PointPy::PyInit(PyObject* args, PyObject* /*kwd*/)
return -1;
}
PyObject* PointPy::toShape(PyObject *args)
{
Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast
(this->getGeomPointPtr()->handle());
try {
if (!this_point.IsNull()) {
if (!PyArg_ParseTuple(args, ""))
return 0;
BRepBuilderAPI_MakeVertex mkBuilder(this_point->Pnt());
const TopoDS_Vertex& sh = mkBuilder.Vertex();
return new TopoShapeVertexPy(new TopoShape(sh));
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return 0;
}
PyErr_SetString(PartExceptionOCCError, "Geometry is not a point");
return 0;
}
Py::Float PointPy::getX(void) const
{
Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast

View File

@ -31,13 +31,14 @@
# include <TopoDS_Vertex.hxx>
# include <BRep_Builder.hxx>
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <Geom_CartesianPoint.hxx>
#endif
#include <Mod/Part/App/TopoShape.h>
#include <Base/VectorPy.h>
#include <Base/Vector3D.h>
#include "TopoShapeEdgePy.h"
#include "PointPy.h"
#include "TopoShapeVertexPy.h"
#include "TopoShapeVertexPy.cpp"
@ -94,6 +95,18 @@ int TopoShapeVertexPy::PyInit(PyObject* args, PyObject* /*kwd*/)
}
}
}
if (!success) {
PyErr_Clear(); // set by PyArg_ParseTuple()
if (PyArg_ParseTuple(args,"O!",&(PointPy::Type), &object)) {
Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast
(static_cast<PointPy*>(object)->getGeomPointPtr()->handle());
gp_Pnt pnt = this_point->Pnt();
x = pnt.X();
y = pnt.Y();
z = pnt.Z();
success = true;
}
}
if (!success) {
PyErr_Clear(); // set by PyArg_ParseTuple()
if (PyArg_ParseTuple(args,"O!",&(Part::TopoShapePy::Type), &object)) {