| 1 |
/**************************************************************************** |
| 2 |
* Copyright (c) 2019 Zheng Lei (realthunder) <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 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. * |
| 10 |
* * |
| 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. * |
| 15 |
* * |
| 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 * |
| 20 |
* * |
| 21 |
****************************************************************************/ |
| 22 |
|
| 23 |
#include <Inventor/nodes/SoGroup.h> |
| 24 |
#include <Inventor/details/SoDetail.h> |
| 25 |
#include <Inventor/SoFullPath.h> |
| 26 |
|
| 27 |
#include "AxisOriginPy.h" |
| 28 |
#include "AxisOriginPy.cpp" |
| 29 |
#include <Base/Interpreter.h> |
| 30 |
|
| 31 |
using namespace Gui; |
| 32 |
|
| 33 |
PyObject* AxisOriginPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper |
| 34 |
{ |
| 35 |
return new AxisOriginPy(new AxisOrigin); |
| 36 |
} |
| 37 |
|
| 38 |
int AxisOriginPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) |
| 39 |
{ |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
// returns a string which represent the object e.g. when printed in python |
| 45 |
std::string AxisOriginPy::representation() const |
| 46 |
{ |
| 47 |
return "<AxisOrigin>"; |
| 48 |
} |
| 49 |
|
| 50 |
PyObject* AxisOriginPy::getElementPicked(PyObject* args) const |
| 51 |
{ |
| 52 |
PyObject* obj; |
| 53 |
if (!PyArg_ParseTuple(args, "O", &obj)) { |
| 54 |
return nullptr; |
| 55 |
} |
| 56 |
|
| 57 |
void* ptr = nullptr; |
| 58 |
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPickedPoint", obj, &ptr, 0); |
| 59 |
if (!ptr) { |
| 60 |
PyErr_SetString(PyExc_TypeError, "'pickedPoint' must be a coin.SoPickedPoint"); |
| 61 |
return nullptr; |
| 62 |
} |
| 63 |
|
| 64 |
auto pp = static_cast<SoPickedPoint*>(ptr); |
| 65 |
std::string name; |
| 66 |
if (!getAxisOriginPtr()->getElementPicked(pp, name)) { |
| 67 |
Py_Return; |
| 68 |
} |
| 69 |
|
| 70 |
return Py::new_reference_to(Py::String(name)); |
| 71 |
} |
| 72 |
|
| 73 |
PyObject* AxisOriginPy::getDetailPath(PyObject* args) const |
| 74 |
{ |
| 75 |
const char* sub; |
| 76 |
PyObject* path; |
| 77 |
if (!PyArg_ParseTuple(args, "sO", &sub, &path)) { |
| 78 |
return nullptr; |
| 79 |
} |
| 80 |
|
| 81 |
void* ptr = nullptr; |
| 82 |
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPath", path, &ptr, 0); |
| 83 |
if (!ptr) { |
| 84 |
PyErr_SetString(PyExc_TypeError, "'path' must be a coin.SoPath"); |
| 85 |
return nullptr; |
| 86 |
} |
| 87 |
|
| 88 |
auto pPath = static_cast<SoPath*>(ptr); |
| 89 |
SoDetail* det = nullptr; |
| 90 |
if (!getAxisOriginPtr()->getDetailPath(sub, static_cast<SoFullPath*>(pPath), det)) { |
| 91 |
delete det; |
| 92 |
Py_Return; |
| 93 |
} |
| 94 |
if (!det) { |
| 95 |
Py_Return; |
| 96 |
} |
| 97 |
|
| 98 |
return Base::Interpreter() |
| 99 |
.createSWIGPointerObj("pivy.coin", "_p_SoDetail", static_cast<void*>(det), 0); |
| 100 |
} |
| 101 |
|
| 102 |
Py::Float AxisOriginPy::getAxisLength() const |
| 103 |
{ |
| 104 |
return Py::Float(getAxisOriginPtr()->getAxisLength()); |
| 105 |
} |
| 106 |
|
| 107 |
void AxisOriginPy::setAxisLength(Py::Float size) |
| 108 |
{ |
| 109 |
getAxisOriginPtr()->setAxisLength(size); |
| 110 |
} |
| 111 |
|
| 112 |
Py::Float AxisOriginPy::getLineWidth() const |
| 113 |
{ |
| 114 |
return Py::Float(getAxisOriginPtr()->getLineWidth()); |
| 115 |
} |
| 116 |
|
| 117 |
void AxisOriginPy::setLineWidth(Py::Float size) |
| 118 |
{ |
| 119 |
getAxisOriginPtr()->setLineWidth(size); |
| 120 |
} |
| 121 |
|
| 122 |
Py::Float AxisOriginPy::getPointSize() const |
| 123 |
{ |
| 124 |
return Py::Float(getAxisOriginPtr()->getPointSize()); |
| 125 |
} |
| 126 |
|
| 127 |
void AxisOriginPy::setPointSize(Py::Float size) |
| 128 |
{ |
| 129 |
getAxisOriginPtr()->setPointSize(size); |
| 130 |
} |
| 131 |
|
| 132 |
Py::Float AxisOriginPy::getScale() const |
| 133 |
{ |
| 134 |
return Py::Float(getAxisOriginPtr()->getScale()); |
| 135 |
} |
| 136 |
|
| 137 |
void AxisOriginPy::setScale(Py::Float size) |
| 138 |
{ |
| 139 |
getAxisOriginPtr()->setScale(size); |
| 140 |
} |
| 141 |
|
| 142 |
Py::Tuple AxisOriginPy::getPlane() const |
| 143 |
{ |
| 144 |
auto info = getAxisOriginPtr()->getPlane(); |
| 145 |
Py::Tuple ret(2); |
| 146 |
ret.setItem(0, Py::Float(info.first)); |
| 147 |
ret.setItem(1, Py::Float(info.second)); |
| 148 |
|
| 149 |
return ret; |
| 150 |
} |
| 151 |
|
| 152 |
void AxisOriginPy::setPlane(Py::Tuple tuple) |
| 153 |
{ |
| 154 |
float s, d; |
| 155 |
if (!PyArg_ParseTuple(*tuple, "ff", &s, &d)) { |
| 156 |
throw Py::Exception(); |
| 157 |
} |
| 158 |
|
| 159 |
getAxisOriginPtr()->setPlane(s, d); |
| 160 |
} |
| 161 |
|
| 162 |
Py::Dict AxisOriginPy::getLabels() const |
| 163 |
{ |
| 164 |
Py::Dict dict; |
| 165 |
for (auto& v : getAxisOriginPtr()->getLabels()) { |
| 166 |
dict.setItem(Py::String(v.first), Py::String(v.second)); |
| 167 |
} |
| 168 |
|
| 169 |
return dict; |
| 170 |
} |
| 171 |
|
| 172 |
void AxisOriginPy::setLabels(Py::Dict dict) |
| 173 |
{ |
| 174 |
std::map<std::string, std::string> labels; |
| 175 |
for (auto it = dict.begin(); it != dict.end(); ++it) { |
| 176 |
const auto& value = *it; |
| 177 |
labels[value.first.as_string()] = Py::Object(value.second).as_string(); |
| 178 |
} |
| 179 |
getAxisOriginPtr()->setLabels(labels); |
| 180 |
} |
| 181 |
|
| 182 |
Py::Object AxisOriginPy::getNode() const |
| 183 |
{ |
| 184 |
SoGroup* node = getAxisOriginPtr()->getNode(); |
| 185 |
PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoGroup *", node, 1); |
| 186 |
node->ref(); |
| 187 |
return Py::Object(Ptr, true); |
| 188 |
} |
| 189 |
|
| 190 |
PyObject* AxisOriginPy::getCustomAttributes(const char* /*attr*/) const |
| 191 |
{ |
| 192 |
return nullptr; |
| 193 |
} |
| 194 |
|
| 195 |
int AxisOriginPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) |
| 196 |
{ |
| 197 |
return 0; |
| 198 |
} |