FreeCAD

Форк
0
/
ViewProviderMeshPyImp.cpp 
153 строки · 4.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2018 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
#ifndef _PreComp_
25
#include <sstream>
26
#endif
27

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

33

34
using namespace MeshGui;
35

36
// returns a string which represents the object e.g. when printed in python
37
std::string ViewProviderMeshPy::representation() const
38
{
39
    std::stringstream str;
40
    str << "<View provider object at " << getViewProviderDocumentObjectPtr() << ">";
41

42
    return str.str();
43
}
44

45
PyObject* ViewProviderMeshPy::setSelection(PyObject* args)
46
{
47
    PyObject* obj {};
48
    if (!PyArg_ParseTuple(args, "O", &obj)) {
49
        return nullptr;
50
    }
51

52
    Py::Sequence list(obj);
53
    std::vector<Mesh::FacetIndex> selection;
54
    selection.reserve(list.size());
55
    for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
56
        Py::Long index(*it);
57
        Mesh::FacetIndex value = static_cast<Mesh::FacetIndex>(index);
58
        selection.push_back(value);
59
    }
60

61
    ViewProviderMesh* vp = getViewProviderMeshPtr();
62
    vp->setSelection(selection);
63
    Py_Return;
64
}
65

66
PyObject* ViewProviderMeshPy::addSelection(PyObject* args)
67
{
68
    PyObject* obj {};
69
    if (!PyArg_ParseTuple(args, "O", &obj)) {
70
        return nullptr;
71
    }
72

73
    Py::Sequence list(obj);
74
    std::vector<Mesh::FacetIndex> selection;
75
    selection.reserve(list.size());
76
    for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
77
        Py::Long index(*it);
78
        Mesh::FacetIndex value = static_cast<Mesh::FacetIndex>(index);
79
        selection.push_back(value);
80
    }
81

82
    ViewProviderMesh* vp = getViewProviderMeshPtr();
83
    vp->addSelection(selection);
84
    Py_Return;
85
}
86

87
PyObject* ViewProviderMeshPy::removeSelection(PyObject* args)
88
{
89
    PyObject* obj {};
90
    if (!PyArg_ParseTuple(args, "O", &obj)) {
91
        return nullptr;
92
    }
93

94
    Py::Sequence list(obj);
95
    std::vector<Mesh::FacetIndex> selection;
96
    selection.reserve(list.size());
97
    for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
98
        Py::Long index(*it);
99
        Mesh::FacetIndex value = static_cast<Mesh::FacetIndex>(index);
100
        selection.push_back(value);
101
    }
102

103
    ViewProviderMesh* vp = getViewProviderMeshPtr();
104
    vp->removeSelection(selection);
105
    Py_Return;
106
}
107

108
PyObject* ViewProviderMeshPy::invertSelection(PyObject* args)
109
{
110
    if (!PyArg_ParseTuple(args, "")) {
111
        return nullptr;
112
    }
113

114
    ViewProviderMesh* vp = getViewProviderMeshPtr();
115
    vp->invertSelection();
116
    Py_Return;
117
}
118

119
PyObject* ViewProviderMeshPy::clearSelection(PyObject* args)
120
{
121
    if (!PyArg_ParseTuple(args, "")) {
122
        return nullptr;
123
    }
124

125
    ViewProviderMesh* vp = getViewProviderMeshPtr();
126
    vp->clearSelection();
127
    Py_Return;
128
}
129

130
PyObject* ViewProviderMeshPy::highlightSegments(PyObject* args)
131
{
132
    PyObject* list {};
133
    if (!PyArg_ParseTuple(args, "O", &list)) {
134
        return nullptr;
135
    }
136

137
    App::PropertyColorList colors;
138
    colors.setPyObject(list);
139

140
    ViewProviderMesh* vp = getViewProviderMeshPtr();
141
    vp->highlightSegments(colors.getValues());
142
    Py_Return;
143
}
144

145
PyObject* ViewProviderMeshPy::getCustomAttributes(const char* /*attr*/) const
146
{
147
    return nullptr;
148
}
149

150
int ViewProviderMeshPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
151
{
152
    return 0;
153
}
154

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

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

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

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