From e0e14a133d21025a27e4a951f607323b8412c874 Mon Sep 17 00:00:00 2001 From: Dave Cowden Date: Sun, 3 Apr 2016 20:24:13 -0400 Subject: [PATCH] fixed tests to pass with FreeCAD 0.15 --- cadquery/freecad_impl/shapes.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cadquery/freecad_impl/shapes.py b/cadquery/freecad_impl/shapes.py index 0ceae22..659d4d1 100644 --- a/cadquery/freecad_impl/shapes.py +++ b/cadquery/freecad_impl/shapes.py @@ -237,8 +237,8 @@ class Shape(object): :param objects: a list of objects with mass """ - total_mass = sum(o.wrapped.Mass for o in objects) - weighted_centers = [o.wrapped.CenterOfMass.multiply(o.wrapped.Mass) for o in objects] + total_mass = sum(Shape.computeMass(o) for o in objects) + weighted_centers = [o.wrapped.CenterOfMass.multiply(Shape.computeMass(o)) for o in objects] sum_wc = weighted_centers[0] for wc in weighted_centers[1:] : @@ -246,6 +246,17 @@ class Shape(object): return Vector(sum_wc.multiply(1./total_mass)) + @staticmethod + def computeMass(object): + """ + Calculates the 'mass' of an object. in FreeCAD < 15, all objects had a mass. + in FreeCAD >=15, faces no longer have mass, but instead have area. + """ + if object.wrapped.ShapeType == 'Face': + return object.wrapped.Area + else: + return object.wrapped.Mass + @staticmethod def CombinedCenterOfBoundBox(objects): """