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

Method getSubObject

src/App/DocumentObject.cpp:1117–1174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1115}
1116
1117DocumentObject* DocumentObject::getSubObject(const char* subname,
1118 PyObject** pyObj,
1119 Base::Matrix4D* mat,
1120 bool transform,
1121 int depth) const
1122{
1123 DocumentObject* ret = nullptr;
1124 auto exts = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
1125 for (auto ext : exts) {
1126 if (ext->extensionGetSubObject(ret, subname, pyObj, mat, transform, depth)) {
1127 return ret;
1128 }
1129 }
1130
1131 std::string name;
1132 const char* dot = nullptr;
1133 if (!subname || !(dot = strchr(subname, '.'))) {
1134 ret = const_cast<DocumentObject*>(this);
1135 }
1136 else if (subname[0] == '$') {
1137 name = std::string(subname + 1, dot);
1138 for (auto obj : getOutList()) {
1139 if (name == obj->Label.getValue()) {
1140 ret = obj;
1141 break;
1142 }
1143 }
1144 }
1145 else {
1146 name = std::string(subname, dot);
1147 const auto& outList = getOutList();
1148 if (outList.size() != _outListMap.size()) {
1149 _outListMap.clear();
1150 for (auto obj : outList) {
1151 _outListMap[obj->getDagKey()] = obj;
1152 }
1153 }
1154 auto it = _outListMap.find(name.c_str());
1155 if (it != _outListMap.end()) {
1156 ret = it->second;
1157 }
1158 }
1159
1160 // TODO: By right, normal object's placement does not transform its sub
1161 // objects (think of the claimed children of a Fusion). But I do think we
1162 // should change that.
1163 if (transform && mat) {
1164 auto pla = freecad_cast<PropertyPlacement*>(getPropertyByName("Placement"));
1165 if (pla) {
1166 *mat *= pla->getValue().toMatrix();
1167 }
1168 }
1169
1170 if (ret && dot) {
1171 return ret->getSubObject(dot + 1, pyObj, mat, true, depth + 1);
1172 }
1173 return ret;
1174}

Callers 2

getParentsMethod · 0.45
resolveRelativeLinkMethod · 0.45

Calls 11

getOutListFunction · 0.85
getPropertyByNameFunction · 0.85
getDagKeyMethod · 0.80
extensionGetSubObjectMethod · 0.45
getValueMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
findMethod · 0.45
c_strMethod · 0.45
endMethod · 0.45
toMatrixMethod · 0.45

Tested by

no test coverage detected