예제 #1
0
    def draw_pipe_comp(self, ctx, comp, fill=False,
                       outline=False, edges=False):

        """
        Intercepts the superclass function to provide for curved casings.
        """

        if self.casing_type == "onepiece" and comp[0] == "c":
            self.draw_curved_bend(ctx, comp, fill=fill,
                                  outline=outline, edges=edges)
        else:
            Pipe.draw_pipe_comp(self, ctx, comp, fill=fill,
                                outline=outline, edges=edges)
예제 #2
0
    def __init__(self, length, casingod, casingid, liningod, liningid, flange):

        """
        Initializes a PipeStraight instance.

        Arguments:
        length -- length of straight, in mm
        casingod -- outside diameter of casing, in mm
        casingid -- inside diameter of casing, in mm
        liningod -- outside diameter of lining, in mm
        liningid -- inside diameter of lining, in mm
        """

        # Call superclass constructor

        Pipe.__init__(self, casingod, casingid, liningod, liningid, flange)

        # Straight properties

        self.length = length
        self.len_dim_line_length = 0
        self.len_dim_line_length_offset_m = 1
        self.len_dim_line_length_width_m = 2

        # Calculate straight component points

        pc_pts_out = {}
        pc_pts_in = {}
        pc_pts_ctr = []

        for comp in ["co", "ci", "lo", "li"]:
            pc_pts_out[comp] = []
            pc_pts_in[comp] = []
            for y in [0, -self.length]:
                pc_pts_out[comp].append(Point(self.p_rad[comp], y))
                pc_pts_in[comp].append(Point(-self.p_rad[comp], y))
            pc_pts_in[comp].reverse()

        for y in [0, -self.length]:
            pc_pts_ctr.append(Point(0, y))

        self.pc_pts = {"in": pc_pts_in, "out": pc_pts_out,
                       "ctr": pc_pts_ctr}
예제 #3
0
    def draw_component(self, ctx, page_w, page_h):

        """
        Draws a straight. Mainly calls supporting functions.

        This function is called by the 'component' base class.

        Arguments:
        ctx -- a Pycairo context
        page_w, page_h -- width and height of drawing area
        """

        # Call the parent function...

        Pipe.draw_component(self, ctx, page_w, page_h)

        # ...and then provide straight-specific drawing functionality.

        self.draw_center_line(ctx)
        self.draw_len_dim(ctx)
예제 #4
0
    def draw_component(self, ctx, page_w, page_h):

        """
        Draws a bend. Mainly calls supporting functions.

        This function is called by the 'component' base class.

        Arguments:
        ctx -- a Pycairo context
        page_w, page_h -- width and height of drawing area
        """

        # Call the superclass function...

        Pipe.draw_component(self, ctx, page_w, page_h)

        # ...and then provide bend-specific drawing functionality.

        self.draw_ribs(ctx, "li")
        self.draw_center_arc(ctx)
        self.draw_arc_dims(ctx)
        if self.ex_dim_drg:
            self.draw_seg_dims(ctx)
예제 #5
0
    def set_scale(self, ctx, page_w, page_h):

        """
        Automatically sets a scale factor for the straight drawing.

        Arguments:
        ctx -- a Pycairo context
        page_w, page_h -- width and height of drawing area
        """

        pipelen = self.length
        fld = self.diameters["fo"]
        flr = self.p_rad["fo"]

        # Calculate radius dimension line lengths, these vary based
        # on font size, and need to be considered for scaling along
        # the y-axis. These dimensions will be upscaled during the
        # final drawing, and will be independent of the scale factor
        # calculated.

        rad_values = []
        for comp in ["co", "ci", "lo", "li"]:
            rad_values.append(str(int(round(self.diameters[comp]))))
        rdm = get_largest_text_height(ctx, rad_values, self.text["dims"], True)
        self.dim_line_length = rdm
        rdm = self.dim_line_length * 4

        # Calculate length dimension width, this can vary based both
        # on font size and on the length itself, and needs to be
        # considered for scaling along the x-axis. This dimension will
        # be upscaled during the final drawing, and will be independent
        # of the scale factor calculated.

        len_values = []
        len_values.append(str(int(round(self.length))))
        ldm = get_largest_text_width(ctx, len_values, self.text["dims"], True)
        self.len_dim_line_length = ldm
        ldm *= (self.len_dim_line_length_offset_m +
                self.len_dim_line_length_width_m)

        # Calculate x and y scale factors

        x_scale = (page_w - ldm) / fld
        y_scale = (page_h - rdm) / (pipelen + flr)

        # Scale based on the smallest factor

        self.scale = min(x_scale, y_scale)
        ctx.scale(self.scale, self.scale)

        # Set the origin based on calculated scale

        page_w /= self.scale
        bend_w = fld + ldm / self.scale
        x_origin = (page_w - bend_w) / 2 + flr

        page_h /= self.scale
        bend_h = pipelen + flr + rdm / self.scale
        y_origin = page_h - (page_h - bend_h) / 2 - flr

        ctx.translate(x_origin, y_origin)

        # Upscale line lengths

        self.len_dim_line_length /= self.scale

        # Call superclass function

        Pipe.set_scale(self, ctx, page_w, page_h)
예제 #6
0
    def __init__(self, nomrad, casingod, casingid, liningod,
                 liningid, bendangle, segangle, ctype, flange,
                 exdimdrg, exdimbox):

        """
        Initializes a PipeBend instance.

        Arguments:
        nomrad -- nominal radius, in mm
        casingod -- outside diameter of casing, in mm
        casingid -- inside diameter of casing, in mm
        liningod -- outside diameter of lining, in mm
        liningid -- inside diameter of lining, in mm
        bendangle -- angle, in degrees, of overall bend
        segangle -- angle, in degrees, of each bend segment
        ctype -- type of casing, either "onepiece" or "segmented"
        exdimdrg -- True to show segment dimensions on main drawing
        exdimbox -- True to show segment dimensions in an infobox
        """

        # Call superclass constructor

        Pipe.__init__(self, casingod, casingid, liningod, liningid, flange)

        # Page dimensions and properties

        self.dos_dim_line_length = 30
        self.dos_dim_dp = 3

        # Bend angles, properties and information

        self.bend_arc_d = bendangle
        self.segment_angle_d = segangle
        self.bend_arc = radians(bendangle)
        self.segment_angle = radians(segangle)
        self.num_segments = int(self.bend_arc / self.segment_angle)
        self.casing_type = ctype
        self.ex_dim_box = exdimbox
        self.ex_dim_drg = exdimdrg

        # Bend diameters and radii

        fod = self.flange.flange_diameter

        self.diameters["nom"] = nomrad * 2

        outer_radii = {"nom": nomrad,
                       "co": nomrad + casingod / 2.0,
                       "ci": nomrad + casingid / 2.0,
                       "lo": nomrad + liningod / 2.0,
                       "li": nomrad + liningid / 2.0,
                       "fo": nomrad + fod / 2.0}
        inner_radii = {"nom": nomrad,
                       "co": nomrad - casingod / 2.0,
                       "ci": nomrad - casingid / 2.0,
                       "lo": nomrad - liningod / 2.0,
                       "li": nomrad - liningid / 2.0,
                       "fo": nomrad - fod / 2.0}
        self.radii = {"inner": inner_radii,
                      "outer": outer_radii,
                      "nom": nomrad}

        # Calculate and store segment dimensions

        # pylint: disable=C0103

        self.segdims = {}
        for k, i, d, l in zip(["cex", "cin", "lex", "lin", "mean"],
                              ["outer", "inner", "outer", "inner", "outer"],
                              ["co", "co", "lo", "lo", "nom"],
                              ["Casing seg. extra. length",
                               "Casing seg. intra. length",
                               "Lining seg. extra. length",
                               "Lining seg. intra. length",
                               "Mean seg. length"]):
            dim = self.radii[i][d] * tan(self.segment_angle / 2) * 2
            self.segdims[k] = LabeledValue(l, dim)

        # pylint: enable=C0103

        # Calculate segmented component points

        pc_pts_out = {}
        pc_pts_in = {}

        for k in ["co", "ci", "lo", "li"]:
            pc_pts_out[k] = self.get_segment_points(self.radii["outer"][k])
            pc_pts_in[k] = self.get_segment_points(self.radii["inner"][k])
            pc_pts_in[k].reverse()
        pc_pts_ctr = self.get_segment_points(self.radii["nom"])
        self.pc_pts = {"in": pc_pts_in, "out": pc_pts_out,
                       "ctr": pc_pts_ctr}
