# -*- coding: utf-8 -*-
"""Pass 2: LINE/ARC 전체 기하를 뽑는다(부재 외곽선의 실제 정체)."""
import json, time
from ezdxf.addons import iterdxf
import product          # 제품 고유값 모음 — 기본값 500pro
SCR = product.SCR
lines, arcs = [], []
t0 = time.time()
doc = iterdxf.opendxf(product.DXF)
try:
    for e in doc.modelspace():
        dt = e.dxftype()
        try:
            if dt == 'LINE':
                s, t = e.dxf.start, e.dxf.end
                lines.append([round(s.x,4), round(s.y,4), round(t.x,4), round(t.y,4), e.dxf.layer])
            elif dt == 'ARC':
                c = e.dxf.center
                arcs.append([round(c.x,4), round(c.y,4), round(e.dxf.radius,4),
                             round(e.dxf.start_angle,4), round(e.dxf.end_angle,4), e.dxf.layer])
        except Exception:
            pass
finally:
    doc.close()
print('lines', len(lines), 'arcs', len(arcs), '%.0fs' % (time.time()-t0))
json.dump({'lines': lines, 'arcs': arcs}, open(SCR + r'\index2.json', 'w', encoding='utf-8'))
