Polar Array: support arbitrary links to subelements

To lines and to circles/arcs
This commit is contained in:
DeepSOIC 2015-11-03 02:26:56 +03:00
parent 007751702b
commit 1a1e04cd0d

View File

@ -71,6 +71,7 @@ class PolarArray(latticeBaseFeature.LatticeFeature):
obj.addProperty("App::PropertyVector","AxisPoint","Lattice Array","Center of rotation") obj.addProperty("App::PropertyVector","AxisPoint","Lattice Array","Center of rotation")
obj.addProperty("App::PropertyLink","AxisLink","Lattice Array","Link to the axis (Edge1 is used for the axis).") obj.addProperty("App::PropertyLink","AxisLink","Lattice Array","Link to the axis (Edge1 is used for the axis).")
obj.addProperty("App::PropertyString","AxisLinkSubelement","Lattice Array","subelement to take from axis link shape")
obj.addProperty("App::PropertyBool","AxisDirIsDriven","Lattice Array","If True, AxisDir is not updated based on the link.") obj.addProperty("App::PropertyBool","AxisDirIsDriven","Lattice Array","If True, AxisDir is not updated based on the link.")
obj.addProperty("App::PropertyBool","AxisPointIsDriven","Lattice Array","If True, AxisPoint is not updated based on the link.") obj.addProperty("App::PropertyBool","AxisPointIsDriven","Lattice Array","If True, AxisPoint is not updated based on the link.")
@ -123,25 +124,27 @@ class PolarArray(latticeBaseFeature.LatticeFeature):
# Apply links # Apply links
if obj.AxisLink: if obj.AxisLink:
axShape = obj.AxisLink #resolve the link
edges = axShape.Shape.Edges if len(obj.AxisLinkSubelement) > 0:
if len(edges) < 1: linkedShape = obj.AxisLink.Shape.getElement(obj.AxisLinkSubelement)
raise ValueError('There are no edges in axis link shape!') else:
elif len(edges) > 1: linkedShape = obj.AxisLink.Shape
latticeExecuter.warning(obj,'There is more than one edge in shape linked as an axis. The first edge will be used, but the shape link was probably added mistakenly.')
edge = edges[0] #Type check
if linkedShape.ShapeType != 'Edge':
raise ValueError('Axis link must be an edge; it is '+linkedShape.ShapeType+' instead.')
#prepare #prepare
dir = App.Vector() dir = App.Vector()
point = App.Vector() point = App.Vector()
if isinstance(edge.Curve, Part.Line): if isinstance(linkedShape.Curve, Part.Line):
dir = edge.Curve.EndPoint - edge.Curve.StartPoint dir = linkedShape.Curve.EndPoint - linkedShape.Curve.StartPoint
point = edge.Curve.StartPoint point = linkedShape.Curve.StartPoint
elif isinstance(edge.Curve, Part.Circle): elif isinstance(linkedShape.Curve, Part.Circle):
obj.AxisDir = edge.Curve.Axis dir = linkedShape.Curve.Axis
obj.AxisPoint = edge.Curve.Center point = linkedShape.Curve.Center
else: else:
raise ValueError("Edge " + repr(edge) + " can't be used to derive an axis. It must be either a line or a circle/arc.") raise ValueError("Edge " + repr(linkedShape) + " can't be used to derive an axis. It must be either a line or a circle/arc.")
#apply #apply
if obj.AxisDirIsDriven: if obj.AxisDirIsDriven:
@ -220,6 +223,8 @@ def CreatePolarArray(name):
FreeCADGui.doCommand("f = latticePolarArray.makePolarArray(name='"+name+"')") FreeCADGui.doCommand("f = latticePolarArray.makePolarArray(name='"+name+"')")
if len(sel) == 1: if len(sel) == 1:
FreeCADGui.doCommand("f.AxisLink = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.AxisLink = App.ActiveDocument."+sel[0].ObjectName)
if sel[0].HasSubObjects:
FreeCADGui.doCommand("f.AxisLinkSubelement = '"+sel[0].SubElementNames[0]+"'")
FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()