Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Reload Libraries macro issues" #95

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions klayout_package/python/kqcircuits/util/layout_to_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,19 @@ def get_node_params(node: Node):
return node_params, elem


def remove_kqc_pcells():
"""Remove all KQCircuits PCells."""

main_window = pya.Application.instance().main_window()
for vid in range(main_window.views()):
top_cell = main_window.view(vid).active_cellview().cell
for inst in top_cell.each_inst():
if isinstance(inst.pcell_declaration(), Element):
inst.delete()


def extract_pcell_data_from_views():
"""Remove all PCells and return their data.
"""Iterate over all KQCircuits PCells and return their data.

Returns: A list of lists. Each element corresponds to a view in KLayout and it is a list of
``(type, location, parameters)`` tuples. These tuples completely describe the type, position and
Expand All @@ -372,14 +383,13 @@ def extract_pcell_data_from_views():
pcells = []
for inst in top_cell.each_inst():
pc = inst.pcell_declaration()
if pc:
if isinstance(pc, Element):
params = inst.pcell_parameters_by_name()
def_params = pc.__class__.get_schema()
for k, v in def_params.items():
if params[k] == v.default:
del params[k]
pcells.append((pc.__class__, inst.dtrans, params))
inst.delete()
views.append(pcells)

return views
Expand Down
8 changes: 6 additions & 2 deletions klayout_package/python/scripts/macros/0system/0reload.lym
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ Note that this does not reload the ``defaults`` file.
"""

from kqcircuits.util.library_helper import load_libraries
from kqcircuits.util.layout_to_code import extract_pcell_data_from_views, restore_pcells_to_views
from kqcircuits.util.layout_to_code import remove_kqc_pcells, extract_pcell_data_from_views, restore_pcells_to_views

views = extract_pcell_data_from_views()
load_libraries(flush=True)
try:
load_libraries(flush=True)
except:
raise RuntimeError("Failed to reload KQCircuits libraries, keeping current views.")
remove_kqc_pcells()
restore_pcells_to_views(views)
qpavsmi marked this conversation as resolved.
Show resolved Hide resolved
</text>
</klayout-macro>