More profiles model refactoring - CURA-4482

This commit is contained in:
ChrisTerBeke 2017-10-26 11:51:24 +02:00
parent de34464e47
commit 152f6f8405
3 changed files with 32 additions and 27 deletions

View file

@ -53,6 +53,7 @@ class CrashHandler:
self.exception_type = exception_type self.exception_type = exception_type
self.value = value self.value = value
self.traceback = tb self.traceback = tb
self.dialog = QDialog()
# While we create the GUI, the information will be stored for sending afterwards # While we create the GUI, the information will be stored for sending afterwards
self.data = dict() self.data = dict()

View file

@ -32,11 +32,9 @@ class ProfilesModel(InstanceContainersModel):
self.addRoleName(self.AvailableRole, "available") self.addRoleName(self.AvailableRole, "available")
Application.getInstance().globalContainerStackChanged.connect(self._update) Application.getInstance().globalContainerStackChanged.connect(self._update)
Application.getInstance().getMachineManager().activeVariantChanged.connect(self._update)
self._machine_manager = Application.getInstance().getMachineManager() Application.getInstance().getMachineManager().activeStackChanged.connect(self._update)
self._machine_manager.activeVariantChanged.connect(self._update) Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update)
self._machine_manager.activeStackChanged.connect(self._update)
self._machine_manager.activeMaterialChanged.connect(self._update)
# Factory function, used by QML # Factory function, used by QML
@staticmethod @staticmethod
@ -153,17 +151,21 @@ class ProfilesModel(InstanceContainersModel):
yield item yield item
continue continue
machine_manager = Application.getInstance().getMachineManager()
# Quality-changes profile that has no value for layer height. Get the corresponding quality profile and ask that profile. # Quality-changes profile that has no value for layer height. Get the corresponding quality profile and ask that profile.
quality_type = profile.getMetaDataEntry("quality_type", None) quality_type = profile.getMetaDataEntry("quality_type", None)
if quality_type: if quality_type:
quality_results = self._machine_manager.determineQualityAndQualityChangesForQualityType(quality_type) quality_results = machine_manager.determineQualityAndQualityChangesForQualityType(quality_type)
for quality_result in quality_results: for quality_result in quality_results:
if quality_result["stack"] is global_container_stack: if quality_result["stack"] is global_container_stack:
quality = quality_result["quality"] quality = quality_result["quality"]
break break
else: #No global container stack in the results: else:
# No global container stack in the results:
if quality_results: if quality_results:
quality = quality_results[0]["quality"] #Take any of the extruders. # Take any of the extruders.
quality = quality_results[0]["quality"]
else: else:
quality = None quality = None
if quality and quality.hasProperty("layer_height", "value"): if quality and quality.hasProperty("layer_height", "value"):
@ -171,11 +173,11 @@ class ProfilesModel(InstanceContainersModel):
yield item yield item
continue continue
#Quality has no value for layer height either. Get the layer height from somewhere lower in the stack. # Quality has no value for layer height either. Get the layer height from somewhere lower in the stack.
skip_until_container = global_container_stack.material skip_until_container = global_container_stack.material
if not skip_until_container or skip_until_container == ContainerRegistry.getInstance().getEmptyInstanceContainer(): #No material in stack. if not skip_until_container or skip_until_container == ContainerRegistry.getInstance().getEmptyInstanceContainer(): # No material in stack.
skip_until_container = global_container_stack.variant skip_until_container = global_container_stack.variant
if not skip_until_container or skip_until_container == ContainerRegistry.getInstance().getEmptyInstanceContainer(): #No variant in stack. if not skip_until_container or skip_until_container == ContainerRegistry.getInstance().getEmptyInstanceContainer(): # No variant in stack.
skip_until_container = global_container_stack.getBottom() skip_until_container = global_container_stack.getBottom()
self._setItemLayerHeight(item, global_container_stack.getRawProperty("layer_height", "value", skip_until_container = skip_until_container.getId()), unit) # Fall through to the currently loaded material. self._setItemLayerHeight(item, global_container_stack.getRawProperty("layer_height", "value", skip_until_container = skip_until_container.getId()), unit) # Fall through to the currently loaded material.
yield item yield item

View file

@ -176,25 +176,27 @@ class MachineSettingsAction(MachineAction):
extruder_manager.setActiveExtruderIndex(0) extruder_manager.setActiveExtruderIndex(0)
# Move settable_per_extruder values out of the global container # Move settable_per_extruder values out of the global container
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStack() # extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStack()
global_user_container = self._global_container_stack.getTop() global_user_container = self._global_container_stack.getTop()
for setting_instance in global_user_container.findInstances(): if extruder_count > 1:
setting_key = setting_instance.definition.key # Multi extrusion
# Make sure one of the extruder stacks is active
if extruder_manager.activeExtruderIndex == -1:
extruder_manager.setActiveExtruderIndex(0)
# Move settable_per_extruder values out of the global container
if previous_extruder_count == 1:
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
global_user_container = self._global_container_stack.getTop()
for setting_instance in global_user_container.findInstances():
for setting_instance in global_user_container.findInstances(): setting_key = setting_instance.definition.key
setting_key = setting_instance.definition.key settable_per_extruder = self._global_container_stack.getProperty(setting_key, "settable_per_extruder")
settable_per_extruder = self._global_container_stack.getProperty(setting_key, "settable_per_extruder") if settable_per_extruder:
if settable_per_extruder: limit_to_extruder = int(self._global_container_stack.getProperty(setting_key, "limit_to_extruder"))
limit_to_extruder = int(self._global_container_stack.getProperty(setting_key, "limit_to_extruder")) extruder_stack = extruder_stacks[max(0, limit_to_extruder)]
extruder_stack = extruder_stacks[max(0, limit_to_extruder)] extruder_stack.getTop().setProperty(setting_key, "value", global_user_container.getProperty(setting_key, "value"))
extruder_stack.getTop().setProperty(setting_key, "value", global_user_container.getProperty(setting_key, "value")) global_user_container.removeInstance(setting_key)
global_user_container.removeInstance(setting_key)
else: else:
# Single extrusion # Single extrusion