void PropertyLinkSubList::setPyObject(PyObject *value) { try { //try PropertyLinkSub syntax PropertyLinkSub dummy; dummy.setPyObject(value); this->setValue(dummy.getValue(), dummy.getSubValues()); } catch (Base::TypeError) { if (PyTuple_Check(value) || PyList_Check(value)) { Py::Sequence list(value); Py::Sequence::size_type size = list.size(); std::vector<DocumentObject*> values; values.reserve(size); std::vector<std::string> SubNames; SubNames.reserve(size); for (Py::Sequence::size_type i=0; i<size; i++) { Py::Object item = list[i]; if (item.isTuple()) { Py::Tuple tup(item); if (PyObject_TypeCheck(tup[0].ptr(), &(DocumentObjectPy::Type))){ if (tup[1].isString()) { DocumentObjectPy *pcObj; pcObj = static_cast<DocumentObjectPy*>(tup[0].ptr()); values.push_back(pcObj->getDocumentObjectPtr()); SubNames.push_back(Py::String(tup[1])); } else if (tup[1].isSequence()) { Py::Sequence list(tup[1]); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { SubNames.push_back(Py::String(*it)); } DocumentObjectPy *pcObj; pcObj = static_cast<DocumentObjectPy*>(tup[0].ptr()); values.insert(values.end(), list.size(), pcObj->getDocumentObjectPtr()); } } } else if (PyObject_TypeCheck(*item, &(DocumentObjectPy::Type))) { DocumentObjectPy *pcObj; pcObj = static_cast<DocumentObjectPy*>(*item); values.push_back(pcObj->getDocumentObjectPtr()); } else if (item.isString()) { SubNames.push_back(Py::String(item)); } } setValues(values,SubNames); } else { std::string error = std::string("type must be 'DocumentObject' or list of 'DocumentObject', not "); error += value->ob_type->tp_name; throw Base::TypeError(error); } } }
bool DocumentObject::testIfLinkDAGCompatible(PropertyLinkSub &linkTo) const { std::vector<App::DocumentObject*> linkTo_in_vector; linkTo_in_vector.reserve(1); linkTo_in_vector.push_back(linkTo.getValue()); return this->testIfLinkDAGCompatible(linkTo_in_vector); }