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 <Geom_OffsetCurve.hxx>
28
#include <Base/GeometryPyCXX.h>
29
#include <Base/Vector3D.h>
30
#include <Base/VectorPy.h>
32
#include "OffsetCurvePy.h"
33
#include "OffsetCurvePy.cpp"
40
// returns a string which represents the object e.g. when printed in python
41
std::string OffsetCurvePy::representation() const
43
return "<OffsetCurve object>";
46
PyObject *OffsetCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
48
// create a new instance of OffsetCurvePy and the Twin object
49
return new OffsetCurvePy(new GeomOffsetCurve);
53
int OffsetCurvePy::PyInit(PyObject* args, PyObject* /*kwd*/)
58
if (!PyArg_ParseTuple(args, "O!dO!",
59
&(GeometryPy::Type), &pGeom,
61
&(Base::VectorPy::Type),&pDir))
64
GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
65
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast
66
(pcGeo->getGeometryPtr()->handle());
68
PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
73
Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
74
Handle(Geom_OffsetCurve) curve2 = new Geom_OffsetCurve(curve, offset, gp_Dir(dir.x,dir.y,dir.z));
75
getGeomOffsetCurvePtr()->setHandle(curve2);
78
catch (Standard_Failure& e) {
80
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
85
Py::Float OffsetCurvePy::getOffsetValue() const
87
Handle(Geom_OffsetCurve) curve = Handle(Geom_OffsetCurve)::DownCast(getGeometryPtr()->handle());
88
return Py::Float(curve->Offset());
91
void OffsetCurvePy::setOffsetValue(Py::Float arg)
93
Handle(Geom_OffsetCurve) curve = Handle(Geom_OffsetCurve)::DownCast(getGeometryPtr()->handle());
94
curve->SetOffsetValue((double)arg);
97
Py::Object OffsetCurvePy::getOffsetDirection() const
99
Handle(Geom_OffsetCurve) curve = Handle(Geom_OffsetCurve)::DownCast(getGeometryPtr()->handle());
100
const gp_Dir& dir = curve->Direction();
101
return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
104
void OffsetCurvePy::setOffsetDirection(Py::Object arg)
106
PyObject* p = arg.ptr();
107
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
108
Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
109
Handle(Geom_OffsetCurve) curve = Handle(Geom_OffsetCurve)::DownCast(getGeometryPtr()->handle());
110
curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
112
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
113
Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
114
Handle(Geom_OffsetCurve) curve = Handle(Geom_OffsetCurve)::DownCast(getGeometryPtr()->handle());
115
curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
118
std::string error = std::string("type must be 'Vector', not ");
119
error += p->ob_type->tp_name;
120
throw Py::TypeError(error);
124
Py::Object OffsetCurvePy::getBasisCurve() const
126
Handle(Geom_OffsetCurve) curve = Handle(Geom_OffsetCurve)::DownCast(getGeometryPtr()->handle());
127
Handle(Geom_Curve) basis = curve->BasisCurve();
128
std::unique_ptr<GeomCurve> ptr(Part::makeFromCurve(basis));
129
return Py::asObject(ptr->getPyObject());
132
void OffsetCurvePy::setBasisCurve(Py::Object arg)
134
PyObject* p = arg.ptr();
135
if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
136
GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
137
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast
138
(pcGeo->getGeometryPtr()->handle());
139
if (curve.IsNull()) {
140
throw Py::TypeError("geometry is not a curve");
144
Handle(Geom_OffsetCurve) curve2 = Handle(Geom_OffsetCurve)::DownCast
145
(getGeometryPtr()->handle());
146
curve2->SetBasisCurve(curve);
148
catch (Standard_Failure& e) {
149
throw Py::RuntimeError(e.GetMessageString());
154
PyObject *OffsetCurvePy::getCustomAttributes(const char* /*attr*/) const
159
int OffsetCurvePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)