From e0e11477081bfd57465282262c0538a895128d87 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 29 Aug 2016 14:40:37 +0200 Subject: [PATCH 1/2] Somewhat working materialspage duplicate. Contributes to CURA-1969 --- plugins/XmlMaterialProfile/XmlMaterialProfile.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 40d85e8ab0..77f775ee27 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -23,7 +23,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer): def duplicate(self, new_id, new_name = None): base_file = self.getMetaDataEntry("base_file", None) - if base_file: + if base_file != self.id: containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = base_file) if containers: new_basefile = containers[0].duplicate(self.getMetaDataEntry("brand") + "_" + new_id, new_name) @@ -36,11 +36,16 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer): variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = variant) if variant_containers: new_id += "_" + variant_containers[0].getName().replace(" ", "_") + has_base_file = True + else: + has_base_file = False new_id = UM.Settings.ContainerRegistry.getInstance().createUniqueName("material", self._id, new_id, "") result = super().duplicate(new_id, new_name) - if result.getMetaDataEntry("base_file", None): + if has_base_file: result.setMetaDataEntry("base_file", base_file) + else: + result.setMetaDataEntry("base_file", result.id) return result ## Overridden from InstanceContainer From 71a77c1fb7850c6b4cbde342b5c644e3907a3971 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 29 Aug 2016 15:35:14 +0200 Subject: [PATCH 2/2] Decrease number of instances of InstanceContainerModel Updates to InstanceContainerModel are becoming expensive because there are so many instances of that model. The MaterialMenu used three, and the MaterialMenu is instantiated three times for a dual extrusion printer. CURA-2193 --- resources/qml/Menus/MaterialMenu.qml | 66 ++++++++++++++++++---------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/resources/qml/Menus/MaterialMenu.qml b/resources/qml/Menus/MaterialMenu.qml index c764f2cd9d..515daa9594 100644 --- a/resources/qml/Menus/MaterialMenu.qml +++ b/resources/qml/Menus/MaterialMenu.qml @@ -14,10 +14,7 @@ Menu Instantiator { - model: UM.InstanceContainersModel - { - filter: materialFilter("Generic") - } + model: genericMaterialsModel MenuItem { text: model.name @@ -40,7 +37,7 @@ Menu { id: brandMenu title: brandName - property string brandName: model.brandName + property string brandName: model.name property var brandMaterials: model.materials Instantiator @@ -50,14 +47,12 @@ Menu { id: brandMaterialsMenu title: materialName - property string materialName: model.materialName + property string materialName: model.name + property var brandMaterialColors: model.colors Instantiator { - model: UM.InstanceContainersModel - { - filter: materialFilter(brandMenu.brandName, brandMaterialsMenu.materialName) - } + model: brandMaterialColors MenuItem { text: model.name @@ -81,10 +76,15 @@ Menu onObjectRemoved: menu.removeItem(object) } + ListModel + { + id: genericMaterialsModel + Component.onCompleted: populateMenuModels() + } + ListModel { id: brandModel - Component.onCompleted: populateBrandModel() } //: Model used to populate the brandModel @@ -92,7 +92,7 @@ Menu { id: materialsModel filter: materialFilter() - onDataChanged: populateBrandModel() + onDataChanged: populateMenuModels() } ExclusiveGroup { id: group } @@ -127,40 +127,58 @@ Menu return result; } - function populateBrandModel() + function populateMenuModels() { // Create a structure of unique brands and their material-types + genericMaterialsModel.clear() + brandModel.clear(); + var items = materialsModel.items; - var materialsByBrand = {} + var materialsByBrand = {}; for (var i in items) { var brandName = items[i]["metadata"]["brand"]; var materialName = items[i]["metadata"]["material"]; if (brandName == "Generic") { - continue; + // Add to top section + var materialId = items[i].id; + genericMaterialsModel.append({ + id:materialId, + name:materialName + }); } - if (!materialsByBrand.hasOwnProperty(brandName)) + else { - materialsByBrand[brandName] = []; - } - if (materialsByBrand[brandName].indexOf(materialName) == -1) - { - materialsByBrand[brandName].push(materialName); + // Add to per-brand, per-material menu + if (!materialsByBrand.hasOwnProperty(brandName)) + { + materialsByBrand[brandName] = {}; + } + if (!materialsByBrand[brandName].hasOwnProperty(materialName)) + { + materialsByBrand[brandName][materialName] = []; + } + materialsByBrand[brandName][materialName].push({ + name: items[i].name, + id: items[i].id + }); } } - brandModel.clear(); for (var brand in materialsByBrand) { var materialsByBrandModel = []; var materials = materialsByBrand[brand]; for (var material in materials) { - materialsByBrandModel.push({materialName: materials[material]}) + materialsByBrandModel.push({ + name: material, + colors: materials[material] + }) } brandModel.append({ - brandName: brand, + name: brand, materials: materialsByBrandModel }); }