Skip to content

Commit

Permalink
Make Helix op robust against features that don't exist anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert committed Jul 15, 2019
1 parent 468ee04 commit f9e23d2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
27 changes: 15 additions & 12 deletions src/Mod/Path/PathScripts/PathCircularHoleBase.py
Expand Up @@ -152,18 +152,21 @@ def holePosition(self, obj, base, sub):
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)

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
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 == '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
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Path/PathScripts/PathHelix.py
Expand Up @@ -71,6 +71,10 @@ def initCircularHoleOperation(self, obj):
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()
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Path/PathScripts/PathJobGui.py
Expand Up @@ -121,6 +121,8 @@ def attach(self, vobj):
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()
Expand Down
15 changes: 12 additions & 3 deletions src/Mod/Path/PathScripts/PathOp.py
Expand Up @@ -23,6 +23,7 @@
# ***************************************************************************

import FreeCAD
import Part
import Path
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
Expand Down Expand Up @@ -215,6 +216,10 @@ def onDocumentRestored(self, obj):
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)

Expand Down Expand Up @@ -393,9 +398,13 @@ def faceZmin(bb, fbb):
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)
Expand Down

0 comments on commit f9e23d2

Please sign in to comment.