utils: use surface/curve Location/Position when available

OCCT shape's visual location is affect by both the shape's placement
and the shape's underlying surface/curve placement. So we can't just
use shape's placement alone. When getting surface/curve
location/position, the BRep_Adaptor will return a surface/curve with
accumulated transformation.
This commit is contained in:
Zheng, Lei 2019-05-29 13:04:32 +08:00
parent 253b67fb83
commit cc91aa105f

View File

@ -315,7 +315,7 @@ def getElementPos(obj):
surface = face.Surface
if str(surface) == '<Plane object>':
if not face.countElement('Edge'):
return face.Placement.Base
return surface.Position
return face.BoundBox.Center
# pos = surface.Position
elif all( hasattr(surface,a) for a in ['Axis','Center','Radius'] ):
@ -338,13 +338,19 @@ def getElementPos(obj):
edge = getElementShape(obj,Part.Edge)
if not edge:
return FreeCAD.Vector()
if isLine(edge.Curve):
curve = edge.Curve
if isLine(curve):
try:
return (edge.Vertex1.Point+edge.Vertex2.Point)*0.5
except Exception:
if hasattr(curve, 'Location'):
return curve.Location
return edge.Placement.Base
elif hasattr( edge.Curve, 'Center'): #circular curve
return edge.Curve.Center
base = getattr(curve,'BasisCurve',None)
if hasattr(curve, 'Center'): #circular curve
return curve.Center
elif hasattr(base, 'Center'):
return base.Center
else:
BSpline = edge.Curve.toBSpline()
arcs = BSpline.toBiArcs(10**-6)