Automate Reinforcement GSoC proposal

Contributions from the participants, questions and answers to their projects.
Discussions of proposals for upcoming events.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Re: Automate Reinforcement GSoC proposal

Post by amrit3701 »

Suraj Dadral wrote: Fri Apr 12, 2019 4:56 pm I added following code snippet to move stirrups with structure in functions makeStirrup() and editStirrup():

Code: Select all

# Rotate Stirrups with Structure
structureAngle=math.degrees(structure.Placement.Rotation.Angle)
stirrupAngle=structureAngle-90
rebar.Placement.Rotation.__setattr__('Angle',math.radians(stirrupAngle))
Complete file:

Code: Select all

from PySide import QtCore, QtGui
from Rebarfunc import *
from PySide.QtCore import QT_TRANSLATE_NOOP
from RebarDistribution import runRebarDistribution, removeRebarDistribution
from PopUpImage import showPopUpImageDialog
import FreeCAD
import FreeCADGui
import ArchCommands
import os
import sys
import math

def getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, facenormal):
    """ getpointsOfStirrup(FacePRM, LeftCover, RightCover, TopCover, BottomCover, BentAngle, BentFactor, Diameter, Rounding, FaceNormal):
    Return the coordinates points of the Stirrup in the form of array."""
    angle = 180 - bentAngle
    tangent_part_length = extendedTangentPartLength(rounding, diameter, angle)
    tangent_length = extendedTangentLength(rounding, diameter, angle)
    if round(facenormal[0]) in {1,-1}:
        x1 = FacePRM[1][0]
        y1 = FacePRM[1][1] - FacePRM[0][0] / 2 + l_cover
        z1 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover + tangent_part_length
        y2 = FacePRM[1][1] - FacePRM[0][0] / 2 + l_cover
        z2 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
        y3 = FacePRM[1][1] + FacePRM[0][0] / 2 - r_cover
        z3 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
        y4 = FacePRM[1][1] + FacePRM[0][0] / 2 - r_cover
        z4 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
        y5 = FacePRM[1][1] - FacePRM[0][0] / 2 + l_cover - tangent_part_length
        z5 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
        side_length = abs(y5 - y4) - tangent_part_length
        normal_dis = (diameter * (side_length + tangent_part_length)) / side_length
        x2 = x1 - normal_dis / 4
        x3 = x2 - normal_dis / 4
        x4 = x3 - normal_dis / 4
        x5 = x4 - normal_dis / 4
        x0 = x1 + normal_dis / 4
        y0 = y1 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(angle))
        z0 = z1 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(angle))
        x6 = x5 - normal_dis / 4
        y6 = y5 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(90 - angle))
        z6 = z5 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(90 - angle))
    elif round(facenormal[1]) in {1,-1}:
        x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
        y1 = FacePRM[1][1]
        z1 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover + tangent_part_length
        x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
        z2 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
        x3 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
        z3 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
        x4 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
        z4 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
        x5 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover - tangent_part_length
        z5 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
        side_length = abs(x5 - x4) - tangent_part_length
        normal_dis = (diameter * (side_length + tangent_part_length)) / side_length
        y2 = y1 - normal_dis / 4
        y3 = y2 - normal_dis / 4
        y4 = y3 - normal_dis / 4
        y5 = y4 - normal_dis / 4
        y0 = y1 + normal_dis / 4
        x0 = x1 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(angle))
        z0 = z1 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(angle))
        x6 = x5 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(90 - angle))
        y6 = y5 - normal_dis / 4
        z6 = z5 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(90 - angle))
    elif round(facenormal[2]) in {1,-1}:
        x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
        y1 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover + tangent_part_length
        z1 = FacePRM[1][2]
        x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
        y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
        x3 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
        y3 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
        x4 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
        y4 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
        x5 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover - tangent_part_length
        y5 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
        side_length = abs(x5 - x4) - tangent_part_length
        normal_dis = (diameter * (side_length + tangent_part_length)) / side_length
        z2 = z1 - normal_dis / 4
        z3 = z2 - normal_dis / 4
        z4 = z3 - normal_dis / 4
        z5 = z4 - normal_dis / 4
        z0 = z1 + normal_dis / 4
        x0 = x1 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(angle))
        y0 = y1 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(angle))
        x6 = x5 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(90 - angle))
        y6 = y5 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(90 - angle))
        z6 = z5 - normal_dis / 4
    return [FreeCAD.Vector(x0, y0, z0), FreeCAD.Vector(x1, y1, z1),\
            FreeCAD.Vector(x2, y2, z2), FreeCAD.Vector(x3, y3, z3),\
            FreeCAD.Vector(x4, y4, z4), FreeCAD.Vector(x5, y5, z5),\
            FreeCAD.Vector(x6, y6, z6)]

class _StirrupTaskPanel:
    def __init__(self, Rebar = None):
        self.CustomSpacing = None
        if not Rebar:
            selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
            self.SelectedObj = selected_obj.Object
            self.FaceName = selected_obj.SubElementNames[0]
        else:
            self.FaceName = Rebar.Base.Support[0][1][0]
            self.SelectedObj = Rebar.Base.Support[0][0]
        self.form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] + ".ui")
        self.form.setWindowTitle(QtGui.QApplication.translate("RebarAddon", "Stirrup Rebar", None))
        self.form.bentAngle.addItems(["135", "90"])
        self.form.amount_radio.clicked.connect(self.amount_radio_clicked)
        self.form.spacing_radio.clicked.connect(self.spacing_radio_clicked)
        self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0]+"/icons/Stirrup.svg").scaled(150, 150, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation))
        self.form.customSpacing.clicked.connect(lambda: runRebarDistribution(self))
        self.form.removeCustomSpacing.clicked.connect(lambda: removeRebarDistribution(self))
        self.form.PickSelectedFace.clicked.connect(lambda: getSelectedFace(self))
        # self.form.toolButton.setIcon(self.form.toolButton.style().standardIcon(QtGui.QStyle.SP_DialogHelpButton))
        self.form.toolButton.clicked.connect(lambda: showPopUpImageDialog(os.path.split(os.path.abspath(__file__))[0] + "/icons/StirrupDetailed.svg"))
        self.Rebar = Rebar

    def getStandardButtons(self):
        return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Apply) | int(QtGui.QDialogButtonBox.Cancel)

    def clicked(self, button):
        if button == int(QtGui.QDialogButtonBox.Apply):
            self.accept(button)

    def accept(self, signal = None):
        l_cover = self.form.l_sideCover.text()
        l_cover = FreeCAD.Units.Quantity(l_cover).Value
        r_cover = self.form.r_sideCover.text()
        r_cover = FreeCAD.Units.Quantity(r_cover).Value
        t_cover = self.form.t_sideCover.text()
        t_cover = FreeCAD.Units.Quantity(t_cover).Value
        b_cover = self.form.b_sideCover.text()
        b_cover = FreeCAD.Units.Quantity(b_cover).Value
        f_cover = self.form.frontCover.text()
        f_cover = FreeCAD.Units.Quantity(f_cover).Value
        diameter = self.form.diameter.text()
        diameter = FreeCAD.Units.Quantity(diameter).Value
        bentAngle = int(self.form.bentAngle.currentText())
        bentFactor = self.form.bentFactor.value()
        rounding = self.form.rounding.value()
        amount_check = self.form.amount_radio.isChecked()
        spacing_check = self.form.spacing_radio.isChecked()
        if not self.Rebar:
            if amount_check:
                amount = self.form.amount.value()
                rebar = makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter,\
                    rounding, True, amount, self.SelectedObj, self.FaceName)
            elif spacing_check:
                spacing = self.form.spacing.text()
                spacing = FreeCAD.Units.Quantity(spacing).Value
                rebar = makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter,\
                    rounding, False, spacing, self.SelectedObj, self.FaceName)
        else:
            if amount_check:
                amount = self.form.amount.value()
                rebar = editStirrup(self.Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor,\
                    diameter, rounding, True, amount, self.SelectedObj, self.FaceName)
            elif spacing_check:
                spacing = self.form.spacing.text()
                spacing = FreeCAD.Units.Quantity(spacing).Value
                rebar = editStirrup(self.Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor,\
                    diameter, rounding, False, spacing, self.SelectedObj, self.FaceName)
        if self.CustomSpacing:
            rebar.CustomSpacing = self.CustomSpacing
            FreeCAD.ActiveDocument.recompute()
        self.Rebar = rebar
        if signal == int(QtGui.QDialogButtonBox.Apply):
            pass
        else:
            FreeCADGui.Control.closeDialog(self)

    def amount_radio_clicked(self):
        self.form.spacing.setEnabled(False)
        self.form.amount.setEnabled(True)

    def spacing_radio_clicked(self):
        self.form.amount.setEnabled(False)
        self.form.spacing.setEnabled(True)


def makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter, rounding,\
        amount_spacing_check, amount_spacing_value, structure = None, facename = None):
    """ makeStirrup(LeftCover, RightCover, TopCover, BottomCover, FrontCover, BentAngle,
    BentFactor, Diameter, Rounding, AmountSpacingCheck, AmountSpacingValue, Structure, Facename):
    Adds the Stirrup reinforcement bar to the selected structural object."""
    if not structure and not facename:
        selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
        structure = selected_obj.Object
        facename = selected_obj.SubElementNames[0]
    face = structure.Shape.Faces[getFaceNumber(facename) - 1]
    #StructurePRM = getTrueParametersOfStructure(structure)
    FacePRM = getParametersOfFace(structure, facename, False)
    FaceNormal = face.normalAt(0,0)
    #FaceNormal = face.Placement.Rotation.inverted().multVec(FaceNormal)
    if not FacePRM:
        FreeCAD.Console.PrintError("Cannot identified shape or from which base object sturctural element is derived\n")
        return
    # Calculate the coordinate values of Stirrup
    points = getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, FaceNormal)
    import Draft
    line = Draft.makeWire(points, closed = False, face = True, support = None)
    import Arch
    line.Support = [(structure, facename)]
    if amount_spacing_check:
        rebar = Arch.makeRebar(structure, line, diameter, amount_spacing_value, f_cover)
    else:
        size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
        rebar = Arch.makeRebar(structure, line, diameter,\
            int((size - diameter) / amount_spacing_value), f_cover)
    rebar.Direction = FaceNormal.negative()
    rebar.Rounding = rounding

    # Rotate Stirrups with Structure
    structureAngle=math.degrees(structure.Placement.Rotation.Angle)
    stirrupAngle=structureAngle-90
    rebar.Placement.Rotation.__setattr__('Angle',math.radians(stirrupAngle))

    # Adds properties to the rebar object
    rebar.ViewObject.addProperty("App::PropertyString", "RebarShape", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property","Shape of rebar")).RebarShape = "Stirrup"
    rebar.ViewObject.setEditorMode("RebarShape", 2)
    rebar.addProperty("App::PropertyDistance", "LeftCover", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Left Side cover of rebar")).LeftCover = l_cover
    rebar.setEditorMode("LeftCover", 2)
    rebar.addProperty("App::PropertyDistance", "RightCover", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Right Side cover of rebar")).RightCover = r_cover
    rebar.setEditorMode("RightCover", 2)
    rebar.addProperty("App::PropertyDistance", "TopCover", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Top Side cover of rebar")).TopCover = t_cover
    rebar.setEditorMode("TopCover", 2)
    rebar.addProperty("App::PropertyDistance", "BottomCover", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Bottom Side cover of rebar")).BottomCover = b_cover
    rebar.setEditorMode("BottomCover", 2)
    rebar.addProperty("App::PropertyDistance", "FrontCover", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Top cover of rebar")).FrontCover = f_cover
    rebar.setEditorMode("FrontCover", 2)
    rebar.addProperty("App::PropertyInteger", "BentAngle", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Bent angle between at the end of rebar")).BentAngle = bentAngle
    rebar.setEditorMode("BentAngle", 2)
    rebar.addProperty("App::PropertyInteger", "BentFactor", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Bent Length is the equal to BentFactor * Diameter")).BentFactor = bentFactor
    rebar.setEditorMode("BentFactor", 2)
    rebar.addProperty("App::PropertyBool", "AmountCheck", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Amount radio button is checked")).AmountCheck
    rebar.setEditorMode("AmountCheck", 2)
    rebar.addProperty("App::PropertyDistance", "TrueSpacing", "RebarDialog",\
        QT_TRANSLATE_NOOP("App::Property", "Spacing between of rebars")).TrueSpacing = amount_spacing_value
    rebar.setEditorMode("TrueSpacing", 2)
    if amount_spacing_check:
        rebar.AmountCheck = True
    else:
        rebar.AmountCheck = False
        rebar.TrueSpacing = amount_spacing_value
    rebar.Label = "Stirrup"
    FreeCAD.ActiveDocument.recompute()
    return rebar

def editStirrup(Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter, rounding,\
        amount_spacing_check, amount_spacing_value, structure = None, facename = None):
    sketch = Rebar.Base
    if structure and facename:
        sketch.Support = [(structure, facename)]
    # Check if sketch support is empty.
    if not sketch.Support:
        showWarning("You have checked remove external geometry of base sketchs when needed.\nTo unchecked Edit->Preferences->Arch.")
        return
    # Assigned values
    facename = sketch.Support[0][1][0]
    structure = sketch.Support[0][0]
    face = structure.Shape.Faces[getFaceNumber(facename) - 1]
    #StructurePRM = getTrueParametersOfStructure(structure)
    # Get parameters of the face where sketch of rebar is drawn
    FacePRM = getParametersOfFace(structure, facename, False)
    FaceNormal = face.normalAt(0, 0)
    #FaceNormal = face.Placement.Rotation.inverted().multVec(FaceNormal)
    # Calculate the coordinates value of Stirrup rebar
    points = getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, FaceNormal)
    Rebar.Base.Points = points
    FreeCAD.ActiveDocument.recompute()
    Rebar.Direction = FaceNormal.negative()
    Rebar.OffsetStart = f_cover
    Rebar.OffsetEnd = f_cover
    Rebar.BentAngle = bentAngle
    Rebar.BentFactor = bentFactor
    Rebar.Rounding = rounding
    Rebar.Diameter = diameter
    if amount_spacing_check:
        Rebar.Amount = amount_spacing_value
        FreeCAD.ActiveDocument.recompute()
        Rebar.AmountCheck = True
    else:
        size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
        Rebar.Amount = int((size - diameter) / amount_spacing_value)
        FreeCAD.ActiveDocument.recompute()
        Rebar.AmountCheck = False
    Rebar.FrontCover = f_cover
    Rebar.LeftCover = l_cover
    Rebar.RightCover = r_cover
    Rebar.TopCover = t_cover
    Rebar.BottomCover = b_cover
    Rebar.TrueSpacing = amount_spacing_value
 
    # Rotate Stirrups with Structure
    structureAngle=math.degrees(structure.Placement.Rotation.Angle)
    stirrupAngle=structureAngle-90
    Rebar.Placement.Rotation.__setattr__('Angle',math.radians(stirrupAngle))

    FreeCAD.ActiveDocument.recompute()
    return Rebar

def editDialog(vobj):
    FreeCADGui.Control.closeDialog()
    obj = _StirrupTaskPanel(vobj.Object)
    obj.form.frontCover.setText(str(vobj.Object.FrontCover))
    obj.form.l_sideCover.setText(str(vobj.Object.LeftCover))
    obj.form.r_sideCover.setText(str(vobj.Object.RightCover))
    obj.form.t_sideCover.setText(str(vobj.Object.TopCover))
    obj.form.b_sideCover.setText(str(vobj.Object.BottomCover))
    obj.form.diameter.setText(str(vobj.Object.Diameter))
    obj.form.bentAngle.setCurrentIndex(obj.form.bentAngle.findText(str(vobj.Object.BentAngle)))
    obj.form.bentFactor.setValue(vobj.Object.BentFactor)
    obj.form.rounding.setValue(vobj.Object.Rounding)
    if vobj.Object.AmountCheck:
        obj.form.amount.setValue(vobj.Object.Amount)
    else:
        obj.form.amount_radio.setChecked(False)
        obj.form.spacing_radio.setChecked(True)
        obj.form.amount.setDisabled(True)
        obj.form.spacing.setEnabled(True)
        obj.form.spacing.setText(str(vobj.Object.TrueSpacing))
    #obj.form.PickSelectedFace.setVisible(False)
    FreeCADGui.Control.showDialog(obj)

def CommandStirrup():
    selected_obj = check_selected_face()
    if selected_obj:
        FreeCADGui.Control.showDialog(_StirrupTaskPanel())
Please review and suggest changes, if any.

Regards,
Hi @Suraj,

Here it is difficult to review your code. You may create a PR to https://github.com/amrit3701/FreeCAD-Re ... ree/gsoc19. I have created a new branch `gsoc19` where you send PR related to GSoC.
Amritpal Singh
Github, Like my work, sponsor me!
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Automate Reinforcement GSoC proposal

Post by chakkree »

Test "singleTieColumn1Reinforcement" in simple structure.

TestRebar_in_Column_01.png
TestRebar_in_Column_01.png (492.65 KiB) Viewed 2350 times
TestRebar_in_Column_02.png
TestRebar_in_Column_02.png (474.13 KiB) Viewed 2345 times

Code: Select all

"""
  
  16 เมย 2562 / 16 Apr 2019
    Version: 0.19.16267 (Git)
    Python version: 3.6.6
"""
import FreeCAD
import Arch , Draft
import Part


from FreeCAD import Vector
from math import radians

xList = [-2000,2000]
yList = [-2000,2000]

def cretePomYam01(): # GuardHouse
    # Footing
    B = 1000 ; L = 1000; t = 300
    z = -1000
    count=1
    for x in xList:
        for y in yList:
            Rect = Draft.makeRectangle(L , B)
            Rect.Placement.Base = Vector(-L/2, -B/2 , 0)
            F1 = Arch.makeStructure(Rect, height=t, name="Footing"+str(count))
            F1.Placement.Base = Vector(x, y , z)
            F1.ViewObject.Transparency = 80
            F1.IfcRole = "Footing"
            count+=1
    # Pier
    b = 200; t = 200; h = 500+1000-300
    z = -1000+300
    count=1
    for x in xList:
        for y in yList:
            Rect = Draft.makeRectangle(t , b)
            Rect.Placement.Base = Vector(-b/2, -t/2 , 0)
            C1 = Arch.makeStructure(Rect, height=h, name="Pier"+str(count))
            C1.Placement.Base = Vector(x, y , z)
            C1.ViewObject.Transparency = 80
            C1.IfcRole = "Column"
            count+=1
    # Column
    b = 200; t = 200; h = 3000
    z = 500
    count=1
    for x in xList:
        for y in yList:
            Rect = Draft.makeRectangle(t , b)
            Rect.Placement.Base = Vector(-b/2, -t/2 , 0)
            C1 = Arch.makeStructure(Rect, height=h, name="Column"+str(count))
            C1.Placement.Base = Vector(x, y , z)
            C1.ViewObject.Transparency = 80
            C1.IfcRole = "Column"
            count+=1
    # Beam Floor1
    b = 200; h = 400; L = 4000-200
    z = 500-h/2
    B1 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="Beam1")
    B1.Placement.Base = Vector(xList[0]+100, yList[0] , z)
    B1.IfcRole = "Beam"
    B1.ViewObject.Transparency = 80
    
    B2 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="Beam2")
    B2.Placement.Base = Vector(xList[0], yList[0]+100 , z)
    B2.Placement.Rotation.Angle = radians(90)
    B2.IfcRole = "Beam"
    B2.ViewObject.Transparency = 80
    
    B3 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="Beam3")
    B3.Placement.Base = Vector(xList[0]+100, yList[1] , z)
    B3.IfcRole = "Beam"
    B3.ViewObject.Transparency = 80
    
    B4 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="Beam4")
    B4.Placement.Base = Vector(xList[1], yList[0]+100 , z)
    B4.Placement.Rotation.Angle = radians(90)
    B4.IfcRole = "Beam"
    B4.ViewObject.Transparency = 80
    # Roof Beam 
    b = 200; h = 400; L = 4000-200
    z = 3500-h/2
    RB1 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="RoofBeam1")
    RB1.Placement.Base = Vector(xList[0]+100, yList[0] , z)
    RB1.IfcRole = "Beam"
    RB1.ViewObject.Transparency = 80
    
    RB2 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="RoofBeam2")
    RB2.Placement.Base = Vector(xList[0], yList[0]+100 , z)
    RB2.Placement.Rotation.Angle = radians(90)
    RB2.IfcRole = "Beam"
    RB2.ViewObject.Transparency = 80
    
    RB3 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="RoofBeam3")
    RB3.Placement.Base = Vector(xList[0]+100, yList[1] , z)
    RB3.IfcRole = "Beam"
    RB3.ViewObject.Transparency = 80
    
    RB4 = Arch.makeStructure(baseobj=None, length=L, width=b,height=h, name="RoofBeam4")
    RB4.Placement.Base = Vector(xList[1], yList[0]+100 , z)
    RB4.Placement.Rotation.Angle = radians(90)
    RB4.IfcRole = "Beam"
    RB4.ViewObject.Transparency = 80
    
    # Rebar
    #return  # move remark if create only structures
    FreeCAD.ActiveDocument.recompute()
    from ColumnReinforcement import SingleTie
    for i in range(0,4):
        SingleTie.singleTieColumn1Reinforcement(25,25, 50, 
            135,4,6, False , 175 , 12 , 50 , 20 ,
            structure=FreeCAD.ActiveDocument.getObjectsByLabel("Column"+str(i+1))[0])
        SingleTie.singleTieColumn1Reinforcement(25+12/2, 25+12/2, 50, 
            135,4,6, False , 175 , 12 , -500 , -250 ,
            structure=FreeCAD.ActiveDocument.getObjectsByLabel("Pier"+str(i+1))[0])

if __name__=="__main__":
    FreeCAD.newDocument()
    cretePomYam01()
    
    FreeCAD.ActiveDocument.recompute()
    
    Msg("Done!\n\n")
User avatar
Suraj Dadral
Posts: 307
Joined: Fri Sep 07, 2018 5:32 pm
Contact:

Re: Automate Reinforcement GSoC proposal

Post by Suraj Dadral »

I updated the code to rotate stirrups with structures and related commit can be found here:
https://github.com/SurajDadral/FreeCAD- ... b8ba2eb96b

Code snippet:

Code: Select all

structureAngle = math.degrees(structure.Placement.Rotation.Angle)
structureAngle = structureAngle % 360
if 30 < structureAngle < 150 or 210 < structureAngle <= 330:
    wireAngle = structureAngle - 90
else:
    wireAngle = structureAngle
line.Placement.Rotation.Angle = math.radians(wireAngle)
Regards
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Automate Reinforcement GSoC proposal

Post by chakkree »

If use DWire for the base of Rebar, I attach DWire to face of structure object and hack some line in ArchRebar.py.
Rebar will be move and rotate with a host like a sketcher attach to the face of the structure.

look at this topic, DWire as rebar's base

TestRebar_in_Column_WithRotation_03.png
TestRebar_in_Column_WithRotation_03.png (476.79 KiB) Viewed 2301 times
TestRebar_in_Column_WithRotation_04.png
TestRebar_in_Column_WithRotation_04.png (560.46 KiB) Viewed 2258 times

ArchRebar.py hacked at line# #541 and #555 with "rotation = FreeCAD.Rotation() # Fixed rotation" (set to zero reference to attached plane)
ArchRebar.py
(26.1 KiB) Downloaded 68 times
TestRotateColumn_01.FCStd
(45.02 KiB) Downloaded 67 times
User avatar
Suraj Dadral
Posts: 307
Joined: Fri Sep 07, 2018 5:32 pm
Contact:

Re: Automate Reinforcement GSoC proposal

Post by Suraj Dadral »

chakkree wrote: Tue Apr 16, 2019 4:59 pm If use DWire for the base of Rebar, I attach DWire to face of structure object and hack some line in ArchRebar.py.
Rebar will be move and rotate with a host like a sketcher attach to the face of the structure.
Hi @chakkree

Attaching DWire to face of structure moves and rotate Stirrups with structure. And it works for me without doing any changes to ArchRebar.py

Do I add appropriate code for this in Stirrups.py file of RebarAddon.

Regards
User avatar
Suraj Dadral
Posts: 307
Joined: Fri Sep 07, 2018 5:32 pm
Contact:

Re: Automate Reinforcement GSoC proposal

Post by Suraj Dadral »

In same column,
- Firstly, I created Stirrups by selecting "Face6" of column. Then set "MapMode" to "FlatFace". It moves stirrups out of structure as in below image:

Stirrup1.png
Stirrup1.png (33.02 KiB) Viewed 2228 times
Column.FCStd
(17.98 KiB) Downloaded 63 times

- After that I created Stirrups by selecting "Face5", which is opposite to Face6, and then set "MapMode" to "FlatFace". Now, there is no such problem as above.

Is there anything I am doing wrong?

Regards,
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Automate Reinforcement GSoC proposal

Post by chakkree »

Suraj Dadral wrote: Wed Apr 17, 2019 7:46 pm In same column,
- Firstly, I created Stirrups by selecting "Face6" of column. Then set "MapMode" to "FlatFace". It moves stirrups out of structure as in below image:


Stirrup.png
Relatd FreeCAD File: Column.FCStd


- After that I created Stirrups by selecting "Face5", which is opposite to Face6, and then set "MapMode" to "FlatFace". Now, there is no such problem as above.

Is there anything I am doing wrong?

Regards,
BaseWire_Elevation.png
BaseWire_Elevation.png (150.96 KiB) Viewed 2195 times
When you create DWire, set elevation(z) to zero when you attach DWire to the selecting face. DWire will set selecting face to the reference point.
User avatar
Suraj Dadral
Posts: 307
Joined: Fri Sep 07, 2018 5:32 pm
Contact:

Re: Automate Reinforcement GSoC proposal

Post by Suraj Dadral »

chakkree wrote: Thu Apr 18, 2019 6:17 am When you create DWire, set elevation(z) to zero when you attach DWire to the selecting face. DWire will set selecting face to the reference point.
Is there any property named 'elevation' of DWire?
Or you are pointing to setting Position of DWire using command:

Code: Select all

FreeCAD.ActiveDocument.Wire.Placement.Base.z=0
But using this command is not working for me as shown by following sequence of commands:

Code: Select all

>>> FreeCAD.ActiveDocument.Wire.Placement.Base.z
1000.0
>>> FreeCAD.ActiveDocument.Wire.Placement.Base.z = 0.0
>>> FreeCAD.ActiveDocument.Wire.Placement.Base.z
0.0
>>> FreeCAD.ActiveDocument.recompute()
2
>>> FreeCAD.ActiveDocument.Wire.Placement.Base.z
1000.0
>>> 
What works for me is this:

Code: Select all

>>> FreeCAD.ActiveDocument.Wire.Placement.Base.z
1000.0
>>> FreeCAD.ActiveDocument.Wire.AttachmentOffset.Base
Vector (0.0, 0.0, 0.0)
>>> FreeCAD.ActiveDocument.Wire.AttachmentOffset.Base.z=-1000
>>> FreeCAD.ActiveDocument.Wire.AttachmentOffset.Base
Vector (0.0, 0.0, -1000.0)
>>> FreeCAD.ActiveDocument.recompute()
2
>>> FreeCAD.ActiveDocument.Wire.AttachmentOffset.Base
Vector (0.0, 0.0, -1000.0)
>>> FreeCAD.ActiveDocument.Wire.Placement.Base.z
0.0
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Automate Reinforcement GSoC proposal

Post by chakkree »

Sorry!, I mean to say z in a coordinate vector of DWire.
Beam_Rebar_Based_DWire_01.png
Beam_Rebar_Based_DWire_01.png (67.51 KiB) Viewed 2167 times

Code: Select all

"""
    18 Apr 2019

    Version: 0.19.16488 (Git)
    Python version: 3.6.6

"""
import FreeCAD
import Arch
import Draft
from FreeCAD import Vector

concrete = FreeCAD.ActiveDocument.addObject("Part::Box","concrete")
concrete.Length = 3800
concrete.Width = 200
concrete.Height = 400
concrete.Placement.Base = Vector(0,-100,-400)
beam = Arch.makeStructure(concrete)
beam.Placement.Base.y += 2000
beam.Placement.Base.z += 300
beam.ViewObject.Transparency = 80

# rebar
db = 12.
A = 3*db+12*db
B = 3800-25*2-12/2*2
coors = []
coors.append( Vector(0,-A,0.) )
coors.append( Vector(0,0,0.) )
coors.append( Vector(B,0,0.) )
coors.append( Vector(B,-A,0.) )
line = Draft.makeWire(coors,closed=False,face=False,support=None) 
line.Support = [beam , 'Face3']
line.MapMode = 'FlatFace'
line.AttachmentOffset.Base.x = 25+12/2
line.AttachmentOffset.Base.y = -25-12/2

dia = 12
covering = 25
dirStir = 6
rebar1 = Arch.makeRebar(beam, line, dia , 2 , covering+dirStir+dia/2)
rebar1.Rounding = 2.0

FreeCAD.ActiveDocument.recompute()



User avatar
Suraj Dadral
Posts: 307
Joined: Fri Sep 07, 2018 5:32 pm
Contact:

Re: Automate Reinforcement GSoC proposal

Post by Suraj Dadral »

Now Stirrups rotate properly with column. I added following code snippet to file Stirrups.py of RebarAddon:

Code: Select all

if structure.IfcRole == "Column":
    line.MapMode = "FlatFace"
    elevation = line.Placement.Base.z
    if elevation is not 0:
        line.AttachmentOffset.Base.z -= elevation
And git commit is here:
https://github.com/SurajDadral/FreeCAD- ... 4f2ccec357

Regards,
Post Reply