Example #1
0
def read_image_file(settings):

    font = Font()

    file_full = settings.get('IMAGE_FILE')
    if not os.path.isfile(file_full):
        return

    fileName, fileExtension = os.path.splitext(file_full)

    if settings.get('useIMGsize'):
        new_origin = False
    else:
        new_origin = True

    segarc = settings.get('segarc')

    filetype = fileExtension.upper()
    if filetype == '.DXF':
        try:
            with open(file_full) as dxf_file:
                # build stroke lists from image file
                font, DXF_source = dxf.parse(dxf_file, segarc, new_origin)
                # font['DXF_source'] = DXF_source
                settings.set('input_type', "image")

        except Exception, e:
            fmessage("Unable To open Drawing Exchange File (DXF) file.")
            fmessage(e)
Example #2
0
def read_image_file(settings):

    font = Font()

    file_full = settings.get('IMAGE_FILE')
    if not os.path.isfile(file_full):
        return

    fileName, fileExtension = os.path.splitext(file_full)

    if settings.get('useIMGsize'):
        new_origin = False
    else:
        new_origin = True

    segarc = settings.get('segarc')

    filetype = fileExtension.upper()
    if filetype == '.DXF':
        try:
            with open(file_full) as dxf_file:
                # build stroke lists from image file
                font, DXF_source = dxf.parse(dxf_file, segarc, new_origin)
                # font['DXF_source'] = DXF_source
                settings.set('input_type', "image")

        except Exception, e:
            fmessage("Unable To open Drawing Exchange File (DXF) file.")
            fmessage(e)
Example #3
0
    def __init__(self, settings):

        self.settings = settings

        fmessage('(F-Engrave Batch Mode)')

        if settings.get('input_type') == "text":
            pass
            # self.readFontFile(self.settings)
        else:
            pass
Example #4
0
    def __init__(self, settings):

        self.settings = settings

        fmessage('(F-Engrave Batch Mode)')

        if settings.get('input_type') == "text":
            pass
            # self.readFontFile(self.settings)
        else:
            pass
Example #5
0
def readFontFile(settings):
    """
    Read a (.cxf, .ttf) font file
    """
    filename = settings.get_fontfile()

    if not os.path.isfile(filename):
        return

    fileName, fileExtension = os.path.splitext(filename)

    segarc = settings.get('segarc')
    TYPE = fileExtension.upper()

    if TYPE == '.CXF':
        with open(filename, 'r', encoding='ISO-8859-1') as fontfile:
            # build stroke lists from font file
            return parse_cxf.parse(fontfile, segarc)

    elif TYPE == '.TTF':
        # convert TTF to CXF
        option = '-e' if settings.get('ext_char') else ''
        cmd = ["ttf2cxf_stream", option, filename, "STDOUT"]
        try:
            p = Popen(cmd, stdout=PIPE, stderr=PIPE)
            stdout, stderr = p.communicate()
            if VERSION == 3:
                fontfile = bytes.decode(stdout).split("\n")
            else:
                fontfile = stdout.split("\n")

            # build stroke lists from font file
            settings.set('input_type', "text")
            return parse_cxf.parse(fontfile, segarc)
        except:
            fmessage("Unable To open True Type (TTF) font file: %s" %
                     (filename))
    else:
        pass
Example #6
0
def readFontFile(settings):
    """
    Read a (.cxf, .ttf) font file
    """
    filename = settings.get_fontfile()

    if not os.path.isfile(filename):
        return

    fileName, fileExtension = os.path.splitext(filename)

    segarc = settings.get('segarc')
    TYPE = fileExtension.upper()

    if TYPE == '.CXF':
        with open(filename, 'r') as fontfile:
            # build stroke lists from font file
            return parse_cxf.parse(fontfile, segarc)

    elif TYPE == '.TTF':
        # convert TTF to CXF
        option = '-e' if settings.get('ext_char') else ''
        cmd = ["ttf2cxf_stream", option, filename, "STDOUT"]
        try:
            p = Popen(cmd, stdout=PIPE, stderr=PIPE)
            stdout, stderr = p.communicate()
            if VERSION == 3:
                fontfile = bytes.decode(stdout).split("\n")
            else:
                fontfile = stdout.split("\n")

            # build stroke lists from font file
            settings.set('input_type', "text")
            return parse_cxf.parse(fontfile, segarc)
        except:
            fmessage("Unable To open True Type (TTF) font file: %s" % (filename))
    else:
        pass
