mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Reduce nesting complexity with some pre-checks
There were two pre-checks here, where the main body of the function was indented two deep. Instead, just early-out if the checks fail. This is easier to read and understand. Found during investigation of CURA-8128.
This commit is contained in:
parent
cc6a629d92
commit
31106d13d0
1 changed files with 31 additions and 29 deletions
|
@ -73,38 +73,40 @@ class PerObjectSettingVisibilityHandler(UM.Settings.Models.SettingVisibilityHand
|
||||||
|
|
||||||
# Add all instances that are not added, but are in visibility list
|
# Add all instances that are not added, but are in visibility list
|
||||||
for item in visible:
|
for item in visible:
|
||||||
if settings.getInstance(item) is None: # Setting was not added already.
|
if settings.getInstance(item) is not None: # Setting was added already.
|
||||||
definition = self._stack.getSettingDefinition(item)
|
continue
|
||||||
if definition:
|
definition = self._stack.getSettingDefinition(item)
|
||||||
new_instance = SettingInstance(definition, settings)
|
if not definition:
|
||||||
|
Logger.log("w", f"Unable to add instance ({item}) to per-object visibility because we couldn't find the matching definition.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
new_instance = SettingInstance(definition, settings)
|
||||||
|
stack_nr = -1
|
||||||
|
stack = None
|
||||||
|
# Check from what stack we should copy the raw property of the setting from.
|
||||||
|
if self._stack.getProperty("machine_extruder_count", "value") > 1:
|
||||||
|
if definition.limit_to_extruder != "-1":
|
||||||
|
# A limit to extruder function was set and it's a multi extrusion machine. Check what stack we do need to use.
|
||||||
|
stack_nr = str(int(round(float(self._stack.getProperty(item, "limit_to_extruder")))))
|
||||||
|
|
||||||
|
# Check if the found stack_number is in the extruder list of extruders.
|
||||||
|
if stack_nr not in ExtruderManager.getInstance().extruderIds and self._stack.getProperty("extruder_nr", "value") is not None:
|
||||||
stack_nr = -1
|
stack_nr = -1
|
||||||
stack = None
|
|
||||||
# Check from what stack we should copy the raw property of the setting from.
|
|
||||||
if self._stack.getProperty("machine_extruder_count", "value") > 1:
|
|
||||||
if definition.limit_to_extruder != "-1":
|
|
||||||
# A limit to extruder function was set and it's a multi extrusion machine. Check what stack we do need to use.
|
|
||||||
stack_nr = str(int(round(float(self._stack.getProperty(item, "limit_to_extruder")))))
|
|
||||||
|
|
||||||
# Check if the found stack_number is in the extruder list of extruders.
|
# Use the found stack number to get the right stack to copy the value from.
|
||||||
if stack_nr not in ExtruderManager.getInstance().extruderIds and self._stack.getProperty("extruder_nr", "value") is not None:
|
if stack_nr in ExtruderManager.getInstance().extruderIds:
|
||||||
stack_nr = -1
|
stack = ContainerRegistry.getInstance().findContainerStacks(id = ExtruderManager.getInstance().extruderIds[stack_nr])[0]
|
||||||
|
else:
|
||||||
|
stack = self._stack
|
||||||
|
|
||||||
# Use the found stack number to get the right stack to copy the value from.
|
# Use the raw property to set the value (so the inheritance doesn't break)
|
||||||
if stack_nr in ExtruderManager.getInstance().extruderIds:
|
if stack is not None:
|
||||||
stack = ContainerRegistry.getInstance().findContainerStacks(id = ExtruderManager.getInstance().extruderIds[stack_nr])[0]
|
new_instance.setProperty("value", stack.getRawProperty(item, "value"))
|
||||||
else:
|
else:
|
||||||
stack = self._stack
|
new_instance.setProperty("value", None)
|
||||||
|
new_instance.resetState() # Ensure that the state is not seen as a user state.
|
||||||
# Use the raw property to set the value (so the inheritance doesn't break)
|
settings.addInstance(new_instance)
|
||||||
if stack is not None:
|
visibility_changed = True
|
||||||
new_instance.setProperty("value", stack.getRawProperty(item, "value"))
|
|
||||||
else:
|
|
||||||
new_instance.setProperty("value", None)
|
|
||||||
new_instance.resetState() # Ensure that the state is not seen as a user state.
|
|
||||||
settings.addInstance(new_instance)
|
|
||||||
visibility_changed = True
|
|
||||||
else:
|
|
||||||
Logger.log("w", "Unable to add instance (%s) to per-object visibility because we couldn't find the matching definition", item)
|
|
||||||
|
|
||||||
if visibility_changed:
|
if visibility_changed:
|
||||||
self.visibilityChanged.emit()
|
self.visibilityChanged.emit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue