mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-09 06:45:09 -06:00
Merge branch 'master' into feature_local_container_server
Contributes to issue CURA-4243.
This commit is contained in:
commit
dad99f5292
542 changed files with 35309 additions and 16367 deletions
|
@ -876,15 +876,6 @@ class BuildVolume(SceneNode):
|
|||
|
||||
return result
|
||||
|
||||
## Private convenience function to get a setting from the adhesion
|
||||
# extruder.
|
||||
#
|
||||
# \param setting_key The key of the setting to get.
|
||||
# \param property The property to get from the setting.
|
||||
# \return The property of the specified setting in the adhesion extruder.
|
||||
def _getSettingFromAdhesionExtruder(self, setting_key, property = "value"):
|
||||
return self._getSettingFromExtruder(setting_key, "adhesion_extruder_nr", property)
|
||||
|
||||
## Private convenience function to get a setting from every extruder.
|
||||
#
|
||||
# For single extrusion machines, this gets the setting from the global
|
||||
|
@ -899,44 +890,6 @@ class BuildVolume(SceneNode):
|
|||
all_values[i] = 0
|
||||
return all_values
|
||||
|
||||
## Private convenience function to get a setting from the support infill
|
||||
# extruder.
|
||||
#
|
||||
# \param setting_key The key of the setting to get.
|
||||
# \param property The property to get from the setting.
|
||||
# \return The property of the specified setting in the support infill
|
||||
# extruder.
|
||||
def _getSettingFromSupportInfillExtruder(self, setting_key, property = "value"):
|
||||
return self._getSettingFromExtruder(setting_key, "support_infill_extruder_nr", property)
|
||||
|
||||
## Helper function to get a setting from an extruder specified in another
|
||||
# setting.
|
||||
#
|
||||
# \param setting_key The key of the setting to get.
|
||||
# \param extruder_setting_key The key of the setting that specifies from
|
||||
# which extruder to get the setting, if there are multiple extruders.
|
||||
# \param property The property to get from the setting.
|
||||
# \return The property of the specified setting in the specified extruder.
|
||||
def _getSettingFromExtruder(self, setting_key, extruder_setting_key, property = "value"):
|
||||
multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
|
||||
if not multi_extrusion:
|
||||
stack = self._global_container_stack
|
||||
else:
|
||||
extruder_index = self._global_container_stack.getProperty(extruder_setting_key, "value")
|
||||
|
||||
if str(extruder_index) == "-1": # If extruder index is -1 use global instead
|
||||
stack = self._global_container_stack
|
||||
else:
|
||||
extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)]
|
||||
stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
||||
|
||||
value = stack.getProperty(setting_key, property)
|
||||
setting_type = stack.getProperty(setting_key, "type")
|
||||
if not value and (setting_type == "int" or setting_type == "float"):
|
||||
return 0
|
||||
return value
|
||||
|
||||
## Convenience function to calculate the disallowed radius around the edge.
|
||||
#
|
||||
# This disallowed radius is to allow for space around the models that is
|
||||
|
@ -945,6 +898,7 @@ class BuildVolume(SceneNode):
|
|||
def _getEdgeDisallowedSize(self):
|
||||
if not self._global_container_stack:
|
||||
return 0
|
||||
|
||||
container_stack = self._global_container_stack
|
||||
used_extruders = ExtruderManager.getInstance().getUsedExtruderStacks()
|
||||
|
||||
|
@ -953,32 +907,44 @@ class BuildVolume(SceneNode):
|
|||
return 0.1 # Return a very small value, so we do draw disallowed area's near the edges.
|
||||
|
||||
adhesion_type = container_stack.getProperty("adhesion_type", "value")
|
||||
skirt_brim_line_width = self._global_container_stack.getProperty("skirt_brim_line_width", "value")
|
||||
initial_layer_line_width_factor = self._global_container_stack.getProperty("initial_layer_line_width_factor", "value")
|
||||
if adhesion_type == "skirt":
|
||||
skirt_distance = self._getSettingFromAdhesionExtruder("skirt_gap")
|
||||
skirt_line_count = self._getSettingFromAdhesionExtruder("skirt_line_count")
|
||||
bed_adhesion_size = skirt_distance + (self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * skirt_line_count) * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
|
||||
if len(used_extruders) > 1:
|
||||
for extruder_stack in used_extruders:
|
||||
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
||||
#We don't create an additional line for the extruder we're printing the skirt with.
|
||||
bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
|
||||
skirt_distance = self._global_container_stack.getProperty("skirt_gap", "value")
|
||||
skirt_line_count = self._global_container_stack.getProperty("skirt_line_count", "value")
|
||||
|
||||
bed_adhesion_size = skirt_distance + (skirt_brim_line_width * skirt_line_count) * initial_layer_line_width_factor / 100.0
|
||||
|
||||
for extruder_stack in used_extruders:
|
||||
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
||||
|
||||
# We don't create an additional line for the extruder we're printing the skirt with.
|
||||
bed_adhesion_size -= skirt_brim_line_width * initial_layer_line_width_factor / 100.0
|
||||
|
||||
elif adhesion_type == "brim":
|
||||
bed_adhesion_size = self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * self._getSettingFromAdhesionExtruder("brim_line_count") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
|
||||
if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||
for extruder_stack in used_extruders:
|
||||
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
||||
#We don't create an additional line for the extruder we're printing the brim with.
|
||||
bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
|
||||
brim_line_count = self._global_container_stack.getProperty("brim_line_count", "value")
|
||||
bed_adhesion_size = skirt_brim_line_width * brim_line_count * initial_layer_line_width_factor / 100.0
|
||||
|
||||
for extruder_stack in used_extruders:
|
||||
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
||||
|
||||
# We don't create an additional line for the extruder we're printing the brim with.
|
||||
bed_adhesion_size -= skirt_brim_line_width * initial_layer_line_width_factor / 100.0
|
||||
|
||||
elif adhesion_type == "raft":
|
||||
bed_adhesion_size = self._getSettingFromAdhesionExtruder("raft_margin")
|
||||
bed_adhesion_size = self._global_container_stack.getProperty("raft_margin", "value")
|
||||
|
||||
elif adhesion_type == "none":
|
||||
bed_adhesion_size = 0
|
||||
|
||||
else:
|
||||
raise Exception("Unknown bed adhesion type. Did you forget to update the build volume calculations for your new bed adhesion type?")
|
||||
|
||||
support_expansion = 0
|
||||
if self._getSettingFromSupportInfillExtruder("support_offset") and self._global_container_stack.getProperty("support_enable", "value"):
|
||||
support_expansion += self._getSettingFromSupportInfillExtruder("support_offset")
|
||||
support_enabled = self._global_container_stack.getProperty("support_enable", "value")
|
||||
support_offset = self._global_container_stack.getProperty("support_offset", "value")
|
||||
if support_enabled and support_offset:
|
||||
support_expansion += support_offset
|
||||
|
||||
farthest_shield_distance = 0
|
||||
if container_stack.getProperty("draft_shield_enabled", "value"):
|
||||
|
|
|
@ -12,8 +12,8 @@ class CameraAnimation(QVariantAnimation):
|
|||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
self._camera_tool = None
|
||||
self.setDuration(500)
|
||||
self.setEasingCurve(QEasingCurve.InOutQuad)
|
||||
self.setDuration(300)
|
||||
self.setEasingCurve(QEasingCurve.OutQuad)
|
||||
|
||||
def setCameraTool(self, camera_tool):
|
||||
self._camera_tool = camera_tool
|
||||
|
|
|
@ -302,24 +302,23 @@ class ConvexHullDecorator(SceneNodeDecorator):
|
|||
self._onChanged()
|
||||
|
||||
## Private convenience function to get a setting from the correct extruder (as defined by limit_to_extruder property).
|
||||
def _getSettingProperty(self, setting_key, property = "value"):
|
||||
def _getSettingProperty(self, setting_key, prop = "value"):
|
||||
per_mesh_stack = self._node.callDecoration("getStack")
|
||||
if per_mesh_stack:
|
||||
return per_mesh_stack.getProperty(setting_key, property)
|
||||
|
||||
multi_extrusion = self._global_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
if not multi_extrusion:
|
||||
return self._global_stack.getProperty(setting_key, property)
|
||||
return per_mesh_stack.getProperty(setting_key, prop)
|
||||
|
||||
extruder_index = self._global_stack.getProperty(setting_key, "limit_to_extruder")
|
||||
if extruder_index == "-1": #No limit_to_extruder.
|
||||
if extruder_index == "-1":
|
||||
# No limit_to_extruder
|
||||
extruder_stack_id = self._node.callDecoration("getActiveExtruder")
|
||||
if not extruder_stack_id: #Decoration doesn't exist.
|
||||
if not extruder_stack_id:
|
||||
# Decoration doesn't exist
|
||||
extruder_stack_id = ExtruderManager.getInstance().extruderIds["0"]
|
||||
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
||||
return extruder_stack.getProperty(setting_key, property)
|
||||
else: #Limit_to_extruder is set. The global stack handles this then.
|
||||
return self._global_stack.getProperty(setting_key, property)
|
||||
return extruder_stack.getProperty(setting_key, prop)
|
||||
else:
|
||||
# Limit_to_extruder is set. The global stack handles this then
|
||||
return self._global_stack.getProperty(setting_key, prop)
|
||||
|
||||
## Returns true if node is a descendant or the same as the root node.
|
||||
def __isDescendant(self, root, node):
|
||||
|
|
|
@ -53,6 +53,7 @@ class CrashHandler:
|
|||
self.exception_type = exception_type
|
||||
self.value = value
|
||||
self.traceback = tb
|
||||
self.dialog = QDialog()
|
||||
|
||||
# While we create the GUI, the information will be stored for sending afterwards
|
||||
self.data = dict()
|
||||
|
@ -74,7 +75,6 @@ class CrashHandler:
|
|||
|
||||
## Creates a modal dialog.
|
||||
def _createDialog(self):
|
||||
self.dialog = QDialog()
|
||||
self.dialog.setMinimumWidth(640)
|
||||
self.dialog.setMinimumHeight(640)
|
||||
self.dialog.setWindowTitle(catalog.i18nc("@title:window", "Crash Report"))
|
||||
|
@ -108,11 +108,11 @@ class CrashHandler:
|
|||
except:
|
||||
self.cura_version = catalog.i18nc("@label unknown version of Cura", "Unknown")
|
||||
|
||||
crash_info = catalog.i18nc("@label Cura version", "<b>Cura version:</b> {version}<br/>").format(version = self.cura_version)
|
||||
crash_info += catalog.i18nc("@label Platform", "<b>Platform:</b> {platform}<br/>").format(platform = platform.platform())
|
||||
crash_info += catalog.i18nc("@label Qt version", "<b>Qt version:</b> {qt}<br/>").format(qt = QT_VERSION_STR)
|
||||
crash_info += catalog.i18nc("@label PyQt version", "<b>PyQt version:</b> {pyqt}<br/>").format(pyqt = PYQT_VERSION_STR)
|
||||
crash_info += catalog.i18nc("@label OpenGL", "<b>OpenGL:</b> {opengl}<br/>").format(opengl = self._getOpenGLInfo())
|
||||
crash_info = "<b>" + catalog.i18nc("@label Cura version number", "Cura version") + ":</b> " + str(self.cura_version) + "<br/>"
|
||||
crash_info += "<b>" + catalog.i18nc("@label Type of platform", "Platform") + ":</b> " + str(platform.platform()) + "<br/>"
|
||||
crash_info += "<b>" + catalog.i18nc("@label", "Qt version") + ":</b> " + str(QT_VERSION_STR) + "<br/>"
|
||||
crash_info += "<b>" + catalog.i18nc("@label", "PyQt version") + ":</b> " + str(PYQT_VERSION_STR) + "<br/>"
|
||||
crash_info += "<b>" + catalog.i18nc("@label OpenGL version", "OpenGL") + ":</b> " + str(self._getOpenGLInfo()) + "<br/>"
|
||||
label.setText(crash_info)
|
||||
|
||||
layout.addWidget(label)
|
||||
|
@ -126,13 +126,18 @@ class CrashHandler:
|
|||
return group
|
||||
|
||||
def _getOpenGLInfo(self):
|
||||
opengl_instance = OpenGL.getInstance()
|
||||
if not opengl_instance:
|
||||
self.data["opengl"] = {"version": "n/a", "vendor": "n/a", "type": "n/a"}
|
||||
return catalog.i18nc("@label", "not yet initialised<br/>")
|
||||
|
||||
info = "<ul>"
|
||||
info += catalog.i18nc("@label OpenGL version", "<li>OpenGL Version: {version}</li>").format(version = OpenGL.getInstance().getOpenGLVersion())
|
||||
info += catalog.i18nc("@label OpenGL vendor", "<li>OpenGL Vendor: {vendor}</li>").format(vendor = OpenGL.getInstance().getGPUVendorName())
|
||||
info += catalog.i18nc("@label OpenGL renderer", "<li>OpenGL Renderer: {renderer}</li>").format(renderer = OpenGL.getInstance().getGPUType())
|
||||
info += catalog.i18nc("@label OpenGL version", "<li>OpenGL Version: {version}</li>").format(version = opengl_instance.getOpenGLVersion())
|
||||
info += catalog.i18nc("@label OpenGL vendor", "<li>OpenGL Vendor: {vendor}</li>").format(vendor = opengl_instance.getGPUVendorName())
|
||||
info += catalog.i18nc("@label OpenGL renderer", "<li>OpenGL Renderer: {renderer}</li>").format(renderer = opengl_instance.getGPUType())
|
||||
info += "</ul>"
|
||||
|
||||
self.data["opengl"] = {"version": OpenGL.getInstance().getOpenGLVersion(), "vendor": OpenGL.getInstance().getGPUVendorName(), "type": OpenGL.getInstance().getGPUType()}
|
||||
self.data["opengl"] = {"version": opengl_instance.getOpenGLVersion(), "vendor": opengl_instance.getGPUVendorName(), "type": opengl_instance.getGPUType()}
|
||||
|
||||
return info
|
||||
|
||||
|
@ -280,5 +285,7 @@ class CrashHandler:
|
|||
Application.getInstance().callLater(self._show)
|
||||
|
||||
def _show(self):
|
||||
self.dialog.exec_()
|
||||
os._exit(1)
|
||||
# When the exception is not in the fatal_exception_types list, the dialog is not created, so we don't need to show it
|
||||
if self.dialog:
|
||||
self.dialog.exec_()
|
||||
os._exit(1)
|
||||
|
|
|
@ -105,7 +105,7 @@ class CuraApplication(QtApplication):
|
|||
# SettingVersion represents the set of settings available in the machine/extruder definitions.
|
||||
# You need to make sure that this version number needs to be increased if there is any non-backwards-compatible
|
||||
# changes of the settings.
|
||||
SettingVersion = 3
|
||||
SettingVersion = 4
|
||||
|
||||
class ResourceTypes:
|
||||
QmlFiles = Resources.UserType + 1
|
||||
|
@ -126,8 +126,6 @@ class CuraApplication(QtApplication):
|
|||
# Cura will always show the Add Machine Dialog upon start.
|
||||
stacksValidationFinished = pyqtSignal() # Emitted whenever a validation is finished
|
||||
|
||||
projectFileLoaded = pyqtSignal(str) # Emitted whenever a project file is loaded
|
||||
|
||||
def __init__(self):
|
||||
# this list of dir names will be used by UM to detect an old cura directory
|
||||
for dir_name in ["extruders", "machine_instances", "materials", "plugins", "quality", "user", "variants"]:
|
||||
|
@ -200,6 +198,7 @@ class CuraApplication(QtApplication):
|
|||
|
||||
self._machine_action_manager = MachineActionManager.MachineActionManager()
|
||||
self._machine_manager = None # This is initialized on demand.
|
||||
self._extruder_manager = None
|
||||
self._material_manager = None
|
||||
self._setting_inheritance_manager = None
|
||||
self._simple_mode_settings_manager = None
|
||||
|
@ -215,8 +214,9 @@ class CuraApplication(QtApplication):
|
|||
|
||||
self.setRequiredPlugins([
|
||||
"CuraEngineBackend",
|
||||
"UserAgreement",
|
||||
"SolidView",
|
||||
"LayerView",
|
||||
"SimulationView",
|
||||
"STLReader",
|
||||
"SelectionTool",
|
||||
"CameraTool",
|
||||
|
@ -259,20 +259,25 @@ class CuraApplication(QtApplication):
|
|||
# Since they are empty, they should never be serialized and instead just programmatically created.
|
||||
# We need them to simplify the switching between materials.
|
||||
empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
|
||||
empty_variant_container = copy.deepcopy(empty_container)
|
||||
empty_variant_container.setMetaDataEntry("id", "empty_variant")
|
||||
empty_variant_container.addMetaDataEntry("type", "variant")
|
||||
ContainerRegistry.getInstance().addContainer(empty_variant_container)
|
||||
|
||||
empty_material_container = copy.deepcopy(empty_container)
|
||||
empty_material_container.setMetaDataEntry("id", "empty_material")
|
||||
empty_material_container.addMetaDataEntry("type", "material")
|
||||
ContainerRegistry.getInstance().addContainer(empty_material_container)
|
||||
|
||||
empty_quality_container = copy.deepcopy(empty_container)
|
||||
empty_quality_container.setMetaDataEntry("id", "empty_quality")
|
||||
empty_quality_container.setName("Not Supported")
|
||||
empty_quality_container.addMetaDataEntry("quality_type", "normal")
|
||||
empty_quality_container.addMetaDataEntry("quality_type", "not_supported")
|
||||
empty_quality_container.addMetaDataEntry("type", "quality")
|
||||
empty_quality_container.addMetaDataEntry("supported", False)
|
||||
ContainerRegistry.getInstance().addContainer(empty_quality_container)
|
||||
|
||||
empty_quality_changes_container = copy.deepcopy(empty_container)
|
||||
empty_quality_changes_container.setMetaDataEntry("id", "empty_quality_changes")
|
||||
empty_quality_changes_container.addMetaDataEntry("type", "quality_changes")
|
||||
|
@ -303,6 +308,8 @@ class CuraApplication(QtApplication):
|
|||
|
||||
preferences.addPreference("view/invert_zoom", False)
|
||||
|
||||
self._need_to_show_user_agreement = not Preferences.getInstance().getValue("general/accepted_user_agreement")
|
||||
|
||||
for key in [
|
||||
"dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin
|
||||
"dialog_profile_path",
|
||||
|
@ -375,6 +382,14 @@ class CuraApplication(QtApplication):
|
|||
def _onEngineCreated(self):
|
||||
self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider())
|
||||
|
||||
@pyqtProperty(bool)
|
||||
def needToShowUserAgreement(self):
|
||||
return self._need_to_show_user_agreement
|
||||
|
||||
|
||||
def setNeedToShowUserAgreement(self, set_value = True):
|
||||
self._need_to_show_user_agreement = set_value
|
||||
|
||||
## The "Quit" button click event handler.
|
||||
@pyqtSlot()
|
||||
def closeApplication(self):
|
||||
|
@ -393,6 +408,7 @@ class CuraApplication(QtApplication):
|
|||
showDiscardOrKeepProfileChanges = pyqtSignal()
|
||||
|
||||
def discardOrKeepProfileChanges(self):
|
||||
has_user_interaction = False
|
||||
choice = Preferences.getInstance().getValue("cura/choice_on_profile_override")
|
||||
if choice == "always_discard":
|
||||
# don't show dialog and DISCARD the profile
|
||||
|
@ -403,18 +419,36 @@ class CuraApplication(QtApplication):
|
|||
else:
|
||||
# ALWAYS ask whether to keep or discard the profile
|
||||
self.showDiscardOrKeepProfileChanges.emit()
|
||||
has_user_interaction = True
|
||||
return has_user_interaction
|
||||
|
||||
#sidebarSimpleDiscardOrKeepProfileChanges = pyqtSignal()
|
||||
onDiscardOrKeepProfileChangesClosed = pyqtSignal() # Used to notify other managers that the dialog was closed
|
||||
|
||||
@pyqtSlot(str)
|
||||
def discardOrKeepProfileChangesClosed(self, option):
|
||||
if option == "discard":
|
||||
global_stack = self.getGlobalContainerStack()
|
||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
||||
for extruder in self._extruder_manager.getMachineExtruders(global_stack.getId()):
|
||||
extruder.getTop().clear()
|
||||
|
||||
global_stack.getTop().clear()
|
||||
|
||||
# if the user decided to keep settings then the user settings should be re-calculated and validated for errors
|
||||
# before slicing. To ensure that slicer uses right settings values
|
||||
elif option == "keep":
|
||||
global_stack = self.getGlobalContainerStack()
|
||||
for extruder in self._extruder_manager.getMachineExtruders(global_stack.getId()):
|
||||
user_extruder_container = extruder.getTop()
|
||||
if user_extruder_container:
|
||||
user_extruder_container.update()
|
||||
|
||||
user_global_container = global_stack.getTop()
|
||||
if user_global_container:
|
||||
user_global_container.update()
|
||||
|
||||
# notify listeners that quality has changed (after user selected discard or keep)
|
||||
self.onDiscardOrKeepProfileChangesClosed.emit()
|
||||
self.getMachineManager().activeQualityChanged.emit()
|
||||
|
||||
@pyqtSlot(int)
|
||||
def messageBoxClosed(self, button):
|
||||
if self._message_box_callback:
|
||||
|
@ -528,6 +562,7 @@ class CuraApplication(QtApplication):
|
|||
super().addCommandLineOptions(parser)
|
||||
parser.add_argument("file", nargs="*", help="Files to load after starting the application.")
|
||||
parser.add_argument("--single-instance", action="store_true", default=False)
|
||||
parser.add_argument("--headless", action = "store_true", default=False)
|
||||
|
||||
# Set up a local socket server which listener which coordinates single instances Curas and accepts commands.
|
||||
def _setUpSingleInstanceServer(self):
|
||||
|
@ -664,25 +699,25 @@ class CuraApplication(QtApplication):
|
|||
|
||||
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
|
||||
|
||||
# Initialise extruder so as to listen to global container stack changes before the first global container stack is set.
|
||||
ExtruderManager.getInstance()
|
||||
qmlRegisterSingletonType(ExtruderManager, "Cura", 1, 0, "ExtruderManager", self.getExtruderManager)
|
||||
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
|
||||
qmlRegisterSingletonType(MaterialManager, "Cura", 1, 0, "MaterialManager", self.getMaterialManager)
|
||||
qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager",
|
||||
self.getSettingInheritanceManager)
|
||||
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 2, "SimpleModeSettingsManager",
|
||||
self.getSimpleModeSettingsManager)
|
||||
|
||||
qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager", self.getSettingInheritanceManager)
|
||||
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 2, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager)
|
||||
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
||||
|
||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
||||
self.initializeEngine()
|
||||
|
||||
if self._engine.rootObjects:
|
||||
run_headless = self.getCommandLineOption("headless", False)
|
||||
if not run_headless:
|
||||
self.initializeEngine()
|
||||
|
||||
if run_headless or self._engine.rootObjects:
|
||||
self.closeSplash()
|
||||
|
||||
for file in self.getCommandLineOption("file", []):
|
||||
self._openFile(file)
|
||||
for file_name in self.getCommandLineOption("file", []):
|
||||
self._openFile(file_name)
|
||||
for file_name in self._open_file_queue: #Open all the files that were queued up while plug-ins were loading.
|
||||
self._openFile(file_name)
|
||||
|
||||
|
@ -695,6 +730,11 @@ class CuraApplication(QtApplication):
|
|||
self._machine_manager = MachineManager.createMachineManager()
|
||||
return self._machine_manager
|
||||
|
||||
def getExtruderManager(self, *args):
|
||||
if self._extruder_manager is None:
|
||||
self._extruder_manager = ExtruderManager.createExtruderManager()
|
||||
return self._extruder_manager
|
||||
|
||||
def getMaterialManager(self, *args):
|
||||
if self._material_manager is None:
|
||||
self._material_manager = MaterialManager.createMaterialManager()
|
||||
|
@ -745,7 +785,6 @@ class CuraApplication(QtApplication):
|
|||
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
|
||||
|
||||
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
||||
|
||||
qmlRegisterType(ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
|
||||
qmlRegisterSingletonType(ProfilesModel, "Cura", 1, 0, "ProfilesModel", ProfilesModel.createProfilesModel)
|
||||
qmlRegisterType(MaterialsModel, "Cura", 1, 0, "MaterialsModel")
|
||||
|
@ -755,15 +794,12 @@ class CuraApplication(QtApplication):
|
|||
qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
|
||||
qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator")
|
||||
qmlRegisterType(UserChangesModel, "Cura", 1, 1, "UserChangesModel")
|
||||
|
||||
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
|
||||
|
||||
# As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
|
||||
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
|
||||
qmlRegisterSingletonType(actions_url, "Cura", 1, 0, "Actions")
|
||||
|
||||
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.getInstance())
|
||||
|
||||
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
||||
type_name = os.path.splitext(os.path.basename(path))[0]
|
||||
if type_name in ("Cura", "Actions"):
|
||||
|
@ -1229,6 +1265,9 @@ class CuraApplication(QtApplication):
|
|||
# see GroupDecorator._onChildrenChanged
|
||||
|
||||
def _createSplashScreen(self):
|
||||
run_headless = self.getCommandLineOption("headless", False)
|
||||
if run_headless:
|
||||
return None
|
||||
return CuraSplashScreen.CuraSplashScreen()
|
||||
|
||||
def _onActiveMachineChanged(self):
|
||||
|
@ -1342,7 +1381,7 @@ class CuraApplication(QtApplication):
|
|||
|
||||
extension = os.path.splitext(filename)[1]
|
||||
if extension.lower() in self._non_sliceable_extensions:
|
||||
self.getController().setActiveView("LayerView")
|
||||
self.getController().setActiveView("SimulationView")
|
||||
view = self.getController().getActiveView()
|
||||
view.resetLayerData()
|
||||
view.setLayer(9999999)
|
||||
|
|
|
@ -47,12 +47,12 @@ class Layer:
|
|||
|
||||
return result
|
||||
|
||||
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices):
|
||||
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices):
|
||||
result_vertex_offset = vertex_offset
|
||||
result_index_offset = index_offset
|
||||
self._element_count = 0
|
||||
for polygon in self._polygons:
|
||||
polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, extruders, line_types, indices)
|
||||
polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices)
|
||||
result_vertex_offset += polygon.lineMeshVertexCount()
|
||||
result_index_offset += polygon.lineMeshElementCount()
|
||||
self._element_count += polygon.elementCount
|
||||
|
|
|
@ -20,11 +20,11 @@ class LayerDataBuilder(MeshBuilder):
|
|||
if layer not in self._layers:
|
||||
self._layers[layer] = Layer(layer)
|
||||
|
||||
def addPolygon(self, layer, polygon_type, data, line_width):
|
||||
def addPolygon(self, layer, polygon_type, data, line_width, line_thickness, line_feedrate):
|
||||
if layer not in self._layers:
|
||||
self.addLayer(layer)
|
||||
|
||||
p = LayerPolygon(self, polygon_type, data, line_width)
|
||||
p = LayerPolygon(self, polygon_type, data, line_width, line_thickness, line_feedrate)
|
||||
self._layers[layer].polygons.append(p)
|
||||
|
||||
def getLayer(self, layer):
|
||||
|
@ -64,13 +64,14 @@ class LayerDataBuilder(MeshBuilder):
|
|||
line_dimensions = numpy.empty((vertex_count, 2), numpy.float32)
|
||||
colors = numpy.empty((vertex_count, 4), numpy.float32)
|
||||
indices = numpy.empty((index_count, 2), numpy.int32)
|
||||
feedrates = numpy.empty((vertex_count), numpy.float32)
|
||||
extruders = numpy.empty((vertex_count), numpy.float32)
|
||||
line_types = numpy.empty((vertex_count), numpy.float32)
|
||||
|
||||
vertex_offset = 0
|
||||
index_offset = 0
|
||||
for layer, data in sorted(self._layers.items()):
|
||||
( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices)
|
||||
( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices)
|
||||
self._element_counts[layer] = data.elementCount
|
||||
|
||||
self.addVertices(vertices)
|
||||
|
@ -107,6 +108,11 @@ class LayerDataBuilder(MeshBuilder):
|
|||
"value": line_types,
|
||||
"opengl_name": "a_line_type",
|
||||
"opengl_type": "float"
|
||||
},
|
||||
"feedrates": {
|
||||
"value": feedrates,
|
||||
"opengl_name": "a_feedrate",
|
||||
"opengl_type": "float"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ class LayerPolygon:
|
|||
# \param data new_points
|
||||
# \param line_widths array with line widths
|
||||
# \param line_thicknesses: array with type as index and thickness as value
|
||||
def __init__(self, extruder, line_types, data, line_widths, line_thicknesses):
|
||||
# \param line_feedrates array with line feedrates
|
||||
def __init__(self, extruder, line_types, data, line_widths, line_thicknesses, line_feedrates):
|
||||
self._extruder = extruder
|
||||
self._types = line_types
|
||||
for i in range(len(self._types)):
|
||||
|
@ -37,6 +38,7 @@ class LayerPolygon:
|
|||
self._data = data
|
||||
self._line_widths = line_widths
|
||||
self._line_thicknesses = line_thicknesses
|
||||
self._line_feedrates = line_feedrates
|
||||
|
||||
self._vertex_begin = 0
|
||||
self._vertex_end = 0
|
||||
|
@ -84,10 +86,11 @@ class LayerPolygon:
|
|||
# \param vertices : vertex numpy array to be filled
|
||||
# \param colors : vertex numpy array to be filled
|
||||
# \param line_dimensions : vertex numpy array to be filled
|
||||
# \param feedrates : vertex numpy array to be filled
|
||||
# \param extruders : vertex numpy array to be filled
|
||||
# \param line_types : vertex numpy array to be filled
|
||||
# \param indices : index numpy array to be filled
|
||||
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices):
|
||||
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices):
|
||||
if self._build_cache_line_mesh_mask is None or self._build_cache_needed_points is None:
|
||||
self.buildCache()
|
||||
|
||||
|
@ -109,10 +112,13 @@ class LayerPolygon:
|
|||
# Create an array with colors for each vertex and remove the color data for the points that has been thrown away.
|
||||
colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()]
|
||||
|
||||
# Create an array with line widths for each vertex.
|
||||
# Create an array with line widths and thicknesses for each vertex.
|
||||
line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
||||
line_dimensions[self._vertex_begin:self._vertex_end, 1] = numpy.tile(self._line_thicknesses, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
||||
|
||||
# Create an array with feedrates for each line
|
||||
feedrates[self._vertex_begin:self._vertex_end] = numpy.tile(self._line_feedrates, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
||||
|
||||
extruders[self._vertex_begin:self._vertex_end] = self._extruder
|
||||
|
||||
# Convert type per vertex to type per line
|
||||
|
@ -166,6 +172,14 @@ class LayerPolygon:
|
|||
@property
|
||||
def lineWidths(self):
|
||||
return self._line_widths
|
||||
|
||||
@property
|
||||
def lineThicknesses(self):
|
||||
return self._line_thicknesses
|
||||
|
||||
@property
|
||||
def lineFeedrates(self):
|
||||
return self._line_feedrates
|
||||
|
||||
@property
|
||||
def jumpMask(self):
|
||||
|
|
|
@ -73,14 +73,8 @@ class MachineAction(QObject, PluginObject):
|
|||
|
||||
## Protected helper to create a view object based on provided QML.
|
||||
def _createViewFromQML(self):
|
||||
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._qml_url))
|
||||
self._component = QQmlComponent(Application.getInstance()._engine, path)
|
||||
self._context = QQmlContext(Application.getInstance()._engine.rootContext())
|
||||
self._context.setContextProperty("manager", self)
|
||||
self._view = self._component.create(self._context)
|
||||
if self._view is None:
|
||||
Logger.log("c", "QQmlComponent status %s", self._component.status())
|
||||
Logger.log("c", "QQmlComponent error string %s", self._component.errorString())
|
||||
path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._qml_url)
|
||||
self._view = Application.getInstance().createQmlComponent(path, {"manager": self})
|
||||
|
||||
@pyqtProperty(QObject, constant = True)
|
||||
def displayItem(self):
|
||||
|
|
57
cura/PreviewPass.py
Normal file
57
cura/PreviewPass.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Uranium is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Resources import Resources
|
||||
|
||||
from UM.View.RenderPass import RenderPass
|
||||
from UM.View.GL.OpenGL import OpenGL
|
||||
from UM.View.RenderBatch import RenderBatch
|
||||
|
||||
|
||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||
|
||||
from typing import Optional
|
||||
|
||||
MYPY = False
|
||||
if MYPY:
|
||||
from UM.Scene.Camera import Camera
|
||||
|
||||
## A render pass subclass that renders slicable objects with default parameters.
|
||||
# It uses the active camera by default, but it can be overridden to use a different camera.
|
||||
#
|
||||
# This is useful to get a preview image of a scene taken from a different location as the active camera.
|
||||
class PreviewPass(RenderPass):
|
||||
def __init__(self, width: int, height: int):
|
||||
super().__init__("preview", width, height, 0)
|
||||
|
||||
self._camera = None # type: Optional[Camera]
|
||||
|
||||
self._renderer = Application.getInstance().getRenderer()
|
||||
|
||||
self._shader = None
|
||||
self._scene = Application.getInstance().getController().getScene()
|
||||
|
||||
# Set the camera to be used by this render pass
|
||||
# if it's None, the active camera is used
|
||||
def setCamera(self, camera: Optional["Camera"]):
|
||||
self._camera = camera
|
||||
|
||||
def render(self) -> None:
|
||||
if not self._shader:
|
||||
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "object.shader"))
|
||||
|
||||
# Create a new batch to be rendered
|
||||
batch = RenderBatch(self._shader)
|
||||
|
||||
# Fill up the batch with objects that can be sliced. `
|
||||
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||
if node.callDecoration("isSliceable") and node.getMeshData() and node.isVisible():
|
||||
batch.addItem(node.getWorldTransformation(), node.getMeshData())
|
||||
|
||||
self.bind()
|
||||
if self._camera is None:
|
||||
batch.render(Application.getInstance().getController().getScene().getActiveCamera())
|
||||
else:
|
||||
batch.render(self._camera)
|
||||
self.release()
|
|
@ -56,6 +56,7 @@ class PrintInformation(QObject):
|
|||
self._material_lengths = []
|
||||
self._material_weights = []
|
||||
self._material_costs = []
|
||||
self._material_names = []
|
||||
|
||||
self._pre_sliced = False
|
||||
|
||||
|
@ -66,11 +67,10 @@ class PrintInformation(QObject):
|
|||
self._base_name = ""
|
||||
self._abbr_machine = ""
|
||||
self._job_name = ""
|
||||
self._project_name = ""
|
||||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._updateJobName)
|
||||
Application.getInstance().fileLoaded.connect(self.setBaseName)
|
||||
Application.getInstance().projectFileLoaded.connect(self.setProjectName)
|
||||
Application.getInstance().workspaceLoaded.connect(self.setProjectName)
|
||||
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
|
||||
|
||||
self._active_material_container = None
|
||||
|
@ -139,6 +139,12 @@ class PrintInformation(QObject):
|
|||
def materialCosts(self):
|
||||
return self._material_costs
|
||||
|
||||
materialNamesChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty("QVariantList", notify = materialNamesChanged)
|
||||
def materialNames(self):
|
||||
return self._material_names
|
||||
|
||||
def _onPrintDurationMessage(self, print_time, material_amounts):
|
||||
|
||||
self._updateTotalPrintTimePerFeature(print_time)
|
||||
|
@ -170,6 +176,7 @@ class PrintInformation(QObject):
|
|||
self._material_lengths = []
|
||||
self._material_weights = []
|
||||
self._material_costs = []
|
||||
self._material_names = []
|
||||
|
||||
material_preference_values = json.loads(Preferences.getInstance().getValue("cura/material_settings"))
|
||||
|
||||
|
@ -188,8 +195,10 @@ class PrintInformation(QObject):
|
|||
|
||||
weight = float(amount) * float(density) / 1000
|
||||
cost = 0
|
||||
material_name = catalog.i18nc("@label unknown material", "Unknown")
|
||||
if material:
|
||||
material_guid = material.getMetaDataEntry("GUID")
|
||||
material_name = material.getName()
|
||||
if material_guid in material_preference_values:
|
||||
material_values = material_preference_values[material_guid]
|
||||
|
||||
|
@ -208,10 +217,12 @@ class PrintInformation(QObject):
|
|||
self._material_weights.append(weight)
|
||||
self._material_lengths.append(length)
|
||||
self._material_costs.append(cost)
|
||||
self._material_names.append(material_name)
|
||||
|
||||
self.materialLengthsChanged.emit()
|
||||
self.materialWeightsChanged.emit()
|
||||
self.materialCostsChanged.emit()
|
||||
self.materialNamesChanged.emit()
|
||||
|
||||
def _onPreferencesChanged(self, preference):
|
||||
if preference != "cura/material_settings":
|
||||
|
@ -241,11 +252,6 @@ class PrintInformation(QObject):
|
|||
self._job_name = name
|
||||
self.jobNameChanged.emit()
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setProjectName(self, name):
|
||||
self._project_name = name
|
||||
self.setJobName(name)
|
||||
|
||||
jobNameChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty(str, notify = jobNameChanged)
|
||||
|
@ -253,11 +259,6 @@ class PrintInformation(QObject):
|
|||
return self._job_name
|
||||
|
||||
def _updateJobName(self):
|
||||
# if the project name is set, we use the project name as the job name, so the job name should not get updated
|
||||
# if a model file is loaded after that.
|
||||
if self._project_name != "":
|
||||
return
|
||||
|
||||
if self._base_name == "":
|
||||
self._job_name = ""
|
||||
self.jobNameChanged.emit()
|
||||
|
@ -283,7 +284,11 @@ class PrintInformation(QObject):
|
|||
return self._base_name
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setBaseName(self, base_name):
|
||||
def setProjectName(self, name):
|
||||
self.setBaseName(name, is_project_file = True)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setBaseName(self, base_name, is_project_file = False):
|
||||
# Ensure that we don't use entire path but only filename
|
||||
name = os.path.basename(base_name)
|
||||
|
||||
|
@ -291,11 +296,17 @@ class PrintInformation(QObject):
|
|||
# extension. This cuts the extension off if necessary.
|
||||
name = os.path.splitext(name)[0]
|
||||
|
||||
# if this is a profile file, always update the job name
|
||||
# name is "" when I first had some meshes and afterwards I deleted them so the naming should start again
|
||||
if name == "" or (self._base_name == "" and self._base_name != name):
|
||||
is_empty = name == ""
|
||||
if is_project_file or (is_empty or (self._base_name == "" and self._base_name != name)):
|
||||
# remove ".curaproject" suffix from (imported) the file name
|
||||
if name.endswith(".curaproject"):
|
||||
name = name[:name.rfind(".curaproject")]
|
||||
self._base_name = name
|
||||
self._updateJobName()
|
||||
|
||||
|
||||
## Created an acronymn-like abbreviated machine name from the currently active machine name
|
||||
# Called each time the global stack is switched
|
||||
def _setAbbreviatedMachineName(self):
|
||||
|
@ -313,7 +324,12 @@ class PrintInformation(QObject):
|
|||
elif word.isdigit():
|
||||
abbr_machine += word
|
||||
else:
|
||||
abbr_machine += self._stripAccents(word.strip("()[]{}#").upper())[0]
|
||||
stripped_word = self._stripAccents(word.strip("()[]{}#").upper())
|
||||
# - use only the first character if the word is too long (> 3 characters)
|
||||
# - use the whole word if it's not too long (<= 3 characters)
|
||||
if len(stripped_word) > 3:
|
||||
stripped_word = stripped_word[0]
|
||||
abbr_machine += stripped_word
|
||||
|
||||
self._abbr_machine = abbr_machine
|
||||
|
||||
|
@ -339,4 +355,3 @@ class PrintInformation(QObject):
|
|||
|
||||
temp_material_amounts = [0]
|
||||
self._onPrintDurationMessage(temp_message, temp_material_amounts)
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
self._can_pause = True
|
||||
self._can_abort = True
|
||||
self._can_pre_heat_bed = True
|
||||
self._can_control_manually = True
|
||||
|
||||
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
|
||||
raise NotImplementedError("requestWrite needs to be implemented")
|
||||
|
@ -144,6 +145,11 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
def canAbort(self):
|
||||
return self._can_abort
|
||||
|
||||
# Does the printer support manual control at all
|
||||
@pyqtProperty(bool, constant=True)
|
||||
def canControlManually(self):
|
||||
return self._can_control_manually
|
||||
|
||||
@pyqtProperty(QObject, constant=True)
|
||||
def monitorItem(self):
|
||||
# Note that we specifically only check if the monitor component is created.
|
||||
|
|
|
@ -86,7 +86,7 @@ class QualityManager:
|
|||
qualities = set(quality_type_dict.values())
|
||||
for material_container in material_containers[1:]:
|
||||
next_quality_type_dict = self.__fetchQualityTypeDictForMaterial(machine_definition, material_container)
|
||||
qualities.update(set(next_quality_type_dict.values()))
|
||||
qualities.intersection_update(set(next_quality_type_dict.values()))
|
||||
|
||||
return list(qualities)
|
||||
|
||||
|
@ -177,12 +177,16 @@ class QualityManager:
|
|||
def findAllUsableQualitiesForMachineAndExtruders(self, global_container_stack: "GlobalStack", extruder_stacks: List["ExtruderStack"]) -> List[InstanceContainer]:
|
||||
global_machine_definition = global_container_stack.getBottom()
|
||||
|
||||
if extruder_stacks:
|
||||
# Multi-extruder machine detected.
|
||||
materials = [stack.material for stack in extruder_stacks]
|
||||
else:
|
||||
# Machine with one extruder.
|
||||
materials = [global_container_stack.material]
|
||||
machine_manager = Application.getInstance().getMachineManager()
|
||||
active_stack_id = machine_manager.activeStackId
|
||||
|
||||
materials = []
|
||||
|
||||
for stack in extruder_stacks:
|
||||
if stack.getId() == active_stack_id and machine_manager.newMaterial:
|
||||
materials.append(machine_manager.newMaterial)
|
||||
else:
|
||||
materials.append(stack.material)
|
||||
|
||||
quality_types = self.findAllQualityTypesForMachineAndMaterials(global_machine_definition, materials)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import os
|
||||
import os.path
|
||||
import re
|
||||
import configparser
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
@ -17,8 +18,9 @@ from UM.Application import Application
|
|||
from UM.Logger import Logger
|
||||
from UM.Message import Message
|
||||
from UM.Platform import Platform
|
||||
from UM.PluginRegistry import PluginRegistry #For getting the possible profile writers to write with.
|
||||
from UM.PluginRegistry import PluginRegistry # For getting the possible profile writers to write with.
|
||||
from UM.Util import parseBool
|
||||
from UM.Resources import Resources
|
||||
|
||||
from . import ExtruderStack
|
||||
from . import GlobalStack
|
||||
|
@ -47,7 +49,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
container = self._convertContainerStack(container)
|
||||
|
||||
if isinstance(container, InstanceContainer) and type(container) != type(self.getEmptyInstanceContainer()):
|
||||
#Check against setting version of the definition.
|
||||
# Check against setting version of the definition.
|
||||
required_setting_version = CuraApplication.SettingVersion
|
||||
actual_setting_version = int(container.getMetaDataEntry("setting_version", default = 0))
|
||||
if required_setting_version != actual_setting_version:
|
||||
|
@ -256,7 +258,8 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
@override(ContainerRegistry)
|
||||
def load(self):
|
||||
super().load()
|
||||
self._fixupExtruders()
|
||||
self._registerSingleExtrusionMachinesExtruderStacks()
|
||||
self._connectUpgradedExtruderStacksToMachines()
|
||||
|
||||
## Update an imported profile to match the current machine configuration.
|
||||
#
|
||||
|
@ -298,11 +301,17 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
|
||||
machine_definition = Application.getInstance().getGlobalContainerStack().getBottom()
|
||||
del quality_type_criteria["definition"]
|
||||
materials = None
|
||||
|
||||
# materials = None
|
||||
|
||||
if "material" in quality_type_criteria:
|
||||
materials = ContainerRegistry.getInstance().findInstanceContainers(id = quality_type_criteria["material"])
|
||||
# materials = ContainerRegistry.getInstance().findInstanceContainers(id = quality_type_criteria["material"])
|
||||
del quality_type_criteria["material"]
|
||||
|
||||
# Do not filter quality containers here with materials because we are trying to import a profile, so it should
|
||||
# NOT be restricted by the active materials on the current machine.
|
||||
materials = None
|
||||
|
||||
# Check to make sure the imported profile actually makes sense in context of the current configuration.
|
||||
# This prevents issues where importing a "draft" profile for a machine without "draft" qualities would report as
|
||||
# successfully imported but then fail to show up.
|
||||
|
@ -356,8 +365,8 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
return global_container_stack.material.getId()
|
||||
return ""
|
||||
|
||||
## Returns true if the current machien requires its own quality profiles
|
||||
# \return true if the current machien requires its own quality profiles
|
||||
## Returns true if the current machine requires its own quality profiles
|
||||
# \return true if the current machine requires its own quality profiles
|
||||
def _machineHasOwnQualities(self):
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
|
@ -390,12 +399,135 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
|
||||
return new_stack
|
||||
|
||||
def _registerSingleExtrusionMachinesExtruderStacks(self):
|
||||
machines = self.findContainerStacks(type = "machine", machine_extruder_trains = {"0": "fdmextruder"})
|
||||
for machine in machines:
|
||||
extruder_stacks = self.findContainerStacks(type = "extruder_train", machine = machine.getId())
|
||||
if not extruder_stacks:
|
||||
self.addExtruderStackForSingleExtrusionMachine(machine, "fdmextruder")
|
||||
|
||||
def addExtruderStackForSingleExtrusionMachine(self, machine, extruder_id):
|
||||
new_extruder_id = extruder_id
|
||||
|
||||
extruder_definitions = self.findDefinitionContainers(id = new_extruder_id)
|
||||
if not extruder_definitions:
|
||||
Logger.log("w", "Could not find definition containers for extruder %s", new_extruder_id)
|
||||
return
|
||||
|
||||
extruder_definition = extruder_definitions[0]
|
||||
unique_name = self.uniqueName(machine.getName() + " " + new_extruder_id)
|
||||
|
||||
extruder_stack = ExtruderStack.ExtruderStack(unique_name)
|
||||
extruder_stack.setName(extruder_definition.getName())
|
||||
extruder_stack.setDefinition(extruder_definition)
|
||||
extruder_stack.addMetaDataEntry("position", extruder_definition.getMetaDataEntry("position"))
|
||||
extruder_stack.setNextStack(machine)
|
||||
|
||||
# create empty user changes container otherwise
|
||||
user_container = InstanceContainer(extruder_stack.id + "_user")
|
||||
user_container.addMetaDataEntry("type", "user")
|
||||
user_container.addMetaDataEntry("machine", extruder_stack.getId())
|
||||
from cura.CuraApplication import CuraApplication
|
||||
user_container.addMetaDataEntry("setting_version", CuraApplication.SettingVersion)
|
||||
user_container.setDefinition(machine.definition)
|
||||
|
||||
if machine.userChanges:
|
||||
# for the newly created extruder stack, we need to move all "per-extruder" settings to the user changes
|
||||
# container to the extruder stack.
|
||||
for user_setting_key in machine.userChanges.getAllKeys():
|
||||
settable_per_extruder = machine.getProperty(user_setting_key, "settable_per_extruder")
|
||||
if settable_per_extruder:
|
||||
user_container.addInstance(machine.userChanges.getInstance(user_setting_key))
|
||||
machine.userChanges.removeInstance(user_setting_key, postpone_emit = True)
|
||||
|
||||
extruder_stack.setUserChanges(user_container)
|
||||
self.addContainer(user_container)
|
||||
|
||||
variant_id = "default"
|
||||
if machine.variant.getId() not in ("empty", "empty_variant"):
|
||||
variant_id = machine.variant.getId()
|
||||
else:
|
||||
variant_id = "empty_variant"
|
||||
extruder_stack.setVariantById(variant_id)
|
||||
|
||||
material_id = "default"
|
||||
if machine.material.getId() not in ("empty", "empty_material"):
|
||||
material_id = machine.material.getId()
|
||||
else:
|
||||
material_id = "empty_material"
|
||||
extruder_stack.setMaterialById(material_id)
|
||||
|
||||
quality_id = "default"
|
||||
if machine.quality.getId() not in ("empty", "empty_quality"):
|
||||
quality_id = machine.quality.getId()
|
||||
else:
|
||||
quality_id = "empty_quality"
|
||||
extruder_stack.setQualityById(quality_id)
|
||||
|
||||
if machine.qualityChanges.getId() not in ("empty", "empty_quality_changes"):
|
||||
extruder_quality_changes_container = self.findInstanceContainers(name = machine.qualityChanges.getName(), extruder = extruder_id)
|
||||
if extruder_quality_changes_container:
|
||||
extruder_quality_changes_container = extruder_quality_changes_container[0]
|
||||
quality_changes_id = extruder_quality_changes_container.getId()
|
||||
extruder_stack.setQualityChangesById(quality_changes_id)
|
||||
else:
|
||||
# Some extruder quality_changes containers can be created at runtime as files in the qualities
|
||||
# folder. Those files won't be loaded in the registry immediately. So we also need to search
|
||||
# the folder to see if the quality_changes exists.
|
||||
extruder_quality_changes_container = self._findQualityChangesContainerInCuraFolder(machine.qualityChanges.getName())
|
||||
if extruder_quality_changes_container:
|
||||
quality_changes_id = extruder_quality_changes_container.getId()
|
||||
extruder_stack.setQualityChangesById(quality_changes_id)
|
||||
|
||||
if not extruder_quality_changes_container:
|
||||
Logger.log("w", "Could not find quality_changes named [%s] for extruder [%s]",
|
||||
machine.qualityChanges.getName(), extruder_stack.getId())
|
||||
else:
|
||||
extruder_stack.setQualityChangesById("empty_quality_changes")
|
||||
|
||||
self.addContainer(extruder_stack)
|
||||
|
||||
return extruder_stack
|
||||
|
||||
def _findQualityChangesContainerInCuraFolder(self, name):
|
||||
quality_changes_dir = Resources.getPath(CuraApplication.ResourceTypes.QualityInstanceContainer)
|
||||
|
||||
instance_container = None
|
||||
|
||||
for item in os.listdir(quality_changes_dir):
|
||||
file_path = os.path.join(quality_changes_dir, item)
|
||||
if not os.path.isfile(file_path):
|
||||
continue
|
||||
|
||||
parser = configparser.ConfigParser()
|
||||
try:
|
||||
parser.read([file_path])
|
||||
except:
|
||||
# skip, it is not a valid stack file
|
||||
continue
|
||||
|
||||
if not parser.has_option("general", "name"):
|
||||
continue
|
||||
|
||||
if parser["general"]["name"] == name:
|
||||
# load the container
|
||||
container_id = os.path.basename(file_path).replace(".inst.cfg", "")
|
||||
|
||||
instance_container = InstanceContainer(container_id)
|
||||
with open(file_path, "r") as f:
|
||||
serialized = f.read()
|
||||
instance_container.deserialize(serialized, file_path)
|
||||
self.addContainer(instance_container)
|
||||
break
|
||||
|
||||
return instance_container
|
||||
|
||||
# Fix the extruders that were upgraded to ExtruderStack instances during addContainer.
|
||||
# The stacks are now responsible for setting the next stack on deserialize. However,
|
||||
# due to problems with loading order, some stacks may not have the proper next stack
|
||||
# set after upgrading, because the proper global stack was not yet loaded. This method
|
||||
# makes sure those extruders also get the right stack set.
|
||||
def _fixupExtruders(self):
|
||||
def _connectUpgradedExtruderStacksToMachines(self):
|
||||
extruder_stacks = self.findContainers(container_type = ExtruderStack.ExtruderStack)
|
||||
for extruder_stack in extruder_stacks:
|
||||
if extruder_stack.getNextStack():
|
||||
|
|
|
@ -41,9 +41,20 @@ class CuraContainerStack(ContainerStack):
|
|||
def __init__(self, container_id: str, *args, **kwargs):
|
||||
super().__init__(container_id, *args, **kwargs)
|
||||
|
||||
self._empty_instance_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._container_registry = ContainerRegistry.getInstance()
|
||||
|
||||
self._empty_instance_container = self._container_registry.getEmptyInstanceContainer()
|
||||
|
||||
self._empty_quality_changes = self._container_registry.findInstanceContainers(id = "empty_quality_changes")[0]
|
||||
self._empty_quality = self._container_registry.findInstanceContainers(id = "empty_quality")[0]
|
||||
self._empty_material = self._container_registry.findInstanceContainers(id = "empty_material")[0]
|
||||
self._empty_variant = self._container_registry.findInstanceContainers(id = "empty_variant")[0]
|
||||
|
||||
self._containers = [self._empty_instance_container for i in range(len(_ContainerIndexes.IndexTypeMap))]
|
||||
self._containers[_ContainerIndexes.QualityChanges] = self._empty_quality_changes
|
||||
self._containers[_ContainerIndexes.Quality] = self._empty_quality
|
||||
self._containers[_ContainerIndexes.Material] = self._empty_material
|
||||
self._containers[_ContainerIndexes.Variant] = self._empty_variant
|
||||
|
||||
self.containersChanged.connect(self._onContainersChanged)
|
||||
|
||||
|
@ -110,7 +121,7 @@ class CuraContainerStack(ContainerStack):
|
|||
#
|
||||
# \throws Exceptions.InvalidContainerError Raised when no container could be found with the specified ID.
|
||||
def setQualityById(self, new_quality_id: str) -> None:
|
||||
quality = self._empty_instance_container
|
||||
quality = self._empty_quality
|
||||
if new_quality_id == "default":
|
||||
new_quality = self.findDefaultQuality()
|
||||
if new_quality:
|
||||
|
@ -148,7 +159,7 @@ class CuraContainerStack(ContainerStack):
|
|||
#
|
||||
# \throws Exceptions.InvalidContainerError Raised when no container could be found with the specified ID.
|
||||
def setMaterialById(self, new_material_id: str) -> None:
|
||||
material = self._empty_instance_container
|
||||
material = self._empty_material
|
||||
if new_material_id == "default":
|
||||
new_material = self.findDefaultMaterial()
|
||||
if new_material:
|
||||
|
@ -186,7 +197,7 @@ class CuraContainerStack(ContainerStack):
|
|||
#
|
||||
# \throws Exceptions.InvalidContainerError Raised when no container could be found with the specified ID.
|
||||
def setVariantById(self, new_variant_id: str) -> None:
|
||||
variant = self._empty_instance_container
|
||||
variant = self._empty_variant
|
||||
if new_variant_id == "default":
|
||||
new_variant = self.findDefaultVariant()
|
||||
if new_variant:
|
||||
|
@ -348,8 +359,8 @@ class CuraContainerStack(ContainerStack):
|
|||
#
|
||||
# \throws InvalidContainerStackError Raised when no definition can be found for the stack.
|
||||
@override(ContainerStack)
|
||||
def deserialize(self, contents: str) -> None:
|
||||
super().deserialize(contents)
|
||||
def deserialize(self, contents: str, file_name: Optional[str] = None) -> None:
|
||||
super().deserialize(contents, file_name)
|
||||
|
||||
new_containers = self._containers.copy()
|
||||
while len(new_containers) < len(_ContainerIndexes.IndexTypeMap):
|
||||
|
@ -396,7 +407,9 @@ class CuraContainerStack(ContainerStack):
|
|||
# \note This method assumes the stack has a valid machine definition.
|
||||
def findDefaultVariant(self) -> Optional[ContainerInterface]:
|
||||
definition = self._getMachineDefinition()
|
||||
if not definition.getMetaDataEntry("has_variants"):
|
||||
# has_variants can be overridden in other containers and stacks.
|
||||
# In the case of UM2, it is overridden in the GlobalStack
|
||||
if not self.getMetaDataEntry("has_variants"):
|
||||
# If the machine does not use variants, we should never set a variant.
|
||||
return None
|
||||
|
||||
|
@ -454,7 +467,7 @@ class CuraContainerStack(ContainerStack):
|
|||
else:
|
||||
search_criteria["definition"] = "fdmprinter"
|
||||
|
||||
if self.material != self._empty_instance_container:
|
||||
if self.material != self._empty_material:
|
||||
search_criteria["name"] = self.material.name
|
||||
else:
|
||||
preferred_material = definition.getMetaDataEntry("preferred_material")
|
||||
|
@ -501,7 +514,7 @@ class CuraContainerStack(ContainerStack):
|
|||
else:
|
||||
search_criteria["definition"] = "fdmprinter"
|
||||
|
||||
if self.quality != self._empty_instance_container:
|
||||
if self.quality != self._empty_quality:
|
||||
search_criteria["name"] = self.quality.name
|
||||
else:
|
||||
preferred_quality = definition.getMetaDataEntry("preferred_quality")
|
||||
|
|
|
@ -47,12 +47,12 @@ class CuraStackBuilder:
|
|||
|
||||
new_global_stack.setName(generated_name)
|
||||
|
||||
for extruder_definition in registry.findDefinitionContainers(machine = machine_definition.id):
|
||||
position = extruder_definition.getMetaDataEntry("position", None)
|
||||
if not position:
|
||||
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.id)
|
||||
extruder_definition = registry.findDefinitionContainers(machine = machine_definition.getId())
|
||||
|
||||
new_extruder_id = registry.uniqueName(extruder_definition.id)
|
||||
if not extruder_definition:
|
||||
# create extruder stack for single extrusion machines that have no separate extruder definition files
|
||||
extruder_definition = registry.findDefinitionContainers(id = "fdmextruder")[0]
|
||||
new_extruder_id = registry.uniqueName(machine_definition.getName() + " " + extruder_definition.id)
|
||||
new_extruder = cls.createExtruderStack(
|
||||
new_extruder_id,
|
||||
definition = extruder_definition,
|
||||
|
@ -62,6 +62,25 @@ class CuraStackBuilder:
|
|||
variant = "default",
|
||||
next_stack = new_global_stack
|
||||
)
|
||||
new_global_stack.addExtruder(new_extruder)
|
||||
else:
|
||||
# create extruder stack for each found extruder definition
|
||||
for extruder_definition in registry.findDefinitionContainers(machine = machine_definition.id):
|
||||
position = extruder_definition.getMetaDataEntry("position", None)
|
||||
if not position:
|
||||
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.id)
|
||||
|
||||
new_extruder_id = registry.uniqueName(extruder_definition.id)
|
||||
new_extruder = cls.createExtruderStack(
|
||||
new_extruder_id,
|
||||
definition = extruder_definition,
|
||||
machine_definition_id = machine_definition.getId(),
|
||||
quality = "default",
|
||||
material = "default",
|
||||
variant = "default",
|
||||
next_stack = new_global_stack
|
||||
)
|
||||
new_global_stack.addExtruder(new_extruder)
|
||||
|
||||
return new_global_stack
|
||||
|
||||
|
@ -80,7 +99,9 @@ class CuraStackBuilder:
|
|||
stack.setName(definition.getName())
|
||||
stack.setDefinition(definition)
|
||||
stack.addMetaDataEntry("position", definition.getMetaDataEntry("position"))
|
||||
if "next_stack" in kwargs: #Add stacks before containers are added, since they may trigger a setting update.
|
||||
|
||||
if "next_stack" in kwargs:
|
||||
# Add stacks before containers are added, since they may trigger a setting update.
|
||||
stack.setNextStack(kwargs["next_stack"])
|
||||
|
||||
user_container = InstanceContainer(new_stack_id + "_user")
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant #For communicating data and events to Qt.
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant # For communicating data and events to Qt.
|
||||
from UM.FlameProfiler import pyqtSlot
|
||||
|
||||
from UM.Application import Application #To get the global container stack to find the current machine.
|
||||
from UM.Application import Application # To get the global container stack to find the current machine.
|
||||
from UM.Logger import Logger
|
||||
from UM.Decorators import deprecated
|
||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from UM.Scene.Selection import Selection
|
||||
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry #Finding containers by ID.
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry # Finding containers by ID.
|
||||
from UM.Settings.SettingFunction import SettingFunction
|
||||
from UM.Settings.ContainerStack import ContainerStack
|
||||
from UM.Settings.Interfaces import DefinitionContainerInterface
|
||||
from UM.Settings.PropertyEvaluationContext import PropertyEvaluationContext
|
||||
from typing import Optional, List, TYPE_CHECKING, Union
|
||||
|
||||
|
@ -28,6 +25,20 @@ if TYPE_CHECKING:
|
|||
#
|
||||
# This keeps a list of extruder stacks for each machine.
|
||||
class ExtruderManager(QObject):
|
||||
|
||||
## Registers listeners and such to listen to changes to the extruders.
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
|
||||
self._extruder_trains = {} # Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders.
|
||||
self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack
|
||||
self._selected_object_extruders = []
|
||||
self._global_container_stack_definition_id = None
|
||||
self._addCurrentMachineExtruders()
|
||||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
||||
Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
|
||||
|
||||
## Signal to notify other components when the list of extruders for a machine definition changes.
|
||||
extrudersChanged = pyqtSignal(QVariant)
|
||||
|
||||
|
@ -38,18 +49,6 @@ class ExtruderManager(QObject):
|
|||
## Notify when the user switches the currently active extruder.
|
||||
activeExtruderChanged = pyqtSignal()
|
||||
|
||||
## Registers listeners and such to listen to changes to the extruders.
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders.
|
||||
self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack
|
||||
self._selected_object_extruders = []
|
||||
Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
||||
self._global_container_stack_definition_id = None
|
||||
self._addCurrentMachineExtruders()
|
||||
|
||||
Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
|
||||
|
||||
## Gets the unique identifier of the currently active extruder stack.
|
||||
#
|
||||
# The currently active extruder stack is the stack that is currently being
|
||||
|
@ -59,10 +58,10 @@ class ExtruderManager(QObject):
|
|||
@pyqtProperty(str, notify = activeExtruderChanged)
|
||||
def activeExtruderStackId(self) -> Optional[str]:
|
||||
if not Application.getInstance().getGlobalContainerStack():
|
||||
return None # No active machine, so no active extruder.
|
||||
return None # No active machine, so no active extruder.
|
||||
try:
|
||||
return self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][str(self._active_extruder_index)].getId()
|
||||
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
|
||||
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
|
||||
return None
|
||||
|
||||
## Return extruder count according to extruder trains.
|
||||
|
@ -76,23 +75,23 @@ class ExtruderManager(QObject):
|
|||
return 0
|
||||
|
||||
## Gets a dict with the extruder stack ids with the extruder number as the key.
|
||||
# The key "-1" indicates the global stack id.
|
||||
#
|
||||
@pyqtProperty("QVariantMap", notify = extrudersChanged)
|
||||
def extruderIds(self):
|
||||
extruder_stack_ids = {}
|
||||
|
||||
global_stack_id = Application.getInstance().getGlobalContainerStack().getId()
|
||||
extruder_stack_ids["-1"] = global_stack_id
|
||||
|
||||
if global_stack_id in self._extruder_trains:
|
||||
for position in self._extruder_trains[global_stack_id]:
|
||||
extruder_stack_ids[position] = self._extruder_trains[global_stack_id][position].getId()
|
||||
|
||||
return extruder_stack_ids
|
||||
|
||||
@pyqtSlot(str, result = str)
|
||||
def getQualityChangesIdByExtruderStackId(self, id: str) -> str:
|
||||
def getQualityChangesIdByExtruderStackId(self, extruder_stack_id: str) -> str:
|
||||
for position in self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()]:
|
||||
extruder = self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][position]
|
||||
if extruder.getId() == id:
|
||||
if extruder.getId() == extruder_stack_id:
|
||||
return extruder.qualityChanges.getId()
|
||||
|
||||
## The instance of the singleton pattern.
|
||||
|
@ -100,6 +99,10 @@ class ExtruderManager(QObject):
|
|||
# It's None if the extruder manager hasn't been created yet.
|
||||
__instance = None
|
||||
|
||||
@staticmethod
|
||||
def createExtruderManager():
|
||||
return ExtruderManager().getInstance()
|
||||
|
||||
## Gets an instance of the extruder manager, or creates one if no instance
|
||||
# exists yet.
|
||||
#
|
||||
|
@ -185,6 +188,7 @@ class ExtruderManager(QObject):
|
|||
if global_container_stack.getId() in self._extruder_trains:
|
||||
if str(self._active_extruder_index) in self._extruder_trains[global_container_stack.getId()]:
|
||||
return self._extruder_trains[global_container_stack.getId()][str(self._active_extruder_index)]
|
||||
|
||||
return None
|
||||
|
||||
## Get an extruder stack by index
|
||||
|
@ -203,40 +207,6 @@ class ExtruderManager(QObject):
|
|||
result.append(self.getExtruderStack(i))
|
||||
return result
|
||||
|
||||
## Adds all extruders of a specific machine definition to the extruder
|
||||
# manager.
|
||||
#
|
||||
# \param machine_definition The machine definition to add the extruders for.
|
||||
# \param machine_id The machine_id to add the extruders for.
|
||||
@deprecated("Use CuraStackBuilder", "2.6")
|
||||
def addMachineExtruders(self, machine_definition: DefinitionContainerInterface, machine_id: str) -> None:
|
||||
changed = False
|
||||
machine_definition_id = machine_definition.getId()
|
||||
if machine_id not in self._extruder_trains:
|
||||
self._extruder_trains[machine_id] = { }
|
||||
changed = True
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
if container_registry:
|
||||
# Add the extruder trains that don't exist yet.
|
||||
for extruder_definition in container_registry.findDefinitionContainers(machine = machine_definition_id):
|
||||
position = extruder_definition.getMetaDataEntry("position", None)
|
||||
if not position:
|
||||
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
||||
if not container_registry.findContainerStacksMetadata(machine = machine_id, position = position): # Doesn't exist yet.
|
||||
self.createExtruderTrain(extruder_definition, machine_definition, position, machine_id)
|
||||
changed = True
|
||||
|
||||
# Gets the extruder trains that we just created as well as any that still existed.
|
||||
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = machine_id)
|
||||
for extruder_train in extruder_trains:
|
||||
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train
|
||||
|
||||
# regardless of what the next stack is, we have to set it again, because of signal routing.
|
||||
extruder_train.setNextStack(Application.getInstance().getGlobalContainerStack())
|
||||
changed = True
|
||||
if changed:
|
||||
self.extrudersChanged.emit(machine_id)
|
||||
|
||||
def registerExtruder(self, extruder_train, machine_id):
|
||||
changed = False
|
||||
|
||||
|
@ -256,138 +226,6 @@ class ExtruderManager(QObject):
|
|||
if changed:
|
||||
self.extrudersChanged.emit(machine_id)
|
||||
|
||||
## Creates a container stack for an extruder train.
|
||||
#
|
||||
# The container stack has an extruder definition at the bottom, which is
|
||||
# linked to a machine definition. Then it has a variant profile, a material
|
||||
# profile, a quality profile and a user profile, in that order.
|
||||
#
|
||||
# The resulting container stack is added to the registry.
|
||||
#
|
||||
# \param extruder_definition The extruder to create the extruder train for.
|
||||
# \param machine_definition The machine that the extruder train belongs to.
|
||||
# \param position The position of this extruder train in the extruder slots of the machine.
|
||||
# \param machine_id The id of the "global" stack this extruder is linked to.
|
||||
@deprecated("Use CuraStackBuilder::createExtruderStack", "2.6")
|
||||
def createExtruderTrain(self, extruder_definition: DefinitionContainerInterface, machine_definition: DefinitionContainerInterface,
|
||||
position, machine_id: str) -> None:
|
||||
# Cache some things.
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_definition_id = Application.getInstance().getMachineManager().getQualityDefinitionId(machine_definition)
|
||||
|
||||
# Create a container stack for this extruder.
|
||||
extruder_stack_id = container_registry.uniqueName(extruder_definition.getId())
|
||||
container_stack = ContainerStack(extruder_stack_id)
|
||||
container_stack.setName(extruder_definition.getName()) # Take over the display name to display the stack with.
|
||||
container_stack.addMetaDataEntry("type", "extruder_train")
|
||||
container_stack.addMetaDataEntry("machine", machine_id)
|
||||
container_stack.addMetaDataEntry("position", position)
|
||||
container_stack.addContainer(extruder_definition)
|
||||
|
||||
# Find the variant to use for this extruder.
|
||||
variant = container_registry.findInstanceContainers(id = "empty_variant")[0]
|
||||
if machine_definition.getMetaDataEntry("has_variants"):
|
||||
# First add any variant. Later, overwrite with preference if the preference is valid.
|
||||
variants = container_registry.findInstanceContainers(definition = machine_definition_id, type = "variant")
|
||||
if len(variants) >= 1:
|
||||
variant = variants[0]
|
||||
preferred_variant_id = machine_definition.getMetaDataEntry("preferred_variant")
|
||||
if preferred_variant_id:
|
||||
preferred_variants = container_registry.findInstanceContainers(id = preferred_variant_id, definition = machine_definition_id, type = "variant")
|
||||
if len(preferred_variants) >= 1:
|
||||
variant = preferred_variants[0]
|
||||
else:
|
||||
Logger.log("w", "The preferred variant \"%s\" of machine %s doesn't exist or is not a variant profile.", preferred_variant_id, machine_id)
|
||||
# And leave it at the default variant.
|
||||
container_stack.addContainer(variant)
|
||||
|
||||
# Find a material to use for this variant.
|
||||
material = container_registry.findInstanceContainers(id = "empty_material")[0]
|
||||
if machine_definition.getMetaDataEntry("has_materials"):
|
||||
# First add any material. Later, overwrite with preference if the preference is valid.
|
||||
machine_has_variant_materials = machine_definition.getMetaDataEntry("has_variant_materials", default = False)
|
||||
if machine_has_variant_materials or machine_has_variant_materials == "True":
|
||||
materials = container_registry.findInstanceContainers(type = "material", definition = machine_definition_id, variant = variant.getId())
|
||||
else:
|
||||
materials = container_registry.findInstanceContainers(type = "material", definition = machine_definition_id)
|
||||
if len(materials) >= 1:
|
||||
material = materials[0]
|
||||
preferred_material_id = machine_definition.getMetaDataEntry("preferred_material")
|
||||
if preferred_material_id:
|
||||
global_stack = ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||
if global_stack:
|
||||
approximate_material_diameter = str(round(global_stack[0].getProperty("material_diameter", "value")))
|
||||
else:
|
||||
approximate_material_diameter = str(round(machine_definition.getProperty("material_diameter", "value")))
|
||||
|
||||
search_criteria = { "type": "material", "id": preferred_material_id, "approximate_diameter": approximate_material_diameter}
|
||||
if machine_definition.getMetaDataEntry("has_machine_materials"):
|
||||
search_criteria["definition"] = machine_definition_id
|
||||
|
||||
if machine_definition.getMetaDataEntry("has_variants") and variant:
|
||||
search_criteria["variant"] = variant.id
|
||||
else:
|
||||
search_criteria["definition"] = "fdmprinter"
|
||||
|
||||
preferred_materials = container_registry.findInstanceContainers(**search_criteria)
|
||||
if len(preferred_materials) >= 1:
|
||||
# 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 container_registry.isReadOnly(preferred_material.getId())]
|
||||
if len(read_only_preferred_materials) >= 1:
|
||||
material = read_only_preferred_materials[0]
|
||||
else:
|
||||
material = preferred_materials[0]
|
||||
else:
|
||||
Logger.log("w", "The preferred material \"%s\" of machine %s doesn't exist or is not a material profile.", preferred_material_id, machine_id)
|
||||
# And leave it at the default material.
|
||||
container_stack.addContainer(material)
|
||||
|
||||
# Find a quality to use for this extruder.
|
||||
quality = container_registry.getEmptyInstanceContainer()
|
||||
|
||||
search_criteria = { "type": "quality" }
|
||||
if machine_definition.getMetaDataEntry("has_machine_quality"):
|
||||
search_criteria["definition"] = machine_definition_id
|
||||
if machine_definition.getMetaDataEntry("has_materials") and material:
|
||||
search_criteria["material"] = material.id
|
||||
else:
|
||||
search_criteria["definition"] = "fdmprinter"
|
||||
|
||||
preferred_quality = machine_definition.getMetaDataEntry("preferred_quality")
|
||||
if preferred_quality:
|
||||
search_criteria["id"] = preferred_quality
|
||||
|
||||
quality_containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||
if not quality_containers and preferred_quality:
|
||||
Logger.log("w", "The preferred quality \"%s\" of machine %s doesn't exist or is not a quality profile.", preferred_quality, machine_id)
|
||||
search_criteria.pop("id", None)
|
||||
quality_containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||
if quality_containers:
|
||||
quality = quality_containers[0]
|
||||
|
||||
container_stack.addContainer(quality)
|
||||
|
||||
empty_quality_changes = container_registry.findInstanceContainers(id = "empty_quality_changes")[0]
|
||||
container_stack.addContainer(empty_quality_changes)
|
||||
|
||||
user_profile = container_registry.findInstanceContainers(type = "user", extruder = extruder_stack_id)
|
||||
if user_profile: # There was already a user profile, loaded from settings.
|
||||
user_profile = user_profile[0]
|
||||
else:
|
||||
user_profile = InstanceContainer(extruder_stack_id + "_current_settings") # Add an empty user profile.
|
||||
user_profile.addMetaDataEntry("type", "user")
|
||||
user_profile.addMetaDataEntry("extruder", extruder_stack_id)
|
||||
from cura.CuraApplication import CuraApplication
|
||||
user_profile.addMetaDataEntry("setting_version", CuraApplication.SettingVersion)
|
||||
user_profile.setDefinition(machine_definition.getId())
|
||||
container_registry.addContainer(user_profile)
|
||||
container_stack.addContainer(user_profile)
|
||||
|
||||
# regardless of what the next stack is, we have to set it again, because of signal routing.
|
||||
container_stack.setNextStack(Application.getInstance().getGlobalContainerStack())
|
||||
|
||||
container_registry.addContainer(container_stack)
|
||||
|
||||
def getAllExtruderValues(self, setting_key):
|
||||
return self.getAllExtruderSettings(setting_key, "value")
|
||||
|
||||
|
@ -396,16 +234,12 @@ class ExtruderManager(QObject):
|
|||
# \param setting_key \type{str} The setting to get the property of.
|
||||
# \param property \type{str} The property to get.
|
||||
# \return \type{List} the list of results
|
||||
def getAllExtruderSettings(self, setting_key, property):
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack.getProperty("machine_extruder_count", "value") <= 1:
|
||||
return [global_container_stack.getProperty(setting_key, property)]
|
||||
|
||||
def getAllExtruderSettings(self, setting_key: str, prop: str):
|
||||
result = []
|
||||
for index in self.extruderIds:
|
||||
extruder_stack_id = self.extruderIds[str(index)]
|
||||
stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
||||
result.append(stack.getProperty(setting_key, property))
|
||||
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
||||
result.append(extruder_stack.getProperty(setting_key, prop))
|
||||
return result
|
||||
|
||||
## Gets the extruder stacks that are actually being used at the moment.
|
||||
|
@ -422,20 +256,25 @@ class ExtruderManager(QObject):
|
|||
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
|
||||
if global_stack.getProperty("machine_extruder_count", "value") <= 1: #For single extrusion.
|
||||
return [global_stack]
|
||||
|
||||
used_extruder_stack_ids = set()
|
||||
|
||||
#Get the extruders of all meshes in the scene.
|
||||
# Get the extruders of all meshes in the scene
|
||||
support_enabled = False
|
||||
support_bottom_enabled = False
|
||||
support_roof_enabled = False
|
||||
|
||||
scene_root = Application.getInstance().getController().getScene().getRoot()
|
||||
meshes = [node for node in DepthFirstIterator(scene_root) if type(node) is SceneNode and node.isSelectable()] #Only use the nodes that will be printed.
|
||||
|
||||
# If no extruders are registered in the extruder manager yet, return an empty array
|
||||
if len(self.extruderIds) == 0:
|
||||
return []
|
||||
|
||||
# Get the extruders of all printable meshes in the scene
|
||||
meshes = [node for node in DepthFirstIterator(scene_root) if type(node) is SceneNode and node.isSelectable()]
|
||||
for mesh in meshes:
|
||||
extruder_stack_id = mesh.callDecoration("getActiveExtruder")
|
||||
if not extruder_stack_id: #No per-object settings for this node.
|
||||
if not extruder_stack_id:
|
||||
# No per-object settings for this node
|
||||
extruder_stack_id = self.extruderIds["0"]
|
||||
used_extruder_stack_ids.add(extruder_stack_id)
|
||||
|
||||
|
@ -471,9 +310,10 @@ class ExtruderManager(QObject):
|
|||
if support_roof_enabled:
|
||||
used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_roof_extruder_nr", "value"))])
|
||||
|
||||
#The platform adhesion extruder. Not used if using none.
|
||||
# The platform adhesion extruder. Not used if using none.
|
||||
if global_stack.getProperty("adhesion_type", "value") != "none":
|
||||
used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("adhesion_extruder_nr", "value"))])
|
||||
|
||||
try:
|
||||
return [container_registry.findContainerStacks(id = stack_id)[0] for stack_id in used_extruder_stack_ids]
|
||||
except IndexError: # One or more of the extruders was not found.
|
||||
|
@ -520,10 +360,6 @@ class ExtruderManager(QObject):
|
|||
result = []
|
||||
machine_extruder_count = global_stack.getProperty("machine_extruder_count", "value")
|
||||
|
||||
# In case the printer is using one extruder, shouldn't exist active extruder stacks
|
||||
if machine_extruder_count == 1:
|
||||
return result
|
||||
|
||||
if global_stack and global_stack.getId() in self._extruder_trains:
|
||||
for extruder in sorted(self._extruder_trains[global_stack.getId()]):
|
||||
result.append(self._extruder_trains[global_stack.getId()][extruder])
|
||||
|
@ -536,24 +372,39 @@ class ExtruderManager(QObject):
|
|||
self._global_container_stack_definition_id = global_container_stack.getBottom().getId()
|
||||
self.globalContainerStackDefinitionChanged.emit()
|
||||
|
||||
# If the global container changed, the number of extruders could be changed and so the active_extruder_index is updated
|
||||
extruder_count = global_container_stack.getProperty("machine_extruder_count", "value")
|
||||
if extruder_count > 1:
|
||||
if self._active_extruder_index == -1:
|
||||
self.setActiveExtruderIndex(0)
|
||||
else:
|
||||
if self._active_extruder_index != -1:
|
||||
self.setActiveExtruderIndex(-1)
|
||||
|
||||
self.activeExtruderChanged.emit()
|
||||
# If the global container changed, the machine changed and might have extruders that were not registered yet
|
||||
self._addCurrentMachineExtruders()
|
||||
|
||||
self.resetSelectedObjectExtruders()
|
||||
|
||||
## Adds the extruders of the currently active machine.
|
||||
def _addCurrentMachineExtruders(self) -> None:
|
||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_stack and global_stack.getBottom():
|
||||
self.addMachineExtruders(global_stack.getBottom(), global_stack.getId())
|
||||
extruders_changed = False
|
||||
|
||||
if global_stack:
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
global_stack_id = global_stack.getId()
|
||||
|
||||
# Gets the extruder trains that we just created as well as any that still existed.
|
||||
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = global_stack_id)
|
||||
|
||||
# Make sure the extruder trains for the new machine can be placed in the set of sets
|
||||
if global_stack_id not in self._extruder_trains:
|
||||
self._extruder_trains[global_stack_id] = {}
|
||||
extruders_changed = True
|
||||
|
||||
# Register the extruder trains by position
|
||||
for extruder_train in extruder_trains:
|
||||
self._extruder_trains[global_stack_id][extruder_train.getMetaDataEntry("position")] = extruder_train
|
||||
|
||||
# regardless of what the next stack is, we have to set it again, because of signal routing. ???
|
||||
extruder_train.setNextStack(global_stack)
|
||||
extruders_changed = True
|
||||
|
||||
if extruders_changed:
|
||||
self.extrudersChanged.emit(global_stack_id)
|
||||
self.setActiveExtruderIndex(0)
|
||||
|
||||
## Get all extruder values for a certain setting.
|
||||
#
|
||||
|
@ -632,7 +483,7 @@ class ExtruderManager(QObject):
|
|||
#
|
||||
# This is exposed to qml for display purposes
|
||||
#
|
||||
# \param key The key of the setting to retieve values for.
|
||||
# \param key The key of the setting to retrieve values for.
|
||||
#
|
||||
# \return String representing the extruder values
|
||||
@pyqtSlot(str, result="QVariant")
|
||||
|
@ -656,7 +507,8 @@ class ExtruderManager(QObject):
|
|||
value = extruder.getRawProperty(key, "value")
|
||||
if isinstance(value, SettingFunction):
|
||||
value = value(extruder)
|
||||
else: #Just a value from global.
|
||||
else:
|
||||
# Just a value from global.
|
||||
value = Application.getInstance().getGlobalContainerStack().getProperty(key, "value")
|
||||
|
||||
return value
|
||||
|
|
|
@ -92,8 +92,8 @@ class ExtruderStack(CuraContainerStack):
|
|||
return self.getNextStack()._getMachineDefinition()
|
||||
|
||||
@override(CuraContainerStack)
|
||||
def deserialize(self, contents: str) -> None:
|
||||
super().deserialize(contents)
|
||||
def deserialize(self, contents: str, file_name: Optional[str] = None) -> None:
|
||||
super().deserialize(contents, file_name)
|
||||
stacks = ContainerRegistry.getInstance().findContainerStacks(id=self.getMetaDataEntry("machine", ""))
|
||||
if stacks:
|
||||
self.setNextStack(stacks[0])
|
||||
|
@ -115,6 +115,11 @@ class ExtruderStack(CuraContainerStack):
|
|||
if has_global_dependencies:
|
||||
self.getNextStack().propertiesChanged.emit(key, properties)
|
||||
|
||||
def findDefaultVariant(self):
|
||||
# The default variant is defined in the machine stack and/or definition, so use the machine stack to find
|
||||
# the default variant.
|
||||
return self.getNextStack().findDefaultVariant()
|
||||
|
||||
|
||||
extruder_stack_mime = MimeType(
|
||||
name = "application/x-cura-extruderstack",
|
||||
|
|
|
@ -71,13 +71,13 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
self._add_global = False
|
||||
self._simple_names = False
|
||||
|
||||
self._active_machine_extruders = [] # type: Iterable[ExtruderStack]
|
||||
self._active_machine_extruders = [] # type: Iterable[ExtruderStack]
|
||||
self._add_optional_extruder = False
|
||||
|
||||
#Listen to changes.
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._extrudersChanged) #When the machine is swapped we must update the active machine extruders.
|
||||
ExtruderManager.getInstance().extrudersChanged.connect(self._extrudersChanged) #When the extruders change we must link to the stack-changed signal of the new extruder.
|
||||
self._extrudersChanged() #Also calls _updateExtruders.
|
||||
# Listen to changes
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._extrudersChanged) # When the machine is swapped we must update the active machine extruders
|
||||
ExtruderManager.getInstance().extrudersChanged.connect(self._extrudersChanged) # When the extruders change we must link to the stack-changed signal of the new extruder
|
||||
self._extrudersChanged() # Also calls _updateExtruders
|
||||
|
||||
def setAddGlobal(self, add):
|
||||
if add != self._add_global:
|
||||
|
@ -128,21 +128,24 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
def _extrudersChanged(self, machine_id = None):
|
||||
if machine_id is not None:
|
||||
if Application.getInstance().getGlobalContainerStack() is None:
|
||||
return #No machine, don't need to update the current machine's extruders.
|
||||
# No machine, don't need to update the current machine's extruders
|
||||
return
|
||||
if machine_id != Application.getInstance().getGlobalContainerStack().getId():
|
||||
return #Not the current machine.
|
||||
#Unlink from old extruders.
|
||||
# Not the current machine
|
||||
return
|
||||
|
||||
# Unlink from old extruders
|
||||
for extruder in self._active_machine_extruders:
|
||||
extruder.containersChanged.disconnect(self._onExtruderStackContainersChanged)
|
||||
|
||||
#Link to new extruders.
|
||||
# Link to new extruders
|
||||
self._active_machine_extruders = []
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
for extruder in extruder_manager.getExtruderStacks():
|
||||
extruder.containersChanged.connect(self._onExtruderStackContainersChanged)
|
||||
self._active_machine_extruders.append(extruder)
|
||||
|
||||
self._updateExtruders() #Since the new extruders may have different properties, update our own model.
|
||||
self._updateExtruders() # Since the new extruders may have different properties, update our own model.
|
||||
|
||||
def _onExtruderStackContainersChanged(self, container):
|
||||
# Update when there is an empty container or material change
|
||||
|
@ -150,7 +153,6 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
# The ExtrudersModel needs to be updated when the material-name or -color changes, because the user identifies extruders by material-name
|
||||
self._updateExtruders()
|
||||
|
||||
|
||||
modelChanged = pyqtSignal()
|
||||
|
||||
def _updateExtruders(self):
|
||||
|
@ -161,14 +163,17 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
# This should be called whenever the list of extruders changes.
|
||||
@UM.FlameProfiler.profile
|
||||
def __updateExtruders(self):
|
||||
changed = False
|
||||
extruders_changed = False
|
||||
|
||||
if self.rowCount() != 0:
|
||||
changed = True
|
||||
extruders_changed = True
|
||||
|
||||
items = []
|
||||
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
|
||||
# TODO: remove this - CURA-4482
|
||||
if self._add_global:
|
||||
material = global_container_stack.material
|
||||
color = material.getMetaDataEntry("color_code", default = self.defaultColors[0]) if material else self.defaultColors[0]
|
||||
|
@ -180,40 +185,44 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
"definition": ""
|
||||
}
|
||||
items.append(item)
|
||||
changed = True
|
||||
extruders_changed = True
|
||||
|
||||
# get machine extruder count for verification
|
||||
machine_extruder_count = global_container_stack.getProperty("machine_extruder_count", "value")
|
||||
manager = ExtruderManager.getInstance()
|
||||
for extruder in manager.getMachineExtruders(global_container_stack.getId()):
|
||||
|
||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_container_stack.getId()):
|
||||
position = extruder.getMetaDataEntry("position", default = "0") # Get the position
|
||||
try:
|
||||
position = int(position)
|
||||
except ValueError: #Not a proper int.
|
||||
except ValueError:
|
||||
# Not a proper int.
|
||||
position = -1
|
||||
if position >= machine_extruder_count:
|
||||
continue
|
||||
extruder_name = extruder.getName()
|
||||
material = extruder.material
|
||||
variant = extruder.variant
|
||||
|
||||
default_color = self.defaultColors[position] if position >= 0 and position < len(self.defaultColors) else self.defaultColors[0]
|
||||
color = material.getMetaDataEntry("color_code", default = default_color) if material else default_color
|
||||
item = { #Construct an item with only the relevant information.
|
||||
default_color = self.defaultColors[position] if 0 <= position < len(self.defaultColors) else self.defaultColors[0]
|
||||
color = extruder.material.getMetaDataEntry("color_code", default = default_color) if extruder.material else default_color
|
||||
|
||||
# construct an item with only the relevant information
|
||||
item = {
|
||||
"id": extruder.getId(),
|
||||
"name": extruder_name,
|
||||
"name": extruder.getName(),
|
||||
"color": color,
|
||||
"index": position,
|
||||
"definition": extruder.getBottom().getId(),
|
||||
"material": material.getName() if material else "",
|
||||
"variant": variant.getName() if variant else "",
|
||||
"material": extruder.material.getName() if extruder.material else "",
|
||||
"variant": extruder.variant.getName() if extruder.variant else "", # e.g. print core
|
||||
}
|
||||
items.append(item)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
items.append(item)
|
||||
extruders_changed = True
|
||||
|
||||
if extruders_changed:
|
||||
# sort by extruder index
|
||||
items.sort(key = lambda i: i["index"])
|
||||
|
||||
# We need optional extruder to be last, so add it after we do sorting.
|
||||
# This way we can simply intrepret the -1 of the index as the last item (which it now always is)
|
||||
# This way we can simply interpret the -1 of the index as the last item (which it now always is)
|
||||
if self._add_optional_extruder:
|
||||
item = {
|
||||
"id": "",
|
||||
|
@ -223,5 +232,6 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
"definition": ""
|
||||
}
|
||||
items.append(item)
|
||||
|
||||
self.setItems(items)
|
||||
self.modelChanged.emit()
|
||||
|
|
|
@ -23,9 +23,9 @@ class GlobalStack(CuraContainerStack):
|
|||
def __init__(self, container_id: str, *args, **kwargs):
|
||||
super().__init__(container_id, *args, **kwargs)
|
||||
|
||||
self.addMetaDataEntry("type", "machine") # For backward compatibility
|
||||
self.addMetaDataEntry("type", "machine") # For backward compatibility
|
||||
|
||||
self._extruders = {}
|
||||
self._extruders = {} # type: Dict[str, "ExtruderStack"]
|
||||
|
||||
# This property is used to track which settings we are calculating the "resolve" for
|
||||
# and if so, to bypass the resolve to prevent an infinite recursion that would occur
|
||||
|
@ -57,13 +57,6 @@ class GlobalStack(CuraContainerStack):
|
|||
# \throws Exceptions.TooManyExtrudersError Raised when trying to add an extruder while we
|
||||
# already have the maximum number of extruders.
|
||||
def addExtruder(self, extruder: ContainerStack) -> None:
|
||||
extruder_count = self.getProperty("machine_extruder_count", "value")
|
||||
|
||||
if extruder_count <= 1:
|
||||
Logger.log("i", "Not adding extruder[%s] to [%s] because it is a single-extrusion machine.",
|
||||
extruder.id, self.id)
|
||||
return
|
||||
|
||||
position = extruder.getMetaDataEntry("position")
|
||||
if position is None:
|
||||
Logger.log("w", "No position defined for extruder {extruder}, cannot add it to stack {stack}", extruder = extruder.id, stack = self.id)
|
||||
|
|
|
@ -47,6 +47,11 @@ class MachineManager(QObject):
|
|||
self._active_container_stack = None # type: CuraContainerStack
|
||||
self._global_container_stack = None # type: GlobalStack
|
||||
|
||||
# Used to store the new containers until after confirming the dialog
|
||||
self._new_variant_container = None
|
||||
self._new_material_container = None
|
||||
self._new_quality_containers = []
|
||||
|
||||
self._error_check_timer = QTimer()
|
||||
self._error_check_timer.setInterval(250)
|
||||
self._error_check_timer.setSingleShot(True)
|
||||
|
@ -58,6 +63,7 @@ class MachineManager(QObject):
|
|||
self._instance_container_timer.timeout.connect(self.__onInstanceContainersChanged)
|
||||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||
|
||||
## When the global container is changed, active material probably needs to be updated.
|
||||
self.globalContainerChanged.connect(self.activeMaterialChanged)
|
||||
self.globalContainerChanged.connect(self.activeVariantChanged)
|
||||
|
@ -65,10 +71,10 @@ class MachineManager(QObject):
|
|||
|
||||
self._stacks_have_errors = None
|
||||
|
||||
self._empty_variant_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_material_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_quality_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_quality_changes_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_variant_container = ContainerRegistry.getInstance().findContainers(id = "empty_variant")[0]
|
||||
self._empty_material_container = ContainerRegistry.getInstance().findContainers(id = "empty_material")[0]
|
||||
self._empty_quality_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality")[0]
|
||||
self._empty_quality_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality_changes")[0]
|
||||
|
||||
self._onGlobalContainerChanged()
|
||||
|
||||
|
@ -84,6 +90,9 @@ class MachineManager(QObject):
|
|||
ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeStackChanged)
|
||||
self.activeStackChanged.connect(self.activeStackValueChanged)
|
||||
|
||||
# when a user closed dialog check if any delayed material or variant changes need to be applied
|
||||
Application.getInstance().onDiscardOrKeepProfileChangesClosed.connect(self._executeDelayedActiveContainerStackChanges)
|
||||
|
||||
Preferences.getInstance().addPreference("cura/active_machine", "")
|
||||
|
||||
self._global_event_keys = set()
|
||||
|
@ -98,9 +107,8 @@ class MachineManager(QObject):
|
|||
if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id):
|
||||
# An active machine was saved, so restore it.
|
||||
self.setActiveMachine(active_machine_id)
|
||||
if self._global_container_stack and self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||
# Make sure _active_container_stack is properly initiated
|
||||
ExtruderManager.getInstance().setActiveExtruderIndex(0)
|
||||
# Make sure _active_container_stack is properly initiated
|
||||
ExtruderManager.getInstance().setActiveExtruderIndex(0)
|
||||
|
||||
self._auto_materials_changed = {}
|
||||
self._auto_hotends_changed = {}
|
||||
|
@ -109,7 +117,7 @@ class MachineManager(QObject):
|
|||
"The selected material is incompatible with the selected machine or configuration."),
|
||||
title = catalog.i18nc("@info:title", "Incompatible Material"))
|
||||
|
||||
globalContainerChanged = pyqtSignal() # Emitted whenever the global stack is changed (ie: when changing between printers, changing a global profile, but not when changing a value)
|
||||
globalContainerChanged = pyqtSignal() # Emitted whenever the global stack is changed (ie: when changing between printers, changing a global profile, but not when changing a value)
|
||||
activeMaterialChanged = pyqtSignal()
|
||||
activeVariantChanged = pyqtSignal()
|
||||
activeQualityChanged = pyqtSignal()
|
||||
|
@ -139,6 +147,14 @@ class MachineManager(QObject):
|
|||
|
||||
self.outputDevicesChanged.emit()
|
||||
|
||||
@property
|
||||
def newVariant(self):
|
||||
return self._new_variant_container
|
||||
|
||||
@property
|
||||
def newMaterial(self):
|
||||
return self._new_material_container
|
||||
|
||||
@pyqtProperty("QVariantList", notify = outputDevicesChanged)
|
||||
def printerOutputDevices(self):
|
||||
return self._printer_output_devices
|
||||
|
@ -241,13 +257,13 @@ class MachineManager(QObject):
|
|||
|
||||
if old_index is not None:
|
||||
extruder_manager.setActiveExtruderIndex(old_index)
|
||||
self._auto_hotends_changed = {} #Processed all of them now.
|
||||
self._auto_hotends_changed = {} # Processed all of them now.
|
||||
|
||||
def _onGlobalContainerChanged(self):
|
||||
if self._global_container_stack:
|
||||
try:
|
||||
self._global_container_stack.nameChanged.disconnect(self._onMachineNameChanged)
|
||||
except TypeError: #pyQtSignal gives a TypeError when disconnecting from something that was already disconnected.
|
||||
except TypeError: # pyQtSignal gives a TypeError when disconnecting from something that was already disconnected.
|
||||
pass
|
||||
try:
|
||||
self._global_container_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
|
||||
|
@ -257,52 +273,38 @@ class MachineManager(QObject):
|
|||
self._global_container_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||
except TypeError:
|
||||
pass
|
||||
material = self._global_container_stack.material
|
||||
material.nameChanged.disconnect(self._onMaterialNameChanged)
|
||||
|
||||
quality = self._global_container_stack.quality
|
||||
quality.nameChanged.disconnect(self._onQualityNameChanged)
|
||||
|
||||
if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||
for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
|
||||
extruder_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||
extruder_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
|
||||
for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
|
||||
extruder_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||
extruder_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
|
||||
|
||||
# update the local global container stack reference
|
||||
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
|
||||
self.globalContainerChanged.emit()
|
||||
|
||||
# after switching the global stack we reconnect all the signals and set the variant and material references
|
||||
if self._global_container_stack:
|
||||
Preferences.getInstance().setValue("cura/active_machine", self._global_container_stack.getId())
|
||||
|
||||
self._global_container_stack.nameChanged.connect(self._onMachineNameChanged)
|
||||
self._global_container_stack.containersChanged.connect(self._onInstanceContainersChanged)
|
||||
self._global_container_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||
|
||||
if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||
# For multi-extrusion machines, we do not want variant or material profiles in the stack,
|
||||
# because these are extruder specific and may cause wrong values to be used for extruders
|
||||
# that did not specify a value in the extruder.
|
||||
global_variant = self._global_container_stack.variant
|
||||
if global_variant != self._empty_variant_container:
|
||||
self._global_container_stack.setVariant(self._empty_variant_container)
|
||||
# set the global variant to empty as we now use the extruder stack at all times - CURA-4482
|
||||
global_variant = self._global_container_stack.variant
|
||||
if global_variant != self._empty_variant_container:
|
||||
self._global_container_stack.setVariant(self._empty_variant_container)
|
||||
|
||||
global_material = self._global_container_stack.material
|
||||
if global_material != self._empty_material_container:
|
||||
self._global_container_stack.setMaterial(self._empty_material_container)
|
||||
# set the global material to empty as we now use the extruder stack at all times - CURA-4482
|
||||
global_material = self._global_container_stack.material
|
||||
if global_material != self._empty_material_container:
|
||||
self._global_container_stack.setMaterial(self._empty_material_container)
|
||||
|
||||
for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks(): #Listen for changes on all extruder stacks.
|
||||
extruder_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||
extruder_stack.containersChanged.connect(self._onInstanceContainersChanged)
|
||||
|
||||
else:
|
||||
material = self._global_container_stack.material
|
||||
material.nameChanged.connect(self._onMaterialNameChanged)
|
||||
|
||||
quality = self._global_container_stack.quality
|
||||
quality.nameChanged.connect(self._onQualityNameChanged)
|
||||
|
||||
self._active_container_stack = self._global_container_stack
|
||||
self.activeStackChanged.emit()
|
||||
# Listen for changes on all extruder stacks
|
||||
for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
|
||||
extruder_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||
extruder_stack.containersChanged.connect(self._onInstanceContainersChanged)
|
||||
|
||||
self._error_check_timer.start()
|
||||
|
||||
|
@ -319,8 +321,6 @@ class MachineManager(QObject):
|
|||
old_active_container_stack = self._active_container_stack
|
||||
|
||||
self._active_container_stack = ExtruderManager.getInstance().getActiveExtruderStack()
|
||||
if not self._active_container_stack:
|
||||
self._active_container_stack = self._global_container_stack
|
||||
|
||||
self._error_check_timer.start()
|
||||
|
||||
|
@ -333,6 +333,7 @@ class MachineManager(QObject):
|
|||
self.activeQualityChanged.emit()
|
||||
self.activeVariantChanged.emit()
|
||||
self.activeMaterialChanged.emit()
|
||||
self._updateStacksHaveErrors() # Prevents unwanted re-slices after changing machine
|
||||
self._error_check_timer.start()
|
||||
|
||||
def _onInstanceContainersChanged(self, container):
|
||||
|
@ -349,6 +350,8 @@ class MachineManager(QObject):
|
|||
@pyqtSlot(str)
|
||||
def setActiveMachine(self, stack_id: str) -> None:
|
||||
self.blurSettings.emit() # Ensure no-one has focus.
|
||||
self._cancelDelayedActiveContainerStackChanges()
|
||||
|
||||
containers = ContainerRegistry.getInstance().findContainerStacks(id = stack_id)
|
||||
if containers:
|
||||
Application.getInstance().setGlobalContainerStack(containers[0])
|
||||
|
@ -364,15 +367,6 @@ class MachineManager(QObject):
|
|||
else:
|
||||
Logger.log("w", "Failed creating a new machine!")
|
||||
|
||||
## Create a name that is not empty and unique
|
||||
# \param container_type \type{string} Type of the container (machine, quality, ...)
|
||||
# \param current_name \type{} Current name of the container, which may be an acceptable option
|
||||
# \param new_name \type{string} Base name, which may not be unique
|
||||
# \param fallback_name \type{string} Name to use when (stripped) new_name is empty
|
||||
# \return \type{string} Name that is unique for the specified type and name/id
|
||||
def _createUniqueName(self, container_type: str, current_name: str, new_name: str, fallback_name: str) -> str:
|
||||
return ContainerRegistry.getInstance().createUniqueName(container_type, current_name, new_name, fallback_name)
|
||||
|
||||
def _checkStacksHaveErrors(self) -> bool:
|
||||
if self._global_container_stack is None: #No active machine.
|
||||
return False
|
||||
|
@ -626,12 +620,17 @@ class MachineManager(QObject):
|
|||
@pyqtProperty(str, notify=activeQualityChanged)
|
||||
def activeQualityId(self) -> str:
|
||||
if self._active_container_stack:
|
||||
quality = self._active_container_stack.qualityChanges
|
||||
if quality and not isinstance(quality, type(self._empty_quality_changes_container)):
|
||||
return quality.getId()
|
||||
quality = self._active_container_stack.quality
|
||||
if quality:
|
||||
return quality.getId()
|
||||
if isinstance(quality, type(self._empty_quality_container)):
|
||||
return ""
|
||||
quality_changes = self._active_container_stack.qualityChanges
|
||||
if quality and quality_changes:
|
||||
if isinstance(quality_changes, type(self._empty_quality_changes_container)):
|
||||
# It's a built-in profile
|
||||
return quality.getId()
|
||||
else:
|
||||
# Custom profile
|
||||
return quality_changes.getId()
|
||||
return ""
|
||||
|
||||
@pyqtProperty(str, notify=activeQualityChanged)
|
||||
|
@ -696,9 +695,9 @@ class MachineManager(QObject):
|
|||
@pyqtProperty(str, notify = activeQualityChanged)
|
||||
def activeQualityChangesId(self) -> str:
|
||||
if self._active_container_stack:
|
||||
changes = self._active_container_stack.qualityChanges
|
||||
if changes and changes.getId() != "empty":
|
||||
return changes.getId()
|
||||
quality_changes = self._active_container_stack.qualityChanges
|
||||
if quality_changes and not isinstance(quality_changes, type(self._empty_quality_changes_container)):
|
||||
return quality_changes.getId()
|
||||
return ""
|
||||
|
||||
## Check if a container is read_only
|
||||
|
@ -709,15 +708,13 @@ class MachineManager(QObject):
|
|||
## Copy the value of the setting of the current extruder to all other extruders as well as the global container.
|
||||
@pyqtSlot(str)
|
||||
def copyValueToExtruders(self, key: str):
|
||||
if not self._active_container_stack or self._global_container_stack.getProperty("machine_extruder_count", "value") <= 1:
|
||||
return
|
||||
|
||||
new_value = self._active_container_stack.getProperty(key, "value")
|
||||
stacks = [stack for stack in ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())]
|
||||
stacks.append(self._global_container_stack)
|
||||
for extruder_stack in stacks:
|
||||
extruder_stacks = [stack for stack in ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())]
|
||||
|
||||
# check in which stack the value has to be replaced
|
||||
for extruder_stack in extruder_stacks:
|
||||
if extruder_stack != self._active_container_stack and extruder_stack.getProperty(key, "value") != new_value:
|
||||
extruder_stack.getTop().setProperty(key, "value", new_value)
|
||||
extruder_stack.userChanges.setProperty(key, "value", new_value) # TODO: nested property access, should be improved
|
||||
|
||||
## Set the active material by switching out a container
|
||||
# Depending on from/to material+current variant, a quality profile is chosen and set.
|
||||
|
@ -744,7 +741,7 @@ class MachineManager(QObject):
|
|||
self.blurSettings.emit()
|
||||
old_material.nameChanged.disconnect(self._onMaterialNameChanged)
|
||||
|
||||
self._active_container_stack.material = material_container
|
||||
self._new_material_container = material_container # self._active_container_stack will be updated with a delay
|
||||
Logger.log("d", "Active material changed")
|
||||
|
||||
material_container.nameChanged.connect(self._onMaterialNameChanged)
|
||||
|
@ -763,29 +760,30 @@ class MachineManager(QObject):
|
|||
quality_type = old_quality_changes.getMetaDataEntry("quality_type")
|
||||
new_quality_id = old_quality_changes.getId()
|
||||
|
||||
# See if the requested quality type is available in the new situation.
|
||||
machine_definition = self._active_container_stack.getBottom()
|
||||
quality_manager = QualityManager.getInstance()
|
||||
candidate_quality = None
|
||||
if quality_type:
|
||||
candidate_quality = quality_manager.findQualityByQualityType(quality_type,
|
||||
quality_manager.getWholeMachineDefinition(machine_definition),
|
||||
[material_container])
|
||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_stack:
|
||||
quality_manager = QualityManager.getInstance()
|
||||
|
||||
if not candidate_quality or isinstance(candidate_quality, type(self._empty_quality_changes_container)):
|
||||
Logger.log("d", "Attempting to find fallback quality")
|
||||
# Fall back to a quality (which must be compatible with all other extruders)
|
||||
new_qualities = quality_manager.findAllUsableQualitiesForMachineAndExtruders(
|
||||
self._global_container_stack, ExtruderManager.getInstance().getExtruderStacks())
|
||||
if new_qualities:
|
||||
new_quality_id = new_qualities[0].getId() # Just pick the first available one
|
||||
candidate_quality = None
|
||||
if quality_type:
|
||||
candidate_quality = quality_manager.findQualityByQualityType(quality_type,
|
||||
quality_manager.getWholeMachineDefinition(global_stack.definition),
|
||||
[material_container])
|
||||
|
||||
if not candidate_quality or isinstance(candidate_quality, type(self._empty_quality_changes_container)):
|
||||
Logger.log("d", "Attempting to find fallback quality")
|
||||
# Fall back to a quality (which must be compatible with all other extruders)
|
||||
new_qualities = quality_manager.findAllUsableQualitiesForMachineAndExtruders(
|
||||
self._global_container_stack, ExtruderManager.getInstance().getExtruderStacks())
|
||||
if new_qualities:
|
||||
new_quality_id = new_qualities[0].getId() # Just pick the first available one
|
||||
else:
|
||||
Logger.log("w", "No quality profile found that matches the current machine and extruders.")
|
||||
else:
|
||||
Logger.log("w", "No quality profile found that matches the current machine and extruders.")
|
||||
else:
|
||||
if not old_quality_changes:
|
||||
new_quality_id = candidate_quality.getId()
|
||||
if not old_quality_changes:
|
||||
new_quality_id = candidate_quality.getId()
|
||||
|
||||
self.setActiveQuality(new_quality_id)
|
||||
self.setActiveQuality(new_quality_id)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setActiveVariant(self, variant_id: str):
|
||||
|
@ -798,13 +796,13 @@ class MachineManager(QObject):
|
|||
old_material = self._active_container_stack.material
|
||||
if old_variant:
|
||||
self.blurSettings.emit()
|
||||
self._active_container_stack.variant = containers[0]
|
||||
self._new_variant_container = containers[0] # self._active_container_stack will be updated with a delay
|
||||
Logger.log("d", "Active variant changed to {active_variant_id}".format(active_variant_id = containers[0].getId()))
|
||||
preferred_material_name = None
|
||||
if old_material:
|
||||
preferred_material_name = old_material.getName()
|
||||
|
||||
self.setActiveMaterial(self._updateMaterialContainer(self._global_container_stack.getBottom(), self._global_container_stack, containers[0], preferred_material_name).id)
|
||||
preferred_material_id = self._updateMaterialContainer(self._global_container_stack.getBottom(), self._global_container_stack, containers[0], preferred_material_name).id
|
||||
self.setActiveMaterial(preferred_material_id)
|
||||
else:
|
||||
Logger.log("w", "While trying to set the active variant, no variant was found to replace.")
|
||||
|
||||
|
@ -819,8 +817,6 @@ class MachineManager(QObject):
|
|||
if not containers or not self._global_container_stack:
|
||||
return
|
||||
|
||||
Logger.log("d", "Attempting to change the active quality to %s", quality_id)
|
||||
|
||||
# Quality profile come in two flavours: type=quality and type=quality_changes
|
||||
# If we found a quality_changes profile then look up its parent quality profile.
|
||||
container_type = containers[0].get("type")
|
||||
|
@ -840,30 +836,74 @@ class MachineManager(QObject):
|
|||
if new_quality_settings_list is None:
|
||||
return
|
||||
|
||||
name_changed_connect_stacks = [] # Connect these stacks to the name changed callback
|
||||
# check if any of the stacks have a not supported profile
|
||||
# if that is the case, all stacks should have a not supported state (otherwise it will show quality_type normal)
|
||||
has_not_supported_quality = False
|
||||
|
||||
# check all stacks for not supported
|
||||
for setting_info in new_quality_settings_list:
|
||||
if setting_info["quality"].getMetaDataEntry("quality_type") == "not_supported":
|
||||
has_not_supported_quality = True
|
||||
break
|
||||
|
||||
# set all stacks to not supported if that's the case
|
||||
if has_not_supported_quality:
|
||||
for setting_info in new_quality_settings_list:
|
||||
setting_info["quality"] = self._empty_quality_container
|
||||
|
||||
self._new_quality_containers.clear()
|
||||
|
||||
# store the upcoming quality profile changes per stack for later execution
|
||||
# this prevents re-slicing before the user has made a choice in the discard or keep dialog
|
||||
# (see _executeDelayedActiveContainerStackChanges)
|
||||
for setting_info in new_quality_settings_list:
|
||||
stack = setting_info["stack"]
|
||||
stack_quality = setting_info["quality"]
|
||||
stack_quality_changes = setting_info["quality_changes"]
|
||||
|
||||
name_changed_connect_stacks.append(stack_quality)
|
||||
name_changed_connect_stacks.append(stack_quality_changes)
|
||||
self._replaceQualityOrQualityChangesInStack(stack, stack_quality, postpone_emit=True)
|
||||
self._replaceQualityOrQualityChangesInStack(stack, stack_quality_changes, postpone_emit=True)
|
||||
self._new_quality_containers.append({
|
||||
"stack": stack,
|
||||
"quality": stack_quality,
|
||||
"quality_changes": stack_quality_changes
|
||||
})
|
||||
|
||||
# Send emits that are postponed in replaceContainer.
|
||||
# Here the stacks are finished replacing and every value can be resolved based on the current state.
|
||||
for setting_info in new_quality_settings_list:
|
||||
setting_info["stack"].sendPostponedEmits()
|
||||
|
||||
# Connect to onQualityNameChanged
|
||||
for stack in name_changed_connect_stacks:
|
||||
stack.nameChanged.connect(self._onQualityNameChanged)
|
||||
# show the keep/discard dialog after the containers have been switched. Otherwise, the default values on
|
||||
# the dialog will be the those before the switching.
|
||||
self._executeDelayedActiveContainerStackChanges()
|
||||
|
||||
if self.hasUserSettings and Preferences.getInstance().getValue("cura/active_mode") == 1:
|
||||
self._askUserToKeepOrClearCurrentSettings()
|
||||
Application.getInstance().discardOrKeepProfileChanges()
|
||||
|
||||
self.activeQualityChanged.emit()
|
||||
## Used to update material and variant in the active container stack with a delay.
|
||||
# This delay prevents the stack from triggering a lot of signals (eventually resulting in slicing)
|
||||
# before the user decided to keep or discard any of their changes using the dialog.
|
||||
# The Application.onDiscardOrKeepProfileChangesClosed signal triggers this method.
|
||||
def _executeDelayedActiveContainerStackChanges(self):
|
||||
if self._new_variant_container is not None:
|
||||
self._active_container_stack.variant = self._new_variant_container
|
||||
self._new_variant_container = None
|
||||
|
||||
if self._new_material_container is not None:
|
||||
self._active_container_stack.material = self._new_material_container
|
||||
self._new_material_container = None
|
||||
|
||||
# apply the new quality to all stacks
|
||||
if self._new_quality_containers:
|
||||
for new_quality in self._new_quality_containers:
|
||||
self._replaceQualityOrQualityChangesInStack(new_quality["stack"], new_quality["quality"], postpone_emit = True)
|
||||
self._replaceQualityOrQualityChangesInStack(new_quality["stack"], new_quality["quality_changes"], postpone_emit = True)
|
||||
|
||||
for new_quality in self._new_quality_containers:
|
||||
new_quality["stack"].nameChanged.connect(self._onQualityNameChanged)
|
||||
new_quality["stack"].sendPostponedEmits() # Send the signals that were postponed in _replaceQualityOrQualityChangesInStack
|
||||
|
||||
self._new_quality_containers.clear()
|
||||
|
||||
## Cancel set changes for material and variant in the active container stack.
|
||||
# Used for ignoring any changes when switching between printers (setActiveMachine)
|
||||
def _cancelDelayedActiveContainerStackChanges(self):
|
||||
self._new_material_container = None
|
||||
self._new_variant_container = None
|
||||
|
||||
## Determine the quality and quality changes settings for the current machine for a quality name.
|
||||
#
|
||||
|
@ -877,29 +917,46 @@ class MachineManager(QObject):
|
|||
global_container_stack = self._global_container_stack
|
||||
if not global_container_stack:
|
||||
return []
|
||||
|
||||
global_machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
|
||||
|
||||
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
|
||||
if extruder_stacks:
|
||||
stacks = extruder_stacks
|
||||
else:
|
||||
stacks = [global_container_stack]
|
||||
|
||||
for stack in stacks:
|
||||
material = stack.material
|
||||
# find qualities for extruders
|
||||
for extruder_stack in extruder_stacks:
|
||||
material = extruder_stack.material
|
||||
|
||||
# TODO: fix this
|
||||
if self._new_material_container and extruder_stack.getId() == self._active_container_stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material])
|
||||
if not quality: #No quality profile is found for this quality type.
|
||||
|
||||
if not quality:
|
||||
# No quality profile is found for this quality type.
|
||||
quality = self._empty_quality_container
|
||||
result.append({"stack": stack, "quality": quality, "quality_changes": empty_quality_changes})
|
||||
|
||||
if extruder_stacks:
|
||||
# Add an extra entry for the global stack.
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [], global_quality = "True")
|
||||
result.append({
|
||||
"stack": extruder_stack,
|
||||
"quality": quality,
|
||||
"quality_changes": empty_quality_changes
|
||||
})
|
||||
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
# also find a global quality for the machine
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [], global_quality = "True")
|
||||
|
||||
result.append({"stack": global_container_stack, "quality": global_quality, "quality_changes": empty_quality_changes})
|
||||
# if there is not global quality but we're using a single extrusion machine, copy the quality of the first extruder - CURA-4482
|
||||
if not global_quality and len(extruder_stacks) == 1:
|
||||
global_quality = result[0]["quality"]
|
||||
|
||||
# if there is still no global quality, set it to empty (not supported)
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
|
||||
result.append({
|
||||
"stack": global_container_stack,
|
||||
"quality": global_quality,
|
||||
"quality_changes": empty_quality_changes
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
|
@ -912,10 +969,8 @@ class MachineManager(QObject):
|
|||
quality_manager = QualityManager.getInstance()
|
||||
|
||||
global_container_stack = self._global_container_stack
|
||||
global_machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
|
||||
|
||||
quality_changes_profiles = quality_manager.findQualityChangesByName(quality_changes_name,
|
||||
global_machine_definition)
|
||||
global_machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.definition)
|
||||
quality_changes_profiles = quality_manager.findQualityChangesByName(quality_changes_name, global_machine_definition)
|
||||
|
||||
global_quality_changes = [qcp for qcp in quality_changes_profiles if qcp.getMetaDataEntry("extruder") is None]
|
||||
if global_quality_changes:
|
||||
|
@ -923,26 +978,25 @@ class MachineManager(QObject):
|
|||
else:
|
||||
Logger.log("e", "Could not find the global quality changes container with name %s", quality_changes_name)
|
||||
return None
|
||||
|
||||
material = global_container_stack.material
|
||||
|
||||
# find a quality type that matches both machine and materials
|
||||
if self._new_material_container and self._active_container_stack.getId() == global_container_stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
# For the global stack, find a quality which matches the quality_type in
|
||||
# the quality changes profile and also satisfies any material constraints.
|
||||
quality_type = global_quality_changes.getMetaDataEntry("quality_type")
|
||||
if global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [], global_quality = True)
|
||||
else:
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material])
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
|
||||
# Find the values for each extruder.
|
||||
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
|
||||
|
||||
for stack in extruder_stacks:
|
||||
extruder_definition = quality_manager.getParentMachineDefinition(stack.getBottom())
|
||||
# append the extruder quality changes
|
||||
for extruder_stack in extruder_stacks:
|
||||
extruder_definition = quality_manager.getParentMachineDefinition(extruder_stack.definition)
|
||||
|
||||
quality_changes_list = [qcp for qcp in quality_changes_profiles if qcp.getMetaDataEntry("extruder") == extruder_definition.getId()]
|
||||
|
||||
quality_changes_list = [qcp for qcp in quality_changes_profiles
|
||||
if qcp.getMetaDataEntry("extruder") == extruder_definition.getId()]
|
||||
if quality_changes_list:
|
||||
quality_changes = quality_changes_list[0]
|
||||
else:
|
||||
|
@ -950,20 +1004,39 @@ class MachineManager(QObject):
|
|||
if not quality_changes:
|
||||
quality_changes = self._empty_quality_changes_container
|
||||
|
||||
material = stack.material
|
||||
material = extruder_stack.material
|
||||
|
||||
if self._new_material_container and self._active_container_stack.getId() == extruder_stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material])
|
||||
if not quality: #No quality profile found for this quality type.
|
||||
|
||||
if not quality:
|
||||
# No quality profile found for this quality type.
|
||||
quality = self._empty_quality_container
|
||||
|
||||
result.append({"stack": stack, "quality": quality, "quality_changes": quality_changes})
|
||||
result.append({
|
||||
"stack": extruder_stack,
|
||||
"quality": quality,
|
||||
"quality_changes": quality_changes
|
||||
})
|
||||
|
||||
if extruder_stacks:
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material], global_quality = "True")
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
result.append({"stack": global_container_stack, "quality": global_quality, "quality_changes": global_quality_changes})
|
||||
else:
|
||||
result.append({"stack": global_container_stack, "quality": global_quality, "quality_changes": global_quality_changes})
|
||||
# append the global quality changes
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material], global_quality = "True")
|
||||
|
||||
# if there is not global quality but we're using a single extrusion machine, copy the quality of the first extruder - CURA-4482
|
||||
if not global_quality and len(extruder_stacks) == 1:
|
||||
global_quality = result[0]["quality"]
|
||||
|
||||
# if still no global quality changes are found we set it to empty (not supported)
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
|
||||
result.append({
|
||||
"stack": global_container_stack,
|
||||
"quality": global_quality,
|
||||
"quality_changes": global_quality_changes
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
|
@ -982,9 +1055,6 @@ class MachineManager(QObject):
|
|||
stack.qualityChanges.nameChanged.connect(self._onQualityNameChanged)
|
||||
self._onQualityNameChanged()
|
||||
|
||||
def _askUserToKeepOrClearCurrentSettings(self):
|
||||
Application.getInstance().discardOrKeepProfileChanges()
|
||||
|
||||
@pyqtProperty(str, notify = activeVariantChanged)
|
||||
def activeVariantName(self) -> str:
|
||||
if self._active_container_stack:
|
||||
|
@ -1075,10 +1145,11 @@ class MachineManager(QObject):
|
|||
|
||||
@pyqtSlot(str, str)
|
||||
def renameMachine(self, machine_id: str, new_name: str):
|
||||
containers = ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||
if containers:
|
||||
new_name = self._createUniqueName("machine", containers[0].getName(), new_name, containers[0].getBottom().getName())
|
||||
containers[0].setName(new_name)
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_stack = container_registry.findContainerStacks(id = machine_id)
|
||||
if machine_stack:
|
||||
new_name = container_registry.createUniqueName("machine", machine_stack[0].getName(), new_name, machine_stack[0].getBottom().getName())
|
||||
machine_stack[0].setName(new_name)
|
||||
self.globalContainerChanged.emit()
|
||||
|
||||
@pyqtSlot(str)
|
||||
|
@ -1102,15 +1173,14 @@ class MachineManager(QObject):
|
|||
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||
def hasMaterials(self) -> bool:
|
||||
if self._global_container_stack:
|
||||
return bool(self._global_container_stack.getMetaDataEntry("has_materials", False))
|
||||
return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_materials", False))
|
||||
|
||||
return False
|
||||
|
||||
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||
def hasVariants(self) -> bool:
|
||||
if self._global_container_stack:
|
||||
return bool(self._global_container_stack.getMetaDataEntry("has_variants", False))
|
||||
|
||||
return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_variants", False))
|
||||
return False
|
||||
|
||||
## Property to indicate if a machine has "specialized" material profiles.
|
||||
|
@ -1118,8 +1188,7 @@ class MachineManager(QObject):
|
|||
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||
def filterMaterialsByMachine(self) -> bool:
|
||||
if self._global_container_stack:
|
||||
return bool(self._global_container_stack.getMetaDataEntry("has_machine_materials", False))
|
||||
|
||||
return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_machine_materials", False))
|
||||
return False
|
||||
|
||||
## Property to indicate if a machine has "specialized" quality profiles.
|
||||
|
@ -1127,7 +1196,7 @@ class MachineManager(QObject):
|
|||
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||
def filterQualityByMachine(self) -> bool:
|
||||
if self._global_container_stack:
|
||||
return bool(self._global_container_stack.getMetaDataEntry("has_machine_quality", False))
|
||||
return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_machine_quality", False))
|
||||
return False
|
||||
|
||||
## Get the Definition ID of a machine (specified by ID)
|
||||
|
@ -1140,7 +1209,7 @@ class MachineManager(QObject):
|
|||
return containers[0].getBottom().getId()
|
||||
|
||||
@staticmethod
|
||||
def createMachineManager(engine=None, script_engine=None):
|
||||
def createMachineManager():
|
||||
return MachineManager()
|
||||
|
||||
@deprecated("Use ExtruderStack.material = ... and it won't be necessary", "2.7")
|
||||
|
|
|
@ -18,4 +18,8 @@ class MaterialsModel(InstanceContainersModel):
|
|||
# \param container The container whose metadata was changed.
|
||||
def _onContainerMetaDataChanged(self, container):
|
||||
if container.getMetaDataEntry("type") == "material": #Only need to update if a material was changed.
|
||||
self._update()
|
||||
self._update()
|
||||
|
||||
def _onContainerChanged(self, container):
|
||||
if container.getMetaDataEntry("type", "") == "material":
|
||||
super()._onContainerChanged(container)
|
||||
|
|
|
@ -12,6 +12,11 @@ from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel
|
|||
from cura.QualityManager import QualityManager
|
||||
from cura.Settings.ExtruderManager import ExtruderManager
|
||||
|
||||
from typing import List, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cura.Settings.ExtruderStack import ExtruderStack
|
||||
|
||||
|
||||
## QML Model for listing the current list of valid quality profiles.
|
||||
#
|
||||
|
@ -27,7 +32,6 @@ class ProfilesModel(InstanceContainersModel):
|
|||
self.addRoleName(self.AvailableRole, "available")
|
||||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._update)
|
||||
|
||||
Application.getInstance().getMachineManager().activeVariantChanged.connect(self._update)
|
||||
Application.getInstance().getMachineManager().activeStackChanged.connect(self._update)
|
||||
Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update)
|
||||
|
@ -54,17 +58,11 @@ class ProfilesModel(InstanceContainersModel):
|
|||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack is None:
|
||||
return {}, {}
|
||||
global_stack_definition = global_container_stack.getBottom()
|
||||
global_stack_definition = global_container_stack.definition
|
||||
|
||||
# Get the list of extruders and place the selected extruder at the front of the list.
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
materials = [global_container_stack.material]
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
extruder_stacks = [active_extruder] + extruder_stacks
|
||||
materials = [extruder.material for extruder in extruder_stacks]
|
||||
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||
materials = [extruder.material for extruder in extruder_stacks]
|
||||
|
||||
# Fetch the list of usable qualities across all extruders.
|
||||
# The actual list of quality profiles come from the first extruder in the extruder list.
|
||||
|
@ -83,39 +81,27 @@ class ProfilesModel(InstanceContainersModel):
|
|||
if quality.getMetaDataEntry("quality_type") not in quality_type_set:
|
||||
result.append(quality)
|
||||
|
||||
# if still profiles are found, add a single empty_quality ("Not supported") instance to the drop down list
|
||||
if len(result) == 0:
|
||||
# If not qualities are found we dynamically create a not supported container for this machine + material combination
|
||||
not_supported_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality")[0]
|
||||
result.append(not_supported_container)
|
||||
|
||||
return {item.getId():item for item in result}, {}
|
||||
|
||||
## Re-computes the items in this model, and adds the layer height role.
|
||||
def _recomputeItems(self):
|
||||
#Some globals that we can re-use.
|
||||
|
||||
# Some globals that we can re-use.
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack is None:
|
||||
return
|
||||
|
||||
# Detecting if the machine has multiple extrusion
|
||||
multiple_extrusion = global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
# Get the list of extruders and place the selected extruder at the front of the list.
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
if multiple_extrusion:
|
||||
# Place the active extruder at the front of the list.
|
||||
# This is a workaround checking if there is an active_extruder or not before moving it to the front of the list.
|
||||
# Actually, when a printer has multiple extruders, should exist always an active_extruder. However, in some
|
||||
# cases the active_extruder is still None.
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
new_extruder_stacks = []
|
||||
if active_extruder is not None:
|
||||
new_extruder_stacks = [active_extruder]
|
||||
extruder_stacks = new_extruder_stacks + extruder_stacks
|
||||
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
|
||||
# Get a list of usable/available qualities for this machine and material
|
||||
qualities = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
|
||||
extruder_stacks)
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_manager = Application.getInstance().getMachineManager()
|
||||
qualities = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||
|
||||
unit = global_container_stack.getBottom().getProperty("layer_height", "unit")
|
||||
if not unit:
|
||||
|
@ -160,13 +146,23 @@ class ProfilesModel(InstanceContainersModel):
|
|||
# Now all the containers are set
|
||||
for item in containers:
|
||||
profile = container_registry.findContainers(id = item["id"])
|
||||
|
||||
# When for some reason there is no profile container in the registry
|
||||
if not profile:
|
||||
self._setItemLayerHeight(item, "", unit)
|
||||
self._setItemLayerHeight(item, "", "")
|
||||
item["available"] = False
|
||||
yield item
|
||||
continue
|
||||
|
||||
profile = profile[0]
|
||||
|
||||
# When there is a profile but it's an empty quality should. It's shown in the list (they are "Not Supported" profiles)
|
||||
if profile.getId() == "empty_quality":
|
||||
self._setItemLayerHeight(item, "", "")
|
||||
item["available"] = True
|
||||
yield item
|
||||
continue
|
||||
|
||||
item["available"] = profile in qualities
|
||||
|
||||
# Easy case: This profile defines its own layer height.
|
||||
|
@ -175,6 +171,8 @@ class ProfilesModel(InstanceContainersModel):
|
|||
yield item
|
||||
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_type = profile.getMetaDataEntry("quality_type", None)
|
||||
if quality_type:
|
||||
|
@ -183,9 +181,11 @@ class ProfilesModel(InstanceContainersModel):
|
|||
if quality_result["stack"] is global_container_stack:
|
||||
quality = quality_result["quality"]
|
||||
break
|
||||
else: #No global container stack in the results:
|
||||
else:
|
||||
# No global container stack in the 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:
|
||||
quality = None
|
||||
if quality and quality.hasProperty("layer_height", "value"):
|
||||
|
@ -193,15 +193,29 @@ class ProfilesModel(InstanceContainersModel):
|
|||
yield item
|
||||
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
|
||||
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
|
||||
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()
|
||||
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
|
||||
|
||||
def _setItemLayerHeight(self, item, value, unit):
|
||||
## Get a list of extruder stacks with the active extruder at the front of the list.
|
||||
@staticmethod
|
||||
def _getOrderedExtruderStacksList() -> List["ExtruderStack"]:
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
extruder_stacks = [active_extruder] + extruder_stacks
|
||||
|
||||
return extruder_stacks
|
||||
|
||||
@staticmethod
|
||||
def _setItemLayerHeight(item, value, unit):
|
||||
item["layer_height"] = str(value) + unit
|
||||
item["layer_height_without_unit"] = str(value)
|
||||
|
|
|
@ -22,49 +22,22 @@ class QualityAndUserProfilesModel(ProfilesModel):
|
|||
|
||||
# Fetch the list of quality changes.
|
||||
quality_manager = QualityManager.getInstance()
|
||||
machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
|
||||
machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.definition)
|
||||
quality_changes_list = quality_manager.findAllQualityChangesForMachine(machine_definition)
|
||||
|
||||
# Detecting if the machine has multiple extrusion
|
||||
multiple_extrusion = global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
# Get the list of extruders
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
if multiple_extrusion:
|
||||
# Place the active extruder at the front of the list.
|
||||
# This is a workaround checking if there is an active_extruder or not before moving it to the front of the list.
|
||||
# Actually, when a printer has multiple extruders, should exist always an active_extruder. However, in some
|
||||
# cases the active_extruder is still None.
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
new_extruder_stacks = []
|
||||
if active_extruder is not None:
|
||||
new_extruder_stacks = [active_extruder]
|
||||
else:
|
||||
# if there is no active extruder, use the first one in the active extruder stacks
|
||||
active_extruder = extruder_stacks[0]
|
||||
extruder_stacks = new_extruder_stacks + extruder_stacks
|
||||
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||
|
||||
# Fetch the list of useable qualities across all extruders.
|
||||
# Fetch the list of usable qualities across all extruders.
|
||||
# The actual list of quality profiles come from the first extruder in the extruder list.
|
||||
quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
|
||||
extruder_stacks)
|
||||
result = {quality.getId():quality for quality in quality_list}
|
||||
quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||
|
||||
# Filter the quality_change by the list of available quality_types
|
||||
quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
|
||||
|
||||
if multiple_extrusion:
|
||||
# If the printer has multiple extruders then quality changes related to the current extruder are kept
|
||||
filtered_quality_changes = {qc.getId():qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||
qc.getMetaDataEntry("extruder") is not None and
|
||||
(qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
|
||||
qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())}
|
||||
else:
|
||||
# If not, the quality changes of the global stack are selected
|
||||
filtered_quality_changes = {qc.getId():qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||
qc.getMetaDataEntry("extruder") is None}
|
||||
result.update(filtered_quality_changes)
|
||||
|
||||
return result, {}
|
||||
filtered_quality_changes = {qc.getId():qc for qc in quality_changes_list if
|
||||
qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||
qc.getMetaDataEntry("extruder") is not None and
|
||||
(qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
|
||||
qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())}
|
||||
return filtered_quality_changes, {}
|
||||
|
|
|
@ -223,7 +223,6 @@ class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
|||
if self._extruder_id == "" and settable_per_extruder:
|
||||
continue
|
||||
|
||||
|
||||
label = definition.label
|
||||
if self._i18n_catalog:
|
||||
label = self._i18n_catalog.i18nc(definition.key + " label", label)
|
||||
|
|
|
@ -47,21 +47,20 @@ class SettingInheritanceManager(QObject):
|
|||
|
||||
@pyqtSlot(str, str, result = "QStringList")
|
||||
def getOverridesForExtruder(self, key, extruder_index):
|
||||
multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
if not multi_extrusion:
|
||||
return self._settings_with_inheritance_warning
|
||||
extruder = ExtruderManager.getInstance().getExtruderStack(extruder_index)
|
||||
if not extruder:
|
||||
Logger.log("w", "Unable to find extruder for current machine with index %s", extruder_index)
|
||||
return []
|
||||
result = []
|
||||
|
||||
definitions = self._global_container_stack.definition.findDefinitions(key=key)
|
||||
extruder_stack = ExtruderManager.getInstance().getExtruderStack(extruder_index)
|
||||
if not extruder_stack:
|
||||
Logger.log("w", "Unable to find extruder for current machine with index %s", extruder_index)
|
||||
return result
|
||||
|
||||
definitions = self._global_container_stack.definition.findDefinitions(key = key)
|
||||
if not definitions:
|
||||
Logger.log("w", "Could not find definition for key [%s] (2)", key)
|
||||
return []
|
||||
result = []
|
||||
return result
|
||||
|
||||
for key in definitions[0].getAllKeys():
|
||||
if self._settingIsOverwritingInheritance(key, extruder):
|
||||
if self._settingIsOverwritingInheritance(key, extruder_stack):
|
||||
result.append(key)
|
||||
|
||||
return result
|
||||
|
@ -78,8 +77,8 @@ class SettingInheritanceManager(QObject):
|
|||
|
||||
def _onActiveExtruderChanged(self):
|
||||
new_active_stack = ExtruderManager.getInstance().getActiveExtruderStack()
|
||||
if not new_active_stack:
|
||||
new_active_stack = self._global_container_stack
|
||||
# if not new_active_stack:
|
||||
# new_active_stack = self._global_container_stack
|
||||
|
||||
if new_active_stack != self._active_container_stack: # Check if changed
|
||||
if self._active_container_stack: # Disconnect signal from old container (if any)
|
||||
|
|
|
@ -27,11 +27,7 @@ class SettingOverrideDecorator(SceneNodeDecorator):
|
|||
self._stack = PerObjectContainerStack(stack_id = id(self))
|
||||
self._stack.setDirty(False) # This stack does not need to be saved.
|
||||
self._stack.addContainer(InstanceContainer(container_id = "SettingOverrideInstanceContainer"))
|
||||
|
||||
if ExtruderManager.getInstance().extruderCount > 1:
|
||||
self._extruder_stack = ExtruderManager.getInstance().getExtruderStack(0).getId()
|
||||
else:
|
||||
self._extruder_stack = None
|
||||
self._extruder_stack = ExtruderManager.getInstance().getExtruderStack(0).getId()
|
||||
|
||||
self._stack.propertyChanged.connect(self._onSettingChanged)
|
||||
|
||||
|
|
|
@ -12,11 +12,18 @@ class SimpleModeSettingsManager(QObject):
|
|||
super().__init__(parent)
|
||||
|
||||
self._machine_manager = Application.getInstance().getMachineManager()
|
||||
self._is_profile_customized = False
|
||||
self._is_profile_customized = False # True when default profile has user changes
|
||||
self._is_profile_user_created = False # True when profile was custom created by user
|
||||
|
||||
self._machine_manager.activeStackValueChanged.connect(self._updateIsProfileCustomized)
|
||||
self._machine_manager.activeQualityChanged.connect(self._updateIsProfileUserCreated)
|
||||
|
||||
# update on create as the activeQualityChanged signal is emitted before this manager is created when Cura starts
|
||||
self._updateIsProfileCustomized()
|
||||
self._updateIsProfileUserCreated()
|
||||
|
||||
isProfileCustomizedChanged = pyqtSignal()
|
||||
isProfileUserCreatedChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty(bool, notify = isProfileCustomizedChanged)
|
||||
def isProfileCustomized(self):
|
||||
|
@ -32,11 +39,13 @@ class SimpleModeSettingsManager(QObject):
|
|||
|
||||
# check user settings in the global stack
|
||||
user_setting_keys.update(set(global_stack.userChanges.getAllKeys()))
|
||||
|
||||
# check user settings in the extruder stacks
|
||||
if global_stack.extruders:
|
||||
for extruder_stack in global_stack.extruders.values():
|
||||
user_setting_keys.update(set(extruder_stack.userChanges.getAllKeys()))
|
||||
|
||||
# remove settings that are visible in recommended (we don't show the reset button for those)
|
||||
for skip_key in self.__ignored_custom_setting_keys:
|
||||
if skip_key in user_setting_keys:
|
||||
user_setting_keys.remove(skip_key)
|
||||
|
@ -47,6 +56,33 @@ class SimpleModeSettingsManager(QObject):
|
|||
self._is_profile_customized = has_customized_user_settings
|
||||
self.isProfileCustomizedChanged.emit()
|
||||
|
||||
@pyqtProperty(bool, notify = isProfileUserCreatedChanged)
|
||||
def isProfileUserCreated(self):
|
||||
return self._is_profile_user_created
|
||||
|
||||
def _updateIsProfileUserCreated(self):
|
||||
quality_changes_keys = set()
|
||||
|
||||
if not self._machine_manager.activeMachine:
|
||||
return False
|
||||
|
||||
global_stack = self._machine_manager.activeMachine
|
||||
|
||||
# check quality changes settings in the global stack
|
||||
quality_changes_keys.update(set(global_stack.qualityChanges.getAllKeys()))
|
||||
|
||||
# check quality changes settings in the extruder stacks
|
||||
if global_stack.extruders:
|
||||
for extruder_stack in global_stack.extruders.values():
|
||||
quality_changes_keys.update(set(extruder_stack.qualityChanges.getAllKeys()))
|
||||
|
||||
# check if the qualityChanges container is not empty (meaning it is a user created profile)
|
||||
has_quality_changes = len(quality_changes_keys) > 0
|
||||
|
||||
if has_quality_changes != self._is_profile_user_created:
|
||||
self._is_profile_user_created = has_quality_changes
|
||||
self.isProfileUserCreatedChanged.emit()
|
||||
|
||||
# These are the settings included in the Simple ("Recommended") Mode, so only when the other settings have been
|
||||
# changed, we consider it as a user customized profile in the Simple ("Recommended") Mode.
|
||||
__ignored_custom_setting_keys = ["support_enable",
|
||||
|
|
|
@ -22,47 +22,24 @@ class UserProfilesModel(ProfilesModel):
|
|||
|
||||
# Fetch the list of quality changes.
|
||||
quality_manager = QualityManager.getInstance()
|
||||
machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
|
||||
machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.definition)
|
||||
quality_changes_list = quality_manager.findAllQualityChangesForMachine(machine_definition)
|
||||
|
||||
# Detecting if the machine has multiple extrusion
|
||||
multiple_extrusion = global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
# Get the list of extruders and place the selected extruder at the front of the list.
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
if multiple_extrusion:
|
||||
# Place the active extruder at the front of the list.
|
||||
# This is a workaround checking if there is an active_extruder or not before moving it to the front of the list.
|
||||
# Actually, when a printer has multiple extruders, should exist always an active_extruder. However, in some
|
||||
# cases the active_extruder is still None.
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
new_extruder_stacks = []
|
||||
if active_extruder is not None:
|
||||
new_extruder_stacks = [active_extruder]
|
||||
else:
|
||||
# if there is no active extruder, use the first one in the active extruder stacks
|
||||
active_extruder = extruder_stacks[0]
|
||||
extruder_stacks = new_extruder_stacks + extruder_stacks
|
||||
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||
|
||||
# Fetch the list of useable qualities across all extruders.
|
||||
# Fetch the list of usable qualities across all extruders.
|
||||
# The actual list of quality profiles come from the first extruder in the extruder list.
|
||||
quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
|
||||
extruder_stacks)
|
||||
quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||
|
||||
# Filter the quality_change by the list of available quality_types
|
||||
quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
|
||||
|
||||
if multiple_extrusion:
|
||||
# If the printer has multiple extruders then quality changes related to the current extruder are kept
|
||||
filtered_quality_changes = {qc.getId():qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||
qc.getMetaDataEntry("extruder") is not None and
|
||||
(qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
|
||||
qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())}
|
||||
else:
|
||||
# If not, the quality changes of the global stack are selected
|
||||
filtered_quality_changes = {qc.getId():qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||
qc.getMetaDataEntry("extruder") is None}
|
||||
filtered_quality_changes = {qc.getId():qc for qc in quality_changes_list if
|
||||
qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||
qc.getMetaDataEntry("extruder") is not None and
|
||||
(qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
|
||||
qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())}
|
||||
|
||||
return filtered_quality_changes, {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue