1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer@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
***************************************************************************/
24
#include "PreCompiled.h"
26
# include <gp_Ax1.hxx>
27
# include <gp_Dir.hxx>
28
# include <gp_Pnt.hxx>
29
# include <gp_Lin.hxx>
30
# include <gp_Pln.hxx>
31
# include <Geom_Line.hxx>
32
# include <Geom_Plane.hxx>
33
# include <Geom_TrimmedCurve.hxx>
34
# include <GC_MakePlane.hxx>
35
# include <Standard_Failure.hxx>
38
#include <Base/VectorPy.h>
39
#include <Base/GeometryPyCXX.h>
44
#include "PlanePy.cpp"
48
extern const char* gce_ErrorStatusText(gce_ErrorType et);
50
// returns a string which represents the object e.g. when printed in python
51
const char *PlanePy::representation(void) const
53
return "<Plane object>";
56
PyObject *PlanePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
58
// create a new instance of PlanePy and the Twin object
59
return new PlanePy(new GeomPlane);
63
int PlanePy::PyInit(PyObject* args, PyObject* kwds)
65
// plane and distance for offset
68
static char* keywords_pd[] = {"Plane","Distance",NULL};
69
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_pd, &(PlanePy::Type), &pPlane, &dist)) {
70
PlanePy* pcPlane = static_cast<PlanePy*>(pPlane);
71
Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast
72
(pcPlane->getGeometryPtr()->handle());
73
GC_MakePlane mc(plane->Pln(), dist);
75
PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
79
Handle_Geom_Plane plan = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle());
80
plan->SetPln(mc.Value()->Pln());
84
// plane from equation
86
static char* keywords_abcd[] = {"A","B","C","D",NULL};
88
if (PyArg_ParseTupleAndKeywords(args, kwds, "dddd", keywords_abcd,
90
GC_MakePlane mc(a,b,c,d);
92
PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
96
Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle());
97
plane->SetPln(mc.Value()->Pln());
101
PyObject *pV1, *pV2, *pV3;
102
static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL};
104
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp,
105
&(Base::VectorPy::Type), &pV1,
106
&(Base::VectorPy::Type), &pV2,
107
&(Base::VectorPy::Type), &pV3)) {
108
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
109
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
110
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
111
GC_MakePlane mc(gp_Pnt(v1.x,v1.y,v1.z),
112
gp_Pnt(v2.x,v2.y,v2.z),
113
gp_Pnt(v3.x,v3.y,v3.z));
115
PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
119
Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle());
120
plane->SetPln(mc.Value()->Pln());
124
// location and normal
125
static char* keywords_cnr[] = {"Location","Normal",NULL};
127
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", keywords_cnr,
128
&(Base::VectorPy::Type), &pV1,
129
&(Base::VectorPy::Type), &pV2)) {
130
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
131
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
132
GC_MakePlane mc(gp_Pnt(v1.x,v1.y,v1.z),
133
gp_Dir(v2.x,v2.y,v2.z));
135
PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
139
Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle());
140
plane->SetPln(mc.Value()->Pln());
144
static char* keywords_p[] = {"Plane",NULL};
146
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_p, &(PlanePy::Type), &pPlane)) {
147
PlanePy* pcPlane = static_cast<PlanePy*>(pPlane);
148
Handle_Geom_Plane plane1 = Handle_Geom_Plane::DownCast
149
(pcPlane->getGeometryPtr()->handle());
150
Handle_Geom_Plane plane2 = Handle_Geom_Plane::DownCast
151
(this->getGeometryPtr()->handle());
152
plane2->SetPln(plane1->Pln());
156
static char* keywords_n[] = {NULL};
158
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
163
PyErr_SetString(PyExc_TypeError, "Plane constructor accepts:\n"
164
"-- empty parameter list\n"
166
"-- Plane, Distance\n"
167
"-- Location, Normal\n"
168
"-- Point1, Point2, Point3\n"
170
" (as equation: Ax + By + Cz + D = 0.0)");
174
Py::Object PlanePy::getPosition(void) const
176
Handle_Geom_Plane this_surf = Handle_Geom_Plane::DownCast
177
(this->getGeomPlanePtr()->handle());
178
gp_Pnt pnt = this_surf->Location();
179
return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
182
void PlanePy::setPosition(Py::Object arg)
185
PyObject *p = arg.ptr();
186
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
187
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
192
else if (PyTuple_Check(p)) {
193
Py::Tuple tuple(arg);
194
loc.SetX((double)Py::Float(tuple.getItem(0)));
195
loc.SetY((double)Py::Float(tuple.getItem(1)));
196
loc.SetZ((double)Py::Float(tuple.getItem(2)));
199
std::string error = std::string("type must be 'Vector' or tuple, not ");
200
error += p->ob_type->tp_name;
201
throw Py::TypeError(error);
205
Handle_Geom_Plane this_surf = Handle_Geom_Plane::DownCast
206
(this->getGeomPlanePtr()->handle());
207
this_surf->SetLocation(loc);
209
catch (Standard_Failure) {
210
Handle_Standard_Failure e = Standard_Failure::Caught();
211
throw Py::Exception(e->GetMessageString());
215
Py::Object PlanePy::getAxis(void) const
217
Handle_Geom_ElementarySurface s = Handle_Geom_ElementarySurface::DownCast
218
(getGeometryPtr()->handle());
219
gp_Dir dir = s->Axis().Direction();
220
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
223
void PlanePy::setAxis(Py::Object arg)
225
Standard_Real dir_x, dir_y, dir_z;
226
PyObject *p = arg.ptr();
227
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
228
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
233
else if (PyTuple_Check(p)) {
234
Py::Tuple tuple(arg);
235
dir_x = (double)Py::Float(tuple.getItem(0));
236
dir_y = (double)Py::Float(tuple.getItem(1));
237
dir_z = (double)Py::Float(tuple.getItem(2));
240
std::string error = std::string("type must be 'Vector' or tuple, not ");
241
error += p->ob_type->tp_name;
242
throw Py::TypeError(error);
246
Handle_Geom_ElementarySurface this_surf = Handle_Geom_ElementarySurface::DownCast
247
(this->getGeometryPtr()->handle());
249
axis.SetLocation(this_surf->Location());
250
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
251
gp_Dir dir = axis.Direction();
252
this_surf->SetAxis(axis);
254
catch (Standard_Failure) {
255
throw Py::Exception("cannot set axis");
259
PyObject* PlanePy::uIso(PyObject * args)
262
if (!PyArg_ParseTuple(args, "d", &u))
266
Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast
267
(getGeomPlanePtr()->handle());
268
Handle_Geom_Line c = Handle_Geom_Line::DownCast(plane->UIso(u));
269
GeomLineSegment* line = new GeomLineSegment();
270
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
272
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
273
(this_curv->BasisCurve());
274
this_line->SetLin(c->Lin());
275
return new LinePy(line);
277
catch (Standard_Failure) {
278
Handle_Standard_Failure e = Standard_Failure::Caught();
279
PyErr_SetString(PyExc_Exception, e->GetMessageString());
284
PyObject* PlanePy::vIso(PyObject * args)
287
if (!PyArg_ParseTuple(args, "d", &v))
291
Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast
292
(getGeomPlanePtr()->handle());
293
Handle_Geom_Line c = Handle_Geom_Line::DownCast(plane->VIso(v));
294
GeomLineSegment* line = new GeomLineSegment();
295
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
297
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
298
(this_curv->BasisCurve());
299
this_line->SetLin(c->Lin());
300
return new LinePy(line);
302
catch (Standard_Failure) {
303
Handle_Standard_Failure e = Standard_Failure::Caught();
304
PyErr_SetString(PyExc_Exception, e->GetMessageString());
309
PyObject *PlanePy::getCustomAttributes(const char* /*attr*/) const
314
int PlanePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)