コード例 #1
0
ファイル: pipebend.py プロジェクト: paulgriffiths/jobcalc
    def get_segment_points(self, rad):

        """
        Calculates coordinates for segment vertices at a specified radius.
        """

        # Note that the nominal radius of the bend is calculated to the
        # center of the segment at its mid-point, not at its end. If this
        # were not so, the midpoint of the bend ends would not align with the
        # nominal radius, as the bend is always ended with half segments.
        # Since we are calculating coordinates for the segment vertices
        # at the ends, and not for the mid-points, we cannot use the
        # nominal radius to do this. Instead, we use the 'erad' variable
        # which calculates the radius we need to use for the segment
        # vertices that will cause the segment mid-points to align
        # with the nominal radius.

        # Contrast this with calculating the segment intrados and
        # extrados lengths, in the class initializer, where we do
        # use the nominal radius, but calculate a tangent. This
        # is not available here due to the ptoc() function needing
        # a radius to the end points, rather than to the mid point.

        pts = []
        s_ang = self.segment_angle
        b_arc = self.bend_arc
        erad = rad / cos(s_ang / 2)

        pts.append(ptoc(0, rad))
        for ang in [n + 0.5 for n in range(self.num_segments)]:
            pts.append(ptoc(s_ang * ang, erad))
        pts.append(ptoc(b_arc, rad))

        return pts
コード例 #2
0
ファイル: pipebend.py プロジェクト: paulgriffiths/jobcalc
    def draw_curved_bend(self, ctx, comp, fill=False,
                         edges=False, outline=False):

        """
        Draws a smoothly curved (not segmented) bend component.

        Arguments:
        ctx -- a Pycairo context
        comp -- type of component, "co", "ci", "lo" or "li"
        outline -- draws an outline around the entire component if True.
        """

        b_arc = self.bend_arc
        rads = self.radii

        ctx.save()

        if fill or outline:
            ctx.move_to(*ptoc(0, rads["inner"][comp]).t())
            ctx.line_to(*ptoc(0, rads["outer"][comp]).t())
            ctx.arc_negative(0, 0, rads["outer"][comp], 0, pi * 2 - b_arc)
            ctx.line_to(*ptoc(b_arc, rads["inner"][comp]).t())
            ctx.arc(0, 0, rads["inner"][comp], pi * 2 - b_arc, 0)
            ctx.close_path()

            if fill:
                if comp == "co" and self.hatching:
                    ctx.set_source(self.chatch)
                else:
                    ctx.set_source_rgb(*self.colors["comp"][comp])

                if outline:
                    ctx.fill_preserve()
                else:
                    ctx.fill()
            if outline:
                ctx.set_source_rgb(*self.drawing_line_color)
                ctx.stroke()

        if edges:
            ctx.set_source_rgb(*self.drawing_line_color)

            for i in ["outer", "inner"]:
                ctx.arc(0, 0, rads[i][comp], pi * 2 - b_arc, 0)
                ctx.stroke()

        ctx.restore()
コード例 #3
0
ファイル: pipe.py プロジェクト: paulgriffiths/jobcalc
    def draw_rad_dims(self, ctx):

        """
        Draw the radius dimensions of the bend.

        Arguments:
        ctx -- a Pycairo context
        """

        # The angle at which the radius dimension lines are drawn
        # depends on the bend angle for pipe bends, but is always
        # vertical for pipe straights. Since this will be called
        # from a subclass, check whether we have a pipe bend by
        # verifying whether the "bend_arc" instance attribute is set.

        if hasattr(self, "bend_arc"):
            b_arc = self.bend_arc       # pylint: disable=E1101
        else:
            b_arc = 0

        pts = {}

        ctx.save()

        for scale, comp in zip(range(4, 0, -1), ["co", "ci", "lo", "li"]):

            # pylint: disable=E1101

            dll = self.dim_line_length * scale

            for i in ["out", "in"]:
                point = self.pc_pts[i][comp][-1 if i == "out" else 0]
                pts[i] = ptoc(b_arc + pi / 2, dll, point)
                ctx.move_to(*point.t())
                ctx.line_to(*pts[i].t())

            # pylint: enable=E1101

            ctx.stroke()
            draw_dim_line(ctx, pts["out"], pts["in"],
                          self.diameters[comp], self.scale, 0)

        ctx.restore()
コード例 #4
0
ファイル: pipebend.py プロジェクト: paulgriffiths/jobcalc
    def draw_arc_dims(self, ctx):

        """
        Draws dimensions for a bend arc and radius.

        ctx -- a Pycairo context
        """

        b_arc = self.bend_arc
        s_ang = self.segment_angle
        rad = self.radii["inner"]["fo"] * 0.95

        ctx.save()

        # Draw angle lines to origin

        ctx.move_to(*ptoc(b_arc, rad).t())
        ctx.line_to(0, 0)
        ctx.line_to(rad, 0)
        ctx.stroke()

        # Draw angle arc and dimension label

        rad /= 3

        ctx.arc(0, 0, rad, pi * 2 - b_arc, 0)
        ctx.stroke()

        draw_arrowhead(ctx, b_arc + pi / 2, ptoc(b_arc, rad), self.scale)
        draw_arrowhead(ctx, pi * 3 / 2, ptoc(0, rad), self.scale)
        draw_dim_label(ctx, ptoc(b_arc / 2, rad),
                       self.bend_arc_d, self.scale, 0, "d")

        # Draw nominal radius dimension line and label

        rad *= 2
        if self.num_segments % 2:
            angle = b_arc / 2 + s_ang / 2
        else:
            angle = b_arc / 2

        pt1 = ptoc(angle, rad)
        pt2 = ptoc(angle, self.radii["nom"])
        ctx.move_to(*pt1.t())
        ctx.line_to(*pt2.t())
        ctx.stroke()
        draw_arrowhead(ctx, angle, pt2, self.scale)
        draw_dim_label(ctx, pt1, self.radii["nom"], self.scale, 0, "r")

        ctx.restore()
