1
/***************************************************************************
2
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
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_TrimmedCurve.hxx>
28
#include <Base/GeometryPyCXX.h>
29
#include <Base/VectorPy.h>
31
#include "ArcOfConicPy.h"
32
#include "ArcOfConicPy.cpp"
38
// returns a string which represents the object e.g. when printed in python
39
std::string ArcOfConicPy::representation() const
41
return "<ArcOfConic object>";
44
PyObject *ArcOfConicPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
46
// never create such objects with the constructor
47
PyErr_SetString(PyExc_RuntimeError,
48
"You cannot create an instance of the abstract class 'ArcOfConic'.");
53
int ArcOfConicPy::PyInit(PyObject* /*args*/, PyObject* /*kwds*/)
58
Py::Object ArcOfConicPy::getLocation() const
60
return Py::Vector(getGeomArcOfConicPtr()->getLocation());
63
Py::Object ArcOfConicPy::getCenter() const
65
return Py::Vector(getGeomArcOfConicPtr()->getCenter());
68
void ArcOfConicPy::setLocation(Py::Object arg)
70
PyObject* p = arg.ptr();
71
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
72
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
73
getGeomArcOfConicPtr()->setLocation(loc);
75
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
76
Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
77
getGeomArcOfConicPtr()->setLocation(loc);
80
std::string error = std::string("type must be 'Vector', not ");
81
error += p->ob_type->tp_name;
82
throw Py::TypeError(error);
86
void ArcOfConicPy::setCenter(Py::Object arg)
88
PyObject* p = arg.ptr();
89
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
90
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
91
getGeomArcOfConicPtr()->setCenter(loc);
93
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
94
Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
95
getGeomArcOfConicPtr()->setCenter(loc);
98
std::string error = std::string("type must be 'Vector', not ");
99
error += p->ob_type->tp_name;
100
throw Py::TypeError(error);
104
Py::Float ArcOfConicPy::getAngleXU() const
106
return Py::Float(getGeomArcOfConicPtr()->getAngleXU());
109
void ArcOfConicPy::setAngleXU(Py::Float arg)
111
getGeomArcOfConicPtr()->setAngleXU((double)arg);
114
Py::Object ArcOfConicPy::getAxis() const
116
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
117
(getGeomArcOfConicPtr()->handle());
118
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
119
gp_Ax1 axis = conic->Axis();
120
gp_Dir dir = axis.Direction();
121
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
124
void ArcOfConicPy::setAxis(Py::Object arg)
126
PyObject* p = arg.ptr();
128
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
129
val = static_cast<Base::VectorPy*>(p)->value();
131
else if (PyTuple_Check(p)) {
132
val = Base::getVectorFromTuple<double>(p);
135
std::string error = std::string("type must be 'Vector', not ");
136
error += p->ob_type->tp_name;
137
throw Py::TypeError(error);
140
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
141
(getGeomArcOfConicPtr()->handle());
142
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
145
axis.SetLocation(conic->Location());
146
axis.SetDirection(gp_Dir(val.x, val.y, val.z));
147
conic->SetAxis(axis);
149
catch (Standard_Failure&) {
150
throw Py::RuntimeError("cannot set axis");
154
Py::Object ArcOfConicPy::getXAxis() const
156
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
157
(getGeomArcOfConicPtr()->handle());
158
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
159
gp_Ax1 axis = conic->XAxis();
160
gp_Dir dir = axis.Direction();
161
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
164
void ArcOfConicPy::setXAxis(Py::Object arg)
166
PyObject* p = arg.ptr();
168
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
169
val = static_cast<Base::VectorPy*>(p)->value();
171
else if (PyTuple_Check(p)) {
172
val = Base::getVectorFromTuple<double>(p);
175
std::string error = std::string("type must be 'Vector', not ");
176
error += p->ob_type->tp_name;
177
throw Py::TypeError(error);
180
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
181
(getGeomArcOfConicPtr()->handle());
182
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
185
pos = conic->Position();
186
pos.SetXDirection(gp_Dir(val.x, val.y, val.z));
187
conic->SetPosition(pos);
189
catch (Standard_Failure&) {
190
throw Py::RuntimeError("cannot set X axis");
194
Py::Object ArcOfConicPy::getYAxis() const
196
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
197
(getGeomArcOfConicPtr()->handle());
198
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
199
gp_Ax1 axis = conic->YAxis();
200
gp_Dir dir = axis.Direction();
201
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
204
void ArcOfConicPy::setYAxis(Py::Object arg)
206
PyObject* p = arg.ptr();
208
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
209
val = static_cast<Base::VectorPy*>(p)->value();
211
else if (PyTuple_Check(p)) {
212
val = Base::getVectorFromTuple<double>(p);
215
std::string error = std::string("type must be 'Vector', not ");
216
error += p->ob_type->tp_name;
217
throw Py::TypeError(error);
220
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
221
(getGeomArcOfConicPtr()->handle());
222
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
225
pos = conic->Position();
226
pos.SetYDirection(gp_Dir(val.x, val.y, val.z));
227
conic->SetPosition(pos);
229
catch (Standard_Failure&) {
230
throw Py::RuntimeError("cannot set Y axis");
234
PyObject *ArcOfConicPy::getCustomAttributes(const char* ) const
239
int ArcOfConicPy::setCustomAttributes(const char* , PyObject *)