def getGridsNotFull(self, width=100, brand='kokos', color='naturel'):
        try:
            grids = []
            query = {"width": width, "brand": brand, "color": color}

            cursor = self.grids_collection.find(query)

            for document in cursor:
                print("Loaded grid " + str(document["name"]) +
                      " from database")
                grid = Grid(width=document['width'],
                            height=document['height'],
                            article_name=document['article_name'],
                            material=document['material'],
                            brand=document['brand'],
                            color=document['color'],
                            name=document['name'],
                            is_cut=document['isCut'])
                rectangles = self.getRectangles(grid)
                grid.setStackedRectangles(rectangles)

                grid.checkAndSetFull()
                if not grid.isFull():
                    grids.append(grid)
        except:
            pass

        return grids
    def getGrid(self, grid_number, for_cutting=False):
        """ 
        Parameters 
        ----------
        for_cutting: get the rectangles with the exact sizes (in mm)
        """

        query = {"name": grid_number}

        cursor = self.grids_collection.find(query)
        for document in cursor:
            grid = Grid(width=document['width'],
                        height=document['height'],
                        article_name=document['article_name'],
                        brand=document['brand'],
                        material=document['material'],
                        color=document['color'],
                        name=document['name'],
                        is_cut=document['isCut'])
            if for_cutting == True:
                rectangles = self.getRectangles(grid, for_cutting)
            else:
                rectangles = self.getRectangles(grid)

            grid.setStackedRectangles(rectangles)

        return grid
    def getGridsCutByWidthBrandColor(self,
                                     width=100,
                                     brand='kokos',
                                     color='naturel'):
        grids = []
        query = {}
        if brand != 'all':
            query["brand"] = brand
        if color != 'all':
            query["color"] = color
        if grid_width != 'all':
            query["grid_width"] = grid_width

        cursor = self.grids_collection.find(query)
        for document in cursor:
            grid = Grid(width=document['width'],
                        height=document['height'],
                        article_name=document['article_name'],
                        material=document['material'],
                        brand=document['brand'],
                        color=document['color'],
                        name=document['name'],
                        is_cut=document['isCut'])
            rectangles = self.getRectangles(grid)
            grid.setStackedRectangles(rectangles)

            if grid.isCut():
                print("Loaded grid " + str(document["name"]) +
                      " from database")

                grids.append(grid)

        return grids
    def getGridsNotCut(self, sort=False):
        grids = []

        cursor = self.grids_collection.find({})
        for document in cursor:
            print("getGridsNotCut material = " + str(document['material']))
            grid = Grid(width=document['width'],
                        height=document['height'],
                        name=document['name'],
                        article_name=document['article_name'],
                        material=document['material'],
                        color=document['color'],
                        brand=document['brand'],
                        is_cut=document['isCut'])
            rectangles = self.getRectangles(grid)
            grid.setStackedRectangles(rectangles)

            if not grid.isCut():
                print("Loaded grid " + str(document["name"]) +
                      " from database")
                grids.append(grid)

        if sort == True:
            grids = sorted(grids, key=lambda g: g.getWidth(), reverse=True)

        print("Grid widths are " + str([grid.getWidth() for grid in grids]))
        print("Grid heights are " + str([grid.getHeight() for grid in grids]))

        return grids
    def getAllGrids(self):
        grids = []
        cursor = self.grids_collection.find({})

        for document in cursor:
            print("Loaded grid " + str(document["name"]) + " from database")
            grid = Grid(width=document['width'],
                        height=document['height'],
                        article_name=document['article_name'],
                        brand=document['brand'],
                        material=document['material'],
                        color=document['color'],
                        name=document['name'],
                        is_cut=document['isCut'])
            rectangles = self.getRectangles(grid)
            grid.setStackedRectangles(rectangles)
            grids.append(grid)

        return grids