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

Method dereference

src/Mod/Material/App/MaterialLoader.cpp:471–536  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469
470
471void MaterialLoader::dereference(
472 const std::shared_ptr<std::map<QString, std::shared_ptr<Material>>>& materialMap,
473 const std::shared_ptr<Material>& material)
474{
475 // Avoid recursion
476 if (material->getDereferenced()) {
477 return;
478 }
479
480 auto parentUUID = material->getParentUUID();
481 if (parentUUID.size() > 0) {
482 std::shared_ptr<Material> parent;
483 try {
484 parent = materialMap->at(parentUUID);
485 }
486 catch (std::out_of_range&) {
487 Base::Console().log(
488 "Unable to apply inheritance for material '%s', parent '%s' not found.\n",
489 material->getName().toStdString().c_str(),
490 parentUUID.toStdString().c_str());
491 return;
492 }
493
494 // Ensure the parent has been dereferenced
495 dereference(materialMap, parent);
496
497 // Add physical models
498 auto modelVector = parent->getPhysicalModels();
499 for (auto& model : *modelVector) {
500 if (!material->hasPhysicalModel(model)) {
501 material->addPhysical(model);
502 }
503 }
504
505 // Add appearance models
506 modelVector = parent->getAppearanceModels();
507 for (auto& model : *modelVector) {
508 if (!material->hasAppearanceModel(model)) {
509 material->addAppearance(model);
510 }
511 }
512
513 // Add values
514 auto properties = parent->getPhysicalProperties();
515 for (auto& itp : properties) {
516 auto name = itp.first;
517 auto property = itp.second;
518
519 if (material->getPhysicalProperty(name)->isNull()) {
520 material->getPhysicalProperty(name)->setValue(property->getValue());
521 }
522 }
523
524 properties = parent->getAppearanceProperties();
525 for (auto& itp : properties) {
526 auto name = itp.first;
527 auto property = itp.second;
528

Callers

nothing calls this directly

Calls 15

getDereferencedMethod · 0.80
atMethod · 0.80
toStdStringMethod · 0.80
getPhysicalModelsMethod · 0.80
addPhysicalMethod · 0.80
getAppearanceModelsMethod · 0.80
addAppearanceMethod · 0.80
getPhysicalPropertiesMethod · 0.80
getPhysicalPropertyMethod · 0.80
getAppearancePropertyMethod · 0.80
markDereferencedMethod · 0.80

Tested by

no test coverage detected