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 <Geom_SurfaceOfLinearExtrusion.hxx>
30
#include "SurfaceOfExtrusionPy.h"
31
#include "SurfaceOfExtrusionPy.cpp"
33
#include <Base/GeometryPyCXX.h>
34
#include <Base/VectorPy.h>
38
// returns a string which represents the object e.g. when printed in python
39
const char *SurfaceOfExtrusionPy::representation(void) const
41
return "<SurfaceOfExtrusion object>";
44
PyObject *SurfaceOfExtrusionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
46
// create a new instance of SurfaceOfExtrusionPy and the Twin object
47
return new SurfaceOfExtrusionPy(new GeomSurfaceOfExtrusion);
51
int SurfaceOfExtrusionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
55
if (!PyArg_ParseTuple(args, "O!O!",
56
&(GeometryPy::Type), &pGeom,
57
&(Base::VectorPy::Type),&pDir))
60
GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
61
Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
62
(pcGeo->getGeometryPtr()->handle());
64
PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
69
Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
70
Handle_Geom_SurfaceOfLinearExtrusion curve2 = new Geom_SurfaceOfLinearExtrusion(curve,
71
gp_Dir(dir.x,dir.y,dir.z));
72
getGeomSurfaceOfExtrusionPtr()->setHandle(curve2);
75
catch (Standard_Failure) {
76
Handle_Standard_Failure e = Standard_Failure::Caught();
77
PyErr_SetString(PyExc_Exception, e->GetMessageString());
82
Py::Object SurfaceOfExtrusionPy::getDirection(void) const
84
Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
85
(getGeometryPtr()->handle());
86
const gp_Dir& dir = curve->Direction();
87
return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
90
void SurfaceOfExtrusionPy::setDirection(Py::Object arg)
92
PyObject* p = arg.ptr();
93
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
94
Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
95
Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
96
(getGeometryPtr()->handle());
97
curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
99
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
100
Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
101
Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
102
(getGeometryPtr()->handle());
103
curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
106
std::string error = std::string("type must be 'Vector', not ");
107
error += p->ob_type->tp_name;
108
throw Py::TypeError(error);
112
Py::Object SurfaceOfExtrusionPy::getBasisCurve(void) const
114
throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
117
void SurfaceOfExtrusionPy::setBasisCurve(Py::Object arg)
119
PyObject* p = arg.ptr();
120
if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
121
GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
122
Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
123
(pcGeo->getGeometryPtr()->handle());
124
if (curve.IsNull()) {
125
throw Py::TypeError("geometry is not a curve");
129
Handle_Geom_SurfaceOfLinearExtrusion curve2 = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
130
(getGeometryPtr()->handle());
131
curve2->SetBasisCurve(curve);
133
catch (Standard_Failure) {
134
Handle_Standard_Failure e = Standard_Failure::Caught();
135
throw Py::Exception(e->GetMessageString());
140
PyObject *SurfaceOfExtrusionPy::getCustomAttributes(const char* /*attr*/) const
145
int SurfaceOfExtrusionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)