Exemplo n.º 1
0
    def _parse(self, mod):
        self.at = [float(x) for x in sexp.find(mod, "at")[1:]]
        self.bounds = [0, 0, 0, 0]
        for text in sexp.find_all(mod, "fp_text"):
            if text[1] == "reference":
                self.ref = text[2]
            elif text[1] == "value":
                self.val = text[2]

        for graphic in sexp.find_all(mod, "fp_line", "fp_circle"):
            self._parse_graphic(graphic)

        for pad in sexp.find_all(mod, "pad"):
            self._parse_pad(pad)
Exemplo n.º 2
0
 def _parse_edges(self, board):
     for graphic in sexp.find_all(board, "gr_line", "gr_arc", "gr_circle"):
         layer = sexp.find(graphic, "layer")[1]
         if layer != "Edge.Cuts":
             continue
         if graphic[0] == "gr_line":
             start = [float(x) for x in sexp.find(graphic, "start")[1:]]
             end = [float(x) for x in sexp.find(graphic, "end")[1:]]
             self.edge_lines.append((start, end))
         elif graphic[0] == "gr_arc":
             center = [float(x) for x in sexp.find(graphic, "start")[1:]]
             start = [float(x) for x in sexp.find(graphic, "end")[1:]]
             r = math.sqrt((center[0] - start[0])**2 +
                           (center[1] - start[1])**2)
             angle = float(sexp.find(graphic, "angle")[1]) * math.pi/180.0
             dx = start[0] - center[0]
             dy = start[1] - center[1]
             start_angle = math.atan2(dy, dx)
             end_angle = start_angle + angle
             self.edge_arcs.append((center[0], center[1], r,
                                    start_angle, end_angle))
         elif graphic[0] == "gr_circle":
             center = [float(x) for x in sexp.find(graphic, "center")[1:]]
             end = [float(x) for x in sexp.find(graphic, "end")[1:]]
             r = math.sqrt((center[0] - end[0])**2 +
                           (center[1] - end[1])**2)
             self.edge_arcs.append((center[0], center[1], r, 0, 2*math.pi))
Exemplo n.º 3
0
    def _parse(self, board):
        for module in sexp.find_all(board, "module"):
            self.modules.append(Module(module))

        # We compute the PCB bounds ourselves rather than relying on the file's
        # area tag which seems to sometimes be wrong. First go based on module
        # positions.
        self.bounds = [
            min(m.at[0] for m in self.modules),
            min(m.at[1] for m in self.modules),
            max(m.at[0] for m in self.modules),
            max(m.at[1] for m in self.modules)
        ]

        # We find all the board edges both for drawing and for bounds
        self._parse_edges(board)

        # Add a slight padding to ensure edge lines are properly drawn
        self.bounds[0] -= 1
        self.bounds[1] -= 1
        self.bounds[2] += 1
        self.bounds[3] += 1

        self.width = self.bounds[2] - self.bounds[0]
        self.height = self.bounds[3] - self.bounds[1]
Exemplo n.º 4
0
    def _parse(self, board):
        for module in sexp.find_all(board, "module"):
            self.modules.append(Module(module))

        # We compute the PCB bounds ourselves rather than relying on the file's
        # area tag which seems to sometimes be wrong. First go based on module
        # positions.
        self.bounds = [
            min(m.at[0] for m in self.modules),
            min(m.at[1] for m in self.modules),
            max(m.at[0] for m in self.modules),
            max(m.at[1] for m in self.modules)
        ]

        # We find all the board edges both for drawing and for bounds
        self._parse_edges(board)

        # Add a slight padding to ensure edge lines are properly drawn
        self.bounds[0] -= 1
        self.bounds[1] -= 1
        self.bounds[2] += 1
        self.bounds[3] += 1

        self.width = self.bounds[2] - self.bounds[0]
        self.height = self.bounds[3] - self.bounds[1]
Exemplo n.º 5
0
    def _parse(self, board):
        general = sexp.find(board, "general")
        self.bounds = [float(x) for x in sexp.find(general, "area")[1:]]
        self.width = self.bounds[2] - self.bounds[0]
        self.height = self.bounds[3] - self.bounds[1]

        for module in sexp.find_all(board, "module"):
            self.modules.append(Module(module))

        self._parse_edges(board)