KLayout 0.29.8 (2024-10-28 63dd591e5) [master]

API reference - Class PCellDeclarationHelper

Notation used in Ruby API documentation

Module: db

Description: A helper class to simplify the declaration of a PCell (Ruby version)

Class hierarchy: PCellDeclarationHelper » PCellDeclaration

This class provides adds some convenience to the PCell declaration based on PCellDeclaration. PCellDeclaration is a C++ object which is less convenient to use than a Ruby-based approach. In particular this class simplifies the declaration and use of parameters through accessor methods that are created automatically from the declaration of the parameters.

The basic usage of this class is the following:

# Derive your PCell from PCellDeclarationHelper
class MyPCell < RBA::PCellDeclarationHelper

  # initalize
  def initialize
    super
    # your initialization: add parameters with name, type, description and
    # optional other values
    param :p, TypeInt, "The parameter", :default => 1
    param :l, TypeLayer, "The layer", :default => RBA::LayerInfo::new(1, 0)
    # add other parameters ..
  end

  # reimplement display_text_impl
  def display_text_impl
    # implement the method here
  end

  # reimplement produce_impl
  def produce_impl
    # implement the method here
  end

  # optionally reimplement coerce_parameters_impl
  def coerce_parameters_impl
    # implement the method here
  end

end

An implementation of display_text_impl could look like this:

  def display_text_impl
    "We have p=#{p}"
  end

Because in the sample declaration above we have declared parameter "p" we can access the value of p inside the implementation simply by using the "p" method.

Similarily the produce_impl implementation could use code like the following. Please note that layout and cell are available to get the layout and cell. Also because we have declared a layer parameter "l", we can access the layer index with the "l_layer" method:

  def produce_impl
    cell.shapes(l_layer).insert(RBA::Box.new(0, 0, p*100, p*200))
  end

Again in this sample, we used "p" to access the parameter "p".

The implementation of coerce_parameter_impl can make use of the parameter setters. In the case of the "p" parameter, the setter is "set_p":

  def coerce_parameter_impl
    p < 10 || set_p(10)
  end

Public methods

callback_implProvides a callback on a parameter change
callback_implProvides a callback on a parameter change
can_create_from_shape_implReturns true if the PCell can be created from the given shape
can_create_from_shape_implReturns true if the PCell can be created from the given shape
cellGets the reference to the current cell within produce_impl
cellGets the reference to the current cell within produce_impl
coerce_parameters_implCoerces the parameters
coerce_parameters_implCoerces the parameters
display_text_implDelivers the display text
display_text_implDelivers the display text
initializeInitializes this instance
initializeInitializes this instance
layerGets the reference to the current layer index within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl
layerGets the reference to the current layer index within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl
layoutGets the reference to the current layout within produce_impl, can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl
layoutGets the reference to the current layout within produce_impl, can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl
param(name,
type,
description,
...)
Declares a parameter with the given name, type and description and optional attributes.
param(name,
type,
description,
...)
Declares a parameter with the given name, type and description and optional attributes.
parameters_from_shape_implSets the parameters from a shape
parameters_from_shape_implSets the parameters from a shape
produce_implProduces the layout
produce_implProduces the layout
shapeGets the reference to the current shape within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl
shapeGets the reference to the current shape within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl
transformation_from_shape_implGets the initial PCell instance transformation when creating from a shape
transformation_from_shape_implGets the initial PCell instance transformation when creating from a shape

Detailed description

callback_impl

(1) Signature: callback_impl

Description: Provides a callback on a parameter change

This method applies to user interface changes only. Whenever a parameter is changed on the parameter page, this method is called with the name of the parameter.

On some occasions, this method called to establish a configuration unspecifically. In this case, the name is an empty string - indicating "all parameters may have changed".

This method can change the state of this or any other parameter. For this, the state objects are supplied instead of the parameter values. For example to enable parameter "b" when a boolean parameter "a" is true, use the following code:

def callback_impl(name)
  if name == "a" || name == ""
    b.enabled = a.value
  end
end

The "enabled" attribute of the PCellParameterState object indicates whether the parameter is enabled in the user interface. "a.value" delivers the value of the (boolean type assumed) parameter "a".

Note that the above code also checks for empty name to consider the case of a global refresh.

