def __init__(self, Rebar=None):
     self.form = FreeCADGui.PySideUic.loadUi(
         os.path.splitext(__file__)[0] + ".ui")
     self.form.setWindowTitle(
         QtGui.QApplication.translate("Arch", "Helical Rebar", None))
     if not Rebar:
         normal = facenormalDirection()
     else:
         normal = facenormalDirection(Rebar.Base.Support[0][0],
                                      Rebar.Base.Support[0][1][0])
     if not round(normal.z) in {1, -1}:
         self.form.topCoverLabel.setText(
             translate("RebarAddon", "Left Cover"))
         self.form.bottomCoverLabel.setText(
             translate("RebarAddon", "Right Cover"))
     self.form.PickSelectedFace.clicked.connect(self.getSelectedFace)
     self.form.image.setPixmap(
         QtGui.QPixmap(
             os.path.split(os.path.abspath(__file__))[0] +
             "/icons/HelicalRebar.svg"))
     self.form.toolButton.clicked.connect(lambda: showPopUpImageDialog(
         os.path.split(os.path.abspath(__file__))[0] +
         "/icons/HelicalRebarDetailed.svg"))
     # self.form.toolButton.setIcon(
     #     self.form.toolButton.style().standardIcon(
     #         QtGui.QStyle.SP_DialogHelpButton
     #     )
     # )
     self.Rebar = Rebar
     self.SelectedObj = None
     self.FaceName = None
 def getSelectedFace(self):
     getSelectedFace(self)
     normal = facenormalDirection()
     if not round(normal.z) in {1, -1}:
         self.form.topCoverLabel.setText(
             translate("RebarAddon", "Left Cover"))
         self.form.bottomCoverLabel.setText(
             translate("RebarAddon", "Right Cover"))
     else:
         self.form.topCoverLabel.setText(
             translate("RebarAddon", "Top Cover"))
         self.form.bottomCoverLabel.setText(
             translate("RebarAddon", "Bottom Cover"))
