Skip to content

Commit

Permalink
+ add toShape() to Part.Point, allow to pass Part.Point in Part.Vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 15, 2015
1 parent 17099d0 commit ee4436b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Mod/Part/App/PointPy.xml
Expand Up @@ -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>
Expand Down
29 changes: 29 additions & 0 deletions src/Mod/Part/App/PointPyImp.cpp
Expand Up @@ -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>
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/Mod/Part/App/TopoShapeVertexPyImp.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit ee4436b

Please sign in to comment.