Exemplo n.º 1
0
    def hdrvars2html(hdrvars, custom_vars):
        """DXF header section as <div> container.
        """
        def vartype(hdrvar):
            if is_point_code(hdrvar.code):
                dim = len(hdrvar.value) - 2
                return ("<point 2D>", "<point 3D>")[dim]
            else:
                return tag_type_str(hdrvar.code)

        varstrings = [
            HEADER_VAR_TPL.format(code=name,
                                  value=escape(ustr(hdrvar.value)),
                                  type=escape(vartype(hdrvar)))
            for name, hdrvar in hdrvars.items()
        ]

        custom_property_strings = [
            CUSTOM_VAR_TPL.format(tag=escape(ustr(tag)),
                                  value=escape(ustr(value)))
            for tag, value in custom_vars
        ]
        varstrings.extend(custom_property_strings)

        return HEADER_SECTION_TPL.format(content="\n".join(varstrings))
Exemplo n.º 2
0
        def tag2html(tag):
            def trim_str(vstr):
                if len(vstr) > MAX_STR_LEN:
                    vstr = vstr[:(MAX_STR_LEN-15)] + " ... " + vstr[-10:]
                return vstr

            if isinstance(tag, PackedTags):
                # inflate packed tags
                return ''.join(tag2html(tag) for tag in tag.dxftags())

            tpl = TAG_TPL
            if tag.code in HANDLE_CODES:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif is_pointer_code(tag.code):  # is handle link
                if tag.value in self.entitydb:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL

            if tag.code in BINARY_FLAGS:
                vstr = with_bitmask(tag.value)
            else:
                if hasattr(tag, 'tostring'):
                    s = tag.tostring()
                else:
                    s = ustr(tag.value)
                vstr = trim_str(s)

            type_str = tag_type_str(tag.code)
            return tpl.format(code=tag.code, value=escape(vstr), type=escape(type_str))
Exemplo n.º 3
0
    def __init__(self):
        self._styles = {}
        self.default = DimStyle('Default')

        self.new("angle.deg",
                 scale=ANGLE_DEG,
                 suffix=ustr('°'),
                 roundval=0,
                 tick="DIMTICK_RADIUS",
                 tick2x=True,
                 dimlineext=0.,
                 dimextline=False)
        self.new("angle.grad",
                 scale=ANGLE_GRAD,
                 suffix='gon',
                 roundval=0,
                 tick="DIMTICK_RADIUS",
                 tick2x=True,
                 dimlineext=0.,
                 dimextline=False)
        self.new("angle.rad",
                 scale=ANGLE_RAD,
                 suffix='rad',
                 roundval=3,
                 tick="DIMTICK_RADIUS",
                 tick2x=True,
                 dimlineext=0.,
                 dimextline=False)
Exemplo n.º 4
0
        def tag2html(tag):
            def trim_str(vstr):
                if len(vstr) > 90:
                    vstr = vstr[:75] + " ... " + vstr[-10:]
                return vstr

            tpl = TAG_TPL
            if tag.code in HANDLE_DEFINITIONS:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif tag.code in HANDLE_LINKS:  # is handle link
                if tag.value in self.entitydb:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL
            vstr = trim_str(ustr(tag.value))
            type_str = tag_type_str(tag.code)
            if type_str == '<bin>':
                if isinstance(tag, CompressedTags):
                    type_str = '<multiple binary encoded data tags compressed to one tag>'
                else:
                    type_str = '<binary encoded data>'
                vstr = ""

            return tpl.format(code=tag.code,
                              value=escape(vstr),
                              type=escape(type_str))
