mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 11:17:49 -06:00
Remove isReadOnly functionality
Everyone should now ask it from the container registry. Contributes to issue CURA-4243.
This commit is contained in:
parent
c63ef6fed6
commit
8707396ad7
7 changed files with 35 additions and 48 deletions
|
@ -164,15 +164,15 @@ class ContainerManager(QObject):
|
||||||
# \return True if successful, False if not.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def clearContainer(self, container_id):
|
def clearContainer(self, container_id):
|
||||||
|
if self._container_registry.isReadOnly(container_id):
|
||||||
|
Logger.log("w", "Cannot clear read-only container %s", container_id)
|
||||||
|
return False
|
||||||
|
|
||||||
containers = self._container_registry.findContainers(id = container_id)
|
containers = self._container_registry.findContainers(id = container_id)
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("w", "Could clear container %s because it was not found.", container_id)
|
Logger.log("w", "Could clear container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if containers[0].isReadOnly():
|
|
||||||
Logger.log("w", "Cannot clear read-only container %s", container_id)
|
|
||||||
return False
|
|
||||||
|
|
||||||
containers[0].clear()
|
containers[0].clear()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -200,6 +200,10 @@ class ContainerManager(QObject):
|
||||||
# \return True if successful, False if not.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, str, str, result = bool)
|
@pyqtSlot(str, str, str, result = bool)
|
||||||
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
||||||
|
if self._container_registry.isReadOnly(container_id):
|
||||||
|
Logger.log("w", "Cannot set metadata of read-only container %s.", container_id)
|
||||||
|
return False
|
||||||
|
|
||||||
containers = self._container_registry.findContainers(id = container_id) #We need the complete container, since we need to know whether the container is read-only or not.
|
containers = self._container_registry.findContainers(id = container_id) #We need the complete container, since we need to know whether the container is read-only or not.
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id)
|
||||||
|
@ -207,10 +211,6 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
container = containers[0]
|
container = containers[0]
|
||||||
|
|
||||||
if container.isReadOnly():
|
|
||||||
Logger.log("w", "Cannot set metadata of read-only container %s.", container_id)
|
|
||||||
return False
|
|
||||||
|
|
||||||
entries = entry_name.split("/")
|
entries = entry_name.split("/")
|
||||||
entry_name = entries.pop()
|
entry_name = entries.pop()
|
||||||
|
|
||||||
|
@ -250,6 +250,10 @@ class ContainerManager(QObject):
|
||||||
# \return True if successful, False if not.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, str, str, str, result = bool)
|
@pyqtSlot(str, str, str, str, result = bool)
|
||||||
def setContainerProperty(self, container_id, setting_key, property_name, property_value):
|
def setContainerProperty(self, container_id, setting_key, property_name, property_value):
|
||||||
|
if self._container_registry.isReadOnly(container_id):
|
||||||
|
Logger.log("w", "Cannot set properties of read-only container %s.", container_id)
|
||||||
|
return False
|
||||||
|
|
||||||
containers = self._container_registry.findContainers(id = container_id)
|
containers = self._container_registry.findContainers(id = container_id)
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("w", "Could not set properties of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not set properties of container %s because it was not found.", container_id)
|
||||||
|
@ -257,10 +261,6 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
container = containers[0]
|
container = containers[0]
|
||||||
|
|
||||||
if container.isReadOnly():
|
|
||||||
Logger.log("w", "Cannot set properties of read-only container %s.", container_id)
|
|
||||||
return False
|
|
||||||
|
|
||||||
container.setProperty(setting_key, property_name, property_value)
|
container.setProperty(setting_key, property_name, property_value)
|
||||||
|
|
||||||
basefile = container.getMetaDataEntry("base_file", container_id)
|
basefile = container.getMetaDataEntry("base_file", container_id)
|
||||||
|
@ -296,18 +296,16 @@ class ContainerManager(QObject):
|
||||||
## Set the name of the specified container.
|
## Set the name of the specified container.
|
||||||
@pyqtSlot(str, str, result = bool)
|
@pyqtSlot(str, str, result = bool)
|
||||||
def setContainerName(self, container_id, new_name):
|
def setContainerName(self, container_id, new_name):
|
||||||
|
if self._container_registry.isReadOnly(container_id):
|
||||||
|
Logger.log("w", "Cannot set name of read-only container %s.", container_id)
|
||||||
|
return False
|
||||||
|
|
||||||
containers = self._container_registry.findContainers(id = container_id) #We need to get the full container, not just metadata, since we need to know whether it's read-only.
|
containers = self._container_registry.findContainers(id = container_id) #We need to get the full container, not just metadata, since we need to know whether it's read-only.
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
container = containers[0]
|
containers[0].setName(new_name)
|
||||||
|
|
||||||
if container.isReadOnly():
|
|
||||||
Logger.log("w", "Cannot set name of read-only container %s.", container_id)
|
|
||||||
return False
|
|
||||||
|
|
||||||
container.setName(new_name)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,6 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
#
|
#
|
||||||
# \return None if configuring was successful or an error message if an error occurred.
|
# \return None if configuring was successful or an error message if an error occurred.
|
||||||
def _configureProfile(self, profile: InstanceContainer, id_seed: str, new_name: str) -> Optional[str]:
|
def _configureProfile(self, profile: InstanceContainer, id_seed: str, new_name: str) -> Optional[str]:
|
||||||
profile.setReadOnly(False)
|
|
||||||
profile.setDirty(True) # Ensure the profiles are correctly saved
|
profile.setDirty(True) # Ensure the profiles are correctly saved
|
||||||
|
|
||||||
new_id = self.createUniqueName("quality_changes", "", id_seed, catalog.i18nc("@label", "Custom profile"))
|
new_id = self.createUniqueName("quality_changes", "", id_seed, catalog.i18nc("@label", "Custom profile"))
|
||||||
|
|
|
@ -332,7 +332,7 @@ class ExtruderManager(QObject):
|
||||||
preferred_materials = container_registry.findInstanceContainers(**search_criteria)
|
preferred_materials = container_registry.findInstanceContainers(**search_criteria)
|
||||||
if len(preferred_materials) >= 1:
|
if len(preferred_materials) >= 1:
|
||||||
# In some cases we get multiple materials. In that case, prefer materials that are marked as read only.
|
# In some cases we get multiple materials. In that case, prefer materials that are marked as read only.
|
||||||
read_only_preferred_materials = [preferred_material for preferred_material in preferred_materials if preferred_material.isReadOnly()]
|
read_only_preferred_materials = [preferred_material for preferred_material in preferred_materials if container_registry.isReadOnly(preferred_material.getId())]
|
||||||
if len(read_only_preferred_materials) >= 1:
|
if len(read_only_preferred_materials) >= 1:
|
||||||
material = read_only_preferred_materials[0]
|
material = read_only_preferred_materials[0]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -704,10 +704,7 @@ class MachineManager(QObject):
|
||||||
## Check if a container is read_only
|
## Check if a container is read_only
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def isReadOnly(self, container_id: str) -> bool:
|
def isReadOnly(self, container_id: str) -> bool:
|
||||||
containers = ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
return ContainerRegistry.getInstance().isReadOnly(container_id)
|
||||||
if not containers or not self._active_container_stack:
|
|
||||||
return True
|
|
||||||
return containers[0].isReadOnly()
|
|
||||||
|
|
||||||
## Copy the value of the setting of the current extruder to all other extruders as well as the global container.
|
## Copy the value of the setting of the current extruder to all other extruders as well as the global container.
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
|
|
|
@ -180,11 +180,10 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
|
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
|
||||||
for material_container_file in material_container_files:
|
for material_container_file in material_container_files:
|
||||||
container_id = self._stripFileToId(material_container_file)
|
container_id = self._stripFileToId(material_container_file)
|
||||||
materials = self._container_registry.findInstanceContainers(id=container_id)
|
|
||||||
material_labels.append(self._getMaterialLabelFromSerialized(archive.open(material_container_file).read().decode("utf-8")))
|
material_labels.append(self._getMaterialLabelFromSerialized(archive.open(material_container_file).read().decode("utf-8")))
|
||||||
if materials:
|
if self._container_registry.findContainersMetadata(id = container_id): #This material already exists.
|
||||||
containers_found_dict["material"] = True
|
containers_found_dict["material"] = True
|
||||||
if not materials[0].isReadOnly(): # Only non readonly materials can be in conflict
|
if not self._container_registry.isReadOnly(container_id): # Only non readonly materials can be in conflict
|
||||||
material_conflict = True
|
material_conflict = True
|
||||||
Job.yieldThread()
|
Job.yieldThread()
|
||||||
|
|
||||||
|
@ -501,7 +500,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
containers_to_add.append(material_container)
|
containers_to_add.append(material_container)
|
||||||
else:
|
else:
|
||||||
material_container = materials[0]
|
material_container = materials[0]
|
||||||
if not material_container.isReadOnly(): # Only create new materials if they are not read only.
|
if not self._container_registry.isReadOnly(container_id): # Only create new materials if they are not read only.
|
||||||
if self._resolve_strategies["material"] == "override":
|
if self._resolve_strategies["material"] == "override":
|
||||||
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
|
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
|
||||||
elif self._resolve_strategies["material"] == "new":
|
elif self._resolve_strategies["material"] == "new":
|
||||||
|
|
|
@ -969,7 +969,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
|
|
||||||
## Send all material profiles to the printer.
|
## Send all material profiles to the printer.
|
||||||
def sendMaterialProfiles(self):
|
def sendMaterialProfiles(self):
|
||||||
for container in UM.Settings.ContainerRegistry.ContainerRegistry.getInstance().findInstanceContainers(type = "material"):
|
registry = UM.Settings.ContainerRegistry.ContainerRegistry.getInstance()
|
||||||
|
for container in registry.findInstanceContainers(type = "material"):
|
||||||
try:
|
try:
|
||||||
xml_data = container.serialize()
|
xml_data = container.serialize()
|
||||||
if xml_data == "" or xml_data is None:
|
if xml_data == "" or xml_data is None:
|
||||||
|
@ -978,7 +979,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
names = ContainerManager.getInstance().getLinkedMaterials(container.getId())
|
names = ContainerManager.getInstance().getLinkedMaterials(container.getId())
|
||||||
if names:
|
if names:
|
||||||
# There are other materials that share this GUID.
|
# There are other materials that share this GUID.
|
||||||
if not container.isReadOnly():
|
if not registry.isReadOnly(container.getId()):
|
||||||
continue # If it's not readonly, it's created by user, so skip it.
|
continue # If it's not readonly, it's created by user, so skip it.
|
||||||
|
|
||||||
material_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType)
|
material_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType)
|
||||||
|
|
|
@ -45,25 +45,18 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
def getInheritedFiles(self):
|
def getInheritedFiles(self):
|
||||||
return self._inherited_files
|
return self._inherited_files
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
|
||||||
def setReadOnly(self, read_only):
|
|
||||||
super().setReadOnly(read_only)
|
|
||||||
|
|
||||||
basefile = self.getMetaDataEntry("base_file", self.getId()) # if basefile is self.getId, this is a basefile.
|
|
||||||
for container in ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
|
||||||
container._read_only = read_only # prevent loop instead of calling setReadOnly
|
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
# set the meta data for all machine / variant combinations
|
# set the meta data for all machine / variant combinations
|
||||||
def setMetaDataEntry(self, key, value):
|
def setMetaDataEntry(self, key, value):
|
||||||
if self.isReadOnly():
|
registry = ContainerRegistry.getInstance()
|
||||||
|
if registry.isReadOnly(self.getId()):
|
||||||
return
|
return
|
||||||
|
|
||||||
super().setMetaDataEntry(key, value)
|
super().setMetaDataEntry(key, value)
|
||||||
|
|
||||||
basefile = self.getMetaDataEntry("base_file", self.getId()) #if basefile is self.getId, this is a basefile.
|
basefile = self.getMetaDataEntry("base_file", self.getId()) #if basefile is self.getId, this is a basefile.
|
||||||
# Update all containers that share basefile
|
# Update all containers that share basefile
|
||||||
for container in ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
for container in registry.findInstanceContainers(base_file = basefile):
|
||||||
if container.getMetaDataEntry(key, None) != value: # Prevent recursion
|
if container.getMetaDataEntry(key, None) != value: # Prevent recursion
|
||||||
container.setMetaDataEntry(key, value)
|
container.setMetaDataEntry(key, value)
|
||||||
|
|
||||||
|
@ -71,7 +64,8 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
# without this function the setName would only set the name of the specific nozzle / material / machine combination container
|
# without this function the setName would only set the name of the specific nozzle / material / machine combination container
|
||||||
# The function is a bit tricky. It will not set the name of all containers if it has the correct name itself.
|
# The function is a bit tricky. It will not set the name of all containers if it has the correct name itself.
|
||||||
def setName(self, new_name):
|
def setName(self, new_name):
|
||||||
if self.isReadOnly():
|
registry = ContainerRegistry.getInstance()
|
||||||
|
if registry.isReadOnly(self.getId()):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Not only is this faster, it also prevents a major loop that causes a stack overflow.
|
# Not only is this faster, it also prevents a major loop that causes a stack overflow.
|
||||||
|
@ -83,7 +77,7 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
basefile = self.getMetaDataEntry("base_file", self.getId()) # if basefile is self.getId, this is a basefile.
|
basefile = self.getMetaDataEntry("base_file", self.getId()) # if basefile is self.getId, this is a basefile.
|
||||||
# Update the basefile as well, this is actually what we're trying to do
|
# Update the basefile as well, this is actually what we're trying to do
|
||||||
# Update all containers that share GUID and basefile
|
# Update all containers that share GUID and basefile
|
||||||
containers = ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile)
|
containers = registry.findInstanceContainers(base_file = basefile)
|
||||||
for container in containers:
|
for container in containers:
|
||||||
container.setName(new_name)
|
container.setName(new_name)
|
||||||
|
|
||||||
|
@ -91,12 +85,11 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
def setDirty(self, dirty):
|
def setDirty(self, dirty):
|
||||||
super().setDirty(dirty)
|
super().setDirty(dirty)
|
||||||
base_file = self.getMetaDataEntry("base_file", None)
|
base_file = self.getMetaDataEntry("base_file", None)
|
||||||
if base_file is not None and base_file != self.getId():
|
registry = ContainerRegistry.getInstance()
|
||||||
containers = ContainerRegistry.getInstance().findContainers(id=base_file)
|
if base_file is not None and base_file != self.getId() and not registry.isReadOnly(base_file):
|
||||||
|
containers = registry.findContainers(id = base_file)
|
||||||
if containers:
|
if containers:
|
||||||
base_container = containers[0]
|
containers[0].setDirty(dirty)
|
||||||
if not base_container.isReadOnly():
|
|
||||||
base_container.setDirty(dirty)
|
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
# base file: common settings + supported machines
|
# base file: common settings + supported machines
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue