Skip to content

Commit bf819ca

Browse files
authored
Merge pull request #2560 from The-OpenROAD-Project-staging/update-convertDrc
Update convertDrc.py to the new json format
2 parents 236184e + ab8cd4e commit bf819ca

File tree

1 file changed

+136
-62
lines changed

1 file changed

+136
-62
lines changed

flow/util/convertDrc.py

Lines changed: 136 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,142 @@
11
# This is a KLayout script to load a RVE DRC rpt file
22
# and write out a json the DRC viewer can read.
33

4+
import os
45
import pya
5-
66
import json
77

8+
def convert_drc(rdb):
9+
source = os.path.abspath(in_drc)
10+
11+
ordb = {
12+
"source": source,
13+
"description": "KLayout DRC conversion",
14+
"category": {}
15+
}
16+
17+
for category in rdb.each_category():
18+
if category.num_items() == 0:
19+
# ignore categories with no data
20+
continue
21+
22+
ordb_category = {
23+
"description": category.description,
24+
"source": source,
25+
"violations": []
26+
}
27+
ordb["category"][category.name()] = ordb_category
28+
29+
for item in rdb.each_item_per_category(category.rdb_id()):
30+
violation = {
31+
"visited": item.is_visited(),
32+
"visible": True,
33+
"waived": "waived" in item.tags_str
34+
}
35+
36+
ordb_category["violations"].append(violation)
37+
38+
shapes = []
39+
violation["shape"] = shapes
40+
41+
text = []
42+
43+
for value in item.each_value():
44+
if value.is_box():
45+
shapes.append({
46+
"type": "box",
47+
"points": [{
48+
"x": value.box().left,
49+
"y": value.box().bottom
50+
}, {
51+
"x": value.box().right,
52+
"y": value.box().top
53+
}]
54+
})
55+
elif value.is_edge():
56+
shapes.append({
57+
"type": "line",
58+
"points": [{
59+
"x": value.edge().p1.x,
60+
"y": value.edge().p1.y
61+
}, {
62+
"x": value.edge().p2.x,
63+
"y": value.edge().p2.y
64+
}]
65+
})
66+
elif value.is_edge_pair():
67+
edge1 = value.edge_pair().first
68+
edge2 = value.edge_pair().second
69+
70+
shapes.append({
71+
"type": "line",
72+
"points": [{
73+
"x": edge1.p1.x,
74+
"y": edge1.p1.y
75+
}, {
76+
"x": edge1.p2.x,
77+
"y": edge1.p2.y
78+
}]
79+
})
80+
shapes.append({
81+
"type": "line",
82+
"points": [{
83+
"x": edge2.p1.x,
84+
"y": edge2.p1.y
85+
}, {
86+
"x": edge2.p2.x,
87+
"y": edge2.p2.y
88+
}]
89+
})
90+
elif value.is_polygon():
91+
points = []
92+
for edge in value.polygon().each_edge():
93+
points.append({
94+
"x": edge.p1.x,
95+
"y": edge.p1.y
96+
})
97+
points.append({
98+
"x": edge.p2.x,
99+
"y": edge.p2.y
100+
})
101+
shapes.append({
102+
"type": "polygon",
103+
"points": points
104+
})
105+
elif value.is_path():
106+
points = []
107+
for edge in value.path().polygon().each_edge():
108+
points.append({
109+
"x": edge.p1.x,
110+
"y": edge.p1.y
111+
})
112+
points.append({
113+
"x": edge.p2.x,
114+
"y": edge.p2.y
115+
})
116+
shapes.append({
117+
"type": "polygon",
118+
"points": points
119+
})
120+
elif value.is_text():
121+
text.append(value.text())
122+
elif value.is_string():
123+
text.append(value.string())
124+
else:
125+
print("[WARN] Unknown violation shape:", value)
126+
127+
comment = ""
128+
if hasattr(item, 'comment'):
129+
comment = item.comment
130+
if text:
131+
if comment:
132+
comment += ": "
133+
comment += ", ".join(text)
134+
135+
if comment:
136+
violation["comment"] = comment
137+
138+
return ordb
139+
8140
app = pya.Application.instance()
9141
win = app.main_window()
10142

@@ -16,68 +148,10 @@
16148
rdb = layout_view.rdb(rdb_id)
17149
rdb.load(in_drc)
18150

19-
violations = []
20-
21-
for category in rdb.each_category():
22-
if category.num_items() == 0:
23-
# ignore categories with no data
24-
continue
25-
26-
violations_shapes = []
27-
for item in rdb.each_item_per_category(category.rdb_id()):
28-
for value in item.each_value():
29-
if value.is_box():
30-
violations_shapes.append(
31-
{
32-
"type": "box",
33-
"shape": [
34-
{"x": value.box().left, "y": value.box().bottom},
35-
{"x": value.box().right, "y": value.box().top},
36-
],
37-
}
38-
)
39-
elif value.is_edge():
40-
violations_shapes.append(
41-
{
42-
"type": "edge",
43-
"shape": [
44-
{"x": value.edge().p1.x, "y": value.edge().p1.y},
45-
{"x": value.edge().p2.x, "y": value.edge().p2.y},
46-
],
47-
}
48-
)
49-
elif value.is_edge_pair():
50-
edge1 = value.edge_pair().first
51-
edge2 = value.edge_pair().second
52-
violations_shapes.append(
53-
{
54-
"type": "edge_pair",
55-
"shape": [
56-
{"x": edge1.p1.x, "y": edge1.p1.y},
57-
{"x": edge1.p2.x, "y": edge1.p2.y},
58-
{"x": edge2.p1.x, "y": edge2.p1.y},
59-
{"x": edge2.p2.x, "y": edge2.p2.y},
60-
],
61-
}
62-
)
63-
elif value.is_polygon():
64-
points = []
65-
for edge in value.polygon().each_edge():
66-
points.append({"x": edge.p1.x, "y": edge.p1.y})
67-
points.append({"x": edge.p2.x, "y": edge.p2.y})
68-
violations_shapes.append({"type": "polygon", "shape": points})
69-
else:
70-
print("Unknown violation shape:", value)
71-
72-
violations.append(
73-
{
74-
"name": category.name(),
75-
"description": category.description,
76-
"violations": violations_shapes,
77-
}
78-
)
151+
ordb = {}
152+
ordb["DRC"] = convert_drc(rdb)
79153

80154
with open(out_file, "w") as outfile:
81-
json.dump({"DRC": violations}, outfile)
155+
json.dump(ordb, outfile)
82156

83157
app.exit(0)

0 commit comments

Comments
 (0)