class Gdsii::Library

Represents a GDSII Library.

Public Class Methods

new(name=nil, units=DEF_LIB_UNITS) { |self| ... } click to toggle source

Create a new GDSII Library object.

lib = Library.new('MYDESIGN.DB')

The units may be specified during construction:

lib2 = Library.new('OTHER.DB', [0.001, 1e-9])
Calls superclass method Gdsii::Group.new
# File lib/gdsii/library.rb, line 55
def initialize(name=nil, units=DEF_LIB_UNITS)
  super()
  @records[Structure] = []
  @records[GRT_ENDLIB] = Record.new(GRT_ENDLIB)
  
  self.header = DEF_LIB_VERSION
  self.name = name unless name.nil?
  self.units = units
  
  # Set modify/access time to the current time
  now = Time.now
  self.modify_time = now
  self.access_time = now

  yield self if block_given?
end
read_header(file) { |lib| ... } click to toggle source

Reads the Library header data of a GDSII file but does not read any Structure records. The Library object is returned (also yielded if a block is given).

File.open(file_name, 'rb') do |file|
  Library.read_header(file) do |lib|
    puts "The GDSII library name is #{lib.name}"
  end
end

See Structure#read_each and Structure#read_each_header for more detailed examples

# File lib/gdsii/library.rb, line 421
def Library.read_header(file)
  Library.read(file, nil, nil, :before_group) do |lib|
    yield lib if block_given?
    break lib
  end
end

Public Instance Methods

access_time() click to toggle source

Returns the access time for this library (returns Time)

# File lib/gdsii/library.rb, line 405
def access_time(); @access_time; end
access_time=(time) click to toggle source

Accepts a Time object and sets the access time for the library.

struct.access_time = Time.now
# File lib/gdsii/library.rb, line 397
def access_time=(time)
  @access_time = time
  update_times
end
add(*args) click to toggle source

Shortcut for Gdsii::Access::EnumerableGroup#add. For example, instead of:

lib = Library.new('MYLIB.DB')
lib.structures.add Structure.new('test')

It could be simply:

lib.add Structure.new('test')
# File lib/gdsii/library.rb, line 88
def add(*args); structures.add(*args); end
archive_format?() click to toggle source

True if format == 0 indicating archive status; false if not.

# File lib/gdsii/library.rb, line 261
def archive_format?(); format == 0; end
attrtable() click to toggle source

Get the attribute table file location. This is a String with a maximum of 44 characters in length. Returns String.

# File lib/gdsii/library.rb, line 215
def attrtable() @records.get_data(GRT_ATTRTABLE); end
attrtable=(val) click to toggle source

Set the attribute table file location. See attrtable for more details.

# File lib/gdsii/library.rb, line 220
def attrtable=(val) @records.set(GRT_ATTRTABLE, val); end
attrtable_record() click to toggle source

Get the attribute table file location ATTRTABLE record (returns Record).

# File lib/gdsii/library.rb, line 209
def attrtable_record() @records.get(GRT_ATTRTABLE); end
bgnlib() click to toggle source

Get the bgnlib number (returns Fixnum). This holds the modify/access time stamp for the library. It is probably easier to not access this directly but to use modify_time and access_time instead.

# File lib/gdsii/library.rb, line 367
def bgnlib() @records.get_data(GRT_BGNLIB); end
bgnlib=(val) click to toggle source

Set the bgnlib number. The value is a Fixnum representation of the modify/access time stamp for the library. It is probably easier to not access this directly but to use modify_time= and access_time= instead.

# File lib/gdsii/library.rb, line 375
def bgnlib=(val) @records.set(GRT_BGNLIB, val); end
bgnlib_record() click to toggle source

Get the bgnlib record (returns Record).

# File lib/gdsii/library.rb, line 360
def bgnlib_record() @records.get(GRT_BGNLIB); end
database_units() click to toggle source

Returns the database units (returns Float). See units for details.

# File lib/gdsii/library.rb, line 337
def database_units(); @database_units; end
database_units=(val) click to toggle source

Sets the database units. See units for details.

# File lib/gdsii/library.rb, line 342
def database_units=(val)
  @database_units = val
  update_units
end
dirsize() click to toggle source

Get the number of pages in the library directory (returns Fixnum). This is likely an old Calma record and is likely unused except in rare circumstances.

# File lib/gdsii/library.rb, line 146
def dirsize() @records.get_data(GRT_LIBDIRSIZE); end
dirsize=(val) click to toggle source

Set the number of pages in the library directory (see dirsize for more information).

# File lib/gdsii/library.rb, line 152
def dirsize=(val) @records.set(GRT_LIBDIRSIZE, val); end
dirsize_record() click to toggle source

Get the library directory size LIBDIRSIZE record (returns Record).

# File lib/gdsii/library.rb, line 139
def dirsize_record() @records.get(GRT_LIBDIRSIZE); end
filtered_format?() click to toggle source

True if format == 1 indicating filtered status; false if not.

# File lib/gdsii/library.rb, line 266
def filtered_format?(); format == 1; end
fonts() click to toggle source

Get the array of paths to font definition files. If this record exists, then exactly 4 array elements should exist. Each array element is a String with a maximum of 44 characters. Returns Array of Strings.

# File lib/gdsii/library.rb, line 199
def fonts() @records.get_data(GRT_FONTS); end
fonts=(val) click to toggle source

Set the path to 4 font definition files. See fonts for more details.

# File lib/gdsii/library.rb, line 204
def fonts=(val) @records.set(GRT_FONTS, val); end
fonts_record() click to toggle source

Get the fonts record (returns Record).

# File lib/gdsii/library.rb, line 192
def fonts_record() @records.get(GRT_FONTS); end
format() click to toggle source

Get the format number (returns Fixnum). This number is used to indicate if the stream file is an archive and/or filtered:

0: Archive 1: Filtered

# File lib/gdsii/library.rb, line 251
def format() @records.get_data(GRT_FORMAT); end
format=(val) click to toggle source

Set the format number. See format for details.

# File lib/gdsii/library.rb, line 256
def format=(val) @records.set(GRT_FORMAT, val); end
format_record() click to toggle source

Get the format record (returns Record).

# File lib/gdsii/library.rb, line 242
def format_record() @records.get(GRT_FORMAT); end
generations() click to toggle source

Get the generations number (returns Fixnum). This number represents how many structures should be retained as backup. This is likely rarely used.

# File lib/gdsii/library.rb, line 232
def generations() @records.get_data(GRT_GENERATIONS); end
generations=(val) click to toggle source

Set the generations number. See generations for details.

# File lib/gdsii/library.rb, line 237
def generations=(val) @records.set(GRT_GENERATIONS, val); end
generations_record() click to toggle source

Get the generations record (returns Record).

# File lib/gdsii/library.rb, line 225
def generations_record() @records.get(GRT_GENERATIONS); end
header() click to toggle source

Get the header number; this is the GDSII version (returns Fixnum).

# File lib/gdsii/library.rb, line 124
def header() @records.get_data(GRT_HEADER); end
Also aliased as: version
header=(val) click to toggle source

Set the header number; this is the GDSII version. Valid numbers are 3, 4, 5, 6, and 7. The default version used is defined by the constant DEF_LIB_VER.

# File lib/gdsii/library.rb, line 131
def header=(val) @records.set(GRT_HEADER, val); end
Also aliased as: version=
header_record() click to toggle source

Get the header record (returns Record).

# File lib/gdsii/library.rb, line 119
def header_record() @records.get(GRT_HEADER); end
m_units() click to toggle source

Get the units in meters (returns Float). Both user and database units must be set. The formula is:

#m_units = #database_units / #user_units

# File lib/gdsii/library.rb, line 353
def m_units()
  ((u=user_units) and (d=database_units)) ? d/u : nil
end
mask() click to toggle source

Get the MASK record (returns Array of String). This is only used in filtered (see format) stream files. This string represents ranges of layers and datatypes separated by a semicolon. There can be more than one MASK defined.

# File lib/gdsii/library.rb, line 279
def mask() @records.get_data(GRT_MASK); end
mask=(val) click to toggle source

Set the mask number. See mask for details.

# File lib/gdsii/library.rb, line 284
def mask=(val) @records.set(GRT_MASK, val); end
mask_record() click to toggle source

Get the mask record (returns Record).

# File lib/gdsii/library.rb, line 271
def mask_record() @records.get(GRT_MASK); end
modify_time() click to toggle source

Returns the modify time for this library (returns Time)

# File lib/gdsii/library.rb, line 390
def modify_time(); @modify_time; end
modify_time=(time) click to toggle source

Accepts a Time object and sets the modify time for the library.

struct.modify_time = Time.now
# File lib/gdsii/library.rb, line 382
def modify_time=(time)
  @modify_time = time
  update_times
end
name() click to toggle source

Get the Library name (returns String).

# File lib/gdsii/library.rb, line 109
def name() @records.get_data(GRT_LIBNAME); end
name=(val) click to toggle source

Set the Library name.

# File lib/gdsii/library.rb, line 114
def name=(val) @records.set(GRT_LIBNAME, val); end
name_record() click to toggle source

Get the Library LIBNAME record (returns Record).

# File lib/gdsii/library.rb, line 104
def name_record() @records.get(GRT_LIBNAME); end
remove(*args) click to toggle source

Shortcut for Gdsii::Access::EnumerableGroup#remove. For example, instead of:

lib.structures.remove {|s| true}

It could be simply:

lib.remove {|s| true}
# File lib/gdsii/library.rb, line 99
def remove(*args); structures.remove(*args); end
secur() click to toggle source

Get the secur number (returns Fixnum). This is an array of 1-32 elements of an array of 3 elements; each containing Fixnum representing (respectively): group number, user number, and access rights. Since this appears to be rarely used, no high-level methods are given to access this record. Returns an Array of Fixnum.

# File lib/gdsii/library.rb, line 182
def secur() @records.get_data(GRT_LIBSECUR); end
secur=(val) click to toggle source

Set the library security number (see secur for details)

# File lib/gdsii/library.rb, line 187
def secur=(val) @records.set(GRT_LIBSECUR, val); end
secur_record() click to toggle source

Get the library security LIBSECUR record (returns Record).

# File lib/gdsii/library.rb, line 173
def secur_record() @records.get(GRT_LIBSECUR); end
srfname() click to toggle source

Get the Library Calma sticks rule file name (returns String). This is likely unused except in rare circumstances.

# File lib/gdsii/library.rb, line 163
def srfname() @records.get_data(GRT_SRFNAME); end
srfname=(val) click to toggle source

Set the Library Calma sticks rule file name (see srfname for details).

# File lib/gdsii/library.rb, line 168
def srfname=(val) @records.set(GRT_SRFNAME, val); end
srfname_record() click to toggle source

Get the Library SRFNAME record (returns Record).

# File lib/gdsii/library.rb, line 157
def srfname_record() @records.get(GRT_SRFNAME); end
structures() click to toggle source

Access to the Structures object. See Structures for a listing of methods.

# File lib/gdsii/library.rb, line 76
def structures(); @records.get(Structures); end
units() click to toggle source

Get the units Array (returns 2 element Array of Float). It may be easier to use the db_units, user_units, and/or m_units methods instead. The units record has two parts, respectively:

  1. User units

  2. Database units

The units in meters can be found by dividing database units by user units (this calculation is done in m_units).

# File lib/gdsii/library.rb, line 302
def units(); @records.get_data(GRT_UNITS); end
units=(val) click to toggle source

Set the units number. See units for details. It may be easier to use db_units= or user_units= instead.

# File lib/gdsii/library.rb, line 308
def units=(val)
  if val.class == Array
    if val.length == 2
      @user_units, @database_units = val
      update_units
    else
      raise ArgumentError, "UNITS Array must have exactly 2 elements"
    end
  else
    raise TypeError, "Expecting 2 element Array; given: #{val.class}"
  end
end
units_record() click to toggle source

Get the units record (returns Record).

# File lib/gdsii/library.rb, line 289
def units_record() @records.get(GRT_UNITS); end
user_units() click to toggle source

Returns the user units (returns Float). See units for details.

# File lib/gdsii/library.rb, line 324
def user_units(); @user_units; end
user_units=(val) click to toggle source

Sets the user units. See units for details.

# File lib/gdsii/library.rb, line 329
def user_units=(val)
  @user_units = val
  update_units
end
version()
Alias for: header
version=(val)
Alias for: header=
write_header(file) { || ... } click to toggle source

Writes only the header portion of the Library to a file. This is useful when streamlined writing is desired (for better performance or when writing GDSII as another GDSII is being read). Be sure to either:

  1. Call write_footer after writing the header and any Structure

objects; Or

  1. Pass a block whereupon the footer will automatically be added after

the block is processed.

Example 1 (manually writing header/footer):

File.open(in_file, 'rb') do |inf|
  File.open(out_file, 'wb') do |outf|
    Library.read_header(inf) do |lib|
      lib.write_header(outf)
      Structure.read_each_header(inf) do |struct|
        struct.write_header(outf)
        Element.read_each(inf) {|element| element.write(outf)}
        struct.write_footer(outf)
      end
      lib.write_footer(outf)
    end
  end
end

Example 2 (using a block):

File.open(in_file, 'rb') do |inf|
  File.open(out_file, 'wb') do |outf|
    Library.read_header(inf) do |lib|
      lib.write_header(outf) do 
        Structure.read_each_header(inf) do |struct|
          struct.write_header(outf) do
            Element.read_each(inf) {|element| element.write(outf)}
          end
        end
      end
    end
  end
end
# File lib/gdsii/library.rb, line 470
def write_header(file)
  # alter the BNF to exclude Structures and ENDLIB; then write to file
  # according to the modified BNF
  alt_bnf = BnfSpec.new(*Library.bnf_spec.bnf_items[0..-3])
  self.write(file, alt_bnf)
  
  # if block is given, then yield to that block and then write the
  # footer afterwards
  if block_given?
    yield
    self.write_footer(file)
  end
end

Private Instance Methods

update_times() click to toggle source

Used by modify_time and access_time

# File lib/gdsii/library.rb, line 499
def update_times()
  if modify_time and access_time
    self.bgnlib = build_time(modify_time) + build_time(access_time)
  else
    self.bgnlib = nil
  end
end
update_units() click to toggle source

Used by various units setting methods

# File lib/gdsii/library.rb, line 508
def update_units()
  if @user_units and @database_units
    @records.set(GRT_UNITS, [@user_units, @database_units])
  else
    @records.set(GRT_UNITS, nil)
  end
end