Example #7
0
    def _move_common(self, x=None, y=None, z=None, i=None, j=None, gcode="G0"):
        """
        G0 and G1 moves
        """
        xstring = ystring = zstring = Istring = Jstring = Rstring = fstring = ""
        if x is None:
            x = self.lastx
        if y is None:
            y = self.lasty
        if z is None:
            z = self.lastz

        if (self.feed != self.lastf):
            fstring = self.feed
            self.lastf = self.feed

        FORMAT = "%%.%df" % (self.dp)

        if (gcode == "G2" or gcode == "G3"):
            XC = self.lastx + i
            YC = self.lasty + j
            R_check_1 = sqrt((XC - self.lastx) ** 2 + (YC - self.lasty) ** 2)
            R_check_2 = sqrt((XC - x) ** 2 + (YC - y) ** 2)

            Rstring = " R" + FORMAT % ((R_check_1 + R_check_2) / 2.0)
            if abs(R_check_1 - R_check_2) > Zero:
                fmessage("-- G-Code Curve Fitting Anomaly - Check Output --")
                fmessage("R_start: %f R_end %f" % (R_check_1, R_check_2))
                fmessage("Begining and end radii do not match: delta = %f" % (abs(R_check_1 - R_check_2)))

        if x != self.lastx:
            xstring = " X" + FORMAT % (x)
            self.lastx = x
        if y != self.lasty:
            ystring = " Y" + FORMAT % (y)
            self.lasty = y
        if z != self.lastz:
            zstring = " Z" + FORMAT % (z)
            self.lastz = z
        if i is not None:
            Istring = " I" + FORMAT % (i)
        if j is not None:
            Jstring = " J" + FORMAT % (j)
        if xstring == ystring == zstring == fstring == "":
            return

        if (self.arc_fit == "radius"):
            cmd = "".join([gcode, xstring, ystring, zstring, Rstring, fstring])
        else:
            cmd = "".join([gcode, xstring, ystring, zstring, Istring, Jstring, fstring])

        if cmd:
            self.write(cmd)
Example #8
0
            cmd = [
                "potrace", "-z",
                settings.get('bmp_turnpol'), "-t",
                settings.get('bmp_turdsize'), "-a",
                settings.get('bmp_alphamax'), "-n", "-b", "dxf", file_full,
                "-o", "-"
            ]
            if settings.get('bmp_longcurve'):
                cmd.extend(("-O", settings.get('bmp_opttolerance')))

            cmd = ' '.join(map(str, cmd))
            p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            stdout, stderr = p.communicate()

            if VERSION == 3:
                dxf_file = bytes.decode(stdout).split("\n")
            else:
                dxf_file = stdout.split("\n")

            # build stroke lists from font file
            font, DXF_source = dxf.parse(dxf_file, segarc, new_origin)
            # font['DXF_source'] = DXF_source
            settings.set('input_type', "image")

        except:
            fmessage("Unable To create path data from bitmap File.")
    else:
        fmessage("Unknown filetype: " + fileExtension)

    return font
