Class: Gdsii::Library
- Includes:
- Access::GdsiiTime
- Defined in:
- lib/gdsii/library.rb
Overview
Represents a GDSII Library.
Instance Attribute Summary
Attributes inherited from Group
Class Method Summary collapse
-
.read_header(file) ⇒ Object
Reads the Library header data of a GDSII file but does not read any Structure records.
Instance Method Summary collapse
-
#access_time ⇒ Object
Returns the access time for this library (returns Time).
-
#access_time=(time) ⇒ Object
Accepts a Time object and sets the access time for the library.
-
#add(*args) ⇒ Object
Shortcut for Structures#add.
-
#archive_format? ⇒ Boolean
True if #format == 0 indicating archive status; false if not.
-
#attrtable ⇒ Object
Get the attribute table file location.
-
#attrtable=(val) ⇒ Object
Set the attribute table file location.
-
#attrtable_record ⇒ Object
Get the attribute table file location ATTRTABLE record (returns Record).
-
#bgnlib ⇒ Object
Get the bgnlib number (returns Fixnum).
-
#bgnlib=(val) ⇒ Object
Set the bgnlib number.
-
#bgnlib_record ⇒ Object
Get the bgnlib record (returns Record).
-
#database_units ⇒ Object
Returns the database units (returns Float).
-
#database_units=(val) ⇒ Object
Sets the database units.
-
#dirsize ⇒ Object
Get the number of pages in the library directory (returns Fixnum).
-
#dirsize=(val) ⇒ Object
Set the number of pages in the library directory (see #dirsize for more information).
-
#dirsize_record ⇒ Object
Get the library directory size LIBDIRSIZE record (returns Record).
-
#filtered_format? ⇒ Boolean
True if #format == 1 indicating filtered status; false if not.
-
#fonts ⇒ Object
Get the array of paths to font definition files.
-
#fonts=(val) ⇒ Object
Set the path to 4 font definition files.
-
#fonts_record ⇒ Object
Get the fonts record (returns Record).
-
#format ⇒ Object
Get the format number (returns Fixnum).
-
#format=(val) ⇒ Object
Set the format number.
-
#format_record ⇒ Object
Get the format record (returns Record).
-
#generations ⇒ Object
Get the generations number (returns Fixnum).
-
#generations=(val) ⇒ Object
Set the generations number.
-
#generations_record ⇒ Object
Get the generations record (returns Record).
-
#header ⇒ Object
(also: #version)
Get the header number; this is the GDSII version (returns Fixnum).
-
#header=(val) ⇒ Object
(also: #version=)
Set the header number; this is the GDSII version.
-
#header_record ⇒ Object
Get the header record (returns Record).
-
#initialize(name = nil, units = DEF_LIB_UNITS) {|_self| ... } ⇒ Library
constructor
Create a new GDSII Library object.
-
#m_units ⇒ Object
Get the units in meters (returns Float).
-
#mask ⇒ Object
Get the MASK record (returns Array of String).
-
#mask=(val) ⇒ Object
Set the mask number.
-
#mask_record ⇒ Object
Get the mask record (returns Record).
-
#modify_time ⇒ Object
Returns the modify time for this library (returns Time).
-
#modify_time=(time) ⇒ Object
Accepts a Time object and sets the modify time for the library.
-
#name ⇒ Object
Get the Library name (returns String).
-
#name=(val) ⇒ Object
Set the Library name.
-
#name_record ⇒ Object
Get the Library LIBNAME record (returns Record).
-
#remove(*args) ⇒ Object
Shortcut for Structures#remove.
-
#secur ⇒ Object
Get the secur number (returns Fixnum).
-
#secur=(val) ⇒ Object
Set the library security number (see #secur for details).
-
#secur_record ⇒ Object
Get the library security LIBSECUR record (returns Record).
-
#srfname ⇒ Object
Get the Library Calma sticks rule file name (returns String).
-
#srfname=(val) ⇒ Object
Set the Library Calma sticks rule file name (see #srfname for details).
-
#srfname_record ⇒ Object
Get the Library SRFNAME record (returns Record).
-
#structures ⇒ Object
Access to the Structures object.
-
#units ⇒ Object
Get the units Array (returns 2 element Array of Float).
-
#units=(val) ⇒ Object
Set the units number.
-
#units_record ⇒ Object
Get the units record (returns Record).
-
#user_units ⇒ Object
Returns the user units (returns Float).
-
#user_units=(val) ⇒ Object
Sets the user units.
-
#write_footer(file) ⇒ Object
Writes only the Library footer (just ENDLIB record) to file.
-
#write_header(file) ⇒ Object
Writes only the header portion of the Library to a file.
Methods included from Access::GdsiiTime
Methods inherited from Group
bnf_key, bnf_key=, bnf_spec, bnf_spec=, #configure, #validate, #write
Methods included from Read
Constructor Details
#initialize(name = nil, units = DEF_LIB_UNITS) {|_self| ... } ⇒ Library
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |
Class Method Details
.read_header(file) ⇒ Object
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
421 422 423 424 425 426 |
# 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 |
Instance Method Details
#access_time ⇒ Object
Returns the access time for this library (returns Time)
405 |
# File 'lib/gdsii/library.rb', line 405 def access_time(); @access_time; end |
#access_time=(time) ⇒ Object
Accepts a Time object and sets the access time for the library.
struct.access_time = Time.now
397 398 399 400 |
# File 'lib/gdsii/library.rb', line 397 def access_time=(time) @access_time = time update_times end |
#add(*args) ⇒ Object
88 |
# File 'lib/gdsii/library.rb', line 88 def add(*args); structures.add(*args); end |
#archive_format? ⇒ Boolean
True if #format == 0 indicating archive status; false if not.
261 |
# File 'lib/gdsii/library.rb', line 261 def archive_format?(); format == 0; end |
#attrtable ⇒ Object
Get the attribute table file location. This is a String with a maximum of 44 characters in length. Returns String.
215 |
# File 'lib/gdsii/library.rb', line 215 def attrtable() @records.get_data(GRT_ATTRTABLE); end |
#attrtable=(val) ⇒ Object
Set the attribute table file location. See #attrtable for more details.
220 |
# File 'lib/gdsii/library.rb', line 220 def attrtable=(val) @records.set(GRT_ATTRTABLE, val); end |
#attrtable_record ⇒ Object
Get the attribute table file location ATTRTABLE record (returns Record).
209 |
# File 'lib/gdsii/library.rb', line 209 def attrtable_record() @records.get(GRT_ATTRTABLE); end |
#bgnlib ⇒ Object
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.
367 |
# File 'lib/gdsii/library.rb', line 367 def bgnlib() @records.get_data(GRT_BGNLIB); end |
#bgnlib=(val) ⇒ Object
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.
375 |
# File 'lib/gdsii/library.rb', line 375 def bgnlib=(val) @records.set(GRT_BGNLIB, val); end |
#bgnlib_record ⇒ Object
Get the bgnlib record (returns Record).
360 |
# File 'lib/gdsii/library.rb', line 360 def bgnlib_record() @records.get(GRT_BGNLIB); end |
#database_units ⇒ Object
Returns the database units (returns Float). See #units for details.
337 |
# File 'lib/gdsii/library.rb', line 337 def database_units(); @database_units; end |
#database_units=(val) ⇒ Object
Sets the database units. See #units for details.
342 343 344 345 |
# File 'lib/gdsii/library.rb', line 342 def database_units=(val) @database_units = val update_units end |
#dirsize ⇒ Object
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.
146 |
# File 'lib/gdsii/library.rb', line 146 def dirsize() @records.get_data(GRT_LIBDIRSIZE); end |
#dirsize=(val) ⇒ Object
Set the number of pages in the library directory (see #dirsize for more information).
152 |
# File 'lib/gdsii/library.rb', line 152 def dirsize=(val) @records.set(GRT_LIBDIRSIZE, val); end |
#dirsize_record ⇒ Object
Get the library directory size LIBDIRSIZE record (returns Record).
139 |
# File 'lib/gdsii/library.rb', line 139 def dirsize_record() @records.get(GRT_LIBDIRSIZE); end |
#filtered_format? ⇒ Boolean
True if #format == 1 indicating filtered status; false if not.
266 |
# File 'lib/gdsii/library.rb', line 266 def filtered_format?(); format == 1; end |
#fonts ⇒ Object
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.
199 |
# File 'lib/gdsii/library.rb', line 199 def fonts() @records.get_data(GRT_FONTS); end |
#fonts=(val) ⇒ Object
Set the path to 4 font definition files. See #fonts for more details.
204 |
# File 'lib/gdsii/library.rb', line 204 def fonts=(val) @records.set(GRT_FONTS, val); end |
#fonts_record ⇒ Object
Get the fonts record (returns Record).
192 |
# File 'lib/gdsii/library.rb', line 192 def fonts_record() @records.get(GRT_FONTS); end |
#format ⇒ Object
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
251 |
# File 'lib/gdsii/library.rb', line 251 def format() @records.get_data(GRT_FORMAT); end |
#format=(val) ⇒ Object
Set the format number. See #format for details.
256 |
# File 'lib/gdsii/library.rb', line 256 def format=(val) @records.set(GRT_FORMAT, val); end |
#format_record ⇒ Object
Get the format record (returns Record).
242 |
# File 'lib/gdsii/library.rb', line 242 def format_record() @records.get(GRT_FORMAT); end |
#generations ⇒ Object
Get the generations number (returns Fixnum). This number represents how many structures should be retained as backup. This is likely rarely used.
232 |
# File 'lib/gdsii/library.rb', line 232 def generations() @records.get_data(GRT_GENERATIONS); end |
#generations=(val) ⇒ Object
Set the generations number. See #generations for details.
237 |
# File 'lib/gdsii/library.rb', line 237 def generations=(val) @records.set(GRT_GENERATIONS, val); end |
#generations_record ⇒ Object
Get the generations record (returns Record).
225 |
# File 'lib/gdsii/library.rb', line 225 def generations_record() @records.get(GRT_GENERATIONS); end |
#header ⇒ Object Also known as: version
Get the header number; this is the GDSII version (returns Fixnum).
124 |
# File 'lib/gdsii/library.rb', line 124 def header() @records.get_data(GRT_HEADER); end |
#header=(val) ⇒ Object Also known as: version=
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.
131 |
# File 'lib/gdsii/library.rb', line 131 def header=(val) @records.set(GRT_HEADER, val); end |
#header_record ⇒ Object
Get the header record (returns Record).
119 |
# File 'lib/gdsii/library.rb', line 119 def header_record() @records.get(GRT_HEADER); end |
#m_units ⇒ Object
Get the units in meters (returns Float). Both user and database units must be set. The formula is:
m_units = database_units / user_units
353 354 355 |
# File 'lib/gdsii/library.rb', line 353 def m_units() ((u=user_units) and (d=database_units)) ? d/u : nil end |
#mask ⇒ Object
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.
279 |
# File 'lib/gdsii/library.rb', line 279 def mask() @records.get_data(GRT_MASK); end |
#mask=(val) ⇒ Object
Set the mask number. See #mask for details.
284 |
# File 'lib/gdsii/library.rb', line 284 def mask=(val) @records.set(GRT_MASK, val); end |
#mask_record ⇒ Object
Get the mask record (returns Record).
271 |
# File 'lib/gdsii/library.rb', line 271 def mask_record() @records.get(GRT_MASK); end |
#modify_time ⇒ Object
Returns the modify time for this library (returns Time)
390 |
# File 'lib/gdsii/library.rb', line 390 def modify_time(); @modify_time; end |
#modify_time=(time) ⇒ Object
Accepts a Time object and sets the modify time for the library.
struct.modify_time = Time.now
382 383 384 385 |
# File 'lib/gdsii/library.rb', line 382 def modify_time=(time) @modify_time = time update_times end |
#name ⇒ Object
Get the Library name (returns String).
109 |
# File 'lib/gdsii/library.rb', line 109 def name() @records.get_data(GRT_LIBNAME); end |
#name=(val) ⇒ Object
Set the Library name.
114 |
# File 'lib/gdsii/library.rb', line 114 def name=(val) @records.set(GRT_LIBNAME, val); end |
#name_record ⇒ Object
Get the Library LIBNAME record (returns Record).
104 |
# File 'lib/gdsii/library.rb', line 104 def name_record() @records.get(GRT_LIBNAME); end |
#remove(*args) ⇒ Object
Shortcut for Structures#remove. For example, instead of:
lib.structures.remove {|s| true}
It could be simply:
lib.remove {|s| true}
99 |
# File 'lib/gdsii/library.rb', line 99 def remove(*args); structures.remove(*args); end |
#secur ⇒ Object
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.
182 |
# File 'lib/gdsii/library.rb', line 182 def secur() @records.get_data(GRT_LIBSECUR); end |
#secur=(val) ⇒ Object
Set the library security number (see #secur for details)
187 |
# File 'lib/gdsii/library.rb', line 187 def secur=(val) @records.set(GRT_LIBSECUR, val); end |
#secur_record ⇒ Object
Get the library security LIBSECUR record (returns Record).
173 |
# File 'lib/gdsii/library.rb', line 173 def secur_record() @records.get(GRT_LIBSECUR); end |
#srfname ⇒ Object
Get the Library Calma sticks rule file name (returns String). This is likely unused except in rare circumstances.
163 |
# File 'lib/gdsii/library.rb', line 163 def srfname() @records.get_data(GRT_SRFNAME); end |
#srfname=(val) ⇒ Object
Set the Library Calma sticks rule file name (see #srfname for details).
168 |
# File 'lib/gdsii/library.rb', line 168 def srfname=(val) @records.set(GRT_SRFNAME, val); end |
#srfname_record ⇒ Object
Get the Library SRFNAME record (returns Record).
157 |
# File 'lib/gdsii/library.rb', line 157 def srfname_record() @records.get(GRT_SRFNAME); end |
#structures ⇒ Object
Access to the Structures object. See Structures for a listing of methods.
76 |
# File 'lib/gdsii/library.rb', line 76 def structures(); @records.get(Structures); end |
#units ⇒ Object
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).
302 |
# File 'lib/gdsii/library.rb', line 302 def units(); @records.get_data(GRT_UNITS); end |
#units=(val) ⇒ Object
Set the units number. See #units for details. It may be easier to use #db_units= or #user_units= instead.
308 309 310 311 312 313 314 315 316 317 318 319 |
# 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 ⇒ Object
Get the units record (returns Record).
289 |
# File 'lib/gdsii/library.rb', line 289 def units_record() @records.get(GRT_UNITS); end |
#user_units ⇒ Object
Returns the user units (returns Float). See #units for details.
324 |
# File 'lib/gdsii/library.rb', line 324 def user_units(); @user_units; end |
#user_units=(val) ⇒ Object
Sets the user units. See #units for details.
329 330 331 332 |
# File 'lib/gdsii/library.rb', line 329 def user_units=(val) @user_units = val update_units end |
#write_footer(file) ⇒ Object
Writes only the Library footer (just ENDLIB record) to file. To be used with #write_header.
488 489 490 |
# File 'lib/gdsii/library.rb', line 488 def (file) Record.new(GRT_ENDLIB).write(file) end |
#write_header(file) ⇒ Object
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.(outf)
end
lib.(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
470 471 472 473 474 475 476 477 478 479 480 481 482 |
# 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.(file) end end |