18
18
dpolygon_dict = {}
19
19
shapes_shown = {}
20
20
21
- prefix = "kfactory:ports:"
22
-
23
21
24
22
class ServerInstance (pya .QTcpServer ):
25
23
"""
@@ -185,58 +183,7 @@ def close(self):
185
183
def __del__ (self ):
186
184
self .close ()
187
185
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
-
238
186
def update_icon (action ):
239
- print ("updating" )
240
187
acv = pya .CellView .active ()
241
188
idx = acv .index ()
242
189
cell = acv .cell
@@ -252,70 +199,19 @@ def update_icon(action):
252
199
action .tool_tip = "Current Status: Hidden"
253
200
254
201
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
+
319
215
320
216
321
217
server = KliveServer ()
0 commit comments