kut 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/LICENSE.rdoc +6 -0
  2. data/README.rdoc +20 -0
  3. data/Rakefile.rb +63 -0
  4. data/bin/kut +27 -0
  5. data/doc-src/PINS.rdoc +18 -0
  6. data/examples/example_helper.rb +1 -0
  7. data/examples/net_list/print_cmp_list.rb +101 -0
  8. data/examples/pins/A3P1000_PQFP208.pins +216 -0
  9. data/examples/pins/AT32UC3A0512.pins +151 -0
  10. data/examples/pins/EMP7464S_TQFP100.pins +101 -0
  11. data/examples/pins/ata40conn.pins +44 -0
  12. data/examples/pins/full_sata.pins +25 -0
  13. data/examples/pins/jm20330.pins +85 -0
  14. data/lib/kut.rb +2 -0
  15. data/lib/kut/application.rb +56 -0
  16. data/lib/kut/commands/gost/bom2el_list.rb +171 -0
  17. data/lib/kut/commands/help-cmd.rb +32 -0
  18. data/lib/kut/commands/lib-gen-cmd.rb +88 -0
  19. data/lib/kut/commands/net_list2bom.rb +81 -0
  20. data/lib/kut/eeschema/wire.rb +3 -0
  21. data/lib/kut/kut_module.rb +18 -0
  22. data/lib/kut/library/components.rb +167 -0
  23. data/lib/kut/library/generator.rb +25 -0
  24. data/lib/kut/library/generator/default.rb +123 -0
  25. data/lib/kut/library/generator/gost-con.rb +116 -0
  26. data/lib/kut/library/generator/simple.rb +123 -0
  27. data/lib/kut/library/pins_reader.rb +47 -0
  28. data/lib/kut/library/regexp.rb +18 -0
  29. data/lib/kut/misc/matrix.rb +2 -0
  30. data/lib/kut/misc/point.rb +25 -0
  31. data/lib/kut/misc/rectangle.rb +20 -0
  32. data/lib/kut/net_list/concept.rb +20 -0
  33. data/lib/kut/net_list/kicad.rb +40 -0
  34. data/lib/kut/net_list/pcad.rb +69 -0
  35. data/lib/kut/tests/Rakefile.rb +0 -0
  36. data/lib/kut/tests/rectangle.rb +23 -0
  37. data/test/library_cmp_pin_test.rb +16 -0
  38. data/test/library_pins_reader_test.rb +40 -0
  39. data/test/point_test.rb +17 -0
  40. metadata +100 -0
