Example #1
0
File: pdf.py Project: awriel/eden
    def parse_img(self, html):
        import os

        I = None
        from reportlab.platypus import Image

        if "_src" in html.attributes:
            src = html.attributes["_src"]
            if os.path.exists(src):
                I = Image(src)
            else:
                src = src.rsplit("/", 1)
                src = os.path.join(current.request.folder, "uploads/", src[1])
                if os.path.exists(src):
                    I = Image(src)
        if not I:
            return None

        iwidth = I.drawWidth
        iheight = I.drawHeight
        # @todo: extract the number from a 60px value
        #        if "_height" in html.attributes:
        #            height = int(html.attributes["_height"]) * inch / 80.0
        #            width = iwidth * (height/iheight)
        #        elif "_width" in html.attributes:
        #            width = int(html.attributes["_width"]) * inch / 80.0
        #            height = iheight * (width/iwidth)
        #        else:
        #            height = 1.0 * inch
        #            width = iwidth * (height/iheight)
        height = 1.0 * inch
        width = iwidth * (height / iheight)
        I.drawHeight = height
        I.drawWidth = width
        return [I]
Example #2
0
    def parse_img(self, html):
        import os
        I = None
        from reportlab.platypus import Image
        if "_src" in html.attributes:
            src = html.attributes["_src"]
            if os.path.exists(src):
                I = Image(src)
            else:
                src = src.rsplit("/", 1)
                src = os.path.join(current.request.folder, "uploads/", src[1])
                if os.path.exists(src):
                    I = Image(src)
        if not I:
            return None

        iwidth = I.drawWidth
        iheight = I.drawHeight
        # @todo: extract the number from a 60px value
        #        if "_height" in html.attributes:
        #            height = int(html.attributes["_height"]) * inch / 80.0
        #            width = iwidth * (height/iheight)
        #        elif "_width" in html.attributes:
        #            width = int(html.attributes["_width"]) * inch / 80.0
        #            height = iheight * (width/iwidth)
        #        else:
        #            height = 1.0 * inch
        #            width = iwidth * (height/iheight)
        height = 1.0 * inch
        width = iwidth * (height / iheight)
        I.drawHeight = height
        I.drawWidth = width
        return [I]
