How top preserve labels in a DRC deck

edited April 2018 in General

This is a suggested feature: if you want to preserve the labels of a layer and write them to
an output, there is no easy way currently.

Here is a workaround: the following patch - if applied at the beginning of a rule deck,
adds a "labels" method which works similar to the "input" method, except that it takes
labels.

The only operation allowed currently on such a layer is "output" which will copy the
labels to a new layer:

# --------------------------------------------------------
#  Adds a new method to take labels from original layers
#  and to write them to an output layer (not more than this)
#
#  Usage is:
#    labels(layer[,datatype]).output(...)
#  or:
#    source.labels(layer[,datatype]).output(...)
#

#  Monkey-patch Shapes#insert to accept an array of anything
class RBA::Shapes
  self.method_defined?(:insert_org) || alias_method(:insert_org, :insert)
  def insert(*args)
    if args.size == 1 && args[0].is_a?(Array)
      args[0].each { |s| self.insert_org(s) }
    else
      self.insert_org(*args)
    end
  end
end

#  Add DRCSource#label to supply a special layer 
#  with an array-of-texts payload
class DRC::DRCSource
  def labels(layer, datatype = 0)
    li = layout.layer(layer, datatype)
    iter = cell_obj.begin_shapes_rec(li)
    iter.shape_flags = RBA::Shapes::STexts
    data = []
    while !iter.at_end?
      data << iter.shape.text.transformed(iter.trans)
      iter.next
    end
    DRCLayer::new(@engine, data)
  end
end

#  Supply the first version of #labels  
class DRC::DRCEngine
  def labels(*args)
    layout.labels(*args)
  end
end

# --------------------------------------------------------
# Example: copy labels from layer 1 to 100, size polygons by 0.1:

labels(1, 0).output(100)
input(1, 0).sized(0.1).output(100)

If that's good feature, it can be added to future releases.

Enjoy,

Matthias

Sign In or Register to comment.