Skip to content

Commit

Permalink
Cleanup. Make surface, drilling, and engrave work with preselect
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptonic authored and yorikvanhavre committed May 23, 2016
1 parent d3ba507 commit 7436a5e
Show file tree
Hide file tree
Showing 5 changed files with 580 additions and 465 deletions.
90 changes: 63 additions & 27 deletions src/Mod/Path/PathScripts/PathDrilling.py
Expand Up @@ -24,6 +24,7 @@

import FreeCAD
import Path
import Part
from PySide import QtCore, QtGui
from PathScripts import PathUtils

Expand Down Expand Up @@ -99,14 +100,22 @@ def execute(self, obj):
else:
s = loc[0].Shape

if s.ShapeType in ['Face', 'Wire', 'Edge']:
X = s.Edges[0].Curve.Center.x
Y = s.Edges[0].Curve.Center.y
Z = s.Edges[0].Curve.Center.z
elif s.ShapeType == 'Vertex':
X = s.Point.x
Y = s.Point.y
Z = s.Point.z
if s.ShapeType in ['Wire', 'Edge']:
X = s.Edges[0].Curve.Center.x
Y = s.Edges[0].Curve.Center.y
Z = s.Edges[0].Curve.Center.z
elif s.ShapeType in ['Vertex']:
X = s.Point.x
Y = s.Point.y
Z = s.Point.z
elif s.ShapeType in ['Face']:
#if abs(s.normalAt(0, 0).z) == 1: # horizontal face
X = s.CenterOfMass.x
Y = s.CenterOfMass.y
Z = s.CenterOfMass.z




locations.append(FreeCAD.Vector(X, Y, Z))

Expand Down Expand Up @@ -137,6 +146,24 @@ def execute(self, obj):
path = Path.Path(output)
obj.Path = path

def checkdrillable(self, obj, sub):
print "in checkdrillable"
drillable = False
if obj.ShapeType == 'Vertex':
drillable = True
elif obj.ShapeType == 'Solid':
if sub[0:4] == 'Face':
subobj = obj.getElement(sub)
drillable = isinstance(subobj.Edges[0].Curve, Part.Circle)
if str(subobj.Surface) == "<Cylinder object>":
drillable = True

if sub[0:4] == 'Edge':
o = obj.getElement(sub)
drillable = isinstance(o.Curve, Part.Circle)

return drillable

def addDrillableLocation(self, obj, ss, sub=""):
baselist = obj.Base
item = (ss, sub)
Expand All @@ -159,13 +186,14 @@ def addDrillableLocation(self, obj, ss, sub=""):
obj.ClearanceHeight = 10.0
obj.SafeHeight = 8.0
obj.RetractHeight = 6.0
if self.checkdrillable(ss.Shape,sub):

if item in baselist:
FreeCAD.Console.PrintWarning("Drillable location already in the list" + "\n")
else:
baselist.append(item)
obj.Base = baselist
self.execute(obj)
if item in baselist:
FreeCAD.Console.PrintWarning("Drillable location already in the list" + "\n")
else:
baselist.append(item)
obj.Base = baselist
self.execute(obj)


class _ViewProviderDrill:
Expand Down Expand Up @@ -269,6 +297,19 @@ def getFields(self):

self.obj.Proxy.execute(self.obj)

def setFields(self):
self.form.startDepth.setText(str(self.obj.StartDepth.Value))
self.form.finalDepth.setText(str(self.obj.FinalDepth.Value))
self.form.peckDepth.setText(str(self.obj.PeckDepth.Value))
self.form.safeHeight.setText(str(self.obj.SafeHeight.Value))
self.form.clearanceHeight.setText(str(self.obj.ClearanceHeight.Value))
self.form.retractHeight.setText(str(self.obj.RetractHeight.Value))

self.form.baseList.clear()
for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])


def open(self):
self.s = SelObserver()
FreeCADGui.Selection.addObserver(self.s)
Expand All @@ -287,10 +328,9 @@ def addBase(self):
else:
self.obj.Proxy.addDrillableLocation(self.obj, s.Object)

self.setupUi() # defaults may have changed. Reload.
self.form.baseList.clear()
for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])
self.setFields() # defaults may have changed. Reload.
# for i in self.obj.Base:
# self.form.baseList.addItem(i[0].Name + "." + i[1])

def deleteBase(self):
dlist = self.form.baseList.selectedItems()
Expand Down Expand Up @@ -336,15 +376,6 @@ def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Ok)

def setupUi(self):
self.form.startDepth.setText(str(self.obj.StartDepth.Value))
self.form.finalDepth.setText(str(self.obj.FinalDepth.Value))
self.form.peckDepth.setText(str(self.obj.PeckDepth.Value))
self.form.safeHeight.setText(str(self.obj.SafeHeight.Value))
self.form.clearanceHeight.setText(str(self.obj.ClearanceHeight.Value))
self.form.retractHeight.setText(str(self.obj.RetractHeight.Value))

for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])

# Connect Signals and Slots
self.form.startDepth.editingFinished.connect(self.getFields)
Expand All @@ -358,6 +389,11 @@ def setupUi(self):

self.form.baseList.itemSelectionChanged.connect(self.itemActivated)

sel = FreeCADGui.Selection.getSelectionEx()
if len(sel) != 0 and sel[0].HasSubObjects:
self.addBase()

self.setFields()

