| 211 | } |
| 212 | |
| 213 | void parseLink(LinkBaseExtension* ext, int index, PyObject* value) |
| 214 | { |
| 215 | App::DocumentObject* obj = nullptr; |
| 216 | PropertyStringList subs; |
| 217 | PropertyString sub; |
| 218 | if (value != Py_None) { |
| 219 | if (PyObject_TypeCheck(value, &DocumentObjectPy::Type)) { |
| 220 | obj = static_cast<DocumentObjectPy*>(value)->getDocumentObjectPtr(); |
| 221 | } |
| 222 | else if (!PySequence_Check(value)) { |
| 223 | throw Base::TypeError("Expects type of DocumentObject or sequence"); |
| 224 | } |
| 225 | else { |
| 226 | Py::Sequence seq(value); |
| 227 | if (seq[0].ptr() != Py_None) { |
| 228 | if (!PyObject_TypeCheck(seq[0].ptr(), &DocumentObjectPy::Type)) { |
| 229 | throw Base::TypeError( |
| 230 | "Expects the first argument to be DocumentObject in sequence"); |
| 231 | } |
| 232 | obj = static_cast<DocumentObjectPy*>(seq[0].ptr())->getDocumentObjectPtr(); |
| 233 | if (seq.size() > 1) { |
| 234 | sub.setPyObject(seq[1].ptr()); |
| 235 | if (seq.size() > 2) { |
| 236 | subs.setPyObject(seq[2].ptr()); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | ext->setLink(index, obj, sub.getValue(), subs.getValue()); |
| 243 | } |
| 244 | |
| 245 | PyObject* LinkBaseExtensionPy::setLink(PyObject* _args) |
| 246 | { |