class Gdsii::Library
Represents a GDSII Library.
Public Class Methods
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])
# 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
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
Returns the access time for this library (returns Time)
# File lib/gdsii/library.rb, line 405 def access_time(); @access_time; end
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
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
True if format == 0 indicating archive status; false if not.
# File lib/gdsii/library.rb, line 261 def archive_format?(); format == 0; end
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
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
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
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
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
Get the bgnlib record (returns Record).
# File lib/gdsii/library.rb, line 360 def bgnlib_record() @records.get(GRT_BGNLIB); end
Returns the database units (returns Float). See units for details.
# File lib/gdsii/library.rb, line 337 def database_units(); @database_units; end
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
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
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
Get the library directory size LIBDIRSIZE record (returns Record).
# File lib/gdsii/library.rb, line 139 def dirsize_record() @records.get(GRT_LIBDIRSIZE); end
True if format == 1 indicating filtered status; false if not.
# File lib/gdsii/library.rb, line 266 def filtered_format?(); format == 1; end
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
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
Get the fonts record (returns Record).
# File lib/gdsii/library.rb, line 192 def fonts_record() @records.get(GRT_FONTS); end
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
Set the format number. See format for details.
# File lib/gdsii/library.rb, line 256 def format=(val) @records.set(GRT_FORMAT, val); end
Get the format record (returns Record).
# File lib/gdsii/library.rb, line 242 def format_record() @records.get(GRT_FORMAT); end
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
Set the generations number. See generations for details.
# File lib/gdsii/library.rb, line 237 def generations=(val) @records.set(GRT_GENERATIONS, val); end
Get the generations record (returns Record).
# File lib/gdsii/library.rb, line 225 def generations_record() @records.get(GRT_GENERATIONS); end
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
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
Get the header record (returns Record).
# File lib/gdsii/library.rb, line 119 def header_record() @records.get(GRT_HEADER); end
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
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
Set the mask number. See mask for details.
# File lib/gdsii/library.rb, line 284 def mask=(val) @records.set(GRT_MASK, val); end
Get the mask record (returns Record).
# File lib/gdsii/library.rb, line 271 def mask_record() @records.get(GRT_MASK); end
Returns the modify time for this library (returns Time)
# File lib/gdsii/library.rb, line 390 def modify_time(); @modify_time; end
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
Get the Library name (returns String).
# File lib/gdsii/library.rb, line 109 def name() @records.get_data(GRT_LIBNAME); end
Set the Library name.
# File lib/gdsii/library.rb, line 114 def name=(val) @records.set(GRT_LIBNAME, val); end
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
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
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
Get the library security LIBSECUR record (returns Record).
# File lib/gdsii/library.rb, line 173 def secur_record() @records.get(GRT_LIBSECUR); end
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
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
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:
-
User units
-
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
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
Get the units record (returns Record).
# File lib/gdsii/library.rb, line 289 def units_record() @records.get(GRT_UNITS); end
Returns the user units (returns Float). See units for details.
# File lib/gdsii/library.rb, line 324 def user_units(); @user_units; end
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
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:
-
Call write_footer after writing the header and any Structure
objects; Or
-
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
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
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