Example #9
0
    def GET_DXF_DATA(self, fd, tol_deg=20):
        data = []
        try:
            self.read_dxf_data(fd, data)
        except:
            fmessage("\nUnable to read input DXF data!")
            return 1

        data = iter(data)
        g_code, value = None, None
        sections = dict()

        he = Header()
        bl = Blocks()
        while value != "EOF":
            g_code, value = next(data)
            if value == "SECTION":
                g_code, value = next(data)
                sections[value] = []

                while value != "ENDSEC":
                    if value == "HEADER":
                        while True:
                            g_code, value = next(data)
                            if value == "ENDSEC":
                                break
                            elif g_code == 9:
                                he.new_var(value)
                            else:
                                he.new_val((g_code, value))

                    elif value == "BLOCKS":
                        while True:
                            g_code, value = next(data)
                            if value == "ENDSEC":
                                break
                            elif value == "ENDBLK":
                                continue
                            elif value == "BLOCK":
                                bl.new_block()
                            elif g_code == 0 and value != "BLOCK":
                                bl.new_entity(value)
                            else:
                                bl.update((g_code, value))

                    elif value == "ENTITIES":
                        TYPE = ""
                        en = Entities()
                        g_code_last = False
                        while True:
                            g_code, value = next(data)

                            if g_code == 0:
                                TYPE = value
                            if TYPE == "LWPOLYLINE" and g_code == 10 and g_code_last == 20:
                                # Add missing code 42
                                en.update((42, 0.0))
                            g_code_last = g_code

                            if value == "ENDSEC":
                                break
                            elif g_code == 0 and value != "ENDSEC":
                                en.new_entity(value)
                            else:
                                en.update((g_code, value))
                    try:
                        g_code, value = next(data)
                    except:
                        break

        for e in en.entities:
            # LINE ############
            if e.type == "LINE":
                x0 = e.data["10"]
                y0 = e.data["20"]
                x1 = e.data["11"]
                y1 = e.data["21"]
                self.coords.append([x0, y0, x1, y1])
            # ARC #############
            elif e.type == "ARC":
                x = e.data["10"]
                y = e.data["20"]
                r = e.data["40"]
                start = e.data["50"]
                end = e.data["51"]

                if end < start:
                    end = end + 360.0
                delta = end - start
                angle_steps = max(floor(delta / tol_deg), 2)

                start_r = radians(start)
                end_r = radians(end)

                step_phi = radians(delta / angle_steps)
                x0 = x + r * cos(start_r)
                y0 = y + r * sin(start_r)
                pcnt = 1
                while pcnt < angle_steps + 1:
                    phi = start_r + pcnt * step_phi
                    x1 = x + r * cos(phi)
                    y1 = y + r * sin(phi)
                    self.coords.append([x0, y0, x1, y1])
                    x0 = x1
                    y0 = y1
                    pcnt += 1

            # LWPOLYLINE ##########
            elif e.type == "LWPOLYLINE":
                flag = 0
                lpcnt = -1
                for x, y in zip(e.data["10"], e.data["20"]):
                    x1 = x
                    y1 = y
                    lpcnt = lpcnt + 1
                    try:
                        bulge1 = e.data["42"][lpcnt]
                    except:
                        bulge1 = 0

                    if flag == 0:
                        x0 = x1
                        y0 = y1
                        bulge0 = bulge1
                        flag = 1
                    else:
                        if bulge0 != 0:
                            bcoords = self.bulge_coords(
                                x0, y0, x1, y1, bulge0, tol_deg)
                            for line in bcoords:
                                self.coords.append(line)
                        else:
                            self.coords.append([x0, y0, x1, y1])
                        x0 = x1
                        y0 = y1
                        bulge0 = bulge1

                if e.data["70"] != 0:
                    x1 = e.data["10"][0]
                    y1 = e.data["20"][0]
                    if bulge0 != 0:
                        bcoords = self.bulge_coords(x0, y0, x1, y1, bulge1,
                                                    tol_deg)
                        for line in bcoords:
                            self.coords.append(line)
                    else:
                        self.coords.append([x0, y0, x1, y1])

            # CIRCLE ############
            elif e.type == "CIRCLE":
                x = e.data["10"]
                y = e.data["20"]
                r = e.data["40"]

                start = 0
                end = 360
                if end < start:
                    end = end + 360.0
                delta = end - start
                angle_steps = max(floor(delta) / tol_deg, 2)

                start_r = radians(start)
                end_r = radians(end)

                step_phi = radians(delta / angle_steps)
                x0 = x + r * cos(start_r)
                y0 = y + r * sin(start_r)
                pcnt = 1
                while pcnt < angle_steps + 1:
                    phi = start_r + pcnt * step_phi
                    x1 = x + r * cos(phi)
                    y1 = y + r * sin(phi)
                    self.coords.append([x0, y0, x1, y1])
                    x0 = x1
                    y0 = y1
                    pcnt += 1

            # SPLINE ###########
            elif e.type == "SPLINE":
                self.Spline_flag = []
                self.degree = 1
                self.Knots = []
                self.Weights = []
                self.CPoints = []

                self.Spline_flag = int(e.data["70"])
                self.degree = int(e.data["71"])
                self.Knots = e.data["40"]
                try:
                    self.Weights = e.data["41"]
                except:
                    for K in self.Knots:
                        self.Weights.append(1)
                    pass

                for x, y in zip(e.data["10"], e.data["20"]):
                    self.CPoints.append(PointClass(float(x), float(y)))

                self.MYNURBS = NURBSClass(degree=self.degree,
                                          Knots=self.Knots,
                                          Weights=self.Weights,
                                          CPoints=self.CPoints)

                mypoints = self.MYNURBS.calc_curve(n=0, tol_deg=tol_deg)
                flag = 0
                for XY in mypoints:
                    x1 = XY.x
                    y1 = XY.y
                    if flag == 0:
                        x0 = x1
                        y0 = y1
                        flag = 1
                    else:
                        self.coords.append([x0, y0, x1, y1])
                        x0 = x1
                        y0 = y1

            # ELLIPSE ###########
            elif e.type == "ELLIPSE":
                # X and Y center points
                xcp = e.data["10"]
                ycp = e.data["20"]

                # X and Y of major axis end point
                xma = e.data["11"]
                yma = e.data["21"]

                # Ratio of minor axis to major axis
                ratio = e.data["40"]

                # Start and end angles (in radians 0 and 2pi for full ellipse)
                start = degrees(e.data["41"])
                end = degrees(e.data["42"])

                rotation = atan2(yma, xma)
                a = sqrt(xma**2 + yma**2)
                b = a * ratio

                # #################
                if end < start:
                    end = end + 360.0
                delta = end - start

                start_r = radians(start)
                end_r = radians(end)

                tol = radians(tol_deg)

                phi = start_r
                x1 = xcp + (a * cos(phi) * cos(rotation) -
                            b * sin(phi) * sin(rotation))
                y1 = ycp + (a * cos(phi) * sin(rotation) +
                            b * sin(phi) * cos(rotation))
                step = tol
                while phi < end_r:
                    if (phi + step > end_r):
                        step = end_r - phi

                    x2 = xcp + (a * cos(phi + step) * cos(rotation) -
                                b * sin(phi + step) * sin(rotation))
                    y2 = ycp + (a * cos(phi + step) * sin(rotation) +
                                b * sin(phi + step) * cos(rotation))

                    x_test = xcp + (a * cos(phi + step / 2) * cos(rotation) -
                                    b * sin(phi + step / 2) * sin(rotation))
                    y_test = ycp + (a * cos(phi + step / 2) * sin(rotation) +
                                    b * sin(phi + step / 2) * cos(rotation))

                    dx1 = (x_test - x1)
                    dy1 = (y_test - y1)
                    L1 = sqrt(dx1 * dx1 + dy1 * dy1)

                    dx2 = (x2 - x_test)
                    dy2 = (y2 - y_test)
                    L2 = sqrt(dx2 * dx2 + dy2 * dy2)

                    angle = acos(dx1 / L1 * dx2 / L2 + dy1 / L1 * dy2 / L2)

                    if angle > tol:
                        step = step / 2
                    else:
                        phi += step
                        self.coords.append([x1, y1, x2, y2])
                        step = step * 2
                        x1 = x2
                        y1 = y2

            # OLD_ELLIPSE ###########
            elif e.type == "OLD_ELLIPSE":
                # X and Y center points
                xcp = e.data["10"]
                ycp = e.data["20"]
                # X and Y of major axis end point
                xma = e.data["11"]
                yma = e.data["21"]
                # Ratio of minor axis to major axis
                ratio = e.data["40"]
                # Start and end angles (in radians 0 and 2pi for full ellipse)
                start = degrees(e.data["41"])
                end = degrees(e.data["42"])

                rotation = atan2(yma, xma)
                a = sqrt(xma**2 + yma**2)
                b = a * ratio

                ##################
                if end < start:
                    end = end + 360.0
                delta = end - start
                angle_steps = max(floor(delta / tol_deg), 2)

                start_r = radians(start)
                end_r = radians(end)

                step_phi = radians(delta / angle_steps)
                x0 = xcp + (a * cos(start_r) * cos(rotation) -
                            b * sin(start_r) * sin(rotation))
                y0 = ycp + (a * cos(start_r) * sin(rotation) +
                            b * sin(start_r) * cos(rotation))
                pcnt = 1
                while pcnt < angle_steps + 1:
                    phi = start_r + pcnt * step_phi
                    x1 = xcp + (a * cos(phi) * cos(rotation) -
                                b * sin(phi) * sin(rotation))
                    y1 = ycp + (a * cos(phi) * sin(rotation) +
                                b * sin(phi) * cos(rotation))
                    self.coords.append([x0, y0, x1, y1])
                    x0 = x1
                    y0 = y1
                    pcnt += 1

            # LEADER ###########
            elif e.type == "LEADER":
                flag = 0
                for x, y in zip(e.data["10"], e.data["20"]):
                    x1 = x
                    y1 = y
                    if flag == 0:
                        x0 = x1
                        y0 = y1
                        flag = 1
                    else:
                        self.coords.append([x0, y0, x1, y1])
                        x0 = x1
                        y0 = y1

            # POLYLINE ###########
            elif e.type == "POLYLINE":
                self.POLY_CLOSED = 0
                self.POLY_FLAG = -1
                try:
                    TYPE = e.data["70"]
                    if (TYPE == 0 or TYPE == 8):
                        pass
                    elif (TYPE == 1):
                        self.POLY_CLOSED = 1
                    else:
                        fmessage("DXF Import Ignored: - %s - Entity" %
                                 (e.type))
                        self.POLY_FLAG = 0
                except:
                    pass

            # SEQEND ###########
            elif e.type == "SEQEND":
                if (self.POLY_FLAG != 0):
                    self.POLY_FLAG = 0
                    if (self.POLY_CLOSED == 1):
                        self.POLY_CLOSED == 0
                        x0 = self.PX
                        y0 = self.PY
                        x1 = self.PX0
                        y1 = self.PY0

                        if self.bulge != 0:
                            bcoords = self.bulge_coords(
                                x0, y0, x1, y1, self.bulge, tol_deg)
                            for line in bcoords:
                                self.coords.append(line)
                        else:
                            self.coords.append([x0, y0, x1, y1])

                else:
                    fmessage("DXF Import Ignored: - %s - Entity" % (e.type))

            # VERTEX ###########
            elif e.type == "VERTEX":

                if (self.POLY_FLAG == -1):
                    self.PX = e.data["10"]
                    self.PY = e.data["20"]
                    self.PX0 = self.PX
                    self.PY0 = self.PY
                    try:
                        self.bulge = e.data["42"]
                    except:
                        self.bulge = 0

                    self.POLY_FLAG = 1
                elif (self.POLY_FLAG == 1):
                    x0 = self.PX
                    y0 = self.PY
                    x1 = e.data["10"]
                    y1 = e.data["20"]
                    self.PX = x1
                    self.PY = y1

                    if self.bulge != 0:
                        bcoords = self.bulge_coords(x0, y0, x1, y1, self.bulge,
                                                    tol_deg)
                        for line in bcoords:
                            self.coords.append(line)
                    else:
                        self.coords.append([x0, y0, x1, y1])

                    try:
                        self.bulge = e.data["42"]
                    except:
                        self.bulge = 0
                else:
                    fmessage("DXF Import Ignored: - %s - Entity" % (e.type))
                    pass
            # END VERTEX ###########
            else:
                fmessage("DXF Import Ignored: %s Entity" % (e.type))
                pass
