KLayout 0.29.8 (2024-11-26 926dac96c) [master]

DRC Reference: Source Object

The layer object represents a collection of polygons, edges or edge pairs. A source specifies where to take layout from. That includes the actual layout, the top cell and options such as clip/query boxes, cell filters etc.

"cell" - Specifies input from a specific cell

Usage:

This method will create a new source that delivers shapes from the specified cell.

"cell_name" - Returns the name of the currently selected cell

Usage:

"cell_obj" - Returns the Cell object of the currently selected cell

Usage:

"clip" - Specifies clipped input

Usage:

Creates a source which represents a rectangular part of the original input. Three ways are provided to specify the rectangular region: a single DBox object (micron units), two DPoint objects (lower/left and upper/right coordinate in micron units) or four coordinates: left, bottom, right and top coordinate.

This method will create a new source which delivers the shapes from that region clipped to the rectangle. A method doing the same but without clipping is touching or overlapping.

"edge_pairs" - Gets the edge pairs from an input layer

Usage:

Creates a layer with the edge_pairs from the given layer of the source. Edge pairs are not supported by layout formats so far. So except if the source is a custom-built layout object, this method has little use. It is provided for future extensions which may include edge pairs in file streams.

This method is identical to input with respect to the options supported.

Use the global version of "edge_pairs" without a source object to address the default source.

"edge_pairs" without any arguments will create a new, empty original layer.

This method has been introduced in version 0.27.

"edges" - Gets the edge shapes (or shapes that can be converted edges) from an input layer

Usage:

Creates a layer with the edges from the given layer of the source. Edge layers are formed from shapes by decomposing the shapes into edges: polygons for example are decomposed into their outline edges. Some file formats support egdes as native objects.

This method is identical to input with respect to the options supported.

Use the global version of "edges" without a source object to address the default source.

"edges" without any arguments will create a new, empty original layer.

This method has been introduced in version 0.27.

"extent" - Returns a layer with the bounding box of the selected layout or cells

Usage:

Without an argument, the extent method returns a layer with the bounding box of the top cell. With a cell filter argument, the method returns a layer with the bounding boxes of the selected cells. The cell filter is a glob pattern.

The extent function is useful to invert a layer:

inverse_1 = extent.sized(100.0) - input(1, 0)

The following example returns the bounding boxes of all cells whose names start with "A":

a_cells = extent("A*")

"global_transform" - Gets or sets a global transformation

Usage:

This method returns a new source representing the transformed layout. It is provided in the spritit of Source#clip and similar methods.

The transformation is either given as a DTrans, DVector or DCplxTrans object or as one of the following specifications:

Multiple transformation specs can be given. In that case the transformations are applied right to left. Using "global_transform" will reset any global transformation present already. Without an argument, the global transformation is reset.

The following example rotates the layout by 90 degree at the origin (0, 0) and then shifts it up by 100 micrometers:

source.global_transform(shift(0, 100.um), rotate(90.0))

"input" - Specifies input from a source

Usage:

Creates a layer with the shapes from the given layer of the source. The layer can be specified by layer and optionally datatype, by a LayerInfo object or by a sequence of filters. Filters are expressions describing ranges of layers and/or datatype numbers or layer names. Multiple filters can be given and all layers matching at least one of these filter expressions are joined to render the input layer for the DRC engine. For the syntax of the filter expressions see LayerMap#map (look for the version that uses a map expression).

Some filter expressions are:

Layers created with "input" may contain both texts (labels) and polygons. There is a subtle difference between flat and deep mode: in flat mode, texts are not visible in polygon operations. In deep mode, texts appear as small 2x2 DBU rectangles. In flat mode, some operations such as clipping are not fully supported for texts. Also, texts will vanish in most polygon operations such as booleans etc.

Texts can later be selected on the layer returned by "input" with the Layer#texts method.

If you don't want to see texts, use polygons to create an input layer with polygon data only. If you only want to see texts, use labels to create an input layer with texts only.

labels also produces a true "text layer" which contains text objects. A variety of operations is available for these objects, such as boolean "and" and "not" with a polygon layer. True text layers should be preferred over mixed polygon/text layers if text object processing is required.

"input" without any arguments will create a new, empty original layer.

If you want to use user properties - for example with properties constraints in DRC checks - you need to enable properties on input:

