Consolidated all depth calculations.
This commit is contained in:
@@ -169,11 +169,8 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
if PathUtils.isDrillable(self.baseobject, edge, tooldiameter):
|
||||
PathLog.debug('Found drillable hole edges: {}'.format(edge))
|
||||
features.append((self.baseobject, "%d.%d.%d" % (holeNr, wireNr, edgeNr)))
|
||||
|
||||
self.setDepths(obj, None, None, self.baseobject.Shape.BoundBox)
|
||||
else:
|
||||
features = self.findHoles(obj, self.baseobject)
|
||||
self.setupDepthsFrom(obj, features, self.baseobject)
|
||||
obj.Base = features
|
||||
obj.Disabled = []
|
||||
|
||||
@@ -199,60 +196,6 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
Must be overwritten by subclasses.'''
|
||||
pass
|
||||
|
||||
def opOnChanged(self, obj, prop):
|
||||
'''opOnChange(obj, prop) ... implements depth calculation if Base changes.
|
||||
Do not overwrite.'''
|
||||
if 'Base' == prop and not 'Restore' in obj.State and obj.Base:
|
||||
features = []
|
||||
for base, subs in obj.Base:
|
||||
for sub in subs:
|
||||
features.append((base, sub))
|
||||
|
||||
job = PathUtils.findParentJob(obj)
|
||||
if not job or not job.Base:
|
||||
return
|
||||
|
||||
self.setupDepthsFrom(obj, features, job.Base)
|
||||
|
||||
def setupDepthsFrom(self, obj, features, baseobject):
|
||||
'''setupDepthsFrom(obj, features, baseobject) ... determins the min and max Z values necessary.
|
||||
Note that the algorithm calculates "safe" values,
|
||||
it determines the highest top Z value of all features
|
||||
and it also determines the highest bottom Z value of all features.
|
||||
The result is that all features can be drilled safely and the operation
|
||||
does not drill deeper than any of the features requires.'''
|
||||
zmax = None
|
||||
zmin = None
|
||||
if not self.baseIsArchPanel(obj, baseobject):
|
||||
for base,sub in features:
|
||||
shape = base.Shape.getElement(sub)
|
||||
bb = shape.BoundBox
|
||||
# find the highes zmax and the highes zmin levels, those provide
|
||||
# the safest values for StartDepth and FinalDepth
|
||||
if zmax is None or zmax < bb.ZMax:
|
||||
zmax = bb.ZMax
|
||||
if zmin is None or zmin < bb.ZMin:
|
||||
zmin = bb.ZMin
|
||||
self.setDepths(obj, zmax, zmin, baseobject.Shape.BoundBox)
|
||||
|
||||
def setDepths(self, obj, zmax, zmin, bb):
|
||||
'''setDepths(obj, zmax, zmin, bb) ... set properties according to the provided values.'''
|
||||
PathLog.track(obj.Label, zmax, zmin, bb)
|
||||
if zmax is None:
|
||||
zmax = bb.ZMax
|
||||
if zmin is None:
|
||||
zmin = bb.ZMin
|
||||
|
||||
if zmin > zmax:
|
||||
zmax = zmin
|
||||
|
||||
PathLog.debug("setDepths(%s): z=%.2f -> %.2f bb.z=%.2f -> %.2f" % (obj.Label, zmin, zmax, bb.ZMin, bb.ZMax))
|
||||
|
||||
obj.StartDepth = zmax
|
||||
obj.ClearanceHeight = max(bb.ZMax, zmax) + 5.0
|
||||
obj.SafeHeight = max(bb.ZMax, zmax) + 3.0
|
||||
obj.FinalDepth = zmin
|
||||
|
||||
def findHoles(self, obj, baseobject):
|
||||
'''findHoles(obj, baseobject) ... inspect baseobject and identify all features that resemble a straight cricular hole.'''
|
||||
shape = baseobject.Shape
|
||||
|
||||
@@ -36,7 +36,7 @@ __author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
__doc__ = "UI and Command for Path Drilling Operation."
|
||||
|
||||
if True:
|
||||
if False:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
else:
|
||||
|
||||
@@ -93,47 +93,6 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
obj.StepOver = 100
|
||||
obj.ZigZagAngle = 45
|
||||
|
||||
def areaOpOnChanged(self, obj, prop):
|
||||
if 'Base' == prop and obj.Base and not 'Restore' in obj.State:
|
||||
PathLog.track(obj.Label, prop)
|
||||
zmin = sys.maxint
|
||||
zmax = -zmin
|
||||
for base, sublist in obj.Base:
|
||||
bb = base.Shape.BoundBox # parent boundbox
|
||||
for sub in sublist:
|
||||
subobj = base.Shape.getElement(sub)
|
||||
fbb = subobj.BoundBox # feature boundbox
|
||||
|
||||
if fbb.ZMax == fbb.ZMin and fbb.ZMax == bb.ZMax: # top face
|
||||
finalDepth = bb.ZMin
|
||||
elif fbb.ZMax > fbb.ZMin and fbb.ZMax == bb.ZMax: # vertical face, full cut
|
||||
finalDepth = fbb.ZMin
|
||||
elif fbb.ZMax > fbb.ZMin and fbb.ZMin > bb.ZMin: # internal vertical wall
|
||||
finalDepth = fbb.ZMin
|
||||
elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf
|
||||
finalDepth = fbb.ZMin
|
||||
else: # catch all
|
||||
finalDepth = bb.ZMin
|
||||
|
||||
if finalDepth < zmin:
|
||||
zmin = finalDepth
|
||||
if bb.ZMax > zmax:
|
||||
zmax = bb.ZMax
|
||||
PathLog.debug("%s: final=%.2f, max=%.2f" % (sub, zmin, zmax))
|
||||
|
||||
PathLog.debug("zmin=%.2f, zmax=%.2f" % (zmin, zmax))
|
||||
if not PathGeom.isRoughly(zmin, obj.FinalDepth.Value):
|
||||
obj.FinalDepth = zmin
|
||||
if not PathGeom.isRoughly(zmax, obj.StartDepth.Value):
|
||||
obj.StartDepth = zmax
|
||||
clearance = zmax + 5.0
|
||||
safe = zmax + 3
|
||||
if not PathGeom.isRoughly(clearance, obj.ClearanceHeight.Value):
|
||||
obj.CearanceHeight = clearance
|
||||
if not PathGeom.isRoughly(safe, obj.SafeHeight.Value):
|
||||
obj.SafeHeight = safe
|
||||
|
||||
|
||||
def Create(name):
|
||||
'''Create(name) ... Creates and returns a Pocket operation.'''
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
|
||||
|
||||
Reference in New Issue
Block a user