class Joseph::Image

Public Class Methods

create() click to toggle source
# File lib/joseph/image.rb, line 3
def self.create
  Bridge.gerbv_create_image nil, nil
end
memory_map() click to toggle source
# File lib/joseph/image.rb, line 7
def self.memory_map
  f = {}
  f[:layertype] = :int

  # Ugly as hell but works
  9999.times do |ix|
    sym = "aperture_#{ix}".to_sym
    f[sym] = Aperture.by_ref
  end

  f[:layers] = :pointer
  f[:states] = :pointer
  f[:amacro] = :pointer
  f[:format] = :pointer
  f[:info] = ImageInfo.by_ref
  f[:netlist] = :pointer
  f[:gerbv_stats] = :pointer
  f[:drill_stats] = :pointer
  f
end

Public Instance Methods

add(image, transformation = UserTransformation.new) click to toggle source
# File lib/joseph/image.rb, line 30
def add(image, transformation = UserTransformation.new)
  Bridge.gerbv_image_copy_image(image.pointer, transformation.pointer, self.pointer)

  # Check if polarity reset is necessary
  return if image.last_layer[:polarity] == 2
  # As Gerbv does not reset polarity, we add another 'dummy' layer with dark polarity
  # Afterwards a zero flash is created and associated to the new created layer
  # Otherwise some strange memory issue occours when dumping the image

  # Reset polarity of both images
  layer = Bridge.gerbv_image_return_new_layer(last_layer)
  layer[:polarity] = 2 # Default polarity

  each_net do |net|
    if net[:next].null?
      dummy = Bridge.gerber_create_new_net(net, layer, nil)
      dummy[:interpolation] = 8 # Do not draw net / GERBV_INTERPOLATION_DELETED
    end
  end

  nil
end
crop!(bb) click to toggle source
# File lib/joseph/image.rb, line 114
def crop!(bb)
  each_net do |net|
    net[:start_y] = [bb[:bottom], net[:start_y]].min
    net[:stop_y] = [bb[:bottom], net[:stop_y]].min
    net[:start_x] = [bb[:left], net[:start_x]].max
    net[:stop_x] = [bb[:left], net[:stop_x]].max
    net[:start_y] = [bb[:top], net[:start_y]].max
    net[:stop_y] = [bb[:top], net[:stop_y]].max
    net[:start_x] = [bb[:right], net[:start_x]].min
    net[:stop_x] = [bb[:right], net[:stop_x]].min
  end
end
destroy!() click to toggle source
# File lib/joseph/image.rb, line 139
def destroy!
  Bridge.gerbv_destroy_image(self)
end
drill?() click to toggle source
# File lib/joseph/image.rb, line 131
def drill?
  self[:layertype] == 1
end
duplicate(transformation = nil) click to toggle source
# File lib/joseph/image.rb, line 53
def duplicate(transformation = nil)
  Bridge.gerbv_image_duplicate_image(self, transformation)
end
each_layer() { |layer| ... } click to toggle source
# File lib/joseph/image.rb, line 91
def each_layer(&block)
  address = self[:layers]
  loop do
    layer = Layer.new(address)
    yield(layer)

    address = layer[:next]
    break if address.null?
  end
end
each_net() { |net| ... } click to toggle source
# File lib/joseph/image.rb, line 67
def each_net(&block)
  address = self[:netlist]
  loop do
    net = Net.new(address)
    yield(net) unless net[:aperture_state] == 0

    # Keep address of next net and return if not available
    address = net[:next]
    break if address.null?
  end
end
info() click to toggle source
# File lib/joseph/image.rb, line 135
def info
  self[:info]
end
last_layer() click to toggle source
# File lib/joseph/image.rb, line 108
def last_layer
  layer = nil
  each_layer { |l| layer = l }
  layer
end
last_net() click to toggle source
# File lib/joseph/image.rb, line 85
def last_net
  net = nil
  each_net { |n| net = n }
  net
end
layer_count() click to toggle source
# File lib/joseph/image.rb, line 102
def layer_count
  c = 0
  each_layer { c += 1 }
  c
end
net_count() click to toggle source
# File lib/joseph/image.rb, line 79
def net_count
  c = 0
  each_net { c += 1 }
  c
end
rs274x?() click to toggle source
# File lib/joseph/image.rb, line 127
def rs274x?
  self[:layertype] == 0
end
to_output(store = Ramdo::Store.new) click to toggle source
# File lib/joseph/image.rb, line 57
def to_output(store = Ramdo::Store.new)
  if rs274x?
    Bridge.gerbv_export_rs274x_file_from_image(store.file, self, UserTransformation.new)
  elsif drill?
    Bridge.gerbv_export_drill_file_from_image(store.file, self, UserTransformation.new)
  end

  store
end