Engrave now can handle imported SVG elements.

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.
This commit is contained in:
sliptonic 2016-07-07 14:46:21 -05:00 committed by Yorik van Havre
parent 8f84b19ed9
commit c5d35a00c4
2 changed files with 27 additions and 11 deletions

View File

@ -26,6 +26,7 @@ import FreeCAD
import FreeCADGui
import Path
import Draft
import Part
from PySide import QtCore, QtGui
from PathScripts import PathUtils
@ -109,10 +110,13 @@ class ObjectPathEngrave:
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 @@ class ObjectPathEngrave:
# 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 @@ class ObjectPathEngrave:
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 @@ class ObjectPathEngrave:
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 @@ class _ViewProviderEngrave:
return True
def getIcon(self):
return ":/icons/Path-Profile.svg"
return ":/icons/Path-Engrave.svg"
def __getstate__(self):
return None
@ -257,6 +262,7 @@ class CommandPathEngrave:
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 @@ class TaskPanel:
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()

View File

@ -77,8 +77,18 @@ class MESHGate:
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):