| 1115 | } |
| 1116 | |
| 1117 | DocumentObject* 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 | } |
no test coverage detected