コード例 #5
0
ファイル: pipebend.py プロジェクト: paulgriffiths/jobcalc
    def draw_seg_dims(self, ctx):

        """
        Draw segment extrados and intrados dimensions.

        Arguments:
        ctx -- a Pycairo context
        """

        segs = self.num_segments
        s_ang = self.segment_angle
        cld = self.p_rad["co"] - self.p_rad["lo"]
        dpt = self.dos_dim_dp
        ddll = self.dos_dim_line_length

        idx = [0, 0]
        pts = [0, 0]

        ctx.save()

        if segs >= 3:

            # Draw extrados dimensions

            idx[0] = segs // 2 + (segs % 2)
            idx[1] = idx[0] + 1

            for comp, dim in zip(["co", "lo"],
                           [self.segdims[k].value for k in ["cex", "lex"]]):
                if comp == "co" and self.casing_type == "onepiece":
                    continue
                for line in range(2):
                    stp = self.pc_pts["out"][comp][idx[line]]
                    lnl = ddll * 1.7 if comp == "co" else cld + ddll * 0.7
                    pts[line] = ptoc(s_ang * idx[0], lnl, stp)

                    ctx.move_to(*stp.t())
                    ctx.line_to(*pts[line].t())

                ctx.stroke()
                draw_dim_line(ctx, pts[1], pts[0], dim, self.scale, dpt)

            # Draw intrados dimensions

            idx[0] += 1 - (segs % 2)
            idx[1] = idx[0] + 1

            for comp, dim in zip(["co", "lo"],
                            [self.segdims[k].value for k in ["cin", "lin"]]):
                if comp == "co" and self.casing_type == "onepiece":
                    continue
                for line in range(2):
                    if self.casing_type == "onepiece":
                        mult = 0.7
                    else:
                        mult = 1.7
                    stp = self.pc_pts["in"][comp][idx[line]]
                    lnl = ddll * 0.7 if comp == "co" else cld + ddll * mult
                    pts[line] = ptoc(s_ang * (idx[0] - 2 + segs % 2) +
                                     pi, lnl, stp)

                    ctx.move_to(*stp.t())
                    ctx.line_to(*pts[line].t())

                ctx.stroke()
                draw_dim_line(ctx, pts[1], pts[0], dim, self.scale, dpt)

        ctx.restore()
コード例 #6
0
ファイル: flange.py プロジェクト: paulgriffiths/jobcalc
    def draw_profile(self, ctx, dash_style):

        """
        Draws the flange arcs, including bolt holes.

        Arguments:
        ctx -- a Pycairo context
        dash_style -- style of dashes to use to the bolt
        hole diameter
        """

        rfr = self.raised_face_diameter / 2.0
        hrd = self.hole_diameter / 2.0
        frd = self.flange_diameter / 2.0
        bcr = self.bolt_circle_diameter / 2.0
        bhr = self.bolt_hole_diameter / 2.0
        nbs = self.num_bolts / 2
        hls = Flange.bolt_hole_line_size

        ctx.save()

        # Draw flange arcs

        ctx.move_to(hrd, 0)
        ctx.line_to(frd, 0)
        ctx.arc(0, 0, frd, 0, pi)
        ctx.line_to(-hrd, 0)
        ctx.arc_negative(0, 0, hrd, pi, 0)
        ctx.close_path()

        ctx.set_source_rgb(*Flange.colors["arc"])
        ctx.fill_preserve()
        ctx.set_source_rgb(*Flange.colors["line"])
        ctx.stroke()

        ctx.arc(0, 0, rfr, 0, pi)
        ctx.stroke()

        # Draw bolt holes

        for i in range(nbs):
            ang = -pi / (nbs * 2) * (1 + i * 2)
            bhc = ptoc(ang, bcr)
            ctx.arc(bhc.x, bhc.y, bhr, 0, pi * 2)
            ctx.set_source_rgb(1, 1, 1)
            ctx.fill_preserve()

            ctx.set_source_rgb(*Flange.colors["line"])
            ctx.move_to(*ptoc(ang, bcr - bhr * hls).t())
            ctx.line_to(*ptoc(ang, bcr + bhr * hls).t())

            ctx.stroke()

        # Draw bolt hole circle arc

        if dash_style:
            ctx.set_dash(dash_style)
        ctx.arc(0, 0, bcr, 0, pi)
        ctx.stroke()

        # Extend center line arc to flange hole diameter

        ctx.move_to(0, 0)
        ctx.line_to(0, 0 + hrd)
        ctx.stroke()

        ctx.restore()