Module: RQRCode::Export::Gerber

Defined in:
lib/rqrcode/export/gerber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mirroredObject

Returns the value of attribute mirrored.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def mirrored
  @mirrored
end

#pixel_widthObject

Returns the value of attribute pixel_width.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def pixel_width
  @pixel_width
end

#positiveObject

Returns the value of attribute positive.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def positive
  @positive
end

#precisionObject

Returns the value of attribute precision.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def precision
  @precision
end

#quiet_zone_sizeObject

Returns the value of attribute quiet_zone_size.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def quiet_zone_size
  @quiet_zone_size
end

#x_originObject

Returns the value of attribute x_origin.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def x_origin
  @x_origin
end

#y_originObject

Returns the value of attribute y_origin.



4
5
6
# File 'lib/rqrcode/export/gerber.rb', line 4

def y_origin
  @y_origin
end

Instance Method Details

#as_gerber(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rqrcode/export/gerber.rb', line 34

def as_gerber(options={})
  options = {
    precision: 6,
    pixel_width: 0.010, # inches
    x_origin: 0.000, # inches
    y_origin: 0.000, # inches
    quiet_zone_size: 1,
    mirrored: false
  }.merge(options)
  @x_origin = options.fetch(:x_origin)
  @y_origin = options.fetch(:y_origin)
  @precision = options.fetch(:precision)
  @pixel_width = options.fetch(:pixel_width)
  @quiet_zone_size = options.fetch(:quiet_zone_size)
  @mirrored = options.fetch(:mirrored)

  @p_mult = 10**options[:precision]

  output="G04 This is an RQRCode Generated gerber file.*\nG04 --End of header info--*\n%MOIN*%\n%FSLAX3\#{options[:precision]}Y3\#{options[:precision]}*%\n%IPPOS*%\n%ADD10R,\#{options[:pixel_width]}X\#{options[:pixel_width]}*%\nG04 --Start main section--*\nG54D10*\n  EOF\n\n  quiet_zone_size = options.fetch(:quiet_zone_size)\n\n  width = quiet_zone_size + @module_count + quiet_zone_size\n\n  quiet_zone_size.times do |r|\n    width.times do |c|\n      output << flash(c,r) ## Top Quiet Zone\n      output << flash(r,c) ## Left Quiet Zone\n      output << flash(r+quiet_zone_size+@module_count,c)\n      output << flash(c,r+quiet_zone_size+@module_count)\n    end\n  end\n\n\n  @modules.each_index do |r|\n    @modules[r].each_index do |c|\n      if is_light(r, c)\n        output << flash(quiet_zone_size+c,quiet_zone_size+r)\n      end\n    end\n  end\n\n  output << \"M02*\\n\"\n\n  return output\nend\n"

#flash(x, y) ⇒ Object

Returns a string of the QR code as characters writen with ANSI background set.

Options: light: Foreground (“033[47m”) dark: Background ANSI code. (“033[47m”) fill_character: The written character. (‘ ’) quiet_zone_size: (4)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rqrcode/export/gerber.rb', line 15

def flash(x,y)
  top_y = (@y_origin + @module_count + (@quiet_zone_size *2 )) * @pixel_width
  y = top_y - (y * @pixel_width)
  if @mirrored then
    right_x = (@x_origin + @module_count + (@quiet_zone_size*2)) * @pixel_width
    x = right_x - (x * @pixel_width)
  else
    x = @x_origin + x * @pixel_width
  end
  #puts "FLASH #{x} #{y}"
  y = (y * @p_mult).to_i
  x = (x * @p_mult).to_i
  return "G01X#{x}Y#{y}D03*\n"
end

#is_light(x, y) ⇒ Object



30
31
32
# File 'lib/rqrcode/export/gerber.rb', line 30

def is_light(x,y)
  ! is_dark(x,y)
end