MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getSubObject

Method getSubObject

src/App/FeaturePython.cpp:264–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264bool FeaturePythonImp::getSubObject(DocumentObject*& ret,
265 const char* subname,
266 PyObject** pyObj,
267 Base::Matrix4D* _mat,
268 bool transform,
269 int depth) const
270{
271 FC_PY_CALL_CHECK(getSubObject);
272 Base::PyGILStateLocker lock;
273 try {
274 Py::Tuple args(6);
275 args.setItem(0, Py::Object(object->getPyObject(), true));
276 if (!subname) {
277 subname = "";
278 }
279 args.setItem(1, Py::String(subname));
280 args.setItem(2, Py::Long(pyObj ? 2 : 1));
281 Base::MatrixPy* pyMat = new Base::MatrixPy(new Base::Matrix4D);
282 if (_mat) {
283 *pyMat->getMatrixPtr() = *_mat;
284 }
285 args.setItem(3, Py::asObject(pyMat));
286 args.setItem(4, Py::Boolean(transform));
287 args.setItem(5, Py::Long(depth));
288
289 Py::Object res(Base::pyCall(py_getSubObject.ptr(), args.ptr()));
290 if (res.isNone()) {
291 ret = nullptr;
292 return true;
293 }
294 if (!res.isTrue()) {
295 return false;
296 }
297 if (!res.isSequence()) {
298 throw Py::TypeError("getSubObject expects return type of tuple");
299 }
300 Py::Sequence seq(res);
301 if (seq.length() < 2
302 || (!seq.getItem(0).isNone()
303 && !PyObject_TypeCheck(seq.getItem(0).ptr(), &DocumentObjectPy::Type))
304 || !PyObject_TypeCheck(seq.getItem(1).ptr(), &Base::MatrixPy::Type)) {
305 throw Py::TypeError("getSubObject expects return type of (obj,matrix,pyobj)");
306 }
307 if (_mat) {
308 *_mat = *static_cast<Base::MatrixPy*>(seq.getItem(1).ptr())->getMatrixPtr();
309 }
310 if (pyObj) {
311 if (seq.length() > 2) {
312 *pyObj = Py::new_reference_to(seq.getItem(2));
313 }
314 else {
315 *pyObj = Py::new_reference_to(Py::None());
316 }
317 }
318 if (seq.getItem(0).isNone()) {
319 ret = nullptr;
320 }
321 else {

Callers 15

getMeasureHandlerMethod · 0.45
getElementIndexMethod · 0.45
extensionGetSubObjectMethod · 0.45
getTrueLinkedObjectMethod · 0.45
extensionGetSubObjectMethod · 0.45
_removeObjectMethod · 0.45
extensionGetSubObjectMethod · 0.45
extensionGetSubObjectMethod · 0.45
getLinksToMethod · 0.45
resolvePropertyMethod · 0.45
accessMethod · 0.45
resolveElementMethod · 0.45

Calls 10

pyCallFunction · 0.85
new_reference_toFunction · 0.85
isNoneMethod · 0.80
ObjectClass · 0.70
StringClass · 0.70
getPyObjectMethod · 0.45
ptrMethod · 0.45
lengthMethod · 0.45
getItemMethod · 0.45
reportExceptionMethod · 0.45

Tested by

no test coverage detected