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

Method restoreExtensions

src/App/ExtensionContainer.cpp:420–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418}
419
420void ExtensionContainer::restoreExtensions(Base::XMLReader& reader)
421{
422
423 // Dynamic extensions are optional (also because they are introduced late into the document
424 // format) and hence it is possible that the element does not exist. As we cannot check for the
425 // existence of an element a object attribute is set if extensions are available. Here we check
426 // that attribute, and only if it exists the extensions element will be available.
427 if (!reader.hasAttribute("Extensions")) {
428 return;
429 }
430
431 reader.readElement("Extensions");
432 int Cnt = reader.getAttribute<long>("Count");
433
434 for (int i = 0; i < Cnt; i++) {
435 reader.readElement("Extension");
436 const char* Type = reader.getAttribute<const char*>("type");
437 const char* Name = reader.getAttribute<const char*>("name");
438 try {
439 App::Extension* ext = getExtension(Name);
440 if (!ext) {
441 // get the extension type asked for
442 Base::Type extension = Base::Type::fromName(Type);
443 if (extension.isBad()
444 || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) {
445 std::stringstream str;
446 str << "No extension found of type '" << Type << "'" << std::ends;
447 throw Base::TypeError(str.str());
448 }
449
450 // register the extension
451 ext = static_cast<App::Extension*>(extension.createInstance());
452 // check if this really is a python extension!
453 if (!ext->isPythonExtension()) {
454 delete ext;
455 std::stringstream str;
456 str << "Extension is not a python addable version: '" << Type << "'";
457 throw Base::TypeError(str.str());
458 }
459
460 ext->initExtension(this);
461 }
462 if (ext && ext->getExtensionTypeId().getName() == Type) {
463 ext->extensionRestore(reader);
464 }
465 }
466 catch (const Base::XMLParseException&) {
467 throw; // re-throw
468 }
469 catch (const Base::Exception& e) {
470 Base::Console().error("%s\n", e.what());
471 }
472 catch (const std::exception& e) {
473 Base::Console().error("%s\n", e.what());
474 }
475 catch (const char* e) {
476 Base::Console().error("%s\n", e);
477 }

Callers

nothing calls this directly

Calls 12

hasAttributeMethod · 0.80
readElementMethod · 0.80
readEndElementMethod · 0.80
getExtensionFunction · 0.70
isBadMethod · 0.45
isDerivedFromMethod · 0.45
strMethod · 0.45
createInstanceMethod · 0.45
initExtensionMethod · 0.45
getNameMethod · 0.45
errorMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected