Exemple #1
0
    def save(self, filename=None):
        if not filename:
            filename = self.filename

        se = sexpr.SexprBuilder('kicad_pcb')

        # Hex value of current epoch timestamp (in seconds)
        tedit = hex(int(time.time())).upper()[2:]

        # Add header items
        header = []
        header.append({'version': self.version})
        #root.append({'generator': self.generator})
        header.append({'host': ['pcbnew', '(5.1.2)-2']})
        se.addItems(header, newline=False)

        # Add Layers
        se.startGroup('layers')
        se.addItems(self.layers)
        se.endGroup()

        # Add Nets
        for key in self.nets.keys():
            se.addItem({'net': [key, self.nets[key]]})

        # Add Line Data
        for line in self.lines:
            self._formatLine(line, se)

        # Add Poly Data
        for poly in self.polys:
            self._formatPoly(poly, se)

        # Add Vias
        for via in self.vias:
            self._formatVia(via, se)

        se.endGroup(True)

        with open(filename, 'w', newline='\n') as f:
            f.write(se.output)
            f.write('\n')
Exemple #2
0
    def save(self, filename=None):
        if not filename:
            filename = self.filename

        se = sexpr.SexprBuilder('module')

        # Hex value of current epoch timestamp (in seconds)
        tedit = hex(int(time.time())).upper()[2:]

        # Output must be precisely formatted
        """ Header order is as follows
        (*items are optional)

        module <name> locked* <layer>  <tedit>
        descr
        tags
        autoplace_cost_90*
        autoplace_cost_180*
        solder_mask_margin*
        solder_paste_margin*
        solder_paste_ratio*
        clearance*
        attr

        fp_text reference
        fp_text value
        [fp_text user]
        """

        # Build the header string
        header = [self.name]
        if self.locked:
            header.append('locked')
        header.append({'layer': self.layer})
        header.append({'tedit': tedit})

        se.addItems(header, newline=False)
        se.addItems({'descr': self.description}, indent=True)
        se.addItems({'tags': self.tags})

        # Following items are optional (only written if non-zero)
        se.addOptItem('autoplace_cost90', self.autoplace_cost90)
        se.addOptItem('autoplace_cost180', self.autoplace_cost180)
        se.addOptItem('solder_mask_margin', self.solder_mask_margin)
        se.addOptItem('solder_paste_margin', self.solder_paste_margin)
        se.addOptItem('solder_paste_ratio', self.solder_paste_ratio)
        se.addOptItem('clearance', self.clearance)

        # 'pth' type is assumed
        attr = self.attribute.lower()
        if attr in ['smd', 'virtual']:
            se.addItems({'attr': attr})

        # Add text items
        self._formatText('reference', self.reference, se)
        self._formatText('value', self.value, se)

        for text in self.userText:
            self._formatText('user', text, se)

        # Add Line Data
        for line in self.lines:
            self._formatLine(line, se)

        # Add Circle Data
        for circle in self.circles:
            self._formatCircle(circle, se)

        # Add Arc Data
        for arc in self.arcs:
            self._formatArc(arc, se)

        # Add Pad Data
        for pad in self.pads:
            self._formatPad(pad, se)

        # Add Model Data
        for model in self.models:
            self._formatModel(model, se)

        se.endGroup(True)

        with open(filename, 'w') as f:
            f.write(se.output)
            f.write('\n')
    def save(self, filename: Optional[str] = None):
        if not filename:
            filename = self.filename

        se = sexpr.SexprBuilder("footprint")

        # Hex value of current epoch timestamp (in seconds)
        tedit = hex(int(time.time())).upper()[2:]

        self.version = self.SEXPR_BOARD_FILE_VERSION
        self.generator = "KicadMod"

        # Output must be precisely formatted
        """ Header order is as follows
        (*items are optional)

        module <name> locked* <version> <generator> <layer>
        <tedit>
        descr
        tags
        autoplace_cost_90*
        autoplace_cost_180*
        solder_mask_margin*
        solder_paste_margin*
        solder_paste_ratio*
        clearance*
        attr

        fp_text reference
        fp_text value
        [fp_text user]
        """

        # Build the header string
        header = [self.name]
        if self.locked:
            header.append("locked")
        header.append({"version": self.version})
        header.append({"generator": self.generator})
        header.append({"layer": self.layer})
        header.append({"tedit": tedit})

        se.addItems(header, newline=False)
        se.addItems({"descr": self.description}, indent=True)
        se.addItems({"tags": self.tags})

        # Following items are optional (only written if non-zero)
        se.addOptItem("autoplace_cost90", self.autoplace_cost90)
        se.addOptItem("autoplace_cost180", self.autoplace_cost180)
        se.addOptItem("solder_mask_margin", self.solder_mask_margin)
        se.addOptItem("solder_paste_margin", self.solder_paste_margin)
        se.addOptItem("solder_paste_ratio", self.solder_paste_ratio)
        se.addOptItem("clearance", self.clearance)

        # Set attribute
        attr = self.attribute.lower()
        if (attr in ["smd", "through_hole"] or self.exclude_from_bom
                or self.exclude_from_pos_files):
            params = []
            if attr in ["smd", "through_hole"]:
                params.append(attr)
            if self.exclude_from_bom:
                params.append("exclude_from_bom")
            if self.exclude_from_pos_files:
                params.append("exclude_from_pos_files")
            se.addItems({"attr": params})

        # Add text items
        self._formatText("reference", self.reference, se)
        self._formatText("value", self.value, se)

        for text in self.userText:
            self._formatText("user", text, se)

        # Add Line Data
        for line in self.lines:
            self._formatLine(line, se)

        # Add Rect Data
        for rect in self.rects:
            self._formatRect(rect, se)

        # Add Circle Data
        for circle in self.circles:
            self._formatCircle(circle, se)

        # Add Poly Data
        for poly in self.polys:
            self._formatPoly(poly, se)

        # Add Arc Data
        for arc in self.arcs:
            self._formatArc(arc, se)

        # Add Pad Data
        for pad in self.pads:
            self._formatPad(pad, se)

        # Add Model Data
        for model in self.models:
            self._formatModel(model, se)

        se.endGroup(True)

        with open(filename, "w", newline="\n") as f:
            f.write(se.output)
            f.write("\n")