11import io
2+ import os
23import sys
34
4- from .common import EcadParser , Component , BoundingBox
5+ from .common import EcadParser , Component , BoundingBox , ExtraFieldData
56
67
78if sys .version_info >= (3 , 0 ):
@@ -20,6 +21,33 @@ class EasyEdaParser(EcadParser):
2021 BOT_ASSEMBLY_LAYER = 14
2122 ALL_LAYERS = 11
2223
24+ def extra_data_file_filter (self ):
25+ return "Json file ({f})|{f}" .format (f = os .path .basename (self .file_name ))
26+
27+ def latest_extra_data (self , extra_dirs = None ):
28+ return self .file_name
29+
30+ def get_extra_field_data (self , file_name ):
31+ if os .path .abspath (file_name ) != os .path .abspath (self .file_name ):
32+ return None
33+
34+ _ , components = self .parse ()
35+ field_set = set ()
36+ comp_dict = {}
37+
38+ for c in components :
39+ ref_fields = comp_dict .setdefault (c .ref , {})
40+
41+ for k , v in c .extra_fields .items ():
42+ field_set .add (k )
43+ ref_fields [k ] = v
44+
45+ by_index = {
46+ i : components [i ].extra_fields for i in range (len (components ))
47+ }
48+
49+ return ExtraFieldData (list (field_set ), comp_dict , by_index )
50+
2351 def get_easyeda_pcb (self ):
2452 import json
2553 with io .open (self .file_name , 'r' , encoding = 'utf-8' ) as f :
@@ -290,7 +318,10 @@ def parse_lib(self, shape):
290318 fp_layer = 'F' if fp_layer == self .TOP_COPPER_LAYER else 'B'
291319 val = '??'
292320 ref = '??'
293- footprint = attr .get ('package' , '??' )
321+ footprint = '??'
322+ if 'package' in attr :
323+ footprint = attr ['package' ]
324+ del attr ['package' ]
294325
295326 pads = []
296327 copper_drawings = []
@@ -343,7 +374,7 @@ def parse_lib(self, shape):
343374 "layer" : fp_layer ,
344375 }
345376
346- component = Component (ref , val , footprint , fp_layer )
377+ component = Component (ref , val , footprint , fp_layer , extra_fields = attr )
347378
348379 return fp_layer , component , footprint_json , extra_drawings
349380
0 commit comments