1
/***************************************************************************
2
* Copyright (c) 2011 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_MakeArcOfCircle.hxx>
26
# include <Geom_Circle.hxx>
27
# include <Geom_TrimmedCurve.hxx>
30
#include <Base/VectorPy.h>
32
#include "ArcOfCirclePy.h"
33
#include "ArcOfCirclePy.cpp"
40
extern const char* gce_ErrorStatusText(gce_ErrorType et);
42
// returns a string which represents the object e.g. when printed in python
43
std::string ArcOfCirclePy::representation() const
45
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
46
(getGeomArcOfCirclePtr()->handle());
47
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(trim->BasisCurve());
49
gp_Ax1 axis = circle->Axis();
50
gp_Dir dir = axis.Direction();
51
gp_Pnt loc = axis.Location();
52
Standard_Real fRad = circle->Radius();
53
Standard_Real u1 = trim->FirstParameter();
54
Standard_Real u2 = trim->LastParameter();
56
std::stringstream str;
57
str << "ArcOfCircle (";
58
str << "Radius : " << fRad << ", ";
59
str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
60
str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
61
str << "Parameter : (" << u1 << ", " << u2 << ")";
67
PyObject *ArcOfCirclePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
69
// create a new instance of ArcOfCirclePy and the Twin object
70
return new ArcOfCirclePy(new GeomArcOfCircle);
74
int ArcOfCirclePy::PyInit(PyObject* args, PyObject* /*kwds*/)
78
PyObject *sense=Py_True;
79
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::CirclePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
81
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast
82
(static_cast<CirclePy*>(o)->getGeomCirclePtr()->handle());
83
GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, Base::asBoolean(sense));
85
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
89
getGeomArcOfCirclePtr()->setHandle(arc.Value());
92
catch (Standard_Failure& e) {
93
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
97
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
103
PyObject *pV1, *pV2, *pV3;
104
if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1,
105
&(Base::VectorPy::Type), &pV2,
106
&(Base::VectorPy::Type), &pV3)) {
107
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
108
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
109
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
111
GC_MakeArcOfCircle arc(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(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
119
getGeomArcOfCirclePtr()->setHandle(arc.Value());
124
PyErr_SetString(PyExc_TypeError,
125
"ArcOfCircle constructor expects a circle curve and a parameter range or three points");
129
Py::Float ArcOfCirclePy::getRadius() const
131
return Py::Float(getGeomArcOfCirclePtr()->getRadius());
134
void ArcOfCirclePy::setRadius(Py::Float arg)
136
getGeomArcOfCirclePtr()->setRadius((double)arg);
139
Py::Object ArcOfCirclePy::getCircle() const
141
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
142
(getGeomArcOfCirclePtr()->handle());
143
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(trim->BasisCurve());
144
return Py::Object(new CirclePy(new GeomCircle(circle)), true);
147
PyObject *ArcOfCirclePy::getCustomAttributes(const char* ) const
152
int ArcOfCirclePy::setCustomAttributes(const char* , PyObject *)