Further useful attributes of the parameters are:

  • enabled : the parameter entry is grayed out if false
  • readonly : the parameter cannot be edited (less strict than enabled)
  • visible : the parameter entry is not visible if false
  • icon : Sets an icon in front of the parameter indicating an error or a warning (use PCellParameterState#WarningIcon or PCellParameterState#ErrorIcon).

(2) Signature: callback_impl

Description: Provides a callback on a parameter change

This method applies to user interface changes only. Whenever a parameter is changed on the parameter page, this method is called with the name of the parameter.

On some occasions, this method called to establish a configuration unspecifically. In this case, the name is an empty string - indicating "all parameters may have changed".

This method can change the state of this or any other parameter. For this, the state objects are supplied instead of the parameter values. For example to enable parameter "b" when a boolean parameter "a" is true, use the following code:

def callback_impl(name)
  if name == "a" || name == ""
    b.enabled = a.value
  end
end

The "enabled" attribute of the PCellParameterState object indicates whether the parameter is enabled in the user interface. "a.value" delivers the value of the (boolean type assumed) parameter "a".

Note that the above code also checks for empty name to consider the case of a global refresh.

Further useful attributes of the parameters are:

  • enabled : the parameter entry is grayed out if false
  • readonly : the parameter cannot be edited (less strict than enabled)
  • visible : the parameter entry is not visible if false
  • icon : Sets an icon in front of the parameter indicating an error or a warning (use PCellParameterState#WarningIcon or PCellParameterState#ErrorIcon).

can_create_from_shape_impl

(1) Signature: can_create_from_shape_impl

Description: Returns true if the PCell can be created from the given shape

This method can be reimplemented in a PCell class. If the PCell can be created from the shape available through the shape accessor (a Shape object), this method is supposed to return true. The layout the shape lives in can be accessed with layout and the layer with layer.

The default implementation returns false.

(2) Signature: can_create_from_shape_impl

Description: Returns true if the PCell can be created from the given shape

This method can be reimplemented in a PCell class. If the PCell can be created from the shape available through the shape accessor (a Shape object), this method is supposed to return true. The layout the shape lives in can be accessed with layout and the layer with layer.

The default implementation returns false.

cell

(1) Signature: cell

Description: Gets the reference to the current cell within produce_impl

(2) Signature: cell

Description: Gets the reference to the current cell within produce_impl

coerce_parameters_impl

(1) Signature: coerce_parameters_impl

Description: Coerces the parameters

This method can be reimplemented in a PCell class. It is supposed to adjust parameters to render a consistent parameter set and to fix parameter range errors. This method is called for example inside the PCell user interface to compute the actual parameters when "Apply" is pressed.

(2) Signature: coerce_parameters_impl

Description: Coerces the parameters

This method can be reimplemented in a PCell class. It is supposed to adjust parameters to render a consistent parameter set and to fix parameter range errors. This method is called for example inside the PCell user interface to compute the actual parameters when "Apply" is pressed.

display_text_impl

(1) Signature: display_text_impl

Description: Delivers the display text

This method must be reimplemented in a PCell class to identify the PCell in human-readable form. This text is shown in the cell tree for the PCell for example.

(2) Signature: display_text_impl

Description: Delivers the display text

This method must be reimplemented in a PCell class to identify the PCell in human-readable form. This text is shown in the cell tree for the PCell for example.

initialize

(1) Signature: initialize

Description: Initializes this instance

(2) Signature: initialize

Description: Initializes this instance

layer

(1) Signature: layer

Description: Gets the reference to the current layer index within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl

The object returned is the layer index within the Layout object of the shape which will be converted.

(2) Signature: layer

Description: Gets the reference to the current layer index within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl

The object returned is the layer index within the Layout object of the shape which will be converted.

layout

(1) Signature: layout

Description: Gets the reference to the current layout within produce_impl, can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl

The object returned is the Layout object of the shape which will be converted.

(2) Signature: layout

Description: Gets the reference to the current layout within produce_impl, can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl

The object returned is the Layout object of the shape which will be converted.

param

(1) Signature: param (name, type, description, ...)

Description: Declares a parameter with the given name, type and description and optional attributes.

name:The name of the parameter. Must be a simple word.
type:The type. One of the Type... constants, that this class borrowed from PCellParameterDeclaration.
description:The description text for this parameter

Optional, named parameters are

  • :hidden: (boolean) true, if the parameter is not shown in the dialog
  • :readonly: (boolean) true, if the parameter cannot be edited
  • :unit: the unit string
  • tooltip: the tool tip text displayed on the edit fields and labels
  • :min_value: the minimum value (effective for numerical types and if no choices are present)
  • :max_value: the maximum value (effective for numerical types and if no choices are present)
  • :default: the default value
  • :choices: ([ [ d, v ], ... ]) choice descriptions/value for choice type

":choices" must be an array of two-element arrays (description text, value) which specify one choice each for parameters with a choice of values. Such parameters are represented by a drop-down box.

This declaration will create accessor methods "x" and "set_x", where "x" is the name of the parameter. If the type is TypeLayer, an accessor "x_layer" delivering the layer index inside produce_impl is created as well.

(2) Signature: param (name, type, description, ...)

Description: Declares a parameter with the given name, type and description and optional attributes.

name:The name of the parameter. Must be a simple word.
type:The type. One of the Type... constants, that this class borrowed from PCellParameterDeclaration.
description:The description text for this parameter

Optional, named parameters are

  • :hidden: (boolean) true, if the parameter is not shown in the dialog
  • :readonly: (boolean) true, if the parameter cannot be edited
  • :unit: the unit string
  • tooltip: the tool tip text displayed on the edit fields and labels
  • :min_value: the minimum value (effective for numerical types and if no choices are present)
  • :max_value: the maximum value (effective for numerical types and if no choices are present)
  • :default: the default value
  • :choices: ([ [ d, v ], ... ]) choice descriptions/value for choice type

":choices" must be an array of two-element arrays (description text, value) which specify one choice each for parameters with a choice of values. Such parameters are represented by a drop-down box.

This declaration will create accessor methods "x" and "set_x", where "x" is the name of the parameter. If the type is TypeLayer, an accessor "x_layer" delivering the layer index inside produce_impl is created as well.

parameters_from_shape_impl

(1) Signature: parameters_from_shape_impl

Description: Sets the parameters from a shape

This method can be reimplemented in a PCell class. If can_create_from_shape_impl returns true, this method is called to set the parameters from the given shape (see shape, layout and layer). Note, that for setting a layer parameter you need to create the LayerInfo object, i.e. like this:

  set_l layout.get_info(layer)

The default implementation does nothing. All parameters not set in this method will receive their default value.

If you use a parameter called "layer" for example, the parameter getter will hide the "layer" argument. Use "_layer" for the argument in this case (same for "layout", "shape" or "cell):

  set_layer layout.get_info(_layer)

(2) Signature: parameters_from_shape_impl

Description: Sets the parameters from a shape

This method can be reimplemented in a PCell class. If can_create_from_shape_impl returns true, this method is called to set the parameters from the given shape (see shape, layout and layer). Note, that for setting a layer parameter you need to create the LayerInfo object, i.e. like this:

  set_l layout.get_info(layer)

The default implementation does nothing. All parameters not set in this method will receive their default value.

If you use a parameter called "layer" for example, the parameter getter will hide the "layer" argument. Use "_layer" for the argument in this case (same for "layout", "shape" or "cell):

  set_layer layout.get_info(_layer)

produce_impl

(1) Signature: produce_impl

Description: Produces the layout

This method must be reimplemented in a PCell class. Using the parameter values provided by the parameter accessor methods and the layout and cell through layout and cell, this method is supposed to produce the final layout inside the given cell.

(2) Signature: produce_impl

Description: Produces the layout

This method must be reimplemented in a PCell class. Using the parameter values provided by the parameter accessor methods and the layout and cell through layout and cell, this method is supposed to produce the final layout inside the given cell.

shape

(1) Signature: shape

Description: Gets the reference to the current shape within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl

The object returned is the Shape object of the shape which will be converted.

(2) Signature: shape

Description: Gets the reference to the current shape within can_create_from_shape_impl, parameters_from_shape_impl and transformation_from_shape_impl

The object returned is the Shape object of the shape which will be converted.

transformation_from_shape_impl

(1) Signature: transformation_from_shape_impl

Description: Gets the initial PCell instance transformation when creating from a shape

This method can be reimplemented in a PCell class. If can_create_from_shape_impl returns true, this method is called to get the initial transformation from the given shape (see shape, layout and layer).

This method must return a Trans object. The default implementation returns a unit transformation (no displacement, no rotation).

(2) Signature: transformation_from_shape_impl

Description: Gets the initial PCell instance transformation when creating from a shape

This method can be reimplemented in a PCell class. If can_create_from_shape_impl returns true, this method is called to get the initial transformation from the given shape (see shape, layout and layer).

This method must return a Trans object. The default implementation returns a unit transformation (no displacement, no rotation).