| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2011 Jürgen Riegel <[email protected]> * |
| 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., 59 Temple Place, * |
| 21 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 22 |
* * |
| 23 |
***************************************************************************/ |
| 24 |
|
| 25 |
#include "GeometryPyCXX.h" |
| 26 |
|
| 27 |
// generated out of Axis.pyi |
| 28 |
#include "AxisPy.h" |
| 29 |
#include "AxisPy.cpp" |
| 30 |
|
| 31 |
#include "PlacementPy.h" |
| 32 |
#include "VectorPy.h" |
| 33 |
|
| 34 |
using namespace Base; |
| 35 |
|
| 36 |
// returns a string which represents the object e.g. when printed in python |
| 37 |
std::string AxisPy::representation() const |
| 38 |
{ |
| 39 |
AxisPy::PointerType ptr = getAxisPtr(); |
| 40 |
std::stringstream str; |
| 41 |
str << "Axis [Base=("; |
| 42 |
str << ptr->getBase().x << "," << ptr->getBase().y << "," << ptr->getBase().z; |
| 43 |
str << "), Direction=("; |
| 44 |
str << ptr->getDirection().x << "," << ptr->getDirection().y << "," << ptr->getDirection().z |
| 45 |
<< ")]"; |
| 46 |
|
| 47 |
return str.str(); |
| 48 |
} |
| 49 |
|
| 50 |
PyObject* AxisPy::PyMake(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) |
| 51 |
{ |
| 52 |
// create a new instance of AxisPy and the Twin object |
| 53 |
return new AxisPy(new Axis); |
| 54 |
} |
| 55 |
|
| 56 |
// constructor method |
| 57 |
int AxisPy::PyInit(PyObject* args, PyObject* /*kwd*/) |
| 58 |
{ |
| 59 |
PyObject* o {}; |
| 60 |
if (PyArg_ParseTuple(args, "")) { |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
PyErr_Clear(); |
| 65 |
if (PyArg_ParseTuple(args, "O!", &(AxisPy::Type), &o)) { |
| 66 |
auto a = static_cast<AxisPy*>(o)->getAxisPtr(); |
| 67 |
*(getAxisPtr()) = *a; |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
PyErr_Clear(); |
| 72 |
PyObject* d {}; |
| 73 |
if (PyArg_ParseTuple(args, "O!O!", &(VectorPy::Type), &o, &(VectorPy::Type), &d)) { |
| 74 |
// NOTE: The first parameter defines the base (origin) and the second the direction. |
| 75 |
*getAxisPtr() = Axis(static_cast<VectorPy*>(o)->value(), static_cast<VectorPy*>(d)->value()); |
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
PyErr_SetString(PyExc_TypeError, "empty parameter list, axis or base and direction expected"); |
| 80 |
return -1; |
| 81 |
} |
| 82 |
|
| 83 |
PyObject* AxisPy::move(PyObject* args) |
| 84 |
{ |
| 85 |
PyObject* vec {}; |
| 86 |
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vec)) { |
| 87 |
return nullptr; |
| 88 |
} |
| 89 |
getAxisPtr()->move(static_cast<VectorPy*>(vec)->value()); |
| 90 |
Py_Return; |
| 91 |
} |
| 92 |
|
| 93 |
PyObject* AxisPy::multiply(PyObject* args) |
| 94 |
{ |
| 95 |
PyObject* plm {}; |
| 96 |
if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) { |
| 97 |
return nullptr; |
| 98 |
} |
| 99 |
Axis mult = (*getAxisPtr()) * (*static_cast<PlacementPy*>(plm)->getPlacementPtr()); |
| 100 |
return new AxisPy(new Axis(mult)); |
| 101 |
} |
| 102 |
|
| 103 |
PyObject* AxisPy::copy(PyObject* args) |
| 104 |
{ |
| 105 |
if (!PyArg_ParseTuple(args, "")) { |
| 106 |
return nullptr; |
| 107 |
} |
| 108 |
return new AxisPy(new Axis(*getAxisPtr())); |
| 109 |
} |
| 110 |
|
| 111 |
PyObject* AxisPy::reversed(PyObject* args) |
| 112 |
{ |
| 113 |
if (!PyArg_ParseTuple(args, "")) { |
| 114 |
return nullptr; |
| 115 |
} |
| 116 |
return new AxisPy(new Axis(getAxisPtr()->reversed())); |
| 117 |
} |
| 118 |
|
| 119 |
Py::Object AxisPy::getBase() const |
| 120 |
{ |
| 121 |
return Py::Vector(getAxisPtr()->getBase()); // NOLINT |
| 122 |
} |
| 123 |
|
| 124 |
void AxisPy::setBase(Py::Object arg) |
| 125 |
{ |
| 126 |
getAxisPtr()->setBase(Py::Vector(arg).toVector()); |
| 127 |
} |
| 128 |
|
| 129 |
Py::Object AxisPy::getDirection() const |
| 130 |
{ |
| 131 |
return Py::Vector(getAxisPtr()->getDirection()); // NOLINT |
| 132 |
} |
| 133 |
|
| 134 |
void AxisPy::setDirection(Py::Object arg) |
| 135 |
{ |
| 136 |
getAxisPtr()->setDirection(Py::Vector(arg).toVector()); |
| 137 |
} |
| 138 |
|
| 139 |
PyObject* AxisPy::getCustomAttributes(const char* /*attr*/) const |
| 140 |
{ |
| 141 |
return nullptr; |
| 142 |
} |
| 143 |
|
| 144 |
int AxisPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) |
| 145 |
{ |
| 146 |
return 0; |
| 147 |
} |