kicad 0.9.5 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d8cfc291b0619e083673bc0239c3423c6fc9decd02348d91e99ce884dd24d39
4
- data.tar.gz: df0a12ac2396bbb27f4c843e76f6c7004e8ffd8e3577c4e824be32d8717b7d91
3
+ metadata.gz: 18fb51abbed1c58f99dbd73f3f9af6b8cac11938f885eb69f1af2b767b41d084
4
+ data.tar.gz: 9379a13c657dfa54b433c02cba67392447a93146980d33299ffd73d8a61860ef
5
5
  SHA512:
6
- metadata.gz: a1907a0652b06784809b3f5c1692c2cd46f187bf0178e1389597e1f56a1142ac66d0772b1964e2b5fa4eda7ffe4ec80c38b34522188b5644d83c310550ed0fb8
7
- data.tar.gz: 7b268bcc9684f36967f36b205a93706128589261cddf51abea86de5dd55b71a431fd2a25b2de6d5da2d6f2b561901669f3f46f8ab925ae72fdc2af05b674ed26
6
+ metadata.gz: 9181bf9733dea2ab7483dfa622088c4604146def2cfcdd1eb249221f8a8a7b6e3dcab80cbb2075d6c3bca72cacd9d9d76e1bb3246e5c07c5210170963629de2e
7
+ data.tar.gz: 884bdd9984b362aee84d9a12af8843732c35d69f92836a349a1a2e1b31167226fb8985325c8b8977f8f14434c89c182b95f2ebcef8cea1efb8d4356a3d669463
@@ -0,0 +1,9 @@
1
+ # ruby -w
2
+ #
3
+ # Pretty-printer for JLC libraries
4
+ #
5
+ require 'kicad'
6
+
7
+ k = KiCad.load(ARGV[0]).value
8
+
9
+ File.open('rewrite.kicad_sym', 'w') { |f| f.puts k.emit }
@@ -0,0 +1,36 @@
1
+ # ruby -w
2
+ #
3
+ # Find duplicate symbol rendering in a Kicad library
4
+ # Merged symbols must have same appearance and reference designator
5
+ #
6
+ require 'kicad'
7
+ require 'debug'
8
+
9
+ k = KiCad.load(ARGV[0]).value
10
+
11
+ symbols_by_pretty = {}
12
+
13
+ k.all_symbol.
14
+ each do |s|
15
+ child_symbols = s.all_symbol
16
+
17
+ # the key is the concatenated pretty-printed contents of all child symbols
18
+ key =
19
+ child_symbols.map do |c|
20
+ s['Reference'].inspect+':' +
21
+ c.children.filter{|e| KiCad::AST::Property === e}.map(&:emit).sort*" "
22
+ end.sort*"\n"
23
+
24
+ existing = symbols_by_pretty[key]
25
+ if existing
26
+ puts "#{s.id} is a dup of #{existing.id}"
27
+
28
+ # delete all child symbols, prepend extends:
29
+ s.children.delete_if{|c| child_symbols.include?(c)}
30
+ s.children.prepend(KiCad.parse("(extends #{existing.id.inspect})")&.value)
31
+ else
32
+ symbols_by_pretty[key] = s
33
+ end
34
+ end
35
+
36
+ File.open('rewrite.kicad_sym', 'w') { |f| f.puts k.emit }
data/kicad.gemspec CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.required_ruby_version = ">= 3.0"
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- # spec.bindir = "bin"
20
- # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_development_dependency "bundler", ">= 1.11"
data/lib/kicad/ast.rb CHANGED
@@ -16,6 +16,19 @@ module KiCad
16
16
  ")\n"
17
17
  end
18
18
 
19
+ # A replacement for a Node#emit that wants descendents compacted
20
+ def emit_compacting depth = 0
21
+ "\t"*depth + emit_compact + "\n"
22
+ end
23
+
24
+ def emit_compact
25
+ '(' +
26
+ [ @values.map{|v| String === v ? v.inspect : v.to_s },
27
+ @children.map{|c| c.emit_compact() }
28
+ ].flatten*' ' +
29
+ ')'
30
+ end
31
+
19
32
  # Define setter and getter methods for each value type this class allows
20
33
  def self.value_types vts
21
34
  i = 1 # @values[0] is always the class symbol
@@ -87,12 +100,21 @@ module KiCad
87
100
  end
88
101
 
89
102
  class Generator < Node
103
+ def emit depth = 0
104
+ emit_compacting depth
105
+ end
90
106
  end
91
107
 
92
108
  class GeneratorVersion < Node
109
+ def emit depth = 0
110
+ emit_compacting depth
111
+ end
93
112
  end
94
113
 
95
114
  class Version < Node
115
+ def emit depth = 0
116
+ emit_compacting depth
117
+ end
96
118
  end
97
119
 
98
120
  # Uncomment or add whatever class you need to customise:
@@ -100,6 +122,10 @@ module KiCad
100
122
  # Position Identifier
101
123
  class At < Node
102
124
  value_types :x => Float, :y => Float, :angle => Float
125
+
126
+ def emit depth = 0
127
+ emit_compacting depth
128
+ end
103
129
  end
104
130
 
105
131
  # Coordinate Point List
@@ -115,6 +141,10 @@ module KiCad
115
141
  # Stroke Definition
116
142
  class Stroke < Node
117
143
  child_types :width, :type, :color
144
+
145
+ def emit depth = 0
146
+ emit_compacting depth
147
+ end
118
148
  end
119
149
 
120
150
  class Width < Node
@@ -132,10 +162,26 @@ module KiCad
132
162
  # Text Effects
133
163
  class Effects < Node
134
164
  child_types :font, :justify, :hide
165
+
166
+ def emit depth = 0
167
+ if @children.size <= 1
168
+ emit_compacting depth
169
+ else
170
+ super
171
+ end
172
+ end
135
173
  end
136
174
 
137
175
  class Font < Node
138
176
  child_types :face, :size, :thickness, :bold, :italic, :line_spacing
177
+
178
+ def emit depth = 0
179
+ if @children.size <= 1
180
+ emit_compacting depth
181
+ else
182
+ super
183
+ end
184
+ end
139
185
  end
140
186
 
141
187
  class Face < Node
@@ -232,6 +278,11 @@ module KiCad
232
278
 
233
279
  class Fill < Node
234
280
  value_types :fill => [:no, :yes]
281
+ child_types :type
282
+
283
+ def emit depth = 0
284
+ emit_compacting depth
285
+ end
235
286
  end
236
287
 
237
288
  class Arc < Node
@@ -366,10 +417,18 @@ module KiCad
366
417
  class PinNumbers < Node
367
418
  # This is a child node, not as documented (a value in https://dev-docs.kicad.org/en/file-formats/sexpr-intro/)
368
419
  child_types :hide
420
+
421
+ def emit depth = 0
422
+ emit_compacting depth
423
+ end
369
424
  end
370
425
 
371
426
  class PinNames < Node
372
427
  child_types :offset, :hide
428
+
429
+ def emit depth = 0
430
+ emit_compacting depth
431
+ end
373
432
  end
374
433
 
375
434
  class InBom < Node
data/lib/kicad/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KiCad
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kicad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-11 00:00:00.000000000 Z
10
+ date: 2025-05-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -80,7 +80,9 @@ dependencies:
80
80
  description: Load and rewrite Kicad s-expression files into a tree structure for scripting
81
81
  email:
82
82
  - clifford.heath@gmail.com
83
- executables: []
83
+ executables:
84
+ - kicad_beautify.rb
85
+ - kicad_dedup_symbols.rb
84
86
  extensions: []
85
87
  extra_rdoc_files: []
86
88
  files:
@@ -89,6 +91,8 @@ files:
89
91
  - Gemfile.lock
90
92
  - README.md
91
93
  - Rakefile
94
+ - bin/kicad_beautify.rb
95
+ - bin/kicad_dedup_symbols.rb
92
96
  - kicad.gemspec
93
97
  - lib/kicad.rb
94
98
  - lib/kicad/ast.rb