mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 06:05:52 +08:00
Put materials into branded material submenus
CURA-2194
This commit is contained in:
parent
baad88fb6c
commit
3b1c11bfcf
@ -39,24 +39,38 @@ Menu
|
|||||||
Menu
|
Menu
|
||||||
{
|
{
|
||||||
id: brandMenu
|
id: brandMenu
|
||||||
title: model.brandName
|
title: brandName
|
||||||
property string brand: model.brandName
|
property string brandName: model.brandName
|
||||||
|
property var brandMaterials: model.materials
|
||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: UM.InstanceContainersModel
|
model: brandMaterials
|
||||||
|
Menu
|
||||||
{
|
{
|
||||||
filter: materialFilter(brandMenu.brandName)
|
id: brandMaterialsMenu
|
||||||
}
|
title: materialName
|
||||||
MenuItem
|
property string materialName: model.materialName
|
||||||
{
|
|
||||||
text: model.name
|
Instantiator
|
||||||
checkable: true;
|
|
||||||
checked: model.id == Cura.MachineManager.activeMaterialId;
|
|
||||||
exclusiveGroup: group;
|
|
||||||
onTriggered:
|
|
||||||
{
|
{
|
||||||
Cura.MachineManager.setActiveMaterial(model.id);
|
model: UM.InstanceContainersModel
|
||||||
|
{
|
||||||
|
filter: materialFilter(brandMenu.brandName, brandMaterialsMenu.materialName)
|
||||||
|
}
|
||||||
|
MenuItem
|
||||||
|
{
|
||||||
|
text: model.name
|
||||||
|
checkable: true;
|
||||||
|
checked: model.id == Cura.MachineManager.activeMaterialId;
|
||||||
|
exclusiveGroup: group;
|
||||||
|
onTriggered:
|
||||||
|
{
|
||||||
|
Cura.MachineManager.setActiveMaterial(model.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onObjectAdded: brandMaterialsMenu.insertItem(index, object)
|
||||||
|
onObjectRemoved: brandMaterialsMenu.removeItem(object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onObjectAdded: brandMenu.insertItem(index, object)
|
onObjectAdded: brandMenu.insertItem(index, object)
|
||||||
@ -87,46 +101,68 @@ Menu
|
|||||||
|
|
||||||
MenuItem { action: Cura.Actions.manageMaterials }
|
MenuItem { action: Cura.Actions.manageMaterials }
|
||||||
|
|
||||||
function populateBrandModel()
|
|
||||||
{
|
|
||||||
var brands = materialsModel.getUniqueValues("brand")
|
|
||||||
var material_types = materialsModel.getUniqueValues("material")
|
|
||||||
brandModel.clear();
|
|
||||||
for (var i in brands)
|
|
||||||
{
|
|
||||||
if(brands[i] != "Generic")
|
|
||||||
{
|
|
||||||
brandModel.append({
|
|
||||||
brandName: brands[i],
|
|
||||||
materials: []
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function materialFilter(brand, material)
|
function materialFilter(brand, material)
|
||||||
{
|
{
|
||||||
var result = { "type": "material" }
|
var result = { "type": "material" };
|
||||||
if(brand != undefined)
|
if(brand)
|
||||||
{
|
{
|
||||||
result.brand = brand
|
result.brand = brand;
|
||||||
}
|
}
|
||||||
if(material != undefined)
|
if(material)
|
||||||
{
|
{
|
||||||
result.material = material
|
result.material = material;
|
||||||
}
|
}
|
||||||
if(Cura.MachineManager.filterMaterialsByMachine)
|
if(Cura.MachineManager.filterMaterialsByMachine)
|
||||||
{
|
{
|
||||||
result.definition = Cura.MachineManager.activeDefinitionId
|
result.definition = Cura.MachineManager.activeDefinitionId;
|
||||||
if(Cura.MachineManager.hasVariants)
|
if(Cura.MachineManager.hasVariants)
|
||||||
{
|
{
|
||||||
result.variant = Cura.MachineManager.activeVariantId
|
result.variant = Cura.MachineManager.activeVariantId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.definition = "fdmprinter"
|
result.definition = "fdmprinter";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateBrandModel()
|
||||||
|
{
|
||||||
|
// Create a structure of unique brands and their material-types
|
||||||
|
var items = materialsModel.items;
|
||||||
|
var materialsByBrand = {}
|
||||||
|
for (var i in items) {
|
||||||
|
var brandName = items[i]["metadata"]["brand"];
|
||||||
|
var materialName = items[i]["metadata"]["material"];
|
||||||
|
|
||||||
|
if (brandName == "Generic")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!materialsByBrand.hasOwnProperty(brandName))
|
||||||
|
{
|
||||||
|
materialsByBrand[brandName] = [];
|
||||||
|
}
|
||||||
|
if (materialsByBrand[brandName].indexOf(materialName) == -1)
|
||||||
|
{
|
||||||
|
materialsByBrand[brandName].push(materialName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
brandModel.clear();
|
||||||
|
for (var brand in materialsByBrand)
|
||||||
|
{
|
||||||
|
var materialsByBrandModel = [];
|
||||||
|
var materials = materialsByBrand[brand];
|
||||||
|
for (var material in materials)
|
||||||
|
{
|
||||||
|
materialsByBrandModel.push({materialName: materials[material]})
|
||||||
|
}
|
||||||
|
brandModel.append({
|
||||||
|
brandName: brand,
|
||||||
|
materials: materialsByBrandModel
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user