FreeCAD

Форк
0
/
PartFeaturePyImp.cpp 
91 строка · 3.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2007 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., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#include <Base/PyWrapParseTupleAndKeywords.h>
26

27
#include "PartFeature.h"
28

29
// inclusion of the generated files (generated out of PartFeaturePy.xml)
30
#include "PartFeaturePy.h"
31
#include "PartFeaturePy.cpp"
32

33

34
using namespace Part;
35

36
// returns a string which represent the object e.g. when printed in python
37
std::string PartFeaturePy::representation() const
38
{
39
    return {"<Part::PartFeature>"};
40
}
41

42
PyObject *PartFeaturePy::getElementHistory(PyObject *args, PyObject *kwds) {
43
    const char *name;
44
    PyObject *recursive = Py_True;
45
    PyObject *sameType = Py_False;
46
    PyObject *showName = Py_False;
47

48
    static const std::array<const char *, 5> kwlist{"elementName", "recursive", "sameType", "showName", nullptr};
49
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "s|OOO", kwlist, &name, &recursive, &sameType, &showName)) {
50
        return {};
51
    }
52

53
    auto feature = getFeaturePtr();
54
    Py::List list;
55
    bool showObjName = PyObject_IsTrue(showName);
56
    PY_TRY {
57
        std::string tmp;
58
        for (auto &history: Feature::getElementHistory(feature, name,
59
                                                       PyObject_IsTrue(recursive), PyObject_IsTrue(sameType))) {
60
            Py::Tuple ret(3);
61
            if (history.obj) {
62
                if (showObjName) {
63
                    ret.setItem(0, Py::TupleN(Py::String(history.obj->getFullName()),
64
                                              Py::String(history.obj->Label.getValue())));
65
                } else
66
                    ret.setItem(0, Py::Object(history.obj->getPyObject(), true));
67
            } else
68
                ret.setItem(0, Py::Int(history.tag));
69
            tmp.clear();
70
            ret.setItem(1, Py::String(history.element.appendToBuffer(tmp)));
71
            Py::List intermedates;
72
            for (auto &h: history.intermediates) {
73
                tmp.clear();
74
                intermedates.append(Py::String(h.appendToBuffer(tmp)));
75
            }
76
            ret.setItem(2, intermedates);
77
            list.append(ret);
78
        }
79
        return Py::new_reference_to(list);
80
    } PY_CATCH;
81
}
82

83
PyObject *PartFeaturePy::getCustomAttributes(const char* ) const
84
{
85
    return nullptr;
86
}
87

88
int PartFeaturePy::setCustomAttributes(const char* , PyObject *)
89
{
90
    return 0;
91
}
92

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

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

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

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