diff --git a/src/Mod/Path/PathScripts/PathEngrave.py b/src/Mod/Path/PathScripts/PathEngrave.py index 92be77a6d72b..02af78bd8b24 100644 --- a/src/Mod/Path/PathScripts/PathEngrave.py +++ b/src/Mod/Path/PathScripts/PathEngrave.py @@ -26,6 +26,7 @@ import FreeCADGui import Path import Draft +import Part from PySide import QtCore, QtGui from PathScripts import PathUtils @@ -109,10 +110,13 @@ def execute(self, obj): obj.Label = obj.UserLabel + " :" + obj.ToolDescription if obj.Base: + wires = [] for o in obj.Base: output += "G0 " + str(obj.ClearanceHeight.Value)+"\n" # we only consider the outer wire if this is a Face - wires = o[0].Shape.Wires + for w in o[0].Shape.Wires: + tempedges = PathUtils.cleanedges(w.Edges, 0.5) + wires.append (Part.Wire(tempedges)) if obj.Algorithm == "OCC Native": output += self.buildpathocc(obj, wires) @@ -154,7 +158,7 @@ def buildpathocc(self, obj, wires): # we set the first move to our first point last = edge.Vertexes[0].Point output += "G0" + " X" + str("%f" % last.x) + " Y" + str("%f" % last.y) # Rapid sto starting position - output += "G1" + " Z" + str("%f" % last.z) + "F " + str(self.vertFeed) + "\n" # Vertical feed to depth + output += "G1" + " X" + str("%f" % last.x) + " Y" + str("%f" % last.y) + " Z" + str("%f" % last.z) + "F " + str(self.vertFeed) + "\n" # Vertical feed to depth if isinstance(edge.Curve, Part.Circle): point = edge.Vertexes[-1].Point if point == last: # edges can come flipped @@ -183,7 +187,7 @@ def buildpathocc(self, obj, wires): output += "G0 Z " + str(obj.SafeHeight.Value) return output - def addShapeString(self, obj, ss): + def addEngraveBase(self, obj, ss): baselist = obj.Base if len(baselist) == 0: # When adding the first base object, guess at heights try: @@ -191,15 +195,16 @@ def addShapeString(self, obj, ss): obj.StartDepth = bb.ZMax obj.ClearanceHeight = bb.ZMax + 5.0 obj.SafeHeight = bb.ZMax + 3.0 - obj.FinalDepth = bb.ZMin + obj.FinalDepth = bb.ZMax - 1 except: obj.StartDepth = 5.0 + obj.FinalDepth = 4.0 obj.ClearanceHeight = 10.0 obj.SafeHeight = 8.0 item = (ss, "") if item in baselist: - FreeCAD.Console.PrintWarning("ShapeString already in the Engraving list" + "\n") + FreeCAD.Console.PrintWarning("Object already in the Engraving list" + "\n") else: baselist.append(item) @@ -225,7 +230,7 @@ def setEdit(self, vobj, mode=0): return True def getIcon(self): - return ":/icons/Path-Profile.svg" + return ":/icons/Path-Engrave.svg" def __getstate__(self): return None @@ -257,6 +262,7 @@ def Activated(self): FreeCADGui.doCommand('obj.StartDepth= 0') FreeCADGui.doCommand('obj.FinalDepth= -0.1') FreeCADGui.doCommand('obj.SafeHeight= 5.0') + FreeCADGui.doCommand('obj.Active = True') FreeCADGui.doCommand('PathScripts.PathUtils.addToProject(obj)') FreeCAD.ActiveDocument.commitTransaction() @@ -314,13 +320,13 @@ def addBase(self): selection = FreeCADGui.Selection.getSelectionEx() if not len(selection) >= 1: - FreeCAD.Console.PrintError(translate("Path_Engrave", "Please select at least one ShapeString\n")) + FreeCAD.Console.PrintError(translate("Path_Engrave", "Please select engraveable geometry\n")) return for s in selection: - if not Draft.getType(s.Object) == "ShapeString": - FreeCAD.Console.PrintError(translate("Path_Engrave", "Please select at least one ShapeString\n")) + if not Draft.getType(s.Object) in ["ShapeString", "Part"]: + FreeCAD.Console.PrintError(translate("Path_Engrave", "Please select valid geometry\n")) return - self.obj.Proxy.addShapeString(self.obj, s.Object) + self.obj.Proxy.addEngraveBase(self.obj, s.Object) self.setFields() diff --git a/src/Mod/Path/PathScripts/PathSelection.py b/src/Mod/Path/PathScripts/PathSelection.py index c78d4f596f4f..bb1f69ba7fc6 100644 --- a/src/Mod/Path/PathScripts/PathSelection.py +++ b/src/Mod/Path/PathScripts/PathSelection.py @@ -77,8 +77,18 @@ def allow(self, doc, obj, sub): class ENGRAVEGate: def allow(self, doc, obj, sub): - return (obj.Name[0:11] == 'ShapeString') - + engraveable = False + + if hasattr(obj, "Shape"): + if obj.Shape.BoundBox.ZLength == 0.0: + try: + obj = obj.Shape + except: + return False + if len(obj.Wires) > 0: + engraveable = True + + return engraveable class DRILLGate: def allow(self, doc, obj, sub):