Debian Codegraph @

src/Gui/ViewProviderDocumentObjectPyImp.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2008 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
24 #include <sstream>
25
26
27 #include <App/DocumentObjectPy.h>
28 #include "Document.h"
29
30 // inclusion of the generated files (generated out of ViewProviderDocumentObjectPy.pyi)
31 #include "ViewProviderDocumentObjectPy.h"
32 #include "ViewProviderDocumentObjectPy.cpp"
33
34
35 using namespace Gui;
36
37 // returns a string which represents the object e.g. when printed in python
38 std::string ViewProviderDocumentObjectPy::representation() const
39 {
40 std::stringstream str;
41 str << "<View provider object at " << getViewProviderDocumentObjectPtr() << ">";
42
43 return str.str();
44 }
45
46 PyObject* ViewProviderDocumentObjectPy::update(PyObject* args)
47 {
48 if (!PyArg_ParseTuple(args, "")) {
49 return nullptr;
50 }
51 PY_TRY
52 {
53 getViewProviderDocumentObjectPtr()->updateView();
54 Py_Return;
55 }
56 PY_CATCH;
57 }
58
59 Py::Object ViewProviderDocumentObjectPy::getObject() const
60 {
61 App::DocumentObject* obj = getViewProviderDocumentObjectPtr()->getObject();
62 return Py::Object(obj->getPyObject(), true); // do not inc'ref twice
63 }
64
65 void ViewProviderDocumentObjectPy::setObject(Py::Object pyobj)
66 {
67 if (!PyObject_TypeCheck(*pyobj, &App::DocumentObjectPy::Type)) {
68 throw Py::TypeError("Expect document object");
69 }
70 App::DocumentObject* obj = getViewProviderDocumentObjectPtr()->getObject();
71 if (obj) {
72 throw Py::RuntimeError("View object already attached");
73 }
74 getViewProviderDocumentObjectPtr()->attach(
75 static_cast<App::DocumentObjectPy*>(*pyobj)->getDocumentObjectPtr()
76 );
77 }
78
79 Py::Boolean ViewProviderDocumentObjectPy::getForceUpdate() const
80 {
81 return {getViewProviderDocumentObjectPtr()->isUpdateForced()};
82 }
83
84 void ViewProviderDocumentObjectPy::setForceUpdate(Py::Boolean arg)
85 {
86 getViewProviderDocumentObjectPtr()->forceUpdate(arg);
87 }
88
89 Py::Object ViewProviderDocumentObjectPy::getDocument() const
90 {
91 Document* doc = getViewProviderDocumentObjectPtr()->getDocument();
92 return Py::asObject(doc->getPyObject()); // do not inc'ref twice
93 }
94
95 PyObject* ViewProviderDocumentObjectPy::getCustomAttributes(const char* /*attr*/) const
96 {
97 return nullptr;
98 }
99
100 int ViewProviderDocumentObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
101 {
102 return 0;
103 }