mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 00:39:01 +08:00
Merge branch 'master' of github.com:Ultimaker/Cura
This commit is contained in:
commit
70af60c5fb
@ -23,7 +23,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
def duplicate(self, new_id, new_name = None):
|
def duplicate(self, new_id, new_name = None):
|
||||||
base_file = self.getMetaDataEntry("base_file", 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)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = base_file)
|
||||||
if containers:
|
if containers:
|
||||||
new_basefile = containers[0].duplicate(self.getMetaDataEntry("brand") + "_" + new_id, new_name)
|
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)
|
variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = variant)
|
||||||
if variant_containers:
|
if variant_containers:
|
||||||
new_id += "_" + variant_containers[0].getName().replace(" ", "_")
|
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, "")
|
new_id = UM.Settings.ContainerRegistry.getInstance().createUniqueName("material", self._id, new_id, "")
|
||||||
result = super().duplicate(new_id, new_name)
|
result = super().duplicate(new_id, new_name)
|
||||||
if result.getMetaDataEntry("base_file", None):
|
if has_base_file:
|
||||||
result.setMetaDataEntry("base_file", base_file)
|
result.setMetaDataEntry("base_file", base_file)
|
||||||
|
else:
|
||||||
|
result.setMetaDataEntry("base_file", result.id)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
|
@ -14,10 +14,7 @@ Menu
|
|||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: UM.InstanceContainersModel
|
model: genericMaterialsModel
|
||||||
{
|
|
||||||
filter: materialFilter("Generic")
|
|
||||||
}
|
|
||||||
MenuItem
|
MenuItem
|
||||||
{
|
{
|
||||||
text: model.name
|
text: model.name
|
||||||
@ -40,7 +37,7 @@ Menu
|
|||||||
{
|
{
|
||||||
id: brandMenu
|
id: brandMenu
|
||||||
title: brandName
|
title: brandName
|
||||||
property string brandName: model.brandName
|
property string brandName: model.name
|
||||||
property var brandMaterials: model.materials
|
property var brandMaterials: model.materials
|
||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
@ -50,14 +47,12 @@ Menu
|
|||||||
{
|
{
|
||||||
id: brandMaterialsMenu
|
id: brandMaterialsMenu
|
||||||
title: materialName
|
title: materialName
|
||||||
property string materialName: model.materialName
|
property string materialName: model.name
|
||||||
|
property var brandMaterialColors: model.colors
|
||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: UM.InstanceContainersModel
|
model: brandMaterialColors
|
||||||
{
|
|
||||||
filter: materialFilter(brandMenu.brandName, brandMaterialsMenu.materialName)
|
|
||||||
}
|
|
||||||
MenuItem
|
MenuItem
|
||||||
{
|
{
|
||||||
text: model.name
|
text: model.name
|
||||||
@ -81,10 +76,15 @@ Menu
|
|||||||
onObjectRemoved: menu.removeItem(object)
|
onObjectRemoved: menu.removeItem(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListModel
|
||||||
|
{
|
||||||
|
id: genericMaterialsModel
|
||||||
|
Component.onCompleted: populateMenuModels()
|
||||||
|
}
|
||||||
|
|
||||||
ListModel
|
ListModel
|
||||||
{
|
{
|
||||||
id: brandModel
|
id: brandModel
|
||||||
Component.onCompleted: populateBrandModel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//: Model used to populate the brandModel
|
//: Model used to populate the brandModel
|
||||||
@ -92,7 +92,7 @@ Menu
|
|||||||
{
|
{
|
||||||
id: materialsModel
|
id: materialsModel
|
||||||
filter: materialFilter()
|
filter: materialFilter()
|
||||||
onDataChanged: populateBrandModel()
|
onDataChanged: populateMenuModels()
|
||||||
}
|
}
|
||||||
|
|
||||||
ExclusiveGroup { id: group }
|
ExclusiveGroup { id: group }
|
||||||
@ -127,40 +127,58 @@ Menu
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateBrandModel()
|
function populateMenuModels()
|
||||||
{
|
{
|
||||||
// Create a structure of unique brands and their material-types
|
// Create a structure of unique brands and their material-types
|
||||||
|
genericMaterialsModel.clear()
|
||||||
|
brandModel.clear();
|
||||||
|
|
||||||
var items = materialsModel.items;
|
var items = materialsModel.items;
|
||||||
var materialsByBrand = {}
|
var materialsByBrand = {};
|
||||||
for (var i in items) {
|
for (var i in items) {
|
||||||
var brandName = items[i]["metadata"]["brand"];
|
var brandName = items[i]["metadata"]["brand"];
|
||||||
var materialName = items[i]["metadata"]["material"];
|
var materialName = items[i]["metadata"]["material"];
|
||||||
|
|
||||||
if (brandName == "Generic")
|
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] = [];
|
// Add to per-brand, per-material menu
|
||||||
}
|
if (!materialsByBrand.hasOwnProperty(brandName))
|
||||||
if (materialsByBrand[brandName].indexOf(materialName) == -1)
|
{
|
||||||
{
|
materialsByBrand[brandName] = {};
|
||||||
materialsByBrand[brandName].push(materialName);
|
}
|
||||||
|
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)
|
for (var brand in materialsByBrand)
|
||||||
{
|
{
|
||||||
var materialsByBrandModel = [];
|
var materialsByBrandModel = [];
|
||||||
var materials = materialsByBrand[brand];
|
var materials = materialsByBrand[brand];
|
||||||
for (var material in materials)
|
for (var material in materials)
|
||||||
{
|
{
|
||||||
materialsByBrandModel.push({materialName: materials[material]})
|
materialsByBrandModel.push({
|
||||||
|
name: material,
|
||||||
|
colors: materials[material]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
brandModel.append({
|
brandModel.append({
|
||||||
brandName: brand,
|
name: brand,
|
||||||
materials: materialsByBrandModel
|
materials: materialsByBrandModel
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user