From 4ad225ca96f73db8c87fc983da9abaf33d73d29a Mon Sep 17 00:00:00 2001 From: Leandro Heck Date: Wed, 13 Jul 2022 11:47:20 -0300 Subject: [PATCH 1/3] Formatting --- kicad_pcb.py | 59 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/kicad_pcb.py b/kicad_pcb.py index 64b998b..115e401 100644 --- a/kicad_pcb.py +++ b/kicad_pcb.py @@ -5,7 +5,7 @@ parser of class `sexp_parser.SexpParser`. Check out the source to see how easy it is to implement a parser in an almost declarative way. -A usage demonstration is available in `test.py` +A usage demonstration is available in `test_pcb.py` ''' try: @@ -41,7 +41,7 @@ def _parse1_layers(self,data): return Sexp(data[1],data[2:],data[0]) -class KicadPCB_module(SexpParser): +class KicadPCB_footprint(SexpParser): __slots__ = () _default_bools = 'locked' _parse_fp_text = KicadPCB_gr_text @@ -51,42 +51,43 @@ class KicadPCB_module(SexpParser): class KicadPCB(SexpParser): # To make sure the following key exists, and is of type SexpList - _module = ['fp_text', - 'fp_circle', - 'fp_arc', - 'pad', - 'model'] - - _defaults =('net', - ('net_class', - 'add_net'), - 'dimension', - 'gr_text', - 'gr_line', - 'gr_circle', - 'gr_arc', - 'gr_curve', - 'segment', - 'arc', - 'via', - ['module'] + _module, - ['footprint'] + _module, - ('zone', - 'filled_polygon')) + _footprint = [ + 'fp_text', + 'fp_line', + 'fp_circle', + 'fp_arc', + 'pad', + 'model'] + + _defaults = ( + 'net', + ('net_class', 'add_net'), + 'dimension', + 'gr_text', + 'gr_line', + 'gr_circle', + 'gr_arc', + 'gr_curve', + 'gr_poly', + 'segment', + 'arc', + 'via', + ['footprint'] + _footprint, + ['module'] + _footprint, + ('zone', 'filled_polygon')) _alias_keys = {'footprint' : 'module'} - _parse_module = KicadPCB_module - _parse_footprint = KicadPCB_module + _parse_footprint = KicadPCB_footprint + _parse_footprint = KicadPCB_footprint _parse_gr_text = KicadPCB_gr_text def export(self, out, indent=' '): - exportSexp(self,out,'',indent) + exportSexp(self, out, '', indent) def getError(self): return getSexpError(self) @staticmethod def load(filename, quote_no_parse=None): - with open(filename,'r') as f: + with open(filename, 'r') as f: return KicadPCB(parseSexp(f.read(), quote_no_parse)) - From 957f89dd5ea49f11d362d22de11f797fc0a0cb81 Mon Sep 17 00:00:00 2001 From: Leandro Heck Date: Wed, 13 Jul 2022 11:47:35 -0300 Subject: [PATCH 2/3] Rename pcb test file --- test.py => test_pcb.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test.py => test_pcb.py (100%) diff --git a/test.py b/test_pcb.py similarity index 100% rename from test.py rename to test_pcb.py From 406ade4abc37af634d674c9b419cd6d4e2e5a93e Mon Sep 17 00:00:00 2001 From: Leandro Heck Date: Wed, 13 Jul 2022 11:57:37 -0300 Subject: [PATCH 3/3] Add initial support for Kicad Schematics --- kicad_sch.py | 112 ++++++++++ test.kicad_sch | 596 +++++++++++++++++++++++++++++++++++++++++++++++++ test_sch.py | 44 ++++ 3 files changed, 752 insertions(+) create mode 100644 kicad_sch.py create mode 100644 test.kicad_sch create mode 100755 test_sch.py diff --git a/kicad_sch.py b/kicad_sch.py new file mode 100644 index 0000000..274dba4 --- /dev/null +++ b/kicad_sch.py @@ -0,0 +1,112 @@ +''' + +``kicad_sch`` parser using `sexp_parser.SexpParser` + +The parser `KicadSCH` demonstrates the usage of a more general S-expression +parser of class `sexp_parser.SexpParser`. Check out the source to see how easy +it is to implement a parser in an almost declarative way. + +A usage demonstration is available in `test_sch.py` +''' + +try: + from .sexp_parser import * +except ImportError: + from sexp_parser.sexp_parser import * + +__author__ = "Heck, Leandro" +__copyright__ = "Copyright 2022, Leandro Heck" +__license__ = "MIT" +__version__ = "1.0.0" +__email__ = "leoheck@gmail.com" +__status__ = "Prototype" + + +class KicadSCH_gr_text(SexpParser): + __slots__ = () + _default_bools = 'hide' + + +class KicadSCH_drill(SexpParser): + __slots__ = () + _default_bools = 'oval' + + +class KicadSCH_pad(SexpParser): + __slots__ = () + _parse1_drill = KicadSCH_drill + + def _parse1_layers(self,data): + if not isinstance(data,list) or len(data)<3: + raise ValueError('expects list of more than 2 element') + return Sexp(data[1],data[2:],data[0]) + + +class KicadSCH_symbol(SexpParser): + __slots__ = () + _default_bools = 'locked' + _parse_fp_text = KicadSCH_gr_text + _parse_pad = KicadSCH_pad + + +class KicadSCH(SexpParser): + + # To make sure the following key exists, and is of type SexpList + + _symbol = [ + 'lib_id', + 'in_bom', + 'on_board', + 'uuid', + 'property', + 'pin' + ] + + _sheet_instances = [ + 'path', + ] + + _defaults = ( + 'uuid', + 'paper', + 'title_block', + 'lib_symbols', + 'junction', + 'wire', + 'text', + 'label' + 'symbol', + 'sheet_instances', + 'symbol_instances' + ) + + + # _defaults = ('net', + # ('net_class','add_net'), + # 'dimension', + # 'gr_text', + # 'gr_line', + # 'gr_circle', + # 'gr_arc', + # 'gr_curve', + # 'segment', + # 'arc', + # 'via', + # ['module'] + _footprint, + # ['footprint'] + _footprint, + # ('zone', 'filled_polygon')) + + _parse_symbol = KicadSCH_symbol + _parse_symbol = KicadSCH_symbol + _parse_gr_text = KicadSCH_gr_text + + def export(self, out, indent=' '): + exportSexp(self, out,'', indent) + + def getError(self): + return getSexpError(self) + + @staticmethod + def load(filename, quote_no_parse=None): + with open(filename, 'r') as f: + return KicadSCH(parseSexp(f.read(), quote_no_parse)) diff --git a/test.kicad_sch b/test.kicad_sch new file mode 100644 index 0000000..0306b09 --- /dev/null +++ b/test.kicad_sch @@ -0,0 +1,596 @@ +(kicad_sch (version 20211123) (generator eeschema) + + (uuid 604d8a6e-acd9-4606-9d76-edf203c01d74) + + (paper "A4") + + (title_block + (title "Test Schematic") + (date "2022-07-13") + (rev "0.1") + (company "No_Company") + (comment 1 "This is the 1st comment") + (comment 2 "This is the 2nd comment") + ) + + (lib_symbols + (symbol "Connector:XLR3" (pin_names hide) (in_bom yes) (on_board yes) + (property "Reference" "J" (id 0) (at 0 8.89 0) + (effects (font (size 1.27 1.27))) + ) + (property "Value" "XLR3" (id 1) (at 0 6.35 0) + (effects (font (size 1.27 1.27))) + ) + (property "Footprint" "" (id 2) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" " ~" (id 3) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_keywords" "xlr connector" (id 4) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_description" "XLR Connector, Male or Female, 3 Pins" (id 5) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_fp_filters" "Jack*XLR*" (id 6) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (symbol "XLR3_0_1" + (circle (center -3.556 0) (radius 1.016) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (circle (center 0 -3.556) (radius 1.016) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy -5.08 0) + (xy -4.572 0) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy 0 -5.08) + (xy 0 -4.572) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy 5.08 0) + (xy 4.572 0) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (circle (center 0 0) (radius 5.08) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type background)) + ) + (circle (center 3.556 0) (radius 1.016) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (text "1" (at -3.556 1.778 0) + (effects (font (size 1.016 1.016) bold)) + ) + (text "2" (at 3.556 1.778 0) + (effects (font (size 1.016 1.016) bold)) + ) + (text "3" (at 0 -1.778 0) + (effects (font (size 1.016 1.016) bold)) + ) + (pin passive line (at -7.62 0 0) (length 2.54) + (name "~" (effects (font (size 1.27 1.27)))) + (number "1" (effects (font (size 1.27 1.27)))) + ) + (pin passive line (at 7.62 0 180) (length 2.54) + (name "~" (effects (font (size 1.27 1.27)))) + (number "2" (effects (font (size 1.27 1.27)))) + ) + (pin passive line (at 0 -7.62 90) (length 2.54) + (name "~" (effects (font (size 1.27 1.27)))) + (number "3" (effects (font (size 1.27 1.27)))) + ) + ) + ) + (symbol "Device:R" (pin_numbers hide) (pin_names (offset 0)) (in_bom yes) (on_board yes) + (property "Reference" "R" (id 0) (at 2.032 0 90) + (effects (font (size 1.27 1.27))) + ) + (property "Value" "R" (id 1) (at 0 0 90) + (effects (font (size 1.27 1.27))) + ) + (property "Footprint" "" (id 2) (at -1.778 0 90) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "~" (id 3) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_keywords" "R res resistor" (id 4) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_description" "Resistor" (id 5) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_fp_filters" "R_*" (id 6) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (symbol "R_0_1" + (rectangle (start -1.016 -2.54) (end 1.016 2.54) + (stroke (width 0.254) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + ) + (symbol "R_1_1" + (pin passive line (at 0 3.81 270) (length 1.27) + (name "~" (effects (font (size 1.27 1.27)))) + (number "1" (effects (font (size 1.27 1.27)))) + ) + (pin passive line (at 0 -3.81 90) (length 1.27) + (name "~" (effects (font (size 1.27 1.27)))) + (number "2" (effects (font (size 1.27 1.27)))) + ) + ) + ) + (symbol "power:+12V" (power) (pin_names (offset 0)) (in_bom yes) (on_board yes) + (property "Reference" "#PWR" (id 0) (at 0 -3.81 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Value" "+12V" (id 1) (at 0 3.556 0) + (effects (font (size 1.27 1.27))) + ) + (property "Footprint" "" (id 2) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "" (id 3) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_keywords" "power-flag" (id 4) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_description" "Power symbol creates a global label with name \"+12V\"" (id 5) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (symbol "+12V_0_1" + (polyline + (pts + (xy -0.762 1.27) + (xy 0 2.54) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy 0 0) + (xy 0 2.54) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy 0 2.54) + (xy 0.762 1.27) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + ) + (symbol "+12V_1_1" + (pin power_in line (at 0 0 90) (length 0) hide + (name "+12V" (effects (font (size 1.27 1.27)))) + (number "1" (effects (font (size 1.27 1.27)))) + ) + ) + ) + (symbol "power:+5V" (power) (pin_names (offset 0)) (in_bom yes) (on_board yes) + (property "Reference" "#PWR" (id 0) (at 0 -3.81 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Value" "+5V" (id 1) (at 0 3.556 0) + (effects (font (size 1.27 1.27))) + ) + (property "Footprint" "" (id 2) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "" (id 3) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_keywords" "power-flag" (id 4) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_description" "Power symbol creates a global label with name \"+5V\"" (id 5) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (symbol "+5V_0_1" + (polyline + (pts + (xy -0.762 1.27) + (xy 0 2.54) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy 0 0) + (xy 0 2.54) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + (polyline + (pts + (xy 0 2.54) + (xy 0.762 1.27) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + ) + (symbol "+5V_1_1" + (pin power_in line (at 0 0 90) (length 0) hide + (name "+5V" (effects (font (size 1.27 1.27)))) + (number "1" (effects (font (size 1.27 1.27)))) + ) + ) + ) + (symbol "power:GND" (power) (pin_names (offset 0)) (in_bom yes) (on_board yes) + (property "Reference" "#PWR" (id 0) (at 0 -6.35 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Value" "GND" (id 1) (at 0 -3.81 0) + (effects (font (size 1.27 1.27))) + ) + (property "Footprint" "" (id 2) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "" (id 3) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_keywords" "power-flag" (id 4) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "ki_description" "Power symbol creates a global label with name \"GND\" , ground" (id 5) (at 0 0 0) + (effects (font (size 1.27 1.27)) hide) + ) + (symbol "GND_0_1" + (polyline + (pts + (xy 0 0) + (xy 0 -1.27) + (xy 1.27 -1.27) + (xy 0 -2.54) + (xy -1.27 -1.27) + (xy 0 -1.27) + ) + (stroke (width 0) (type default) (color 0 0 0 0)) + (fill (type none)) + ) + ) + (symbol "GND_1_1" + (pin power_in line (at 0 0 270) (length 0) hide + (name "GND" (effects (font (size 1.27 1.27)))) + (number "1" (effects (font (size 1.27 1.27)))) + ) + ) + ) + ) + + (junction (at 115.57 88.9) (diameter 0) (color 0 0 0 0) + (uuid 21aa309b-3651-420c-93d8-9a9351fb4330) + ) + (junction (at 105.41 88.9) (diameter 0) (color 0 0 0 0) + (uuid 3a4ea823-4a41-4514-8f52-cf532fedb08a) + ) + (junction (at 95.25 88.9) (diameter 0) (color 0 0 0 0) + (uuid 8217166d-c8bf-4483-9d01-30feabe0c0e4) + ) + (junction (at 95.25 73.66) (diameter 0) (color 0 0 0 0) + (uuid 907392bf-e1db-4912-840d-1605e6e2e427) + ) + + (no_connect (at 83.82 76.2) (uuid 5b6708fb-1423-4bf7-b6e6-0bb58a9ca371)) + + (bus (pts (xy 166.37 48.26) (xy 166.37 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 000a3489-5f85-4807-b8cf-16eab6baa47f) + ) + + (wire (pts (xy 125.73 73.66) (xy 129.54 73.66)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 1726f087-a1cd-4cda-97d3-5ed6c834e604) + ) + (wire (pts (xy 115.57 88.9) (xy 125.73 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 2076a7f0-69be-4fff-9d25-21ea9033c7b0) + ) + (wire (pts (xy 95.25 85.09) (xy 95.25 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 2b6dc366-e263-4fd0-aca8-f5fa7b0258d0) + ) + (wire (pts (xy 95.25 73.66) (xy 105.41 73.66)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 31cb4c82-c2a1-4dbf-be8b-d67064931caf) + ) + (wire (pts (xy 125.73 88.9) (xy 125.73 85.09)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 36f954c0-5290-4420-ae7d-9cdf24259392) + ) + (polyline (pts (xy 199.39 101.6) (xy 199.39 41.91)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 3af22253-563d-40e2-a7e1-ba9229f6984d) + ) + (polyline (pts (xy 45.72 101.6) (xy 199.39 101.6)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 3ffc5e70-a6da-4752-8944-244eabcd41db) + ) + + (wire (pts (xy 95.25 88.9) (xy 76.2 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 6e05f764-3498-4379-8f21-387ab648376f) + ) + (wire (pts (xy 95.25 88.9) (xy 95.25 91.44)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 741687e2-2df0-47f0-a490-6186ebef980b) + ) + (polyline (pts (xy 45.72 41.91) (xy 199.39 41.91)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 80bd6a5f-d83f-4d7f-8607-cf45f557a942) + ) + + (wire (pts (xy 60.96 76.2) (xy 68.58 76.2)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 885588f3-8d7e-466e-997e-5bab1c66f929) + ) + (wire (pts (xy 115.57 71.12) (xy 115.57 77.47)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 891219a7-def3-4710-b0de-6988f2091130) + ) + (wire (pts (xy 105.41 85.09) (xy 105.41 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 93f450ac-8a22-4ab4-ae7b-a70531f4e4ff) + ) + (wire (pts (xy 105.41 73.66) (xy 105.41 77.47)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 9719b9ed-8050-43be-82d0-65c45e6ba040) + ) + (wire (pts (xy 125.73 73.66) (xy 125.73 77.47)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 9e202d12-793a-458b-a6ff-40e7740f28df) + ) + (bus (pts (xy 166.37 88.9) (xy 190.5 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid b59200d2-5f8a-40d5-8677-77857fa19158) + ) + + (wire (pts (xy 95.25 73.66) (xy 95.25 77.47)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid bf863872-d34c-477f-b5c1-4881b3ea36b0) + ) + (wire (pts (xy 95.25 88.9) (xy 105.41 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid c6e81a51-1efa-41a5-8793-71c4f715420f) + ) + (wire (pts (xy 76.2 88.9) (xy 76.2 83.82)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid c9c9026d-6945-43ac-af56-250410f025c0) + ) + (wire (pts (xy 95.25 72.39) (xy 95.25 73.66)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid d6ee9c09-3561-4c8a-a4d9-bf6f06e31f64) + ) + (wire (pts (xy 105.41 88.9) (xy 115.57 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid d7139448-24d5-43cf-8196-520250456271) + ) + (wire (pts (xy 115.57 85.09) (xy 115.57 88.9)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid f80d2fbd-60f5-4b35-b0dd-2417e0c6340e) + ) + (polyline (pts (xy 45.72 43.18) (xy 45.72 101.6)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid fdca51ee-daf3-4f6f-b471-b2155814b45c) + ) + + (text "This is another test label" (at 74.93 52.07 0) + (effects (font (size 1.27 1.27)) (justify left bottom)) + (uuid 16836959-1e0a-4514-afd3-2750eca86bac) + ) + (text "This is a test label" (at 74.93 49.53 0) + (effects (font (size 1.27 1.27)) (justify left bottom)) + (uuid 2765e55f-a27f-49cb-9f05-5f4571e5beb8) + ) + + (label "my_signal" (at 60.96 76.2 180) + (effects (font (size 1.27 1.27)) (justify right bottom)) + (uuid 4ad9da2a-367c-4e4d-abea-65be99ccc1c7) + ) + + (global_label "my_global_signal" (shape input) (at 129.54 73.66 0) (fields_autoplaced) + (effects (font (size 1.27 1.27)) (justify left)) + (uuid 5606489b-5e54-434f-ba2f-68e7138916ba) + (property "Intersheet References" "${INTERSHEET_REFS}" (id 0) (at 148.2212 73.5806 0) + (effects (font (size 1.27 1.27)) (justify left) hide) + ) + ) + + (symbol (lib_id "power:GND") (at 95.25 91.44 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid 0ea13c35-6f48-4718-a843-8d141b52f3d8) + (property "Reference" "#PWR02" (id 0) (at 95.25 97.79 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Value" "GND" (id 1) (at 95.25 96.52 0)) + (property "Footprint" "" (id 2) (at 95.25 91.44 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "" (id 3) (at 95.25 91.44 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid 40281c13-e6f1-4861-8cff-57e791f40a37)) + ) + + (symbol (lib_id "power:+12V") (at 95.25 72.39 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid 4765f35a-eded-43ae-b619-43e98a596d29) + (property "Reference" "#PWR01" (id 0) (at 95.25 76.2 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Value" "+12V" (id 1) (at 95.25 67.31 0)) + (property "Footprint" "" (id 2) (at 95.25 72.39 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "" (id 3) (at 95.25 72.39 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid 8d8c797b-7d46-4493-b52e-9300ad509d00)) + ) + + (symbol (lib_id "Device:R") (at 125.73 81.28 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid 50cce587-ad5f-4213-a89b-420c3c35a940) + (property "Reference" "R4" (id 0) (at 128.27 80.0099 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Value" "R" (id 1) (at 128.27 82.5499 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Footprint" "" (id 2) (at 123.952 81.28 90) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "~" (id 3) (at 125.73 81.28 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid 149fa64a-2fa8-47eb-a5dc-223f52710b73)) + (pin "2" (uuid f3dc5aca-31c8-4e6a-baee-98c9049a48dc)) + ) + + (symbol (lib_id "Device:R") (at 105.41 81.28 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid 6333037f-bab5-49d9-b7ac-c53d97108781) + (property "Reference" "R2" (id 0) (at 107.95 80.0099 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Value" "R" (id 1) (at 107.95 82.5499 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Footprint" "" (id 2) (at 103.632 81.28 90) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "~" (id 3) (at 105.41 81.28 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid 53c3f49c-8dcf-4feb-b07b-db85c727e154)) + (pin "2" (uuid c095918b-aaa3-45f7-bf2f-fc45602412a2)) + ) + + (symbol (lib_id "Device:R") (at 115.57 81.28 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid 8ce1eda9-7f09-4261-a2e9-0dba0e36791f) + (property "Reference" "R3" (id 0) (at 118.11 80.0099 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Value" "R" (id 1) (at 118.11 82.5499 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Footprint" "" (id 2) (at 113.792 81.28 90) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "~" (id 3) (at 115.57 81.28 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid 5e4ede25-4420-4433-9114-81b8b01efdaf)) + (pin "2" (uuid a393dd27-8540-447a-b08c-7da9f89458f7)) + ) + + (symbol (lib_id "Connector:XLR3") (at 76.2 76.2 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid c4b15471-2f14-484c-bc47-92f97015bd66) + (property "Reference" "J1" (id 0) (at 76.2 66.04 0)) + (property "Value" "XLR3" (id 1) (at 76.2 68.58 0)) + (property "Footprint" "" (id 2) (at 76.2 76.2 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" " ~" (id 3) (at 76.2 76.2 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid df4d7ee2-4c7b-40a9-b787-fa6173069777)) + (pin "2" (uuid 8a536383-fafe-47cc-ae4a-80defa0c98e8)) + (pin "3" (uuid 9d24215e-3ceb-48f8-a03d-90df309a7f9f)) + ) + + (symbol (lib_id "Device:R") (at 95.25 81.28 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid cb52061e-cdbd-4f10-9f64-5c5db6e54211) + (property "Reference" "R1" (id 0) (at 97.79 80.0099 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Value" "R" (id 1) (at 97.79 82.5499 0) + (effects (font (size 1.27 1.27)) (justify left)) + ) + (property "Footprint" "" (id 2) (at 93.472 81.28 90) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "~" (id 3) (at 95.25 81.28 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid bf192b2d-34dc-4670-a21b-ad9a015308f8)) + (pin "2" (uuid 12eb27b4-1127-43cd-8fb9-1ce1dcb6e3be)) + ) + + (symbol (lib_id "power:+5V") (at 115.57 71.12 0) (unit 1) + (in_bom yes) (on_board yes) (fields_autoplaced) + (uuid d95a6d46-92c3-4a29-8236-25594b1db8ef) + (property "Reference" "#PWR03" (id 0) (at 115.57 74.93 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Value" "+5V" (id 1) (at 115.57 66.04 0)) + (property "Footprint" "" (id 2) (at 115.57 71.12 0) + (effects (font (size 1.27 1.27)) hide) + ) + (property "Datasheet" "" (id 3) (at 115.57 71.12 0) + (effects (font (size 1.27 1.27)) hide) + ) + (pin "1" (uuid 9772d889-4ddb-4273-a78a-bb6a68af5728)) + ) + + (sheet_instances + (path "/" (page "1")) + ) + + (symbol_instances + (path "/4765f35a-eded-43ae-b619-43e98a596d29" + (reference "#PWR01") (unit 1) (value "+12V") (footprint "") + ) + (path "/0ea13c35-6f48-4718-a843-8d141b52f3d8" + (reference "#PWR02") (unit 1) (value "GND") (footprint "") + ) + (path "/d95a6d46-92c3-4a29-8236-25594b1db8ef" + (reference "#PWR03") (unit 1) (value "+5V") (footprint "") + ) + (path "/c4b15471-2f14-484c-bc47-92f97015bd66" + (reference "J1") (unit 1) (value "XLR3") (footprint "") + ) + (path "/cb52061e-cdbd-4f10-9f64-5c5db6e54211" + (reference "R1") (unit 1) (value "R") (footprint "") + ) + (path "/6333037f-bab5-49d9-b7ac-c53d97108781" + (reference "R2") (unit 1) (value "R") (footprint "") + ) + (path "/8ce1eda9-7f09-4261-a2e9-0dba0e36791f" + (reference "R3") (unit 1) (value "R") (footprint "") + ) + (path "/50cce587-ad5f-4213-a89b-420c3c35a940" + (reference "R4") (unit 1) (value "R") (footprint "") + ) + ) +) diff --git a/test_sch.py b/test_sch.py new file mode 100755 index 0000000..28c036e --- /dev/null +++ b/test_sch.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +from kicad_sch import * +from sexp_parser import * + +import sys +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("filename", nargs='?', default='test.kicad_sch', help='If not used, the default is test.kicad_sch') +parser.add_argument("-l", "--log", dest="logLevel", + choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], + help="Set the logging level") +parser.add_argument("-o", "--output", help="output filename") +args = parser.parse_args() +logging.basicConfig(level=args.logLevel, + format="%(filename)s:%(lineno)s: %(levelname)s - %(message)s") + +sch = KicadSCH.load(args.filename) + +# check for error +for e in sch.getError(): + print('Error: {}'.format(e)) + +print('root values: ') +for k in sch: + print('\t{}: {}'.format(k, sch[k])) + +print('\nversion: {}'.format(sch.version)) + +# KicadSCH will ensure several common keys to be presented even if there is none, +# in which case an empty SexpList will be inserted. And if there is only one instance, +# it will be converted to SexpList with one instance two. This is to spare the pain to +# always check key presence and to check whether it is a list +# +# However, KicadSCH does not exhaust all the possibilities, you insert your own keys into +# kicad_sch.py. Or, do as follow +print('\naccess using SexpList') +if 'general' in sch: + for k in SexpList(sch.general): + print(k) + +if args.output: + sch.export(sys.stdout if args.output=='-' else args.output)