Exemplo n.º 1
0
 def pack_many(self, cells, origin=ap.SOUTH_WEST, direction=ap.VERTICAL):
     """
     Pack many cells with the same settings
     """
     failed = []
     for cell in cells:
         try:
             self.pack_auto(cell, origin, direction)
         except ap.OutOfSpaceError as e:
             print(e)
             failed.append(cell)
     return CellList(failed)
Exemplo n.º 2
0
    def pop_doe(self, regex):
        """pop out a set of cells"""
        cells = []
        if regex in self.does:
            cells = self.does[regex]
            del self.does[regex]
            self.delete_cells(cells)
            cells = sorted(cells, key=area, reverse=True)

        else:
            print("Warning: no cells found for {}".format(regex))

        return CellList(cells)
Exemplo n.º 3
0
    def pop(self, regex: str, delete: bool = True) -> CellList:
        """pop cells"""
        # pop out the cells
        # cells = [
        #     cell for key, cell in self.cells.items()
        #     if re.search(regex, key, flags=re.IGNORECASE)
        # ]
        cells = []
        keys = []
        for key, cell in self.cells.items():
            if re.search(regex, key, flags=re.IGNORECASE):
                cells.append(cell)
                keys.append(key)

        if delete:
            for key in keys:
                del self.cells[key]
        if cells:
            cells = sorted(cells, key=area, reverse=True)
        else:
            print("Warning: no cells found for {}".format(regex))

        return CellList(cells)
Exemplo n.º 4
0
    def pack_grid(
        self,
        cells: CellList,
        cols: None = None,
        rows: None = None,
        aspect: int = 3,
        direction: int = ap.VERTICAL,
        align: int = ap.BOTH,
        normalization_origin: Tuple[int, int] = ap.SOUTH_WEST,
        origin: Tuple[int, int] = ap.SOUTH_WEST,
        name: None = None,
        padding: int = ap.PADDING,
    ) -> None:
        """
        Pack into a grid, assuming that all cells are the same size
        """
        if not cells:
            return

        # Get the name from the longest common substring
        if name is None:
            name = ap.longest_common_prefix([c.name for c in cells]) + "_g"
            name = name if len(name) > 2 else "Misc"

        # Make the block with approriate size
        block = AutoPlacer(name)

        # Collect and clean the cells
        cells.align(align)
        cells.normalize(ap.BOTH, normalization_origin)
        cells.pad(padding=padding)
        # cells.sort(lambda c: c.name)

        # Safety check
        assert not (
            cols is not None and rows is not None
        ), "Don't specify both rows and cols"

        # Infer the dimensions, targeting an aspect ratio of 1
        if rows is None and cols is None:
            b = cells[0].bbox()
            cols = ap.estimate_cols(len(cells), b.width(), b.height(), aspect)

        # Accept user parameters
        if cols is None:
            cols = int(math.ceil(len(cells) / rows))
        elif rows is None:
            rows = int(math.ceil(len(cells) / cols))

        # Get dimensions
        bbox = cells[0].bbox()
        w, h = bbox.width(), bbox.height()

        # Place
        assert cols * rows >= len(cells)
        grid = itertools.product(list(range(int(cols))), list(range(int(rows))))
        for cell, (col, row) in zip(cells, grid):
            block.pack_manual(cell, w * col, h * row)

        # Shrink and add a boundary
        block.shrink()
        block.draw_boundary()

        # Pack into the container
        self.pack_auto(block.top_cell(), direction=direction, origin=origin)
Exemplo n.º 5
0
 def get(self, regex):
     cells = [
         cell for key, cell in self.cells.items()
         if re.search(regex, key, flags=re.IGNORECASE)
     ]
     return CellList(cells)