Exemple #1
0
def getUShapeRebarSVGData(
    rebar,
    view_plane,
    rebars_svg,
    rebars_stroke_width,
    rebars_color_style,
    longitudinal_line_dia=None,
):
    """getUShapeRebarSVGData(UShapeRebar, ViewPlane, RebarsSVG,
    RebarsStrokeWidth, RebarsColorStyle, longitudinal_line_dia):
    Returns dictionary containing UShape rebar svg data.

    rebars_color_style can be:
        - "shape color" to select color of rebar shape
        - color name or hex value of color

    Returns dictionary format:
    {
        "svg": u_rebar_svg,
        "visibility": is_rebar_visible,
    }
    """
    if longitudinal_line_dia is None:
        longitudinal_line_dia = 2 * 2 * rebars_stroke_width

    rebars_color = getRebarColor(rebar, rebars_color_style)

    u_rebar_svg = ElementTree.Element("g", attrib={"id": str(rebar.Name)})
    is_rebar_visible = False
    drawing_plane_normal = view_plane.axis
    if round(drawing_plane_normal.cross(getRebarsSpanAxis(rebar)).Length) == 0:
        basewire = rebar.Base.Shape.Wires[0].copy()
        basewire.Placement = rebar.PlacementList[0].multiply(
            basewire.Placement)
        edges = Part.__sortEdges__(
            DraftGeomUtils.filletWire(
                basewire,
                rebar.Rounding * rebar.Diameter.Value,
            ).Edges)
        for edge in edges:
            if DraftGeomUtils.geomType(edge) == "Line":
                p1 = getProjectionToSVGPlane(edge.Vertexes[0].Point,
                                             view_plane)
                p2 = getProjectionToSVGPlane(edge.Vertexes[1].Point,
                                             view_plane)
                if round(p1.x) == round(p2.x) and round(p1.y) == round(p2.y):
                    edge_svg = getPointSVG(p1,
                                           radius=longitudinal_line_dia / 2,
                                           fill=rebars_color)
                else:
                    edge_svg = getLineSVG(p1, p2, rebars_stroke_width,
                                          rebars_color)
                    if not isLineInSVG(p1, p2, rebars_svg):
                        is_rebar_visible = True
                if is_rebar_visible:
                    u_rebar_svg.append(edge_svg)
                    is_rebar_visible = True
            elif DraftGeomUtils.geomType(edge) == "Circle":
                p1 = getProjectionToSVGPlane(edge.Vertexes[0].Point,
                                             view_plane)
                p2 = getProjectionToSVGPlane(edge.Vertexes[1].Point,
                                             view_plane)
                if round(p1.x) == round(p2.x) or round(p1.y) == round(p2.y):
                    edge_svg = getLineSVG(p1, p2, rebars_stroke_width,
                                          rebars_color)
                    if not isLineInSVG(p1, p2, rebars_svg):
                        is_rebar_visible = True
                else:
                    edge_svg = getRoundEdgeSVG(edge, view_plane,
                                               rebars_stroke_width,
                                               rebars_color)
                    if not isRoundCornerInSVG(
                            edge,
                            rebar.Rounding * rebar.Diameter.Value,
                            view_plane,
                            rebars_svg,
                    ):
                        is_rebar_visible = True
                if is_rebar_visible:
                    u_rebar_svg.append(edge_svg)
    else:
        basewire = rebar.Base.Shape.Wires[0]
        for placement in rebar.PlacementList:
            wire = basewire.copy()
            wire.Placement = placement.multiply(basewire.Placement)

            edges = Part.__sortEdges__(
                DraftGeomUtils.filletWire(
                    wire,
                    rebar.Rounding * rebar.Diameter.Value,
                ).Edges)
            for edge in edges:
                if DraftGeomUtils.geomType(edge) == "Line":
                    p1 = getProjectionToSVGPlane(edge.Vertexes[0].Point,
                                                 view_plane)
                    p2 = getProjectionToSVGPlane(edge.Vertexes[1].Point,
                                                 view_plane)
                    if round(p1.x) == round(p2.x) and round(p1.y) == round(
                            p2.y):
                        edge_svg = getPointSVG(
                            p1,
                            radius=longitudinal_line_dia / 2,
                            fill=rebars_color,
                        )
                    else:
                        edge_svg = getLineSVG(p1, p2, rebars_stroke_width,
                                              rebars_color)
                        if not isLineInSVG(p1, p2, rebars_svg):
                            is_rebar_visible = True
                    if is_rebar_visible or not isLineInSVG(p1, p2, rebars_svg):
                        u_rebar_svg.append(edge_svg)
                        is_rebar_visible = True
                elif DraftGeomUtils.geomType(edge) == "Circle":
                    p1 = getProjectionToSVGPlane(edge.Vertexes[0].Point,
                                                 view_plane)
                    p2 = getProjectionToSVGPlane(edge.Vertexes[1].Point,
                                                 view_plane)
                    if round(p1.x) == round(p2.x) or round(p1.y) == round(
                            p2.y):
                        edge_svg = getLineSVG(p1, p2, rebars_stroke_width,
                                              rebars_color)
                        if not isLineInSVG(p1, p2, rebars_svg):
                            is_rebar_visible = True
                    else:
                        edge_svg = getRoundEdgeSVG(edge, view_plane,
                                                   rebars_stroke_width,
                                                   rebars_color)
                        if not isRoundCornerInSVG(
                                edge,
                                rebar.Rounding * rebar.Diameter.Value,
                                view_plane,
                                rebars_svg,
                        ):
                            is_rebar_visible = True
                    if is_rebar_visible:
                        u_rebar_svg.append(edge_svg)
    return {
        "svg": u_rebar_svg,
        "visibility": is_rebar_visible,
    }
