예제 #1
0
파일: dim_base.py 프로젝트: vshu3000/ezdxf
def format_text(value: float,
                dimrnd: float = None,
                dimdec: int = None,
                dimzin: int = 0,
                dimdsep: str = '.',
                dimpost: str = '<>') -> str:
    if dimrnd is not None:
        value = xround(value, dimrnd)

    if dimdec is None:
        fmt = "{:f}"
        dimzin = dimzin | 8  # remove pending zeros for undefined decimal places, '{:f}'.format(0) -> '0.000000'
    else:
        fmt = "{:." + str(dimdec) + "f}"
    text = fmt.format(value)

    leading = bool(dimzin & 4)
    pending = bool(dimzin & 8)
    text = suppress_zeros(text, leading, pending)
    if dimdsep != '.':
        text = text.replace('.', dimdsep)
    if dimpost:
        if '<>' in dimpost:
            fmt = dimpost.replace('<>', '{}', 1)
            text = fmt.format(text)
        else:
            raise DXFValueError('Invalid dimpost string: "{}"'.format(dimpost))
    return text
예제 #2
0
 def dms_format(_value: float) -> str:
     if dimrnd is not None:
         _value = xround(_value, dimrnd)
     d, m, s = decdeg2dms(_value)
     if dimdec > 4:
         places = dimdec - 5
         s = round(s, places)
         return f"{d:.0f}°{m:.0f}'{decimal_format(s)}\""
     if dimdec > 2:
         return f"{d:.0f}°{m:.0f}'{s:.0f}\""
     if dimdec > 0:
         return f"{d:.0f}°{m:.0f}'"
     return f"{d:.0f}°"
예제 #3
0
def test_xround():
    assert xround(9.999, 0.) == 10
    assert xround(9.999, 0.5) == 10
    assert xround(9.75, 0.5) == 10
    assert xround(9.74, 0.5) == 9.5
    assert xround(9.74, 0.25) == 9.75
    assert xround(9.626, 0.25) == 9.75
    assert xround(9.624, 0.25) == 9.50
    assert xround(9.624, 0.1) == 9.6
    assert xround(9.624, 0.01) == 9.62
    assert xround(9.626, 0.01) == 9.63
    assert xround(9.626, 0.05) == 9.65

    assert xround(19.1, 1.) == 19
    assert xround(19.1, 2.) == 20
    assert xround(18.9, 2.) == 18
    assert xround(18.9, 5.) == 20
    assert xround(18.9, 10) == 20
    assert xround(1234, 10) == 1230
    assert xround(1236, 10) == 1240
예제 #4
0
파일: parse.py 프로젝트: tehnology/parseF23
def main(path):
    stem = path.stem
    name = Path(stem).with_suffix('.dxf')
    doc = ezdxf.new('R2000')
    msp = doc.modelspace()

    pts = []
    switch = 0
    operation = ''  # VREZKA, CUT, VYHOD
    sum_area = 0

    with open(path) as f:
        for line in f:

            if 'LP' in line:

                b = get_data(line, 'SA')
                l = get_data(line, 'LP')

                msp.add_lwpolyline(((0, 0), (0, b), (l, b), (l, 0)),
                                   close=True)
                list_area = area([(0, 0), (0, b), (l, b), (l, 0)])

                continue

            if 'ANG' in line:
                line = line.strip('[MARK] ')

                msp.add_text(get_data(line, 'N:'),
                             dxfattribs={
                                 'height': 10,
                                 'rotation': get_data(line, 'ANG'),
                                 'color': 120
                             }).set_pos(
                                 [get_data(line, 'X'),
                                  get_data(line, 'Y')],
                                 align='TOP_LEFT')

                print('MARK: ', line, end='')
                continue

            if 'TS33' in line:
                line = line.strip('[HOL] ')
                print('HOLE: ', line, end='')

                msp.add_circle([get_data(line, 'X'),
                                get_data(line, 'Y')],
                               get_data(line, 'DC') / 2)

                continue

            if all(i in line for i in ('R', 'X', 'Y')) or 'LEAD' in line:
                line = line.strip('[CUT] ')
                switch += 1
                operation = 'CUT'

                if pts:
                    # pts.append(get_new_pt(line, pts[-1], get_data(line, 'R')))
                    pts = fix_pts(pts, line)
                else:
                    pts.append((get_data(line, 'X'), get_data(line, 'Y')))
                # print(get_data(line, 'X'))
                # print(get_data(line, 'Y'))
                # print(get_data(line, 'R'))
                # print(get_new_pt(line, pts[-1], get_data(line, 'R')))

                print(line, end='')
                print(operation)
                print(pts)
                print(switch, end='\n**********************\n')

                if 'LEAD' in line:
                    line = line.strip('[LEAD] ')
                    operation = 'VREZKA'

                    print(line, end='')
                    print(operation)
                    print(pts)
                    print(switch, end='\n**********************\n')

                    continue

                if 'SR1401' in line:
                    switch = 3333

                    print(line, end='')
                    print(operation)
                    print(pts)
                    print(switch, end='\n**********************\n')
                    continue

                if switch == 3335:
                    pts_vhod = [pts.pop(0), pts[0]]
                    pts_vyhod = [pts[-2], pts.pop(-1)]
                    msp.add_lwpolyline(pts_vhod,
                                       format='xyb',
                                       dxfattribs={'color': 11})
                    msp.add_lwpolyline(pts_vyhod,
                                       format='xyb',
                                       dxfattribs={'color': 140})
                    msp.add_lwpolyline(
                        pts,
                        format='xyb',
                    )
                    sum_area += area(pts)
                    pts = []

                    print('AREA: ', sum_area)
                    if list_area:
                        othod = list_area - sum_area
                        print('Отход от чистого:',
                              xround((othod / sum_area), 0.01))
                        print('Отход от грязного:',
                              xround((othod / list_area), 0.01))

            # if 'LEAD' in line:
            #     line = line.strip('[LEAD] ')
            #     start_vrez = (get_data(line, 'X'), get_data(line, 'Y'))
            #     operation = 'VREZKA'
            #     switch += 1
            #     continue
            #
            # if 'SR1401' in line:
            #     switch = 3333
            #
            # if all(i in line for i in('R', 'X', 'Y')):
            #     line = line.strip('[CUT] ')
            #     switch += 1
            #
            #
            #     if operation == 'VREZKA':
            #         # end_vrez = (get_data(line, 'X'), get_data(line, 'Y'), get_data(line, 'R'))
            #         end_vrez = (get_new_pt(line, start_vrez, get_data(line, 'R')))
            #         # msp.add_line(start_vrez, end_vrez, dxfattribs={'color': 11})
            #         msp.add_lwpolyline(pts, format='xyb', dxfattribs={'color': 11})
            #         # pts.append(end_vrez)
            #         operation = 'CUT'
            #
            #     if operation == 'CUT' and switch <= 3334:
            #         # pts.append((get_data(line, 'X'), get_data(line, 'Y'), get_data(line, 'R')))
            #         # pts.append(get_new_pt(line, pts[-1], get_data(line, 'R')))
            #         pass
            #
            #     elif operation == 'CUT' and switch > 3334:
            #         start_vyhod = (get_data(line, 'X'), get_data(line, 'Y'), get_data(line, 'R'))
            #         pts.append(start_vyhod)
            #         msp.add_lwpolyline(pts, format='xyb')
            #         pts = []
            #         operation = 'VYHOD'
            #
            #     if operation == 'VYHOD':
            #         end_vyhod = (get_data(line, 'X'), get_data(line, 'Y'))
            #         # end_vyhod = get_new_pt(line, pts[-1], get_data(line, 'R'))
            #         msp.add_line(start_vyhod, end_vyhod, dxfattribs={'color': 140})
            #         switch = 1
            #     # elif operation == 'CUT' and sr != 2:
            #     #     pts.append((get_data(line, 'X'), get_data(line, 'Y')))
            #     #     sr += 1
            #
            #     # print(pts)
            #     continue
    # msp.add_line([0,0], [500,500])
    # msp.add_circle([0,0], 50)
    # msp.add_text([50,0],'DSFSDFSD')
    doc.saveas(name)