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

Method evalExpression

src/App/DocumentObjectPyImp.cpp:452–482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

450}
451
452PyObject* DocumentObjectPy::evalExpression(PyObject* self, PyObject* args)
453{
454 const char* expr;
455 if (!PyArg_ParseTuple(args, "s", &expr)) {
456 return nullptr;
457 }
458
459 // HINT:
460 // The standard behaviour of Python for class methods is to always pass the class
461 // object as first argument.
462 // For FreeCAD-specific types the behaviour is a bit different:
463 // When calling this method for an instance then this is passed as first argument
464 // and otherwise the class object is passed.
465 // This behaviour is achieved by the function _getattr() that passed 'this' to
466 // PyCFunction_New().
467 //
468 // evalExpression() is a class method and thus 'self' can either be an instance of
469 // DocumentObjectPy or a type object.
470 App::DocumentObject* obj = nullptr;
471 if (self && PyObject_TypeCheck(self, &DocumentObjectPy::Type)) {
472 obj = static_cast<DocumentObjectPy*>(self)->getDocumentObjectPtr();
473 }
474
475 PY_TRY
476 {
477 std::shared_ptr<Expression> shared_expr(Expression::parse(obj, expr));
478 if (shared_expr) {
479 return Py::new_reference_to(shared_expr->getPyValue());
480 }
481 Py_Return;
482 }
483 PY_CATCH
484}
485

Callers 5

__init__Method · 0.80
setupUiMethod · 0.80
updateInputFieldFunction · 0.80
updateWidgetMethod · 0.80
testExpressionMethod · 0.80

Calls 3

new_reference_toFunction · 0.85
parseFunction · 0.50
getPyValueMethod · 0.45

Tested by

no test coverage detected