Ejemplo n.º 3
0
def editStraightRebar(
    Rebar,
    f_cover,
    coverAlong,
    rt_cover,
    lb_cover,
    diameter,
    amount_spacing_check,
    amount_spacing_value,
    orientation,
    structure=None,
    facename=None,
):
    sketch = Rebar.Base
    if structure and facename:
        sketch.Support = [(structure, facename)]
        FreeCAD.ActiveDocument.recompute()
    # Check if sketch support is empty.
    if not sketch.Support:
        showWarning(
            "You have checked: 'Remove external geometry of base sketches when "
            "needed.'\nTo uncheck: 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)
    # Get points of Straight rebar
    points = getpointsOfStraightRebar(
        FacePRM,
        rt_cover,
        lb_cover,
        coverAlong,
        orientation,
        diameter,
        facenormalDirection(structure, facename),
    )
    sketch.movePoint(0, 1, points[0], 0)
    FreeCAD.ActiveDocument.recompute()
    sketch.movePoint(0, 2, points[1], 0)
    FreeCAD.ActiveDocument.recompute()
    Rebar.OffsetStart = f_cover + diameter / 2
    Rebar.OffsetEnd = f_cover + diameter / 2
    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 = get_rebar_amount_from_spacing(size, diameter,
                                                     amount_spacing_value)
        FreeCAD.ActiveDocument.recompute()
        Rebar.AmountCheck = False
    Rebar.FrontCover = f_cover
    Rebar.RightTopCover = rt_cover
    Rebar.LeftBottomCover = lb_cover
    Rebar.CoverAlong = coverAlong[0]
    Rebar.Cover = coverAlong[1]
    Rebar.TrueSpacing = amount_spacing_value
    Rebar.Diameter = diameter
    Rebar.Orientation = orientation
    FreeCAD.ActiveDocument.recompute()
    return Rebar
Ejemplo n.º 4
0
def makeStraightRebar(
    f_cover,
    coverAlong,
    rt_cover,
    lb_cover,
    diameter,
    amount_spacing_check,
    amount_spacing_value,
    orientation="Horizontal",
    structure=None,
    facename=None,
):
    """Adds the straight reinforcement bar to the selected structural object.

    Case I: When orientation of straight rebar is 'Horizontal':
        makeStraightRebar(FrontCover, CoverAlong, RightCover, LeftCover,
        Diameter, AmountSpacingCheck, AmountSpacingValue, Orientation =
        "Horizontal", Structure, Facename)
        Note: Type of CoverAlong argument is a tuple. Syntax: (<Along>,
        <Value>). Here we have horizontal orientation so we can pass Top Side
        and Bottom Side to <Along> arguments.
        For eg. ("Top Side", 20) and ("Bottom Side", 20)

    Case II: When orientation of straight rebar is 'Vertical':
        makeStraightRebar(FrontCover, CoverAlong, TopCover, BottomCover,
        Diameter, AmountSpacingCheck, AmountSpacingValue, Orientation =
        "Horizontal", Structure, Facename)
        Note: Type of CoverAlong argument is a tuple. Syntax: (<Along>,
        <Value>). Here we have vertical orientation so we can pass Left Side
        and Right Side to <Along> arguments.
        For eg. ("Left Side", 20) and ("Right Side", 20)
    """
    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)
    if not FacePRM:
        FreeCAD.Console.PrintError(
            "Cannot identify shape or from which base object structural "
            "element is derived\n")
        return
    # Get points of Straight rebar
    points = getpointsOfStraightRebar(
        FacePRM,
        rt_cover,
        lb_cover,
        coverAlong,
        orientation,
        diameter,
        facenormalDirection(structure, facename),
    )
    import Part
    import Arch

    sketch = FreeCAD.activeDocument().addObject("Sketcher::SketchObject",
                                                "Sketch")
    sketch.MapMode = "FlatFace"
    sketch.Support = [(structure, facename)]
    FreeCAD.ActiveDocument.recompute()
    sketch.addGeometry(Part.LineSegment(points[0], points[1]), False)
    if amount_spacing_check:
        rebar = Arch.makeRebar(
            structure,
            sketch,
            diameter,
            amount_spacing_value,
            f_cover + diameter / 2,
            name="StraightRebar",
        )
        FreeCAD.ActiveDocument.recompute()
    else:
        size = (ArchCommands.projectToVector(structure.Shape.copy(),
                                             face.normalAt(0, 0))).Length
        rebar = Arch.makeRebar(
            structure,
            sketch,
            diameter,
            get_rebar_amount_from_spacing(size, diameter,
                                          amount_spacing_value),
            f_cover + diameter / 2,
            name="StraightRebar",
        )
    # Adds properties to the rebar object
    rebar.addProperty(
        "App::PropertyEnumeration",
        "RebarShape",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
    ).RebarShape = RebarTypes.tolist()
    rebar.RebarShape = "StraightRebar"
    rebar.setEditorMode("RebarShape", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "FrontCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Front cover of rebar"),
    ).FrontCover = f_cover
    rebar.setEditorMode("FrontCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "RightTopCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Right/Top Side cover of rebar"),
    ).RightTopCover = rt_cover
    rebar.setEditorMode("RightTopCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "LeftBottomCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Left/Bottom Side cover of rebar"),
    ).LeftBottomCover = lb_cover
    rebar.setEditorMode("LeftBottomCover", 2)
    rebar.addProperty(
        "App::PropertyString",
        "CoverAlong",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Cover along"),
    ).CoverAlong = coverAlong[0]
    rebar.setEditorMode("CoverAlong", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "Cover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property",
                          "Cover of rebar along user selected side"),
    ).Cover = coverAlong[1]
    rebar.setEditorMode("Cover", 2)
    rebar.addProperty(
        "App::PropertyBool",
        "AmountCheck",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Amount radio button is checked"),
    )
    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)
    rebar.addProperty(
        "App::PropertyString",
        "Orientation",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
    ).Orientation = orientation
    rebar.setEditorMode("Orientation", 2)
    if amount_spacing_check:
        rebar.AmountCheck = True
    else:
        rebar.AmountCheck = False
        rebar.TrueSpacing = amount_spacing_value
    FreeCAD.ActiveDocument.recompute()
    return rebar
def makeBentShapeRebar(
    f_cover,
    b_cover,
    l_cover,
    r_cover,
    diameter,
    t_cover,
    bentLength,
    bentAngle,
    rounding,
    amount_spacing_check,
    amount_spacing_value,
    orientation="Bottom Left",
    structure=None,
    facename=None,
):
    """makeBentShapeRebar(FrontCover, BottomCover, LeftCover, RightCover,
    Diameter, TopCover, BentLength, BentAngle, Rounding, AmountSpacingCheck,
    AmountSpacingValue, Orientation, Structure, Facename):
    Adds the Bent-Shape reinforcement bar to the selected structural object.

    It takes four different orientations input i.e. 'Bottom', 'Top', 'Left',
    'Right'.
    """
    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)
    if not FacePRM:
        FreeCAD.Console.PrintError(
            "Cannot identify shape or from which base object structural "
            "element is derived\n")
        return
    # Get points of L-Shape rebar
    points = getpointsOfBentShapeRebar(
        FacePRM,
        l_cover,
        r_cover,
        b_cover,
        t_cover,
        bentLength,
        bentAngle,
        orientation,
        diameter,
        facenormalDirection(structure, facename),
    )
    import Part
    import Arch

    sketch = FreeCAD.activeDocument().addObject("Sketcher::SketchObject",
                                                "Sketch")
    sketch.MapMode = "FlatFace"
    sketch.Support = [(structure, facename)]
    FreeCAD.ActiveDocument.recompute()
    sketch.addGeometry(Part.LineSegment(points[0], points[1]), False)
    sketch.addGeometry(Part.LineSegment(points[1], points[2]), False)
    sketch.addGeometry(Part.LineSegment(points[2], points[3]), False)
    sketch.addGeometry(Part.LineSegment(points[3], points[4]), False)
    sketch.addGeometry(Part.LineSegment(points[4], points[5]), False)

    if amount_spacing_check:
        rebar = Arch.makeRebar(
            structure,
            sketch,
            diameter,
            amount_spacing_value,
            f_cover + diameter / 2,
            name="BentShapeRebar",
        )
        FreeCAD.ActiveDocument.recompute()
    else:
        size = (ArchCommands.projectToVector(structure.Shape.copy(),
                                             face.normalAt(0, 0))).Length
        rebar = Arch.makeRebar(
            structure,
            sketch,
            diameter,
            get_rebar_amount_from_spacing(size, diameter,
                                          amount_spacing_value),
            f_cover + diameter / 2,
            name="BentShapeRebar",
        )
    rebar.Rounding = rounding
    # Adds properties to the rebar object
    rebar.addProperty(
        "App::PropertyEnumeration",
        "RebarShape",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
    ).RebarShape = RebarTypes.tolist()
    rebar.RebarShape = "BentShapeRebar"
    rebar.setEditorMode("RebarShape", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "FrontCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Front cover of rebar"),
    ).FrontCover = f_cover
    rebar.setEditorMode("FrontCover", 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",
        "BottomCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Bottom cover of rebar"),
    ).BottomCover = b_cover
    rebar.setEditorMode("BottomCover", 2)
    rebar.addProperty(
        "App::PropertyBool",
        "AmountCheck",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Amount radio button is checked"),
    )
    rebar.setEditorMode("AmountCheck", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "TopCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Top cover of rebar"),
    ).TopCover = t_cover
    rebar.setEditorMode("TopCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "TrueSpacing",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Spacing between of rebars"),
    ).TrueSpacing = amount_spacing_value
    rebar.addProperty(
        "App::PropertyString",
        "Orientation",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
    ).Orientation = orientation
    rebar.setEditorMode("Orientation", 2)
    rebar.setEditorMode("TrueSpacing", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "BentLength",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "BentLength cover of rebar"),
    ).BentLength = bentLength
    rebar.setEditorMode("BentLength", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "BentAngle",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Bent Angle of rebar"),
    ).BentAngle = bentAngle
    rebar.setEditorMode("BentAngle", 2)

    if amount_spacing_check:
        rebar.AmountCheck = True
    else:
        rebar.AmountCheck = False
        rebar.TrueSpacing = amount_spacing_value
    FreeCAD.ActiveDocument.recompute()
    return rebar
def editLShapeRebar(
    Rebar,
    f_cover,
    b_cover,
    l_cover,
    r_cover,
    diameter,
    t_cover,
    rounding,
    amount_spacing_check,
    amount_spacing_value,
    orientation,
    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 sketches when "
            "needed.'\nTo uncheck: Edit->Preferences->Arch.")
        return
    # Recompute sketch to resolve issue as discussed here:
    # https://forum.freecadweb.org/viewtopic.php?f=3&t=6989#p335986
    sketch.recompute()
    # 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)
    # Get points of L-Shape rebar
    points = getpointsOfLShapeRebar(
        FacePRM,
        l_cover,
        r_cover,
        b_cover,
        t_cover,
        orientation,
        diameter,
        facenormalDirection(structure, facename),
    )
    sketch.movePoint(0, 1, points[0], 0)
    FreeCAD.ActiveDocument.recompute()
    sketch.movePoint(0, 2, points[1], 0)
    FreeCAD.ActiveDocument.recompute()
    sketch.movePoint(1, 1, points[1], 0)
    FreeCAD.ActiveDocument.recompute()
    sketch.movePoint(1, 2, points[2], 0)
    FreeCAD.ActiveDocument.recompute()
    Rebar.OffsetStart = f_cover + diameter / 2
    Rebar.OffsetEnd = f_cover + diameter / 2
    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.Diameter = diameter
    Rebar.FrontCover = f_cover
    Rebar.LeftCover = l_cover
    Rebar.RightCover = r_cover
    Rebar.BottomCover = b_cover
    Rebar.TopCover = t_cover
    Rebar.Rounding = rounding
    Rebar.TrueSpacing = amount_spacing_value
    Rebar.Orientation = orientation
    FreeCAD.ActiveDocument.recompute()
    return Rebar