| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 5 |
* * |
| 6 |
* This file is part of the FreeCAD CAx development system. * |
| 7 |
* * |
| 8 |
* This library is free software; you can redistribute it and/or * |
| 9 |
* modify it under the terms of the GNU Library General Public * |
| 10 |
* License as published by the Free Software Foundation; either * |
| 11 |
* version 2 of the License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* This library is distributed in the hope that it will be useful, * |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 |
* GNU Library General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Library General Public * |
| 19 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 20 |
* write to the Free Software Foundation, Inc., 51 Franklin Street, * |
| 21 |
* Fifth Floor, Boston, MA 02110-1301, USA * |
| 22 |
* * |
| 23 |
***************************************************************************/ |
| 24 |
|
| 25 |
|
| 26 |
#include "GeometryPyCXX.h" |
| 27 |
|
| 28 |
// generated out of CoordinateSystem.pyi |
| 29 |
#include "CoordinateSystemPy.h" |
| 30 |
#include "CoordinateSystemPy.cpp" |
| 31 |
|
| 32 |
#include "AxisPy.h" |
| 33 |
#include "PlacementPy.h" |
| 34 |
#include "VectorPy.h" |
| 35 |
|
| 36 |
using namespace Base; |
| 37 |
|
| 38 |
// returns a string which represents the object e.g. when printed in python |
| 39 |
std::string CoordinateSystemPy::representation() const |
| 40 |
{ |
| 41 |
return {"<CoordinateSystem object>"}; |
| 42 |
} |
| 43 |
|
| 44 |
PyObject* CoordinateSystemPy::PyMake(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) |
| 45 |
{ |
| 46 |
// create a new instance of CoordinateSystemPy and the Twin object |
| 47 |
return new CoordinateSystemPy(new CoordinateSystem); |
| 48 |
} |
| 49 |
|
| 50 |
// constructor method |
| 51 |
int CoordinateSystemPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) |
| 52 |
{ |
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
PyObject* CoordinateSystemPy::setAxes(PyObject* args) |
| 57 |
{ |
| 58 |
PyObject* axis {}; |
| 59 |
PyObject* xdir {}; |
| 60 |
if (PyArg_ParseTuple(args, "O!O!", &(AxisPy::Type), &axis, &(VectorPy::Type), &xdir)) { |
| 61 |
getCoordinateSystemPtr()->setAxes( |
| 62 |
*static_cast<AxisPy*>(axis)->getAxisPtr(), |
| 63 |
*static_cast<VectorPy*>(xdir)->getVectorPtr() |
| 64 |
); |
| 65 |
Py_Return; |
| 66 |
} |
| 67 |
|
| 68 |
PyErr_Clear(); |
| 69 |
if (PyArg_ParseTuple(args, "O!O!", &(VectorPy::Type), &axis, &(VectorPy::Type), &xdir)) { |
| 70 |
getCoordinateSystemPtr()->setAxes( |
| 71 |
*static_cast<VectorPy*>(axis)->getVectorPtr(), |
| 72 |
*static_cast<VectorPy*>(xdir)->getVectorPtr() |
| 73 |
); |
| 74 |
Py_Return; |
| 75 |
} |
| 76 |
|
| 77 |
PyErr_SetString(PyExc_TypeError, "Axis and Vector or Vector and Vector expected"); |
| 78 |
return nullptr; |
| 79 |
} |
| 80 |
|
| 81 |
PyObject* CoordinateSystemPy::displacement(PyObject* args) const |
| 82 |
{ |
| 83 |
PyObject* cs {}; |
| 84 |
if (!PyArg_ParseTuple(args, "O!", &(CoordinateSystemPy::Type), &cs)) { |
| 85 |
return nullptr; |
| 86 |
} |
| 87 |
Placement plm = getCoordinateSystemPtr()->displacement( |
| 88 |
*static_cast<CoordinateSystemPy*>(cs)->getCoordinateSystemPtr() |
| 89 |
); |
| 90 |
return new PlacementPy(new Placement(plm)); |
| 91 |
} |
| 92 |
|
| 93 |
PyObject* CoordinateSystemPy::transformTo(PyObject* args) |
| 94 |
{ |
| 95 |
PyObject* vecpy {}; |
| 96 |
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vecpy)) { |
| 97 |
return nullptr; |
| 98 |
} |
| 99 |
Vector3d vec = static_cast<VectorPy*>(vecpy)->value(); |
| 100 |
getCoordinateSystemPtr()->transformTo(vec); |
| 101 |
return new VectorPy(new Vector3d(vec)); |
| 102 |
} |
| 103 |
|
| 104 |
PyObject* CoordinateSystemPy::transform(PyObject* args) |
| 105 |
{ |
| 106 |
PyObject* plm {}; |
| 107 |
if (PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) { |
| 108 |
getCoordinateSystemPtr()->transform(*static_cast<PlacementPy*>(plm)->getPlacementPtr()); |
| 109 |
Py_Return; |
| 110 |
} |
| 111 |
|
| 112 |
PyErr_Clear(); |
| 113 |
if (PyArg_ParseTuple(args, "O!", &(RotationPy::Type), &plm)) { |
| 114 |
getCoordinateSystemPtr()->transform(*static_cast<RotationPy*>(plm)->getRotationPtr()); |
| 115 |
Py_Return; |
| 116 |
} |
| 117 |
|
| 118 |
PyErr_SetString(PyExc_TypeError, "Rotation or placement expected"); |
| 119 |
return nullptr; |
| 120 |
} |
| 121 |
|
| 122 |
PyObject* CoordinateSystemPy::setPlacement(PyObject* args) |
| 123 |
{ |
| 124 |
PyObject* plm {}; |
| 125 |
if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) { |
| 126 |
return nullptr; |
| 127 |
} |
| 128 |
getCoordinateSystemPtr()->setPlacement(*static_cast<PlacementPy*>(plm)->getPlacementPtr()); |
| 129 |
Py_Return; |
| 130 |
} |
| 131 |
|
| 132 |
Py::Object CoordinateSystemPy::getAxis() const |
| 133 |
{ |
| 134 |
const Axis& axis = getCoordinateSystemPtr()->getAxis(); |
| 135 |
return Py::asObject(new AxisPy(new Axis(axis))); |
| 136 |
} |
| 137 |
|
| 138 |
void CoordinateSystemPy::setAxis(Py::Object arg) |
| 139 |
{ |
| 140 |
if (PyObject_TypeCheck(arg.ptr(), &(AxisPy::Type))) { |
| 141 |
AxisPy* axis = static_cast<AxisPy*>(arg.ptr()); |
| 142 |
getCoordinateSystemPtr()->setAxis(*axis->getAxisPtr()); |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
throw Py::TypeError("not an Axis"); |
| 147 |
} |
| 148 |
|
| 149 |
Py::Object CoordinateSystemPy::getXDirection() const |
| 150 |
{ |
| 151 |
return Py::Vector(getCoordinateSystemPtr()->getXDirection()); // NOLINT |
| 152 |
} |
| 153 |
|
| 154 |
void CoordinateSystemPy::setXDirection(Py::Object arg) |
| 155 |
{ |
| 156 |
getCoordinateSystemPtr()->setXDirection(Py::Vector(arg).toVector()); |
| 157 |
} |
| 158 |
|
| 159 |
Py::Object CoordinateSystemPy::getYDirection() const |
| 160 |
{ |
| 161 |
return Py::Vector(getCoordinateSystemPtr()->getYDirection()); // NOLINT |
| 162 |
} |
| 163 |
|
| 164 |
void CoordinateSystemPy::setYDirection(Py::Object arg) |
| 165 |
{ |
| 166 |
getCoordinateSystemPtr()->setYDirection(Py::Vector(arg).toVector()); |
| 167 |
} |
| 168 |
|
| 169 |
Py::Object CoordinateSystemPy::getZDirection() const |
| 170 |
{ |
| 171 |
return Py::Vector(getCoordinateSystemPtr()->getZDirection()); // NOLINT |
| 172 |
} |
| 173 |
|
| 174 |
void CoordinateSystemPy::setZDirection(Py::Object arg) |
| 175 |
{ |
| 176 |
getCoordinateSystemPtr()->setZDirection(Py::Vector(arg).toVector()); |
| 177 |
} |
| 178 |
|
| 179 |
Py::Object CoordinateSystemPy::getPosition() const |
| 180 |
{ |
| 181 |
return Py::Vector(getCoordinateSystemPtr()->getPosition()); // NOLINT |
| 182 |
} |
| 183 |
|
| 184 |
void CoordinateSystemPy::setPosition(Py::Object arg) |
| 185 |
{ |
| 186 |
getCoordinateSystemPtr()->setPosition(Py::Vector(arg).toVector()); |
| 187 |
} |
| 188 |
|
| 189 |
PyObject* CoordinateSystemPy::getCustomAttributes(const char* /*attr*/) const |
| 190 |
{ |
| 191 |
return nullptr; |
| 192 |
} |
| 193 |
|
| 194 |
int CoordinateSystemPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) |
| 195 |
{ |
| 196 |
return 0; |
| 197 |
} |