1
/***************************************************************************
2
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> *
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., 51 Franklin Street, *
19
* Fifth Floor, Boston, MA 02110-1301, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
26
#include "CoordinateSystemPy.h"
27
#include "CoordinateSystemPy.cpp"
28
#include "GeometryPyCXX.h"
29
#include "PlacementPy.h"
35
// returns a string which represents the object e.g. when printed in python
36
std::string CoordinateSystemPy::representation() const
38
return {"<CoordinateSystem object>"};
42
CoordinateSystemPy::PyMake(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/)
44
// create a new instance of CoordinateSystemPy and the Twin object
45
return new CoordinateSystemPy(new CoordinateSystem);
49
int CoordinateSystemPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
54
PyObject* CoordinateSystemPy::setAxes(PyObject* args)
58
if (PyArg_ParseTuple(args, "O!O!", &(AxisPy::Type), &axis, &(VectorPy::Type), &xdir)) {
59
getCoordinateSystemPtr()->setAxes(*static_cast<AxisPy*>(axis)->getAxisPtr(),
60
*static_cast<VectorPy*>(xdir)->getVectorPtr());
65
if (PyArg_ParseTuple(args, "O!O!", &(VectorPy::Type), &axis, &(VectorPy::Type), &xdir)) {
66
getCoordinateSystemPtr()->setAxes(*static_cast<VectorPy*>(axis)->getVectorPtr(),
67
*static_cast<VectorPy*>(xdir)->getVectorPtr());
71
PyErr_SetString(PyExc_TypeError, "Axis and Vector or Vector and Vector expected");
75
PyObject* CoordinateSystemPy::displacement(PyObject* args)
78
if (!PyArg_ParseTuple(args, "O!", &(CoordinateSystemPy::Type), &cs)) {
81
Placement plm = getCoordinateSystemPtr()->displacement(
82
*static_cast<CoordinateSystemPy*>(cs)->getCoordinateSystemPtr());
83
return new PlacementPy(new Placement(plm));
86
PyObject* CoordinateSystemPy::transformTo(PyObject* args)
89
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vecpy)) {
92
Vector3d vec = static_cast<VectorPy*>(vecpy)->value();
93
getCoordinateSystemPtr()->transformTo(vec);
94
return new VectorPy(new Vector3d(vec));
97
PyObject* CoordinateSystemPy::transform(PyObject* args)
100
if (PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) {
101
getCoordinateSystemPtr()->transform(*static_cast<PlacementPy*>(plm)->getPlacementPtr());
106
if (PyArg_ParseTuple(args, "O!", &(RotationPy::Type), &plm)) {
107
getCoordinateSystemPtr()->transform(*static_cast<RotationPy*>(plm)->getRotationPtr());
111
PyErr_SetString(PyExc_TypeError, "Rotation or placement expected");
115
PyObject* CoordinateSystemPy::setPlacement(PyObject* args)
118
if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) {
121
getCoordinateSystemPtr()->setPlacement(*static_cast<PlacementPy*>(plm)->getPlacementPtr());
125
Py::Object CoordinateSystemPy::getAxis() const
127
const Axis& axis = getCoordinateSystemPtr()->getAxis();
128
return Py::asObject(new AxisPy(new Axis(axis)));
131
void CoordinateSystemPy::setAxis(Py::Object arg)
133
if (PyObject_TypeCheck(arg.ptr(), &(Base::AxisPy::Type))) {
134
AxisPy* axis = static_cast<AxisPy*>(arg.ptr());
135
getCoordinateSystemPtr()->setAxis(*axis->getAxisPtr());
139
throw Py::TypeError("not an Axis");
142
Py::Object CoordinateSystemPy::getXDirection() const
144
return Py::Vector(getCoordinateSystemPtr()->getXDirection()); // NOLINT
147
void CoordinateSystemPy::setXDirection(Py::Object arg)
149
getCoordinateSystemPtr()->setXDirection(Py::Vector(arg).toVector());
152
Py::Object CoordinateSystemPy::getYDirection() const
154
return Py::Vector(getCoordinateSystemPtr()->getYDirection()); // NOLINT
157
void CoordinateSystemPy::setYDirection(Py::Object arg)
159
getCoordinateSystemPtr()->setYDirection(Py::Vector(arg).toVector());
162
Py::Object CoordinateSystemPy::getZDirection() const
164
return Py::Vector(getCoordinateSystemPtr()->getZDirection()); // NOLINT
167
void CoordinateSystemPy::setZDirection(Py::Object arg)
169
getCoordinateSystemPtr()->setZDirection(Py::Vector(arg).toVector());
172
Py::Object CoordinateSystemPy::getPosition() const
174
return Py::Vector(getCoordinateSystemPtr()->getPosition()); // NOLINT
177
void CoordinateSystemPy::setPosition(Py::Object arg)
179
getCoordinateSystemPtr()->setPosition(Py::Vector(arg).toVector());
182
PyObject* CoordinateSystemPy::getCustomAttributes(const char* /*attr*/) const
187
int CoordinateSystemPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)