Skip to content

Commit 80a35a8

Browse files
CAM: Ensure pre-/postamble help text matches active values by avoiding duplication
Make sure to use the active default values for preamble and postamble in the help text, and provide the current default values as the default in the add_argument(). The only exception is uccnc_post.py, where the real default value depend on the use of --no-comments, and sending the default argument to add_argument() would change behaviour. This change was inspired by the changes done to fix (FreeCAD#20792) in d84d9c9.
1 parent 6c66564 commit 80a35a8

14 files changed

+221
-149
lines changed

src/Mod/CAM/Path/Post/scripts/KineticNCBeamicon2_post.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
KineticNCBeamicon2_post.export(object,"/path/to/file.ncc","")
5858
"""
5959

60+
# Preamble text will appear at the beginning of the GCODE output file.
61+
PREAMBLE = """%
62+
G17 G21 G40 G49 G80 G90
63+
"""
64+
65+
# Postamble text will appear following the last operation.
66+
POSTAMBLE = """M05
67+
M09
68+
G17 G90 G80 G40
69+
M30
70+
"""
71+
6072
now = datetime.datetime.now()
6173

6274
parser = argparse.ArgumentParser(
@@ -74,11 +86,15 @@
7486
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
7587
parser.add_argument(
7688
"--preamble",
77-
help=r'set commands to be issued before the first command, default="%%\nG17 G21 G40 G49 G80 G90\nM08\n"',
89+
help='set commands to be issued before the first command, default="'
90+
+ PREAMBLE.replace("\n", "\\n")
91+
+ '"',
7892
)
7993
parser.add_argument(
8094
"--postamble",
81-
help=r'set commands to be issued after the last command, default="M05 M09\nG17 G90 G80 G40\nM30\n"',
95+
help='set commands to be issued after the last command, default="'
96+
+ POSTAMBLE.replace("\n", "\\n")
97+
+ '"',
8298
)
8399
parser.add_argument(
84100
"--inches", action="store_true", help="Convert output for US imperial mode (G20)"
@@ -112,18 +128,6 @@
112128
CORNER_MAX = {"x": 1000, "y": 600, "z": 300}
113129
PRECISION = 3
114130

115-
# Preamble text will appear at the beginning of the GCODE output file.
116-
PREAMBLE = """%
117-
G17 G21 G40 G49 G80 G90
118-
"""
119-
120-
# Postamble text will appear following the last operation.
121-
POSTAMBLE = """M05
122-
M09
123-
G17 G90 G80 G40
124-
M30
125-
"""
126-
127131
# Pre operation text will be inserted before every operation
128132
PRE_OPERATION = """"""
129133

src/Mod/CAM/Path/Post/scripts/dynapath_4060_post.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@
5050
delta_4060_post.export(object,"/path/to/file.ncc","")
5151
"""
5252

53+
# Preamble text will appear at the beginning of the GCODE output file.
54+
PREAMBLE = """G17
55+
G90
56+
G80
57+
G40
58+
"""
59+
60+
# Postamble text will appear following the last operation.
61+
POSTAMBLE = """M05
62+
G80
63+
G40
64+
G17
65+
G90
66+
M30
67+
"""
68+
5369
parser = argparse.ArgumentParser(prog="delta_4060", add_help=False)
5470
parser.add_argument("--no-header", action="store_true", help="suppress header output")
5571
parser.add_argument("--no-comments", action="store_true", help="suppress comment output")
@@ -62,11 +78,17 @@
6278
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
6379
parser.add_argument(
6480
"--preamble",
65-
help='set commands to be issued before the first command, default="G17\\nG90\\nG80\\nG40\\n"',
81+
help='set commands to be issued before the first command, default="'
82+
+ PREAMBLE.replace("\n", "\\n")
83+
+ '"',
84+
default=PREAMBLE,
6685
)
6786
parser.add_argument(
6887
"--postamble",
69-
help='set commands to be issued after the last command, default="M09\\nM05\\nG80\\nG40\\nG17\\nG90\\nM30\\n"',
88+
help='set commands to be issued after the last command, default="'
89+
+ POSTAMBLE.replace("\n", "\\n")
90+
+ '"',
91+
default=POSTAMBLE,
7092
)
7193
parser.add_argument(
7294
"--inches", action="store_true", help="Convert output for US imperial mode (G70)"
@@ -129,21 +151,6 @@
129151
"G59": "E06",
130152
}
131153

132-
# Preamble text will appear at the beginning of the GCODE output file.
133-
PREAMBLE = """G17
134-
G90
135-
G80
136-
G40
137-
"""
138-
139-
# Postamble text will appear following the last operation.
140-
POSTAMBLE = """M05
141-
G80
142-
G40
143-
G17
144-
G90
145-
M30
146-
"""
147154
# Create following variable for use with the 2nd reference plane.
148155
clearanceHeight = None
149156

src/Mod/CAM/Path/Post/scripts/dynapath_post.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@
7676
dynapath_post.export(object,"/path/to/file.ncc","")
7777
"""
7878

79+
# Preamble text will appear at the beginning of the GCODE output file.
80+
PREAMBLE = """G17
81+
G90
82+
;G90.1 ;needed for simulation only
83+
G80
84+
G40
85+
"""
86+
87+
# Postamble text will appear following the last operation.
88+
POSTAMBLE = """M09
89+
M05
90+
G80
91+
G40
92+
G17
93+
G90
94+
M30
95+
"""
96+
7997
parser = argparse.ArgumentParser(prog="dynapath_post", add_help=False)
8098
parser.add_argument("--no-header", action="store_true", help="suppress header output")
8199
parser.add_argument("--no-comments", action="store_true", help="suppress comment output")
@@ -88,11 +106,17 @@
88106
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
89107
parser.add_argument(
90108
"--preamble",
91-
help='set commands to be issued before the first command, default="G17\\nG90\\nG80\\nG40\\n"',
109+
help='set commands to be issued before the first command, default="'
110+
+ PREAMBLE.replace("\n", "\\n")
111+
+ '"',
112+
default=PREAMBLE,
92113
)
93114
parser.add_argument(
94115
"--postamble",
95-
help='set commands to be issued after the last command, default="M09\\nM05\\nG80\\nG40\\nG17\\nG90\\nM30\\n"',
116+
help='set commands to be issued after the last command, default="'
117+
+ POSTAMBLE.replace("\n", "\\n")
118+
+ '"',
119+
default=POSTAMBLE,
96120
)
97121
parser.add_argument(
98122
"--inches", action="store_true", help="Convert output for US imperial mode (G20)"
@@ -121,24 +145,6 @@
121145
CORNER_MIN = {"x": -340, "y": 0, "z": 0}
122146
CORNER_MAX = {"x": 340, "y": -355, "z": -150}
123147

124-
# Preamble text will appear at the beginning of the GCODE output file.
125-
PREAMBLE = """G17
126-
G90
127-
;G90.1 ;needed for simulation only
128-
G80
129-
G40
130-
"""
131-
132-
# Postamble text will appear following the last operation.
133-
POSTAMBLE = """M09
134-
M05
135-
G80
136-
G40
137-
G17
138-
G90
139-
M30
140-
"""
141-
142148

143149
# Pre operation text will be inserted before every operation
144150
PRE_OPERATION = """"""

src/Mod/CAM/Path/Post/scripts/estlcam_post.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@
115115
)
116116
parser.add_argument(
117117
"--preamble",
118-
help='set commands to be issued before the first command, default=""',
118+
help='set commands to be issued before the first command, default="'
119+
+ PREAMBLE.replace("\n", "\\n")
120+
+ '"',
119121
)
120122
parser.add_argument(
121123
"--postamble",
122-
help='set commands to be issued after the last command, default="M5\\n"',
124+
help='set commands to be issued after the last command, default="'
125+
+ POSTAMBLE.replace("\n", "\\n")
126+
+ '"',
123127
)
124128
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
125129
parser.add_argument("--inches", action="store_true", help="convert output for US imperial mode")

src/Mod/CAM/Path/Post/scripts/fangling_post.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
FangLing_post.export(object,"/path/to/file.ncc","")
5858
"""
5959

60+
# Preamble text will appear at the beginning of the GCODE output file.
61+
# PREAMBLE = '''G17 G54 G40 G49 G80 G90'''
62+
# Changed to match preamble produced by Fusion 360
63+
PREAMBLE = """G90
64+
"""
65+
66+
# Postamble text will appear following the last operation.
67+
POSTAMBLE = """M8
68+
G90 G40
69+
M2
70+
"""
71+
6072
now = datetime.datetime.now()
6173

6274
parser = argparse.ArgumentParser(prog="FangLing", add_help=False)
@@ -68,11 +80,16 @@
6880
)
6981
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
7082
parser.add_argument(
71-
"--preamble", help='set commands to be issued before the first command, default="G90\\n"'
83+
"--preamble",
84+
help='set commands to be issued before the first command, default="'
85+
+ PREAMBLE.replace("\n", "\\n")
86+
+ '"',
7287
)
7388
parser.add_argument(
7489
"--postamble",
75-
help='set commands to be issued after the last command, default="M8\\nG90 G40\\nM2\\n"',
90+
help='set commands to be issued after the last command, default="'
91+
+ POSTAMBLE.replace("\n", "\\n")
92+
+ '"',
7693
)
7794
parser.add_argument(
7895
"--inches", action="store_true", help="Convert output for US imperial mode (G20)"
@@ -108,18 +125,6 @@
108125
CORNER_MAX = {"x": 500, "y": 300, "z": 300}
109126
PRECISION = 3
110127

111-
# Preamble text will appear at the beginning of the GCODE output file.
112-
# PREAMBLE = '''G17 G54 G40 G49 G80 G90'''
113-
# Changed to match preamble produced by Fusion 360
114-
PREAMBLE = """G90
115-
"""
116-
117-
# Postamble text will appear following the last operation.
118-
POSTAMBLE = """M8
119-
G90 G40
120-
M2
121-
"""
122-
123128
# Pre operation text will be inserted before every operation
124129
PRE_OPERATION = """"""
125130

src/Mod/CAM/Path/Post/scripts/fanuc_post.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
fanuc_post.export(object,"/path/to/file.ncc","")
5050
"""
5151

52+
# Preamble text will appear at the beginning of the GCODE output file.
53+
DEFAULT_PREAMBLE = """G17 G54 G40 G49 G80 G90
54+
"""
55+
56+
# Postamble text will appear following the last operation.
57+
DEFAULT_POSTAMBLE = """M05
58+
G17 G54 G90 G80 G40
59+
M30
60+
"""
61+
5262
now = datetime.datetime.now()
5363

5464
parser = argparse.ArgumentParser(prog="fanuc", add_help=False)
@@ -63,11 +73,15 @@
6373
parser.add_argument("--precision", help="number of digits of precision, default=3 (mm) or 4 (in)")
6474
parser.add_argument(
6575
"--preamble",
66-
help='set commands to be issued before the first command, default="G17 G54 G40 G49 G80 G90\\n"',
76+
help='set commands to be issued before the first command, default="'
77+
+ DEFAULT_PREAMBLE.replace("\n", "\\n")
78+
+ '"',
6779
)
6880
parser.add_argument(
6981
"--postamble",
70-
help='set commands to be issued after the last command, default="M05\\nG17 G54 G90 G80 G40\\nM30\\n"',
82+
help='set commands to be issued after the last command, default="'
83+
+ DEFAULT_POSTAMBLE.replace("\n", "\\n")
84+
+ '"',
7185
)
7286
parser.add_argument(
7387
"--inches", action="store_true", help="Convert output for US imperial mode (G20)"
@@ -122,15 +136,8 @@
122136
# rigid tapping.
123137
tapSpeed = 0
124138

125-
# Preamble text will appear at the beginning of the GCODE output file.
126-
DEFAULT_PREAMBLE = """G17 G54 G40 G49 G80 G90
127-
"""
128-
129-
# Postamble text will appear following the last operation.
130-
DEFAULT_POSTAMBLE = """M05
131-
G17 G54 G90 G80 G40
132-
M30
133-
"""
139+
PREAMBLE = DEFAULT_PREAMBLE
140+
POSTAMBLE = DEFAULT_POSTAMBLE
134141

135142
# Pre operation text will be inserted before every operation
136143
PRE_OPERATION = """"""
@@ -150,6 +157,8 @@ def processArguments(argstring):
150157
global OUTPUT_LINE_NUMBERS
151158
global SHOW_EDITOR
152159
global PRECISION
160+
global DEFAULT_PREAMBLE
161+
global DEFAULT_POSTAMBLE
153162
global PREAMBLE
154163
global POSTAMBLE
155164
global UNITS

src/Mod/CAM/Path/Post/scripts/grbl_legacy_post.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,15 @@
122122
)
123123
parser.add_argument(
124124
"--preamble",
125-
help='set commands to be issued before the first command, default="G17 G90\\n"',
125+
help='set commands to be issued before the first command, default="'
126+
+ PREAMBLE.replace("\n", "\\n")
127+
+ '"',
126128
)
127129
parser.add_argument(
128130
"--postamble",
129-
help='set commands to be issued after the last command, default="M5\\nG17 G90\\nM2\\n"',
131+
help='set commands to be issued after the last command, default="'
132+
+ POSTAMBLE.replace("\n", "\\n")
133+
+ '"',
130134
)
131135
parser.add_argument(
132136
"--inches", action="store_true", help="Convert output for US imperial mode (G20)"

src/Mod/CAM/Path/Post/scripts/jtech_post.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
jtech_post.export(object,"/path/to/file.ngc","")
4545
"""
4646

47+
# Preamble text will appear at the beginning of the GCODE output file.
48+
PREAMBLE = """M05 S0
49+
G90
50+
"""
51+
52+
# Postamble text will appear following the last operation.
53+
POSTAMBLE = """M05 S0
54+
M2
55+
"""
56+
4757
now = datetime.datetime.now()
4858

4959
parser = argparse.ArgumentParser(prog="jtech", add_help=False)
@@ -58,11 +68,15 @@
5868
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
5969
parser.add_argument(
6070
"--preamble",
61-
help='set commands to be issued before the first command, default="M05 S0\\nG90\\n"',
71+
help='set commands to be issued before the first command, default="'
72+
+ PREAMBLE.replace("\n", "\\n")
73+
+ '"',
6274
)
6375
parser.add_argument(
6476
"--postamble",
65-
help='set commands to be issued after the last command, default="M05 S0\\nM2\\n"',
77+
help='set commands to be issued after the last command, default="'
78+
+ POSTAMBLE.replace("\n", "\\n")
79+
+ '"',
6680
)
6781
parser.add_argument(
6882
"--inches", action="store_true", help="Convert output for US imperial mode (G20)"
@@ -100,16 +114,6 @@
100114
MACHINE_NAME = "JTECH Photonic Laser"
101115
PRECISION = 3
102116

103-
# Preamble text will appear at the beginning of the GCODE output file.
104-
PREAMBLE = """M05 S0
105-
G90
106-
"""
107-
108-
# Postamble text will appear following the last operation.
109-
POSTAMBLE = """M05 S0
110-
M2
111-
"""
112-
113117
PRE_FEED = """M03
114118
G4 P{}
115119
"""

0 commit comments

Comments
 (0)