Skip to content

Commit

Permalink
removed things that belong in lytest
Browse files Browse the repository at this point in the history
  • Loading branch information
atait committed Oct 9, 2018
1 parent 7e1e824 commit 9aa8a06
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions klayout_dot_config/python/lyipc/client/phidl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,3 @@ def new_add(self, *args, **kwargs):
klayout_quickplot(device, file, fresh=False)
return retval
phidl.device_layout.Device.add = new_add


@contextmanager
def save_or_visualize(device_name=None, out_file=None):
''' Handles a conditional write to file or send over lyipc connection.
The context manager yields a new empty Device.
The context block then modifies that device by adding references to it. It does not need to return anything.
Back to the context manager, the Device is saved if out_file is not None, or it is sent over ipc
Example::
with save_or_visualize(out_file='my_box.gds') as D:
r = D << phidl.geometry.rectangle(size=(10, 10), layer=1)
r.movex(20)
will write the device with a rectangle to a file called 'my_box.gds' and do nothing with lyipc.
By changing out_file to None, it will send an ipc load command instead of writing to a permanent file,
(Although ipc does write a file to be loaded by klayout, it's name or persistence is not guaranteed.)
'''
if device_name is None:
CELL = Device()
else:
CELL = Device(device_name)
yield CELL
if out_file is None:
klayout_quickplot(CELL, 'debugging.gds', fresh=True)
else:
CELL.write_gds(out_file)


def contained_geometry(func):
'''
Converts a function that takes a Device argument to one that takes a filename argument.
This is used to develop fixed geometry creation blocks and then save them as reference files.
Bad idea to try to use this in a library or call it from other functions.
func should take *only one* argument that is a Device, modify that Device, and return nothing.
It's sort of a decorator version of save_or_visualize.
When called with a None argument, it will use klayout_quickplot.
Example::
@contained_geometry
def boxer(D):
r = D << phidl.geometry.rectangle(size=(10, 10), layer=1)
r.movex(20)
Usage::
boxer() # displays in klayout over ipc
boxer('temp.gds') # saves to file instead
'''
@wraps(func)
def geometry_container(out_file=None):
with save_or_visualize(out_file=out_file) as TOP:
func(TOP)
return geometry_container

0 comments on commit 9aa8a06

Please sign in to comment.