mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-11 16:57:51 -06:00
Move createMaterial() to MaterialManager
This commit is contained in:
parent
cf2252f4f9
commit
c93643bc2f
3 changed files with 30 additions and 27 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from collections import defaultdict, OrderedDict
|
from collections import defaultdict, OrderedDict
|
||||||
import copy
|
import copy
|
||||||
|
import uuid
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from PyQt5.Qt import QTimer, QObject, pyqtSignal, pyqtSlot
|
from PyQt5.Qt import QTimer, QObject, pyqtSignal, pyqtSlot
|
||||||
|
@ -429,3 +430,31 @@ class MaterialManager(QObject):
|
||||||
container_to_add.setDirty(True)
|
container_to_add.setDirty(True)
|
||||||
self._container_registry.addContainer(container_to_add)
|
self._container_registry.addContainer(container_to_add)
|
||||||
return new_base_id
|
return new_base_id
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a new material by cloning Generic PLA for the current material diameter and generate a new GUID.
|
||||||
|
#
|
||||||
|
@pyqtSlot(result = str)
|
||||||
|
def createMaterial(self) -> str:
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
# Ensure all settings are saved.
|
||||||
|
self._application.saveSettings()
|
||||||
|
|
||||||
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
|
approximate_diameter = str(round(global_stack.getProperty("material_diameter", "value")))
|
||||||
|
root_material_id = "generic_pla"
|
||||||
|
root_material_id = self.getRootMaterialIDForDiameter(root_material_id, approximate_diameter)
|
||||||
|
material_group = self.getMaterialGroup(root_material_id)
|
||||||
|
|
||||||
|
# Create a new ID & container to hold the data.
|
||||||
|
new_id = self._container_registry.uniqueName("custom_material")
|
||||||
|
new_metadata = {"name": catalog.i18nc("@label", "Custom Material"),
|
||||||
|
"brand": catalog.i18nc("@label", "Custom"),
|
||||||
|
"GUID": str(uuid.uuid4()),
|
||||||
|
}
|
||||||
|
|
||||||
|
self.duplicateMaterial(material_group.root_material_node,
|
||||||
|
new_base_id = new_id,
|
||||||
|
new_metadata = new_metadata)
|
||||||
|
return new_id
|
||||||
|
|
|
@ -382,32 +382,6 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
self._container_registry.addContainer(new_changes)
|
self._container_registry.addContainer(new_changes)
|
||||||
|
|
||||||
## Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
|
|
||||||
#
|
|
||||||
# \return \type{str} the id of the newly created container.
|
|
||||||
@pyqtSlot(result = str)
|
|
||||||
def createMaterial(self):
|
|
||||||
# Ensure all settings are saved.
|
|
||||||
Application.getInstance().saveSettings()
|
|
||||||
|
|
||||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
|
||||||
approximate_diameter = str(round(global_stack.getProperty("material_diameter", "value")))
|
|
||||||
root_material_id = "generic_pla"
|
|
||||||
root_material_id = self._material_manager.getRootMaterialIDForDiameter(root_material_id, approximate_diameter)
|
|
||||||
material_group = self._material_manager.getMaterialGroup(root_material_id)
|
|
||||||
|
|
||||||
# Create a new ID & container to hold the data.
|
|
||||||
new_id = self._container_registry.uniqueName("custom_material")
|
|
||||||
new_metadata = {"name": catalog.i18nc("@label", "Custom Material"),
|
|
||||||
"brand": catalog.i18nc("@label", "Custom"),
|
|
||||||
"GUID": str(uuid.uuid4()),
|
|
||||||
}
|
|
||||||
|
|
||||||
self.duplicateMaterial(material_group.root_material_node,
|
|
||||||
new_base_id = new_id,
|
|
||||||
new_metadata = new_metadata)
|
|
||||||
return new_id
|
|
||||||
|
|
||||||
## Get a list of materials that have the same GUID as the reference material
|
## Get a list of materials that have the same GUID as the reference material
|
||||||
#
|
#
|
||||||
# \param material_id \type{str} the id of the material for which to get the linked materials.
|
# \param material_id \type{str} the id of the material for which to get the linked materials.
|
||||||
|
|
|
@ -79,7 +79,7 @@ Item
|
||||||
iconName: "list-add"
|
iconName: "list-add"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
base.newRootMaterialIdToSwitchTo = Cura.ContainerManager.createMaterial();
|
base.newRootMaterialIdToSwitchTo = base.materialManager.createMaterial();
|
||||||
base.toActivateNewMaterial = true;
|
base.toActivateNewMaterial = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue