示例#1
0
def output(ifn, ofn, entities, args):
    opts = []
    if args.contours:
        opts = ['contours']
    if args.markers:
        opts.append('markers')
    sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey}
    sortkey = sorters[args.sort]
    if not args.alllayers:
        layers = dxf.numberedlayers(entities)
        entities = [e for e in entities if dxf.bycode(e, 8) in layers]
    else:
        layers = dxf.layernames(entities)
    num = len(entities)
    if num == 0:
        logging.info("no entities found! Skipping file '{}'.".format(ifn))
        return
    logging.info('{} entities found'.format(num))
    allsegments = lines.mksegments(entities)
    bboxes = [lines.bbox(s) for s in allsegments]
    minx, miny, maxx, maxy = lines.merge_bbox(bboxes)
    out, ctx = plot.setup(ofn, minx, miny, maxx, maxy)
    plot.grid(ctx, minx, miny, maxx, maxy)
    for layername in layers:
        thislayer = dxf.fromlayer(entities, layername)
        segments = lines.mksegments(thislayer)
        ls = '{} entities found in layer "{}".'
        logging.info(ls.format(len(thislayer), layername))
        logging.info('plotting the entities')
        if args.contours:
            closedseg, openseg = lines.combine_segments(segments)
            fs = '{} {} segments in layer "{}"'
            for a, b in (('closed', closedseg), ('open', openseg)):
                logging.info(fs.format(len(b), a, layername))
            openseg.sort(key=sortkey)
            plot.lines(ctx, openseg, marks=args.markers)
            closedseg.sort(key=sortkey)
            plot.lines(ctx, closedseg, marks=args.markers)
        else:
            fs = '{} segments in layer "{}"'
            logging.info(fs.format(len(segments), layername))
            plot.lines(ctx, segments, marks=args.markers)
    plot.title(ctx, 'dxf2pdf', ofn, maxy - miny, options=opts)
    out.show_page()
    logging.info('writing output file "{}"'.format(ofn))
    out.finish()
    logging.info('file "{}" done.'.format(ifn))
示例#2
0
def output(ifn, ofn, entities, args):
    opts = []
    if args.contours:
        opts = ['contours']
    if args.markers:
        opts.append('markers')
    sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey}
    sortkey = sorters[args.sort]
    if not args.alllayers:
        layers = dxf.numberedlayers(entities)
        entities = [e for e in entities if dxf.bycode(e, 8) in layers]
    else:
        layers = dxf.layernames(entities)
    num = len(entities)
    if num == 0:
        logging.info("no entities found! Skipping file '{}'.".format(ifn))
        return
    logging.info('{} entities found'.format(num))
    allsegments = lines.mksegments(entities)
    bboxes = [lines.bbox(s) for s in allsegments]
    minx, miny, maxx, maxy = lines.merge_bbox(bboxes)
    out, ctx = plot.setup(ofn, minx, miny, maxx, maxy)
    plot.grid(ctx, minx, miny, maxx, maxy)
    for layername in layers:
        thislayer = dxf.fromlayer(entities, layername)
        segments = lines.mksegments(thislayer)
        ls = '{} entities found in layer "{}".'
        logging.info(ls.format(len(thislayer), layername))
        logging.info('plotting the entities')
        if args.contours:
            closedseg, openseg = lines.combine_segments(segments)
            fs = '{} {} segments in layer "{}"'
            for a, b in (('closed', closedseg), ('open', openseg)):
                logging.info(fs.format(len(b), a, layername))
            openseg.sort(key=sortkey)
            plot.lines(ctx, openseg, marks=args.markers)
            closedseg.sort(key=sortkey)
            plot.lines(ctx, closedseg, marks=args.markers)
        else:
            fs = '{} segments in layer "{}"'
            logging.info(fs.format(len(segments), layername))
            plot.lines(ctx, segments, marks=args.markers)
    plot.title(ctx, 'dxf2pdf', ofn, maxy - miny, options=opts)
    out.show_page()
    logging.info('writing output file "{}"'.format(ofn))
    out.finish()
    logging.info('file "{}" done.'.format(ifn))
示例#3
0
def test_mksegments_arc():
    arc = [((0, 'ARC'), (5, '35F'), (330, '475'), (100, 'AcDbEntity'),
            (8, 'deel 1'), (100, 'AcDbCircle'), (10, '900.0'),
            (20, '349.9999999999998'), (30, '0.0'), (40, '800.0'), (100,
                                                                    'AcDbArc'),
            (50, '169.1930771251396'), (51, '190.8069228748603'))]
    rv = lines.mksegments(arc)
    ev = [[(114.188, 500.0), (106.316, 450.331), (101.581, 400.265),
           (100.0, 350.0), (101.581, 299.735), (106.316, 249.669),
           (114.188, 200.0)]]
    assert rv[0] == ev[0]
