1
/****************************************************************************
2
* Copyright (c) 2019 Zheng Lei (realthunder) <realthunder.dev@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 <Inventor/nodes/SoGroup.h>
26
# include <Inventor/details/SoDetail.h>
27
# include <Inventor/SoFullPath.h>
30
#include "AxisOriginPy.h"
31
#include "AxisOriginPy.cpp"
32
#include <Base/Interpreter.h>
36
PyObject *AxisOriginPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
38
return new AxisOriginPy(new AxisOrigin);
41
int AxisOriginPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
47
// returns a string which represent the object e.g. when printed in python
48
std::string AxisOriginPy::representation() const
50
return "<AxisOrigin>";
53
PyObject* AxisOriginPy::getElementPicked(PyObject* args)
56
if (!PyArg_ParseTuple(args, "O", &obj))
60
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPickedPoint", obj, &ptr, 0);
62
PyErr_SetString(PyExc_TypeError, "'pickedPoint' must be a coin.SoPickedPoint");
66
auto pp = static_cast<SoPickedPoint*>(ptr);
68
if (!getAxisOriginPtr()->getElementPicked(pp,name))
71
return Py::new_reference_to(Py::String(name));
74
PyObject* AxisOriginPy::getDetailPath(PyObject* args)
78
if (!PyArg_ParseTuple(args, "sO", &sub,&path))
82
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPath", path, &ptr, 0);
84
PyErr_SetString(PyExc_TypeError, "'path' must be a coin.SoPath");
88
auto pPath = static_cast<SoPath*>(ptr);
89
SoDetail *det = nullptr;
90
if (!getAxisOriginPtr()->getDetailPath(sub, static_cast<SoFullPath*>(pPath), det)) {
97
return Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoDetail", static_cast<void*>(det), 0);
100
Py::Float AxisOriginPy::getAxisLength() const
102
return Py::Float(getAxisOriginPtr()->getAxisLength());
105
void AxisOriginPy::setAxisLength(Py::Float size)
107
getAxisOriginPtr()->setAxisLength(size);
110
Py::Float AxisOriginPy::getLineWidth() const
112
return Py::Float(getAxisOriginPtr()->getLineWidth());
115
void AxisOriginPy::setLineWidth(Py::Float size)
117
getAxisOriginPtr()->setLineWidth(size);
120
Py::Float AxisOriginPy::getPointSize() const
122
return Py::Float(getAxisOriginPtr()->getPointSize());
125
void AxisOriginPy::setPointSize(Py::Float size)
127
getAxisOriginPtr()->setPointSize(size);
130
Py::Float AxisOriginPy::getScale() const
132
return Py::Float(getAxisOriginPtr()->getScale());
135
void AxisOriginPy::setScale(Py::Float size)
137
getAxisOriginPtr()->setScale(size);
140
Py::Tuple AxisOriginPy::getPlane() const
142
auto info = getAxisOriginPtr()->getPlane();
144
ret.setItem(0,Py::Float(info.first));
145
ret.setItem(1,Py::Float(info.second));
150
void AxisOriginPy::setPlane(Py::Tuple tuple)
153
if (!PyArg_ParseTuple(*tuple, "ff",&s,&d))
154
throw Py::Exception();
156
getAxisOriginPtr()->setPlane(s,d);
159
Py::Dict AxisOriginPy::getLabels() const
162
for (auto &v : getAxisOriginPtr()->getLabels())
163
dict.setItem(Py::String(v.first),Py::String(v.second));
168
void AxisOriginPy::setLabels(Py::Dict dict)
170
std::map<std::string,std::string> labels;
171
for (auto it=dict.begin(); it!=dict.end(); ++it) {
172
const auto &value = *it;
173
labels[value.first.as_string()] = Py::Object(value.second).as_string();
175
getAxisOriginPtr()->setLabels(labels);
178
Py::Object AxisOriginPy::getNode() const
180
SoGroup* node = getAxisOriginPtr()->getNode();
181
PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","SoGroup *", node, 1);
183
return Py::Object(Ptr, true);
186
PyObject *AxisOriginPy::getCustomAttributes(const char* /*attr*/) const
191
int AxisOriginPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)