From 5ff29e2b5c6f7096a9bb4771d3b28786560ba3ed Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 5 Apr 2012 15:11:47 -0300 Subject: [PATCH] Added a function to calculate cut volumes to ArchCommads --- src/Mod/Arch/ArchCommands.py | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/Mod/Arch/ArchCommands.py b/src/Mod/Arch/ArchCommands.py index 342e0f1f9..c3a58174b 100644 --- a/src/Mod/Arch/ArchCommands.py +++ b/src/Mod/Arch/ArchCommands.py @@ -199,6 +199,50 @@ def makeFace(wires,method=2,cleanup=False): print "final face:",mf.Faces return mf.Faces[0] +def getCutVolume(objects,placement): + '''getCutVolume(objects,placement): returns a tuple with 2 objects: a face, positioned + at the given placement's position, and wide enough so the projection of all objects + in the list fits into it, and an extrusion vector, that can be used to extrude the + plane so it includes all objects in the list.''' + import Part + if not objects: + return None + bb = objects[0].Shape.BoundBox + for obj in objects[1:]: + bb.add(obj.Shape.BoundBox) + bb.enlarge(1) + u = placement.Rotation.multVec(FreeCAD.Vector(1,0,0)) + v = placement.Rotation.multVec(FreeCAD.Vector(0,1,0)) + w = placement.Rotation.multVec(FreeCAD.Vector(0,0,1)) + um = vm = wm = 0 + if not bb.isCutPlane(placement.Base,w): + return None + corners = [FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMin), + FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMin), + FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMin), + FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMin), + FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMax), + FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMax), + FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMax), + FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax)] + for c in corners: + dv = c.sub(placement.Base) + um1 = fcvec.project(dv,u).Length + um = max(um,um1) + vm1 = fcvec.project(dv,v).Length + vm = max(vm,vm1) + wm1 = fcvec.project(dv,w).Length + wm = max(wm,wm1) + p1 = FreeCAD.Vector(-um,vm,0) + p2 = FreeCAD.Vector(um,vm,0) + p3 = FreeCAD.Vector(um,-vm,0) + p4 = FreeCAD.Vector(-um,-vm,0) + f = Part.makePolygon([p1,p2,p3,p4,p1]) + f = Part.Face(f) + f.Placement = placement + n = fcvec.scaleTo(w,wm) + return (f,n) + def meshToShape(obj,mark=True): '''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If mark is True (default), non-solid objects will be marked in red'''