23
#include "PreCompiled.h"
25
#include <App/Document.h>
26
#include <App/DocumentObject.h>
27
#include <Base/GeometryPyCXX.h>
30
#include "SelectionObject.h"
34
#include "SelectionObjectPy.h"
35
#include "SelectionObjectPy.cpp"
41
std::string SelectionObjectPy::representation() const
43
return "<SelectionObject>";
46
PyObject* SelectionObjectPy::remove(PyObject * args)
48
if (!PyArg_ParseTuple(args, ""))
50
Selection().rmvSelection(getSelectionObjectPtr()->getDocName(),
51
getSelectionObjectPtr()->getFeatName());
55
PyObject* SelectionObjectPy::isObjectTypeOf(PyObject * args)
58
if (!PyArg_ParseTuple(args, "s", &type))
60
Base::Type id = Base::Type::fromName(type);
62
PyErr_SetString(PyExc_TypeError, "Not a valid type");
66
bool ok = getSelectionObjectPtr()->isObjectTypeOf(id);
68
return Py_BuildValue("O", (ok ? Py_True : Py_False));
71
Py::String SelectionObjectPy::getObjectName() const
73
return {getSelectionObjectPtr()->getFeatName()};
76
Py::Tuple SelectionObjectPy::getSubElementNames() const
78
std::vector<std::string> objs = getSelectionObjectPtr()->getSubNames();
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));
88
Py::String SelectionObjectPy::getFullName() const
90
return {getSelectionObjectPtr()->getAsPropertyLinkSubString()};
93
Py::String SelectionObjectPy::getTypeName() const
95
return {getSelectionObjectPtr()->getTypeName()};
98
Py::String SelectionObjectPy::getDocumentName() const
100
return {getSelectionObjectPtr()->getDocName()};
103
Py::Object SelectionObjectPy::getDocument() const
105
App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
107
throw Py::RuntimeError("Cannot get document of deleted object");
108
return Py::Object(obj->getDocument()->getPyObject(), true);
111
Py::Object SelectionObjectPy::getObject() const
113
App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
115
throw Py::RuntimeError("Object already deleted");
116
return Py::Object(obj->getPyObject(), true);
119
Py::Tuple SelectionObjectPy::getSubObjects() const
121
App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
123
throw Py::RuntimeError("Cannot get sub-objects of deleted object");
125
std::vector<PyObject *> subObjs;
127
for(const auto &subname : getSelectionObjectPtr()->getSubNames()) {
128
PyObject *pyObj=nullptr;
130
obj->getSubObject(subname.c_str(),&pyObj,&mat);
132
subObjs.push_back(pyObj);
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));
143
Py::Boolean SelectionObjectPy::getHasSubObjects() const
145
return {getSelectionObjectPtr()->hasSubNames()};
148
Py::Tuple SelectionObjectPy::getPickedPoints() const
150
const std::vector<Base::Vector3d>& points = getSelectionObjectPtr()->getPickedPoints();
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));
160
PyObject *SelectionObjectPy::getCustomAttributes(const char* ) const
165
int SelectionObjectPy::setCustomAttributes(const char* , PyObject* )