Exemple #1
0
def svg_upload():
    """Parse SVG string."""
    filename = request.forms.get('filename')
    filedata = request.forms.get('filedata')
    dpi_forced = None
    try:
        dpi_forced = float(request.forms.get('dpi'))
    except:
        pass

    optimize = True
    try:
        optimize = bool(int(request.forms.get('optimize')))
    except:
        pass

    if filename and filedata:
        print "You uploaded %s (%d bytes)." % (filename, len(filedata))
        if filename[-4:] in ['.dxf', '.DXF']:
            res = read_dxf(filedata, TOLERANCE, optimize)
        else:
            res = read_svg(filedata, [400, 250], TOLERANCE, dpi_forced,
                           optimize)
        # print boundarys
        jsondata = json.dumps(res)
        # print "returning %d items as %d bytes." % (len(res['boundarys']), len(jsondata))
        return jsondata
    return "You missed a field."
Exemple #2
0
def svg_upload():
    """Parse SVG string."""
    filename = request.forms.get('filename')
    filedata = request.forms.get('filedata')
    dpi_forced = None
    try:
        dpi_forced = float(request.forms.get('dpi'))
    except:
        pass

    optimize = True
    try:
        optimize = bool(int(request.forms.get('optimize')))
    except:
        pass

    if filename and filedata:
        print "You uploaded %s (%d bytes)." % (filename, len(filedata))
        if filename[-4:] in ['.dxf', '.DXF']: 
            res = read_dxf(filedata, TOLERANCE, optimize)
        else:
            res = read_svg(filedata, [1220,610], TOLERANCE, dpi_forced, optimize)
        # print boundarys
        jsondata = json.dumps(res)
        # print "returning %d items as %d bytes." % (len(res['boundarys']), len(jsondata))
        return jsondata
    return "You missed a field."
Exemple #3
0
def file_reader():
    """Parse SVG string."""
    filename = request.forms.get('filename')
    filedata = request.forms.get('filedata')
    dimensions = request.forms.get('dimensions')
    try:
        dimensions = json.loads(dimensions)
    except TypeError:
        dimensions = None
    # print "dims", dimensions[0], ":", dimensions[1]


    dpi_forced = None
    try:
        dpi_forced = float(request.forms.get('dpi'))
    except:
        pass

    dxf_unit = None
    try:
        dxf_unit = int(request.forms.get('dxf_unit'))
        print ("dxf_unit ", dxf_unit)
    except:
        pass

    optimize = True
    try:
        optimize = bool(int(request.forms.get('optimize')))
    except:
        pass

    if filename and filedata:
        print "You uploaded %s (%d bytes)." % (filename, len(filedata))
        if filename[-4:] in ['.dxf', '.DXF']: 
            res = read_dxf(filedata, TOLERANCE, dxf_unit, optimize)
        elif filename[-4:] in ['.svg', '.SVG']: 
            res = read_svg(filedata, dimensions, TOLERANCE, dpi_forced, optimize)
        elif filename[-4:] in ['.lsa', '.LSA']:
            res = read_lsa(filedata, TOLERANCE, optimize)
        elif filename[-4:] in ['.ngc', '.NGC'] or filename[-3:] in ['.nc','.NC','.gc', '.GC']:
            res = read_ngc(filedata, TOLERANCE, optimize)
        else:
            print "error: unsupported file format"
            return "error: unsupported file format"

        # print boundaries
        jsondata = json.dumps(res)
        # print "returning %d items as %d bytes." % (len(res['boundaries']), len(jsondata))
        return jsondata
    return "You missed a field."
Exemple #4
0
def file_reader():
    """Parse SVG string."""
    filename = request.forms.get('filename')
    filedata = request.forms.get('filedata')
    dimensions = request.forms.get('dimensions')
    try:
        dimensions = json.loads(dimensions)
    except TypeError:
        dimensions = None
    # print "dims", dimensions[0], ":", dimensions[1]

    dpi_forced = None
    try:
        dpi_forced = float(request.forms.get('dpi'))
    except:
        pass

    optimize = True
    try:
        optimize = bool(int(request.forms.get('optimize')))
    except:
        pass

    try:
        if filename and filedata:
            print("You uploaded %s (%d bytes)." % (filename, len(filedata)))
            if filename[-4:] in ['.dxf', '.DXF']:
                res = read_dxf(filedata, TOLERANCE, optimize)
            elif filename[-4:] in ['.svg', '.SVG']:
                res = read_svg(filedata, dimensions, TOLERANCE, dpi_forced,
                               optimize)
            elif filename[-4:] in ['.ngc', '.NGC']:
                res = read_ngc(filedata, TOLERANCE, optimize)
            else:
                print("error: unsupported file format")
                return None

            # print boundarys
            jsondata = json.dumps(res)
            # print "returning %d items as %d bytes." % (len(res['boundarys']), len(jsondata))
            return jsondata
    except Exception as e:
        msg = "Failed to parse file" + e.message
        print(msg)
        return msg
    return "You missed a field."
Exemple #5
0
def file_reader():
    """Parse SVG string."""
    filename = request.forms.get("filename")
    filedata = request.forms.get("filedata")
    dimensions = request.forms.get("dimensions")
    try:
        dimensions = json.loads(dimensions)
    except TypeError:
        dimensions = None
    # print "dims", dimensions[0], ":", dimensions[1]

    dpi_forced = None
    try:
        dpi_forced = float(request.forms.get("dpi"))
    except:
        pass

    optimize = True
    try:
        optimize = bool(int(request.forms.get("optimize")))
    except:
        pass

    if filename and filedata:
        print "You uploaded %s (%d bytes)." % (filename, len(filedata))
        if filename[-4:] in [".dxf", ".DXF"]:
            res = read_dxf(filedata, TOLERANCE, optimize)
        elif filename[-4:] in [".svg", ".SVG"]:
            res = read_svg(filedata, dimensions, TOLERANCE, dpi_forced, optimize)
        elif filename[-4:] in [".ngc", ".NGC"]:
            res = read_ngc(filedata, TOLERANCE, optimize)
        else:
            print "error: unsupported file format"

        # print boundarys
        jsondata = json.dumps(res)
        # print "returning %d items as %d bytes." % (len(res['boundarys']), len(jsondata))
        return jsondata
    return "You missed a field."