aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demo/doit/demo.kicad_pcb130
-rw-r--r--demo/doit/demo.sch51
-rw-r--r--demo/doit/dodo.py13
-rw-r--r--demo/doit/ee/bom/bom-component/BT1.ini7
-rw-r--r--demo/doit/ee/bom/bom-component/C1.ini7
-rw-r--r--demo/doit/ee/bom/bom-component/R1.ini7
-rw-r--r--demo/doit/ee/bom/bom-component/R2.ini7
-rw-r--r--demo/doit/ee/bom/data-set.ini3
-rw-r--r--demo/doit/ee/kicad-pcb/data-set.ini3
-rw-r--r--demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC1DF.ini10
-rw-r--r--demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC36D.ini9
-rw-r--r--demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D0FE8.ini9
-rw-r--r--demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D10B5.ini9
-rw-r--r--demo/doit/ee/kicad-sch/data-set.ini3
-rw-r--r--demo/doit/ee/kicad-sch/kicad-schematic-component/5B431328.ini11
-rw-r--r--demo/doit/ee/kicad-sch/kicad-schematic-component/5B431438.ini11
-rw-r--r--demo/doit/ee/kicad-sch/kicad-schematic-component/5B4314AB.ini11
-rw-r--r--demo/doit/ee/kicad-sch/kicad-schematic-component/5B4315FE.ini9
-rw-r--r--demo/doit/ee/kicad-sch/kicad-schematic-component/5B5CC4D4.ini11
-rw-r--r--demo/doit/ee/order-100.csv4
-rw-r--r--demo/doit/ee/order.csv4
-rw-r--r--requirements.txt2
-rw-r--r--setup.py1
-rw-r--r--src/ee/bom/doit.py133
-rw-r--r--src/ee/doit.py16
-rw-r--r--src/ee/ds/__init__.py138
-rw-r--r--src/ee/kicad/doit.py125
27 files changed, 504 insertions, 240 deletions
diff --git a/demo/doit/demo.kicad_pcb b/demo/doit/demo.kicad_pcb
index 27217da..fcb69aa 100644
--- a/demo/doit/demo.kicad_pcb
+++ b/demo/doit/demo.kicad_pcb
@@ -3,10 +3,10 @@
(general
(thickness 1.6)
(drawings 0)
- (tracks 7)
+ (tracks 10)
(zones 0)
- (modules 3)
- (nets 4)
+ (modules 4)
+ (nets 5)
)
(page A4)
@@ -93,6 +93,7 @@
(net 1 "Net-(BT1-Pad1)")
(net 2 GND)
(net 3 "Net-(C1-Pad1)")
+ (net 4 "Net-(R1-Pad1)")
(net_class Default "This is the default net class."
(clearance 0.2)
@@ -104,6 +105,7 @@
(add_net GND)
(add_net "Net-(BT1-Pad1)")
(add_net "Net-(C1-Pad1)")
+ (add_net "Net-(R1-Pad1)")
)
(module Battery:BatteryHolder_MPD_BC2AAPC_2xAA (layer F.Cu) (tedit 5AC8F8F7) (tstamp 5B5BC36D)
@@ -178,73 +180,84 @@
)
)
- (module Capacitor_THT:CP_Axial_L11.0mm_D8.0mm_P15.00mm_Horizontal (layer F.Cu) (tedit 5AE50EF2) (tstamp 5B5BC1CE)
- (at 46 76)
- (descr "CP, Axial series, Axial, Horizontal, pin pitch=15mm, , length*diameter=11*8mm^2, Electrolytic Capacitor, , http://www.vishay.com/docs/28325/021asm.pdf")
- (tags "CP Axial series Axial Horizontal pin pitch 15mm length 11mm diameter 8mm Electrolytic Capacitor")
+ (module Resistor_SMD:R_1206_3216Metric (layer F.Cu) (tedit 5B20DC38) (tstamp 5B5BC1DF)
+ (at 60 61.4 90)
+ (descr "Resistor SMD 1206 (3216 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: http://www.tortai-tech.com/upload/download/2011102023233369053.pdf), generated with kicad-footprint-generator")
+ (tags resistor)
+ (path /5B431328)
+ (attr smd)
+ (fp_text reference R1 (at 0 -1.82 90) (layer F.SilkS)
+ (effects (font (size 1 1) (thickness 0.15)))
+ )
+ (fp_text value 10k (at 0 1.82 90) (layer F.Fab)
+ (effects (font (size 1 1) (thickness 0.15)))
+ )
+ (fp_line (start -1.6 0.8) (end -1.6 -0.8) (layer F.Fab) (width 0.1))
+ (fp_line (start -1.6 -0.8) (end 1.6 -0.8) (layer F.Fab) (width 0.1))
+ (fp_line (start 1.6 -0.8) (end 1.6 0.8) (layer F.Fab) (width 0.1))
+ (fp_line (start 1.6 0.8) (end -1.6 0.8) (layer F.Fab) (width 0.1))
+ (fp_line (start -0.602064 -0.91) (end 0.602064 -0.91) (layer F.SilkS) (width 0.12))
+ (fp_line (start -0.602064 0.91) (end 0.602064 0.91) (layer F.SilkS) (width 0.12))
+ (fp_line (start -2.28 1.12) (end -2.28 -1.12) (layer F.CrtYd) (width 0.05))
+ (fp_line (start -2.28 -1.12) (end 2.28 -1.12) (layer F.CrtYd) (width 0.05))
+ (fp_line (start 2.28 -1.12) (end 2.28 1.12) (layer F.CrtYd) (width 0.05))
+ (fp_line (start 2.28 1.12) (end -2.28 1.12) (layer F.CrtYd) (width 0.05))
+ (fp_text user %R (at 0 0 90) (layer F.Fab)
+ (effects (font (size 0.8 0.8) (thickness 0.12)))
+ )
+ (pad 1 smd roundrect (at -1.4 0 90) (size 1.25 1.75) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.2)
+ (net 4 "Net-(R1-Pad1)"))
+ (pad 2 smd roundrect (at 1.4 0 90) (size 1.25 1.75) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.2)
+ (net 1 "Net-(BT1-Pad1)"))
+ (model ${KISYS3DMOD}/Resistor_SMD.3dshapes/R_1206_3216Metric.wrl
+ (at (xyz 0 0 0))
+ (scale (xyz 1 1 1))
+ (rotate (xyz 0 0 0))
+ )
+ )
+
+ (module Capacitor_THT:CP_Radial_Tantal_D10.5mm_P5.00mm (layer F.Cu) (tedit 5AE50EF0) (tstamp 5B5D0FE8)
+ (at 51.25 76)
+ (descr "CP, Radial_Tantal series, Radial, pin pitch=5.00mm, , diameter=10.5mm, Tantal Electrolytic Capacitor, http://cdn-reichelt.de/documents/datenblatt/B300/TANTAL-TB-Serie%23.pdf")
+ (tags "CP Radial_Tantal series Radial pin pitch 5.00mm diameter 10.5mm Tantal Electrolytic Capacitor")
(path /5B4314AB)
- (fp_text reference C1 (at 7.5 -5.12) (layer F.SilkS)
+ (fp_text reference C1 (at 2.5 -6.5) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
- (fp_text value 1u (at 7.5 5.12) (layer F.Fab)
+ (fp_text value 1u (at 2.5 6.5) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
- (fp_line (start 2 -4) (end 2 4) (layer F.Fab) (width 0.1))
- (fp_line (start 13 -4) (end 13 4) (layer F.Fab) (width 0.1))
- (fp_line (start 2 -4) (end 3.38 -4) (layer F.Fab) (width 0.1))
- (fp_line (start 3.38 -4) (end 4.13 -3.25) (layer F.Fab) (width 0.1))
- (fp_line (start 4.13 -3.25) (end 4.88 -4) (layer F.Fab) (width 0.1))
- (fp_line (start 4.88 -4) (end 13 -4) (layer F.Fab) (width 0.1))
- (fp_line (start 2 4) (end 3.38 4) (layer F.Fab) (width 0.1))
- (fp_line (start 3.38 4) (end 4.13 3.25) (layer F.Fab) (width 0.1))
- (fp_line (start 4.13 3.25) (end 4.88 4) (layer F.Fab) (width 0.1))
- (fp_line (start 4.88 4) (end 13 4) (layer F.Fab) (width 0.1))
- (fp_line (start 0 0) (end 2 0) (layer F.Fab) (width 0.1))
- (fp_line (start 15 0) (end 13 0) (layer F.Fab) (width 0.1))
- (fp_line (start 3.4 0) (end 4.9 0) (layer F.Fab) (width 0.1))
- (fp_line (start 4.15 -0.75) (end 4.15 0.75) (layer F.Fab) (width 0.1))
- (fp_line (start 0.13 -2.2) (end 1.63 -2.2) (layer F.SilkS) (width 0.12))
- (fp_line (start 0.88 -2.95) (end 0.88 -1.45) (layer F.SilkS) (width 0.12))
- (fp_line (start 1.88 -4.12) (end 1.88 4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 13.12 -4.12) (end 13.12 4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 1.88 -4.12) (end 3.38 -4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 3.38 -4.12) (end 4.13 -3.37) (layer F.SilkS) (width 0.12))
- (fp_line (start 4.13 -3.37) (end 4.88 -4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 4.88 -4.12) (end 13.12 -4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 1.88 4.12) (end 3.38 4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 3.38 4.12) (end 4.13 3.37) (layer F.SilkS) (width 0.12))
- (fp_line (start 4.13 3.37) (end 4.88 4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 4.88 4.12) (end 13.12 4.12) (layer F.SilkS) (width 0.12))
- (fp_line (start 1.24 0) (end 1.88 0) (layer F.SilkS) (width 0.12))
- (fp_line (start 13.76 0) (end 13.12 0) (layer F.SilkS) (width 0.12))
- (fp_line (start -1.25 -4.25) (end -1.25 4.25) (layer F.CrtYd) (width 0.05))
- (fp_line (start -1.25 4.25) (end 16.25 4.25) (layer F.CrtYd) (width 0.05))
- (fp_line (start 16.25 4.25) (end 16.25 -4.25) (layer F.CrtYd) (width 0.05))
- (fp_line (start 16.25 -4.25) (end -1.25 -4.25) (layer F.CrtYd) (width 0.05))
- (fp_text user %R (at 7.5 0) (layer F.Fab)
+ (fp_circle (center 2.5 0) (end 7.75 0) (layer F.Fab) (width 0.1))
+ (fp_circle (center 2.5 0) (end 7.87 0) (layer F.SilkS) (width 0.12))
+ (fp_circle (center 2.5 0) (end 8 0) (layer F.CrtYd) (width 0.05))
+ (fp_line (start -2.004387 -2.2975) (end -0.954387 -2.2975) (layer F.Fab) (width 0.1))
+ (fp_line (start -1.479387 -2.8225) (end -1.479387 -1.7725) (layer F.Fab) (width 0.1))
+ (fp_line (start -3.247133 -3.015) (end -2.197133 -3.015) (layer F.SilkS) (width 0.12))
+ (fp_line (start -2.722133 -3.54) (end -2.722133 -2.49) (layer F.SilkS) (width 0.12))
+ (fp_text user %R (at 2.5 0) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
- (pad 1 thru_hole rect (at 0 0) (size 2 2) (drill 1) (layers *.Cu *.Mask)
+ (pad 1 thru_hole rect (at 0 0) (size 1.6 1.6) (drill 0.8) (layers *.Cu *.Mask)
(net 3 "Net-(C1-Pad1)"))
- (pad 2 thru_hole oval (at 15 0) (size 2 2) (drill 1) (layers *.Cu *.Mask)
+ (pad 2 thru_hole circle (at 5 0) (size 1.6 1.6) (drill 0.8) (layers *.Cu *.Mask)
(net 2 GND))
- (model ${KISYS3DMOD}/Capacitor_THT.3dshapes/CP_Axial_L11.0mm_D8.0mm_P15.00mm_Horizontal.wrl
+ (model ${KISYS3DMOD}/Capacitor_THT.3dshapes/CP_Radial_Tantal_D10.5mm_P5.00mm.wrl
(at (xyz 0 0 0))
(scale (xyz 1 1 1))
(rotate (xyz 0 0 0))
)
)
- (module Resistor_SMD:R_1206_3216Metric (layer F.Cu) (tedit 5B20DC38) (tstamp 5B5BC1DF)
- (at 60 61.4 90)
+ (module Resistor_SMD:R_1206_3216Metric (layer F.Cu) (tedit 5B20DC38) (tstamp 5B5D10B5)
+ (at 58.75 66.5)
(descr "Resistor SMD 1206 (3216 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: http://www.tortai-tech.com/upload/download/2011102023233369053.pdf), generated with kicad-footprint-generator")
(tags resistor)
- (path /5B431328)
+ (path /5B5CC4D4)
(attr smd)
- (fp_text reference R1 (at 0 -1.82 90) (layer F.SilkS)
+ (fp_text reference R2 (at 0 -1.82) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
- (fp_text value 10k (at 0 1.82 90) (layer F.Fab)
+ (fp_text value 10k (at 0 1.82) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_line (start -1.6 0.8) (end -1.6 -0.8) (layer F.Fab) (width 0.1))
@@ -257,13 +270,13 @@
(fp_line (start -2.28 -1.12) (end 2.28 -1.12) (layer F.CrtYd) (width 0.05))
(fp_line (start 2.28 -1.12) (end 2.28 1.12) (layer F.CrtYd) (width 0.05))
(fp_line (start 2.28 1.12) (end -2.28 1.12) (layer F.CrtYd) (width 0.05))
- (fp_text user %R (at 0 0 90) (layer F.Fab)
+ (fp_text user %R (at 0 0) (layer F.Fab)
(effects (font (size 0.8 0.8) (thickness 0.12)))
)
- (pad 1 smd roundrect (at -1.4 0 90) (size 1.25 1.75) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.2)
+ (pad 1 smd roundrect (at -1.4 0) (size 1.25 1.75) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.2)
(net 3 "Net-(C1-Pad1)"))
- (pad 2 smd roundrect (at 1.4 0 90) (size 1.25 1.75) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.2)
- (net 1 "Net-(BT1-Pad1)"))
+ (pad 2 smd roundrect (at 1.4 0) (size 1.25 1.75) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.2)
+ (net 4 "Net-(R1-Pad1)"))
(model ${KISYS3DMOD}/Resistor_SMD.3dshapes/R_1206_3216Metric.wrl
(at (xyz 0 0 0))
(scale (xyz 1 1 1))
@@ -275,8 +288,11 @@
(segment (start 60 60) (end 71.25 60) (width 0.25) (layer F.Cu) (net 1))
(segment (start 62.91 74.09) (end 61 76) (width 0.25) (layer B.Cu) (net 2))
(segment (start 71.75 74.09) (end 62.91 74.09) (width 0.25) (layer B.Cu) (net 2))
- (segment (start 60 62.8) (end 46.45 62.8) (width 0.25) (layer F.Cu) (net 3))
- (segment (start 46 63.25) (end 46 76) (width 0.25) (layer F.Cu) (net 3))
- (segment (start 46.45 62.8) (end 46 63.25) (width 0.25) (layer F.Cu) (net 3))
+ (segment (start 56.25 76) (end 61 76) (width 0.25) (layer B.Cu) (net 2))
+ (segment (start 53.25 66.5) (end 51.25 68.5) (width 0.25) (layer F.Cu) (net 3))
+ (segment (start 57.35 66.5) (end 53.25 66.5) (width 0.25) (layer F.Cu) (net 3))
+ (segment (start 51.25 76) (end 51.25 68.5) (width 0.25) (layer F.Cu) (net 3))
+ (segment (start 60 66.35) (end 60.15 66.5) (width 0.25) (layer F.Cu) (net 4))
+ (segment (start 60 62.8) (end 60 66.35) (width 0.25) (layer F.Cu) (net 4))
)
diff --git a/demo/doit/demo.sch b/demo/doit/demo.sch
index 9ccb57c..37a2ff9 100644
--- a/demo/doit/demo.sch
+++ b/demo/doit/demo.sch
@@ -17,12 +17,13 @@ $EndDescr
$Comp
L Device:R R1
U 1 1 5B431328
-P 4350 2600
-F 0 "R1" V 4143 2600 50 0000 C CNN
-F 1 "10k" V 4234 2600 50 0000 C CNN
-F 2 "Resistor_SMD:R_1206_3216Metric" V 4280 2600 50 0001 C CNN
-F 3 "~" H 4350 2600 50 0001 C CNN
- 1 4350 2600
+P 4150 2600
+F 0 "R1" V 3943 2600 50 0000 C CNN
+F 1 "10k" V 4034 2600 50 0000 C CNN
+F 2 "Resistor_SMD:R_1206_3216Metric" V 4080 2600 50 0001 C CNN
+F 3 "~" H 4150 2600 50 0001 C CNN
+F 4 "RMCF1206JT10K0" V 4150 2600 50 0001 C CNN "mpn"
+ 1 4150 2600
0 1 1 0
$EndComp
$Comp
@@ -33,24 +34,26 @@ F 0 "BT1" H 3818 2996 50 0000 L CNN
F 1 "9V" H 3818 2905 50 0000 L CNN
F 2 "Battery:BatteryHolder_MPD_BC2AAPC_2xAA" V 3700 2960 50 0001 C CNN
F 3 "~" V 3700 2960 50 0001 C CNN
+F 4 "BC2AAPC" H 3700 2900 50 0001 C CNN "mpn"
1 3700 2900
1 0 0 -1
$EndComp
$Comp
L Device:C C1
U 1 1 5B4314AB
-P 5000 2850
-F 0 "C1" H 5115 2896 50 0000 L CNN
-F 1 "1u" H 5115 2805 50 0000 L CNN
-F 2 "Capacitor_THT:CP_Axial_L11.0mm_D8.0mm_P15.00mm_Horizontal" H 5038 2700 50 0001 C CNN
-F 3 "~" H 5000 2850 50 0001 C CNN
- 1 5000 2850
+P 5100 2850
+F 0 "C1" H 5215 2896 50 0000 L CNN
+F 1 "1u" H 5215 2805 50 0000 L CNN
+F 2 "Capacitor_THT:CP_Radial_Tantal_D10.5mm_P5.00mm" H 5138 2700 50 0001 C CNN
+F 3 "~" H 5100 2850 50 0001 C CNN
+F 4 "UCA2G100MPD1TD" H 5100 2850 50 0001 C CNN "mpn"
+ 1 5100 2850
1 0 0 -1
$EndComp
Wire Wire Line
3700 3000 3700 3100
Wire Wire Line
- 5000 3100 5000 3000
+ 5100 3100 5100 3000
$Comp
L power:GND #PWR0101
U 1 1 5B4315FE
@@ -68,11 +71,25 @@ Connection ~ 3700 3100
Wire Wire Line
3700 2700 3700 2600
Wire Wire Line
- 5000 2600 5000 2700
+ 5100 2600 5100 2700
Wire Wire Line
- 3700 2600 4200 2600
+ 3700 2600 4000 2600
Wire Wire Line
- 3700 3100 5000 3100
+ 3700 3100 5100 3100
Wire Wire Line
- 4500 2600 5000 2600
+ 4300 2600 4500 2600
+$Comp
+L Device:R R2
+U 1 1 5B5CC4D4
+P 4650 2600
+F 0 "R2" V 4443 2600 50 0000 C CNN
+F 1 "10k" V 4534 2600 50 0000 C CNN
+F 2 "Resistor_SMD:R_1206_3216Metric" V 4580 2600 50 0001 C CNN
+F 3 "~" H 4650 2600 50 0001 C CNN
+F 4 "RMCF1206JT10K0" V 4650 2600 50 0001 C CNN "mpn"
+ 1 4650 2600
+ 0 1 1 0
+$EndComp
+Wire Wire Line
+ 4800 2600 5100 2600
$EndSCHEMATC
diff --git a/demo/doit/dodo.py b/demo/doit/dodo.py
index 1f5fec8..c5372fc 100644
--- a/demo/doit/dodo.py
+++ b/demo/doit/dodo.py
@@ -1,8 +1,7 @@
+import ee.doit
import ee.kicad.doit
-import ee.bom.doit
# noinspection PyUnresolvedReferences
from ee.bom.doit import *
-from ee.ds import DataSetManager
from ee.kicad.doit import *
prj = "demo"
@@ -11,6 +10,8 @@ kicad_pcb = "{}.kicad_pcb".format(prj)
DOIT_CONFIG = {'check_file_uptodate': 'timestamp'}
+ee.doit.configure_logging()
+
dsm = DataSetManager("ee")
kicad_footprint = "kicad-footprint"
@@ -28,3 +29,11 @@ ee.kicad.doit.init(
ee.bom.doit.init(
data_set_manager=dsm,
)
+
+
+def task_orders():
+ data_sets = [ee.bom.doit.output_data_set_for_task(task_bom)]
+ for size in [1, 100]:
+ yield create_task_order_csv("ee/order-{}.csv".format(size) if size != 1 else "ee/order.csv",
+ data_sets,
+ count=size)
diff --git a/demo/doit/ee/bom/bom-component/BT1.ini b/demo/doit/ee/bom/bom-component/BT1.ini
new file mode 100644
index 0000000..b65c2f0
--- /dev/null
+++ b/demo/doit/ee/bom/bom-component/BT1.ini
@@ -0,0 +1,7 @@
+[meta]
+type = bom-component
+
+[values]
+ref = BT1
+mpn = BC2AAPC
+
diff --git a/demo/doit/ee/bom/bom-component/C1.ini b/demo/doit/ee/bom/bom-component/C1.ini
new file mode 100644
index 0000000..ceee93c
--- /dev/null
+++ b/demo/doit/ee/bom/bom-component/C1.ini
@@ -0,0 +1,7 @@
+[meta]
+type = bom-component
+
+[values]
+ref = C1
+mpn = UCA2G100MPD1TD
+
diff --git a/demo/doit/ee/bom/bom-component/R1.ini b/demo/doit/ee/bom/bom-component/R1.ini
new file mode 100644
index 0000000..f76332b
--- /dev/null
+++ b/demo/doit/ee/bom/bom-component/R1.ini
@@ -0,0 +1,7 @@
+[meta]
+type = bom-component
+
+[values]
+ref = R1
+mpn = RMCF1206JT10K0
+
diff --git a/demo/doit/ee/bom/bom-component/R2.ini b/demo/doit/ee/bom/bom-component/R2.ini
new file mode 100644
index 0000000..301daa1
--- /dev/null
+++ b/demo/doit/ee/bom/bom-component/R2.ini
@@ -0,0 +1,7 @@
+[meta]
+type = bom-component
+
+[values]
+ref = R2
+mpn = RMCF1206JT10K0
+
diff --git a/demo/doit/ee/bom/data-set.ini b/demo/doit/ee/bom/data-set.ini
new file mode 100644
index 0000000..e915b00
--- /dev/null
+++ b/demo/doit/ee/bom/data-set.ini
@@ -0,0 +1,3 @@
+[data-set]
+name = bom
+
diff --git a/demo/doit/ee/kicad-pcb/data-set.ini b/demo/doit/ee/kicad-pcb/data-set.ini
new file mode 100644
index 0000000..7229def
--- /dev/null
+++ b/demo/doit/ee/kicad-pcb/data-set.ini
@@ -0,0 +1,3 @@
+[data-set]
+name = kicad-pcb
+
diff --git a/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC1DF.ini b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC1DF.ini
new file mode 100644
index 0000000..bffc18c
--- /dev/null
+++ b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC1DF.ini
@@ -0,0 +1,10 @@
+[meta]
+type = kicad-pcb-component
+
+[values]
+ref = R1
+placement-x = 60.0
+placement-y = 61.4
+placement-rotation = 90.0
+layer = F.Cu
+
diff --git a/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC36D.ini b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC36D.ini
new file mode 100644
index 0000000..42cab19
--- /dev/null
+++ b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5BC36D.ini
@@ -0,0 +1,9 @@
+[meta]
+type = kicad-pcb-component
+
+[values]
+ref = BT1
+placement-x = 71.75
+placement-y = 60.5
+layer = F.Cu
+
diff --git a/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D0FE8.ini b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D0FE8.ini
new file mode 100644
index 0000000..41df177
--- /dev/null
+++ b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D0FE8.ini
@@ -0,0 +1,9 @@
+[meta]
+type = kicad-pcb-component
+
+[values]
+ref = C1
+placement-x = 51.25
+placement-y = 76.0
+layer = F.Cu
+
diff --git a/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D10B5.ini b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D10B5.ini
new file mode 100644
index 0000000..4e39ba0
--- /dev/null
+++ b/demo/doit/ee/kicad-pcb/kicad-pcb-component/5B5D10B5.ini
@@ -0,0 +1,9 @@
+[meta]
+type = kicad-pcb-component
+
+[values]
+ref = R2
+placement-x = 58.75
+placement-y = 66.5
+layer = F.Cu
+
diff --git a/demo/doit/ee/kicad-sch/data-set.ini b/demo/doit/ee/kicad-sch/data-set.ini
new file mode 100644
index 0000000..23c66c7
--- /dev/null
+++ b/demo/doit/ee/kicad-sch/data-set.ini
@@ -0,0 +1,3 @@
+[data-set]
+name = kicad-sch
+
diff --git a/demo/doit/ee/kicad-sch/kicad-schematic-component/5B431328.ini b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B431328.ini
new file mode 100644
index 0000000..5bec452
--- /dev/null
+++ b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B431328.ini
@@ -0,0 +1,11 @@
+[meta]
+type = kicad-schematic-component
+
+[values]
+ref = R1
+ref-type = R
+ref-num = 1
+value = 10k
+footprint = Resistor_SMD:R_1206_3216Metric
+field-mpn = RMCF1206JT10K0
+
diff --git a/demo/doit/ee/kicad-sch/kicad-schematic-component/5B431438.ini b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B431438.ini
new file mode 100644
index 0000000..aa748e4
--- /dev/null
+++ b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B431438.ini
@@ -0,0 +1,11 @@
+[meta]
+type = kicad-schematic-component
+
+[values]
+ref = BT1
+ref-type = BT
+ref-num = 1
+value = 9V
+footprint = Battery:BatteryHolder_MPD_BC2AAPC_2xAA
+field-mpn = BC2AAPC
+
diff --git a/demo/doit/ee/kicad-sch/kicad-schematic-component/5B4314AB.ini b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B4314AB.ini
new file mode 100644
index 0000000..30f9a91
--- /dev/null
+++ b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B4314AB.ini
@@ -0,0 +1,11 @@
+[meta]
+type = kicad-schematic-component
+
+[values]
+ref = C1
+ref-type = C
+ref-num = 1
+value = 1u
+footprint = Capacitor_THT:CP_Radial_Tantal_D10.5mm_P5.00mm
+field-mpn = UCA2G100MPD1TD
+
diff --git a/demo/doit/ee/kicad-sch/kicad-schematic-component/5B4315FE.ini b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B4315FE.ini
new file mode 100644
index 0000000..5896e1c
--- /dev/null
+++ b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B4315FE.ini
@@ -0,0 +1,9 @@
+[meta]
+type = kicad-schematic-component
+
+[values]
+ref = #PWR0101
+ref-type = #PWR
+ref-num = 101
+value = GND
+
diff --git a/demo/doit/ee/kicad-sch/kicad-schematic-component/5B5CC4D4.ini b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B5CC4D4.ini
new file mode 100644
index 0000000..65ed524
--- /dev/null
+++ b/demo/doit/ee/kicad-sch/kicad-schematic-component/5B5CC4D4.ini
@@ -0,0 +1,11 @@
+[meta]
+type = kicad-schematic-component
+
+[values]
+ref = R2
+ref-type = R
+ref-num = 2
+value = 10k
+footprint = Resistor_SMD:R_1206_3216Metric
+field-mpn = RMCF1206JT10K0
+
diff --git a/demo/doit/ee/order-100.csv b/demo/doit/ee/order-100.csv
new file mode 100644
index 0000000..4f5b439
--- /dev/null
+++ b/demo/doit/ee/order-100.csv
@@ -0,0 +1,4 @@
+MPN,Count,References
+BC2AAPC,100,BT1
+RMCF1206JT10K0,200,"R2,R1"
+UCA2G100MPD1TD,100,C1
diff --git a/demo/doit/ee/order.csv b/demo/doit/ee/order.csv
new file mode 100644
index 0000000..9722390
--- /dev/null
+++ b/demo/doit/ee/order.csv
@@ -0,0 +1,4 @@
+MPN,Count,References
+BC2AAPC,1,BT1
+RMCF1206JT10K0,2,"R2,R1"
+UCA2G100MPD1TD,1,C1
diff --git a/requirements.txt b/requirements.txt
index b5bd818..7bcc478 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,10 +1,12 @@
# for development, see setup.py for production dependencies.
ansicolors==1.1.8
CacheControl==0.12.5
+configclass==0.1.0
lockfile==0.12.2
lxml==4.2.3
matplotlib==2.2.2
mpmath==1.0.0
+namedlist==1.7
numpy==1.14.5
pandas==0.23.3
parsec==3.3
diff --git a/setup.py b/setup.py
index b13b857..0abc8d4 100644
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,7 @@ setup(name='ee',
'lxml',
'matplotlib',
'mpmath',
+ 'namedlist',
'numpy',
'pandas',
'parsec',
diff --git a/src/ee/bom/doit.py b/src/ee/bom/doit.py
index d7407d8..f793611 100644
--- a/src/ee/bom/doit.py
+++ b/src/ee/bom/doit.py
@@ -1,13 +1,31 @@
-from typing import Mapping
+import logging
+from pathlib import Path
+from typing import Mapping, Union
from configclass import Config
+from namedlist import namedlist
-from ee.ds import DataSetManager
+from ee.ds import DataSetManager, DataSet
+
+logger = logging.getLogger(__name__)
_dsm = None # type: DataSetManager
_data_sets = {}
+
+def change_data_sets_for_task(task, _callable):
+ _data_sets[task][1] = _callable(_data_sets[task][1])
+
+
+def output_data_set_for_task(task):
+ return _data_sets[task][0]
+
+
+def input_data_sets_for_task(task):
+ return _data_sets[task][1]
+
+
_config_template = Config({
})
@@ -28,62 +46,48 @@ class BomComponent(object):
self.mpn = mpn
def to_object(self, ds):
- return ds.create_object("bom-component", self.ref).\
- set("ref", self.ref).\
- set("mpn", self.mpn)
-
-
-class MpnBomComponent(object):
- def __init__(self, ref, mpn):
- self.ref = ref
- self.mpn = mpn
- self.count = 1
-
- def to_object(self, ds):
- return ds.create_object("mpn-bom-component", self.ref).\
- set("ref", self.ref).\
+ return ds.create_object("bom-component", self.ref). \
+ set("ref", self.ref). \
set("mpn", self.mpn)
def task_bom():
- out_data_set = "bom"
- in_data_sets = _data_sets[task_bom]
+ """
+ Takes all schematic components, filters out all virtual/non-
+ physical components (like power flags and ground components) and
+ creates 'bom-component' objects.
+ """
- def action(count=1):
- with _dsm.create_ro(in_data_sets) as in_ds:
- with _dsm.create_rw(out_data_set, clean=True) as output:
- components = [o for o in in_ds.items() if o.object_type.name == "component"]
+ out_data_set = _data_sets[task_bom][0]
+ in_data_sets = _data_sets[task_bom][1]
- bom_components = {}
- mpn_bom_components = {}
+ def action():
+ in_ds = _dsm.load_data_sets(in_data_sets)
- for c in components:
- ref = c.get("ref")
- mpn = c.get("mpn")
+ with _dsm.create_rw(out_data_set, clean=True) as output:
+ components = [o for o in in_ds.items() if o.object_type.name == "component"]
- if not ref:
- raise Exception("Missing ref")
+ bom_components = {}
- if not mpn:
- output.create_object("message", "bom-{}".format(ref)). \
- set("level", "error"). \
- set("message", "Missing required field 'mpn'")
- continue
+ for c in components:
+ ref = c.get("ref")
+ mpn = c.get("mpn")
- if ref in bom_components:
- raise Exception("Duplicate ref '{}'".format("ref"))
+ if not ref:
+ raise Exception("Missing ref")
- bom_components[ref] = BomComponent(ref, mpn)
+ if not mpn:
+ output.create_object("message", "bom-{}".format(ref)). \
+ set("level", "error"). \
+ set("message", "Missing required field 'mpn'")
+ continue
- mpn_bom_component = mpn_bom_components[ref]
- if not mpn_bom_component:
- mpn_bom_component = MpnBomComponent(ref, mpn)
- mpn_bom_components[ref] = mpn_bom_component
+ if ref in bom_components:
+ raise Exception("Duplicate ref '{}'".format("ref"))
- mpn_bom_component.count += 1
+ bom_components[ref] = BomComponent(ref, mpn)
- [c.to_object(output) for c in bom_components.values()]
- [c.to_object(output) for c in mpn_bom_components.values()]
+ [c.to_object(output) for c in bom_components.values()]
return {
"file_dep": [_dsm.cookie_for_ds(ds) for ds in in_data_sets],
@@ -92,4 +96,43 @@ def task_bom():
}
-_data_sets[task_bom] = ["components"]
+_data_sets[task_bom] = ["bom", ["components"]]
+
+
+def order_csv(count: int, group_by_mpn: bool, output_file: Path, data_sets):
+ ds = _dsm.load_data_sets(data_sets)
+
+ out = DataSet()
+
+ if group_by_mpn:
+ parts = {}
+
+ Part = namedlist("Part", "mpn, cnt, refs")
+
+ for c in [o for o in ds.items() if o.object_type.name == "bom-component"]:
+ ref = c.get("ref")
+ mpn = c.get("mpn")
+ if mpn in parts:
+ parts[mpn].cnt += 1
+ parts[mpn].refs.append(ref)
+ else:
+ parts[mpn] = Part(mpn=mpn, cnt=1, refs=[ref])
+
+ for part in sorted(parts.values(), key=lambda p: p.mpn):
+ out.create_object("row", part.mpn). \
+ set("MPN", part.mpn). \
+ set("Count", part.cnt * count). \
+ set("References", ",".join(part.refs))
+
+ _dsm.store_csv(output_file, out, "row", order_by="MPN")
+ else:
+ raise Exception("Not implemented")
+
+
+def create_task_order_csv(output_file: Union[str, Path], data_sets, count: int = 1):
+ return {
+ "name": "order-{}".format(count),
+ "actions": [(order_csv, [count, True, Path(output_file), data_sets])],
+ "file_dep": [_dsm.cookie_for_ds(ds) for ds in data_sets],
+ "targets": [output_file],
+ }
diff --git a/src/ee/doit.py b/src/ee/doit.py
new file mode 100644
index 0000000..87a6601
--- /dev/null
+++ b/src/ee/doit.py
@@ -0,0 +1,16 @@
+import logging
+
+from doit import get_var
+
+
+def configure_logging():
+ log_level = get_var("log-level", None)
+
+ if log_level:
+ ee_logger = logging.getLogger("ee")
+ formatter = logging.Formatter("%(levelname)s: %(message)s")
+ ch = logging.StreamHandler()
+ ch.setFormatter(formatter)
+ ee_logger.addHandler(ch)
+
+ ee_logger.setLevel(log_level)
diff --git a/src/ee/ds/__init__.py b/src/ee/ds/__init__.py
index 5899d28..030113b 100644
--- a/src/ee/ds/__init__.py
+++ b/src/ee/ds/__init__.py
@@ -5,7 +5,7 @@ import os
import shutil
from functools import total_ordering
from pathlib import Path
-from typing import MutableMapping, Optional, List, Tuple, Union, Iterator
+from typing import MutableMapping, Optional, List, Tuple, Union, Iterator, Iterable
logger = logging.getLogger(__name__)
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
class ObjectType(object):
def __init__(self, name: str):
self._name = name
- self._fields = []
+ self._fields = [] # type: List[str]
self._objects = {}
def __eq__(self, o) -> bool:
@@ -42,7 +42,7 @@ class ObjectType(object):
def index_of(self, field: str, create: bool = False) -> Optional[int]:
try:
return self._fields.index(field)
- except ValueError as e:
+ except ValueError:
if not create:
return None
@@ -81,6 +81,13 @@ class Object(object):
idx = self._ot.index_of(key)
return self._data[idx] if idx is not None and idx < len(self._data) else None
+ def get_req(self, key: str) -> str:
+ idx = self._ot.index_of(key)
+ if idx is not None and idx < len(self._data):
+ return self._data[idx]
+ else:
+ raise Exception("No such field: {}".format(key))
+
def get_all(self, *keys: str) -> Optional[List[str]]:
values = []
for key in keys:
@@ -92,18 +99,11 @@ class Object(object):
class DataSet(object):
- def __init__(self, name: Optional[str] = None):
- self._name = name
+ def __init__(self):
self._object_types = {} # type: MutableMapping[str, ObjectType]
self._objects_by_type = {} # type: MutableMapping[ObjectType, MutableMapping[str, Object]]
self._frozen = False
- @property
- def name(self):
- if not self._name:
- raise Exception("Unnamed data set")
- return self._name
-
def __len__(self):
return sum((len(objects) for objects in self._objects_by_type.values()))
@@ -151,11 +151,12 @@ class DataSet(object):
return o
def get_object_type(self, object_type: str) -> ObjectType:
- ot, objects = self._check_object_type(object_type, False)
+ t = self._check_object_type(object_type, False)
- if not ot:
+ if not t:
raise Exception("No such object type: {}".format(object_type))
+ ot, objects = t
return ot
def get_object(self, object_type: str, key: str) -> Object:
@@ -192,7 +193,7 @@ class DataSet(object):
yield o
def merge(self, other: "DataSet") -> "DataSet":
- ds = DataSet(self._name)
+ ds = DataSet()
for objects in self._objects_by_type.values():
for o in objects.values():
ds.create_object(o.object_type.name, o.key)._set_from_object(o)
@@ -203,6 +204,14 @@ class DataSet(object):
return ds
+ def import_object(self, other: Object) -> Object:
+ o = self._check_object(other.object_type.name, other.key, create=True)
+
+ for k in other.object_type.fields:
+ o.set(k, other.get(k))
+
+ return o
+
class DataSetManager(object):
def __init__(self, basedir: Union[Path, str]):
@@ -218,8 +227,15 @@ class DataSetManager(object):
def create_rw(self, name, clean: bool) -> "LazyRwDataSet":
return LazyRwDataSet(self, name, clean)
- def create_ro(self, inputs: List[str]) -> "LazyRoDataSet":
- return LazyRoDataSet(self, inputs)
+ def load_data_sets(self, inputs: List[str], freeze: bool = True) -> DataSet:
+ ds = DataSet()
+ for name in inputs:
+ ds = ds.merge(self.load(name, freeze=True))
+
+ if freeze:
+ ds.freeze()
+
+ return ds
def add_ds(self, ds_type: str, name: str, object_type: str, path: str = None):
if ds_type == "csv":
@@ -233,21 +249,21 @@ class DataSetManager(object):
def ds_type(self, name: str):
return "csv" if name in self._csv else "ini-dir"
- def load(self, name, freeze=False) -> DataSet:
+ def load(self, path, freeze=False) -> DataSet:
try:
- object_type, path = self._csv[name]
+ object_type, path = self._csv[path]
if not freeze:
raise Exception("CSV data sources must be frozen")
- return DataSetManager._load_csv(name, object_type, path, freeze)
+ return DataSetManager._load_csv(object_type, path, freeze)
except KeyError:
- return self._load_ini_dir(name, freeze)
+ return self._load_ini_dir(path, freeze)
@staticmethod
- def _load_csv(name: str, object_type: str, path: Path, freeze: bool) -> DataSet:
- logger.info("Loading CSV file {}".format(path))
- ds = DataSet(name)
+ def _load_csv(object_type: str, path: Path, freeze: bool) -> DataSet:
+ logger.debug("Loading CSV file {}".format(path))
+ ds = DataSet()
with open(str(path), newline='') as f:
r = csv.reader(f)
@@ -263,31 +279,33 @@ class DataSetManager(object):
for idx, value in zip(range(0, min(len(row), len(header))), row):
o.set(header[idx], value)
+ if freeze:
+ ds.freeze()
+
logger.debug("Loaded {} objects".format(len(ds)))
return ds
- def _load_ini_dir(self, name: str, freeze: bool) -> DataSet:
- ds_dir = Path(name) if Path(name).is_absolute() else self._basedir / name
+ def _load_ini_dir(self, _path: str, freeze: bool) -> DataSet:
+ ds_dir = Path(_path) if Path(_path).is_absolute() else self._basedir / _path
ds_dir = ds_dir if ds_dir.is_dir() else ds_dir.parent
- logger.info("Loading DS from '{}'".format(ds_dir))
+ logger.debug("Loading DS from '{}'".format(ds_dir))
- ini = self._load_ini(ds_dir / "data-set.ini")
- name = ini.get("data-set", "name")
+ self._load_ini(ds_dir / "data-set.ini")
- ds = DataSet(name)
+ ds = DataSet()
count = 0
for ot_path in ds_dir.glob("*"):
if not ot_path.is_dir():
continue
ot = ot_path.name
- logger.info(" Loading type '{}'".format(ot))
+ logger.debug(" Loading type '{}'".format(ot))
for o_path in ot_path.glob("*.ini"):
count += 1
key = o_path.name[:-4]
- logger.info(" Loading key '{}'".format(key))
+ logger.debug(" Loading key '{}'".format(key))
ini = self._load_ini(o_path)
o = ds.create_object(ot, key)
for k, v in ini.items("values"):
@@ -296,18 +314,18 @@ class DataSetManager(object):
if freeze:
ds.freeze()
- logger.info("Loaded {} items".format(count))
+ logger.debug("Loaded {} items".format(count))
return ds
- def store(self, ds: DataSet):
- ds_dir = self._basedir / ds.name
+ def store(self, ds: DataSet, ds_name: str):
+ ds_dir = self._basedir / ds_name
items = list(ds.items())
- logger.info("Storing DS '{}' with {} objects to {}".format(ds.name, len(items), ds_dir))
+ logger.info("Storing DS '{}' with {} objects to {}".format(ds_name, len(items), ds_dir))
os.makedirs(ds_dir, exist_ok=True)
ini = self._blank_ini()
ini.add_section("data-set")
- ini.set("data-set", "name", ds.name)
+ ini.set("data-set", "name", ds_name)
self._store_ini(ini, ds_dir / "data-set.ini")
for o in items:
@@ -327,6 +345,30 @@ class DataSetManager(object):
ini.set("values", k, str(v))
self._store_ini(ini, ot_dir / "{}.ini".format(key))
+ # noinspection PyMethodMayBeStatic
+ def store_csv(self, path: Union[str, Path], ds: DataSet, object_type: str,
+ order_by: Union[str, Iterable[str]] = None):
+ items = [o for o in ds.items() if o.object_type.name == object_type]
+
+ if order_by:
+ if isinstance(order_by, str):
+ items = sorted(items, key=lambda o: o.get_req(order_by))
+ elif isinstance(order_by, Iterable):
+ items = sorted(items, key=lambda o: [o.get_req(ob) for ob in order_by])
+ else:
+ raise Exception("Unsupported order_by")
+
+ with open(path, "w") as f:
+ w = csv.writer(f)
+
+ if len(items):
+ header = ds.get_object_type(object_type).fields
+ w.writerow(header)
+
+ for o in items:
+ row = [o.get(k) for k in header]
+ w.writerow(row)
+
@staticmethod
def _blank_ini():
return configparser.ConfigParser(interpolation=None)
@@ -350,26 +392,6 @@ class DataSetManager(object):
shutil.rmtree(self._basedir / name)
-class LazyRoDataSet(object):
- def __init__(self, dsm: DataSetManager, inputs):
- self._dsm = dsm
- self._inputs = inputs
-
- def __enter__(self) -> DataSet:
- # logger.info("enter: name={}, inputs={}".format(self._name, self._inputs))
- ds = DataSet()
- for name in self._inputs:
- ds = ds.merge(self._dsm.load(name, freeze=True))
-
- ds.freeze()
-
- self._ds = ds
- return ds
-
- def __exit__(self, *args):
- return False
-
-
class LazyRwDataSet(object):
def __init__(self, dsm: DataSetManager, name, clean):
self._dsm = dsm
@@ -384,10 +406,10 @@ class LazyRwDataSet(object):
raise IOError("DataSet already exists: {}, cookie={}".format(self._name, cookie))
self._dsm.remove(self._name)
- ds = DataSet(self._name)
+ ds = DataSet()
self._ds = ds
return ds
def __exit__(self, *args):
- self._dsm.store(self._ds)
+ self._dsm.store(self._ds, self._name)
return False
diff --git a/src/ee/kicad/doit.py b/src/ee/kicad/doit.py
index 30ca40d..bfbf0a1 100644
--- a/src/ee/kicad/doit.py
+++ b/src/ee/kicad/doit.py
@@ -26,24 +26,24 @@ _data_sets = {}
def change_data_sets_for_task(task, _callable):
- _data_sets[task] = _callable(_data_sets[task])
+ _data_sets[task][1] = _callable(_data_sets[task][1])
-def init(data_set_manager: DataSetManager, **kwargs):
- global _config
- _config = _config_template.make(kwargs)
+def output_data_set_for_task(task):
+ return _data_sets[task][0]
+
- ee_logger = logging.getLogger("ee")
- formatter = logging.Formatter("%(levelname)s: %(message)s")
- ch = logging.StreamHandler()
- ch.setFormatter(formatter)
- ee_logger.addHandler(ch)
+def input_data_sets_for_task(task):
+ return _data_sets[task][1]
- ee_logger.setLevel(logging.DEBUG)
+def init(data_set_manager: DataSetManager, **kwargs):
global _dsm
_dsm = data_set_manager
+ global _config
+ _config = _config_template.make(kwargs)
+
def task_kicad_gerber():
kicad_pcb = _config["kicad_pcb"]
@@ -84,8 +84,7 @@ def task_kicad_gerber():
def task_kicad_sch_to_data_set():
- out_data_set = "kicad-sch"
- in_data_sets = _data_sets[task_kicad_sch_to_data_set]
+ out_data_set, in_data_sets = _data_sets[task_kicad_sch_to_data_set]
sch = _config["sch"]
@@ -106,7 +105,7 @@ def task_kicad_sch_to_data_set():
for f in c.fields:
if f.value and f.name not in ComponentField.names:
- o.set(f.name, str(f.value))
+ o.set("field-{}".format(f.name), str(f.value))
return {
"file_dep": [Path(sch)] + [_dsm.cookie_for_ds(ds) for ds in in_data_sets],
@@ -115,14 +114,13 @@ def task_kicad_sch_to_data_set():
}
-_data_sets[task_kicad_sch_to_data_set] = []
+_data_sets[task_kicad_sch_to_data_set] = ["kicad-sch", []]
def task_kicad_pcb_to_data_set():
kicad_pcb = _config["kicad_pcb"]
- out_data_set = "kicad-pcb"
- in_data_sets = _data_sets[task_kicad_pcb_to_data_set]
+ out_data_set, in_data_sets = _data_sets[task_kicad_pcb_to_data_set]
def action():
from ee.kicad.pcb import KicadPcb, Module
@@ -154,71 +152,76 @@ def task_kicad_pcb_to_data_set():
}
-_data_sets[task_kicad_pcb_to_data_set] = []
+_data_sets[task_kicad_pcb_to_data_set] = ["kicad-pcb", []]
def task_kicad_create_component_data_set():
- out_data_set = "components"
- in_data_sets = _data_sets[task_kicad_create_component_data_set]
+ out_data_set, in_data_sets = _data_sets[task_kicad_create_component_data_set]
def action():
logger.info("in_data_sets={}, out_data_set={}".format(in_data_sets, out_data_set))
- with _dsm.create_ro(in_data_sets) as in_ds:
- # for o in in_ds.items():
- # logger.info("item: {}/{}".format(o.object_type.name, o.key))
+ in_ds = _dsm.load_data_sets(in_data_sets)
+ # for o in in_ds.items():
+ # logger.info("item: {}/{}".format(o.object_type.name, o.key))
+
+ def map_footprint(footprint):
+ for o in in_ds.items():
+ if not o.object_type.name == "kicad-footprint-mapping":
+ continue
- def map_footprint(footprint):
- for o in in_ds.items():
- if not o.object_type.name == "kicad-footprint-mapping":
- continue
+ common = o.get("common")
+ if common:
+ return common
- common = o.get("common")
- if common:
- return common
+ return footprint
- return footprint
+ with _dsm.create_rw(out_data_set, clean=True) as output:
+ kicad_sch = [o for o in in_ds.items() if o.object_type.name == "kicad-schematic-component"]
- with _dsm.create_rw(out_data_set, clean=True) as output:
- kicad_sch = [o for o in in_ds.items() if o.object_type.name == "kicad-schematic-component"]
+ logger.info("processing {} kicad-sch".format(len(kicad_sch)))
- logger.info("processing {} kicad-sch".format(len(kicad_sch)))
+ ignored_ref_types = {"#PWR", }
- ignored_ref_types = {"#PWR", }
+ for sch in kicad_sch:
+ ref = sch.get("ref")
+ ref_num = sch.get("ref-num")
+ if not ref or not ref_num:
+ logger.debug("Missing ref or ref-num")
+ continue
- for sch in kicad_sch:
- ref = sch.get("ref")
- ref_num = sch.get("ref-num")
- if not ref or not ref_num:
- logger.debug("Missing ref or ref-num")
- continue
+ ref_type = sch.get("ref-type")
+ if not ref_type:
+ logger.debug("Missing ref-type")
+ continue
+
+ if ref_type in ignored_ref_types:
+ continue
- ref_type = sch.get("ref-type")
- if not ref_type or ref_type in ignored_ref_types:
- logger.debug("Missing ref-type or bad ref-type: ref={}, ref-type={}".format(ref, ref_type))
- continue
+ c = output.create_object("component", ref)
+ c.set("ref", ref)
+ c.set("ref-num", ref_num)
+ c.set("ref-type", ref_type)
- c = output.create_object("component", ref)
- c.set("ref", ref)
- c.set("ref-num", ref_num)
- c.set("ref-type", ref_type)
+ fp = sch.get("footprint")
+ if fp:
+ fp = map_footprint(fp)
+ c.set("footprint", fp)
- fp = sch.get("footprint")
- if fp:
- fp = map_footprint(fp)
- c.set("footprint", fp)
+ c.set("mpn", sch.get("field-mpn"))
+ c.set("distributor", sch.get("field-distributor"))
- def pcb_match(o):
- return o.object_type.name == "kicad-pcb-component" and \
- o.get("ref") == ref
+ def pcb_match(o):
+ return o.object_type.name == "kicad-pcb-component" and \
+ o.get("ref") == ref
- pcb = [o for o in in_ds.items() if pcb_match(o)]
+ pcb = [o for o in in_ds.items() if pcb_match(o)]
- if not pcb:
- logger.info("Could not find PCB component for {}".format(ref))
+ if not pcb:
+ logger.info("Could not find PCB component for {}".format(ref))
- # TODO: check that the SCH and PCB footprint are the same
- # c.set("footprint", pcb.)
+ # TODO: check that the SCH and PCB footprint are the same
+ # c.set("footprint", pcb.)
return {
"file_dep": [_dsm.cookie_for_ds(ds) for ds in in_data_sets],
@@ -227,7 +230,7 @@ def task_kicad_create_component_data_set():
}
-_data_sets[task_kicad_create_component_data_set] = ["kicad-sch", "kicad-pcb"]
+_data_sets[task_kicad_create_component_data_set] = ["components", ["kicad-sch", "kicad-pcb"]]
__all__ = [
init.__name__,