Skip to content

Commit 86f3831

Browse files
remove port showing and make it metaports only package
1 parent 24cb8ba commit 86f3831

File tree

2 files changed

+14
-125
lines changed

2 files changed

+14
-125
lines changed

klayout/pymacros/klive.lym

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<text>import pya
1919

2020
from pathlib import Path
21-
from klive_server import server, toggle_ports, update_icon
21+
from klive_server import server, update_icon
2222

2323
app = pya.Application.instance()
2424
mw = app.main_window()
@@ -33,13 +33,6 @@ reset_server.icon_text = "Restart klive"
3333
reset_server.icon = off
3434
menu.insert_item("@toolbar.end", "reset_server", reset_server)
3535

36-
port_action = pya.Action()
37-
port_action.icon = poff
38-
port_action.on_triggered = lambda: toggle_ports(port_action)
39-
port_action.icon_text = "Show Ports"
40-
menu.insert_item("@toolbar.end", "klive_action", port_action)
41-
mw.on_current_view_changed = lambda: update_icon(port_action)
42-
4336
# Start the server
4437
server.reset(reset_server)
4538
</text>

klayout/python/klive_server.py

Lines changed: 13 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
dpolygon_dict = {}
1919
shapes_shown = {}
2020

21-
prefix = "kfactory:ports:"
22-
2321

2422
class ServerInstance(pya.QTcpServer):
2523
"""
@@ -185,58 +183,7 @@ def close(self):
185183
def __del__(self):
186184
self.close()
187185
super(ServerInstance, self).__del__()
188-
189-
190-
@dataclass
191-
class KliveServer:
192-
instance: Optional[ServerInstance] = None
193-
194-
def reset(self, action):
195-
app = pya.Application.instance()
196-
mw = app.main_window()
197-
if self.instance is not None and self.instance.isListening():
198-
self.instance.close()
199-
app.process_events()
200-
sleep(0.1)
201-
self.instance = ServerInstance(self, parent=mw, action=action)
202-
203-
204-
def toggle_ports(action):
205-
acv = pya.CellView.active()
206-
idx = acv.index()
207-
cell = acv.cell
208-
209-
if cell is not None:
210-
cidx = cell.cell_index()
211-
layout = acv.layout()
212-
213-
if idx not in shapes_shown:
214-
shapes_shown[idx] = {}
215-
216-
if cidx in shapes_shown[idx]:
217-
shapes = shapes_shown[idx][cidx]
218-
for layer, shapes in shapes_shown[idx][cidx].items():
219-
lidx = cell.layout().layer(layer)
220-
for shape in shapes:
221-
if cell.shapes(lidx).is_valid(shape):
222-
cell.shapes(lidx).erase(shape)
223-
# del shapes_shown[idx][cidx][lidx]
224-
del shapes_shown[idx][cidx]
225-
update_icon(action)
226-
else:
227-
shapes_shown[idx][cidx] = {}
228-
ports = portdict_from_meta(cell)
229-
for port in ports.values():
230-
shapes = show_port(port, cell)
231-
if port["layer"] not in shapes_shown[idx][cidx]:
232-
shapes_shown[idx][cidx][port["layer"]] = []
233-
234-
shapes_shown[idx][cidx][port["layer"]].extend(shapes)
235-
update_icon(action)
236-
237-
238186
def update_icon(action):
239-
print("updating")
240187
acv = pya.CellView.active()
241188
idx = acv.index()
242189
cell = acv.cell
@@ -252,70 +199,19 @@ def update_icon(action):
252199
action.tool_tip = "Current Status: Hidden"
253200

254201

255-
def portdict_from_meta(cell):
256-
ports = {}
257-
for meta in cell.each_meta_info():
258-
if meta.name.startswith(prefix):
259-
name = meta.name.removeprefix(prefix)
260-
index, _type = name.split(":", 1)
261-
if index not in ports:
262-
ports[index] = {}
263-
264-
if _type == "width":
265-
ports[index]["width"] = meta.value
266-
elif _type == "trans":
267-
ports[index]["trans"] = pya.Trans.from_s(meta.value)
268-
elif _type == "dcplx_trans":
269-
ports[index]["dcplx_trans"] = pya.DCplx_Trans.from_s(meta.value)
270-
elif _type == "layer":
271-
ports[index]["layer"] = pya.LayerInfo.from_string(meta.value)
272-
elif _type == "name":
273-
ports[index]["name"] = meta.value
274-
275-
return ports
276-
277-
278-
def show_port(port, cell):
279-
if "width" in port and "layer" in port and "trans" in port:
280-
lidx = cell.layout().layer(port["layer"])
281-
trans = pya.Trans(port["trans"])
282-
shapes = [
283-
cell.shapes(lidx).insert(get_polygon(port["width"]).transformed(trans))
284-
]
285-
if "name" in port:
286-
shapes.append(cell.shapes(lidx).insert(pya.Text(port["name"], trans)))
287-
return shapes
288-
elif "width" in port and "layer" in port and "dcplx_trans" in port:
289-
lidx = cell.layout().layer(port["layer"])
290-
trans = pya.DCplxTrans(port["dcplx_trans"])
291-
shape = shapes = [
292-
cell.shapes(lidx).insert(
293-
get_polygon(port["width"]).to_dtype(layout.dbu).transformed()
294-
)
295-
]
296-
if "name" in port:
297-
shapes.append(cell.shapes(lidx).insert(pya.DText(port["name"], trans)))
298-
return shapes
299-
300-
301-
def get_polygon(width):
302-
if width in polygon_dict:
303-
return polygon_dict[width]
304-
else:
305-
poly = pya.Polygon(
306-
[
307-
pya.Point(0, width // 2),
308-
pya.Point(0, -width // 2),
309-
pya.Point(width // 2, 0),
310-
]
311-
)
312-
313-
hole = pya.Region(poly).sized(-int(width * 0.05) or -1)
314-
hole -= pya.Region(pya.Box(0, 0, width // 2, -width // 2))
315-
316-
poly.insert_hole(list(list(hole.each())[0].each_point_hull()))
317-
polygon_dict[width] = poly
318-
return poly
202+
@dataclass
203+
class KliveServer:
204+
instance: Optional[ServerInstance] = None
205+
206+
def reset(self, action):
207+
app = pya.Application.instance()
208+
mw = app.main_window()
209+
if self.instance is not None and self.instance.isListening():
210+
self.instance.close()
211+
app.process_events()
212+
sleep(0.1)
213+
self.instance = ServerInstance(self, parent=mw, action=action)
214+
319215

320216

321217
server = KliveServer()

0 commit comments

Comments
 (0)