Instance GUI invoked from a script

Hi Matthias,

Is it possible to invoke the Instance GUI (menu Edit | Mode | Instance) from a script? As an argument to the function call, I would like to 1) set the Cell and Library, 2) then query the list of PCell parameters, then 3) pass some PCell parameters to the GUI. Then via function, click "Apply" or "Ok", so that the GUI disappears, but the mouse is in the mode of showing the cell to be instantiated.

2 is above is already possible.

Thank you
Lukas

Comments

  • Hi Lukas,

    sorry for the delayed response. The feature you ask for is not available out of the box, but it can be emulated (sorry, Ruby - but the Python transformation should be straightforward):

    app = RBA::Application::instance
    mw = app.main_window
    
    # if instance mode is one, make sure we leave it:
    mw.cancel
    
    # configure instance dialog:
    
    # cell placement
    app.set_config("edit-inst-angle", "0")
    app.set_config("edit-inst-mirror", "false")
    app.set_config("edit-inst-place-origin", "true")
    app.set_config("edit-inst-scale", "1")
    
    # cell origin
    app.set_config("edit-inst-cell-name", "CIRCLE")
    app.set_config("edit-inst-lib-name", "Basic")
    # PCell parameters: "coerced" form, notation is "name:value;...", value is:
    #   "#n" for integer
    #   "##d" for double
    #   "[layer:layer-spec]" for a layer
    #   "[dpoint:dpoint-spec]" for a double-typed point
    #   ...
    # peek into ~/.klayout/klayout under edit-inst-pcell-parameters for other
    # forms.
    app.set_config("edit-inst-pcell-parameters", "layer:[layer:1/0];radius:##10;handle:[dpoint:-10,0];npoints:#16;actual_radius:##10;")
    
    # array spec
    app.set_config("edit-inst-array", "false")
    # only if edit-inst-array is "true":
    app.set_config("edit-inst-column_x", "0")
    app.set_config("edit-inst-column_y", "1")
    app.set_config("edit-inst-row_x", "1")
    app.set_config("edit-inst-row_y", "0")
    app.set_config("edit-inst-columns", "10")
    app.set_config("edit-inst-rows", "10")
    
    # enter instance mode
    
    mw.menu.action("edit_menu.mode_menu.instance").trigger
    
    # hide the dialog right after we opened it
    
    opt = RBA::QApplication::topLevelWidgets.find { |w| w.objectName == "EditorOptionsDialog" }
    opt && opt.accept
    

    The last statements are somewhat questionable as they rely on the widget hierarchy, but as long as there is no major UI update, this should work.

    Best regards,

    Matthias

  • Thank you Matthias.

    This is very helpful, and useful for implementing schematic driven layout:

    Are there any ways of querying the to-be-instantiated cell, e.g., location, rotation, etc?

    Is there a way to create a call back for when the to-be-instantiated cell moves or changes otherwise?

    The goal is to create fly lines.

    Alternatively:

    • Do you know if there is a way to find the x,y coordinates of the mouse, in DBU? Namely the same numbers as displayed in the bottom right corner.
    • Do you know if there is a callback for when the mouse moves and the cell outline is redrawn?

    thank you

  • Hi Lukas,

    there are no callbacks for the editor functions such as "create instance" or "create polygon". Changing the behavior there is C++ domain.

    It is possible however to implement new editor functions. Such as "place cell with fly lines". The key for doing so is the Plugin API (https://www.klayout.de/doc-qt5/programming/application_api.html#k_11). This allows implementing entirely new tools that take full control over the mouse. These tools plug themselves into the tool bar as new tools.

    However that will basically means reimplementing the cell placement feature. KLayout doesn't really have an open architecture where you can plug in and replace things as you like. That is owned to the static nature of the C++ core. And opening too many callbacks only induces side effects that are very hard to control.

    Matthias

  • thank you.

Sign In or Register to comment.