kqcircuits.klayout_view
- class kqcircuits.klayout_view.KLayoutView(current=False, initialize=None, background_color='#ffffff')[source]
Bases:
object
Helper object to represent the KLayout rendering environment.
KLayoutView
is a wrapper around the KLayoutLayoutView
andCellView
objects, that represent containers for viewing a layout in the GUI. It provides methods to initialize the views and layout for KQCircuits, for placing KQCircuitsElements
, and for exporting images.Create a new view as follows:
view = KLayoutView()
This creates a new set of
LayoutView
,CellView
,Layout
and topCell
objects with layers initialized to the KQCircuits layer configuration. In the KLayout GUI, the new view will show as a new tab.Note: In standalone python mode, the user must keep a reference to the
KLayoutView
object in scope, otherwise the associated layout and cells may also go out of scope.When running scripts or macros in the KLayout application, the following command creates a wrapper around the currently active view:
view = KLayoutView(current=True)
This can be used in macros to act on the existing layout. The argument
current=True
is not available in standalone python mode.Once a view is created, new
Elements
can be placed with theinsert_cell
method.Several methods are available to export PNG files of the current view or specific cells and layers. In Jupyter notebooks, the
show
method displays the current view inline in the notebook.Initialize a
KLayoutView
instance.- Parameters:
current – Boolean. If True, wrap the currently active
LayoutView
(not available in standalone python)initialize – Boolean, specify whether to initialize the layout with the default layer configuration and a top cell. Defaults to True if
current==False
, and to False ifcurrent==True
.background_color – Background color as HTML color code. Defaults to “#ffffff” (white).
- layout_view: LayoutView
- insert_cell(cell, trans=None, inst_name=None, label_trans=None, align_to=None, align=None, rec_levels=0, **parameters)[source]
Inserts a subcell into the first top cell (the very first cell in the cell window)
It will use the given
cell
object or ifcell
is an Element class’ name then directly take the provided keyword arguments to first create the cell object.If inst_name given, a label
inst_name
is added to labels layer at thebase
refpoint and label_trans transformation.- Parameters:
cell – cell object or Element class name
trans – used transformation for placement. None by default, which places the subcell into the coordinate origin of the parent cell. If align and align_to arguments are used, trans is applied to the cell before alignment transform which allows for example rotation of the cell before placement.
inst_name – possible instance name inserted into subcell properties under id. Default is None
label_trans – relative transformation for the instance name label
align_to –
DPoint
orDVector
location in parent cell coordinates for alignment of cell. Default is Nonealign – name of the
cell
refpoint aligned to argumentalign_to
. Default is Nonerec_levels – recursion level when looking for refpoints from subcells. Set to 0 to disable recursion.
**parameters – PCell parameters for the element, as keyword argument
- Returns:
tuple of placed cell instance and reference points with the same transformation
- focus(cell=None)[source]
Sets a given cell as the active cell, and fits the zoom level to fit the cell.
- Parameters:
cell – cell to focus on, or None to focus on the currently active cell
- show(**kwargs)[source]
In KLayout, show this LayoutView as the current in the main window.
In standalone python, display an image of the view. Requires IPython / Jupyter. Keyword arguments are passed to
KLayoutView.get_pixels
.
- property cell_view: CellView
The active
CellView
- property layout: Layout
The active
Layout
- property active_cell: Cell
The active
Cell
, which is shown as current top in the cellview and bold in the cell window.Can be set to any Cell in the layout.
- property top_cell: Cell
The first top cell of the active layout.
- add_default_layers()[source]
Populate view with KQCircuits default layers. Adds the layers to the layout, and populates the layer view.
- create_top_cell(top_cell_name='Top Cell')[source]
Creates a new static cell and set it as the top cell.
- export_layers_bitmaps(path, cell, filename=None, layers_set=None, face_id=None)[source]
Exports each layer to a separate png image.
- Parameters:
path – Directory to place the exported file in
cell – Cell to export
filename – Filename to export to, or None to use the cell’s name.
layers_set – A list of layer names to export, or None for default values specified in the layer configuration
face_id – The face id for which to export the given layers, or None for general layers not associated to a face.
- export_all_layers_bitmap(path, cell, filename=None)[source]
Exports a cell to a .png file with all layers visible
- Parameters:
path – Directory to place the exported file in
cell – Cell to export
filename – Filename to export to, or None to use the cell’s name.
- export_pcell_png(path, cell, filename=None, max_size=1000)[source]
Exports a cell to a .png file no bigger than max_size at either dimension.
- Parameters:
path – Directory to place the exported file in
cell – Cell to export
filename – Filename to export to, or None to use the cell’s name.
max_size – Maximum size of the image.
- get_pixels(cell=None, width=None, height=None, layers_set=None, box=None)[source]
Returns a PixelBuffer render of the current view.
This method first zooms to fit the whole layout and shows all hierarchy levels. If either
width
orheight
is specified, the other is chosen correspondingly to keep the same viewport aspect ratio. If neither is specified, the current viewport size is used.- Parameters:
cell – Cell to render, or None to render the currently active cell.
width – image width in pixels, or None for automatic.
height – image height in pixels, or None for automatic.
layers_set – list of layer names to export, or None for the default set.
box – DBox area to show, or None for the full layout.
Returns: PixelBuffer
- static get_active_cell_view()[source]
Gets the currently active CellView. Not supported in standalone python mode.
Deprecated, use
KLayoutView(current=True).cell_view
to get the same behavior.
- static get_active_layout()[source]
Gets the layout of the currently active CellView. Not supported in standalone python mode.
Deprecated, use
KLayoutView(current=True).layout
to get the same behavior. If you already have a KLayoutView instance, use thelayout
property of that instance instead.
- static get_active_cell()[source]
Gets the active cell of the currently active CellView. Not supported in standalone python mode.
Deprecated, use
KLayoutView(current=True).active_cell
to get the same behavior. If you already have a KLayoutView instance, use theactive_cell
property of that instance instead.
- exception kqcircuits.klayout_view.MissingUILibraryException(message='Missing KLayout UI library.')[source]
Bases:
Exception
- kqcircuits.klayout_view.resolve_default_layer_info(layer_name, face_id=None)[source]
Returns LayerInfo based on default_layers.
Assumes that layer_name is valid, and that face_id is valid or None.
- Parameters:
layer_name – layer name (without face prefix for face-specific layers)
face_id – id of the face from which this layer should be