Skip to content

Commit 002ebbf

Browse files
committed
Fix bug where blank lines led to incomplete toolchanges
1 parent 52cc9cd commit 002ebbf

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

src/gui.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# UI Constants
2222
APP_NAME_ABBREVIATION = 'MFM'
2323
APP_NAME = f'3D G-code Map Feature Modifier ({APP_NAME_ABBREVIATION})'
24-
APP_VERSION = '1.6.0'
24+
APP_VERSION = '1.6.1'
2525
POST_PROCESS_BUTTON = 'Post Process'
2626
POST_PROCESS_BUTTON_PROCESSING = 'Processing'
2727

@@ -168,7 +168,7 @@ def create_widgets(self):
168168
gcodeFlavorLabel.grid(row=0, column=0, sticky=tk.W, padx=10)
169169
gcodeFlavorComboBox = ttk.Combobox(
170170
state="readonly",
171-
values=['Marlin 2 (PrusaSlicer/Bambu Studio)']
171+
values=['Marlin 2 (PrusaSlicer/Bambu Studio/Orca Slicer)']
172172
)
173173
gcodeFlavorComboBox.current(0)
174174
gcodeFlavorComboBox.grid(row=0, column=1, sticky=tk.EW, padx=10, pady=10)
@@ -326,11 +326,13 @@ def postProcessTask():
326326
if TEST_MODE:
327327
#userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_bambu_prime.gcode'
328328
#userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_bambu_no_prime.gcode'
329-
userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_prusa_prime.gcode'
329+
userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_orca_prime.gcode'
330+
#userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_orca_no_prime.gcode'
331+
#userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_prusa_prime.gcode'
330332
#userOptions[CONFIG_INPUT_FILE] = 'sample_models/dual_color_dice/tests/dice_multiple_prusa_no_prime.gcode'
331333
userOptions[IMPORT_OPTIONS_FILENAME] = 'sample_models/dual_color_dice/config-dice-test.json'
332-
#userOptions[CONFIG_TOOLCHANGE_MINIMAL_FILE] = 'minimal_toolchanges/bambu-x1-series.gcode'
333-
userOptions[CONFIG_TOOLCHANGE_MINIMAL_FILE] = 'minimal_toolchanges/prusa-xl-series.gcode'
334+
userOptions[CONFIG_TOOLCHANGE_MINIMAL_FILE] = 'minimal_toolchanges/bambu-x1-series.gcode'
335+
#userOptions[CONFIG_TOOLCHANGE_MINIMAL_FILE] = 'minimal_toolchanges/prusa-xl-series.gcode'
334336
userOptions[CONFIG_OUTPUT_FILE] = 'dice-export.gcode'
335337

336338
#userOptions[CONFIG_INPUT_FILE] = 'sample_models/CA/ca_p3.gcode'

src/mfm/map_post_process.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def addFeatureToList(ps: PrintState, cf: Feature):
128128
# wipe_end marker for normal printing features to skip
129129
wipeEndMatch = re.match(WIPE_END, cl)
130130

131+
#Debug
132+
if f.tell() == 155194:
133+
0==0
134+
131135
# end if we find next layer marker
132136
if changeLayerMatch:
133137
printState.layerEnd = f.tell() - len(cl) - (len(le)-1)
@@ -138,10 +142,6 @@ def addFeatureToList(ps: PrintState, cf: Feature):
138142
printState.layerEndOriginalColor = curOriginalColor
139143
break
140144

141-
#Debug
142-
if f.tell() == 125095:
143-
0==0
144-
145145
checkAndUpdatePosition(cl=cl, pp=curStartPosition)
146146

147147
# If UNIVERSAL LAYER CHANGE END found first, look ahead to see if a new feature is the first thing on this layer or previous feature is continued.
@@ -191,7 +191,7 @@ def addFeatureToList(ps: PrintState, cf: Feature):
191191

