API reference - Class PCellDeclarationHelper

Notation used in Ruby API documentation

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

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
coerce_parameters_implCoerces the parameters
display_text_implDelivers the display text
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
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.
parameters_from_shape_implSets the parameters from a shape
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
transformation_from_shape_implGets the initial PCell instance transformation when creating from a shape

Detailed description

can_create_from_shape_impl

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

Signature: cell

Description: Gets the reference to the current cell within produce_impl

coerce_parameters_impl

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

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

Signature: initialize

Description: Initializes this instance

layer

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

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

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
  • :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

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

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

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

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).