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

Method getModelTree

src/Mod/Material/App/ModelLibrary.cpp:56–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>>
57ModelLibrary::getModelTree(ModelFilter filter) const
58{
59 std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> modelTree =
60 std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>();
61
62 auto models = ModelManager::getManager().libraryModels(getName());
63 for (auto& it : *models) {
64 auto uuid = it.getUUID();
65 auto path = it.getPath();
66 auto filename = it.getName();
67
68 auto model = ModelManager::getManager().getModel(getName(), uuid);
69 if (ModelManager::passFilter(filter, model->getType())) {
70 QStringList list = path.split(QLatin1Char('/'));
71
72 // Start at the root
73 std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> node = modelTree;
74 for (auto& itp : list) {
75 // Add the folder only if it's not already there
76 if (!node->contains(itp)) {
77 auto mapPtr =
78 std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>();
79 std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>();
80 child->setFolder(mapPtr);
81 (*node)[itp] = child;
82 node = mapPtr;
83 }
84 else {
85 node = (*node)[itp]->getFolder();
86 }
87 }
88 std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>();
89 child->setUUID(uuid);
90 child->setData(model);
91 (*node)[filename] = child;
92 }
93 }
94
95 return modelTree;
96}
97
98TYPESYSTEM_SOURCE(Materials::ModelLibraryLocal, Materials::ModelLibrary)
99

Callers 3

ModelManager.hFile · 0.80
fillTreeMethod · 0.80

Calls 13

setFolderMethod · 0.80
getFolderMethod · 0.80
getNameFunction · 0.70
libraryModelsMethod · 0.45
getUUIDMethod · 0.45
getPathMethod · 0.45
getNameMethod · 0.45
getModelMethod · 0.45
getTypeMethod · 0.45
splitMethod · 0.45
containsMethod · 0.45
setUUIDMethod · 0.45

Tested by

no test coverage detected