033551c78f539fe3afa52f3bb0440ebfe1483501
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py   1) #! /usr/bin/env python3
pcb_footpr_conv/pcbfp2dxf.py   2) 
pcb_footpr_conv/pcbfp2dxf.py   3) import ezdxf
pcb_footpr_conv/pcbfp2dxf.py   4) import re
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py      5) import sys
pcb_footpr_conv/fp2dxf.py      6) 
pcb_footpr_conv/fp2dxf.py      7) 
pcb_footpr_conv/fp2dxf.py      8) class ParseError(Exception):
pcb_footpr_conv/fp2dxf.py      9)     def __init__(self, msg: str, pos: str):
pcb_footpr_conv/fp2dxf.py     10)         super().__init__(self, msg, pos)
pcb_footpr_conv/fp2dxf.py     11)         self.msg = msg
pcb_footpr_conv/fp2dxf.py     12)         self.pos = pos
pcb_footpr_conv/fp2dxf.py     13) 
pcb_footpr_conv/fp2dxf.py     14)     def __repr__(self) -> str:
pcb_footpr_conv/fp2dxf.py     15)         return f'ParseError({repr(self.msg):s}, {repr(self.pos):s})'
pcb_footpr_conv/fp2dxf.py     16) 
pcb_footpr_conv/fp2dxf.py     17)     def __str__(self) -> str:
pcb_footpr_conv/fp2dxf.py     18)         return f'ParseError: {self.msg:s} at {self.pos:s}'
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py  19) 
pcb_footpr_conv/pcbfp2dxf.py  20) 
pcb_footpr_conv/pcbfp2dxf.py  21) class StringBuffer:
pcb_footpr_conv/pcbfp2dxf.py  22)     """
pcb_footpr_conv/pcbfp2dxf.py  23)     Store a string, an index and provide some operations.
pcb_footpr_conv/pcbfp2dxf.py  24)     """
pcb_footpr_conv/pcbfp2dxf.py  25) 
pcb_footpr_conv/pcbfp2dxf.py  26)     def __init__(self, string: str):
pcb_footpr_conv/pcbfp2dxf.py  27)         self._string = string
pcb_footpr_conv/pcbfp2dxf.py  28)         self._index = 0
pcb_footpr_conv/pcbfp2dxf.py  29)         self._stack = []
pcb_footpr_conv/pcbfp2dxf.py  30) 
pcb_footpr_conv/pcbfp2dxf.py  31)     def __enter__(self):
pcb_footpr_conv/pcbfp2dxf.py  32)         self.enter()
pcb_footpr_conv/pcbfp2dxf.py  33)         return self
pcb_footpr_conv/pcbfp2dxf.py  34) 
pcb_footpr_conv/pcbfp2dxf.py  35)     def __exit__(self, exc_type, _exc_value, _traceback):
pcb_footpr_conv/pcbfp2dxf.py  36)         if exc_type is None:
pcb_footpr_conv/pcbfp2dxf.py  37)             self.complete()
pcb_footpr_conv/pcbfp2dxf.py  38)         else:
pcb_footpr_conv/pcbfp2dxf.py  39)             self.backtrack()
pcb_footpr_conv/pcbfp2dxf.py  40) 
pcb_footpr_conv/pcbfp2dxf.py  41)     def advance(self, length: int):
pcb_footpr_conv/pcbfp2dxf.py  42)         """
pcb_footpr_conv/pcbfp2dxf.py  43)         Advance the index by length.
pcb_footpr_conv/pcbfp2dxf.py  44)         """
pcb_footpr_conv/pcbfp2dxf.py  45)         self._index = min(len(self._string), self._index + length)
pcb_footpr_conv/pcbfp2dxf.py  46) 
pcb_footpr_conv/pcbfp2dxf.py  47)     def backtrack(self):
pcb_footpr_conv/pcbfp2dxf.py  48)         """
pcb_footpr_conv/pcbfp2dxf.py  49)         Track back from parsing something.
pcb_footpr_conv/pcbfp2dxf.py  50)         Pop index from stack and use it as the new current index.
pcb_footpr_conv/pcbfp2dxf.py  51)         """
pcb_footpr_conv/pcbfp2dxf.py  52)         self._index = self._stack[-1]
pcb_footpr_conv/pcbfp2dxf.py  53)         del self._stack[-1]
pcb_footpr_conv/pcbfp2dxf.py  54) 
pcb_footpr_conv/pcbfp2dxf.py  55)     def check(self, s: str) -> bool:
pcb_footpr_conv/pcbfp2dxf.py  56)         """
pcb_footpr_conv/pcbfp2dxf.py  57)         Check if string s follows index.
pcb_footpr_conv/pcbfp2dxf.py  58)         If so, advance by length of s and return True
pcb_footpr_conv/pcbfp2dxf.py  59)         Otherwise, keep index and return False.
pcb_footpr_conv/pcbfp2dxf.py  60)         """
pcb_footpr_conv/pcbfp2dxf.py  61)         if self.peek(len(s)) == s:
pcb_footpr_conv/pcbfp2dxf.py  62)             self.advance(len(s))
pcb_footpr_conv/pcbfp2dxf.py  63)             return True
pcb_footpr_conv/pcbfp2dxf.py  64)         return False
pcb_footpr_conv/pcbfp2dxf.py  65) 
pcb_footpr_conv/pcbfp2dxf.py  66)     def complete(self):
pcb_footpr_conv/pcbfp2dxf.py  67)         """
pcb_footpr_conv/pcbfp2dxf.py  68)         Complete parsing something.
pcb_footpr_conv/pcbfp2dxf.py  69)         Pop index from stack and throw it away.
pcb_footpr_conv/pcbfp2dxf.py  70)         """
pcb_footpr_conv/pcbfp2dxf.py  71)         del self._stack[-1]
pcb_footpr_conv/pcbfp2dxf.py  72) 
pcb_footpr_conv/pcbfp2dxf.py  73)     def enter(self):
pcb_footpr_conv/pcbfp2dxf.py  74)         """
pcb_footpr_conv/pcbfp2dxf.py  75)         Enter parsing something.
pcb_footpr_conv/pcbfp2dxf.py  76)         Push current index onto stack.
pcb_footpr_conv/pcbfp2dxf.py  77)         """
pcb_footpr_conv/pcbfp2dxf.py  78)         self._stack.append(self._index)
pcb_footpr_conv/pcbfp2dxf.py  79) 
pcb_footpr_conv/pcbfp2dxf.py  80)     def expect(self, s: str):
pcb_footpr_conv/pcbfp2dxf.py  81)         """
pcb_footpr_conv/pcbfp2dxf.py  82)         Check that string s follows index.
pcb_footpr_conv/pcbfp2dxf.py  83)         If so, advance.
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py     84)         If not, throw ParseError.
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py  85)         """
pcb_footpr_conv/pcbfp2dxf.py  86)         if not self.check(s):
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py     87)             raise ParseError(f'expected {repr(s):s}', self.pos())
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py  88) 
pcb_footpr_conv/pcbfp2dxf.py  89)     def get(self, length: int) -> str:
pcb_footpr_conv/pcbfp2dxf.py  90)         """
pcb_footpr_conv/pcbfp2dxf.py  91)         Return the next length characters and advance the index.
pcb_footpr_conv/pcbfp2dxf.py  92)         """
pcb_footpr_conv/pcbfp2dxf.py  93)         s = self.peek(length)
pcb_footpr_conv/pcbfp2dxf.py  94)         self.advance(length)
pcb_footpr_conv/pcbfp2dxf.py  95)         return s
pcb_footpr_conv/pcbfp2dxf.py  96) 
pcb_footpr_conv/pcbfp2dxf.py  97)     def getRe(self, ptrn: re.Pattern):
pcb_footpr_conv/pcbfp2dxf.py  98)         """
pcb_footpr_conv/pcbfp2dxf.py  99)         Return the matching the regular expression pattern and advance
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    100)         index or throw ParseError.
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 101)         """
pcb_footpr_conv/pcbfp2dxf.py 102)         m = ptrn.match(self._string[self._index:])
pcb_footpr_conv/pcbfp2dxf.py 103)         if not m:
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    104)             raise ParseError(f'expected pattern {repr(ptrn.pattern):s}',
pcb_footpr_conv/fp2dxf.py    105)                              self.pos())
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 106)         self._index += len(m.group(0))
pcb_footpr_conv/pcbfp2dxf.py 107)         return m
pcb_footpr_conv/pcbfp2dxf.py 108) 
pcb_footpr_conv/pcbfp2dxf.py 109)     def peek(self, length: int) -> str:
pcb_footpr_conv/pcbfp2dxf.py 110)         """
pcb_footpr_conv/pcbfp2dxf.py 111)         Return the next length characters without advancing the index.
pcb_footpr_conv/pcbfp2dxf.py 112)         """
pcb_footpr_conv/pcbfp2dxf.py 113)         return self._string[self._index:self._index + length]
pcb_footpr_conv/pcbfp2dxf.py 114) 
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    115)     def pos(self) -> str:
pcb_footpr_conv/fp2dxf.py    116)         """
pcb_footpr_conv/fp2dxf.py    117)         Get string describing current position.
pcb_footpr_conv/fp2dxf.py    118)         """
pcb_footpr_conv/fp2dxf.py    119)         before = self._string[:self._index].split('\n')
pcb_footpr_conv/fp2dxf.py    120)         after = self._string[self._index:].split('\n')
pcb_footpr_conv/fp2dxf.py    121)         line_no = len(before)
pcb_footpr_conv/fp2dxf.py    122)         column_no = len(before[-1]) + 1
pcb_footpr_conv/fp2dxf.py    123)         rest = after[0]
pcb_footpr_conv/fp2dxf.py    124)         return f'line {line_no:d} column {column_no:d} {repr(rest):s}'
pcb_footpr_conv/fp2dxf.py    125) 
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 126) 
pcb_footpr_conv/pcbfp2dxf.py 127) class PcbBaseParser(StringBuffer):
pcb_footpr_conv/pcbfp2dxf.py 128)     """
pcb_footpr_conv/pcbfp2dxf.py 129)     Parser for the basic element of GNU PCB files.
pcb_footpr_conv/pcbfp2dxf.py 130)     """
pcb_footpr_conv/pcbfp2dxf.py 131) 
pcb_footpr_conv/pcbfp2dxf.py 132)     re_float = re.compile(r'^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)'
pcb_footpr_conv/pcbfp2dxf.py 133)                           r'(?:[]eE[+-]?[0-9]\+)?')
pcb_footpr_conv/pcbfp2dxf.py 134)     re_int = re.compile(r'^[+-]?[0-9]+')
pcb_footpr_conv/pcbfp2dxf.py 135)     re_quoted = re.compile(r'^"([^"]*)"')
pcb_footpr_conv/pcbfp2dxf.py 136)     re_space = re.compile(r'^\s+', re.MULTILINE)
pcb_footpr_conv/pcbfp2dxf.py 137)     re_space_opt = re.compile(r'^\s*', re.MULTILINE)
pcb_footpr_conv/pcbfp2dxf.py 138) 
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    139)     known_string_flags = set([
pcb_footpr_conv/fp2dxf.py    140)         'edge2', 'hole', 'nopaste', 'octagon', 'onsolder', 'pin', 'showname',
pcb_footpr_conv/fp2dxf.py    141)         'square', 'via'
pcb_footpr_conv/fp2dxf.py    142)     ])
pcb_footpr_conv/fp2dxf.py    143) 
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 144)     def parseCoord(self) -> float:
pcb_footpr_conv/pcbfp2dxf.py 145)         """
pcb_footpr_conv/pcbfp2dxf.py 146)         Parse a coordinate.
pcb_footpr_conv/pcbfp2dxf.py 147)         """
pcb_footpr_conv/pcbfp2dxf.py 148)         with self:
pcb_footpr_conv/pcbfp2dxf.py 149)             f = self.parseFloat()
pcb_footpr_conv/pcbfp2dxf.py 150)             if self.check('mil'):
pcb_footpr_conv/pcbfp2dxf.py 151)                 f *= 100  # native unit == .01mil
pcb_footpr_conv/pcbfp2dxf.py 152)             elif self.check('mm'):
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    153)                 f *= 1e5 / 25.4  # 25.4mm == 1inch == 1e5 * .01mil
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 154)             return f
pcb_footpr_conv/pcbfp2dxf.py 155) 
pcb_footpr_conv/pcbfp2dxf.py 156)     def parseFloat(self) -> float:
pcb_footpr_conv/pcbfp2dxf.py 157)         """
pcb_footpr_conv/pcbfp2dxf.py 158)         Parse a floating point value.
pcb_footpr_conv/pcbfp2dxf.py 159)         """
pcb_footpr_conv/pcbfp2dxf.py 160)         with self:
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    161)             s = self.getRe(self.re_float).group(0)
pcb_footpr_conv/fp2dxf.py    162)             try:
pcb_footpr_conv/fp2dxf.py    163)                 return float(s)
pcb_footpr_conv/fp2dxf.py    164)             except ValueError as exc:
pcb_footpr_conv/fp2dxf.py    165)                 raise ParseError(f'invalid floating point value {repr(s):s}',
pcb_footpr_conv/fp2dxf.py    166)                                  self.pos())
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 167) 
pcb_footpr_conv/pcbfp2dxf.py 168)     def parseInt(self) -> int:
pcb_footpr_conv/pcbfp2dxf.py 169)         """
pcb_footpr_conv/pcbfp2dxf.py 170)         Parse a decimal integer.
pcb_footpr_conv/pcbfp2dxf.py 171)         """
pcb_footpr_conv/pcbfp2dxf.py 172)         with self:
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    173)             s = self.getRe(self.re_int).group(0)
pcb_footpr_conv/fp2dxf.py    174)             try:
pcb_footpr_conv/fp2dxf.py    175)                 return int(s)
pcb_footpr_conv/fp2dxf.py    176)             except ValueError as exc:
pcb_footpr_conv/fp2dxf.py    177)                 raise ParseError('invalid integer value {repr(s):s}',
pcb_footpr_conv/fp2dxf.py    178)                                  self.pos())
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 179) 
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    180)     def parseQuoted(self) -> str:
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 181)         """
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    182)         Parse a quoted string.
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 183)         """
pcb_footpr_conv/pcbfp2dxf.py 184)         with self:
pcb_footpr_conv/pcbfp2dxf.py 185)             return self.getRe(self.re_quoted).group(1)
pcb_footpr_conv/pcbfp2dxf.py 186) 
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    187)     def parseStringFlags(self) -> list:
pcb_footpr_conv/fp2dxf.py    188)         """
pcb_footpr_conv/fp2dxf.py    189)         Parse string flags.
pcb_footpr_conv/fp2dxf.py    190)         """
pcb_footpr_conv/fp2dxf.py    191)         with self:
pcb_footpr_conv/fp2dxf.py    192)             q = self.parseQuoted()
pcb_footpr_conv/fp2dxf.py    193)             fs = set(q.split(','))
pcb_footpr_conv/fp2dxf.py    194)             fs -= {''}
pcb_footpr_conv/fp2dxf.py    195)             unk = fs - self.known_string_flags
pcb_footpr_conv/fp2dxf.py    196)             if unk:
pcb_footpr_conv/fp2dxf.py    197)                 unknown = ','.join(sorted(unk))
pcb_footpr_conv/fp2dxf.py    198)                 raise ParseError(f'unknown string flags {unknown:s}',
pcb_footpr_conv/fp2dxf.py    199)                                  self.pos())
pcb_footpr_conv/fp2dxf.py    200)             return sorted(fs)
pcb_footpr_conv/fp2dxf.py    201) 
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 202)     def parseSpace(self):
pcb_footpr_conv/pcbfp2dxf.py 203)         """
pcb_footpr_conv/pcbfp2dxf.py 204)         Parse at least one whitespace character or more.
pcb_footpr_conv/pcbfp2dxf.py 205)         """
pcb_footpr_conv/pcbfp2dxf.py 206)         with self:
pcb_footpr_conv/pcbfp2dxf.py 207)             self.getRe(self.re_space)
pcb_footpr_conv/pcbfp2dxf.py 208) 
pcb_footpr_conv/pcbfp2dxf.py 209)     def parseSpaceOpt(self):
pcb_footpr_conv/pcbfp2dxf.py 210)         """
pcb_footpr_conv/pcbfp2dxf.py 211)         Parse any number of whitespace characters.
pcb_footpr_conv/pcbfp2dxf.py 212)         """
pcb_footpr_conv/pcbfp2dxf.py 213)         with self:
pcb_footpr_conv/pcbfp2dxf.py 214)             self.getRe(self.re_space_opt)
pcb_footpr_conv/pcbfp2dxf.py 215) 
pcb_footpr_conv/pcbfp2dxf.py 216) 
pcb_footpr_conv/pcbfp2dxf.py 217) class PcbFootprintParser(PcbBaseParser):
pcb_footpr_conv/pcbfp2dxf.py 218)     """
pcb_footpr_conv/pcbfp2dxf.py 219)     Parser for a GNU PCB footprint file.
pcb_footpr_conv/pcbfp2dxf.py 220)     """
pcb_footpr_conv/pcbfp2dxf.py 221) 
pcb_footpr_conv/pcbfp2dxf.py 222)     def parseBody(self, contents: list):
pcb_footpr_conv/pcbfp2dxf.py 223)         """
pcb_footpr_conv/pcbfp2dxf.py 224)         Parse a body of a block.
pcb_footpr_conv/pcbfp2dxf.py 225)         contents: list of lambdas with options for recursive descent
pcb_footpr_conv/pcbfp2dxf.py 226)         """
pcb_footpr_conv/pcbfp2dxf.py 227)         with self:
pcb_footpr_conv/pcbfp2dxf.py 228)             self.parseOpen()
pcb_footpr_conv/pcbfp2dxf.py 229)             while True:
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    230)                 excs = []  # collect parse errors
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 231)                 # end of body
pcb_footpr_conv/pcbfp2dxf.py 232)                 try:
pcb_footpr_conv/pcbfp2dxf.py 233)                     self.parseClose()
pcb_footpr_conv/pcbfp2dxf.py 234)                     break
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    235)                 except ParseError as exc:
pcb_footpr_conv/fp2dxf.py    236)                     excs.append(exc)
pcb_footpr_conv/fp2dxf.py    237)                     # not end of body, try options
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 238)                 # try options
pcb_footpr_conv/pcbfp2dxf.py 239)                 for c in contents:
pcb_footpr_conv/pcbfp2dxf.py 240)                     try:
pcb_footpr_conv/pcbfp2dxf.py 241)                         c()
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    242)                         # option succeded, go to next content
pcb_footpr_conv/fp2dxf.py    243)                         break
pcb_footpr_conv/fp2dxf.py    244)                     except ParseError as exc:
pcb_footpr_conv/fp2dxf.py    245)                         # an option failed, try next option
pcb_footpr_conv/fp2dxf.py    246)                         excs.append(exc)
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 247)                 # all options failed
pcb_footpr_conv/pcbfp2dxf.py 248)                 else:
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    249)                     raise ParseError(
pcb_footpr_conv/fp2dxf.py    250)                         'invalid syntax, all options failed: ' +
pcb_footpr_conv/fp2dxf.py    251)                         ', '.join([exc.msg for exc in excs]), self.pos())
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 252) 
pcb_footpr_conv/pcbfp2dxf.py 253)     def parseClose(self):
pcb_footpr_conv/pcbfp2dxf.py 254)         """
pcb_footpr_conv/pcbfp2dxf.py 255)         Parse a closing parenthesis.
pcb_footpr_conv/pcbfp2dxf.py 256)         """
pcb_footpr_conv/pcbfp2dxf.py 257)         with self:
pcb_footpr_conv/pcbfp2dxf.py 258)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 259)             self.expect(')')
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    260)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    261) 
pcb_footpr_conv/fp2dxf.py    262)     def parseElementArcClause(self):
pcb_footpr_conv/fp2dxf.py    263)         """
pcb_footpr_conv/fp2dxf.py    264)         Parse a GNU PCB element arc clause.
pcb_footpr_conv/fp2dxf.py    265)         """
pcb_footpr_conv/fp2dxf.py    266)         with self:
pcb_footpr_conv/fp2dxf.py    267)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    268)             self.expect('ElementArc')
pcb_footpr_conv/fp2dxf.py    269)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    270)             self.expect('[')
pcb_footpr_conv/fp2dxf.py    271)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    272)             r_x = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    273)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    274)             r_y = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    275)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    276)             width = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    277)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    278)             height = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    279)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    280)             start_angle = self.parseFloat()
pcb_footpr_conv/fp2dxf.py    281)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    282)             end_angle = self.parseFloat()
pcb_footpr_conv/fp2dxf.py    283)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    284)             thickness = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    285)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    286)             self.expect(']')
pcb_footpr_conv/fp2dxf.py    287)             self.parseSpaceOpt()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 288) 
pcb_footpr_conv/pcbfp2dxf.py 289)     def parseElementBlock(self):
pcb_footpr_conv/pcbfp2dxf.py 290)         """
pcb_footpr_conv/pcbfp2dxf.py 291)         Parse a GNU PCB element block.
pcb_footpr_conv/pcbfp2dxf.py 292)         """
pcb_footpr_conv/pcbfp2dxf.py 293)         with self:
pcb_footpr_conv/pcbfp2dxf.py 294)             self.parseElementClause()
pcb_footpr_conv/pcbfp2dxf.py 295)             self.parseBody([
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    296)                 # parse options
pcb_footpr_conv/fp2dxf.py    297)                 lambda: self.parseElementArcClause(),
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 298)                 lambda: self.parseElementLineClause(),
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    299)                 lambda: self.parsePadClause(),
pcb_footpr_conv/fp2dxf.py    300)                 lambda: self.parsePinClause()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 301)             ])
pcb_footpr_conv/pcbfp2dxf.py 302) 
pcb_footpr_conv/pcbfp2dxf.py 303)     def parseElementClause(self):
pcb_footpr_conv/pcbfp2dxf.py 304)         """
pcb_footpr_conv/pcbfp2dxf.py 305)         Parse a GNU PCB element clause.
pcb_footpr_conv/pcbfp2dxf.py 306)         """
pcb_footpr_conv/pcbfp2dxf.py 307)         with self:
pcb_footpr_conv/pcbfp2dxf.py 308)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 309)             self.expect('Element')
pcb_footpr_conv/pcbfp2dxf.py 310)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 311)             self.expect('[')
pcb_footpr_conv/pcbfp2dxf.py 312)             self.parseSpaceOpt()
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    313)             s_flags = self.parseStringFlags()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 314)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 315)             desc = self.parseQuoted()
pcb_footpr_conv/pcbfp2dxf.py 316)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 317)             name = self.parseQuoted()
pcb_footpr_conv/pcbfp2dxf.py 318)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 319)             value = self.parseQuoted()
pcb_footpr_conv/pcbfp2dxf.py 320)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 321)             m_x = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 322)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 323)             m_y = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 324)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 325)             t_x = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 326)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 327)             t_y = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 328)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 329)             t_dir = self.parseInt()
pcb_footpr_conv/pcbfp2dxf.py 330)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 331)             t_scale = self.parseInt()
pcb_footpr_conv/pcbfp2dxf.py 332)             self.parseSpace()
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    333)             t_s_flags = self.parseStringFlags()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 334)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 335)             self.expect(']')
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    336)             self.parseSpaceOpt()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 337) 
pcb_footpr_conv/pcbfp2dxf.py 338)     def parseElementLineClause(self):
pcb_footpr_conv/pcbfp2dxf.py 339)         """
pcb_footpr_conv/pcbfp2dxf.py 340)         Parse a GNU PCB element line clause.
pcb_footpr_conv/pcbfp2dxf.py 341)         """
pcb_footpr_conv/pcbfp2dxf.py 342)         with self:
pcb_footpr_conv/pcbfp2dxf.py 343)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 344)             self.expect('ElementLine')
pcb_footpr_conv/pcbfp2dxf.py 345)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 346)             self.expect('[')
pcb_footpr_conv/pcbfp2dxf.py 347)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 348)             r_x1 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 349)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 350)             r_y1 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 351)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 352)             r_x2 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 353)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 354)             r_y2 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 355)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 356)             thickness = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 357)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 358)             self.expect(']')
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    359)             self.parseSpaceOpt()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 360) 
pcb_footpr_conv/pcbfp2dxf.py 361)     def parseOpen(self):
pcb_footpr_conv/pcbfp2dxf.py 362)         """
pcb_footpr_conv/pcbfp2dxf.py 363)         Parse an opening parenthesis.
pcb_footpr_conv/pcbfp2dxf.py 364)         """
pcb_footpr_conv/pcbfp2dxf.py 365)         with self:
pcb_footpr_conv/pcbfp2dxf.py 366)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 367)             self.expect('(')
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    368)             self.parseSpaceOpt()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 369) 
pcb_footpr_conv/pcbfp2dxf.py 370)     def parsePadClause(self):
pcb_footpr_conv/pcbfp2dxf.py 371)         """
pcb_footpr_conv/pcbfp2dxf.py 372)         Parse a GNU PCB pad clause.
pcb_footpr_conv/pcbfp2dxf.py 373)         """
pcb_footpr_conv/pcbfp2dxf.py 374)         with self:
pcb_footpr_conv/pcbfp2dxf.py 375)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 376)             self.expect('Pad')
pcb_footpr_conv/pcbfp2dxf.py 377)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 378)             self.expect('[')
pcb_footpr_conv/pcbfp2dxf.py 379)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 380)             r_x1 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 381)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 382)             r_y1 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 383)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 384)             r_x2 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 385)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 386)             r_y2 = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 387)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 388)             thickness = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 389)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 390)             clearance = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 391)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 392)             mask = self.parseCoord()
pcb_footpr_conv/pcbfp2dxf.py 393)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 394)             name = self.parseQuoted()
pcb_footpr_conv/pcbfp2dxf.py 395)             self.parseSpace()
pcb_footpr_conv/pcbfp2dxf.py 396)             number = self.parseQuoted()
pcb_footpr_conv/pcbfp2dxf.py 397)             self.parseSpace()
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    398)             s_flags = self.parseStringFlags()
pcb_footpr_conv/fp2dxf.py    399)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    400)             self.expect(']')
pcb_footpr_conv/fp2dxf.py    401)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    402) 
pcb_footpr_conv/fp2dxf.py    403)     def parsePinClause(self):
pcb_footpr_conv/fp2dxf.py    404)         """
pcb_footpr_conv/fp2dxf.py    405)         Parse a GNU PCB pin clause.
pcb_footpr_conv/fp2dxf.py    406)         """
pcb_footpr_conv/fp2dxf.py    407)         with self:
pcb_footpr_conv/fp2dxf.py    408)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    409)             self.expect('Pin')
pcb_footpr_conv/fp2dxf.py    410)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    411)             self.expect('[')
pcb_footpr_conv/fp2dxf.py    412)             self.parseSpaceOpt()
pcb_footpr_conv/fp2dxf.py    413)             r_x = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    414)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    415)             r_y = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    416)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    417)             thickness = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    418)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    419)             clearance = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    420)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    421)             mask = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    422)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    423)             drill = self.parseCoord()
pcb_footpr_conv/fp2dxf.py    424)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    425)             name = self.parseQuoted()
pcb_footpr_conv/fp2dxf.py    426)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    427)             number = self.parseQuoted()
pcb_footpr_conv/fp2dxf.py    428)             self.parseSpace()
pcb_footpr_conv/fp2dxf.py    429)             s_flags = self.parseStringFlags()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 430)             self.parseSpaceOpt()
pcb_footpr_conv/pcbfp2dxf.py 431)             self.expect(']')
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    432)             self.parseSpaceOpt()
Stefan Schuermans begin of PCB footprint parser

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/pcbfp2dxf.py 433) 
pcb_footpr_conv/pcbfp2dxf.py 434) 
pcb_footpr_conv/pcbfp2dxf.py 435) class PcbFootprint:
pcb_footpr_conv/pcbfp2dxf.py 436)     """
pcb_footpr_conv/pcbfp2dxf.py 437)     A footprint of GNU PCB.
pcb_footpr_conv/pcbfp2dxf.py 438)     """
pcb_footpr_conv/pcbfp2dxf.py 439) 
pcb_footpr_conv/pcbfp2dxf.py 440)     def __init__(self):
pcb_footpr_conv/pcbfp2dxf.py 441)         self.reset()
pcb_footpr_conv/pcbfp2dxf.py 442) 
pcb_footpr_conv/pcbfp2dxf.py 443)     def readPcb(self, file_name: str):
pcb_footpr_conv/pcbfp2dxf.py 444)         """
pcb_footpr_conv/pcbfp2dxf.py 445)         Read a PCB footprint file.
pcb_footpr_conv/pcbfp2dxf.py 446)         """
pcb_footpr_conv/pcbfp2dxf.py 447)         self.reset()
pcb_footpr_conv/pcbfp2dxf.py 448)         with open(file_name, 'r') as f:
pcb_footpr_conv/pcbfp2dxf.py 449)             s = f.read()
pcb_footpr_conv/pcbfp2dxf.py 450)         p = PcbFootprintParser(s)
pcb_footpr_conv/pcbfp2dxf.py 451)         p.parseElementBlock()
pcb_footpr_conv/pcbfp2dxf.py 452) 
pcb_footpr_conv/pcbfp2dxf.py 453)     def reset(self):
pcb_footpr_conv/pcbfp2dxf.py 454)         pass
pcb_footpr_conv/pcbfp2dxf.py 455) 
pcb_footpr_conv/pcbfp2dxf.py 456) 
pcb_footpr_conv/pcbfp2dxf.py 457) def write_dxf(file_name: str):
pcb_footpr_conv/pcbfp2dxf.py 458)     doc = ezdxf.new('R12')
pcb_footpr_conv/pcbfp2dxf.py 459)     msp = doc.modelspace()
pcb_footpr_conv/pcbfp2dxf.py 460)     msp.add_circle((1, 2), radius=3)
pcb_footpr_conv/pcbfp2dxf.py 461)     doc.saveas(file_name)
pcb_footpr_conv/pcbfp2dxf.py 462) 
pcb_footpr_conv/pcbfp2dxf.py 463) 
pcb_footpr_conv/pcbfp2dxf.py 464) def main():
pcb_footpr_conv/pcbfp2dxf.py 465)     fp = PcbFootprint()
Stefan Schuermans begin of PCB footprint pars...

Stefan Schuermans authored 3 years ago

pcb_footpr_conv/fp2dxf.py    466)     fp.readPcb(sys.argv[1])