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