From 4452d412cd3472b88841387dfa0ca1e0d3531431 Mon Sep 17 00:00:00 2001 From: pietro Date: Sat, 8 Jun 2024 22:58:52 +0200 Subject: [PATCH] More informative exception and prevent non-deleted child instances --- .../python/kqcircuits/util/layout_to_code.py | 2 +- .../python/scripts/macros/0system/0reload.lym | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/klayout_package/python/kqcircuits/util/layout_to_code.py b/klayout_package/python/kqcircuits/util/layout_to_code.py index 072f97f4c..f446cb5de 100644 --- a/klayout_package/python/kqcircuits/util/layout_to_code.py +++ b/klayout_package/python/kqcircuits/util/layout_to_code.py @@ -362,7 +362,7 @@ def extract_pcell_data_from_views(): Returns: a tuple (views, instances) where views: 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 + ``(type, location, parameters)`` tuples. These tuples completely describe the type, position and parameters of a single PCell in the "Top Cell" of this view. instances: flattened list of all instances of KQCircuits PCells found. """ diff --git a/klayout_package/python/scripts/macros/0system/0reload.lym b/klayout_package/python/scripts/macros/0system/0reload.lym index feb2e6a35..0c35d1f7c 100644 --- a/klayout_package/python/scripts/macros/0system/0reload.lym +++ b/klayout_package/python/scripts/macros/0system/0reload.lym @@ -41,12 +41,14 @@ from kqcircuits.util.library_helper import load_libraries from kqcircuits.util.layout_to_code import extract_pcell_data_from_views, restore_pcells_to_views views, instances = extract_pcell_data_from_views() -try: - load_libraries(flush=True) -except: - raise RuntimeError("Failed to reload KQCircuits libraries, keeping current views.") for inst in instances: inst.delete() +try: + load_libraries(flush=True) +except Exception as e: + restore_pcells_to_views(views) + raise RuntimeError("Failed to reload KQCircuits libraries and redraw cells." + + f"\nThe following exception was raised: \n{type(e).__name__}: {e}") restore_pcells_to_views(views)