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.
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user