Merge pull request #5352 from sliptonic/bug/simulator

[Path]  bug fixes for dxf_post and simulator
This commit is contained in:
sliptonic
2022-01-10 09:28:05 -06:00
committed by GitHub
2 changed files with 29 additions and 28 deletions

View File

@@ -31,7 +31,6 @@ import PathScripts.PathJob as PathJob
import PathSimulator
import math
import os
from PySide.QtCore import QT_TRANSLATE_NOOP
from FreeCAD import Vector, Base
@@ -311,9 +310,7 @@ class PathSimulation:
self.stock = newStock.removeSplitter()
except Exception:
if self.debug:
FreeCAD.Console.PrintError(
"invalid cut at cmd #{}".format(self.icmd)
)
print("invalid cut at cmd #{}".format(self.icmd))
if not self.disableAnim:
self.cutTool.Placement = FreeCAD.Placement(self.curpos, self.stdrot)
self.icmd += 1
@@ -622,9 +619,9 @@ class CommandPathSimulate:
def GetResources(self):
return {
"Pixmap": "Path_Simulator",
"MenuText": QT_TRANSLATE_NOOP("Path_Simulator", "CAM Simulator"),
"MenuText": QtCore.QT_TRANSLATE_NOOP("Path_Simulator", "CAM Simulator"),
"Accel": "P, M",
"ToolTip": QT_TRANSLATE_NOOP(
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"Path_Simulator", "Simulate Path G-Code on stock"
),
}
@@ -637,11 +634,10 @@ class CommandPathSimulate:
return False
def Activated(self):
pathSimulation = PathSimulation()
pathSimulation.Activate()
pathSimulation = PathSimulation()
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand("Path_Simulator", CommandPathSimulate())

View File

@@ -29,7 +29,7 @@ import importDXF
import Path
import PathScripts.PathLog as PathLog
TOOLTIP = '''
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
take a pseudo-gcode fragment outputted by a Path object, and output
a dxf file.
@@ -41,23 +41,26 @@ Does NOT remove redundant lines. If you have multiple step-downs in your
operation, you'll get multiple redundant lines in your dxf.
import dxf_post
'''
"""
TOOLTIP_ARGS = '''
TOOLTIP_ARGS = """
Arguments for dxf:
'''
"""
now = datetime.datetime.now()
# # These globals set common customization preferences
OUTPUT_HEADER = True
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
# to distinguish python built-in open function from the one declared below
if open.__module__ in ['__builtin__', 'io']:
if open.__module__ in ["__builtin__", "io"]:
pythonopen = open
@@ -89,10 +92,10 @@ def dxfWrite(objlist, filename):
def parse(pathobj):
''' accepts a Path object. Returns a list of wires'''
"""accepts a Path object. Returns a list of wires"""
feedcommands = ['G01', 'G1', 'G2', 'G3', 'G02', 'G03']
rapidcommands = ['G0', 'G00']
feedcommands = PathGeom.CmdMove
rapidcommands = PathGeom.CmdMoveRapid
edges = []
objlist = []
@@ -100,10 +103,10 @@ def parse(pathobj):
# Gotta start somewhere. Assume 0,0,0
curPoint = FreeCAD.Vector(0, 0, 0)
for c in pathobj.Path.Commands:
PathLog.debug('{} -> {}'.format(curPoint, c))
if 'Z' in c.Parameters:
PathLog.debug("{} -> {}".format(curPoint, c))
if "Z" in c.Parameters:
newparams = c.Parameters
newparams.pop('Z', None)
newparams.pop("Z", None)
flatcommand = Path.Command(c.Name, newparams)
c.Parameters = newparams
else:
@@ -111,23 +114,25 @@ def parse(pathobj):
# ignore gcode that isn't moving
if flatcommand.Name not in feedcommands + rapidcommands:
PathLog.debug('non move')
PathLog.debug("non move")
continue
# ignore pure vertical feed and rapid
if (flatcommand.Parameters.get('X', curPoint.x) == curPoint.x
and flatcommand.Parameters.get('Y', curPoint.y) == curPoint.y):
PathLog.debug('vertical')
if (
flatcommand.Parameters.get("X", curPoint.x) == curPoint.x
and flatcommand.Parameters.get("Y", curPoint.y) == curPoint.y
):
PathLog.debug("vertical")
continue
# feeding move. Build an edge
if flatcommand.Name in feedcommands:
edges.append(PathGeom.edgeForCmd(flatcommand, curPoint))
PathLog.debug('feeding move')
PathLog.debug("feeding move")
# update the curpoint
curPoint.x = flatcommand.Parameters['X']
curPoint.y = flatcommand.Parameters['Y']
curPoint.x = flatcommand.Parameters.get("X", curPoint.x)
curPoint.y = flatcommand.Parameters.get("Y", curPoint.y)
if len(edges) > 0:
candidates = Part.sortEdges(edges)