@@ -0,0 +1,25 @@
1
+ module Kut
2
+ module Library
3
+
4
+ #Generator concept
5
+ class Generator
6
+ attr_reader :name
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def help
13
+ 'How to use this generator is help string'
14
+ end
15
+
16
+ #Generate library
17
+ #Options for all generators: :no_lib_decl - output only components without library head and end
18
+ #in_f input file
19
+ #out_f output file
20
+ def generate(in_f, out_f, options)
21
+ end
22
+ end
23
+
24
+ end # end module Library
25
+ end # end module Kut
@@ -0,0 +1,123 @@
1
+ require 'kut/library/generator'
2
+ require 'kut/library/pins_reader'
3
+ require 'kut/library/components'
4
+
5
+ module Kut
6
+ module Library
7
+
8
+ class DefaultGenerator
9
+ attr_reader :name
10
+
11
+ def initialize
12
+ @name = :default
13
+ @options = OpenStruct.new
14
+ @options.pin_step = 100
15
+ @options.pin_space = 400
16
+ end
17
+
18
+ def help
19
+ 'How to use this generator is help string'
20
+ end
21
+ #Preapare generator for generate library component
22
+ def prepare(args)
23
+ opts = OptionParser.new do |opts|
24
+ opts.banner = '' #"Usage: kut #{self.name} [options]"
25
+
26
+ opts.on("--pin-step PIN_STEP", "Pin step in mils.") do |step|
27
+ @options.pin_step = step.to_i()
28
+ end
29
+
30
+ opts.on("--pin-space PIN_SPACE","Pin space in mils.") do |space|
31
+ @options.pin_space = space.to_i()
32
+ end
33
+
34
+ opts.on("--alias ALIAS", "Component alias.") do |al|
35
+ @options.alias = al
36
+ end
37
+
38
+ opts.on("--name NAME", "Component name.") do |name|
39
+ @options.name = name
40
+ end
41
+
42
+ opts.on("--ref REFERENCE", "Component reference.") do |ref|
43
+ @options.reference = ref
44
+ end
45
+ end
46
+ opts.parse!(args)
47
+ opts
48
+ end
49
+
50
+ #Generate library component
51
+ #in_f input file
52
+ #out_f output file
53
+ def generate(in_f, out_f)
54
+ pins_desc = Kut::Library::PinsParser.parse(in_f)
55
+
56
+ left_pins = pins_desc.left_pins + pins_desc.other_pins
57
+ bottom_pins = pins_desc.bottom_pins
58
+ right_pins = pins_desc.right_pins
59
+ top_pins = pins_desc.top_pins
60
+
61
+ pin_name_max_length = 0
62
+ left_pins.each { |pin| pin_name_max_length = [pin[0].size, pin_name_max_length].max if pin }
63
+ bottom_pins.each { |pin| pin_name_max_length = [pin[0].size, pin_name_max_length].max if pin }
64
+ right_pins.each { |pin| pin_name_max_length = [pin[0].size, pin_name_max_length].max if pin }
65
+ top_pins.each { |pin| pin_name_max_length = [pin[0].size, pin_name_max_length].max if pin }
66
+ snom = 60
67
+
68
+ step = @options.pin_step
69
+ space = @options.pin_space
70
+
71
+ x_size = [top_pins.length-1, bottom_pins.length-1].max*step + 2*space
72
+ y_size = [left_pins.length-1, right_pins.length-1].max*step + 2*space
73
+
74
+ cmp_name = pins_desc.names[0] if pins_desc.names && pins_desc.names.size() > 0
75
+ cmp_name = @options.name if @options.name
76
+ cmp_ref = pins_desc.reference
77
+ cmp_ref = @options.reference if @options.reference
78
+
79
+ cmp_alias = pins_desc.names[1 .. pins_desc.names.size - 1] if pins_desc.names && pins_desc.names.size > 1
80
+ cmp_alias = @options.alias if @options.alias
81
+
82
+ component = Component.new(:name => cmp_name, :reference => cmp_ref)
83
+ component.fields << Field.new(:number => 0, :text => cmp_ref, :pos => [x_size / 2, -y_size / 2 + 50])
84
+ component.fields << Field.new(:number => 1, :text => cmp_name, :pos => [x_size / 2, -y_size / 2 - 50])
85
+ component.alias = cmp_alias
86
+ component.draws << Rectangle.new(:end => [x_size, -y_size])
87
+
88
+ x, y = 0, -space
89
+ pin_len = 300
90
+ left_pins.each { |pin|
91
+ component.draws << Pin.new(:name => pin[0], :number => pin[1],
92
+ :pos => [x - pin_len, y], :orientation => 'R') if pin
93
+ y -= step
94
+ }
95
+
96
+ x, y = x_size, -space
97
+ right_pins.each { |pin|
98
+ component.draws << Pin.new(:name => pin[0], :number => pin[1],
99
+ :pos => [x + pin_len, y], :orientation => 'L') if pin
100
+ y -= step
101
+ }
102
+
103
+
104
+ x, y = space, 0
105
+ top_pins.each { |pin|
106
+ component.draws << Pin.new(:name => pin[0], :number => pin[1],
107
+ :pos => [x, y + pin_len], :orientation => 'D') if pin
108
+ x += step
109
+ }
110
+
111
+ x, y = space, -y_size
112
+ bottom_pins.each { |pin|
113
+ component.draws << Pin.new(:name => pin[0], :number => pin[1],
114
+ :pos => [x, y - pin_len], :orientation => 'U') if pin
115
+ x += step
116
+ }
117
+
118
+ component
119
+ end
120
+ end
121
+
122
+ end # end module Library
123
+ end # end module Kut
@@ -0,0 +1,116 @@
1
+ require 'kut/library/generator'
2
+ require 'kut/library/pins_reader'
3
+ require 'kut/library/components'
4
+
5
+ module Kut
6
+ module Library
7
+
8
+ class GOSTConnGenerator
9
+ attr_reader :name
10
+
11
+ def initialize
12
+ @name = :gost_con
13
+ @options = OpenStruct.new
14
+ @options.pin_step = 100
15
+ end
16
+
17
+ def help
18
+ 'How to use this generator is help string'
19
+ end
20
+ #Preapare generator for generate library component
21
+ def prepare(args)
22
+ opts = OptionParser.new do |opts|
23
+ opts.banner = '' #"Usage: kut #{self.name} [options]"
24
+
25
+ opts.on("--pin-step PIN_STEP", "Pin step in mils.") do |step|
26
+ @options.pin_step = step.to_i()
27
+ end
28
+
29
+ opts.on("--alias ALIAS", "Component alias.") do |al|
30
+ @options.alias = al
31
+ end
32
+
33
+ opts.on("--name NAME", "Component name.") do |name|
34
+ @options.name = name
35
+ end
36
+
37
+ opts.on("--ref REFERENCE", "Component reference.") do |ref|
38
+ @options.reference = ref
39
+ end
40
+
41
+ opts.on('--no-pins', "Generate component without pins.") do
42
+ @options.no_pins = true
43
+ end
44
+
45
+ end
46
+ opts.parse!(args)
47
+ opts
48
+ end
49
+
50
+ #Generate library component
51
+ #in_f input file
52
+ #out_f output file
53
+ def generate(in_f, out_f)
54
+ pins_desc = Kut::Library::PinsParser.parse(in_f)
55
+ all_pins = pins_desc.other_pins + pins_desc.left_pins +
56
+ pins_desc.right_pins + pins_desc.top_pins + pins_desc.bottom_pins
57
+ all_pins.compact! # may be to contain nil
58
+ all_pins.sort! { |x,y| Integer(x[1]) <=> Integer(y[1]) }
59
+
60
+ max_length = [4, 5] # цепь, конт.
61
+ all_pins.each { |pin|
62
+ max_length[0] = [pin[0].size, max_length[0]].max
63
+ max_length[0] = [pin[0].size, max_length[0]].max
64
+ }
65
+
66
+ font_size = 60
67
+
68
+ step = @options.pin_step
69
+
70
+ y_size = all_pins.length*step + step
71
+ x_size = (max_length[0] + max_length[1] + 4)*font_size
72
+
73
+ cmp_name = pins_desc.names[0] if pins_desc.names && pins_desc.names.size() > 0
74
+ cmp_name = @options.name if @options.name
75
+ cmp_ref = pins_desc.reference
76
+ cmp_ref = @options.reference if @options.reference
77
+
78
+ cmp_alias = pins_desc.names[1 .. pins_desc.names.size - 1] if pins_desc.names && pins_desc.names.size > 1
79
+ cmp_alias = @options.alias if @options.alias
80
+
81
+ component = Component.new(:name => cmp_name, :reference => cmp_ref,
82
+ :draw_pinname => 'N', :draw_pinnumber=> 'N', :text_offset => 0)
83
+ component.alias = cmp_alias
84
+ component.draws << Rectangle.new(:start => [0, step + step /2], :end => [x_size, -y_size + step + step /2])
85
+ x = (max_length[1] + 2)*font_size
86
+ component.draws << Polygon.new(:points => [[x, step + step /2], [x, -y_size + step + step /2]])
87
+
88
+ component.fields << Field.new(:number => 0, :text => cmp_ref, :pos => [x, step + step /2 + 50])
89
+ component.fields << Field.new(:number => 1, :text => cmp_name, :pos => [x, -y_size / 2 + 100], :visibility => 'I')
90
+
91
+
92
+ y = step
93
+ pin_num_x = (max_length[1] + 2)*font_size / 2
94
+ component.draws << Text.new(:text => 'Конт.', :pos => [pin_num_x, y])
95
+ pin_name_x = (max_length[1] + 2)*font_size + (max_length[0] + 2)*font_size / 2
96
+ component.draws << Text.new(:text => 'Цепь', :pos => [pin_name_x, y])
97
+
98
+ x, y = 0, 0
99
+ pin_len = 300
100
+ all_pins.each { |pin|
101
+ component.draws << Pin.new(:name => pin[0], :number => pin[1],
102
+ :pos => [x - pin_len, y], :orientation => 'R') unless @options.no_pins
103
+ pin_num_x = x + (max_length[1] + 2)*font_size / 2
104
+ component.draws << Text.new(:text => pin[1], :pos => [pin_num_x, y])
105
+ pin_name_x = x + (max_length[1] + 2)*font_size + (max_length[0] + 2)*font_size / 2
106
+ component.draws << Text.new(:text => pin[0], :pos => [pin_name_x, y])
107
+ component.draws << Polygon.new(:points => [[x, y + step/2], [x + x_size, y + step /2]])
108
+ y -= step
109
+ }
110
+
111
+ component
112
+ end
113
+ end
114
+
115
+ end # end module Library
116
+ end # end module Kut
@@ -0,0 +1,123 @@
1
+ require 'kut/library/generator'
2
+ require 'kut/library/pins_reader'
3
+ require 'kut/library/components'
4
+
5
+ module Kut
6
+ module Library
7
+
8
+ class SimpleGenerator
9
+ attr_reader :name
10
+
11
+ def initialize
12
+ @name = :simple
13
+ @options = OpenStruct.new
14
+ @options.pin_step = 100
15
+ @options.pin_space = 400
16
+ end
17
+
18
+ def help
19
+ 'How to use this generator is help string'
20
+ end
21
+ #Preapare generator for generate library component
22
+ def prepare(args)
23
+ opts = OptionParser.new do |opts|
24
+ opts.banner = '' #"Usage: kut #{self.name} [options]"
25
+
26
+ opts.on("--pin-step PIN_STEP", "Pin step in mils.") do |step|
27
+ @options.pin_step = step.to_i()
28
+ end
29
+
30
+ opts.on("--pin-space PIN_SPACE","Pin space in mils.") do |space|
31
+ @options.pin_space = space.to_i()
32
+ end
33
+
34
+ opts.on("--alias ALIAS", "Component alias.") do |al|
35
+ @options.alias = al
36
+ end
37
+
38
+ opts.on("--name NAME", "Component name.") do |name|
39
+ @options.name = name
40
+ end
41
+
42
+ opts.on("--ref REFERENCE", "Component reference.") do |ref|
43
+ @options.reference = ref
44
+ end
45
+ end
46
+ opts.parse!(args)
47
+ opts
48
+ end
49
+
50
+ #Generate library component
51
+ #in_f input file
52
+ #out_f output file
53
+ def generate(in_f, out_f)
54
+ pins_desc = Kut::Library::PinsParser.parse(in_f)
55
+ all_pins = pins_desc.other_pins + pins_desc.left_pins +
56
+ pins_desc.right_pins + pins_desc.top_pins + pins_desc.bottom_pins
57
+ all_pins.compact! # may be to contain nil
58
+ all_pins.sort! { |x,y| Integer(x[1]) <=> Integer(y[1]) }
59
+
60
+ left_pins = all_pins[0 ... all_pins.length / 4]
61
+ bottom_pins = all_pins[(all_pins.length / 4) .. (all_pins.length / 4 * 2 - 1)]
62
+ right_pins = all_pins[(all_pins.length / 4 * 2) .. (all_pins.length / 4 * 3 - 1)]
63
+ top_pins = all_pins[(all_pins.length / 4 * 3) .. (all_pins.length - 1)]
64
+
65
+ top_pins.reverse!
66
+ right_pins.reverse!
67
+
68
+ pin_name_max_length = 0
69
+ all_pins.each { |pin| pin_name_max_length = [pin[0].size, pin_name_max_length].max }
70
+ snom = 60
71
+
72
+ step = @options.pin_step
73
+ space = @options.pin_space
74
+
75
+ x_size = [top_pins.length-1, bottom_pins.length-1].max*step + 2*space
76
+ y_size = [left_pins.length-1, right_pins.length-1].max*step + 2*space
77
+
78
+ cmp_name = pins_desc.names[0] if pins_desc.names && pins_desc.names.size() > 0
79
+ cmp_name = @options.name if @options.name
80
+ cmp_ref = pins_desc.reference
81
+ cmp_ref = @options.reference if @options.reference
82
+
83
+ cmp_alias = pins_desc.names[1 .. pins_desc.names.size - 1] if pins_desc.names && pins_desc.names.size > 1
84
+ cmp_alias = @options.alias if @options.alias
85
+
86
+ component = Component.new(:name => cmp_name, :reference => cmp_ref)
87
+ component.fields << Field.new(:number => 0, :text => cmp_ref, :pos => [x_size / 2, -y_size / 2 + 50])
88
+ component.fields << Field.new(:number => 1, :text => cmp_name, :pos => [x_size / 2, -y_size / 2 - 50])
89
+ component.alias = cmp_alias
90
+ component.draws << Rectangle.new(:end => [x_size, -y_size])
91
+
92
+ x, y = 0, -space
93
+ pin_len = 300
94
+ left_pins.each { |pin|
95
+ component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x - pin_len, y], :orientation => 'R')
96
+ y -= step
97
+ }
98
+
99
+ x, y = x_size, -space
100
+ right_pins.each { |pin|
101
+ component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x + pin_len, y], :orientation => 'L')
102
+ y -= step
103
+ }
104
+
105
+
106
+ x, y = space, 0
107
+ top_pins.each { |pin|
108
+ component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x, y + pin_len], :orientation => 'D')
109
+ x += step
110
+ }
111
+
112
+ x, y = space, -y_size
113
+ bottom_pins.each { |pin|
114
+ component.draws << Pin.new(:name => pin[0], :number => pin[1], :pos => [x, y - pin_len], :orientation => 'U')
115
+ x += step
116
+ }
117
+
118
+ component
119
+ end
120
+ end
121
+
122
+ end # end module Library
123
+ end # end module Kut
@@ -0,0 +1,47 @@
1
+ require 'ostruct'
2
+ module Kut
3
+ module Library
4
+
5
+ class PinsParser
6
+
7
+ def PinsParser.parse(in_f)
8
+ result = OpenStruct.new
9
+ result.left_pins = []
10
+ result.right_pins = []
11
+ result.top_pins = []
12
+ result.bottom_pins = []
13
+ result.other_pins = []
14
+ result.reference = 'U'
15
+ result.names = ['NONAME']
16
+
17
+ current_pin_list = result.other_pins
18
+
19
+ in_f.each_line { |line|
20
+ case line
21
+ when /\A([^#]\S*)\s+(\S+).*/
22
+ current_pin_list << [$2, $1]
23
+ when /\A#NO-PIN\s*/
24
+ current_pin_list << nil
25
+ when /\A#TOP\s*/
26
+ current_pin_list = result.top_pins
27
+ when /\A#BOTTOM\s*/
28
+ current_pin_list = result.bottom_pins
29
+ when /\A#LEFT\s*/
30
+ current_pin_list = result.left_pins
31
+ when /\A#RIGHT\s*/
32
+ current_pin_list = result.right_pins
33
+ when /\A#REF\s+(\S+)/
34
+ result.reference = $1
35
+ when /\A#NAMES\s+(.*)/
36
+ str =$1.gsub(/\s+/, '')
37
+ result.names = str.split(',')
38
+ end
39
+ }
40
+
41
+ result
42
+ end
43
+
44
+ end
45
+
46
+ end # module Libary
47
+ end # module Kut
@@ -0,0 +1,18 @@
1
+ module Kut
2
+ module Library
3
+ class RegExp
4
+ LIBRARY_EXP = /^EESchema-LIBRARY\sVersion\s+(\S+)\s+Date:\s+(.*)/
5
+ CMPDEF_EXP = /^DEF\s(\S+)\s(\S+)\s\S+\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/
6
+ ALIAS_EXP = /^ALIAS\s(.*)/
7
+ FIELD_EXP = /^F(\d+)\s\"([^\"]*)\"\s(\d+)\s(\d+)\s(\d+)\s([HV])\s([VI])\s([LRCBT])\s([LRCBT])([IN]?)([BN]?)(?:\s\"([^\"]*)\")?/
8
+
9
+ DRAW_EXP = /^Draw/
10
+
11
+ PIN_EXP = /^X \s+ (\S+) \s+ (\S+) \s+ (-?\d+) \s+ (-?\d+) \s+ (\d+)\s([UDRL])\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S)(?:\s(\S*))/x
12
+
13
+ DRAW_END_EXP = /^DrawEnd/
14
+ CMPDEF_END_XEP = /^ENDDEF/
15
+ LIBRARY_END_EXP = /#End Library/
16
+ end
17
+ end
18
+ end