Introduced custom spacing property in the Rebar object

This commit is contained in:
Amritpal Singh
2017-07-07 17:36:50 +05:30
committed by Yorik van Havre
parent a066490b28
commit 3aab7ffce5

View File

@@ -20,6 +20,7 @@
#* USA *
#* *
#***************************************************************************
# Modified Amritpal Singh <amrit3701@gmail.com> on 07-07-2017
import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands
from FreeCAD import Vector
@@ -162,6 +163,7 @@ class _Rebar(ArchComponent.Component):
obj.addProperty("App::PropertyFloat","Rounding","Arch",QT_TRANSLATE_NOOP("App::Property","The fillet to apply to the angle of the base profile. This value is multiplied by the bar diameter."))
obj.addProperty("App::PropertyPlacementList","PlacementList","Arch",QT_TRANSLATE_NOOP("App::Property","List of placement of all the bars"))
obj.addProperty("App::PropertyLink","Host","Arch",QT_TRANSLATE_NOOP("App::Property","The structure object that hosts this rebar"))
obj.addProperty("App::PropertyString", "CustomSpacing", "Arch", QT_TRANSLATE_NOOP("App::Property","The custom spacing of rebar"))
self.Type = "Rebar"
obj.setEditorMode("Spacing",1)
@@ -236,7 +238,7 @@ class _Rebar(ArchComponent.Component):
wire.translate(vinterval)
wires.append(wire)
return [wires,obj.Diameter.Value/2]
def onChanged(self,obj,prop):
if prop == "Host":
if hasattr(obj,"Host"):
@@ -298,9 +300,13 @@ class _Rebar(ArchComponent.Component):
size = obj.Distance.Value
#print(axis)
#print(size)
spacinglist = None
if hasattr(obj, "CustomSpacing"):
if obj.CustomSpacing:
spacinglist = strprocessOfCustomSpacing(obj.CustomSpacing)
influenceArea = sum(spacinglist) - spacinglist[0] / 2 - spacinglist[-1] / 2
if (obj.OffsetStart.Value + obj.OffsetEnd.Value) > size:
return
# all tests ok!
pl = obj.Placement
import Part
@@ -335,6 +341,23 @@ class _Rebar(ArchComponent.Component):
placementlist.append(barplacement)
if hasattr(obj,"Spacing"):
obj.Spacing = interval
# Calculate placement of bars from custom spacing.
if spacinglist:
placementlist[:] = []
reqInfluenceArea = size - (obj.OffsetStart.Value + obj.OffsetEnd.Value)
if influenceArea > reqInfluenceArea:
return FreeCAD.Console.PrintError("Influence area of rebars is greater than "+ str(reqInfluenceArea) + ".\n")
elif influenceArea < reqInfluenceArea:
FreeCAD.Console.PrintWarning("Last span is greater that end offset.\n")
for i in range(len(spacinglist)):
if i == 0:
barplacement = CustomSpacingPlacement(spacinglist, 1, axis, father.Placement.Rotation, obj.OffsetStart.Value, obj.OffsetEnd.Value)
placementlist.append(barplacement)
else:
barplacement = CustomSpacingPlacement(spacinglist, i+1, axis, father.Placement.Rotation, obj.OffsetStart.Value, obj.OffsetEnd.Value)
placementlist.append(barplacement)
obj.Amount = len(spacinglist)
obj.Spacing = 0
obj.PlacementList = placementlist
for i in range(len(obj.PlacementList)):
if i == 0:
@@ -385,5 +408,43 @@ def CalculatePlacement(baramount, barnumber, size, axis, rotation, offsetstart,
placement = FreeCAD.Placement(barplacement, rotation)
return placement
def CustomSpacingPlacement(spacinglist, barnumber, axis, rotation, offsetstart, offsetend):
""" CustomSpacingPlacement(spacinglist, barnumber, axis, rotation, offsetstart, offsetend):
Calculate placement of the bar from custom spacing list."""
if barnumber == 1:
bardistance = offsetstart
else:
bardistance = sum(spacinglist[0:barnumber])
bardistance = bardistance - spacinglist[0] / 2
bardistance = bardistance - spacinglist[barnumber - 1] / 2
bardistance = bardistance + offsetstart
barplacement = DraftVecUtils.scaleTo(axis, bardistance)
placement = FreeCAD.Placement(barplacement, rotation)
return placement
def strprocessOfCustomSpacing(span_string):
""" strprocessOfCustomSpacing(span_string): This function take input
in specific syntax and return output in the form of list. For eg.
Input: "3@100+2@200+3@100"
Output: [100, 100, 100, 200, 200, 100, 100, 100]"""
import string
span_st = string.strip(span_string)
span_sp = string.split(span_st, '+')
index = 0
spacinglist = []
while index < len(span_sp):
# Find "@" recursively in span_sp array.
# If not found, append the index value to "spacinglist" array.
if string.find(span_sp[index],'@') == -1:
spacinglist.append(float(span_sp[index]))
else:
in_sp = string.split(span_sp[index], '@')
count = 0
while count < int(in_sp[0]):
spacinglist.append(float(in_sp[1]))
count += 1
index += 1
return spacinglist
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Arch_Rebar',_CommandRebar())