Exemple #2
0
def getStraightRebarSVGData(
    rebar,
    view_plane,
    rebars_svg,
    rebars_stroke_width,
    rebars_color_style,
):
    """getStraightRebarSVGData(StraightRebar, ViewPlane, RebarsSVG,
    RebarsStrokeWidth, RebarsColorStyle):
    Returns dictionary containing straight rebar svg data.

    rebars_color_style can be:
        - "shape color" to select color of rebar shape
        - color name or hex value of color

    Returns dictionary format:
    {
        "svg": straight_rebar_svg,
        "visibility": is_rebar_visible,
    }
    """
    rebars_color = getRebarColor(rebar, rebars_color_style)

    straight_rebar_svg = ElementTree.Element("g",
                                             attrib={"id": str(rebar.Name)})
    is_rebar_visible = False
    drawing_plane_normal = view_plane.axis
    if round(drawing_plane_normal.cross(getRebarsSpanAxis(rebar)).Length) == 0:
        basewire = rebar.Base.Shape.Wires[0].copy()
        basewire.Placement = rebar.PlacementList[0].multiply(
            basewire.Placement)
        p1 = getProjectionToSVGPlane(basewire.Vertexes[0].Point, view_plane)
        p2 = getProjectionToSVGPlane(basewire.Vertexes[1].Point, view_plane)
        if round(p1.x) == round(p2.x) and round(p1.y) == round(p2.y):
            rebar_svg = getPointSVG(p1,
                                    radius=2 * rebars_stroke_width,
                                    fill=rebars_color)
            if not isPointInSVG(p1, rebars_svg):
                is_rebar_visible = True
        else:
            rebar_svg = getLineSVG(p1, p2, rebars_stroke_width, rebars_color)
            if not isLineInSVG(p1, p2, rebars_svg):
                is_rebar_visible = True
        if is_rebar_visible:
            straight_rebar_svg.append(rebar_svg)
    else:
        basewire = rebar.Base.Shape.Wires[0]
        for placement in rebar.PlacementList:
            wire = basewire.copy()
            wire.Placement = placement.multiply(basewire.Placement)
            p1 = getProjectionToSVGPlane(wire.Vertexes[0].Point, view_plane)
            p2 = getProjectionToSVGPlane(wire.Vertexes[1].Point, view_plane)
            if round(p1.x) == round(p2.x) and round(p1.y) == round(p2.y):
                rebar_svg = getPointSVG(p1,
                                        radius=2 * rebars_stroke_width,
                                        fill=rebars_color)
                if not (isPointInSVG(p1, rebars_svg)
                        or isPointInSVG(p1, straight_rebar_svg)):
                    is_rebar_visible = True
            else:
                rebar_svg = getLineSVG(p1, p2, rebars_stroke_width,
                                       rebars_color)
                if not (isLineInSVG(p1, p2, rebars_svg)
                        or isLineInSVG(p1, p2, straight_rebar_svg)):
                    is_rebar_visible = True
            if is_rebar_visible:
                straight_rebar_svg.append(rebar_svg)
    return {
        "svg": straight_rebar_svg,
        "visibility": is_rebar_visible,
    }