Exemplo n.º 5
0
        def tag2html(tag):
            def trim_str(vstr):
                if len(vstr) > MAX_STR_LEN:
                    vstr = vstr[:(MAX_STR_LEN - 15)] + " ... " + vstr[-10:]
                return vstr

            tpl = TAG_TPL
            if tag.code in HANDLE_CODES:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif is_pointer_code(tag.code):  # is handle link
                if tag.value in self.entitydb:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL

            if tag.code in BINARY_FLAGS:
                vstr = with_bitmask(tag.value)
            else:
                vstr = trim_str(ustr(tag.value))

            type_str = tag_type_str(tag.code)
            if type_str == '<bin>':
                if isinstance(tag, CompressedTags):
                    type_str = '<multiple binary encoded data tags compressed to one tag>'
                else:
                    type_str = '<binary encoded data>'
                vstr = ""

            return tpl.format(code=tag.code,
                              value=escape(vstr),
                              type=escape(type_str))
Exemplo n.º 6
0
 def tag2html(tag):
     type_str = tag_type_str(tag.code)
     if tag.code in BINARY_FLAGS:
         vstr = with_bitmask(tag.value)
     else:
         vstr = ustr(tag.value)
         if tag.code in HEX_HANDLE_CODES:
             vstr = '#' + vstr
     if len(vstr) > MAX_STR_LEN:
         vstr = vstr[:MAX_STR_LEN - 3] + '...'
     return TAG_TPL.format(code=tag.code,
                           value=escape(vstr),
                           type=escape(type_str))
Exemplo n.º 7
0
    def hdrvars2html(hdrvars, custom_vars):
        """DXF header section as <div> container.
        """
        def vartype(hdrvar):
            if is_point_code(hdrvar.code):
                dim = len(hdrvar.value) - 2
                return ("<point 2D>", "<point 3D>")[dim]
            else:
                return tag_type_str(hdrvar.code)

        varstrings = [
            HEADER_VAR_TPL.format(code=name, value=escape(ustr(hdrvar.value)), type=escape(vartype(hdrvar)))
            for name, hdrvar in hdrvars.items()
        ]

        custom_property_strings = [
            CUSTOM_VAR_TPL.format(tag=escape(ustr(tag)), value=escape(ustr(value)))
            for tag, value in custom_vars
        ]
        varstrings.extend(custom_property_strings)

        return HEADER_SECTION_TPL.format(content="\n".join(varstrings))
Exemplo n.º 8
0
        def tag2html(tag):
            def trim_str(vstr):
                if len(vstr) > 90:
                    vstr = vstr[:75] + " ... " + vstr[-10:]
                return vstr

            tpl = TAG_TPL
            if tag.code in HANDLE_DEFINITIONS:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif tag.code in HANDLE_LINKS:  # is handle link
                if tag.value in self.entitydb:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL
            vstr = trim_str(ustr(tag.value))
            type_str = tag_type_str(tag.code)
            if type_str == '<bin>':
                if isinstance(tag, CompressedTags):
                    type_str = '<multiple binary encoded data tags compressed to one tag>'
                else:
                    type_str = '<binary encoded data>'
                vstr = ""

            return tpl.format(code=tag.code, value=escape(vstr), type=escape(type_str))
Exemplo n.º 9
0
 def readline(self):
     next_line = self.dxf_file.readline().replace(WIN_NEW_LINE, NEW_LINE)
     return ustr(next_line, self.encoding)
Exemplo n.º 10
0
 def readline(self):
     next_line = self.dxf_file.readline().replace(WIN_NEW_LINE, NEW_LINE)
     return ustr(next_line, self.encoding)
Exemplo n.º 11
0
 def readline(self):
     next_line = self.dxf_file.readline()
     return ustr(next_line, self.encoding)
Exemplo n.º 12
0
 def append(self, tag, value):
     # custom properties always stored as strings
     self.properties.append((tag, ustr(value)))
Exemplo n.º 13
0
 def _write(name, value):
     tagwriter.write_tag2(9, name)
     tagwriter.write_str(ustr(value))
Exemplo n.º 14
0
 def readline(self):
     next_line = self.dxf_file.readline()
     return ustr(next_line, self.encoding)