Class: Kut::Library::SimpleGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/kut/library/generator/simple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimpleGenerator

Returns a new instance of SimpleGenerator.



11
12
13
14
15
16
# File 'lib/kut/library/generator/simple.rb', line 11

def initialize
  @name = :simple
  @options = OpenStruct.new
  @options.pin_step = 100
  @options.pin_space = 400
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/kut/library/generator/simple.rb', line 9

def name
  @name
end

Instance Method Details

#generate(in_f, out_f) ⇒ Object

Generate library component in_f input file out_f output file



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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/kut/library/generator/simple.rb', line 53

def generate(in_f, out_f)
  pins_desc = Kut::Library::PinsParser.parse(in_f)
  all_pins = pins_desc.other_pins + pins_desc.left_pins + 
    pins_desc.right_pins + pins_desc.top_pins + pins_desc.bottom_pins
  all_pins.compact! # may be to contain nil
  all_pins.sort! { |x,y| Integer(x[1]) <=> Integer(y[1]) }
    
  left_pins = all_pins[0 ... all_pins.length / 4]
  bottom_pins = all_pins[(all_pins.length / 4) .. (all_pins.length / 4 * 2 - 1)]
  right_pins = all_pins[(all_pins.length / 4 * 2) .. (all_pins.length / 4 * 3 - 1)]
  top_pins = all_pins[(all_pins.length / 4 * 3) .. (all_pins.length - 1)]
    
  top_pins.reverse!
  right_pins.reverse! 
  
  pin_name_max_length = 0
  all_pins.each { |pin| pin_name_max_length = [pin[0].size, pin_name_max_length].max }
  snom = 60
  
  step = @options.pin_step 
  space = @options.pin_space
  
  x_size = [top_pins.length-1, bottom_pins.length-1].max*step + 2*space
  y_size = [left_pins.length-1, right_pins.length-1].max*step + 2*space
  
  cmp_name = pins_desc.names[0] if pins_desc.names && pins_desc.names.size() > 0
  cmp_name = @options.name if @options.name
  cmp_ref = pins_desc.reference
  cmp_ref = @options.reference if @options.reference
  
  cmp_alias = pins_desc.names[1 .. pins_desc.names.size - 1] if pins_desc.names && pins_desc.names.size > 1
  cmp_alias = @options.alias if @options.alias
  
  component = Component.new(:name => cmp_name, :reference => cmp_ref)
  component.fields << Field.new(:number => 0, :text => cmp_ref, :pos => [x_size / 2, -y_size / 2 + 50])
  component.fields << Field.new(:number => 1, :text => cmp_name, :pos => [x_size / 2, -y_size / 2 - 50])
  component.alias = cmp_alias
  component.draws << Rectangle.new(:end => [x_size, -y_size])
  
  x, y = 0, -space
  pin_len = 300
  left_pins.each { |pin|
    component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x - pin_len, y], :orientation => 'R')
    y -= step
  }
  
  x, y = x_size, -space
  right_pins.each { |pin|
    component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x + pin_len, y], :orientation => 'L')
    y -= step
  }
  
   
  x, y = space, 0
  top_pins.each { |pin|
    component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x, y + pin_len], :orientation => 'D')
    x += step
  }
  
  x, y = space, -y_size
  bottom_pins.each { |pin|
    component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x, y - pin_len], :orientation => 'U')
    x += step
  }  
  
  component
end

#helpObject



18
19
20
# File 'lib/kut/library/generator/simple.rb', line 18

def help
  'How to use this generator is help string'
end

#prepare(args) ⇒ Object

Preapare generator for generate library component



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kut/library/generator/simple.rb', line 22

def prepare(args)
  opts = OptionParser.new do |opts|
    opts.banner = '' #"Usage: kut #{self.name} [options]"
    
    opts.on("--pin-step PIN_STEP", "Pin step in mils.") do |step|
      @options.pin_step = step.to_i()
    end
          
    opts.on("--pin-space PIN_SPACE","Pin space in mils.") do |space|
      @options.pin_space = space.to_i()
    end
          
    opts.on("--alias ALIAS", "Component alias.") do |al|
      @options.alias = al
    end   
          
    opts.on("--name NAME", "Component name.") do |name|
      @options.name = name
    end
    
    opts.on("--ref REFERENCE", "Component reference.") do |ref|
      @options.reference = ref
    end
  end
  opts.parse!(args)
  opts
end