def get_sexpr(s): sx = [ 'kicad_symbol_lib', ['version', s.version], ['generator', s.generator] ] for sym in s.symbols: sx.append(sym.get_sexpr()) return sexpr.format_sexp(sexpr.build_sexp(sx), max_nesting=4)
def get_sexpr(self) -> str: sx = [ "kicad_symbol_lib", ["version", self.version], ["generator", self.generator], ] for sym in self.symbols: sx.append(sym.get_sexpr()) return sexpr.format_sexp(sexpr.build_sexp(sx), max_nesting=4)
def get_checksum (comp, unit, variant): data='' items=[] formatted_items = [] items = comp.arcs + comp.circles + comp.polylines + comp.texts for elem in items: formatted_items.append (sexpr.build_sexp(elem.get_sexpr())) formatted_items.sort() data = ' '.join(formatted_items) try: md5 = hashlib.md5(data.encode('utf-8')) except UnicodeDecodeError: md5 = hashlib.md5(data) checksum = md5.hexdigest() return checksum
def save(self, filename=None): if not filename: filename = self.filename # module name self.sexpr_data[1] = self.name # locked flag try: self.sexpr_data.remove('locked') except ValueError: pass if self.locked: self.sexpr_data.insert(2, 'locked') # description if self.description: self._updateCreateArray(['descr', self.description], ['tedit']) # tags if self.tags: self._updateCreateArray(['tags', self.tags], ['descr', 'tedit']) # auto place settings if self.autoplace_cost90: self._updateCreateArray( ['autoplace_cost90', self.autoplace_cost90], ['tags', 'descr', 'tedit']) if self.autoplace_cost180: self._updateCreateArray( ['autoplace_cost180', self.autoplace_cost180], ['tags', 'descr', 'tedit']) # module clearance settings if self.clearance: self._updateCreateArray(['clearance', self.clearance], ['tags', 'descr', 'tedit']) if self.solder_mask_margin: self._updateCreateArray( ['solder_mask_margin', self.solder_mask_margin], ['tags', 'descr', 'tedit']) if self.solder_paste_margin: self._updateCreateArray( ['solder_paste_margin', self.solder_paste_margin], ['tags', 'descr', 'tedit']) if self.solder_paste_ratio: self._updateCreateArray( ['solder_paste_ratio', self.solder_paste_ratio], ['tags', 'descr', 'tedit']) # attribute attr = self.attribute.lower() assert attr in [ 'pth', 'smd', 'virtual' ], "attribute must be one of the following options: 'pth', 'smd', 'virtual'" # when the footprint is PTH the attr isn't explicitly defined, thus the field attr doesn't exists try: self.sexpr_data.remove(self._getArray(self.sexpr_data, 'attr')[0]) except IndexError: pass # create the field attr if not pth if attr != 'pth': self._updateCreateArray(['attr', attr], ['tags', 'descr', 'tedit']) # remove all existing text arrays for text in self._getArray(self.sexpr_data, 'fp_text'): self.sexpr_data.remove(text) # reference self._addText('reference', [self.reference]) # value self._addText('value', [self.value]) # user text self._addText('user', self.userText) # lines # remove all existing lines arrays for line in self._getArray(self.sexpr_data, 'fp_line'): self.sexpr_data.remove(line) self._addLines(self.lines) # circles # remove all existing circles arrays for circle in self._getArray(self.sexpr_data, 'fp_circle'): self.sexpr_data.remove(circle) self._addCircles(self.circles) # arcs # remove all existing arcs arrays for arc in self._getArray(self.sexpr_data, 'fp_arc'): self.sexpr_data.remove(arc) self._addArcs(self.arcs) # pads # remove all existing pads arrays for pad in self._getArray(self.sexpr_data, 'pad'): self.sexpr_data.remove(pad) self._addPads(self.pads) # models # remove all existing models arrays for model in self._getArray(self.sexpr_data, 'model'): self.sexpr_data.remove(model) self._addModels(self.models) # convert array data to s-expression and save in the disc output = sexpr.build_sexp(self.sexpr_data) output = sexpr.format_sexp(output, max_nesting=1) f = open(filename, 'w') f.write(output) f.close()
def save(self, filename=None): if not filename: filename = self.filename # module name self.sexpr_data[1] = self.name # locked flag try: self.sexpr_data.remove('locked') except ValueError: pass if self.locked: self.sexpr_data.insert(2, 'locked') # description if self.description: self._updateCreateArray(['descr', self.description], ['tedit']) # tags if self.tags: self._updateCreateArray(['tags', self.tags], ['descr', 'tedit']) # auto place settings if self.autoplace_cost90: self._updateCreateArray(['autoplace_cost90', self.autoplace_cost90], ['tags', 'descr', 'tedit']) if self.autoplace_cost180: self._updateCreateArray(['autoplace_cost180', self.autoplace_cost180], ['tags', 'descr', 'tedit']) # module clearance settings if self.clearance: self._updateCreateArray(['clearance', self.clearance], ['tags', 'descr', 'tedit']) if self.solder_mask_margin: self._updateCreateArray(['solder_mask_margin', self.solder_mask_margin], ['tags', 'descr', 'tedit']) if self.solder_paste_margin: self._updateCreateArray(['solder_paste_margin', self.solder_paste_margin], ['tags', 'descr', 'tedit']) if self.solder_paste_ratio: self._updateCreateArray(['solder_paste_ratio', self.solder_paste_ratio], ['tags', 'descr', 'tedit']) # attribute attr = self.attribute.lower() assert attr in ['pth', 'smd', 'virtual'], "attribute must be one of the following options: 'pth', 'smd', 'virtual'" # when the footprint is PTH the attr isn't explicitly defined, thus the field attr doesn't exists try: self.sexpr_data.remove(self._getArray(self.sexpr_data, 'attr')[0]) except IndexError: pass # create the field attr if not pth if attr != 'pth': self._updateCreateArray(['attr', attr], ['tags', 'descr', 'tedit']) # remove all existing text arrays for text in self._getArray(self.sexpr_data, 'fp_text'): self.sexpr_data.remove(text) # reference self._addText('reference', [self.reference]) # value self._addText('value', [self.value]) # user text self._addText('user', self.userText) # lines # remove all existing lines arrays for line in self._getArray(self.sexpr_data, 'fp_line'): self.sexpr_data.remove(line) self._addLines(self.lines) # circles # remove all existing circles arrays for circle in self._getArray(self.sexpr_data, 'fp_circle'): self.sexpr_data.remove(circle) self._addCircles(self.circles) # arcs # remove all existing arcs arrays for arc in self._getArray(self.sexpr_data, 'fp_arc'): self.sexpr_data.remove(arc) self._addArcs(self.arcs) # pads # remove all existing pads arrays for pad in self._getArray(self.sexpr_data, 'pad'): self.sexpr_data.remove(pad) self._addPads(self.pads) # models # remove all existing models arrays for model in self._getArray(self.sexpr_data, 'model'): self.sexpr_data.remove(model) self._addModels(self.models) # convert array data to s-expression and save in the disc output = sexpr.build_sexp(self.sexpr_data) output = sexpr.format_sexp(output) f = open(filename, 'w') f.write(output) f.close()