Skip to content

Commit

Permalink
Clip sections when too long
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
furti authored and yorikvanhavre committed May 8, 2019
1 parent 41a4ef6 commit 750d808
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/Mod/Arch/ArchFence.py
Expand Up @@ -97,7 +97,8 @@ def execute(self, obj):
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)
Expand Down Expand Up @@ -140,7 +141,7 @@ def calculatePosts(self, obj, postPlacements):

return posts

def calculateSections(self, obj, postPlacements, postLength):
def calculateSections(self, obj, postPlacements, postLength, sectionLength):
import Part

shapes = []
Expand All @@ -149,8 +150,6 @@ def calculateSections(self, obj, postPlacements, postLength):
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)
Expand All @@ -167,12 +166,39 @@ def calculateSections(self, obj, postPlacements, postLength):
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]
Expand Down

0 comments on commit 750d808

Please sign in to comment.