Exemple #3
0
def getStirrupSVGData(rebar, view_plane, rebars_svg, rebars_stroke_width,
                      rebars_color_style):
    """getStirrupSVGData(StirrupRebar, ViewPlane, RebarsSVG, RebarsStrokeWidth,
    RebarsColorStyle):
    Returns dictionary containing stirrup svg data.

    rebars_color_style can be:
        - "shape color" to select color of rebar shape
        - color name or hex value of color

    Returns dictionary format:
    {
        "svg": stirrup_svg,
        "visibility": is_rebar_visible,
    }
    """
    rebars_color = getRebarColor(rebar, rebars_color_style)

    stirrup_svg = ElementTree.Element("g", attrib={"id": str(rebar.Name)})
    is_rebar_visible = False
    drawing_plane_normal = view_plane.axis
    stirrup_span_axis = getRebarsSpanAxis(rebar)
    if round(drawing_plane_normal.cross(stirrup_span_axis).Length) == 0:
        basewire = rebar.Base.Shape.Wires[0].copy()
        basewire.Placement = rebar.PlacementList[0].multiply(
            basewire.Placement)
        edges = Part.__sortEdges__(
            DraftGeomUtils.filletWire(
                basewire,
                rebar.Rounding * rebar.Diameter.Value,
            ).Edges)
        for edge in edges:
            if DraftGeomUtils.geomType(edge) == "Line":
                p1 = getProjectionToSVGPlane(edge.Vertexes[0].Point,
                                             view_plane)
                p2 = getProjectionToSVGPlane(edge.Vertexes[1].Point,
                                             view_plane)
                edge_svg = getLineSVG(p1, p2, rebars_stroke_width,
                                      rebars_color)
                if is_rebar_visible or not isLineInSVG(p1, p2, rebars_svg):
                    stirrup_svg.append(edge_svg)
                    is_rebar_visible = True
            elif DraftGeomUtils.geomType(edge) == "Circle":
                edge_svg = getRoundEdgeSVG(edge, view_plane,
                                           rebars_stroke_width, rebars_color)
                if is_rebar_visible or not isRoundCornerInSVG(
                        edge,
                        rebar.Rounding * rebar.Diameter.Value,
                        view_plane,
                        rebars_svg,
                ):
                    stirrup_svg.append(edge_svg)
                    is_rebar_visible = True

    else:
        if round(stirrup_span_axis.cross(view_plane.u).Length) == 0:
            stirrup_alignment = "V"
        else:
            stirrup_alignment = "H"
        basewire = DraftGeomUtils.filletWire(
            rebar.Base.Shape.Wires[0], rebar.Rounding * rebar.Diameter.Value)
        for placement in rebar.PlacementList:
            wire = basewire.copy()
            wire.Placement = placement.multiply(basewire.Placement)
            p1, p2 = getStirrupSVGPoints(wire, stirrup_alignment, view_plane)
            rebar_svg = getLineSVG(p1, p2, rebars_stroke_width, rebars_color)
            if not isLineInSVG(p1, p2, rebars_svg):
                is_rebar_visible = True
            if is_rebar_visible:
                stirrup_svg.append(rebar_svg)
    return {
        "svg": stirrup_svg,
        "visibility": is_rebar_visible,
    }