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

Method addProperty

src/App/DocumentPyImp.cpp:43–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42
43PyObject* DocumentPy::addProperty(PyObject* args, PyObject* kwd)
44{
45 char* sType {nullptr};
46 char* sName {nullptr};
47 char* sGroup {nullptr};
48 char* sDoc {nullptr};
49 short attr = 0;
50 std::string sDocStr;
51 PyObject *ro = Py_False, *hd = Py_False, *lk = Py_False;
52 PyObject* enumVals = nullptr;
53 static const std::array<const char*, 10> kwlist {"type",
54 "name",
55 "group",
56 "doc",
57 "attr",
58 "read_only",
59 "hidden",
60 "locked",
61 "enum_vals",
62 nullptr};
63 if (!Base::Wrapped_ParseTupleAndKeywords(args,
64 kwd,
65 "ss|sethO!O!O!O",
66 kwlist,
67 &sType,
68 &sName,
69 &sGroup,
70 "utf-8",
71 &sDoc,
72 &attr,
73 &PyBool_Type,
74 &ro,
75 &PyBool_Type,
76 &hd,
77 &PyBool_Type,
78 &lk,
79 &enumVals)) {
80 return nullptr;
81 }
82
83 if (sDoc) {
84 sDocStr = sDoc;
85 PyMem_Free(sDoc);
86 }
87
88 Property* prop = getDocumentPtr()->addDynamicProperty(sType,
89 sName,
90 sGroup,
91 sDocStr.c_str(),
92 attr,
93 Base::asBoolean(ro),
94 Base::asBoolean(hd));
95 prop->setStatus(Property::LockDynamic, Base::asBoolean(lk));
96
97 // enum support
98 auto* propEnum = dynamic_cast<App::PropertyEnumeration*>(prop);
99 if (propEnum && enumVals) {
100 propEnum->setPyObject(enumVals);

Callers

nothing calls this directly

Calls 7

asBooleanFunction · 0.85
new_reference_toFunction · 0.85
addDynamicPropertyMethod · 0.45
c_strMethod · 0.45
setStatusMethod · 0.45
setPyObjectMethod · 0.45

Tested by

no test coverage detected