class Gdsii::ARef

Represents a GDSII structure array reference (ARef) element. Most methods are from Element or from the various included Access module methods.

Public Class Methods

new(sname=nil, ref_xy=nil, colrow=nil, colrow_spc=nil) { |self| ... } click to toggle source

Create a new structure array reference (ARef) to be used within a Structure object. The structure name is a String or anything that has a to_s method. The #ref_xy is a single set of x/y coordinates that the placement of the ARef (note this is NOT the same as the XY record for ARef - see xy_record for more details). The colrow is an array of a number of columns and rows respectively. The colrow_spc is an array of spacing values for columns and rows respectively.

# Create an ARef at coordinates (0,0) with 2 columns and 8 rows.  The
# spacing between columns is 200 units and between rows is 300 units.
aref = ARef.new('array', [0,0], [2,8], [200, 300])

Note, the ref_xy, column_space, and row_space are required. See xy_record for details.

Calls superclass method
# File lib/gdsii/aref.rb, line 53
def initialize(sname=nil, ref_xy=nil, colrow=nil, colrow_spc=nil)
  super()      
  @records[GRT_AREF] = Record.new(GRT_AREF)
  self.sname = sname unless sname.nil?
  self.colrow = colrow unless colrow.nil?
  self.ref_xy = ref_xy unless ref_xy.nil?
  self.column_space = colrow_spc[0] if colrow_spc.class == Array
  self.row_space = colrow_spc[1] if colrow_spc.class == Array
  yield self if block_given?
end

Public Instance Methods

colrow() click to toggle source

Get the colrow array of numbers (returns 2-element Array of Fixnum) where the first number is columns and the second is rows [col, row]. Alternatively, the rows and columns method may also be used.

aref.colrow  #=> [2, 8]
# File lib/gdsii/aref.rb, line 76
def colrow() @records.get_data(GRT_COLROW); end
colrow=(val) click to toggle source

Set the colrow number (see colrow for format details). Alternatively, the rows= and columns= methods may be used.

aref.colrow = [2, 8]
# File lib/gdsii/aref.rb, line 84
def colrow=(val) @records.set(GRT_COLROW, val); end
colrow_record() click to toggle source

Get the colrow record (returns Record)

# File lib/gdsii/aref.rb, line 67
def colrow_record() @records.get(GRT_COLROW); end
column_space() click to toggle source

Returns the placement XY coordinate for this ARef. See xy_record for details on how the XY record is used in ARef.

aref.column_space  #=> 200
# File lib/gdsii/aref.rb, line 171
def column_space(); @column_space; end
column_space=(val) click to toggle source

Defines the column spacing (in units) for this ARef. Internally this value is stored in the XY record. See xy_record for details on how the XY record is used in ARef.

aref.column_space = 200
# File lib/gdsii/aref.rb, line 160
def column_space=(val)
  @column_space = val
  update_xy
end
columns() click to toggle source

Get the columns number in the COLROW record (returns Fixnum)

aref.columns  #=> 2
# File lib/gdsii/aref.rb, line 104
def columns()
  (cr=@records.get(GRT_COLROW)) ? cr[0] : nil
end
columns=(val) click to toggle source

Set the columns number in the COLROW record (Fixnum)

aref.columns = 2
# File lib/gdsii/aref.rb, line 91
def columns=(val)
  if (cr=colrow)
    @records.set(GRT_COLROW, [val, cr[1]])
  else
    @records.set(GRT_COLROW, [val, nil])
  end
end
ref_xy() click to toggle source

Returns the placement XY coordinate for this ARef. See xy_record for details on how the XY record is used in ARef.

aref.ref_xy  #=> [10, 20]
# File lib/gdsii/aref.rb, line 151
def ref_xy(); @ref_xy; end
ref_xy=(val) click to toggle source

Defines the placement XY coordinate for this ARef. See xy_record for details on how the XY record is used in ARef.

aref.ref_xy = [10, 20]
# File lib/gdsii/aref.rb, line 136
def ref_xy=(val)
  if val.class == Array and val.length == 2
    @ref_xy = val
    update_xy
  else
    raise TypeError, "Expected Array of length 2"
  end
end
row_space() click to toggle source

Returns the placement XY coordinate for this ARef. See xy_record for details on how the XY record is used in ARef.

aref.row_space  #=> 300
# File lib/gdsii/aref.rb, line 191
def row_space(); @row_space; end
row_space=(val) click to toggle source

Defines the row spacing (in units) for this ARef. Internally this value is stored in the XY record. See xy_record for details on how the XY record is used in ARef.

aref.row_space = 300
# File lib/gdsii/aref.rb, line 180
def row_space=(val)
  @row_space = val
  update_xy
end
rows() click to toggle source

Get the rows number in the COLROW record (returns Fixnum)

aref.rows  #=> 8
# File lib/gdsii/aref.rb, line 126
def rows()
  (cr=@records.get(GRT_COLROW)) ? cr[1] : nil
end
rows=(val) click to toggle source

Set the rows number in the COLROW record

aref.rows = 8
# File lib/gdsii/aref.rb, line 113
def rows=(val)
  if (cr=colrow)
    @records.set(GRT_COLROW, [cr[0], val])
  else
    @records.set(GRT_COLROW, [nil, val])
  end
end
xy() click to toggle source

Gets an xy point record (returns an Array). Note, it is probably easier to use ref_xy, column_space, or row_space instead; see xy_record for details on how the XY record is used for ARef.

# File lib/gdsii/aref.rb, line 215
def xy() @records.get_data(GRT_XY); end
xy_record() click to toggle source

Gets the ARef record for XY.

Important note on the XY record (i.e. xy, xy_record): the GDSII specification calls for exactly 3 XY records for ARef. Because of this specification, there is no xy= method available for the ARef class. Instead, the XY record is created dynamically when all three of these components are set. Otherwise, the XY record will not exist.

The XY record data specification is as follows:

# File lib/gdsii/aref.rb, line 208
def xy_record() @records.get(GRT_XY); end

Private Instance Methods

update_xy() click to toggle source

Update the GRT_XY record if all prerequisites are met (#ref_xy, column_space, and row_space).

# File lib/gdsii/aref.rb, line 228
def update_xy()
  if ((pxy=ref_xy) and (cs=column_space) and (rs=row_space) and (cr=colrow).length == 2)
    # see #xy_record for an explanation of this formula
    array = pxy + [pxy[0]+cs*cr[0], pxy[1]] + [pxy[0], pxy[1]+rs*cr[1]]
    @records.set(GRT_XY, array)
  else
    @records.set(GRT_XY, nil)
  end
end