input1_with_props = input(1, 0, enable_props)

You can also filter or map property keys, similar to the functions available on layers (DRCLayer#map_props, DRCLayer#select_props). For example to select property values with key 17 (numerical) only, use:

input1_with_props = input(1, 0, select_props(17))

Use the global version of "input" without a source object to address the default source.

"labels" - Gets the labels (texts) from an input layer

Usage:

Creates a true text layer with the labels from the given layer of the source.

This method is identical to input, but takes only texts from the given input layer. Starting with version 0.27, the result is no longer a polygon layer that tries to provide text support but a layer type which is provided for carrying text objects explicitly.

"labels" without any arguments will create a new, empty original layer.

Use the global version of "labels" without a source object to address the default source.

"layers" - Gets the layers the source contains

Usage:

Delivers a list of LayerInfo objects representing the layers inside the source.

One application is to read all layers from a source. In the following example, the "and" operation is used to perform a clip with the given rectangle. Note that this solution is not efficient - it's provided as an example only:

output_cell("Clipped")

clip_box = polygon_layer
clip_box.insert(box(0.um, -4.um, 4.um, 0.um))

layers.each { |l| (input(l) & clip_box).output(l) }

"layout" - Returns the Layout object associated with this source

Usage:

"make_layer" - Creates an empty polygon layer based on the hierarchy of the layout

Usage:

This method delivers a new empty original layer. It is provided to keep old code working. Use "input" without arguments instead.

"overlapping" - Specifies input selected from a region in overlapping mode

Usage:

Like clip, this method will create a new source delivering shapes from a specified rectangular region. In contrast to clip, all shapes overlapping the region with their bounding boxes are delivered as a whole and are not clipped. Hence shapes may extent beyond the limits of the specified rectangle.

touching is a similar method which delivers shapes touching the search region with their bounding box (without the requirement to overlap)

"path" - Gets the path of the corresponding layout file or nil if there is no path

Usage:

"polygons" - Gets the polygon shapes (or shapes that can be converted polygons) from an input layer

Usage:

Creates a layer with the polygon shapes from the given layer of the source. With "polygon shapes" we mean all kind of shapes that can be converted to polygons. Those are boxes, paths and real polygons.

This method is identical to input with respect to the options supported.

"polygons" without any arguments will create a new, empty original layer.

Use the global version of "polygons" without a source object to address the default source.

"select" - Adds cell name expressions to the cell filters

Usage:

This method will construct a new source object with the given cell filters applied. Note that there is a global version of "select" which does not create a new source, but acts on the default source.

Cell filters will enable or disable cells plus their subtree. Cells can be switched on and off, which makes the hierarchy traversal stop or begin delivering shapes at the given cell. The arguments of the select method form a sequence of enabling or disabling instructions using cell name pattern in the glob notation ("*" as the wildcard, like shell). Disabling instructions start with a "-", enabling instructions with a "+" or no specification.

The following options are available:

To disable the TOP cell but enabled a hypothetical cell B below the top cell, use that code:

source_with_selection = source.select("-TOP", "+B")
l1 = source_with_selection.input(1, 0)
...

Please note that the sample above will deliver the children of "B" because there is nothing said about how to proceed with cells other than "TOP" or "B". Conceptually, the instantiation path of a cell will be matched against the different filters in the order they are given. A matching negative expression will disable the cell, a matching positive expression will enable the cell. Hence, every cell that has a "B" in the instantiation path is enabled.

The following code will just select "B" without its children, because in the first "-*" selection, all cells including the children of "B" are disabled:

source_with_selection = source.select("-*", "+B")
l1 = source_with_selection.input(1, 0)
...

The short form "-" will disable the top cell. This code is identical to the first example and will start with a disabled top cell regardless of its name:

source_with_selection = source.select("-", "+B")
l1 = source_with_selection.input(1, 0)
...

"touching" - Specifies input selected from a region in touching mode

Usage:

Like clip, this method will create a new source delivering shapes from a specified rectangular region. In contrast to clip, all shapes touching the region with their bounding boxes are delivered as a whole and are not clipped. Hence shapes may extent beyond the limits of the specified rectangle.

overlapping is a similar method which delivers shapes overlapping the search region with their bounding box (and not just touching)