From 72b291ecff323e61d812d4a09643e8f5aaa8a93c Mon Sep 17 00:00:00 2001 From: furti Date: Tue, 7 May 2019 19:40:58 +0200 Subject: [PATCH] Clip sections when too long When the path wraps around a corner the section might be too long to fit between the fence posts. So we clip it to the length so that it fits. --- src/Mod/Arch/ArchFence.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Mod/Arch/ArchFence.py b/src/Mod/Arch/ArchFence.py index da66c3eb2d..fb2d9bde80 100644 --- a/src/Mod/Arch/ArchFence.py +++ b/src/Mod/Arch/ArchFence.py @@ -97,7 +97,8 @@ class _Fence(ArchComponent.Component): obj, pathwire, downRotation) postShapes = self.calculatePosts(obj, postPlacements) - sectionShapes = self.calculateSections(obj, postPlacements, postLength) + sectionShapes = self.calculateSections( + obj, postPlacements, postLength, sectionLength) allShapes = [] allShapes.extend(postShapes) @@ -140,7 +141,7 @@ class _Fence(ArchComponent.Component): return posts - def calculateSections(self, obj, postPlacements, postLength): + def calculateSections(self, obj, postPlacements, postLength, sectionLength): import Part shapes = [] @@ -149,8 +150,6 @@ class _Fence(ArchComponent.Component): startPlacement = postPlacements[i] endPlacement = postPlacements[i + 1] - # print("start: %s, end: %s\n" % (startPlacement, endPlacement)) - sectionLine = Part.LineSegment( startPlacement.Base, endPlacement.Base) sectionBase = sectionLine.value(postLength) @@ -167,12 +166,39 @@ class _Fence(ArchComponent.Component): placement.Rotation = sectionRotation sectionCopy = obj.Section.Shape.copy() + + if sectionLength > sectionLine.length(): + # Part.show(Part.Shape([sectionLine]), 'line') + sectionCopy = self.clipSection( + sectionCopy, sectionLength, sectionLine.length() - postLength) + sectionCopy.Placement = placement shapes.append(sectionCopy) return shapes + def clipSection(self, shape, length, clipLength): + print("length: %s, clipLength: %s" % (length, clipLength)) + + boundBox = shape.BoundBox + lengthToCut = length - clipLength + halfLengthToCut = lengthToCut / 2 + + leftBox = Part.makeBox(halfLengthToCut, boundBox.YMax + 1, boundBox.ZMax + 1, + FreeCAD.Vector(boundBox.XMin, boundBox.YMin, boundBox.ZMin)) + rightBox = Part.makeBox(halfLengthToCut, boundBox.YMax + 1, boundBox.ZMax + 1, + FreeCAD.Vector(boundBox.XMin + halfLengthToCut + clipLength, boundBox.YMin, boundBox.ZMin)) + + newShape = shape.cut([leftBox, rightBox]) + newBoundBox = newShape.BoundBox + + newShape.translate(FreeCAD.Vector(-newBoundBox.XMin, 0, 0)) + + print(newShape.BoundBox) + + return newShape.removeSplitter() + def calculatePathWire(self, obj): if (hasattr(obj.Path.Shape, 'Wires') and obj.Path.Shape.Wires): return obj.Path.Shape.Wires[0]