Make Helix op robust against features that don't exist anymore

This commit is contained in:
Markus Lampert
2019-07-14 21:30:38 -07:00
parent 8014e50a3a
commit cadea61e0b
4 changed files with 31 additions and 13 deletions

View File

@@ -152,18 +152,21 @@ class ObjectOp(PathOp.ObjectOp):
center = edge.Curve.Center
return FreeCAD.Vector(center.x, center.y, 0)
shape = base.Shape.getElement(sub)
if shape.ShapeType == 'Vertex':
return FreeCAD.Vector(shape.X, shape.Y, 0)
try:
shape = base.Shape.getElement(sub)
if shape.ShapeType == 'Vertex':
return FreeCAD.Vector(shape.X, shape.Y, 0)
if shape.ShapeType == 'Edge' and hasattr(shape.Curve, 'Center'):
return FreeCAD.Vector(shape.Curve.Center.x, shape.Curve.Center.y, 0)
if shape.ShapeType == 'Edge' and hasattr(shape.Curve, 'Center'):
return FreeCAD.Vector(shape.Curve.Center.x, shape.Curve.Center.y, 0)
if shape.ShapeType == 'Face':
if hasattr(shape.Surface, 'Center'):
return FreeCAD.Vector(shape.Surface.Center.x, shape.Surface.Center.y, 0)
if len(shape.Edges) == 1 and type(shape.Edges[0].Curve) == Part.Circle:
return shape.Edges[0].Curve.Center
if shape.ShapeType == 'Face':
if hasattr(shape.Surface, 'Center'):
return FreeCAD.Vector(shape.Surface.Center.x, shape.Surface.Center.y, 0)
if len(shape.Edges) == 1 and type(shape.Edges[0].Curve) == Part.Circle:
return shape.Edges[0].Curve.Center
except Part.OCCError as e:
PathLog.error(e)
PathLog.error(translate("Path", "Feature %s.%s cannot be processed as a circular hole - please remove from Base geometry list.") % (base.Label, sub))
return None

View File

@@ -71,6 +71,10 @@ class ObjectHelix(PathCircularHoleBase.ObjectOp):
obj.addProperty("App::PropertyEnumeration", "EnableRotation", "Rotation", QtCore.QT_TRANSLATE_NOOP("App::Property", "Enable rotation to gain access to pockets/areas not normal to Z axis."))
obj.EnableRotation = ['Off', 'A(x)', 'B(y)', 'A & B']
def opOnDocumentRestored(self, obj):
if not hasattr(obj, 'StartRadius'):
obj.addProperty("App::PropertyLength", "StartRadius", "Helix Drill", translate("PathHelix", "Starting Radius"))
def circularHoleExecute(self, obj, holes):
'''circularHoleExecute(obj, holes) ... generate helix commands for each hole in holes'''
PathLog.track()

View File

@@ -121,6 +121,8 @@ class ViewProvider:
self.vobj = vobj
self.obj = vobj.Object
self.taskPanel = None
self.baseVisibility = None
self.stockVisibility = None
# setup the axis display at the origin
self.switch = coin.SoSwitch()

View File

@@ -23,6 +23,7 @@
# ***************************************************************************
import FreeCAD
import Part
import Path
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
@@ -215,6 +216,10 @@ class ObjectOp(object):
if not hasattr(obj, 'OpStockZMax'):
self.addOpValues(obj, ['stockz'])
if not hasattr(obj, 'EnableRotation'):
obj.addProperty("App::PropertyEnumeration", "EnableRotation", "Rotation", QtCore.QT_TRANSLATE_NOOP("App::Property", "Enable rotation to gain access to pockets/areas not normal to Z axis."))
obj.EnableRotation = ['Off', 'A(x)', 'B(y)', 'A & B']
self.setEditorModes(obj, features)
self.opOnDocumentRestored(obj)
@@ -393,9 +398,13 @@ class ObjectOp(object):
bb = base.Shape.BoundBox
zmax = max(zmax, bb.ZMax)
for sub in sublist:
fbb = base.Shape.getElement(sub).BoundBox
zmin = max(zmin, faceZmin(bb, fbb))
zmax = max(zmax, fbb.ZMax)
try:
fbb = base.Shape.getElement(sub).BoundBox
zmin = max(zmin, faceZmin(bb, fbb))
zmax = max(zmax, fbb.ZMax)
except Part.OCCError as e:
PathLog.error(e)
else:
# clearing with stock boundaries
job = PathUtils.findParentJob(obj)