예제 #7
0
    def set_scale(self, ctx, page_w, page_h):

        """
        Automatically sets a scale factor for the bend drawing.

        Arguments:
        ctx -- a Pycairo context
        page_w, page_h -- width and height of drawing area
        """

        b_arc = self.bend_arc
        cri = self.radii["inner"]["co"]
        cro = self.radii["outer"]["co"]
        bfr = self.radii["outer"]["fo"]
        flr = self.p_rad["fo"]

        # Calculate segment dimension line lengths

        dim_values = []
        dpt = self.dos_dim_dp
        for dim in ["cex", "cin", "lex", "lin"]:
            dim_values.append(str(round(self.segdims[dim].value, dpt)))
        ddm = get_largest_text_width(ctx, dim_values, self.text["dims"], True)
        self.dos_dim_line_length = ddm

        # Calculate radius dimension line lengths, these vary based
        # on font size, and need to be considered for scaling along
        # the axes. These dimensions will be upscaled during the
        # final drawing, and will be independent of the scale factor
        # calculated.

        rad_values = []
        for comp in ["co", "ci", "lo", "li"]:
            rad_values.append(str(int(round(self.diameters[comp]))))
        rdm = get_largest_text_width(ctx, rad_values, self.text["dims"], True)
        self.dim_line_length = rdm
        rdm = self.dim_line_length * 4

        # Calculate x scale factor

        # dos_s not yet implemented. Under some circumstances the segment
        # dimension lines on the drawing can extend past the right edge
        # of the drawing extent currently calculated here. The option to
        # suppress the dimension lines and relegate them to a box is
        # available, so problem is minor. Scaling depends upon whether
        # casing is one-piece of segments, whether the option to show
        # the segment dimensions was shown, and so on, so is more
        # complicated than the options shown here. Approach should be
        # the same, calculate the width including the segment dimension
        # lines under the selected options, and then scale based on that
        # if it turns out to be the largest of the calculated width. Then
        # set the x origin accordingly.

        #n      = ns//2 + (ns%2)
        #dx     = ptoc(sa*n,ddm*1.5).x
        #pt     = self.pc_pts["out"]["co"][n]
        #dos_w  = pt.x

        rad_w = bfr
        ang_w = rad_w - cos(b_arc) * cri
        dm_w = cos(pi / 2 - b_arc) * rdm

        #dos_s  = (page_w - dx) / dos_w

        rad_s = page_w / bfr
        ang_s = (page_w - dm_w) / ang_w
        x_scale = min(rad_s, ang_s)

        # Calculate y scale factor

        rad_h = sin(b_arc) * bfr + flr
        ang_h = sin(b_arc) * cro + flr
        dm_h = sin(pi / 2 - b_arc) * rdm
        y_scale = min(page_h / rad_h, (page_h - dm_h) / ang_h)

        # Set scale based on smallest factor

        self.scale = min(x_scale, y_scale)
        ctx.scale(self.scale, self.scale)

        # Set bend origin based on calculated scale

        page_w /= self.scale
        bend_w = max(rad_w, ang_w + dm_w / self.scale)
        x_origin = page_w - (page_w - bend_w) / 2 - bfr

        page_h /= self.scale
        bend_h = max(rad_h, ang_h + dm_h / self.scale)
        y_origin = page_h - (page_h - bend_h) / 2 - flr

        ctx.translate(x_origin, y_origin)

        # Scale lines

        self.dos_dim_line_length /= self.scale

        # Call superclass function

        Pipe.set_scale(self, ctx, page_w, page_h)