void PropertyLink::Restore(Base::XMLReader &reader) { // read my element reader.readElement("Link"); // get the value of my attribute std::string name = reader.getAttribute("value"); // Property not in a DocumentObject! assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) ); if (name != "") { DocumentObject* parent = static_cast<DocumentObject*>(getContainer()); App::Document* document = parent->getDocument(); DocumentObject* object = document ? document->getObject(name.c_str()) : 0; if (!object) { if (reader.isVerbose()) { Base::Console().Warning("Lost link to '%s' while loading, maybe " "an object was not loaded correctly\n",name.c_str()); } } else if (parent == object) { if (reader.isVerbose()) { Base::Console().Warning("Object '%s' links to itself, nullify it\n",name.c_str()); } object = 0; } setValue(object); } else { setValue(0); } }
void PropertyLinkSubList::Restore(Base::XMLReader &reader) { // read my element reader.readElement("LinkSubList"); // get the value of my attribute int count = reader.getAttributeAsInteger("count"); std::vector<DocumentObject*> values; values.reserve(count); std::vector<std::string> SubNames; SubNames.reserve(count); for (int i = 0; i < count; i++) { reader.readElement("Link"); std::string name = reader.getAttribute("obj"); // In order to do copy/paste it must be allowed to have defined some // referenced objects in XML which do not exist anymore in the new // document. Thus, we should silently ignore this. // Property not in an object! DocumentObject* father = static_cast<DocumentObject*>(getContainer()); App::Document* document = father->getDocument(); DocumentObject* child = document ? document->getObject(name.c_str()) : 0; if (child) values.push_back(child); else if (reader.isVerbose()) Base::Console().Warning("Lost link to '%s' while loading, maybe " "an object was not loaded correctly\n",name.c_str()); std::string subName = reader.getAttribute("sub"); SubNames.push_back(subName); } reader.readEndElement("LinkSubList"); // assignment setValues(values,SubNames); }
void PropertyLinkSub::Restore(Base::XMLReader &reader) { // read my element reader.readElement("LinkSub"); // get the values of my attributes std::string name = reader.getAttribute("value"); int count = reader.getAttributeAsInteger("count"); // Property not in a DocumentObject! assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) ); std::vector<std::string> values(count); for (int i = 0; i < count; i++) { reader.readElement("Sub"); values[i] = reader.getAttribute("value"); } reader.readEndElement("LinkSub"); DocumentObject *pcObject; if (!name.empty()) { App::Document* document = static_cast<DocumentObject*>(getContainer())->getDocument(); pcObject = document ? document->getObject(name.c_str()) : 0; if (!pcObject) { if (reader.isVerbose()) { Base::Console().Warning("Lost link to '%s' while loading, maybe " "an object was not loaded correctly\n",name.c_str()); } } setValue(pcObject,values); } else { setValue(0); } }
void PropertyLinkList::Restore(Base::XMLReader &reader) { // read my element reader.readElement("LinkList"); // get the value of my attribute int count = reader.getAttributeAsInteger("count"); App::PropertyContainer* container = getContainer(); if (!container) throw Base::RuntimeError("Property is not part of a container"); if (!container->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) { std::stringstream str; str << "Container is not a document object (" << container->getTypeId().getName() << ")"; throw Base::TypeError(str.str()); } std::vector<DocumentObject*> values; values.reserve(count); for (int i = 0; i < count; i++) { reader.readElement("Link"); std::string name = reader.getAttribute("value"); // In order to do copy/paste it must be allowed to have defined some // referenced objects in XML which do not exist anymore in the new // document. Thus, we should silently ignore this. // Property not in an object! DocumentObject* father = static_cast<DocumentObject*>(getContainer()); App::Document* document = father->getDocument(); DocumentObject* child = document ? document->getObject(name.c_str()) : 0; if (child) values.push_back(child); else if (reader.isVerbose()) Base::Console().Warning("Lost link to '%s' while loading, maybe " "an object was not loaded correctly\n", name.c_str()); } reader.readEndElement("LinkList"); // assignment setValues(values); }