Example #10
0
            # cmd = ["potrace","-b","dxf",file_full,"-o","-"]
            cmd = ["potrace",
                   "-z", settings.get('bmp_turnpol'),
                   "-t", settings.get('bmp_turdsize'),
                   "-a", settings.get('bmp_alphamax'),
                   "-n",
                   "-b", "dxf", file_full, "-o", "-"]
            if settings.get('bmp_longcurve'):
                cmd.extend(("-O", settings.get('bmp_opttolerance')))

            cmd = ' '.join(map(str, cmd))
            p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            stdout, stderr = p.communicate()

            if VERSION == 3:
                dxf_file = bytes.decode(stdout).split("\n")
            else:
                dxf_file = stdout.split("\n")

            # build stroke lists from font file
            font, DXF_source = dxf.parse(dxf_file, segarc, new_origin)
            # font['DXF_source'] = DXF_source
            settings.set('input_type', "image")

        except:
            fmessage("Unable To create path data from bitmap File.")
    else:
        fmessage("Unknown filetype: " + fileExtension)

    return font
Example #11
0
    def GET_DXF_DATA(self, fd, tol_deg=20):
        data = []
        try:
            self.read_dxf_data(fd, data)
        except:
            fmessage("\nUnable to read input DXF data!")
            return 1

        data = iter(data)
        g_code, value = None, None
        sections = dict()

        he = Header()
        bl = Blocks()
        while value != "EOF":
            g_code, value = next(data)
            if value == "SECTION":
                g_code, value = next(data)
                sections[value] = []

                while value != "ENDSEC":
                    if value == "HEADER":
                        while True:
                            g_code, value = next(data)
                            if value == "ENDSEC":
                                break
                            elif g_code == 9:
                                he.new_var(value)
                            else:
                                he.new_val((g_code, value))

                    elif value == "BLOCKS":
                        while True:
                            g_code, value = next(data)
                            if value == "ENDSEC":
                                break
                            elif value == "ENDBLK":
                                continue
                            elif value == "BLOCK":
                                bl.new_block()
                            elif g_code == 0 and value != "BLOCK":
                                bl.new_entity(value)
                            else:
                                bl.update((g_code, value))

                    elif value == "ENTITIES":
                        TYPE = ""
                        en = Entities()
                        g_code_last = False
                        while True:
                            g_code, value = next(data)

                            if g_code == 0:
                                TYPE = value
                            if TYPE == "LWPOLYLINE" and g_code == 10 and g_code_last == 20:
                                # Add missing code 42
                                en.update((42, 0.0))
                            g_code_last = g_code

                            if value == "ENDSEC":
                                break
                            elif g_code == 0 and value != "ENDSEC":
                                en.new_entity(value)
                            else:
                                en.update((g_code, value))
                    try:
                        g_code, value = next(data)
                    except:
                        break

        for e in en.entities:
            # LINE ############
            if e.type == "LINE":
                x0 = e.data["10"]
                y0 = e.data["20"]
                x1 = e.data["11"]
                y1 = e.data["21"]
                self.coords.append([x0, y0, x1, y1])
            # ARC #############
            elif e.type == "ARC":
                x = e.data["10"]
                y = e.data["20"]
                r = e.data["40"]
                start = e.data["50"]
                end = e.data["51"]

                if end < start:
                    end = end + 360.0
                delta = end - start
                angle_steps = max(floor(delta / tol_deg), 2)

                start_r = radians(start)
                end_r = radians(end)

                step_phi = radians(delta / angle_steps)
                x0 = x + r * cos(start_r)
                y0 = y + r * sin(start_r)
                pcnt = 1
                while pcnt < angle_steps + 1:
                    phi = start_r + pcnt * step_phi
                    x1 = x + r * cos(phi)
                    y1 = y + r * sin(phi)
                    self.coords.append([x0, y0, x1, y1])
                    x0 = x1
                    y0 = y1
                    pcnt += 1

            # LWPOLYLINE ##########
            elif e.type == "LWPOLYLINE":
                flag = 0
                lpcnt = -1
                for x, y in zip(e.data["10"], e.data["20"]):
                    x1 = x
                    y1 = y
                    lpcnt = lpcnt + 1
                    try:
                        bulge1 = e.data["42"][lpcnt]
                    except:
                        bulge1 = 0

                    if flag == 0:
                        x0 = x1
                        y0 = y1
                        bulge0 = bulge1
                        flag = 1
                    else:
                        if bulge0 != 0:
                            bcoords = self.bulge_coords(x0, y0, x1, y1, bulge0, tol_deg)
                            for line in bcoords:
                                self.coords.append(line)
                        else:
                            self.coords.append([x0, y0, x1, y1])
                        x0 = x1
                        y0 = y1
                        bulge0 = bulge1

                if e.data["70"] != 0:
                    x1 = e.data["10"][0]
                    y1 = e.data["20"][0]
                    if bulge0 != 0:
                        bcoords = self.bulge_coords(x0, y0, x1, y1, bulge1, tol_deg)
                        for line in bcoords:
                            self.coords.append(line)
                    else:
                        self.coords.append([x0, y0, x1, y1])

            # CIRCLE ############
            elif e.type == "CIRCLE":
                x = e.data["10"]
                y = e.data["20"]
                r = e.data["40"]

                start = 0
                end = 360
                if end < start:
                    end = end + 360.0
                delta = end - start
                angle_steps = max(floor(delta) / tol_deg, 2)

                start_r = radians(start)
                end_r = radians(end)

                step_phi = radians(delta / angle_steps)
                x0 = x + r * cos(start_r)
                y0 = y + r * sin(start_r)
                pcnt = 1
                while pcnt < angle_steps + 1:
                    phi = start_r + pcnt * step_phi
                    x1 = x + r * cos(phi)
                    y1 = y + r * sin(phi)
                    self.coords.append([x0, y0, x1, y1])
                    x0 = x1
                    y0 = y1
                    pcnt += 1

            # SPLINE ###########
            elif e.type == "SPLINE":
                self.Spline_flag = []
                self.degree = 1
                self.Knots = []
                self.Weights = []
                self.CPoints = []

                self.Spline_flag = int(e.data["70"])
                self.degree = int(e.data["71"])
                self.Knots = e.data["40"]
                try:
                    self.Weights = e.data["41"]
                except:
                    for K in self.Knots:
                        self.Weights.append(1)
                    pass

                for x, y in zip(e.data["10"], e.data["20"]):
                    self.CPoints.append(PointClass(float(x), float(y)))

                self.MYNURBS = NURBSClass(degree=self.degree,
                                          Knots=self.Knots,
                                          Weights=self.Weights,
                                          CPoints=self.CPoints)

                mypoints = self.MYNURBS.calc_curve(n=0, tol_deg=tol_deg)
                flag = 0
                for XY in mypoints:
                    x1 = XY.x
                    y1 = XY.y
                    if flag == 0:
                        x0 = x1
                        y0 = y1
                        flag = 1
                    else:
                        self.coords.append([x0, y0, x1, y1])
                        x0 = x1
                        y0 = y1

            # ELLIPSE ###########
            elif e.type == "ELLIPSE":
                # X and Y center points
                xcp = e.data["10"]
                ycp = e.data["20"]

                # X and Y of major axis end point
                xma = e.data["11"]
                yma = e.data["21"]

                # Ratio of minor axis to major axis
                ratio = e.data["40"]

                # Start and end angles (in radians 0 and 2pi for full ellipse)
                start = degrees(e.data["41"])
                end = degrees(e.data["42"])

                rotation = atan2(yma, xma)
                a = sqrt(xma ** 2 + yma ** 2)
                b = a * ratio

                # #################
                if end < start:
                    end = end + 360.0
                delta = end - start

                start_r = radians(start)
                end_r = radians(end)

                tol = radians(tol_deg)

                phi = start_r
                x1 = xcp + (a * cos(phi) * cos(rotation) - b * sin(phi) * sin(rotation))
                y1 = ycp + (a * cos(phi) * sin(rotation) + b * sin(phi) * cos(rotation))
                step = tol
                while phi < end_r:
                    if (phi + step > end_r):
                        step = end_r - phi

                    x2 = xcp + (a * cos(phi + step) * cos(rotation) - b * sin(phi + step) * sin(rotation))
                    y2 = ycp + (a * cos(phi + step) * sin(rotation) + b * sin(phi + step) * cos(rotation))

                    x_test = xcp + (a * cos(phi + step / 2) * cos(rotation) - b * sin(phi + step / 2) * sin(rotation))
                    y_test = ycp + (a * cos(phi + step / 2) * sin(rotation) + b * sin(phi + step / 2) * cos(rotation))

                    dx1 = (x_test - x1)
                    dy1 = (y_test - y1)
                    L1 = sqrt(dx1 * dx1 + dy1 * dy1)

                    dx2 = (x2 - x_test)
                    dy2 = (y2 - y_test)
                    L2 = sqrt(dx2 * dx2 + dy2 * dy2)

                    angle = acos(dx1 / L1 * dx2 / L2 + dy1 / L1 * dy2 / L2)

                    if angle > tol:
                        step = step / 2
                    else:
                        phi += step
                        self.coords.append([x1, y1, x2, y2])
                        step = step * 2
                        x1 = x2
                        y1 = y2

            # OLD_ELLIPSE ###########
            elif e.type == "OLD_ELLIPSE":
                # X and Y center points
                xcp = e.data["10"]
                ycp = e.data["20"]
                # X and Y of major axis end point
                xma = e.data["11"]
                yma = e.data["21"]
                # Ratio of minor axis to major axis
                ratio = e.data["40"]
                # Start and end angles (in radians 0 and 2pi for full ellipse)
                start = degrees(e.data["41"])
                end = degrees(e.data["42"])

                rotation = atan2(yma, xma)
                a = sqrt(xma ** 2 + yma ** 2)
                b = a * ratio

                ##################
                if end < start:
                    end = end + 360.0
                delta = end - start
                angle_steps = max(floor(delta / tol_deg), 2)

                start_r = radians(start)
                end_r = radians(end)

                step_phi = radians(delta / angle_steps)
                x0 = xcp + (a * cos(start_r) * cos(rotation) - b * sin(start_r) * sin(rotation))
                y0 = ycp + (a * cos(start_r) * sin(rotation) + b * sin(start_r) * cos(rotation))
                pcnt = 1
                while pcnt < angle_steps + 1:
                    phi = start_r + pcnt * step_phi
                    x1 = xcp + (a * cos(phi) * cos(rotation) - b * sin(phi) * sin(rotation))
                    y1 = ycp + (a * cos(phi) * sin(rotation) + b * sin(phi) * cos(rotation))
                    self.coords.append([x0, y0, x1, y1])
                    x0 = x1
                    y0 = y1
                    pcnt += 1

            # LEADER ###########
            elif e.type == "LEADER":
                flag = 0
                for x, y in zip(e.data["10"], e.data["20"]):
                    x1 = x
                    y1 = y
                    if flag == 0:
                        x0 = x1
                        y0 = y1
                        flag = 1
                    else:
                        self.coords.append([x0, y0, x1, y1])
                        x0 = x1
                        y0 = y1

            # POLYLINE ###########
            elif e.type == "POLYLINE":
                self.POLY_CLOSED = 0
                self.POLY_FLAG = -1
                try:
                    TYPE = e.data["70"]
                    if (TYPE == 0 or TYPE == 8):
                        pass
                    elif (TYPE == 1):
                        self.POLY_CLOSED = 1
                    else:
                        fmessage("DXF Import Ignored: - %s - Entity" % (e.type))
                        self.POLY_FLAG = 0
                except:
                    pass

            # SEQEND ###########
            elif e.type == "SEQEND":
                if (self.POLY_FLAG != 0):
                    self.POLY_FLAG = 0
                    if (self.POLY_CLOSED == 1):
                        self.POLY_CLOSED == 0
                        x0 = self.PX
                        y0 = self.PY
                        x1 = self.PX0
                        y1 = self.PY0

                        if self.bulge != 0:
                            bcoords = self.bulge_coords(x0, y0, x1, y1, self.bulge, tol_deg)
                            for line in bcoords:
                                self.coords.append(line)
                        else:
                            self.coords.append([x0, y0, x1, y1])

                else:
                    fmessage("DXF Import Ignored: - %s - Entity" % (e.type))

            # VERTEX ###########
            elif e.type == "VERTEX":

                if (self.POLY_FLAG == -1):
                    self.PX = e.data["10"]
                    self.PY = e.data["20"]
                    self.PX0 = self.PX
                    self.PY0 = self.PY
                    try:
                        self.bulge = e.data["42"]
                    except:
                        self.bulge = 0

                    self.POLY_FLAG = 1
                elif (self.POLY_FLAG == 1):
                    x0 = self.PX
                    y0 = self.PY
                    x1 = e.data["10"]
                    y1 = e.data["20"]
                    self.PX = x1
                    self.PY = y1

                    if self.bulge != 0:
                        bcoords = self.bulge_coords(x0, y0, x1, y1, self.bulge, tol_deg)
                        for line in bcoords:
                            self.coords.append(line)
                    else:
                        self.coords.append([x0, y0, x1, y1])

                    try:
                        self.bulge = e.data["42"]
                    except:
                        self.bulge = 0
                else:
                    fmessage("DXF Import Ignored: - %s - Entity" % (e.type))
                    pass
            # END VERTEX ###########
            else:
                fmessage("DXF Import Ignored: %s Entity" % (e.type))
                pass