1
/***************************************************************************
2
* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
27
# include <BRep_Builder.hxx>
28
# include <BRep_Tool.hxx>
29
# include <BRepBuilderAPI_MakeVertex.hxx>
30
# include <Geom_CartesianPoint.hxx>
31
# include <Standard_Failure.hxx>
33
# include <TopoDS_Vertex.hxx>
36
#include <Base/Vector3D.h>
37
#include <Base/VectorPy.h>
39
#include "TopoShapeVertexPy.h"
40
#include "TopoShapeVertexPy.cpp"
46
// returns a string which represents the object e.g. when printed in python
47
std::string TopoShapeVertexPy::representation() const
49
std::stringstream str;
50
str << "<Vertex object at " << getTopoShapePtr() << ">";
55
PyObject *TopoShapeVertexPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
57
// create a new instance of TopoShapeVertexPy and the Twin object
58
return new TopoShapeVertexPy(new TopoShape);
62
int TopoShapeVertexPy::PyInit(PyObject* args, PyObject* /*kwd*/)
64
if (PyArg_ParseTuple(args, "")) {
66
getTopoShapePtr()->setShape(TopoDS_Vertex());
71
double x=0.0,y=0.0,z=0.0;
74
if (PyArg_ParseTuple(args, "|ddd", &x,&y,&z)) {
79
PyErr_Clear(); // set by PyArg_ParseTuple()
80
if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
81
Base::Vector3d* ptr = static_cast<Base::VectorPy*>(object)->getVectorPtr();
89
PyErr_Clear(); // set by PyArg_ParseTuple()
90
if (PyArg_ParseTuple(args,"O!",&(PyTuple_Type), &object)) {
92
Py::Tuple tuple(object);
93
x = Py::Float(tuple.getItem(0));
94
y = Py::Float(tuple.getItem(1));
95
z = Py::Float(tuple.getItem(2));
98
catch (const Py::Exception&) {
104
PyErr_Clear(); // set by PyArg_ParseTuple()
105
if (PyArg_ParseTuple(args,"O!",&(PointPy::Type), &object)) {
106
Handle(Geom_CartesianPoint) this_point = Handle(Geom_CartesianPoint)::DownCast
107
(static_cast<PointPy*>(object)->getGeomPointPtr()->handle());
108
gp_Pnt pnt = this_point->Pnt();
116
PyErr_Clear(); // set by PyArg_ParseTuple()
117
if (PyArg_ParseTuple(args,"O!",&(Part::TopoShapePy::Type), &object)) {
118
TopoShape* ptr = static_cast<TopoShapePy*>(object)->getTopoShapePtr();
119
TopoDS_Shape shape = ptr->getShape();
120
if (!shape.IsNull() && shape.ShapeType() == TopAbs_VERTEX) {
121
TopoShapeVertexPy::PointerType vert = getTopoShapePtr();
122
vert->setShape(ptr->getShape());
128
PyErr_SetString(PyExc_TypeError, "Either three floats, tuple, vector or vertex expected");
132
TopoShapeVertexPy::PointerType ptr = getTopoShapePtr();
133
BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(x,y,z));
134
TopoDS_Shape s = aBuilder.Vertex();
140
Py::Float TopoShapeVertexPy::getTolerance() const
142
const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
143
return Py::Float(BRep_Tool::Tolerance(v));
146
void TopoShapeVertexPy::setTolerance(Py::Float tol)
148
BRep_Builder aBuilder;
149
const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
150
aBuilder.UpdateVertex(v, (double)tol);
153
Py::Float TopoShapeVertexPy::getX() const
156
const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
157
return Py::Float(BRep_Tool::Pnt(v).X());
159
catch (Standard_Failure& e) {
161
throw Py::RuntimeError(e.GetMessageString());
165
Py::Float TopoShapeVertexPy::getY() const
168
const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
169
return Py::Float(BRep_Tool::Pnt(v).Y());
171
catch (Standard_Failure& e) {
173
throw Py::RuntimeError(e.GetMessageString());
177
Py::Float TopoShapeVertexPy::getZ() const
180
const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
181
return Py::Float(BRep_Tool::Pnt(v).Z());
183
catch (Standard_Failure& e) {
185
throw Py::RuntimeError(e.GetMessageString());
189
Py::Object TopoShapeVertexPy::getPoint() const
192
const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
193
gp_Pnt p = BRep_Tool::Pnt(v);
194
Base::PyObjectBase* pnt = new Base::VectorPy(new Base::Vector3d(p.X(),p.Y(),p.Z()));
195
pnt->setNotTracking();
196
return Py::asObject(pnt);
198
catch (Standard_Failure& e) {
200
throw Py::RuntimeError(e.GetMessageString());
204
PyObject *TopoShapeVertexPy::getCustomAttributes(const char* /*attr*/) const
209
int TopoShapeVertexPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)