1
/***************************************************************************
2
* Copyright (c) 2016 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 <Geom2d_OffsetCurve.hxx>
28
#include "Geom2d/OffsetCurve2dPy.h"
29
#include "Geom2d/OffsetCurve2dPy.cpp"
35
// returns a string which represents the object e.g. when printed in python
36
std::string OffsetCurve2dPy::representation() const
38
return "<OffsetCurve2d object>";
41
PyObject *OffsetCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
43
// create a new instance of OffsetCurve2dPy and the Twin object
44
return new OffsetCurve2dPy(new Geom2dOffsetCurve);
48
int OffsetCurve2dPy::PyInit(PyObject* args, PyObject* /*kwd*/)
52
if (!PyArg_ParseTuple(args, "O!d",
53
&(Curve2dPy::Type), &pGeom,
57
Curve2dPy* pcGeo = static_cast<Curve2dPy*>(pGeom);
58
Handle(Geom2d_Curve) curve = Handle(Geom2d_Curve)::DownCast
59
(pcGeo->getGeometry2dPtr()->handle());
61
PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
66
Handle(Geom2d_OffsetCurve) curve2 = new Geom2d_OffsetCurve(curve, offset);
67
getGeom2dOffsetCurvePtr()->setHandle(curve2);
70
catch (Standard_Failure& e) {
72
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
77
Py::Float OffsetCurve2dPy::getOffsetValue() const
79
Handle(Geom2d_OffsetCurve) curve = Handle(Geom2d_OffsetCurve)::DownCast(getGeometry2dPtr()->handle());
80
return Py::Float(curve->Offset());
83
void OffsetCurve2dPy::setOffsetValue(Py::Float arg)
85
Handle(Geom2d_OffsetCurve) curve = Handle(Geom2d_OffsetCurve)::DownCast(getGeometry2dPtr()->handle());
86
curve->SetOffsetValue((double)arg);
89
Py::Object OffsetCurve2dPy::getBasisCurve() const
91
Handle(Geom2d_OffsetCurve) curve = Handle(Geom2d_OffsetCurve)::DownCast(getGeometry2dPtr()->handle());
92
Handle(Geom2d_Curve) basis = curve->BasisCurve();
95
std::unique_ptr<Geom2dCurve> geo2d = makeFromCurve2d(basis);
97
throw Py::RuntimeError("Unknown curve type");
98
return Py::asObject(geo2d->getPyObject());
101
void OffsetCurve2dPy::setBasisCurve(Py::Object arg)
103
PyObject* p = arg.ptr();
104
if (PyObject_TypeCheck(p, &(Curve2dPy::Type))) {
105
Curve2dPy* pcGeo = static_cast<Curve2dPy*>(p);
106
Handle(Geom2d_Curve) curve = Handle(Geom2d_Curve)::DownCast
107
(pcGeo->getGeometry2dPtr()->handle());
108
if (curve.IsNull()) {
109
throw Py::TypeError("geometry is not a curve");
112
Handle(Geom2d_OffsetCurve) curve2 = Handle(Geom2d_OffsetCurve)::DownCast
113
(getGeometry2dPtr()->handle());
114
if (curve == curve2) {
115
throw Py::RuntimeError("cannot set this curve as basis");
119
curve2->SetBasisCurve(curve);
121
catch (Standard_Failure& e) {
122
throw Py::RuntimeError(e.GetMessageString());
127
PyObject *OffsetCurve2dPy::getCustomAttributes(const char* /*attr*/) const
132
int OffsetCurve2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)