FreeCAD

Форк
0
/
AxisOriginPyImp.cpp 
194 строки · 5.9 Кб
1
/****************************************************************************
2
 *   Copyright (c) 2019 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
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
#ifndef _PreComp_
25
# include <Inventor/nodes/SoGroup.h>
26
# include <Inventor/details/SoDetail.h>
27
# include <Inventor/SoFullPath.h>
28
#endif
29

30
#include "AxisOriginPy.h"
31
#include "AxisOriginPy.cpp"
32
#include <Base/Interpreter.h>
33

34
using namespace Gui;
35

36
PyObject *AxisOriginPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
37
{
38
    return new AxisOriginPy(new AxisOrigin);
39
}
40

41
int AxisOriginPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
42
{
43
    return 0;
44
}
45

46

47
// returns a string which represent the object e.g. when printed in python
48
std::string AxisOriginPy::representation() const
49
{
50
    return "<AxisOrigin>";
51
}
52

53
PyObject* AxisOriginPy::getElementPicked(PyObject* args)
54
{
55
    PyObject *obj;
56
    if (!PyArg_ParseTuple(args, "O", &obj))
57
        return nullptr;
58

59
    void *ptr = nullptr;
60
    Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPickedPoint", obj, &ptr, 0);
61
    if (!ptr) {
62
        PyErr_SetString(PyExc_TypeError, "'pickedPoint' must be a coin.SoPickedPoint");
63
        return nullptr;
64
    }
65

66
    auto pp = static_cast<SoPickedPoint*>(ptr);
67
    std::string name;
68
    if (!getAxisOriginPtr()->getElementPicked(pp,name))
69
        Py_Return;
70

71
    return Py::new_reference_to(Py::String(name));
72
}
73

74
PyObject* AxisOriginPy::getDetailPath(PyObject* args)
75
{
76
    const char *sub;
77
    PyObject *path;
78
    if (!PyArg_ParseTuple(args, "sO", &sub,&path))
79
        return nullptr;
80

81
    void *ptr = nullptr;
82
    Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPath", path, &ptr, 0);
83
    if (!ptr) {
84
        PyErr_SetString(PyExc_TypeError, "'path' must be a coin.SoPath");
85
        return nullptr;
86
    }
87

88
    auto pPath = static_cast<SoPath*>(ptr);
89
    SoDetail *det = nullptr;
90
    if (!getAxisOriginPtr()->getDetailPath(sub, static_cast<SoFullPath*>(pPath), det)) {
91
        delete det;
92
        Py_Return;
93
    }
94
    if (!det)
95
        Py_Return;
96

97
    return Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoDetail", static_cast<void*>(det), 0);
98
}
99

100
Py::Float AxisOriginPy::getAxisLength() const
101
{
102
    return Py::Float(getAxisOriginPtr()->getAxisLength());
103
}
104

105
void AxisOriginPy::setAxisLength(Py::Float size)
106
{
107
    getAxisOriginPtr()->setAxisLength(size);
108
}
109

110
Py::Float AxisOriginPy::getLineWidth() const
111
{
112
    return Py::Float(getAxisOriginPtr()->getLineWidth());
113
}
114

115
void AxisOriginPy::setLineWidth(Py::Float size)
116
{
117
    getAxisOriginPtr()->setLineWidth(size);
118
}
119

120
Py::Float AxisOriginPy::getPointSize() const
121
{
122
    return Py::Float(getAxisOriginPtr()->getPointSize());
123
}
124

125
void AxisOriginPy::setPointSize(Py::Float size)
126
{
127
    getAxisOriginPtr()->setPointSize(size);
128
}
129

130
Py::Float AxisOriginPy::getScale() const
131
{
132
    return Py::Float(getAxisOriginPtr()->getScale());
133
}
134

135
void AxisOriginPy::setScale(Py::Float size)
136
{
137
    getAxisOriginPtr()->setScale(size);
138
}
139

140
Py::Tuple AxisOriginPy::getPlane() const
141
{
142
    auto info = getAxisOriginPtr()->getPlane();
143
    Py::Tuple ret(2);
144
    ret.setItem(0,Py::Float(info.first));
145
    ret.setItem(1,Py::Float(info.second));
146

147
    return ret;
148
}
149

150
void AxisOriginPy::setPlane(Py::Tuple tuple)
151
{
152
    float s,d;
153
    if (!PyArg_ParseTuple(*tuple, "ff",&s,&d))
154
        throw Py::Exception();
155

156
    getAxisOriginPtr()->setPlane(s,d);
157
}
158

159
Py::Dict AxisOriginPy::getLabels() const
160
{
161
    Py::Dict dict;
162
    for (auto &v : getAxisOriginPtr()->getLabels())
163
        dict.setItem(Py::String(v.first),Py::String(v.second));
164

165
    return dict;
166
}
167

168
void AxisOriginPy::setLabels(Py::Dict dict)
169
{
170
    std::map<std::string,std::string> labels;
171
    for (auto it=dict.begin(); it!=dict.end(); ++it) {
172
        const auto &value = *it;
173
        labels[value.first.as_string()] = Py::Object(value.second).as_string();
174
    }
175
    getAxisOriginPtr()->setLabels(labels);
176
}
177

178
Py::Object AxisOriginPy::getNode() const
179
{
180
    SoGroup* node = getAxisOriginPtr()->getNode();
181
    PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","SoGroup *", node, 1);
182
    node->ref();
183
    return Py::Object(Ptr, true);
184
}
185

186
PyObject *AxisOriginPy::getCustomAttributes(const char* /*attr*/) const
187
{
188
    return nullptr;
189
}
190

191
int AxisOriginPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
192
{
193
    return 0;
194
}
195

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

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

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

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