mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Remove defaults section from current settings before adding it to a gcode file.
Contributes to CURA-936
This commit is contained in:
parent
05a9b449af
commit
90fda4cb3d
1 changed files with 7 additions and 5 deletions
|
@ -6,6 +6,7 @@ from UM.Logger import Logger
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
import io
|
import io
|
||||||
import re #For escaping characters in the settings.
|
import re #For escaping characters in the settings.
|
||||||
|
import copy
|
||||||
|
|
||||||
|
|
||||||
class GCodeWriter(MeshWriter):
|
class GCodeWriter(MeshWriter):
|
||||||
|
@ -56,17 +57,18 @@ class GCodeWriter(MeshWriter):
|
||||||
def _serialiseProfile(self, profile):
|
def _serialiseProfile(self, profile):
|
||||||
prefix = ";SETTING_" + str(GCodeWriter.version) + " " #The prefix to put before each line.
|
prefix = ";SETTING_" + str(GCodeWriter.version) + " " #The prefix to put before each line.
|
||||||
prefix_length = len(prefix)
|
prefix_length = len(prefix)
|
||||||
|
|
||||||
serialised = profile.serialise()
|
#Serialise a deepcopy to remove the defaults from the profile
|
||||||
|
serialised = copy.deepcopy(profile).serialise()
|
||||||
|
|
||||||
#Escape characters that have a special meaning in g-code comments.
|
#Escape characters that have a special meaning in g-code comments.
|
||||||
pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))
|
pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))
|
||||||
serialised = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialised) #Perform the replacement with a regular expression.
|
serialised = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialised) #Perform the replacement with a regular expression.
|
||||||
|
|
||||||
#Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix.
|
#Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix.
|
||||||
result = ""
|
result = ""
|
||||||
for pos in range(0, len(serialised), 80 - prefix_length): #Lines have 80 characters, so the payload of each line is 80 - prefix.
|
for pos in range(0, len(serialised), 80 - prefix_length): #Lines have 80 characters, so the payload of each line is 80 - prefix.
|
||||||
result += prefix + serialised[pos : pos + 80 - prefix_length] + "\n"
|
result += prefix + serialised[pos : pos + 80 - prefix_length] + "\n"
|
||||||
serialised = result
|
serialised = result
|
||||||
|
|
||||||
return serialised
|
return serialised
|
Loading…
Add table
Add a link
Reference in a new issue