示例#4
0
def test_mksegments_arc():
    arc = [
        (
            (0, 'ARC'), (5, '35F'), (330, '475'), (100, 'AcDbEntity'), (8, 'deel 1'),
            (100, 'AcDbCircle'), (10, '900.0'), (20, '349.9999999999998'), (30, '0.0'),
            (40, '800.0'), (100, 'AcDbArc'), (50, '169.1930771251396'), (51, '190.8069228748603')
        )
    ]
    rv = lines.mksegments(arc)
    ev = [
        [
            (114.188, 500.0), (106.316, 450.331), (101.581, 400.265), (100.0, 350.0),
            (101.581, 299.735), (106.316, 249.669), (114.188, 200.0)
        ]
    ]
    assert rv[0] == ev[0]
示例#5
0
def test_mksegments_line():
    entities = [
        ((0, 'LINE'), (5, '359'), (330, '475'), (100, 'AcDbEntity'),
         (8, 'deel 1'), (100, 'AcDbLine'), (10, '999.9999999999984'),
         (20, '100.0'), (30, '0.0'), (11, '1100.0'), (21, '100.0'), (31,
                                                                     '0.0')),
        ((0, 'LINE'), (5, '35A'), (330, '475'), (100, 'AcDbEntity'),
         (8, 'deel 1'), (100, 'AcDbLine'), (10, '1100.0'), (20, '100.0'),
         (30, '0.0'), (11, '1100.0'), (21, '600.0'), (31, '0.0')),
        ((0, 'LINE'), (5, '35B'), (330, '475'), (100, 'AcDbEntity'),
         (8, 'deel 1'), (100, 'AcDbLine'), (10, '1100.0'), (20, '600.0'),
         (30, '0.0'), (11, '1000.0000001'), (21, '600.0'), (31, '0.0'))
    ]
    segments = lines.mksegments(entities)
    assert segments == [[(1000, 100), (1100, 100)], [(1100, 100), (1100, 600)],
                        [(1100, 600), (1000, 600)]]
示例#6
0
def main():
    """
    Entry point for dxf2nc.py.
    """
    args = process_arguments()
    sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey}
    sortkey = sorters[args.sort]
    lines.epsilon = args.dist
    for f in utils.xpand(args.files):
        logging.info('Starting file "{}"'.format(f))
        try:
            ofn = utils.outname(f, extension='.nc')
            data = dx.parse(f)
            entities = dx.entities(data)
        except ValueError as ex:
            logging.info(str(ex))
            fns = "error during processing. Skipping file '{}'."
            logging.error(fns.format(f))
            continue
        except IOError as ex:
            logging.info(str(ex))
            logging.error("i/o error in file '{}'. Skipping it.".format(f))
            continue
        layers = dx.numberedlayers(entities)
        entities = [e for e in entities if dx.bycode(e, 8) in layers]
        num = len(entities)
        if num == 0:
            logging.info("no entities found! Skipping file '{}'.".format(f))
            continue
        logging.info('{} entities found.'.format(num))
        out = gerbernc.Writer(ofn)
        for layername in layers:
            out.newpiece()
            thislayer = dx.fromlayer(entities, layername)
            ls = '{} entities found in layer "{}".'
            logging.info(ls.format(len(thislayer), layername))
            segments = lines.mksegments(thislayer)
            fs = '{} segments in layer "{}"'
            logging.info(fs.format(len(segments), layername))
            if args.contours:
                cut_contours(segments, out, layername, sortkey)
            else:
                segments.sort(key=sortkey)
                cut_segments(segments, out)
        out.write()
示例#7
0
def main():
    """
    Entry point for dxf2nc.py.
    """
    args = process_arguments()
    sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey}
    sortkey = sorters[args.sort]
    lines.epsilon = args.dist
    for f in utils.xpand(args.files):
        logging.info('Starting file "{}"'.format(f))
        try:
            ofn = utils.outname(f, extension='.nc')
            data = dx.parse(f)
            entities = dx.entities(data)
        except ValueError as ex:
            logging.info(str(ex))
            fns = "error during processing. Skipping file '{}'."
            logging.error(fns.format(f))
            continue
        except IOError as ex:
            logging.info(str(ex))
            logging.error("i/o error in file '{}'. Skipping it.".format(f))
            continue
        layers = dx.numberedlayers(entities)
        entities = [e for e in entities if dx.bycode(e, 8) in layers]
        num = len(entities)
        if num == 0:
            logging.info("no entities found! Skipping file '{}'.".format(f))
            continue
        logging.info('{} entities found.'.format(num))
        out = gerbernc.Writer(ofn)
        for layername in layers:
            out.newpiece()
            thislayer = dx.fromlayer(entities, layername)
            ls = '{} entities found in layer "{}".'
            logging.info(ls.format(len(thislayer), layername))
            segments = lines.mksegments(thislayer)
            fs = '{} segments in layer "{}"'
            logging.info(fs.format(len(segments), layername))
            if args.contours:
                cut_contours(segments, out, layername, sortkey)
            else:
                segments.sort(key=sortkey)
                cut_segments(segments, out)
        out.write()
示例#8
0
def test_mksegments_line():
    entities = [
        (
            (0, 'LINE'), (5, '359'), (330, '475'), (100, 'AcDbEntity'), (8, 'deel 1'),
            (100, 'AcDbLine'), (10, '999.9999999999984'), (20, '100.0'), (30, '0.0'),
            (11, '1100.0'), (21, '100.0'), (31, '0.0')
        ), (
            (0, 'LINE'), (5, '35A'), (330, '475'), (100, 'AcDbEntity'), (8, 'deel 1'),
            (100, 'AcDbLine'), (10, '1100.0'), (20, '100.0'), (30, '0.0'), (11, '1100.0'),
            (21, '600.0'), (31, '0.0')
        ), (
            (0, 'LINE'), (5, '35B'), (330, '475'), (100, 'AcDbEntity'), (8, 'deel 1'),
            (100, 'AcDbLine'), (10, '1100.0'), (20, '600.0'), (30, '0.0'), (11, '1000.0000001'),
            (21, '600.0'), (31, '0.0')
        )
    ]
    segments = lines.mksegments(entities)
    assert segments == [
        [(1000, 100), (1100, 100)], [(1100, 100), (1100, 600)], [(1100, 600), (1000, 600)]
    ]
示例#9
0
def main():
    """
    Entry point for dxfgerber.py.
    """
    args = process_arguments()
    sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey}
    sortkey = sorters[args.sort]
    lines.epsilon = args.dist
    for f in utils.xpand(args.files):
        logging.info('starting file "{}"'.format(f))
        try:
            ofn = utils.outname(f, extension='.dxf', addenum='_mod')
            data = dx.parse(f)
            entities = dx.entities(data)
        except ValueError as ex:
            logging.info(str(ex))
            fns = "error during processing. Skipping file '{}'."
            logging.error(fns.format(f))
            continue
        except IOError as ex:
            logging.info(str(ex))
            logging.error("i/o error in file '{}'. Skipping it.".format(f))
            continue
        layers = dx.numberedlayers(entities)
        entities = [e for e in entities if dx.bycode(e, 8) in layers]
        num = len(entities)
        if num == 0:
            logging.info("no entities found! Skipping file '{}'.".format(f))
            continue
        logging.info('{} entities found.'.format(num))
        with open(ofn, 'w') as out:
            out.write(dxfheader)
            for layername in layers:
                thislayer = dx.fromlayer(entities, layername)
                ls = '{} entities found in layer "{}".'
                logging.info(ls.format(num, layername))
                segments = lines.mksegments(thislayer)
                fs = '{} segments in layer "{}"'
                logging.info(fs.format(len(segments), layername))
                write_allseg(segments, out, layername, sortkey)
            out.write(dxffooter)
示例#10
0
def main():
    """
    Entry point for dxfgerber.py.
    """
    args = process_arguments()
    sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey}
    sortkey = sorters[args.sort]
    lines.epsilon = args.dist
    for f in utils.xpand(args.files):
        logging.info('starting file "{}"'.format(f))
        try:
            ofn = utils.outname(f, extension='.dxf', addenum='_mod')
            data = dx.parse(f)
            entities = dx.entities(data)
        except ValueError as ex:
            logging.info(str(ex))
            fns = "error during processing. Skipping file '{}'."
            logging.error(fns.format(f))
            continue
        except IOError as ex:
            logging.info(str(ex))
            logging.error("i/o error in file '{}'. Skipping it.".format(f))
            continue
        layers = dx.numberedlayers(entities)
        entities = [e for e in entities if dx.bycode(e, 8) in layers]
        num = len(entities)
        if num == 0:
            logging.info("no entities found! Skipping file '{}'.".format(f))
            continue
        logging.info('{} entities found.'.format(num))
        with open(ofn, 'w') as out:
            out.write(dxfheader)
            for layername in layers:
                thislayer = dx.fromlayer(entities, layername)
                ls = '{} entities found in layer "{}".'
                logging.info(ls.format(num, layername))
                segments = lines.mksegments(thislayer)
                fs = '{} segments in layer "{}"'
                logging.info(fs.format(len(segments), layername))
                write_allseg(segments, out, layername, sortkey)
            out.write(dxffooter)