Skip to content

Commit

Permalink
Engrave now can handle imported SVG elements.
Browse files Browse the repository at this point in the history
Selection gate changed to allow selection of Shape objects with
boundbox.z = 0 and having wires.

Splines and curves are processed through pathutils.cleanedges but the precision is
hard coded.  Might want to change this to a property.
  • Loading branch information
sliptonic authored and yorikvanhavre committed Jul 12, 2016
1 parent 8f84b19 commit c5d35a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/Mod/Path/PathScripts/PathEngrave.py
Expand Up @@ -26,6 +26,7 @@
import FreeCADGui
import Path
import Draft
import Part

from PySide import QtCore, QtGui
from PathScripts import PathUtils
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -183,23 +187,24 @@ 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:
bb = ss.Shape.BoundBox # parent boundbox
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)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
14 changes: 12 additions & 2 deletions src/Mod/Path/PathScripts/PathSelection.py
Expand Up @@ -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):
Expand Down

0 comments on commit c5d35a0

Please sign in to comment.