forked from NVSL/Swoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateSwoop.py
More file actions
1338 lines (1106 loc) · 63 KB
/
GenerateSwoop.py
File metadata and controls
1338 lines (1106 loc) · 63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
.. module:: GenerateSwoop
.. moduleauthor:: Steven Swanson (swanson@cs.ucsd.edu)
GenerateSwoop.py generates the file Swoop.py, which contains a set
of python classes for manipulating eagle files. The process relies on two
bodies of information.
1. The contents of this file. It specifies the characteristic of each class
that corresponds to a part of an eagle file. The file defines several
classes (:class:`Attr`, :class:`List`, :class:`Map`, :class:`Singleton`,
and :class:`TagClass`) that specify how the Eagle classes should behave.
This file describes a collections of classes that represent a "flattened"
version of the XML format described in the Eagle DTD.
2. The contents of Swoop.jinja.py. This contains the template code for
the classes, a base class for all the classes, and a class to represent
eagle files, EagleFile.
The classes that this code generates each represent a part of an eagle file
(class :class:`EagleFilePart`). Instances of this class form a tree. The root of the
tree is an instance of :class:`SchematicFile`, :class:`BoardFile`, or :class:`LibraryFile`, all of which
are subclasses of :class:`EagleFile`.
Each :class:`EagleFilePart` contains one or more attributes and one or more
'collections' (i.e., lists, maps, or singletons) of :class:`EagleFilePart` objects. For
instance, :class:`SchematicFile` contains a collection that maps library names to
:class:`Library` objects, a list of :class:`Sheet` objects, and a singleton :class:`Description`
instance.
This file defines the set of collections that each subclass of :class:`EagleFilePart`
contains. Each of these subclasses is represented by a :class:`TagClass` object, which
contains a list (called :code:`sections`) of collections (represented by subclasses
of :class:`Collection` -- namely :class:`Map`, :class:`List`, and :class:`Singleton`). :class:`TagClass` also
includes a list of attributes (represented by :class:`Attr`).
Each :class:`Attr`, :class:`Map`, :class:`List`, and :class:`Singleton` object includes information necessary to
generate code for it. This includes mostly pedantic stuff like converting
"-" to "_" in attribute names so they are valid python identifiers, dealing
with eagle tag and attribute names that clash with python reserve words, and
information about which attributes and tags are required and which are
optional. There's also some support for parsing values (e.g., converting
"yes" to True).
The organization of the :class:`EagleFilePart` hierarchy is similar to the structure
of the eagle XML file. However, we make it easier to navigate by flattening
it. For instance, in the eagle file layer defintions live in
:code:`eagle/drawing/layers` and sheets live in :code:`eagle/drawing/schematic/sheets`. Our
library "flattens" this hierarchy so that :class:`SchematicFile` has a map of
layers and a list of sheets.
To realize this flattened structure, we specify the contents of each
collection using an xpath expression. All the elements that match the
expression for :class:`Map`, :class:`List`, or :class:`Singleton` will end up in that collection. The
xpath expressions get passed the constructors for the :class:`Map`, :class:`List`, and :class:`Singleton`.
The final stage is to generate the code. We use the jinja templating system
for this. Swoop.jinja.py contains templates for the :class:`EagleFilePart` subclasses.
It generates code for the constructor, the :code:`from_et()` method to convert for
element tree to :class:`EagleFileParts`, the :code:`get_et()` method for the reverse
conversion, a :code:`clone()` function for copying :class:`EagleFileParts`, and accessors for
attributes (:code:`get_*()` and :code:`set_*()`) and collections (:code:`get_*()` and :code:`add_*()`).
Generating Extension to Swoop
=============================
You can also import :code:`GenerateSwoop` as a module. In this case, it
exposes the a map called :code:`tag` that maps Eagle file XML tag names to
:class:`Tag` objects. You can then use this information however you would like
to generate extensions to Swoop.
"""
import jinja2 as J2
import argparse
import logging as log
import copy
import re
class Attr:
"""
Class representing an attribute.
"""
def __init__(self, name,
default=None,
required=False,
parse=None,
unparse=None,
vtype=None,
accessorName=None,
xmlName=None,
lookupEFP=None,
isKey=False,
**quirks):
"""Create a class describing an attribute.
:param name: The attribute's name. This is the name used for the member of the :class:`EagleFilePart` object. For example :code:`foo.netclass` (since :code:`class` clashes with a the Python :code:`class` reserved word.
:param require: Is the attribute required?
:param parse: String used to parse to attribute value. It will be invoked as :code:`parse(x)` where :code:`x` is the contents of the XML attribute.
:param unparse: String used to unparse the attribute value while generating XML. It will be invoked as :code:`unparse(x)` where :code:`x` is :mod:`Swoop`'s value for the attribute. :code:'unparse(parse(x))` should be the identity function.
:param accessorName:This is the string that will appear in Swoop API calls. For example :code:`foo.get_class()`
:param xmlName:This is string used in the XML representation. For example, :code:`class`.
:param lookupEFP: This is a tuple. The first element is a type. The second is a function that looks up an object of that type based on the value of this attribute. Function should take two arguments, the current :class:`EagleFilePart` and the value of the attribute.
:param isKey: True if this attribute is key in a map of the parent.
"""
self.name = name.replace("-", "_")
self.isKey= isKey
if xmlName is None:
self.xmlName = name
else:
self.xmlName = xmlName
# if default is None:
# if type == "None_is_empty_string":
# self.default = ""
# elif type == "None_is_float_zero":
# self.default = 0.0
# elif type == "None_is_int_zero":
# self.default = 0
# elif type == "str":
# self.default = ""
# elif type == "layer_string":
# self.default = "Top"
# elif type == "int":
# self.default = 0
# elif type == "float":
# self.default = 0.0
# elif type == "bool" or type == "constant_bool":
# self.default = True
self.default = default
#assert self.xmlName is not None
# print "Is " + str(self.name) + " == " + str(self.xmlName) +"?"
if lookupEFP is None:
self.lookupEFP = None
else:
self.lookupEFP = lookupEFP
if vtype is None:
self.vtype = "str"
else:
self.vtype = vtype
if accessorName is None:
self.accessorName = name
else:
self.accessorName = accessorName
self.required = required
if unparse is None:
self.unparse = "unparseByType"
else:
assert False
self.unparse = unparse
if parse is None:
self.parse = "parseByType"
else:
assert False
self.parse = parse
self.quirks = quirks
def get_literal_default(self):
return repr(self.default)
def initialCap(a):
t = a[0].upper() + a[1:]
return t
def rstClassify(x):
return ":class:`" + x + "`"
class Collection:
"""
Base class for collections.
"""
def __init__(self, name, xpath, accessorName=None, suppressAccessors=False, requireTag=False, containedTypes=None, dontsort=False):
"""Create a class describing an attribute.
:param name: The collection's name. This will be used as the name of the member in the the :code:`EagleFilePart`.
:param xpath: XPath expression that matches all the tags that should be held in this collection.
:param suppressAccessors: If :code:`True`, don't generate accessor functions.
:param requireTag: This the tag for this collection must appear in the output XML. The tag that is inserted are the all-but-last tags of xpath expression. For example if :code:`xpath` is :code:`./foo/bar/baz`, the this will ensure that :code:`./foo/bar` exists.
:param accessorName:This is the string that will appear in Swoop API calls. For example :code:`foo.get_class()`. By default, this is the last tag in the xpath. For example if :code:`xpath` is :code:`foo/bar', the :code:`accessorName` will be :code:`bar`.
:param xmlName: This is string used in the XML representation. For example, :code:`class`.
"""
self.name = name
self.xpath = xpath
if accessorName is None:
self.accessorName = xpath.split("/")[-1]
else:
self.accessorName = accessorName
self.suppressAccessors = suppressAccessors
self.requireTag = requireTag
if containedTypes is None:
self.containedTypes = [self.accessorName]
else:
self.containedTypes = containedTypes
def get_contained_type_list_doc_string(self, conjunction="or"):
if len(self.containedTypes) == 1:
return rstClassify(initialCap(self.containedTypes[0]))
else:
return ", ".join(map(rstClassify , map(initialCap,self.containedTypes[0:-1]))) + " " + conjunction + " " + rstClassify(initialCap(self.containedTypes[-1]))
def get_contained_type_list_string(self, conjunction="or"):
if len(self.containedTypes) == 1:
return initialCap(self.containedTypes[0])
else:
return ", ".join(map(initialCap,self.containedTypes[0:-1])) + " " + conjunction + " " + initialCap(self.containedTypes[-1])
def get_contained_type_list(self):
return map(initialCap,self.containedTypes)
class Map(Collection):
"""
Collection that maps strings to items
"""
def __init__(self, name, xpath, accessorName=None, suppressAccessors=False, requireTag=False, mapkey=None, containedTypes=None):
"""Create a Map object.
See the documentation for :class:`Collection` for the parameters. There is one additional parameter:
:param mapkey: This is the attribute of the contained elements that will be used as the index in the map.
"""
Collection.__init__(self,name, xpath, accessorName, suppressAccessors, requireTag, containedTypes)
self.type = "Map"
if mapkey is None:
self.mapkey = "name"
else:
self.mapkey = mapkey
class List(Collection):
"""
Collection that is an ordered list
"""
def __init__(self, name, xpath, accessorName=None, suppressAccessors=False, requireTag=False, containedTypes=None):
"""Create a List object.
See the documentation for :class:`Collection` for the parameters.
"""
Collection.__init__(self,name, xpath, accessorName,suppressAccessors, requireTag, containedTypes)
self.type = "List"
class AttrList(Collection):
"""
Collection that is an ordered list but is stored as a whitespace-separeted attribute value.
"""
def __init__(self, name, attr, accessorName):
"""Create a List object.
See the documentation for :class:`Collection` for the parameters.
"""
Collection.__init__(self, name, "", accessorName, False, False, str)
self.attr = attr
self.type = "AttrList"
def get_contained_type_list_doc_string(self, conjunction="or"):
return "str"
def get_contained_type_list_string(self, conjunction="or"):
return "str"
def get_contained_type_list(self):
assert False
class Singleton(Collection):
"""
Collection with a single element
"""
def __init__(self, name, xpath, accessorName=None, suppressAccessors=False, requireTag=False,containedTypes=None):
"""Create a Singleton object.
See the documentation for :class:`Collection` for the parameters.
"""
Collection.__init__(self,name, xpath, accessorName, suppressAccessors, requireTag, containedTypes)
self.type = "Singleton"
class TagClass:
"""
Everything we need to know about an object that can hold the contents of a tag in order ot generate the classes for accessing it.
"""
def __init__(self,
tag,
baseclass=None,
mixins=None,
classname=None,
customchild=False,
preserveTextAs=None,
attrs=None,
sections=None,
sortattr=None,
dontsort=False
):
"""
:param tag: The name of the tag this class is for.
:param baseclass: The base class to inherit from.
:param customchild: We will define a child class to implement extra functions, so name the class ``Base_tag`` instead of ``tag``
:param preserveTextAs: Preserve the text content of the tag in a variable with this name.
:param attrs: A list of :class:`Attr` objects specifying attributes for the class.
:param sections: A list of :class:`List`, :class:`Map`, and :class:`Singleton` objects that this class should contain.
:param dontsort: Don't sort these elements in collections (i.e., order matters)
"""
if sections is None:
self.sections = []
else:
self.sections = sections
if mixins is None:
self.mixins = []
else:
self.mixins = mixins
self.dontsort = dontsort
self.tag = tag
self.attrs = attrs
self.sortattr = sortattr
self.lists = []
self.maps = []
self.attrLists= []
self.baseclass = baseclass
if classname is None:
self.classname = self.get_tag_initial_cap()
else:
self.classname = classname
self.customchild = customchild
self.maps = [m for m in self.sections if isinstance(m, Map)]
self.lists = [l for l in self.sections if isinstance(l, List)]
self.attrLists = [l for l in self.sections if isinstance(l, AttrList)]
self.singletons = [s for s in self.sections if isinstance(s, Singleton)]
if preserveTextAs is None:
self.preserveTextAs = ""
else:
self.preserveTextAs = preserveTextAs
self.hasCollections = (len(self.maps) + len(self.lists) + len(self.singletons) > 0)
def get_all_base_classes_as_str(self):
return ", ".join([self.baseclass] + self.mixins)
def get_all_base_classes_as_list(self):
return [self.baseclass] + self.mixins
def get_attr_names(self):
return [x for x in self.attrs]
def get_list_names(self):
return [x.name for x in self.lists]
def get_map_names(self):
return [x.name for x in self.maps]
def get_tag_initial_cap(self):
return initialCap(self.tag)
def has_maps(self):
return len(self.maps) > 0
tags = {}
def layerAttr(required=True):
return Attr(name="layer",
vtype="layer_string",
required=required)
def dimensionAttr(name, required):
return Attr(name, vtype="float", required=required)
def widthAttr(required):
return dimensionAttr("width", required)
def drillAttr(required):
return dimensionAttr("drill", required)
def extwidthAttr(required):
return dimensionAttr("extwidth", required)
def extlengthAttr(required):
return dimensionAttr("extlength", required)
def extoffsetAttr(required):
return dimensionAttr("extoffset", required)
def textsizeAttr(required):
return dimensionAttr("textsize", required)
def sizeAttr(required):
return dimensionAttr("size", required)
def diameterAttr(required):
return dimensionAttr("diameter", required)
def spacingAttr(required):
return dimensionAttr("spacing", required)
def isolateAttr(required):
return dimensionAttr("isolate", required)
def locally_modifiedAttr():
return Attr("locally_modified", required=False, default="no", vtype="bool")
def library_locally_modifiedAttr():
return Attr("library_locally_modified", required=False, default="no", vtype="bool")
def library_versionAttr():
return Attr("library_version", required=False, vtype="int")
def urnAttr(s="urn"):
return Attr(s, vtype="str", required=False)
rotAttr = Attr("rot",
vtype="str",
required=False)
def nameAttr(isKey=True):
return Attr("name",
vtype="str",
required=True,
isKey=isKey)
smashedAttr = Attr("smashed", required=False)
tags["note"] = TagClass("note",
baseclass = "EagleFilePart",
preserveTextAs = "text",
attrs=[Attr("minversion",
required=True),
Attr("version",
required=True),
Attr("severity", required=True)])
tags["library"] = TagClass("library",
baseclass = "EagleFilePart",
attrs=[
Attr("name", required=False, supress_in_lib_file=True),
urnAttr(),
],
sections=[Singleton("description", "./description", requireTag=False),
Map("packages", "./packages/package", requireTag=True),
Map("packages3d", "./packages3d/package3d", requireTag=False),
Map("symbols", "./symbols/symbol" , requireTag=True),
Map("devicesets", "./devicesets/deviceset", requireTag=True)])
tags["schematic"] = TagClass("schematic",
baseclass = "EagleFilePart",
attrs=[Attr("xreflabel", required=False),
Attr("xrefpart", required=False)])
tags["module"] = TagClass("module",
baseclass = "EagleFilePart",
mixins=["DimensionGeometry"],
attrs=[nameAttr(),
Attr("prefix", required=False),
dimensionAttr("dx",True),
dimensionAttr("dy",True)],
sections=[Singleton("description", "./description", requireTag=True),
Map("ports", "./ports/port", requireTag=True),
Map("variantdefs", "./variantdefs/variantdef", requireTag=True),
Map("parts", "./parts/part", requireTag=True),
List("sheets", "./sheets/sheet")])
tags["package"] = TagClass("package",
baseclass = "EagleFilePart",
attrs=[
nameAttr(),
urnAttr(),
locally_modifiedAttr(),
library_versionAttr(),
library_locally_modifiedAttr()
],
sections=[Singleton("description", "./description", requireTag=True),
List("drawing_elements","./polygon|./wire|./text|./dimension|./circle|./rectangle|./hole|./frame",
containedTypes=["polygon","wire","text","dimension","circle","rectangle","hole", "frame"],
accessorName="drawing_element"),
Map("pads", "./pad"),
Map("smds", "./smd")])
tags["package3d"] = TagClass("package3d",
baseclass = "EagleFilePart",
attrs=[
nameAttr(),
urnAttr(),
Attr("type", vtype="str", required=True),
locally_modifiedAttr(),
library_versionAttr(),
library_locally_modifiedAttr()
],
sections=[
Singleton("description", "./description", requireTag=True),
List("packageinstances", "./packageinstances/packageinstance", requireTag=False)
])
tags["packageinstance"] = TagClass("packageinstance",
baseclass = "EagleFilePart",
attrs=[nameAttr()])
tags["package3dinstance"] = TagClass("package3dinstance",
baseclass = "EagleFilePart",
attrs=[urnAttr("package3d_urn")])
tags["symbol"] = TagClass("symbol",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
urnAttr(),
locally_modifiedAttr(),
library_versionAttr(),
library_locally_modifiedAttr()
],
sections=[Singleton("description", "./description", requireTag=True),
List("drawing_elements","./polygon|./wire|./text|./dimension|./circle|./rectangle|./frame|./hole",
containedTypes=["polygon","wire","text","dimension","circle","rectangle","hole","frame"],
accessorName="drawing_element"),
Map("pins", "./pin")])
tags["deviceset"] = TagClass("deviceset",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
Attr("prefix", required=False),
Attr("uservalue",
vtype="bool",
required=False),
urnAttr(),
locally_modifiedAttr(),
library_versionAttr(),
library_locally_modifiedAttr()
],
sections=[Singleton("description", "./description", requireTag=True),
Map("gates", "./gates/gate", requireTag=True),
Map("devices", "./devices/device", requireTag=True)])
tags["device"] = TagClass("device",
baseclass = "EagleFilePart",
attrs=[Attr("name",
required=True,
vtype="str"),
Attr("package",
required=False,
#vtype="None_is_default_string",
lookupEFP=("Package", "lambda efp, key: efp.get_parent().get_parent().get_package(key)"))],
sections=[List("connects", "./connects/connect"),
List("package3dinstances", "./package3dinstances/package3dinstance"),
Map("technologies", "./technologies/technology")])
tags["bus"] = TagClass("bus",
baseclass = "EagleFilePart",
attrs=[nameAttr()],
sections = [List("segments", "./segment")])
tags["net"] = TagClass("net",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
Attr("netclass",
accessorName = "class",
xmlName="class",
required=False)],
sections = [List("segments", "./segment")])
tags["signal"] = TagClass("signal",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
Attr("netclass",
accessorName = "class",
xmlName="class",
required=False,
lookupEFP=("Class", "lambda efp, key: NotImplemented('class lookup from signal not implemented')")),
Attr("airwireshidden",
vtype="bool",
required=False)],
sections = [List("contactrefs", "./contactref"),
List("polygons", "./polygon"),
List("wires", "./wire"),
List("vias", "./via")])
tags["moduleinst"] = TagClass("moduleinst",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "RotationGeometry"],
attrs=[nameAttr(),
Attr("module",
required=True,
lookupEFP=("Module","lambda efp, key: NotImplemented('Module lookup not implemented')")),
Attr("modulevariant", required=False),
dimensionAttr("x",True),
dimensionAttr("y",True),
Attr("offset",
vtype="int",
required=False),
smashedAttr,
rotAttr],
sections=[
Map("attributes", "./attribute")
])
tags["variantdef"] = TagClass("variantdef",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
Attr("current",
vtype="bool",
required=False)])
tags["variant"] = TagClass("variant",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
Attr("populate",
vtype="bool",
required=False),
Attr("value",
required=False),
Attr("technology",
required=True)])
tags["gate"] = TagClass("gate",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry"],
attrs=[nameAttr(),
Attr("symbol",
required=True,
lookupEFP=("Symbol", "lambda efp, key: efp.get_parent().get_parent().get_symbol(key)")),
dimensionAttr("x",True),
dimensionAttr("y",True),
Attr("addlevel", required=False),
Attr("swaplevel",
vtype="int",
required=False)])
tags["wire"] = TagClass("wire",
baseclass = "EagleFilePart",
mixins=["LineGeometry"],
attrs=[dimensionAttr("x1", required=True),
dimensionAttr("y1", required=True),
dimensionAttr("x2", required=True),
dimensionAttr("y2", required=True),
widthAttr(required=True),
layerAttr(required=True),
Attr("extent", required=False),
Attr("style", required=False),
Attr("curve",
vtype="None_is_default_float",
default=0.0,
required=False),
Attr("cap", required=False)])
tags["dimension"] = TagClass("dimension",
baseclass = "EagleFilePart",
mixins=["MeasureGeometry"],
attrs=[dimensionAttr("x1", required=True),
dimensionAttr("y1", required=True),
dimensionAttr("x2", required=True),
dimensionAttr("y2", required=True),
dimensionAttr("x3", required=True),
dimensionAttr("y3", required=True),
layerAttr(required=True),
Attr("dtype", required=False),
widthAttr(required=False), # this is in disagreement with the dtd. However, Eagle generates <dimensions> with no width attribute. The default seems to be 0.13mm and if that value is selected, the attribute is omitted.
extwidthAttr(required=False),
extlengthAttr(required=False),
extoffsetAttr(required=False),
textsizeAttr(required=True),
Attr("textratio",
vtype="int",
required=False),
Attr("unit", required=False),
Attr("precision",
vtype="int",
required=False),
Attr("visible",
vtype="bool",
required=False)])
tags["text"] = TagClass("text",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry","RotationGeometry"],
preserveTextAs = "text",
attrs=[dimensionAttr("x",True),
dimensionAttr("y",True),
sizeAttr(required=True),
layerAttr(required=True),
Attr("font",
required=False,
vtype="None_is_default_string",
default="proportional"),
Attr("ratio",
vtype="None_is_default_int",
default=8,
required=False),
rotAttr,
Attr("align",
vtype="None_is_default_string",
default="bottom-left",
required=False),
Attr("distance",
vtype="None_is_default_int",
default=50,
required=False)])
tags["circle"] = TagClass("circle",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "CircleRadiusGeometry"],
attrs=[dimensionAttr("x",required=True),
dimensionAttr("y",required=True),
dimensionAttr("radius", required=True),
widthAttr( required=True),
layerAttr()])
tags["rectangle"] = TagClass("rectangle",
baseclass = "EagleFilePart",
mixins=["RectGeometry", "RotationGeometry"],
attrs=[dimensionAttr("x1", required=True),
dimensionAttr("y1", required=True),
dimensionAttr("x2", required=True),
dimensionAttr("y2", required=True),
layerAttr(required=True),
rotAttr])
tags["frame"] = TagClass("frame",
baseclass = "EagleFilePart",
mixins=["RectGeometry"],
attrs=[dimensionAttr("x1", required=True),
dimensionAttr("y1", required=True),
dimensionAttr("x2", required=True),
dimensionAttr("y2", required=True),
Attr("columns",
vtype="int",
required=True),
Attr("rows",
vtype="int",
required=True),
layerAttr(required=True),
Attr(name="border_left",
accessorName="border_left",
xmlName="border-left",
vtype="bool",
required=False),
Attr(name="border_right",
accessorName="border_right",
xmlName="border-right",
vtype="bool",
required=False),
Attr(name="border_top",
accessorName="border_top",
xmlName="border-top",
vtype="bool",
required=False),
Attr(name="border_bottom",
accessorName="border_bottom",
xmlName="border-bottom",
vtype="bool",
required=False)])
tags["hole"] = TagClass("hole",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry"],
attrs=[dimensionAttr("x",True),
dimensionAttr("y",True),
drillAttr( required=True)])
tags["pad"] = TagClass("pad",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "CircleDiameterGeometry", "RotationGeometry"],
attrs=[nameAttr(),
dimensionAttr("x",True),
dimensionAttr("y",True),
drillAttr( required=True),
diameterAttr(required=False),
Attr("shape", required=False),
rotAttr,
Attr("stop",
vtype="bool",
required=False),
Attr("thermals",
vtype="bool",
required=False),
Attr("first",
vtype="bool",
required=False)])
tags["smd"] = TagClass("smd",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "DimensionGeometry", "RotationGeometry"],
attrs=[nameAttr(),
dimensionAttr("x",True),
dimensionAttr("y",True),
dimensionAttr("dx",True),
dimensionAttr("dy",True),
layerAttr(required=True),
Attr("roundness",
vtype="int",
required=False),
rotAttr,
Attr("stop",
vtype="bool",
required=False),
Attr("thermals",
vtype="bool",
required=False),
Attr("cream",
vtype="bool",
required=False)])
tags["element"] = TagClass("element",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "RotationGeometry"],
#customchild = True,
attrs=[nameAttr(),
Attr("library",
required=True,
lookupEFP=("Library", "lambda efp, key: efp.get_parent().get_library(key)")),
urnAttr("library_urn"),
Attr("package",
required=True,
lookupEFP=("Package", "lambda efp, key: efp.find_library().get_package(key)")),
urnAttr("package3d_urn"),
Attr("value",
required=True),
dimensionAttr("x",True),
dimensionAttr("y",True),
Attr("locked",
vtype="locked_bool",
required=False),
Attr("populate",
vtype="bool",
required=False),
smashedAttr,
rotAttr],
# I'm not sure if this should be a Map or a
# List. There's a board in our test suite that
# has two instances of the same attributes. But
# what I generate boards like that myself, Eagle
# throws an error. So it's a map for now.
sections = [List("attributes", "./attribute", requireTag=True)])
tags["via"] = TagClass("via",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "CircleDiameterGeometry"],
attrs=[dimensionAttr("x",True),
dimensionAttr("y",True),
Attr("extent", required=True),
drillAttr( required=True),
diameterAttr(required=False),
Attr("shape", required=False),
Attr("alwaysstop",
vtype="bool",
required=False)])
tags["polygon"] = TagClass("polygon",
baseclass = "EagleFilePart",
attrs=[widthAttr( required=True),
layerAttr(required=True),
spacingAttr(required=False),
Attr("pour", required=False),
isolateAttr(required=False),
Attr("orphans",
vtype="bool",
required=False),
Attr("thermals",
vtype="bool",
required=False),
Attr("rank",
vtype="int",
required=False)],
sections = [List("vertices", "./vertex")])
tags["vertex"] = TagClass("vertex",
dontsort=True,
baseclass = "EagleFilePart",
mixins=["OnePointGeometry"],
attrs=[dimensionAttr("x",True),
dimensionAttr("y",True),
Attr("curve",
vtype="float",
required=False)])
tags["pin"] = TagClass("pin",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "RotationGeometry"],
attrs=[nameAttr(),
dimensionAttr("x",True),
dimensionAttr("y",True),
Attr("visible",
required=False),
Attr("length", required=False),
Attr("direction", required=False),
Attr("function", required=False),
Attr("swaplevel",
vtype="int",
required=False),
rotAttr])
tags["part"] = TagClass("part",
baseclass="EagleFilePart",
customchild=True,
attrs=[nameAttr(),
Attr("library",
lookupEFP=("Library", "lambda efp, key: efp.get_parent().get_library(key)"),
required=True),
urnAttr("library_urn"),
Attr("deviceset",
lookupEFP=("Deviceset", "lambda efp, key: efp.find_library().get_deviceset(key)"),
required=True),
Attr("device",
lookupEFP=("Device", "lambda efp, key: efp.find_deviceset().get_device(key)"),
required=True),
urnAttr("package3d_urn"),
Attr("technology",
lookupEFP=("Technology","lambda efp, key: efp.find_device().get_technology(key)"),
required=False,
vtype="None_is_default_string",
default=""),
Attr("value",
required=False)],
sections=[Map("attributes", "./attribute", requireTag=True),
Map("variants", "./variant")])
tags["port"] = TagClass("port",
baseclass = "EagleFilePart",
attrs=[nameAttr(),
Attr("side",
vtype="int",
required=True),
Attr("dimension", required=True),
Attr("direction", required=False)])
tags["instance"] = TagClass("instance",
customchild=True,
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "RotationGeometry"],
attrs=[Attr("part",
lookupEFP=("Part","lambda efp, key: efp.get_parent().get_parent().get_part(key)"),
required=True),
Attr("gate",
lookupEFP=("Gate", "lambda efp, key: NotImplemented('Lookup of gate from instance not implemented.')"),
required=True),
dimensionAttr("x",True),
dimensionAttr("y",True),
smashedAttr,
rotAttr],
sections= [Map("attributes", "./attribute", requireTag=True)])
tags["label"] = TagClass("label",
baseclass = "EagleFilePart",
mixins=["OnePointGeometry", "RotationGeometry"],
attrs=[dimensionAttr("x",True),
dimensionAttr("y",True),
sizeAttr(required=True),
layerAttr(required=True),
Attr("font", required=False),
Attr("ratio",
vtype="int",
required=False),