FreeCAD

Форк
0
/
CoordinateSystemPyImp.cpp 
190 строк · 6.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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., 51 Franklin Street,      *
19
 *   Fifth Floor, Boston, MA  02110-1301, USA                              *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#include "AxisPy.h"
26
#include "CoordinateSystemPy.h"
27
#include "CoordinateSystemPy.cpp"
28
#include "GeometryPyCXX.h"
29
#include "PlacementPy.h"
30
#include "VectorPy.h"
31

32

33
using namespace Base;
34

35
// returns a string which represents the object e.g. when printed in python
36
std::string CoordinateSystemPy::representation() const
37
{
38
    return {"<CoordinateSystem object>"};
39
}
40

41
PyObject*
42
CoordinateSystemPy::PyMake(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/)
43
{
44
    // create a new instance of CoordinateSystemPy and the Twin object
45
    return new CoordinateSystemPy(new CoordinateSystem);
46
}
47

48
// constructor method
49
int CoordinateSystemPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
50
{
51
    return 0;
52
}
53

54
PyObject* CoordinateSystemPy::setAxes(PyObject* args)
55
{
56
    PyObject* axis {};
57
    PyObject* xdir {};
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());
61
        Py_Return;
62
    }
63

64
    PyErr_Clear();
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());
68
        Py_Return;
69
    }
70

71
    PyErr_SetString(PyExc_TypeError, "Axis and Vector or Vector and Vector expected");
72
    return nullptr;
73
}
74

75
PyObject* CoordinateSystemPy::displacement(PyObject* args)
76
{
77
    PyObject* cs {};
78
    if (!PyArg_ParseTuple(args, "O!", &(CoordinateSystemPy::Type), &cs)) {
79
        return nullptr;
80
    }
81
    Placement plm = getCoordinateSystemPtr()->displacement(
82
        *static_cast<CoordinateSystemPy*>(cs)->getCoordinateSystemPtr());
83
    return new PlacementPy(new Placement(plm));
84
}
85

86
PyObject* CoordinateSystemPy::transformTo(PyObject* args)
87
{
88
    PyObject* vecpy {};
89
    if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vecpy)) {
90
        return nullptr;
91
    }
92
    Vector3d vec = static_cast<VectorPy*>(vecpy)->value();
93
    getCoordinateSystemPtr()->transformTo(vec);
94
    return new VectorPy(new Vector3d(vec));
95
}
96

97
PyObject* CoordinateSystemPy::transform(PyObject* args)
98
{
99
    PyObject* plm {};
100
    if (PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) {
101
        getCoordinateSystemPtr()->transform(*static_cast<PlacementPy*>(plm)->getPlacementPtr());
102
        Py_Return;
103
    }
104

105
    PyErr_Clear();
106
    if (PyArg_ParseTuple(args, "O!", &(RotationPy::Type), &plm)) {
107
        getCoordinateSystemPtr()->transform(*static_cast<RotationPy*>(plm)->getRotationPtr());
108
        Py_Return;
109
    }
110

111
    PyErr_SetString(PyExc_TypeError, "Rotation or placement expected");
112
    return nullptr;
113
}
114

115
PyObject* CoordinateSystemPy::setPlacement(PyObject* args)
116
{
117
    PyObject* plm {};
118
    if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) {
119
        return nullptr;
120
    }
121
    getCoordinateSystemPtr()->setPlacement(*static_cast<PlacementPy*>(plm)->getPlacementPtr());
122
    Py_Return;
123
}
124

125
Py::Object CoordinateSystemPy::getAxis() const
126
{
127
    const Axis& axis = getCoordinateSystemPtr()->getAxis();
128
    return Py::asObject(new AxisPy(new Axis(axis)));
129
}
130

131
void CoordinateSystemPy::setAxis(Py::Object arg)
132
{
133
    if (PyObject_TypeCheck(arg.ptr(), &(Base::AxisPy::Type))) {
134
        AxisPy* axis = static_cast<AxisPy*>(arg.ptr());
135
        getCoordinateSystemPtr()->setAxis(*axis->getAxisPtr());
136
        return;
137
    }
138

139
    throw Py::TypeError("not an Axis");
140
}
141

142
Py::Object CoordinateSystemPy::getXDirection() const
143
{
144
    return Py::Vector(getCoordinateSystemPtr()->getXDirection());  // NOLINT
145
}
146

147
void CoordinateSystemPy::setXDirection(Py::Object arg)
148
{
149
    getCoordinateSystemPtr()->setXDirection(Py::Vector(arg).toVector());
150
}
151

152
Py::Object CoordinateSystemPy::getYDirection() const
153
{
154
    return Py::Vector(getCoordinateSystemPtr()->getYDirection());  // NOLINT
155
}
156

157
void CoordinateSystemPy::setYDirection(Py::Object arg)
158
{
159
    getCoordinateSystemPtr()->setYDirection(Py::Vector(arg).toVector());
160
}
161

162
Py::Object CoordinateSystemPy::getZDirection() const
163
{
164
    return Py::Vector(getCoordinateSystemPtr()->getZDirection());  // NOLINT
165
}
166

167
void CoordinateSystemPy::setZDirection(Py::Object arg)
168
{
169
    getCoordinateSystemPtr()->setZDirection(Py::Vector(arg).toVector());
170
}
171

172
Py::Object CoordinateSystemPy::getPosition() const
173
{
174
    return Py::Vector(getCoordinateSystemPtr()->getPosition());  // NOLINT
175
}
176

177
void CoordinateSystemPy::setPosition(Py::Object arg)
178
{
179
    getCoordinateSystemPtr()->setPosition(Py::Vector(arg).toVector());
180
}
181

182
PyObject* CoordinateSystemPy::getCustomAttributes(const char* /*attr*/) const
183
{
184
    return nullptr;
185
}
186

187
int CoordinateSystemPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
188
{
189
    return 0;
190
}
191

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.