From cc91aa105fd4da6d771e36c174726d3aeaf5eeff Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 29 May 2019 13:04:32 +0800 Subject: [PATCH] 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. --- utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/utils.py b/utils.py index 9eb6fef..33a5a80 100644 --- a/utils.py +++ b/utils.py @@ -315,7 +315,7 @@ def getElementPos(obj): surface = face.Surface if str(surface) == '': 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)