class SelObserver:
def __init__(self):
Expand Down
37 changes: 19 additions & 18 deletions src/Mod/Path/PathScripts/PathEngrave.py
Expand Up @@ -45,7 +45,7 @@ def translate(context, text, disambig=None):

class ObjectPathEngrave:

def __init__(self,obj):
def __init__(self, obj):
obj.addProperty("App::PropertyLinkSubList", "Base", "Path", "The base geometry of this object")
obj.addProperty("App::PropertyBool", "Active", "Path", translate("Path", "Make False, to prevent operation from generating code"))
obj.addProperty("App::PropertyString", "Comment", "Path", translate("Path", "An optional comment for this profile"))
Expand Down Expand Up @@ -166,16 +166,10 @@ def addShapeString(self, obj, ss):
if len(baselist) == 0: # When adding the first base object, guess at heights
try:
bb = ss.Shape.BoundBox # parent boundbox
subobj = ss.Shape.getElement(sub)
fbb = subobj.BoundBox # feature boundbox
obj.StartDepth = bb.ZMax
obj.ClearanceHeight = bb.ZMax + 5.0
obj.SafeHeight = bb.ZMax + 3.0

if fbb.ZMax < bb.ZMax:
obj.FinalDepth = fbb.ZMax
else:
obj.FinalDepth = bb.ZMin
obj.FinalDepth = bb.ZMin
except:
obj.StartDepth = 5.0
obj.ClearanceHeight = 10.0
Expand Down Expand Up @@ -278,6 +272,16 @@ def getFields(self):

self.obj.Proxy.execute(self.obj)

def setFields(self):
self.form.startDepth.setText(str(self.obj.StartDepth.Value))
self.form.finalDepth.setText(str(self.obj.FinalDepth.Value))
self.form.safeHeight.setText(str(self.obj.SafeHeight.Value))
self.form.clearanceHeight.setText(str(self.obj.ClearanceHeight.Value))

self.form.baseList.clear()
for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name)

def open(self):
self.s = SelObserver()
# install the function mode resident
Expand All @@ -296,9 +300,7 @@ def addBase(self):
return
self.obj.Proxy.addShapeString(self.obj, s.Object)

self.form.baseList.clear()
for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name)
self.setFields()

def deleteBase(self):
dlist = self.form.baseList.selectedItems()
Expand Down Expand Up @@ -332,13 +334,6 @@ def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Ok)

def setupUi(self):
self.form.startDepth.setText(str(self.obj.StartDepth.Value))
self.form.finalDepth.setText(str(self.obj.FinalDepth.Value))
self.form.safeHeight.setText(str(self.obj.SafeHeight.Value))
self.form.clearanceHeight.setText(str(self.obj.ClearanceHeight.Value))

for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name)

# Connect Signals and Slots
self.form.startDepth.editingFinished.connect(self.getFields)
Expand All @@ -352,6 +347,12 @@ def setupUi(self):

self.form.baseList.itemSelectionChanged.connect(self.itemActivated)

sel = FreeCADGui.Selection.getSelectionEx()
if len(sel) != 0:
self.addBase()

self.setFields()


class SelObserver:
def __init__(self):
Expand Down
28 changes: 6 additions & 22 deletions src/Mod/Path/PathScripts/PathSelection.py
Expand Up @@ -21,7 +21,7 @@
# * USA *
# * *
# ***************************************************************************
'''Path selection function select a face or faces, two edges, etc to get a dictionary with what was selected in order '''
'''Selection gates and observers to control selectability while building Path operations '''

import FreeCAD
import FreeCADGui
Expand Down Expand Up @@ -72,7 +72,6 @@ def allow(self, doc, obj, sub):

class MESHGate:
def allow(self, doc, obj, sub):
print obj.TypeId[0:4] == 'Mesh'
return (obj.TypeId[0:4] == 'Mesh')


Expand All @@ -91,19 +90,13 @@ def allow(self, doc, obj, sub):
return False
if obj.ShapeType == 'Vertex':
drillable = True
elif obj.ShapeType == 'Edge':
if isinstance(obj.Curve, Part.Circle):
drillable = True
elif obj.ShapeType == 'Face':
if isinstance(obj.Edges[0].Curve, Part.Circle):
drillable = True
elif obj.ShapeType == 'Wire':
if isinstance(obj.Edges[0].Curve, Part.Circle):
drillable = True
elif obj.ShapeType == 'Solid':
if sub[0:4] == 'Face':
o = obj.getElement(sub)
drillable = isinstance(o.Edges[0].Curve, Part.Circle)
subobj = obj.getElement(sub)
drillable = isinstance(subobj.Edges[0].Curve, Part.Circle)
if str(subobj.Surface) == "<Cylinder object>":
drillable = True

if sub[0:4] == 'Edge':
o = obj.getElement(sub)
drillable = isinstance(o.Curve, Part.Circle)
Expand Down Expand Up @@ -169,15 +162,6 @@ def allow(self, doc, obj, sub):
if sub[0:4] == 'Face':
pocketable = True

# if sub[0:4] == 'Edge':
# pocketable = True

# elif obj.ShapeType == 'Wire':
# pocketable = True

# if sub[0:6] == 'Vertex':
# print "might be fun to try to derive the loop by hovering near a vertex"

return pocketable


Expand Down

0 comments on commit 7436a5e

Please sign in to comment.