mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-07 05:53:59 -06:00
Merge branch 'settings_rework'
Contributes to CURA-1278 * settings_rework: (224 commits) Improve slice trigger documentation Import Cura in materials preferences page so we can use the active definition id Add layer height to high quality profile so we have something that changes Update example XML material to use the right product names Filter available materials by the machine definition Show the add machine dialog when we do not have an active machine Create machine-specific material containers for machine specific overrides in XML material files When creating a new container stack, add empty containers for things where we cannot find containers Add preferred variant, material and quality to UM2+ definition Account for global container stack being None in the backend plugin Use the global stack instance variable and account for it potentially being None Store the global container stack as an instance property Added wildcard to filtering Per object settings filter now uses correct bool types (instead of strings) Removed stray = sign. Fix creating print job name Disable asynchronous loading of SettingItem when Qt Version < 5.5 Document QTbug Properly serialise all settings to g-code file Document GCodeWriter class ...
This commit is contained in:
commit
386aec32a8
125 changed files with 7651 additions and 2131 deletions
|
@ -11,6 +11,7 @@ from UM.Qt.Bindings.BackendProxy import BackendState #To determine the state of
|
|||
from UM.Message import Message
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from UM.Resources import Resources
|
||||
from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then.
|
||||
|
||||
from cura.OneAtATimeIterator import OneAtATimeIterator
|
||||
from . import ProcessSlicedLayersJob
|
||||
|
@ -29,6 +30,10 @@ catalog = i18nCatalog("cura")
|
|||
|
||||
|
||||
class CuraEngineBackend(Backend):
|
||||
## Starts the back-end plug-in.
|
||||
#
|
||||
# This registers all the signal listeners and prepares for communication
|
||||
# with the back-end in general.
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
|
@ -50,19 +55,19 @@ class CuraEngineBackend(Backend):
|
|||
self._onActiveViewChanged()
|
||||
self._stored_layer_data = []
|
||||
|
||||
# When there are current settings and machine instance is changed, there is no profile changed event. We should
|
||||
# pretend there is though.
|
||||
Application.getInstance().getMachineManager().activeMachineInstanceChanged.connect(self._onActiveProfileChanged)
|
||||
|
||||
self._profile = None
|
||||
Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onActiveProfileChanged)
|
||||
self._onActiveProfileChanged()
|
||||
#Triggers for when to (re)start slicing:
|
||||
if Application.getInstance().getGlobalContainerStack():
|
||||
Application.getInstance().getGlobalContainerStack().propertyChanged.connect(self._onSettingChanged) #Note: Only starts slicing when the value changed.
|
||||
|
||||
#When you update a setting and other settings get changed through inheritance, many propertyChanged signals are fired.
|
||||
#This timer will group them up, and only slice for the last setting changed signal.
|
||||
#TODO: Properly group propertyChanged signals by whether they are triggered by the same user interaction.
|
||||
self._change_timer = QTimer()
|
||||
self._change_timer.setInterval(500)
|
||||
self._change_timer.setSingleShot(True)
|
||||
self._change_timer.timeout.connect(self.slice)
|
||||
|
||||
#Listeners for receiving messages from the back-end.
|
||||
self._message_handlers["cura.proto.Layer"] = self._onLayerMessage
|
||||
self._message_handlers["cura.proto.Progress"] = self._onProgressMessage
|
||||
self._message_handlers["cura.proto.GCodeLayer"] = self._onGCodeLayerMessage
|
||||
|
@ -70,39 +75,35 @@ class CuraEngineBackend(Backend):
|
|||
self._message_handlers["cura.proto.ObjectPrintTime"] = self._onObjectPrintTimeMessage
|
||||
self._message_handlers["cura.proto.SlicingFinished"] = self._onSlicingFinishedMessage
|
||||
|
||||
self._slicing = False
|
||||
self._start_slice_job = None
|
||||
self._restart = False
|
||||
self._enabled = True
|
||||
self._always_restart = True
|
||||
self._slicing = False #Are we currently slicing?
|
||||
self._restart = False #Back-end is currently restarting?
|
||||
self._enabled = True #Should we be slicing? Slicing might be paused when, for instance, the user is dragging the mesh around.
|
||||
self._always_restart = True #Always restart the engine when starting a new slice. Don't keep the process running. TODO: Fix engine statelessness.
|
||||
self._process_layers_job = None #The currently active job to process layers, or None if it is not processing layers.
|
||||
|
||||
self._message = None
|
||||
self._message = None #Pop-up message that shows the slicing progress bar (or an error message).
|
||||
|
||||
self.backendQuit.connect(self._onBackendQuit)
|
||||
|
||||
self.backendConnected.connect(self._onBackendConnected)
|
||||
|
||||
#When a tool operation is in progress, don't slice. So we need to listen for tool operations.
|
||||
Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
|
||||
Application.getInstance().getController().toolOperationStopped.connect(self._onToolOperationStopped)
|
||||
|
||||
Application.getInstance().getMachineManager().activeMachineInstanceChanged.connect(self._onInstanceChanged)
|
||||
|
||||
## Called when closing the application.
|
||||
#
|
||||
# This function should terminate the engine process.
|
||||
def close(self):
|
||||
# Terminate CuraEngine if it is still running at this point
|
||||
self._terminate()
|
||||
super().close()
|
||||
|
||||
## Get the command that is used to call the engine.
|
||||
# This is usefull for debugging and used to actually start the engine
|
||||
# This is useful for debugging and used to actually start the engine.
|
||||
# \return list of commands and args / parameters.
|
||||
def getEngineCommand(self):
|
||||
active_machine = Application.getInstance().getMachineManager().getActiveMachineInstance()
|
||||
json_path = ""
|
||||
if not active_machine:
|
||||
json_path = Resources.getPath(Resources.MachineDefinitions, "fdmprinter.json")
|
||||
else:
|
||||
json_path = active_machine.getMachineDefinition().getPath()
|
||||
|
||||
json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json")
|
||||
return [Preferences.getInstance().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, "-vv"]
|
||||
|
||||
def close(self):
|
||||
|
@ -116,45 +117,51 @@ class CuraEngineBackend(Backend):
|
|||
## Emitted when the slicing process starts.
|
||||
slicingStarted = Signal()
|
||||
|
||||
## Emitted whne the slicing process is aborted forcefully.
|
||||
## Emitted when the slicing process is aborted forcefully.
|
||||
slicingCancelled = Signal()
|
||||
|
||||
## Perform a slice of the scene.
|
||||
def slice(self):
|
||||
self._stored_layer_data = []
|
||||
|
||||
if not self._enabled:
|
||||
if not self._enabled: #We shouldn't be slicing.
|
||||
return
|
||||
|
||||
if self._slicing:
|
||||
if self._slicing: #We were already slicing. Stop the old job.
|
||||
self._terminate()
|
||||
|
||||
if self._message:
|
||||
self._message.hide()
|
||||
self._message = None
|
||||
|
||||
return
|
||||
|
||||
if self._process_layers_job:
|
||||
if self._process_layers_job: #We were processing layers. Stop that, the layers are going to change soon.
|
||||
self._process_layers_job.abort()
|
||||
self._process_layers_job = None
|
||||
|
||||
if self._profile.hasErrorValue():
|
||||
Logger.log("w", "Profile has error values. Aborting slicing")
|
||||
if self._message:
|
||||
self._message.hide()
|
||||
self._message = None
|
||||
self._message = Message(catalog.i18nc("@info:status", "Unable to slice. Please check your setting values for errors."))
|
||||
self._message.show()
|
||||
return #No slicing if we have error values since those are by definition illegal values.
|
||||
#Don't slice if there is a setting with an error value.
|
||||
stack = Application.getInstance().getGlobalContainerStack()
|
||||
for key in stack.getAllKeys():
|
||||
validation_state = stack.getProperty(key, "validationState")
|
||||
#Only setting instances have a validation state, so settings which
|
||||
#are not overwritten by any instance will have none. The property
|
||||
#then, and only then, evaluates to None. We make the assumption that
|
||||
#the definition defines the setting with a default value that is
|
||||
#valid. Therefore we can allow both ValidatorState.Valid and None as
|
||||
#allowable validation states.
|
||||
#TODO: This assumption is wrong! If the definition defines an inheritance function that through inheritance evaluates to a disallowed value, a setting is still invalid even though it's default!
|
||||
#TODO: Therefore we must also validate setting definitions.
|
||||
if validation_state != None and validation_state != ValidatorState.Valid:
|
||||
Logger.log("w", "Setting %s is not valid, but %s. Aborting slicing.", key, validation_state)
|
||||
if self._message: #Hide any old message before creating a new one.
|
||||
self._message.hide()
|
||||
self._message = None
|
||||
self._message = Message(catalog.i18nc("@info:status", "Unable to slice. Please check your setting values for errors."))
|
||||
self._message.show()
|
||||
return
|
||||
|
||||
self.processingProgress.emit(0.0)
|
||||
self.backendStateChange.emit(BackendState.NOT_STARTED)
|
||||
if self._message:
|
||||
self._message.setProgress(-1)
|
||||
#else:
|
||||
# self._message = Message(catalog.i18nc("@info:status", "Slicing..."), 0, False, -1)
|
||||
# self._message.show()
|
||||
else:
|
||||
self._message = Message(catalog.i18nc("@info:status", "Slicing..."), 0, False, -1)
|
||||
self._message.show()
|
||||
|
||||
self._scene.gcode_list = []
|
||||
self._slicing = True
|
||||
|
@ -162,10 +169,11 @@ class CuraEngineBackend(Backend):
|
|||
|
||||
slice_message = self._socket.createMessage("cura.proto.Slice")
|
||||
settings_message = self._socket.createMessage("cura.proto.SettingList");
|
||||
self._start_slice_job = StartSliceJob.StartSliceJob(self._profile, slice_message, settings_message)
|
||||
self._start_slice_job = StartSliceJob.StartSliceJob(slice_message, settings_message)
|
||||
self._start_slice_job.start()
|
||||
self._start_slice_job.finished.connect(self._onStartSliceCompleted)
|
||||
|
||||
## Terminate the engine process.
|
||||
def _terminate(self):
|
||||
self._slicing = False
|
||||
self._restart = True
|
||||
|
@ -182,10 +190,21 @@ class CuraEngineBackend(Backend):
|
|||
self._process.terminate()
|
||||
Logger.log("d", "Engine process is killed. Received return code %s", self._process.wait())
|
||||
self._process = None
|
||||
#self._createSocket() # Re create the socket
|
||||
except Exception as e: # terminating a process that is already terminating causes an exception, silently ignore this.
|
||||
Logger.log("d", "Exception occured while trying to kill the engine %s", str(e))
|
||||
Logger.log("d", "Exception occurred while trying to kill the engine %s", str(e))
|
||||
|
||||
if self._message:
|
||||
self._message.hide()
|
||||
self._message = None
|
||||
|
||||
## Event handler to call when the job to initiate the slicing process is
|
||||
# completed.
|
||||
#
|
||||
# When the start slice job is successfully completed, it will be happily
|
||||
# slicing. This function handles any errors that may occur during the
|
||||
# bootstrapping of a slice job.
|
||||
#
|
||||
# \param job The start slice job that was just finished.
|
||||
def _onStartSliceCompleted(self, job):
|
||||
# Note that cancelled slice jobs can still call this method.
|
||||
if self._start_slice_job is job:
|
||||
|
@ -200,6 +219,11 @@ class CuraEngineBackend(Backend):
|
|||
self._socket.sendMessage(job.getSettingsMessage())
|
||||
self._socket.sendMessage(job.getSliceMessage())
|
||||
|
||||
## Listener for when the scene has changed.
|
||||
#
|
||||
# This should start a slice if the scene is now ready to slice.
|
||||
#
|
||||
# \param source The scene node that was changed.
|
||||
def _onSceneChanged(self, source):
|
||||
if type(source) is not SceneNode:
|
||||
return
|
||||
|
@ -215,6 +239,9 @@ class CuraEngineBackend(Backend):
|
|||
|
||||
self._onChanged()
|
||||
|
||||
## Called when an error occurs in the socket connection towards the engine.
|
||||
#
|
||||
# \param error The exception that occurred.
|
||||
def _onSocketError(self, error):
|
||||
if Application.getInstance().isShuttingDown():
|
||||
return
|
||||
|
@ -225,22 +252,23 @@ class CuraEngineBackend(Backend):
|
|||
if error.getErrorCode() not in [Arcus.ErrorCode.BindFailedError, Arcus.ErrorCode.ConnectionResetError, Arcus.ErrorCode.Debug]:
|
||||
Logger.log("e", "A socket error caused the connection to be reset")
|
||||
|
||||
def _onActiveProfileChanged(self):
|
||||
if self._profile:
|
||||
self._profile.settingValueChanged.disconnect(self._onSettingChanged)
|
||||
|
||||
self._profile = Application.getInstance().getMachineManager().getWorkingProfile()
|
||||
if self._profile:
|
||||
self._profile.settingValueChanged.connect(self._onSettingChanged)
|
||||
## A setting has changed, so check if we must reslice.
|
||||
#
|
||||
# \param instance The setting instance that has changed.
|
||||
# \param property The property of the setting instance that has changed.
|
||||
def _onSettingChanged(self, instance, property):
|
||||
if property == "value": #Only reslice if the value has changed.
|
||||
self._onChanged()
|
||||
|
||||
def _onSettingChanged(self, setting):
|
||||
self._onChanged()
|
||||
|
||||
## Called when a sliced layer data message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing sliced layer data.
|
||||
def _onLayerMessage(self, message):
|
||||
self._stored_layer_data.append(message)
|
||||
|
||||
|
||||
## Called when a progress message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing the slicing progress.
|
||||
def _onProgressMessage(self, message):
|
||||
if self._message:
|
||||
self._message.setProgress(round(message.amount * 100))
|
||||
|
@ -248,6 +276,9 @@ class CuraEngineBackend(Backend):
|
|||
self.processingProgress.emit(message.amount)
|
||||
self.backendStateChange.emit(BackendState.PROCESSING)
|
||||
|
||||
## Called when the engine sends a message that slicing is finished.
|
||||
#
|
||||
# \param message The protobuf message signalling that slicing is finished.
|
||||
def _onSlicingFinishedMessage(self, message):
|
||||
self.backendStateChange.emit(BackendState.DONE)
|
||||
self.processingProgress.emit(1.0)
|
||||
|
@ -264,15 +295,27 @@ class CuraEngineBackend(Backend):
|
|||
self._process_layers_job.start()
|
||||
self._stored_layer_data = []
|
||||
|
||||
## Called when a g-code message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing g-code, encoded as UTF-8.
|
||||
def _onGCodeLayerMessage(self, message):
|
||||
self._scene.gcode_list.append(message.data.decode("utf-8", "replace"))
|
||||
|
||||
## Called when a g-code prefix message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing the g-code prefix,
|
||||
# encoded as UTF-8.
|
||||
def _onGCodePrefixMessage(self, message):
|
||||
self._scene.gcode_list.insert(0, message.data.decode("utf-8", "replace"))
|
||||
|
||||
## Called when a print time message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing the print time and
|
||||
# material amount.
|
||||
def _onObjectPrintTimeMessage(self, message):
|
||||
self.printDurationMessage.emit(message.time, message.material_amount)
|
||||
|
||||
## Creates a new socket connection.
|
||||
def _createSocket(self):
|
||||
super()._createSocket(os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto")))
|
||||
|
||||
|
@ -280,28 +323,41 @@ class CuraEngineBackend(Backend):
|
|||
def forceSlice(self):
|
||||
self._change_timer.start()
|
||||
|
||||
## Called when anything has changed to the stuff that needs to be sliced.
|
||||
#
|
||||
# This indicates that we should probably re-slice soon.
|
||||
def _onChanged(self):
|
||||
if not self._profile:
|
||||
return
|
||||
|
||||
self._change_timer.start()
|
||||
|
||||
## Called when the back-end connects to the front-end.
|
||||
def _onBackendConnected(self):
|
||||
if self._restart:
|
||||
self._onChanged()
|
||||
self._restart = False
|
||||
|
||||
## Called when the user starts using some tool.
|
||||
#
|
||||
# When the user starts using a tool, we should pause slicing to prevent
|
||||
# continuously slicing while the user is dragging some tool handle.
|
||||
#
|
||||
# \param tool The tool that the user is using.
|
||||
def _onToolOperationStarted(self, tool):
|
||||
self._terminate() # Do not continue slicing once a tool has started
|
||||
self._enabled = False # Do not reslice when a tool is doing it's 'thing'
|
||||
|
||||
## Called when the user stops using some tool.
|
||||
#
|
||||
# This indicates that we can safely start slicing again.
|
||||
#
|
||||
# \param tool The tool that the user was using.
|
||||
def _onToolOperationStopped(self, tool):
|
||||
self._enabled = True # Tool stop, start listening for changes again.
|
||||
|
||||
## Called when the user changes the active view mode.
|
||||
def _onActiveViewChanged(self):
|
||||
if Application.getInstance().getController().getActiveView():
|
||||
view = Application.getInstance().getController().getActiveView()
|
||||
if view.getPluginId() == "LayerView":
|
||||
if view.getPluginId() == "LayerView": #If switching to layer view, we should process the layers if that hasn't been done yet.
|
||||
self._layer_view_active = True
|
||||
# There is data and we're not slicing at the moment
|
||||
# if we are slicing, there is no need to re-calculate the data as it will be invalid in a moment.
|
||||
|
@ -312,9 +368,9 @@ class CuraEngineBackend(Backend):
|
|||
else:
|
||||
self._layer_view_active = False
|
||||
|
||||
def _onInstanceChanged(self):
|
||||
self._terminate()
|
||||
|
||||
## Called when the back-end self-terminates.
|
||||
#
|
||||
# We should reset our state and start listening for new connections.
|
||||
def _onBackendQuit(self):
|
||||
if not self._restart and self._process:
|
||||
Logger.log("d", "Backend quit with return code %s. Resetting process and socket.", self._process.wait())
|
||||
|
|
|
@ -62,8 +62,6 @@ class ProcessSlicedLayersJob(Job):
|
|||
self._progress.hide()
|
||||
return
|
||||
|
||||
settings = Application.getInstance().getMachineManager().getWorkingProfile()
|
||||
|
||||
mesh = MeshData()
|
||||
layer_data = LayerData.LayerData()
|
||||
layer_count = len(self._layers)
|
||||
|
@ -132,8 +130,9 @@ class ProcessSlicedLayersJob(Job):
|
|||
new_node.setMeshData(mesh)
|
||||
new_node.setParent(self._scene.getRoot()) # Note: After this we can no longer abort!
|
||||
|
||||
if not settings.getSettingValue("machine_center_is_zero"):
|
||||
new_node.setPosition(Vector(-settings.getSettingValue("machine_width") / 2, 0.0, settings.getSettingValue("machine_depth") / 2))
|
||||
settings = Application.getInstance().getGlobalContainerStack()
|
||||
if not settings.getProperty("machine_center_is_zero", "value"):
|
||||
new_node.setPosition(Vector(-settings.getProperty("machine_width", "value") / 2, 0.0, settings.getProperty("machine_depth", "value") / 2))
|
||||
|
||||
if self._progress:
|
||||
self._progress.setProgress(100)
|
||||
|
|
|
@ -30,11 +30,10 @@ class GcodeStartEndFormatter(Formatter):
|
|||
|
||||
## Job class that builds up the message of scene data to send to CuraEngine.
|
||||
class StartSliceJob(Job):
|
||||
def __init__(self, profile, slice_message, settings_message):
|
||||
def __init__(self, slice_message, settings_message):
|
||||
super().__init__()
|
||||
|
||||
self._scene = Application.getInstance().getController().getScene()
|
||||
self._profile = profile
|
||||
self._slice_message = slice_message
|
||||
self._settings_message = settings_message
|
||||
self._is_cancelled = False
|
||||
|
@ -45,18 +44,27 @@ class StartSliceJob(Job):
|
|||
def getSliceMessage(self):
|
||||
return self._slice_message
|
||||
|
||||
## Runs the job that initiates the slicing.
|
||||
def run(self):
|
||||
stack = Application.getInstance().getGlobalContainerStack()
|
||||
if not stack:
|
||||
self.setResult(False)
|
||||
return
|
||||
|
||||
with self._scene.getSceneLock():
|
||||
# Remove old layer data.
|
||||
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||
if node.callDecoration("getLayerData"):
|
||||
node.getParent().removeChild(node)
|
||||
break
|
||||
|
||||
# Get the objects in their groups to print.
|
||||
object_groups = []
|
||||
if self._profile.getSettingValue("print_sequence") == "one_at_a_time":
|
||||
if stack.getProperty("print_sequence", "value") == "one_at_a_time":
|
||||
for node in OneAtATimeIterator(self._scene.getRoot()):
|
||||
temp_list = []
|
||||
|
||||
# Node can't be printed, so don't bother sending it.
|
||||
if getattr(node, "_outside_buildarea", False):
|
||||
continue
|
||||
|
||||
|
@ -85,7 +93,7 @@ class StartSliceJob(Job):
|
|||
if not object_groups:
|
||||
return
|
||||
|
||||
self._buildSettingsMessage(self._profile)
|
||||
self._buildGlobalSettingsMessage(stack)
|
||||
|
||||
for group in object_groups:
|
||||
group_message = self._slice_message.addRepeatedMessage("object_lists")
|
||||
|
@ -97,8 +105,10 @@ class StartSliceJob(Job):
|
|||
obj = group_message.addRepeatedMessage("objects")
|
||||
obj.id = id(object)
|
||||
verts = numpy.array(mesh_data.getVertices())
|
||||
verts[:,[1,2]] = verts[:,[2,1]]
|
||||
verts[:,1] *= -1
|
||||
|
||||
# Convert from Y up axes to Z up axes. Equals a 90 degree rotation.
|
||||
verts[:, [1, 2]] = verts[:, [2, 1]]
|
||||
verts[:, 1] *= -1
|
||||
|
||||
obj.vertices = verts
|
||||
|
||||
|
@ -124,18 +134,27 @@ class StartSliceJob(Job):
|
|||
Logger.log("w", "Unabled to do token replacement on start/end gcode %s", traceback.format_exc())
|
||||
return str(value).encode("utf-8")
|
||||
|
||||
def _buildSettingsMessage(self, profile):
|
||||
settings = profile.getAllSettingValues(include_machine = True)
|
||||
## Sends all global settings to the engine.
|
||||
#
|
||||
# The settings are taken from the global stack. This does not include any
|
||||
# per-extruder settings or per-object settings.
|
||||
def _buildGlobalSettingsMessage(self, stack):
|
||||
keys = stack.getAllKeys()
|
||||
settings = {}
|
||||
for key in keys:
|
||||
settings[key] = stack.getProperty(key, "value")
|
||||
|
||||
start_gcode = settings["machine_start_gcode"]
|
||||
settings["material_bed_temp_prepend"] = "{material_bed_temperature}" not in start_gcode
|
||||
settings["material_bed_temp_prepend"] = "{material_bed_temperature}" not in start_gcode #Pre-compute material material_bed_temp_prepend and material_print_temp_prepend
|
||||
settings["material_print_temp_prepend"] = "{material_print_temperature}" not in start_gcode
|
||||
for key, value in settings.items():
|
||||
s = self._settings_message.addRepeatedMessage("settings")
|
||||
s.name = key
|
||||
if key == "machine_start_gcode" or key == "machine_end_gcode":
|
||||
s.value = self._expandGcodeTokens(key, value, settings)
|
||||
|
||||
for key, value in settings.items(): #Add all submessages for each individual setting.
|
||||
setting_message = self._settings_message.addRepeatedMessage("settings")
|
||||
setting_message.name = key
|
||||
if key == "machine_start_gcode" or key == "machine_end_gcode": #If it's a g-code message, use special formatting.
|
||||
setting_message.value = self._expandGcodeTokens(key, value, settings)
|
||||
else:
|
||||
s.value = str(value).encode("utf-8")
|
||||
setting_message.value = str(value).encode("utf-8")
|
||||
|
||||
def _handlePerObjectSettings(self, node, message):
|
||||
profile = node.callDecoration("getProfile")
|
||||
|
|
|
@ -13,7 +13,7 @@ def getMetaData():
|
|||
"name": catalog.i18nc("@label", "CuraEngine Backend"),
|
||||
"author": "Ultimaker",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Provides the link to the CuraEngine slicing backend."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
# Copyright (c) 2015 Ultimaker B.V.
|
||||
# Copyright (c) 2016 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from UM.Mesh.MeshWriter import MeshWriter
|
||||
from UM.Logger import Logger
|
||||
from UM.Application import Application
|
||||
from UM.Settings.InstanceContainer import InstanceContainer #To create a complete setting profile to store in the g-code.
|
||||
import re #For escaping characters in the settings.
|
||||
import copy
|
||||
|
||||
|
||||
## Writes g-code to a file.
|
||||
#
|
||||
# While this poses as a mesh writer, what this really does is take the g-code
|
||||
# in the entire scene and write it to an output device. Since the g-code of a
|
||||
# single mesh isn't separable from the rest what with rafts and travel moves
|
||||
# and all, it doesn't make sense to write just a single mesh.
|
||||
#
|
||||
# So this plug-in takes the g-code that is stored in the root of the scene
|
||||
# node tree, adds a bit of extra information about the profiles and writes
|
||||
# that to the output device.
|
||||
class GCodeWriter(MeshWriter):
|
||||
## The file format version of the serialised g-code.
|
||||
#
|
||||
|
@ -32,7 +41,7 @@ class GCodeWriter(MeshWriter):
|
|||
|
||||
def write(self, stream, node, mode = MeshWriter.OutputMode.TextMode):
|
||||
if mode != MeshWriter.OutputMode.TextMode:
|
||||
Logger.log("e", "GCode Writer does not support non-text mode")
|
||||
Logger.log("e", "GCode Writer does not support non-text mode.")
|
||||
return False
|
||||
|
||||
scene = Application.getInstance().getController().getScene()
|
||||
|
@ -40,26 +49,30 @@ class GCodeWriter(MeshWriter):
|
|||
if gcode_list:
|
||||
for gcode in gcode_list:
|
||||
stream.write(gcode)
|
||||
# Serialise the profile and put them at the end of the file.
|
||||
profile = self._serialiseProfile(Application.getInstance().getMachineManager().getWorkingProfile())
|
||||
stream.write(profile)
|
||||
# Serialise the current container stack and put it at the end of the file.
|
||||
settings = self._serialiseSettings(Application.getInstance().getGlobalContainerStack())
|
||||
stream.write(settings)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
## Serialises the profile to prepare it for saving in the g-code.
|
||||
## Serialises a container stack to prepare it for writing at the end of the
|
||||
# g-code.
|
||||
#
|
||||
# The profile are serialised, and special characters (including newline)
|
||||
# The settings are serialised, and special characters (including newline)
|
||||
# are escaped.
|
||||
#
|
||||
# \param profile The profile to serialise.
|
||||
# \return A serialised string of the profile.
|
||||
def _serialiseProfile(self, profile):
|
||||
# \param settings A container stack to serialise.
|
||||
# \return A serialised string of the settings.
|
||||
def _serialiseSettings(self, settings):
|
||||
prefix = ";SETTING_" + str(GCodeWriter.version) + " " # The prefix to put before each line.
|
||||
prefix_length = len(prefix)
|
||||
|
||||
# Serialise a deepcopy to remove the defaults from the profile
|
||||
serialised = copy.deepcopy(profile).serialise()
|
||||
all_settings = InstanceContainer("G-code-imported-profile") #Create a new 'profile' with ALL settings so that the slice can be precisely reproduced.
|
||||
all_settings.setDefinition(settings.getBottom())
|
||||
for key in settings.getAllKeys():
|
||||
all_settings.setProperty(key, "value", settings.getProperty(key, "value")) #Just copy everything over to the setting instance.
|
||||
serialised = all_settings.serialize()
|
||||
|
||||
# Escape characters that have a special meaning in g-code comments.
|
||||
pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))
|
||||
|
|
|
@ -13,7 +13,7 @@ def getMetaData():
|
|||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Writes GCode to a file."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
},
|
||||
|
||||
"mesh_writer": {
|
||||
|
|
|
@ -14,7 +14,7 @@ def getMetaData():
|
|||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Provides the Layer view."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
},
|
||||
"view": {
|
||||
"name": catalog.i18nc("@item:inlistbox", "Layers"),
|
||||
|
|
|
@ -9,8 +9,9 @@ import os.path #For concatenating the path to the plugin and the relative path t
|
|||
from UM.Application import Application #To get the machine manager to create the new profile in.
|
||||
from UM.Logger import Logger #Logging errors.
|
||||
from UM.PluginRegistry import PluginRegistry #For getting the path to this plugin's directory.
|
||||
from UM.Settings.Profile import Profile
|
||||
from UM.Settings.ProfileReader import ProfileReader
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer #For getting the current machine's defaults.
|
||||
from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
|
||||
from cura.ProfileReader import ProfileReader #The plug-in type to implement.
|
||||
|
||||
## A plugin that reads profile data from legacy Cura versions.
|
||||
#
|
||||
|
@ -66,7 +67,7 @@ class LegacyProfileReader(ProfileReader):
|
|||
if file_name.split(".")[-1] != "ini":
|
||||
return None
|
||||
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
|
||||
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
|
||||
profile = InstanceContainer("Imported Legacy Profile") #Create an empty profile.
|
||||
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
try:
|
||||
|
@ -103,23 +104,24 @@ class LegacyProfileReader(ProfileReader):
|
|||
if "target_version" not in dict_of_doom:
|
||||
Logger.log("e", "Dictionary of Doom has no target version. Is it the correct JSON file?")
|
||||
return None
|
||||
if Profile.ProfileVersion != dict_of_doom["target_version"]:
|
||||
Logger.log("e", "Dictionary of Doom of legacy profile reader (version %s) is not in sync with the profile version (version %s)!", dict_of_doom["target_version"], str(Profile.ProfileVersion))
|
||||
if InstanceContainer.Version != dict_of_doom["target_version"]:
|
||||
Logger.log("e", "Dictionary of Doom of legacy profile reader (version %s) is not in sync with the current instance container version (version %s)!", dict_of_doom["target_version"], str(InstanceContainer.Version))
|
||||
return None
|
||||
|
||||
if "translation" not in dict_of_doom:
|
||||
Logger.log("e", "Dictionary of Doom has no translation. Is it the correct JSON file?")
|
||||
return None
|
||||
current_printer = Application.getInstance().getGlobalContainerStack().findContainer({ }, DefinitionContainer)
|
||||
for new_setting in dict_of_doom["translation"]: #Evaluate all new settings that would get a value from the translations.
|
||||
old_setting_expression = dict_of_doom["translation"][new_setting]
|
||||
compiled = compile(old_setting_expression, new_setting, "eval")
|
||||
try:
|
||||
new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation.
|
||||
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
|
||||
except Exception as e: #Probably some setting name that was missing or something else that went wrong in the ini file.
|
||||
except Exception: #Probably some setting name that was missing or something else that went wrong in the ini file.
|
||||
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
|
||||
continue
|
||||
if new_value != value_using_defaults and profile.getSettingValue(new_setting) != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura.
|
||||
if new_value != value_using_defaults and current_printer.findDefinitions(key = new_setting).default_value != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura.
|
||||
profile.setSettingValue(new_setting, new_value) #Store the setting in the profile!
|
||||
|
||||
if len(profile.getChangedSettings()) == 0:
|
||||
|
|
|
@ -13,7 +13,7 @@ def getMetaData():
|
|||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Provides support for importing profiles from legacy Cura versions."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
},
|
||||
"profile_reader": [
|
||||
{
|
||||
|
|
29
plugins/PerObjectSettingsTool/PerObjectCategory.qml
Normal file
29
plugins/PerObjectSettingsTool/PerObjectCategory.qml
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2015 Ultimaker B.V.
|
||||
// Uranium is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
import QtQuick 2.2
|
||||
import QtQuick.Controls 1.1
|
||||
import QtQuick.Controls.Styles 1.1
|
||||
import QtQuick.Layouts 1.1
|
||||
|
||||
import UM 1.1 as UM
|
||||
|
||||
import ".."
|
||||
|
||||
Button {
|
||||
id: base;
|
||||
|
||||
style: UM.Theme.styles.sidebar_category;
|
||||
|
||||
signal showTooltip(string text);
|
||||
signal hideTooltip();
|
||||
signal contextMenuRequested()
|
||||
|
||||
text: definition.label
|
||||
iconSource: UM.Theme.getIcon(definition.icon)
|
||||
|
||||
checkable: true
|
||||
checked: definition.expanded
|
||||
|
||||
onClicked: definition.expanded ? settingDefinitionsModel.collapse(definition.key) : settingDefinitionsModel.expandAll(definition.key)
|
||||
}
|
29
plugins/PerObjectSettingsTool/PerObjectItem.qml
Normal file
29
plugins/PerObjectSettingsTool/PerObjectItem.qml
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2015 Ultimaker B.V.
|
||||
// Uranium is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
import QtQuick 2.1
|
||||
import QtQuick.Layouts 1.1
|
||||
import QtQuick.Controls 1.1
|
||||
import QtQuick.Controls.Styles 1.1
|
||||
|
||||
import UM 1.2 as UM
|
||||
|
||||
UM.TooltipArea
|
||||
{
|
||||
x: model.depth * UM.Theme.getSize("default_margin").width;
|
||||
text: model.description;
|
||||
|
||||
width: childrenRect.width;
|
||||
height: childrenRect.height;
|
||||
|
||||
Button
|
||||
{
|
||||
id: check
|
||||
|
||||
text: definition.label
|
||||
|
||||
//onClicked: delegateItem.settingsModel.setSettingVisible(model.key, checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7,8 +7,8 @@ from UM.Application import Application
|
|||
from UM.Qt.ListModel import ListModel
|
||||
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
||||
from UM.Settings.ProfileOverrideDecorator import ProfileOverrideDecorator
|
||||
#from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
||||
#from UM.Settings.ProfileOverrideDecorator import ProfileOverrideDecorator
|
||||
|
||||
from . import SettingOverrideModel
|
||||
|
||||
|
@ -35,7 +35,7 @@ class PerObjectSettingsModel(ListModel):
|
|||
self.setProperty(self.find("id", object_id), "profile", profile_name)
|
||||
|
||||
profile = None
|
||||
if profile_name != "global":
|
||||
'''if profile_name != "global":
|
||||
profile = Application.getInstance().getMachineManager().findProfile(profile_name)
|
||||
|
||||
node = self._scene.findObject(object_id)
|
||||
|
@ -45,7 +45,7 @@ class PerObjectSettingsModel(ListModel):
|
|||
node.callDecoration("setProfile", profile)
|
||||
else:
|
||||
if node.getDecorator(ProfileOverrideDecorator):
|
||||
node.removeDecorator(ProfileOverrideDecorator)
|
||||
node.removeDecorator(ProfileOverrideDecorator)'''
|
||||
|
||||
@pyqtSlot("quint64", str)
|
||||
def addSettingOverride(self, object_id, key):
|
||||
|
@ -54,8 +54,8 @@ class PerObjectSettingsModel(ListModel):
|
|||
return
|
||||
|
||||
node = self._scene.findObject(object_id)
|
||||
if not node.getDecorator(SettingOverrideDecorator):
|
||||
node.addDecorator(SettingOverrideDecorator())
|
||||
#if not node.getDecorator(SettingOverrideDecorator):
|
||||
# node.addDecorator(SettingOverrideDecorator())
|
||||
|
||||
node.callDecoration("addSetting", key)
|
||||
|
||||
|
@ -64,8 +64,8 @@ class PerObjectSettingsModel(ListModel):
|
|||
node = self._scene.findObject(object_id)
|
||||
node.callDecoration("removeSetting", key)
|
||||
|
||||
if len(node.callDecoration("getAllSettings")) == 0:
|
||||
node.removeDecorator(SettingOverrideDecorator)
|
||||
#if len(node.callDecoration("getAllSettings")) == 0:
|
||||
# node.removeDecorator(SettingOverrideDecorator)
|
||||
|
||||
def _updateModel(self):
|
||||
self.clear()
|
||||
|
|
|
@ -6,7 +6,10 @@ import QtQuick.Controls 1.2
|
|||
import QtQuick.Controls.Styles 1.2
|
||||
import QtQuick.Window 2.2
|
||||
|
||||
import UM 1.1 as UM
|
||||
import UM 1.2 as UM
|
||||
import Cura 1.0 as Cura
|
||||
import ".."
|
||||
|
||||
|
||||
Item {
|
||||
id: base;
|
||||
|
@ -133,6 +136,7 @@ Item {
|
|||
id: settingPickDialog
|
||||
|
||||
title: catalog.i18nc("@title:window", "Pick a Setting to Customize")
|
||||
property string labelFilter: ""
|
||||
|
||||
TextField {
|
||||
id: filter;
|
||||
|
@ -145,123 +149,61 @@ Item {
|
|||
|
||||
placeholderText: catalog.i18nc("@label:textbox", "Filter...");
|
||||
|
||||
onTextChanged: settingCategoriesModel.filter(text);
|
||||
onTextChanged:
|
||||
{
|
||||
if(text != "")
|
||||
{
|
||||
listview.model.filter = {"global_only": false, "label": "*" + text}
|
||||
}
|
||||
else
|
||||
{
|
||||
listview.model.filter = {"global_only": false}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
id: view;
|
||||
anchors {
|
||||
ScrollView
|
||||
{
|
||||
id: scrollView
|
||||
|
||||
anchors
|
||||
{
|
||||
top: filter.bottom;
|
||||
left: parent.left;
|
||||
right: parent.right;
|
||||
bottom: parent.bottom;
|
||||
}
|
||||
ListView
|
||||
{
|
||||
id:listview
|
||||
model: UM.SettingDefinitionsModel
|
||||
{
|
||||
id: definitionsModel;
|
||||
containerId: Cura.MachineManager.activeDefinitionId
|
||||
filter:
|
||||
{
|
||||
"global_only": false
|
||||
}
|
||||
}
|
||||
delegate:Loader
|
||||
{
|
||||
id: loader
|
||||
|
||||
Column {
|
||||
width: view.width - UM.Theme.getSize("default_margin").width * 2;
|
||||
height: childrenRect.height;
|
||||
width: parent.width
|
||||
height: model.type != undefined ? UM.Theme.getSize("section").height : 0;
|
||||
|
||||
Repeater {
|
||||
id: settingList;
|
||||
property var definition: model
|
||||
property var settingDefinitionsModel: definitionsModel
|
||||
|
||||
model: UM.SettingCategoriesModel { id: settingCategoriesModel; }
|
||||
|
||||
delegate: Item {
|
||||
id: delegateItem;
|
||||
|
||||
width: parent.width;
|
||||
height: childrenRect.height;
|
||||
visible: model.visible && settingsColumn.childrenHeight != 0 //If all children are hidden, the height is 0, and then the category header must also be hidden.
|
||||
|
||||
ToolButton {
|
||||
id: categoryHeader;
|
||||
text: model.name;
|
||||
checkable: true;
|
||||
width: parent.width;
|
||||
onCheckedChanged: settingsColumn.state != "" ? settingsColumn.state = "" : settingsColumn.state = "collapsed";
|
||||
|
||||
style: ButtonStyle {
|
||||
background: Rectangle
|
||||
{
|
||||
width: control.width;
|
||||
height: control.height;
|
||||
color: control.hovered ? palette.highlight : "transparent";
|
||||
}
|
||||
label: Row
|
||||
{
|
||||
spacing: UM.Theme.getSize("default_margin").width;
|
||||
Image
|
||||
{
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
source: control.checked ? UM.Theme.getIcon("arrow_right") : UM.Theme.getIcon("arrow_bottom");
|
||||
}
|
||||
Label
|
||||
{
|
||||
text: control.text;
|
||||
font.bold: true;
|
||||
color: control.hovered ? palette.highlightedText : palette.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property variant settingsModel: model.settings;
|
||||
|
||||
Column {
|
||||
id: settingsColumn;
|
||||
|
||||
anchors.top: categoryHeader.bottom;
|
||||
|
||||
property real childrenHeight:
|
||||
{
|
||||
var h = 0.0;
|
||||
for(var i in children)
|
||||
{
|
||||
var item = children[i];
|
||||
h += children[i].height;
|
||||
if(item.settingVisible)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
h += spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
width: childrenRect.width;
|
||||
height: childrenHeight;
|
||||
Repeater {
|
||||
model: delegateItem.settingsModel;
|
||||
|
||||
delegate: ToolButton {
|
||||
id: button;
|
||||
x: model.visible_depth * UM.Theme.getSize("default_margin").width;
|
||||
text: model.name;
|
||||
tooltip: model.description;
|
||||
visible: !model.global_only
|
||||
height: model.global_only ? 0 : undefined
|
||||
|
||||
onClicked: {
|
||||
var object_id = UM.ActiveTool.properties.getValue("Model").getItem(base.currentIndex).id;
|
||||
UM.ActiveTool.properties.getValue("Model").addSettingOverride(object_id, model.key);
|
||||
settingPickDialog.visible = false;
|
||||
}
|
||||
|
||||
states: State {
|
||||
name: "filtered"
|
||||
when: model.filtered || !model.visible || !model.enabled
|
||||
PropertyChanges { target: button; height: 0; opacity: 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
states: State {
|
||||
name: "collapsed";
|
||||
|
||||
PropertyChanges { target: settingsColumn; opacity: 0; height: 0; }
|
||||
}
|
||||
asynchronous: true
|
||||
source:
|
||||
{
|
||||
switch(model.type)
|
||||
{
|
||||
case "category":
|
||||
return "PerObjectCategory.qml"
|
||||
default:
|
||||
return "PerObjectItem.qml"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ from PyQt5.QtCore import Qt, pyqtSlot, QUrl
|
|||
|
||||
from UM.Application import Application
|
||||
from UM.Qt.ListModel import ListModel
|
||||
from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
||||
#from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
||||
|
||||
class SettingOverrideModel(ListModel):
|
||||
KeyRole = Qt.UserRole + 1
|
||||
|
@ -29,9 +29,9 @@ class SettingOverrideModel(ListModel):
|
|||
self._node.decoratorsChanged.connect(self._onDecoratorsChanged)
|
||||
self._onDecoratorsChanged(None)
|
||||
|
||||
self._activeProfile = Application.getInstance().getMachineManager().getWorkingProfile() #To be able to get notified when a setting changes.
|
||||
self._activeProfile.settingValueChanged.connect(self._onProfileSettingValueChanged)
|
||||
Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onProfileChanged)
|
||||
#self._activeProfile = Application.getInstance().getMachineManager().getWorkingProfile() #To be able to get notified when a setting changes.
|
||||
#self._activeProfile.settingValueChanged.connect(self._onProfileSettingValueChanged)
|
||||
#Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onProfileChanged)
|
||||
|
||||
self.addRoleName(self.KeyRole, "key")
|
||||
self.addRoleName(self.LabelRole, "label")
|
||||
|
@ -53,7 +53,8 @@ class SettingOverrideModel(ListModel):
|
|||
self._decorator.setSettingValue(key, value)
|
||||
|
||||
def _onDecoratorsChanged(self, node):
|
||||
if not self._node.getDecorator(SettingOverrideDecorator):
|
||||
return
|
||||
'''if not self._node.getDecorator(SettingOverrideDecorator):
|
||||
self.clear()
|
||||
return
|
||||
|
||||
|
@ -61,7 +62,7 @@ class SettingOverrideModel(ListModel):
|
|||
self._decorator.settingAdded.connect(self._onSettingsChanged)
|
||||
self._decorator.settingRemoved.connect(self._onSettingsChanged)
|
||||
self._decorator.settingValueChanged.connect(self._onSettingValueChanged)
|
||||
self._onSettingsChanged()
|
||||
self._onSettingsChanged()'''
|
||||
|
||||
def _createOptionsModel(self, options):
|
||||
if not options:
|
||||
|
|
|
@ -13,7 +13,7 @@ def getMetaData():
|
|||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": i18n_catalog.i18nc("@info:whatsthis", "Provides the Per Object Settings."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
},
|
||||
"tool": {
|
||||
"name": i18n_catalog.i18nc("@label", "Per Object Settings"),
|
||||
|
|
|
@ -29,17 +29,26 @@ class RemovableDriveOutputDevice(OutputDevice):
|
|||
if self._writing:
|
||||
raise OutputDeviceError.DeviceBusyError()
|
||||
|
||||
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite() #Formats supported by this application.
|
||||
# Formats supported by this application (File types that we can actually write)
|
||||
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
|
||||
if filter_by_machine:
|
||||
machine_file_formats = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getFileFormats()
|
||||
file_formats = list(filter(lambda file_format: file_format["mime_type"] in machine_file_formats, file_formats)) #Take the intersection between file_formats and machine_file_formats.
|
||||
container = Application.getInstance().getGlobalContainerStack().findContainer({"file_formats": "*"})
|
||||
|
||||
# Create a list from supported file formats string
|
||||
machine_file_formats = [file_type.strip() for file_type in container.getMetaDataEntry("file_formats").split(";")]
|
||||
|
||||
# Take the intersection between file_formats and machine_file_formats.
|
||||
file_formats = list(filter(lambda file_format: file_format["mime_type"] in machine_file_formats, file_formats))
|
||||
|
||||
if len(file_formats) == 0:
|
||||
Logger.log("e", "There are no file formats available to write with!")
|
||||
raise OutputDeviceError.WriteRequestFailedError()
|
||||
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"]) #Just take the first file format available.
|
||||
|
||||
# Just take the first file format available.
|
||||
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"])
|
||||
extension = file_formats[0]["extension"]
|
||||
|
||||
if file_name == None:
|
||||
if file_name is None:
|
||||
for n in BreadthFirstIterator(node):
|
||||
if n.getMeshData():
|
||||
file_name = n.getName()
|
||||
|
@ -50,7 +59,7 @@ class RemovableDriveOutputDevice(OutputDevice):
|
|||
Logger.log("e", "Could not determine a proper file name when trying to write to %s, aborting", self.getName())
|
||||
raise OutputDeviceError.WriteRequestFailedError()
|
||||
|
||||
if extension: #Not empty string.
|
||||
if extension: # Not empty string.
|
||||
extension = "." + extension
|
||||
file_name = os.path.join(self.getId(), os.path.splitext(file_name)[0] + extension)
|
||||
|
||||
|
|
|
@ -34,12 +34,10 @@ class SolidView(View):
|
|||
self._disabled_shader.setUniformValue("u_diffuseColor", [0.68, 0.68, 0.68, 1.0])
|
||||
self._disabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0)))
|
||||
|
||||
if Application.getInstance().getMachineManager().getWorkingProfile():
|
||||
profile = Application.getInstance().getMachineManager().getWorkingProfile()
|
||||
|
||||
if Application.getInstance().getGlobalContainerStack():
|
||||
if Preferences.getInstance().getValue("view/show_overhang"):
|
||||
angle = profile.getSettingValue("support_angle")
|
||||
if angle != None:
|
||||
angle = Application.getInstance().getGlobalContainerStack().getProperty("support_angle", "value")
|
||||
if angle is not None:
|
||||
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(90 - angle)))
|
||||
else:
|
||||
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0))) #Overhang angle of 0 causes no area at all to be marked as overhang.
|
||||
|
|
|
@ -13,7 +13,7 @@ def getMetaData():
|
|||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": i18n_catalog.i18nc("@info:whatsthis", "Provides a normal solid mesh view."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
},
|
||||
"view": {
|
||||
"name": i18n_catalog.i18nc("@item:inmenu", "Solid"),
|
||||
|
|
|
@ -13,7 +13,7 @@ def getMetaData():
|
|||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Provides the X-Ray view."),
|
||||
"api": 2
|
||||
"api": 3
|
||||
},
|
||||
"view": {
|
||||
"name": catalog.i18nc("@item:inlistbox", "X-Ray"),
|
||||
|
|
135
plugins/XmlMaterialProfile/XmlMaterialProfile.py
Normal file
135
plugins/XmlMaterialProfile/XmlMaterialProfile.py
Normal file
|
@ -0,0 +1,135 @@
|
|||
# Copyright (c) 2016 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
import math
|
||||
import copy
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from UM.Logger import Logger
|
||||
|
||||
import UM.Settings
|
||||
|
||||
# The namespace is prepended to the tag name but between {}.
|
||||
# We are only interested in the actual tag name, so discard everything
|
||||
# before the last }
|
||||
def _tag_without_namespace(element):
|
||||
return element.tag[element.tag.rfind("}") + 1:]
|
||||
|
||||
class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
||||
def __init__(self, container_id, *args, **kwargs):
|
||||
super().__init__(container_id, *args, **kwargs)
|
||||
|
||||
def serialize(self):
|
||||
raise NotImplementedError("Writing material profiles has not yet been implemented")
|
||||
|
||||
def deserialize(self, serialized):
|
||||
data = ET.fromstring(serialized)
|
||||
|
||||
self.addMetaDataEntry("type", "material")
|
||||
|
||||
# TODO: Add material verfication
|
||||
self.addMetaDataEntry("status", "Unknown")
|
||||
|
||||
metadata = data.iterfind("./um:metadata/*", self.__namespaces)
|
||||
for entry in metadata:
|
||||
tag_name = _tag_without_namespace(entry)
|
||||
|
||||
if tag_name == "name":
|
||||
brand = entry.find("./um:brand", self.__namespaces)
|
||||
material = entry.find("./um:material", self.__namespaces)
|
||||
color = entry.find("./um:color", self.__namespaces)
|
||||
|
||||
self.setName("{0} {1} ({2})".format(brand.text, material.text, color.text))
|
||||
|
||||
self.addMetaDataEntry("brand", brand.text)
|
||||
self.addMetaDataEntry("material", material.text)
|
||||
self.addMetaDataEntry("color_name", color.text)
|
||||
|
||||
self.addMetaDataEntry(tag_name, entry.text)
|
||||
|
||||
property_values = {}
|
||||
properties = data.iterfind("./um:properties/*", self.__namespaces)
|
||||
for entry in properties:
|
||||
tag_name = _tag_without_namespace(entry)
|
||||
property_values[tag_name] = entry.text
|
||||
|
||||
diameter = float(property_values.get("diameter", 2.85)) # In mm
|
||||
density = float(property_values.get("density", 1.3)) # In g/cm3
|
||||
|
||||
weight_per_cm = (math.pi * (diameter / 20) ** 2 * 0.1) * density
|
||||
|
||||
spool_weight = property_values.get("spool_weight")
|
||||
spool_length = property_values.get("spool_length")
|
||||
if spool_weight:
|
||||
length = float(spool_weight) / weight_per_cm
|
||||
property_values["spool_length"] = str(length / 100)
|
||||
elif spool_length:
|
||||
weight = (float(spool_length) * 100) * weight_per_cm
|
||||
property_values["spool_weight"] = str(weight)
|
||||
|
||||
self.addMetaDataEntry("properties", property_values)
|
||||
|
||||
global_setting_values = {}
|
||||
settings = data.iterfind("./um:settings/um:setting", self.__namespaces)
|
||||
for entry in settings:
|
||||
key = entry.get("key")
|
||||
if key in self.__material_property_setting_map:
|
||||
self.setProperty(self.__material_property_setting_map[key], "value", entry.text, self._definition)
|
||||
global_setting_values[key] = entry.text
|
||||
|
||||
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
|
||||
for machine in machines:
|
||||
machine_setting_values = {}
|
||||
settings = machine.iterfind("./um:setting", self.__namespaces)
|
||||
for entry in settings:
|
||||
key = entry.get("key")
|
||||
if key in self.__material_property_setting_map:
|
||||
machine_setting_values[self.__material_property_setting_map[key]] = entry.text
|
||||
|
||||
identifiers = machine.iterfind("./um:machine_identifier", self.__namespaces)
|
||||
for identifier in identifiers:
|
||||
machine_id = self.__product_id_map.get(identifier.get("product"), None)
|
||||
if machine_id is None:
|
||||
Logger.log("w", "Cannot create material for unknown machine %s", machine_id)
|
||||
continue
|
||||
|
||||
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = machine_id)
|
||||
if not definitions:
|
||||
Logger.log("w", "No definition found for machine ID %s", machine_id)
|
||||
continue
|
||||
|
||||
new_material = XmlMaterialProfile(self.id + "_" + machine_id)
|
||||
new_material.setName(self.getName())
|
||||
new_material.setMetaData(self.getMetaData())
|
||||
new_material.setDefinition(definitions[0])
|
||||
|
||||
for key, value in global_setting_values.items():
|
||||
new_material.setProperty(key, "value", value, definitions[0])
|
||||
|
||||
for key, value in machine_setting_values.items():
|
||||
new_material.setProperty(key, "value", value, definitions[0])
|
||||
|
||||
new_material._dirty = False
|
||||
|
||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_material)
|
||||
|
||||
|
||||
__material_property_setting_map = {
|
||||
"print temperature": "material_print_temperature",
|
||||
"heated bed temperature": "material_bed_temperature",
|
||||
"standby temperature": "material_standby_temperature",
|
||||
}
|
||||
|
||||
__product_id_map = {
|
||||
"Ultimaker2": "ultimaker2",
|
||||
"Ultimaker2+": "ultimaker2_plus",
|
||||
"Ultimaker2go": "ultimaker2_go",
|
||||
"Ultimaker2extended": "ultimaker2_extended",
|
||||
"Ultimaker2extended+": "ultimaker2_extended_plus",
|
||||
"Ultimaker Original": "ultimaker_original",
|
||||
"Ultimaker Original+": "ultimaker_original_plus"
|
||||
}
|
||||
|
||||
__namespaces = {
|
||||
"um": "http://www.ultimaker.com/material"
|
||||
}
|
32
plugins/XmlMaterialProfile/__init__.py
Normal file
32
plugins/XmlMaterialProfile/__init__.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Copyright (c) 2016 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from . import XmlMaterialProfile
|
||||
|
||||
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
"plugin": {
|
||||
"name": catalog.i18nc("@label", "Material Profiles"),
|
||||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Provides capabilities to read and write XML-based material profiles."),
|
||||
"api": 3
|
||||
},
|
||||
"settings_container": {
|
||||
"mimetype": "application/x-ultimaker-material-profile"
|
||||
}
|
||||
}
|
||||
|
||||
def register(app):
|
||||
mime_type = MimeType(
|
||||
name = "application/x-ultimaker-material-profile",
|
||||
comment = "Ultimaker Material Profile",
|
||||
suffixes = [ "xml.fdm_material" ]
|
||||
)
|
||||
MimeTypeDatabase.addMimeType(mime_type)
|
||||
return { "settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile") }
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue