Esempio n. 1
0
def editSingleTieMultipleRebars(
    rebar_group,
    l_cover_of_tie,
    r_cover_of_tie,
    t_cover_of_tie,
    b_cover_of_tie,
    offset_of_tie,
    bent_angle,
    extension_factor,
    dia_of_tie,
    number_spacing_check,
    number_spacing_value,
    dia_of_main_rebars,
    main_rebars_t_offset,
    main_rebars_b_offset,
    main_rebars_type="StraightRebar",
    main_hook_orientation="Top Inside",
    main_hook_extend_along="x-axis",
    l_main_rebar_rounding=None,
    main_hook_extension=None,
    sec_rebars_t_offset=None,
    sec_rebars_b_offset=None,
    sec_rebars_number_diameter=None,
    sec_rebars_type=("StraightRebar", "StraightRebar"),
    sec_hook_orientation=("Top Inside", "Top Inside"),
    l_sec_rebar_rounding=None,
    sec_hook_extension=None,
    structure=None,
    facename=None,
):
    """editSingleTieMultipleRebars(RebarGroup, LeftCoverOfTie, RightCoverOfTie,
    TopCoverOfTie, BottomCoverOfTie, OffsetofTie, BentAngle, ExtensionFactor,
    DiameterOfTie, NumberSpacingCheck, NumberSpacingValue, DiameterOfMainRebars,
    TopOffsetofMainRebars, BottomOffsetofMainRebars, MainRebarType,
    MainLShapeHookOrientation, MainLShapeHookExtendAlong,
    LShapeMainRebarRounding, LShapeMainHookLength, TopOffsetofSecondaryRebars,
    BottomOffsetofSecondaryRebars, SecondaryRebarNumberDiameterString,
    SecondaryRebarType, SecondaryLShapeHookOrientation,
    LShapeSecondaryRebarRounding, LShapeSecondaryHookLength, Structure,
    Facename):
    Edit the Single Tie Multiple Rebars reinforcement for the selected
    structural column object.

    It takes two different inputs for main_rebars_type i.e. 'StraightRebar',
    'LShapeRebar'.

    It takes eight different orientations input for Main L-shaped hooks i.e.
    'Top Inside', 'Top Outside', 'Bottom Inside', 'Bottom Outside', 'Top Left',
    'Top Right', 'Bottom Left', 'Bottom Right'.

    It takes two different inputs for main_hook_extend_along i.e. 'x-axis',
    'y-axis'.

    Note: Type of sec_rebars_t_offset, sec_rebars_b_offset,
    sec_rebars_number_diameter, sec_rebars_type, sec_hook_orientation,
    l_sec_rebar_rounding and sec_hook_extension arguments is a tuple.
    Syntax: (<value_for_xdir_rebars>, <value_for_ydir_rebars>).

    In sec_hook_orientation(<xdir_rebars_orientation>,
    <ydir_rebars_orientation>),
    Value of xdir_rebars_orientation can be: 'Top Inside', 'Top Outside',
    'Bottom Inside', 'Bottom Outside', 'Top Upward', 'Top Downward', 'Bottom
    Upward', 'Bottom Downward'.
    Value of ydir_rebars_orientation can be: 'Top Inside', 'Top Outside',
    'Bottom Inside', 'Bottom Outside', 'Top Left', 'Top Right', 'Bottom
    Left', 'Bottom Right'.
    """
    if len(rebar_group.RebarGroups) == 0:
        return rebar_group
    for i, tmp_rebar_group in enumerate(rebar_group.RebarGroups):
        if hasattr(tmp_rebar_group, "Ties"):
            if len(tmp_rebar_group.Ties) > 0:
                Tie = tmp_rebar_group.Ties[0]
                break
            else:
                showWarning(
                    "You have deleted ties. Please recreate the "
                    "ColumnReinforcement."
                )
                return rebar_group
        elif i == len(rebar_group.RebarGroups) - 1:
            showWarning(
                "You have deleted ties group. Please recreate the "
                "ColumnReinforcement."
            )
            return rebar_group

    if not structure and not facename:
        structure = Tie.Base.Support[0][0]
        facename = Tie.Base.Support[0][1][0]

    # Edit ties and main rebars
    editSingleTieFourRebars(
        rebar_group,
        l_cover_of_tie,
        r_cover_of_tie,
        t_cover_of_tie,
        b_cover_of_tie,
        offset_of_tie,
        bent_angle,
        extension_factor,
        dia_of_tie,
        number_spacing_check,
        number_spacing_value,
        dia_of_main_rebars,
        main_rebars_t_offset,
        main_rebars_b_offset,
        main_rebars_type,
        main_hook_orientation,
        main_hook_extend_along,
        l_main_rebar_rounding,
        main_hook_extension,
        structure,
        facename,
    )

    # If secondary rebars doesn't exists, return
    if len(rebar_group.RebarGroups) < 3:
        FreeCAD.ActiveDocument.recompute()
        return rebar_group

    # Set parameters for xdir and ydir rebars
    xdir_rebars_group = rebar_group.RebarGroups[2].SecondaryRebars[0]
    ydir_rebars_group = rebar_group.RebarGroups[2].SecondaryRebars[1]
    if not sec_rebars_t_offset:
        xdir_rebars_t_offset = xdir_rebars_group.TopOffset
        ydir_rebars_t_offset = ydir_rebars_group.TopOffset
    else:
        xdir_rebars_t_offset = sec_rebars_t_offset[0]
        ydir_rebars_t_offset = sec_rebars_t_offset[1]
    if not sec_rebars_b_offset:
        xdir_rebars_b_offset = xdir_rebars_group.BottomOffset
        ydir_rebars_b_offset = ydir_rebars_group.BottomOffset
    else:
        xdir_rebars_b_offset = sec_rebars_b_offset[0]
        ydir_rebars_b_offset = sec_rebars_b_offset[1]
    if not sec_rebars_number_diameter:
        xdir_rebars_number_diameter = xdir_rebars_group.NumberDiameter
        ydir_rebars_number_diameter = ydir_rebars_group.NumberDiameter
    else:
        xdir_rebars_number_diameter = sec_rebars_number_diameter[0]
        ydir_rebars_number_diameter = sec_rebars_number_diameter[1]

    xdir_rebars_type = sec_rebars_type[0]
    ydir_rebars_type = sec_rebars_type[1]
    xdir_hook_orientation = sec_hook_orientation[0]
    ydir_hook_orientation = sec_hook_orientation[1]
    if l_sec_rebar_rounding:
        l_xdir_rebar_rounding = l_sec_rebar_rounding[0]
        l_ydir_rebar_rounding = l_sec_rebar_rounding[1]
    if sec_hook_extension:
        xdir_hook_extension = sec_hook_extension[0]
        ydir_hook_extension = sec_hook_extension[1]

    # Set common parameters of xdir and ydir rebars
    xdir_rebars = xdir_rebars_group.XDirRebars
    ydir_rebars = ydir_rebars_group.YDirRebars

    # Check if there is need to recreate rebars
    prev_xdir_rebars_type = xdir_rebars_group.RebarType
    prev_xdir_rebars_number_diameter = xdir_rebars_group.NumberDiameter
    prev_ydir_rebars_type = ydir_rebars_group.RebarType
    prev_ydir_rebars_number_diameter = ydir_rebars_group.NumberDiameter
    if (
        prev_xdir_rebars_type == xdir_rebars_type
        and prev_xdir_rebars_number_diameter == xdir_rebars_number_diameter
    ):
        recreate_xdir_rebars = False
    else:
        recreate_xdir_rebars = True
    if (
        prev_ydir_rebars_type == ydir_rebars_type
        and prev_ydir_rebars_number_diameter == ydir_rebars_number_diameter
    ):
        recreate_ydir_rebars = False
    else:
        recreate_ydir_rebars = True

    if recreate_xdir_rebars:
        for Rebar in xdir_rebars:
            base_name = Rebar.Base.Name
            FreeCAD.ActiveDocument.removeObject(Rebar.Name)
            FreeCAD.ActiveDocument.removeObject(base_name)
        FreeCAD.ActiveDocument.recompute()

        if xdir_rebars_number_diameter and xdir_rebars_number_diameter != "0":
            xdir_rebars = makeXDirRebars(
                l_cover_of_tie,
                r_cover_of_tie,
                t_cover_of_tie,
                b_cover_of_tie,
                dia_of_tie,
                dia_of_main_rebars,
                xdir_rebars_t_offset,
                xdir_rebars_b_offset,
                xdir_rebars_type,
                xdir_hook_orientation,
                xdir_hook_extension,
                l_xdir_rebar_rounding,
                xdir_rebars_number_diameter,
                facename,
                structure,
            )
    else:
        editXDirRebars(
            xdir_rebars,
            l_cover_of_tie,
            r_cover_of_tie,
            t_cover_of_tie,
            b_cover_of_tie,
            dia_of_tie,
            dia_of_main_rebars,
            xdir_rebars_t_offset,
            xdir_rebars_b_offset,
            xdir_rebars_type,
            xdir_hook_orientation,
            xdir_hook_extension,
            l_xdir_rebar_rounding,
            xdir_rebars_number_diameter,
            facename,
            structure,
        )

    if recreate_ydir_rebars:
        for Rebar in ydir_rebars:
            base_name = Rebar.Base.Name
            FreeCAD.ActiveDocument.removeObject(Rebar.Name)
            FreeCAD.ActiveDocument.removeObject(base_name)
        FreeCAD.ActiveDocument.recompute()

        if ydir_rebars_number_diameter and ydir_rebars_number_diameter != "0":
            ydir_rebars = makeYDirRebars(
                l_cover_of_tie,
                r_cover_of_tie,
                t_cover_of_tie,
                b_cover_of_tie,
                dia_of_tie,
                dia_of_main_rebars,
                ydir_rebars_t_offset,
                ydir_rebars_b_offset,
                ydir_rebars_type,
                ydir_hook_orientation,
                ydir_hook_extension,
                l_ydir_rebar_rounding,
                ydir_rebars_number_diameter,
                facename,
                structure,
            )
    else:
        editYDirRebars(
            ydir_rebars,
            l_cover_of_tie,
            r_cover_of_tie,
            t_cover_of_tie,
            b_cover_of_tie,
            dia_of_tie,
            dia_of_main_rebars,
            ydir_rebars_t_offset,
            ydir_rebars_b_offset,
            ydir_rebars_type,
            ydir_hook_orientation,
            ydir_hook_extension,
            l_ydir_rebar_rounding,
            ydir_rebars_number_diameter,
            facename,
            structure,
        )

    # Add created xdir/ydir rebars to xdir_rebars_group/ydir_rebars_group
    xdir_rebars_group.addObjects(xdir_rebars)
    ydir_rebars_group.addObjects(ydir_rebars)

    # Set properties values for xdir_rebars in  xdir_rebars_group object
    xdir_rebars_group.XDirRebars = xdir_rebars
    xdir_rebars_group.RebarType = xdir_rebars_type
    if xdir_rebars_type == "LShapeRebar":
        xdir_rebars_group.HookOrientation = xdir_hook_orientation
        xdir_rebars_group.HookExtension = xdir_hook_extension
    xdir_rebars_group.TopOffset = xdir_rebars_t_offset
    xdir_rebars_group.BottomOffset = xdir_rebars_b_offset
    xdir_rebars_group.NumberDiameter = xdir_rebars_number_diameter

    # Set properties values for ydir_rebars in  ydir_rebars_group object
    ydir_rebars_group.YDirRebars = ydir_rebars
    ydir_rebars_group.RebarType = ydir_rebars_type
    if ydir_rebars_type == "LShapeRebar":
        ydir_rebars_group.HookOrientation = ydir_hook_orientation
        ydir_rebars_group.HookExtension = ydir_hook_extension
    ydir_rebars_group.TopOffset = ydir_rebars_t_offset
    ydir_rebars_group.BottomOffset = ydir_rebars_b_offset
    ydir_rebars_group.NumberDiameter = ydir_rebars_number_diameter

    FreeCAD.ActiveDocument.recompute()
    return rebar_group
def editTwoTiesSixRebars(
        rebar_group,
        l_cover_of_ties,
        r_cover_of_ties,
        t_cover_of_ties,
        b_cover_of_ties,
        offset_of_ties,
        bent_angle_of_ties,
        extension_factor_of_ties,
        dia_of_ties,
        number_spacing_check,
        number_spacing_value,
        dia_of_main_rebars,
        t_offset_of_rebars,
        b_offset_of_rebars,
        main_rebars_type="StraightRebar",
        hook_orientation="Top Inside",
        hook_extend_along="x-axis",
        l_rebar_rounding=None,
        hook_extension=None,
        ties_sequence=("Tie1", "Tie2"),
        structure=None,
        facename=None,
):
    """editTwoTiesSixRebars(RebarGroup, LeftCoverOfTies, RightCoverOfTies,
    TopCoverOfTies, BottomCoverOfTies, OffsetofTies, BentAngleOfTies,
    ExtensionFactorOfTies, DiameterOfTies, NumberSpacingCheck,
    NumberSpacingValue, DiameterOfMainRebars, TopOffsetOfMainRebars,
    BottomOffsetOfRebars, MainRebarsType, LShapeHookOrientation,
    HookExtendAlong, LShapeRebarRounding, LShapeHookLength, TiesSequence,
    Structure, Facename):
    """
    if len(rebar_group.RebarGroups) == 0:
        return rebar_group
    for i, tmp_rebar_group in enumerate(rebar_group.RebarGroups):
        if hasattr(tmp_rebar_group, "Ties"):
            if len(tmp_rebar_group.Ties) > 0:
                Tie = tmp_rebar_group.Ties[0]
                break
            else:
                showWarning("You have deleted ties. Please recreate the"
                            "ColumnReinforcement.")
                return rebar_group
        elif i == len(rebar_group.RebarGroups) - 1:
            showWarning("You have deleted ties group. Please recreate the"
                        "ColumnReinforcement.")
            return rebar_group

    if not structure and not facename:
        structure = Tie.Base.Support[0][0]
        facename = Tie.Base.Support[0][1][0]

    FacePRM = getParametersOfFace(structure, facename)
    face_length = FacePRM[0][0]

    # Calculate parameters for tie1 and tie2
    if ties_sequence[0] == "Tie2" and ties_sequence[1] == "Tie1":
        start_offset_of_tie1 = offset_of_ties + dia_of_ties + dia_of_ties / 2
        start_offset_of_tie2 = offset_of_ties
        end_offset_of_tie1 = start_offset_of_tie2
        end_offset_of_tie2 = start_offset_of_tie1
    else:
        start_offset_of_tie1 = offset_of_ties
        start_offset_of_tie2 = offset_of_ties + 2 * dia_of_ties
        end_offset_of_tie1 = start_offset_of_tie2
        end_offset_of_tie2 = start_offset_of_tie1
    l_cover_of_tie1 = l_cover_of_ties
    r_cover_of_tie1 = face_length / 2 - dia_of_main_rebars / 2 - dia_of_ties
    l_cover_of_tie2 = r_cover_of_tie1
    r_cover_of_tie2 = r_cover_of_ties

    # Edit tie2
    tie2 = rebar_group.RebarGroups[0].Ties[1]
    rounding = (float(dia_of_ties) / 2 + dia_of_main_rebars / 2) / dia_of_ties
    tie2 = editStirrup(
        tie2,
        l_cover_of_tie2,
        r_cover_of_tie2,
        t_cover_of_ties,
        b_cover_of_ties,
        start_offset_of_tie2,
        bent_angle_of_ties,
        extension_factor_of_ties,
        dia_of_ties,
        rounding,
        number_spacing_check,
        number_spacing_value,
        structure,
        facename,
    )
    tie2.OffsetEnd = end_offset_of_tie2 + dia_of_ties / 2

    main_rebar_group = rebar_group.RebarGroups[1]
    main_rebars = editMainRebars(
        main_rebar_group,
        l_cover_of_ties,
        r_cover_of_ties,
        t_cover_of_ties,
        b_cover_of_ties,
        dia_of_ties,
        dia_of_main_rebars,
        t_offset_of_rebars,
        b_offset_of_rebars,
        main_rebars_type,
        hook_orientation,
        hook_extend_along,
        hook_extension,
        l_rebar_rounding,
        structure,
        facename,
    )

    # Edit SingleTieFourRebars
    rebar_group = editSingleTieFourRebars(
        rebar_group,
        l_cover_of_tie1,
        r_cover_of_tie1,
        t_cover_of_ties,
        b_cover_of_ties,
        start_offset_of_tie1,
        bent_angle_of_ties,
        extension_factor_of_ties,
        dia_of_ties,
        number_spacing_check,
        number_spacing_value,
        dia_of_main_rebars,
        t_offset_of_rebars,
        b_offset_of_rebars,
        main_rebars_type,
        hook_orientation,
        hook_extend_along,
        l_rebar_rounding,
        hook_extension,
        structure,
        facename,
    )
    rebar_group.RebarGroups[0].Ties[0].OffsetEnd = (end_offset_of_tie1 +
                                                    dia_of_ties / 2)

    if main_rebars:
        main_rebar_group.addObjects(main_rebars)
        prev_main_rebars = main_rebar_group.MainRebars
        prev_main_rebars.extend(main_rebars)
        main_rebar_group.MainRebars = prev_main_rebars

    rebar_group.RebarGroups[0].LeftCover = l_cover_of_ties
    rebar_group.RebarGroups[0].RightCover = r_cover_of_ties
    rebar_group.RebarGroups[0].TopCover = t_cover_of_ties
    rebar_group.RebarGroups[0].BottomCover = b_cover_of_ties
    rebar_group.RebarGroups[0].TiesSequence = ties_sequence

    FreeCAD.ActiveDocument.recompute()
    return rebar_group