Skip to content

Commit

Permalink
connect_pins_with_waveguides: error handling
Browse files Browse the repository at this point in the history
raise Exception rather than just a Message window: in case there are many errors, it will stop at the first one.
  • Loading branch information
lukasc-ubc committed Jan 30, 2024
1 parent cd6f945 commit c03b1f4
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions klayout_dot_config/python/SiEPIC/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,33 @@ def connect_pins_with_waveguide(instanceA, pinA, instanceB, pinB, waveguide = No
cpinA = [instanceA.find_pin(pinA)]
except:
error_message = "SiEPIC-Tools, in function connect_pins_with_waveguide: Pin (%s) not found in componentA (%s). Available pins: %s" % (pinA,componentA.component, [p.pin_name for p in componentA.pins])
'''
if _globals.Python_Env == "KLayout_GUI":
question = pya.QMessageBox().setStandardButtons(pya.QMessageBox.Ok)
question.setText("SiEPIC-Tools scripted layout, requested pin not found")
question.setInformativeText(error_message)
pya.QMessageBox_StandardButton(question.exec_())
return
else:
raise Exception(error_message)
else:
'''
raise Exception(error_message)
if cpinB==[]:
try:
# this checks if the cell (which could contain multiple components)
# contains only one pin matching the name, e.g. unique opt_input in a sub-circuit
cpinB = [instanceB.find_pin(pinB)]
except:
error_message = "SiEPIC-Tools, in function connect_pins_with_waveguide: Pin (%s) not found in componentB (%s). Available pins: %s" % (pinB,componentB.component, [p.pin_name for p in componentB.pins])
'''
if _globals.Python_Env == "KLayout_GUI":
question = pya.QMessageBox().setStandardButtons(pya.QMessageBox.Ok)
question.setText("SiEPIC-Tools scripted layout, requested pin not found")
question.setInformativeText(error_message)
pya.QMessageBox_StandardButton(question.exec_())
return
else:
raise Exception(error_message)
'''
raise Exception(error_message)

cpinA=cpinA[0]
cpinB=cpinB[0]
Expand Down Expand Up @@ -1731,14 +1735,16 @@ def connect_cell(instanceA, pinA, cellB, pinB, mirror = False, verbose=False, tr
else:
raise Exception("Component instanceA not found")
if componentB==[]:
'''
if _globals.Python_Env == "KLayout_GUI":
question = pya.QMessageBox().setStandardButtons(pya.QMessageBox.Ok)
question.setText("SiEPIC-Tools scripted layout, requested component not found")
question.setInformativeText("Component cellB not found: %s, %s" % (cellB, cellB.name))
pya.QMessageBox_StandardButton(question.exec_())
return
else:
raise Exception("Component cellB not found")
'''
raise Exception("Component cellB not found")

# for c in componentA:
# if c.trans.s_trans() == instanceA.trans:
Expand Down Expand Up @@ -1768,26 +1774,31 @@ def connect_cell(instanceA, pinA, cellB, pinB, mirror = False, verbose=False, tr

def error_pinA(pinA,componentA):
from inspect import getframeinfo, stack
error_message = "SiEPIC-Tools, in function connect_cell: PinA (%s) not found in componentA (%s). Available pins: %s.\n%s" % (pinA,componentA.component, [p.pin_name for p in componentA.pins], getframeinfo(stack()[2][0]))
error_message = "SiEPIC-Tools, in function connect_cell: PinA (%s) not found in componentA (%s). Available pins: %s.\n%s" % (pinA,componentA.component, [p.pin_name for p in componentA.pins], str(getframeinfo(stack()[2][0])).replace(',','\n'))
'''
if _globals.Python_Env == "KLayout_GUI":
question = pya.QMessageBox().setStandardButtons(pya.QMessageBox.Ok)
question.setText("SiEPIC-Tools scripted layout, requested pin not found")
question.setInformativeText(error_message)
pya.QMessageBox_StandardButton(question.exec_())
return
else:
raise Exception(error_message)
'''
raise Exception(error_message)

def error_pinB(pinB,componentB):
from inspect import getframeinfo, stack
error_message = "SiEPIC-Tools, in function connect_cell: PinB (%s) not found in componentB (%s). Available pins: %s.\n%s" % (pinB,componentB.component, [p.pin_name for p in componentB.pins], getframeinfo(stack()[2][0]))
error_message = "SiEPIC-Tools, in function connect_cell: PinB (%s) not found in componentB (%s). Available pins: %s.\n%s" % (pinB,componentB.component, [p.pin_name for p in componentB.pins], str(getframeinfo(stack()[2][0])).replace(',','\n'))
'''
if _globals.Python_Env == "KLayout_GUI":
question = pya.QMessageBox().setStandardButtons(pya.QMessageBox.Ok)
question.setText("SiEPIC-Tools scripted layout, requested pin not found")
question.setInformativeText(error_message)
pya.QMessageBox_StandardButton(question.exec_())
return
else:
raise Exception(error_message)
'''
raise Exception(error_message)


# for cells with hierarchy
Expand Down

0 comments on commit c03b1f4

Please sign in to comment.