192192
# Look for FEATURE to find feature type
193193
if featureTypeMatch or (len(printState.features) == 0 and useFirstSpecialGcodeAsFeature and specialGcodeMatch):
194-
#print(f"found FEATURE match at {f.tell() - len(cl) - (len(le)-1)}")
194+
print(f"found FEATURE match {featureTypeMatch.groups()[0] if featureTypeMatch else 'None'} at {f.tell() - len(cl) - (len(le)-1)}")
195195

196196
# Don't end prime tower if we found prime tower feature for Bambu
197197
if curFeature and curFeature.featureType == PRIME_TOWER and featureTypeMatch and (featureTypeMatch.groups()[0] == PRIME_TOWER or featureTypeMatch.groups()[0] == WIPE_TOWER):
@@ -236,7 +236,7 @@ def addFeatureToList(ps: PrintState, cf: Feature):
236236
# A toolchange is found UNIVERSAL_TOOLCHANGE_START
237237
elif univeralToolchangeStartMatch:
238238
curFeature.toolchange = Feature()
239-
curFeature.toolchange.featureType = TOOLCHANGE
239+
curFeature.toolchange.featureType = TOOLCHANGE
240240
curFeature.toolchange.start = f.tell() - len(cl) - (len(le)-1)
241241
#print(f"found toolchange start at {curFeature.toolchange.start}")
242242
continue
@@ -253,6 +253,7 @@ def addFeatureToList(ps: PrintState, cf: Feature):
253253
elif univeralToolchangeEndMatch:
254254
if curFeature.toolchange == None:
255255
print(f"toolchange end found before toolchange start at {f.tell()} set .end to {f.tell() - len(cl) - (len(le)-1)}")
256+
1==0 # assert crash
256257
break
257258
curFeature.toolchange.end = f.tell() - len(cl) - (len(le)-1)
258259
#print(f"found toolchange end at {curFeature.toolchange.end}")
@@ -346,10 +347,14 @@ def checkAndInsertToolchange(ps: PrintState, f: typing.TextIO, out: typing.TextI
346347
nextAvailablePrimeTowerFeature = ps.primeTowerFeatures.pop(0)
347348
cp = f.tell()
348349
f.seek(nextAvailablePrimeTowerFeature.start, os.SEEK_SET)
349-
while f.tell() <= nextAvailablePrimeTowerFeature.end:
350+
# We check if the position is != instead of <= because readline() with the next line being empty meaning it looks like double line endings leads to high tell() values that do not make sense but still seek to the correct position anyways.
351+
while f.tell() != nextAvailablePrimeTowerFeature.end:
350352
cl = f.readline()
351353

352-
# Skip WIPE_END of the inserted prime tower
354+
if f.tell() == 155194:
355+
0==0
356+
357+
# Skip WIPE_END of the nserted prime tower
353358
if nextAvailablePrimeTowerFeature.wipeEnd and f.tell() == nextAvailablePrimeTowerFeature.wipeEnd.start:
354359
writeWithFilters(out, cl, loadedColors)
355360
out.write(";WIPE_END placeholder for PrusaSlicer Gcode Viewer\n")

src/mfm/printing_classes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,29 @@ class SkipType(enum.Enum):
3434

3535
# State of current Print FILE
3636
class PrintState:
37+
"""The current state of the processed G-code file."""
38+
3739
def __init__(self):
3840
self.height: float = -1
41+
"""The current printing height relative to the buildplate."""
42+
3943
self.layerHeight: float = 0
44+
"""The layer height of an individual layer relative to the top of the last layer. E.g. 0.12, 0.2"""
45+
4046
self.previousLayerHeight: float = 0
47+
"""The previous layer's layer height."""
48+
4149
self.layerStart: int = 0
50+
"""The character position of the layer start."""
51+
4252
self.layerEnd: int = 0
53+
"""The character position of the layer end."""
54+
4355
self.lastFeature: Feature = None
56+
"""Reference to last original feature of the previous layer. Used in case it originally continues to next layer."""
57+
4458
self.prevLayerLastFeature: Feature = None
59+
"""Reference to last original feature of the layer before the previous layer."""
4560

4661
# Color info
4762
self.originalColor: int = -1 # last color changed to in original print at the start of the layer

0 commit comments

Comments
 (0)