1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
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"
25
# include <GC_MakeCylindricalSurface.hxx>
26
# include <Geom_Circle.hxx>
27
# include <Geom_CylindricalSurface.hxx>
28
# include <gp_Cylinder.hxx>
31
#include <Base/GeometryPyCXX.h>
32
#include <Base/PyWrapParseTupleAndKeywords.h>
33
#include <Base/VectorPy.h>
35
#include "CylinderPy.h"
36
#include "CylinderPy.cpp"
43
extern const char* gce_ErrorStatusText(gce_ErrorType et);
45
// returns a string which represents the object e.g. when printed in python
46
std::string CylinderPy::representation() const
48
return "<Cylinder object>";
51
PyObject *CylinderPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
53
// create a new instance of CylinderPy and the Twin object
54
return new CylinderPy(new GeomCylinder);
58
int CylinderPy::PyInit(PyObject* args, PyObject* kwds)
60
// cylinder and distance for offset
63
static const std::array<const char *, 3> keywords_cd{"Cylinder", "Distance", nullptr};
64
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(CylinderPy::Type), &pCyl, &dist)) {
65
CylinderPy* pcCylinder = static_cast<CylinderPy*>(pCyl);
66
Handle(Geom_CylindricalSurface) cylinder = Handle(Geom_CylindricalSurface)::DownCast
67
(pcCylinder->getGeomCylinderPtr()->handle());
68
GC_MakeCylindricalSurface mc(cylinder->Cylinder(), dist);
70
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
74
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
75
(getGeomCylinderPtr()->handle());
76
cyl->SetCylinder(mc.Value()->Cylinder());
80
static const std::array<const char *, 2> keywords_c {"Cylinder", nullptr};
82
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(CylinderPy::Type), &pCyl)) {
83
CylinderPy* pcCylinder = static_cast<CylinderPy*>(pCyl);
84
Handle(Geom_CylindricalSurface) cyl1 = Handle(Geom_CylindricalSurface)::DownCast
85
(pcCylinder->getGeomCylinderPtr()->handle());
86
Handle(Geom_CylindricalSurface) cyl2 = Handle(Geom_CylindricalSurface)::DownCast
87
(this->getGeomCylinderPtr()->handle());
88
cyl2->SetCylinder(cyl1->Cylinder());
92
PyObject *pV1, *pV2, *pV3;
93
static const std::array<const char *, 4> keywords_ppp {"Point1", "Point2", "Point3", nullptr};
95
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp,
96
&(Base::VectorPy::Type), &pV1,
97
&(Base::VectorPy::Type), &pV2,
98
&(Base::VectorPy::Type), &pV3)) {
99
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
100
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
101
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
102
GC_MakeCylindricalSurface mc(gp_Pnt(v1.x,v1.y,v1.z),
103
gp_Pnt(v2.x,v2.y,v2.z),
104
gp_Pnt(v3.x,v3.y,v3.z));
106
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
110
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
111
(getGeomCylinderPtr()->handle());
112
cyl->SetCylinder(mc.Value()->Cylinder());
116
static const std::array<const char *, 2> keywords_cc {"Circle", nullptr};
119
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!", keywords_cc, &(CirclePy::Type), &pCirc)) {
120
CirclePy* pcCircle = static_cast<CirclePy*>(pCirc);
121
Handle(Geom_Circle) circ = Handle(Geom_Circle)::DownCast
122
(pcCircle->getGeomCirclePtr()->handle());
123
GC_MakeCylindricalSurface mc(circ->Circ());
125
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
129
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
130
(getGeomCylinderPtr()->handle());
131
cyl->SetCylinder(mc.Value()->Cylinder());
135
static const std::array<const char *, 1> keywords_n {nullptr};
137
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
138
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
139
(getGeomCylinderPtr()->handle());
145
PyErr_SetString(PyExc_TypeError, "Cylinder constructor accepts:\n"
146
"-- empty parameter list\n"
148
"-- Cylinder, Distance\n"
149
"-- Point1, Point2, Point3\n"
154
Py::Float CylinderPy::getRadius() const
156
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
157
(getGeomCylinderPtr()->handle());
158
return Py::Float(cyl->Radius());
161
void CylinderPy::setRadius(Py::Float arg)
163
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
164
(getGeomCylinderPtr()->handle());
165
cyl->SetRadius((double)arg);
168
Py::Object CylinderPy::getCenter() const
170
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
171
(getGeomCylinderPtr()->handle());
172
gp_Pnt loc = cyl->Location();
173
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
176
void CylinderPy::setCenter(Py::Object arg)
178
PyObject* p = arg.ptr();
179
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
180
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
181
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
182
(getGeomCylinderPtr()->handle());
183
cyl->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
185
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
186
Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
187
Handle(Geom_CylindricalSurface) cyl = Handle(Geom_CylindricalSurface)::DownCast
188
(getGeomCylinderPtr()->handle());
189
cyl->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
192
std::string error = std::string("type must be 'Vector', not ");
193
error += p->ob_type->tp_name;
194
throw Py::TypeError(error);
198
Py::Object CylinderPy::getAxis() const
200
Handle(Geom_ElementarySurface) s = Handle(Geom_ElementarySurface)::DownCast
201
(getGeometryPtr()->handle());
202
gp_Dir dir = s->Axis().Direction();
203
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
206
void CylinderPy::setAxis(Py::Object arg)
208
Standard_Real dir_x, dir_y, dir_z;
209
PyObject *p = arg.ptr();
210
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
211
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
216
else if (PyTuple_Check(p)) {
217
Py::Tuple tuple(arg);
218
dir_x = (double)Py::Float(tuple.getItem(0));
219
dir_y = (double)Py::Float(tuple.getItem(1));
220
dir_z = (double)Py::Float(tuple.getItem(2));
223
std::string error = std::string("type must be 'Vector' or tuple, not ");
224
error += p->ob_type->tp_name;
225
throw Py::TypeError(error);
229
Handle(Geom_ElementarySurface) this_surf = Handle(Geom_ElementarySurface)::DownCast
230
(this->getGeometryPtr()->handle());
232
axis.SetLocation(this_surf->Location());
233
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
234
this_surf->SetAxis(axis);
236
catch (Standard_Failure&) {
237
throw Py::RuntimeError("cannot set axis");
241
PyObject *CylinderPy::getCustomAttributes(const char* /*attr*/) const
246
int CylinderPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)