|
18 | 18 | import calendar |
19 | 19 | import datetime |
20 | 20 | import re |
21 | | -from dataclasses import dataclass, field |
22 | | -from typing import Optional, List, Dict |
| 21 | +from typing import Dict |
23 | 22 | from os import path |
24 | 23 |
|
25 | 24 | from kiutils.items.zones import Zone |
26 | | -from kiutils.items.common import Image, Position, Coordinate, Net, Group, Font |
| 25 | +from kiutils.items.common import Image, Coordinate, Net, Group, Font |
27 | 26 | from kiutils.items.fpitems import * |
28 | 27 | from kiutils.items.gritems import * |
29 | 28 | from kiutils.utils import sexpr |
30 | 29 | from kiutils.utils.strings import dequote, remove_prefix |
31 | | -from kiutils.misc.config import KIUTILS_CREATE_NEW_VERSION_STR |
| 30 | +from kiutils.misc.config import * |
32 | 31 |
|
33 | 32 | @dataclass |
34 | 33 | class Attributes(): |
@@ -112,7 +111,7 @@ def to_sexpr(self, indent=0, newline=False) -> str: |
112 | 111 | Returns: |
113 | 112 | - str: S-Expression of this object |
114 | 113 | """ |
115 | | - if (self.type == None |
| 114 | + if (self.type is None |
116 | 115 | and self.boardOnly == False |
117 | 116 | and self.excludeFromBom == False |
118 | 117 | and self.excludeFromPosFiles == False |
@@ -980,32 +979,29 @@ def create_new(cls, library_id: str, value: str, |
980 | 979 | if type not in ['smd', 'through_hole', 'other']: |
981 | 980 | raise Exception("Unsupported type was given") |
982 | 981 |
|
983 | | - fp = cls( |
984 | | - version = KIUTILS_CREATE_NEW_VERSION_STR, |
985 | | - generator = 'kiutils' |
986 | | - ) |
| 982 | + fp = Footprint() |
| 983 | + fp.version = KIUTILS_CREATE_NEW_VERSION_STR |
| 984 | + fp.generator = KIUTILS_CREATE_NEW_GENERATOR_STR |
| 985 | + fp.generator_version = KIUTILS_CREATE_NEW_GENERATOR_VERSION_STR |
987 | 986 | fp.libId = library_id |
988 | 987 |
|
989 | 988 | # Create text items that are created when adding a new footprint to a library |
990 | | - # TODO - In v9 these are not FpTexts anymore but rather Properties |
991 | | - fp.graphicItems.extend( |
992 | | - [ |
993 | | - FpText( |
994 | | - type = 'reference', text = reference, layer = 'F.SilkS', |
995 | | - effects = Effects(font=Font(thickness=0.15)), |
996 | | - position = Position(X=0, Y=-0.5, unlocked=True) |
997 | | - ), |
998 | | - FpText( |
999 | | - type = 'value', text = value, layer ='F.Fab', |
1000 | | - effects = Effects(font=Font(thickness=0.15)), |
1001 | | - position = Position(X=0, Y=1, unlocked=True) |
1002 | | - ), |
1003 | | - FpText( |
1004 | | - type = 'user', text = '${REFERENCE}', layer = 'F.Fab', |
1005 | | - effects = Effects(font=Font(thickness=0.15)), |
1006 | | - position = Position(X=0, Y=2.5, unlocked=True) |
1007 | | - ) |
1008 | | - ] |
| 989 | + fp.properties['Reference'] = FpProperty( |
| 990 | + type='Reference', text=reference, layer='F.SilkS', |
| 991 | + effects=Effects(font=Font(thickness=0.15)), |
| 992 | + at=Position(X=0, Y=-0.5, unlocked=True) |
| 993 | + ), |
| 994 | + fp.properties['Value'] = FpProperty( |
| 995 | + type='Value', text=value, layer='F.Fab', |
| 996 | + effects=Effects(font=Font(thickness=0.15)), |
| 997 | + at=Position(X=0, Y=1, unlocked=True) |
| 998 | + ), |
| 999 | + fp.graphicItems.append( |
| 1000 | + FpText( |
| 1001 | + type = 'user', text = '${REFERENCE}', layer = 'F.Fab', |
| 1002 | + effects = Effects(font=Font(thickness=0.15)), |
| 1003 | + position = Position(X=0, Y=2.5, unlocked=True) |
| 1004 | + ) |
1009 | 1005 | ) |
1010 | 1006 |
|
1011 | 1007 | # The type ``other`` does not set the attributes type token |
@@ -1053,7 +1049,7 @@ def to_sexpr(self, indent=0, newline=True, layerInFirstLine=False) -> str: |
1053 | 1049 | placed = f' (placed yes)' if self.placed else '' |
1054 | 1050 | version = f' (version {self.version})' if self.version is not None else '' |
1055 | 1051 | generator = f' (generator {self.generator})' if self.generator is not None else '' |
1056 | | - generator_version = f' (generator_version "{self.generator_version}")' if self.generator_version is not None else '' |
| 1052 | + generator_version = f' (generator_version "{self.generator_version}")' |
1057 | 1053 | tstamp = f' (uuid "{self.tstamp}")' if self.tstamp is not None else '' |
1058 | 1054 |
|
1059 | 1055 | expression = f'{indents}(footprint "{dequote(self.libId)}"{locked}{placed}{version}{generator}{generator_version}{tstamp}' |
|
0 commit comments