mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Store the Quality profile for the 'global' and extruders in the gcode. Read in all of the quality profile during import.
Contributes to CURA-1727 GCode Profile reading/writing: Broken and needs update
This commit is contained in:
parent
26612e17b6
commit
64ecb114b8
5 changed files with 84 additions and 46 deletions
|
@ -4,8 +4,11 @@
|
|||
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.
|
||||
|
||||
from cura.Settings.ExtruderManager import ExtruderManager
|
||||
|
||||
import re #For escaping characters in the settings.
|
||||
import json
|
||||
|
||||
## Writes g-code to a file.
|
||||
#
|
||||
|
@ -23,7 +26,7 @@ class GCodeWriter(MeshWriter):
|
|||
# It can only read settings with the same version as the version it was
|
||||
# written with. If the file format is changed in a way that breaks reverse
|
||||
# compatibility, increment this version number!
|
||||
version = 2
|
||||
version = 3
|
||||
|
||||
## Dictionary that defines how characters are escaped when embedded in
|
||||
# g-code.
|
||||
|
@ -64,25 +67,33 @@ class GCodeWriter(MeshWriter):
|
|||
#
|
||||
# \param settings A container stack to serialise.
|
||||
# \return A serialised string of the settings.
|
||||
def _serialiseSettings(self, settings):
|
||||
def _serialiseSettings(self, stack):
|
||||
prefix = ";SETTING_" + str(GCodeWriter.version) + " " # The prefix to put before each line.
|
||||
prefix_length = len(prefix)
|
||||
|
||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
container_with_profile = global_stack.findContainer({"type": "quality"})
|
||||
container_with_profile = stack.findContainer({"type": "quality"})
|
||||
serialized = container_with_profile.serialize()
|
||||
|
||||
data = {"global_quality": serialized}
|
||||
|
||||
manager = ExtruderManager.getInstance()
|
||||
for extruder in manager.getMachineExtruders(stack.getBottom().getId()):
|
||||
extruder_quality = extruder.findContainer({"type": "quality"})
|
||||
extruder_serialized = extruder_quality.serialize()
|
||||
data.setdefault("extruder_quality", []).append(extruder_serialized)
|
||||
|
||||
json_string = json.dumps(data)
|
||||
|
||||
# Escape characters that have a special meaning in g-code comments.
|
||||
pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))
|
||||
|
||||
# Perform the replacement with a regular expression.
|
||||
serialized = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialized)
|
||||
escaped_string = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], json_string)
|
||||
|
||||
# Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix.
|
||||
result = ""
|
||||
|
||||
# Lines have 80 characters, so the payload of each line is 80 - prefix.
|
||||
for pos in range(0, len(serialized), 80 - prefix_length):
|
||||
result += prefix + serialized[pos : pos + 80 - prefix_length] + "\n"
|
||||
serialized = result
|
||||
|
||||
return serialized
|
||||
for pos in range(0, len(escaped_string), 80 - prefix_length):
|
||||
result += prefix + escaped_string[pos : pos + 80 - prefix_length] + "\n"
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue