From 72d1e93907709d2817b9e388883f09a8779304a2 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 17 Oct 2015 18:31:20 +0300 Subject: [PATCH] BoundBox: informational read-only properties --- latticeBoundBox.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/latticeBoundBox.py b/latticeBoundBox.py index f440295..0ccef2d 100644 --- a/latticeBoundBox.py +++ b/latticeBoundBox.py @@ -83,20 +83,44 @@ class _BoundBox: obj.addProperty("App::PropertyBool","Precision","BoundBox","Use precise alorithm (slower).") obj.Precision = True obj.addProperty("App::PropertyBool","InLocalSpace","BoundBox","Construct bounding box in local coordinate space of the object, not in global.") + + # read-only properties: + prop = "Size" + obj.addProperty("App::PropertyVector",prop,"Info","Diagonal vector of bounding box") + obj.setEditorMode(prop, 1) # set read-only + + prop = "Center" + obj.addProperty("App::PropertyVector",prop,"Info","Center of bounding box") + obj.setEditorMode(prop, 1) # set read-only + obj.Proxy = self def execute(self,obj): shape = obj.Base.Shape + plm = obj.Base.Placement if obj.InLocalSpace: shape = shape.copy() - shape.transformShape(obj.Base.Placement.inverse().toMatrix()) + shape.transformShape(plm.inverse().toMatrix()) - rst = boundBox2RealBox(getPrecisionBoundBox(shape)) + bb = None + if obj.Precision: + bb = getPrecisionBoundBox(shape) + else: + bb = shape.BoundBox + rst = boundBox2RealBox(bb) if obj.InLocalSpace: - rst.transformShape(obj.Base.Placement.toMatrix(), True) #True is for Copy argument + rst.transformShape(plm.toMatrix(), True) #True is for Copy argument + + #Fill in read-only properties + obj.Size = FreeCAD.Vector(bb.XLength,bb.YLength,bb.ZLength) + + cnt = bb.Center + if obj.InLocalSpace: + cnt = plm.multVec(cnt) + obj.Center = cnt obj.Shape = rst return