FreeCAD

Форк
0
/
SelectionObjectPyImp.cpp 
168 строк · 5.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2009 Jürgen Riegel <FreeCAD@juergen-riegel.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 <App/Document.h>
26
#include <App/DocumentObject.h>
27
#include <Base/GeometryPyCXX.h>
28

29
#include "Selection.h"
30
#include "SelectionObject.h"
31

32

33
// inclusion of the generated files (generated out of SelectionObjectPy.xml)
34
#include "SelectionObjectPy.h"
35
#include "SelectionObjectPy.cpp"
36

37

38
using namespace Gui;
39

40
// returns a string which represents the object e.g. when printed in python
41
std::string SelectionObjectPy::representation() const
42
{
43
    return "<SelectionObject>";
44
}
45

46
PyObject* SelectionObjectPy::remove(PyObject * args)
47
{
48
    if (!PyArg_ParseTuple(args, ""))
49
        return nullptr;
50
    Selection().rmvSelection(getSelectionObjectPtr()->getDocName(),
51
                             getSelectionObjectPtr()->getFeatName());
52
    Py_Return;
53
}
54

55
PyObject* SelectionObjectPy::isObjectTypeOf(PyObject * args)
56
{
57
    char* type;
58
    if (!PyArg_ParseTuple(args, "s", &type))
59
        return nullptr;
60
    Base::Type id = Base::Type::fromName(type);
61
    if (id.isBad()) {
62
        PyErr_SetString(PyExc_TypeError, "Not a valid type");
63
        return nullptr;
64
    }
65

66
    bool ok = getSelectionObjectPtr()->isObjectTypeOf(id);
67

68
    return Py_BuildValue("O", (ok ? Py_True : Py_False));
69
}
70

71
Py::String SelectionObjectPy::getObjectName() const
72
{
73
    return {getSelectionObjectPtr()->getFeatName()};
74
}
75

76
Py::Tuple SelectionObjectPy::getSubElementNames() const
77
{
78
    std::vector<std::string> objs = getSelectionObjectPtr()->getSubNames();
79

80
    Py::Tuple temp(objs.size());
81
    Py::sequence_index_type index = 0;
82
    for(const auto & obj : objs)
83
        temp.setItem(index++, Py::String(obj));
84

85
    return temp;
86
}
87

88
Py::String SelectionObjectPy::getFullName() const
89
{
90
    return {getSelectionObjectPtr()->getAsPropertyLinkSubString()};
91
}
92

93
Py::String SelectionObjectPy::getTypeName() const
94
{
95
    return {getSelectionObjectPtr()->getTypeName()};
96
}
97

98
Py::String SelectionObjectPy::getDocumentName() const
99
{
100
    return {getSelectionObjectPtr()->getDocName()};
101
}
102

103
Py::Object SelectionObjectPy::getDocument() const
104
{
105
    App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
106
    if (!obj)
107
        throw Py::RuntimeError("Cannot get document of deleted object");
108
    return Py::Object(obj->getDocument()->getPyObject(), true);
109
}
110

111
Py::Object SelectionObjectPy::getObject() const
112
{
113
    App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
114
    if (!obj)
115
        throw Py::RuntimeError("Object already deleted");
116
    return Py::Object(obj->getPyObject(), true);
117
}
118

119
Py::Tuple SelectionObjectPy::getSubObjects() const
120
{
121
    App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
122
    if (!obj)
123
        throw Py::RuntimeError("Cannot get sub-objects of deleted object");
124

125
    std::vector<PyObject *> subObjs;
126

127
    for(const auto &subname : getSelectionObjectPtr()->getSubNames()) {
128
        PyObject *pyObj=nullptr;
129
        Base::Matrix4D mat;
130
        obj->getSubObject(subname.c_str(),&pyObj,&mat);
131
        if(pyObj)
132
            subObjs.push_back(pyObj);
133
    }
134

135
    Py::Tuple temp(subObjs.size());
136
    Py::sequence_index_type index = 0;
137
    for(const auto & subObj : subObjs)
138
        temp.setItem(index++, Py::asObject(subObj));
139

140
    return temp;
141
}
142

143
Py::Boolean SelectionObjectPy::getHasSubObjects() const
144
{
145
    return {getSelectionObjectPtr()->hasSubNames()};
146
}
147

148
Py::Tuple SelectionObjectPy::getPickedPoints() const
149
{
150
    const std::vector<Base::Vector3d>& points = getSelectionObjectPtr()->getPickedPoints();
151

152
    Py::Tuple temp(points.size());
153
    Py::sequence_index_type index = 0;
154
    for(const auto & point : points)
155
        temp.setItem(index++, Py::Vector(point));
156

157
    return temp;
158
}
159

160
PyObject *SelectionObjectPy::getCustomAttributes(const char* /*attr*/) const
161
{
162
    return nullptr;
163
}
164

165
int SelectionObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
166
{
167
    return 0;
168
}
169

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

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

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

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