Skip to content

Commit

Permalink
change preprocessor to split lines
Browse files Browse the repository at this point in the history
  • Loading branch information
etrombly committed Mar 22, 2020
1 parent 31b1705 commit f1ebaa4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/Mod/Path/CMakeLists.txt
Expand Up @@ -128,6 +128,7 @@ SET(PathScripts_post_SRCS
PathScripts/post/comparams_post.py
PathScripts/post/dynapath_post.py
PathScripts/post/example_pre.py
PathScripts/post/gcode_pre.py
PathScripts/post/grbl_post.py
PathScripts/post/jtech_post.py
PathScripts/post/linuxcnc_post.py
Expand Down
34 changes: 15 additions & 19 deletions src/Mod/Path/PathScripts/PathCustom.py
Expand Up @@ -52,27 +52,23 @@ def __setstate__(self, state):
return None

def execute(self, obj):
commands = []
newPath = Path.Path
if obj.Gcode:
s = ""
for l in obj.Gcode:
s += str(l)
if s:
path = Path.Path(s)
if obj.OperationPlacement:
for x in range(len(path.Commands)):
if path.Commands[x].Name in movecommands:
base = copy(obj.Placement.Base)
new = path.Commands[x]
if 'X' not in path.Commands[x].Parameters:
base[0] = 0.0
if 'Y' not in path.Commands[x].Parameters:
base[1] = 0.0
if 'Z' not in path.Commands[x].Parameters:
base[2] = 0.0
new.Placement.translate(base)
path.deleteCommand(x)
path.insertCommand(new, x)
obj.Path = path
newcommand=Path.Command(str(l))
if newcommand.Name in movecommands and obj.OperationPlacement:
if 'X' in newcommand.Parameters:
newcommand.x += obj.Placement.Base.x
if 'Y' in newcommand.Parameters:
newcommand.y += obj.Placement.Base.y
if 'Z' in newcommand.Parameters:
newcommand.z += obj.Placement.Base.z

commands.append(newcommand)
newPath.addCommands(commands)

obj.Path = newPath


class CommandPathCustom:
Expand Down
13 changes: 6 additions & 7 deletions src/Mod/Path/PathScripts/post/gcode_pre.py
Expand Up @@ -78,13 +78,11 @@ def insert(filename, docname):
def parse(inputstring):
"parse(inputstring): returns a parsed output string"
print("preprocessing...")
print(inputstring)
PathLog.track(inputstring)
# split the input by line
lines = inputstring.split("\n")
output = ""
output = [] #""
lastcommand = None
print(lines)

for lin in lines:
# remove any leftover trailing and preceding spaces
Expand All @@ -96,7 +94,7 @@ def parse(inputstring):
# remove line numbers
lin = lin.split(" ", 1)
if len(lin) >= 1:
lin = lin[1]
lin = lin[1].strip()
else:
continue

Expand All @@ -105,7 +103,8 @@ def parse(inputstring):
continue
if lin[0].upper() in ["G", "M"]:
# found a G or M command: we store it
output += lin + "\n"
#output += lin + "\n"
output.append(lin) # + "\n"
last = lin[0].upper()
for c in lin[1:]:
if not c.isdigit():
Expand All @@ -115,10 +114,10 @@ def parse(inputstring):
lastcommand = last
elif lastcommand:
# no G or M command: we repeat the last one
output += lastcommand + " " + lin + "\n"
output.append(lastcommand + " " + lin) # + "\n"

print("done preprocessing.")
return output


print(__name__ + " gcode preprocessor loaded.")
print(__name__ + " gcode preprocessor loaded.")

0 comments on commit f1ebaa4

Please sign in to comment.