Example #3
0
    def createDocument(self):
        """"""
        voffset = 100
        user = os.getlogin()
        time_now = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

        # create return address
        address = """<font size="12"><strong> ANYstructure report generator<br/></strong></font>""" + '<br/>' + \
                  """<font size="12"> User: </font>""" + '<font size="12">' + user + '</font>' + '<br/>' + '<br/>' + \
                  """<font size="12"> Time : </font>""" + '<font size="12">' + time_now + '</font>' + '<br/>'
        p = Paragraph(address, self.styles["Normal"])
        # add a logo and size it
        img_file_name = 'ANYstructure_logo.jpg'
        if os.path.isfile('images/' + img_file_name):
            file_path = 'images/' + img_file_name
        else:
            file_path = os.path.dirname(
                os.path.abspath(__file__)) + '/images/' + img_file_name
        logo = Image(file_path)
        logo.drawHeight = 1 * inch
        logo.drawWidth = 2.5 * inch
        data = [[p, logo]]
        table = Table(data, colWidths=4 * inch)
        table.setStyle([("VALIGN", (0, 0), (0, 0), "TOP")])
        table.wrapOn(self.c, self.width, self.height)
        table.drawOn(self.c, *self.coord(18, 50, mm))

        self.draw_lines()

        ptext = '<font size="12" color = "blue"><strong>' + "Compartments: " + '</strong></font>'
        self.createParagraph(ptext, 10, voffset + 85)
        delta = 0
        h_start = 130
        for name, obj in self.data['compartments'].items():

            ptext = '<font size="7" color = "black">' + 'Name: '+ name + ', content: ' \
                    + obj.get_content() + '</font>'
            self.createParagraph(ptext, h_start, voffset + 100 + delta)

            delta += 3
            ptext = '<font size="7" color = "black">' + 'Min. elevation: ' + str(obj.get_lowest_elevation()) + \
                    ', Max. elevation: ' + str(obj.get_highest_elevation()) + '</font>'
            self.createParagraph(ptext, h_start, voffset + 100 + delta)

            delta += 3
            ptext = '<font size="7" color = "black">' + 'Applied overpressure: ' + str(obj.get_overpressure()) + \
                    '</font>'
            self.createParagraph(ptext, h_start, voffset + 100 + delta)

            delta += 3
            ptext = '<font size="7" color = "black">'+'(a_stat, a_dyn_loa, a_dyn_bal): ' + \
                    str(obj.get_accelerations()) + '</font>'
            self.createParagraph(ptext, h_start, voffset + 100 + delta)
            delta += 4
        try:
            self.c.drawImage('current_comps.png',
                             10,
                             50,
                             width=350,
                             height=250)
        except OSError:
            self.c.drawImage('current_comps_NONE.png',
                             10,
                             50,
                             width=350,
                             height=250)

        # insert body of letter

        self.c.showPage()
        ptext = '<font size="12" color = "blue"><strong>' + "Results for defined structure: " + '</strong></font>'
        self.createParagraph(ptext, 10, 0)

        delta = 160
        vpos = 950

        for line in sorted(self.data['lines'].keys()):
            vpos -= delta
            if line in self.data['struc_obj'].keys():
                struc_obj = self.data['struc_obj'][line]
                fo = self.data['fatigue_obj'][line]
                pressure = self.data['pressure_uls'][line] / 1000
                textobject = self.c.beginText()
                textobject.setTextOrigin(30, vpos)
                textobject.setFont("Helvetica-Oblique", 10)
                textobject.textLine('*********** ' + line + ' ***********')
                textobject.textLine('Plate thickness: ' +
                                    str(struc_obj.get_pl_thk() * 1000) +
                                    ' [mm]          '
                                    'Stiffener spacing: ' +
                                    str(struc_obj.get_s() * 1000) + ' [mm]' +
                                    '          Span: ' +
                                    str(round(struc_obj.get_span(), 4)) +
                                    ' [m]')
                textobject.textLine('Stiffener: ' +
                                    str(struc_obj.get_web_h() * 1000) + 'x' +
                                    str(struc_obj.get_web_thk() * 1000) +
                                    ' + ' + str(struc_obj.get_fl_w() * 1000) +
                                    'x' + str(struc_obj.get_fl_thk() * 1000))

                textobject.textLine(
                    'Fixation paramters: kps: = ' + str(struc_obj.get_kps()) +
                    '  kpp = ' + str(struc_obj.get_kpp()) +
                    ', Bending moment factors km1/km2/km3 (support/field/support)'
                    + ' = ' + str(int(struc_obj.get_km1())) + '/' +
                    str(int(struc_obj.get_km2())) + '/' +
                    str(int(struc_obj.get_km3())))
                textobject.textLine('Defined stresses [MPa]:  sigma_x = ' +
                                    str(struc_obj.get_sigma_x()) +
                                    '  sigma_y1 = ' +
                                    str(struc_obj.get_sigma_y1()) +
                                    '  sigma_y2 = ' +
                                    str(struc_obj.get_sigma_y2()) +
                                    '  tau_xy = ' +
                                    str(struc_obj.get_tau_xy()))
                textobject.textLine('ULS max pressure for line: ' +
                                    str(round(pressure, 2) * 1000) + ' [kPa]' +
                                    '      Pressure applied at: ' +
                                    'plate side' if struc_obj.get_side() ==
                                    'p' else 'stiffener side')

                if fo is not None:
                    textobject.textLine('Fatigue pressure [Pa]: ' + ' p_int:' +
                                        ' loaded/ballast/part = ' + str(
                                            round(
                                                self.data['pressure_fls'][line]
                                                ['p_int']['loaded'], 0)) +
                                        '/' + str(
                                            round(
                                                self.data['pressure_fls'][line]
                                                ['p_int']['ballast'], 0)) +
                                        '/' + str(
                                            round(
                                                self.data['pressure_fls'][line]
                                                ['p_int']['part'], 0)) +
                                        ' p_ext:' + ' loaded/ballast/part = ' +
                                        str(
                                            round(
                                                self.data['pressure_fls'][line]
                                                ['p_ext']['loaded'], 0)) +
                                        '/' + str(
                                            round(
                                                self.data['pressure_fls'][line]
                                                ['p_ext']['ballast'], 0)) +
                                        '/' + str(
                                            round(
                                                self.data['pressure_fls'][line]
                                                ['p_ext']['part'], 0)))
                else:
                    textobject.textLine(
                        ' Fatigue pressure: No pressures defined')

                textobject.setFillColor('red') if self.data['colors'][line]['section'] == 'red' \
                    else textobject.setFillColor('black')
                textobject.textLine(
                    'Section modulus: ' + str(
                        int(
                            min(self.data['section_modulus'][line]['sec_mod']
                                ) * 1000**3)) + ' [mm3]' +
                    '  Min. section modulus: ' + str(
                        int(self.data['section_modulus'][line]['min_sec_mod'] *
                            1000**3)) + ' [mm3]' + ' -> ' +
                    'OK' if int(
                        min(self.data['section_modulus'][line]['sec_mod']) *
                        1000**3) >= int(
                            self.data['section_modulus'][line]['min_sec_mod'] *
                            1000**3) else 'Section modulus: ' +
                    str(
                        int(
                            min(self.data['section_modulus'][line]['sec_mod']
                                ) * 1000**3)) + ' [mm3]' +
                    '  Min. section modulus: ' + str(
                        int(self.data['section_modulus'][line]['min_sec_mod'] *
                            1000**3)) + ' [mm3]' + ' -> ' + 'NOT OK')
                textobject.setFillColor('black')
                textobject.setFillColor('red') if self.data['colors'][line]['thickness'] == 'red' \
                    else textobject.setFillColor('black')
                textobject.textLine(
                    'Min plate thickness:  ' +
                    str(round(self.data['thickness'][line]['min_thk'], 2)) +
                    ' [mm] '
                    ' -> ' + 'OK' if struc_obj.get_pl_thk() *
                    1000 >= self.data['thickness'][line]['min_thk'] else
                    'Min plate thickness:  ' +
                    str(round(self.data['thickness'][line]['min_thk'], 2)) +
                    ' [mm] '
                    ' -> ' + 'NOT OK')
                textobject.setFillColor('black')
                textobject.setFillColor('red') if self.data['colors'][line]['shear'] == 'red' \
                    else textobject.setFillColor('black')
                textobject.textLine(
                    'Shear area: ' + str(
                        int(self.data['shear_area'][line]['shear_area'] *
                            1000**2)) + ' [mm2] ' + '   Min shear area: ' +
                    str(
                        int(self.data['shear_area'][line]['min_shear_area'] *
                            1000**2)) + ' [mm2] ' + ' -> ' +
                    'OK' if self.data['shear_area'][line]['shear_area'] >= self
                    .data['shear_area'][line]['min_shear_area'] else
                    'Shear area: ' + str(
                        int(self.data['shear_area'][line]['shear_area'] *
                            1000**2)) + ' [mm2] ' + '   Min shear area: ' +
                    str(
                        int(self.data['shear_area'][line]['min_shear_area'] *
                            1000**2)) + ' [mm2] ' + ' -> ' + 'NOT OK')
                textobject.setFillColor('black')
                textobject.setFillColor('red') if self.data['colors'][line]['buckling'] == 'red' \
                    else textobject.setFillColor('black')
                textobject.textLine(
                    'Highest buckling utilization: ' +
                    str(round(max(self.data['buckling'][line]), 2)) + ' -> ' +
                    'OK' if max(self.data['buckling'][line]) < 1 else
                    'Highest buckling utilization: ' +
                    str(round(max(self.data['buckling'][line]), 2)) + ' -> ' +
                    'NOT OK')
                textobject.setFillColor('black')
                textobject.setFillColor('red') if self.data['colors'][line]['fatigue'] == 'red' \
                    else textobject.setFillColor('black')
                if self.data['fatigue'][line]['damage'] is not None:
                    textobject.textLine(
                        'Fatigue (plate/stiffeners) utilization: ' +
                        str(round(self.data['fatigue'][line]['damage'], 2)) +
                        ' * DFF(' + str(self.data['fatigue'][line]['dff']) +
                        ') = ' + str(
                            round(
                                self.data['fatigue'][line]['damage'] *
                                self.data['fatigue'][line]['dff'], 2)) +
                        ' (SN-curve = ' + self.data['fatigue'][line]['curve'] +
                        ')')

                else:
                    textobject.textLine('No fatigue results')

                textobject.textLine(
                    'Utilization percentage (highest calculated): ' +
                    str(int(
                        max(self.data['utilization'][line].values()) * 100)) +
                    '%')

                textobject.setFillColor('black')
                self.c.drawText(textobject)
            else:
                textobject.setFont("Helvetica-Oblique", 10)
                textobject.textLine('*********** ' + line + ' ***********')
                textobject.textLine('(no structural properties defined)')
            if vpos <= 290:
                self.c.showPage()
                vpos = 950