FreeCAD

Форк
0
/
AxisPyImp.cpp 
149 строк · 4.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de>              *
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 "PreCompiled.h"
24

25
#include "GeometryPyCXX.h"
26

27
// inclusion of the generated files (generated out of AxisPy.xml)
28
#include "AxisPy.h"
29
#include "AxisPy.cpp"
30

31
#include "VectorPy.h"
32
#include "PlacementPy.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!", &(Base::AxisPy::Type), &o)) {
66
        Base::Axis* a = static_cast<Base::AxisPy*>(o)->getAxisPtr();
67
        *(getAxisPtr()) = *a;
68
        return 0;
69
    }
70

71
    PyErr_Clear();
72
    PyObject* d {};
73
    if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type), &o, &(Base::VectorPy::Type), &d)) {
74
        // NOTE: The first parameter defines the base (origin) and the second the direction.
75
        *getAxisPtr() = Base::Axis(static_cast<Base::VectorPy*>(o)->value(),
76
                                   static_cast<Base::VectorPy*>(d)->value());
77
        return 0;
78
    }
79

80
    PyErr_SetString(PyExc_TypeError, "empty parameter list, axis or base and direction expected");
81
    return -1;
82
}
83

84
PyObject* AxisPy::move(PyObject* args)
85
{
86
    PyObject* vec {};
87
    if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vec)) {
88
        return nullptr;
89
    }
90
    getAxisPtr()->move(static_cast<VectorPy*>(vec)->value());
91
    Py_Return;
92
}
93

94
PyObject* AxisPy::multiply(PyObject* args)
95
{
96
    PyObject* plm {};
97
    if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm)) {
98
        return nullptr;
99
    }
100
    Axis mult = (*getAxisPtr()) * (*static_cast<PlacementPy*>(plm)->getPlacementPtr());
101
    return new AxisPy(new Axis(mult));
102
}
103

104
PyObject* AxisPy::copy(PyObject* args)
105
{
106
    if (!PyArg_ParseTuple(args, "")) {
107
        return nullptr;
108
    }
109
    return new AxisPy(new Axis(*getAxisPtr()));
110
}
111

112
PyObject* AxisPy::reversed(PyObject* args)
113
{
114
    if (!PyArg_ParseTuple(args, "")) {
115
        return nullptr;
116
    }
117
    Base::Axis a = getAxisPtr()->reversed();
118
    return new AxisPy(new Axis(a));
119
}
120

121
Py::Object AxisPy::getBase() const
122
{
123
    return Py::Vector(getAxisPtr()->getBase());  // NOLINT
124
}
125

126
void AxisPy::setBase(Py::Object arg)
127
{
128
    getAxisPtr()->setBase(Py::Vector(arg).toVector());
129
}
130

131
Py::Object AxisPy::getDirection() const
132
{
133
    return Py::Vector(getAxisPtr()->getDirection());  // NOLINT
134
}
135

136
void AxisPy::setDirection(Py::Object arg)
137
{
138
    getAxisPtr()->setDirection(Py::Vector(arg).toVector());
139
}
140

141
PyObject* AxisPy::getCustomAttributes(const char* /*attr*/) const
142
{
143
    return nullptr;
144
}
145

146
int AxisPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
147
{
148
    return 0;
149
}
150

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

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

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

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