def createAndAddNewGrid(self,
                            width,
                            article_name='default',
                            material='kokos',
                            brand='kokos',
                            color='naturel'):
        if self.rectangle.getBrand().lower(
        ) == 'kokos' and self.rectangle.getGridWidth() == 100:
            grid_height = 1230
        elif self.rectangle.getBrand().lower(
        ) == 'kokos' and self.rectangle.getGridWidth() == 200:
            grid_height = 605
        else:
            grid_height = 980

        try:
            grid = Grid(width=width,
                        height=grid_height,
                        article_name=article_name,
                        material=material,
                        name=self.grids[-1].getName() + 1,
                        brand=brand,
                        color=color,
                        stacked_rectangles=[])
            self.grids.append(grid)

            self.db_manager.addGrid(grid)
            print("Created and added new grid to database")

        except IndexError:
            grid = Grid(width=200, height=grid_height, name=1)
            self.grids.append(grid)
            self.db_manager.addGrid(grid)
            print("Created and added initial grid to database")
    def setUp(self):

        self.rectangle_4 = Rectangle(50, 80, 4)
        self.rectangle_5 = Rectangle(50, 80, 5)

        self.grid_1 = Grid(200, 1500, 1)
        self.grid_2 = Grid(100, 100, 2)
        self.grid_3 = Grid(100, 80, 3)
    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 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 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 testIsValidPosition(self):
        self.grid_2 = Grid(100, 100, 2)

        self.rectangle_4.setPosition([25, 40])
        self.rectangle_5.setPosition([24, 40])

        self.grid_2.addRectangle(self.rectangle_4)
        self.assertFalse(self.grid_2.isValidPosition(self.rectangle_5))

        self.rectangle_5.setPosition([76, 40])
        self.assertFalse(self.grid_2.isValidPosition(self.rectangle_5))
    def __init__(self, data_logger=DataLogger()):
        self.db_manager = DatabaseManager()
        self.setStandardSizesToFill([])
        self.setFillOrdersWithSmallerGridWidths(False)

        self.rectangles = []
        self.is_stacking = False

        # current rectangle to stack in current grid
        self.rectangle = Rectangle()
        self.grid = Grid()
        self.setDataLogger(data_logger)

        # stacking position of current rectangle
        self.stacking_position = []

        # stacking position of current rectangle rotated
        self.stacking_position_rotated = []
    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
    def createUniqueGrid(self,
                         width,
                         height=None,
                         article_name='',
                         material='kokos',
                         brand='kokos',
                         color='naturel'):

        brand_lower_case = brand.lower()
        material_lower_case = material.lower()

        # only do this when the height is not specified
        if height == None:
            if brand_lower_case == 'kokos' and width == 100:
                height = 1225
            elif brand_lower_case == 'kokos' and width == 200:
                height = 600

            # ambiant except lobby
            elif brand_lower_case == 'ambiant' and material_lower_case.split(
            )[1] != 'lobby' and width == 123:
                height = 975
            elif brand_lower_case == 'ambiant' and material_lower_case.split(
            )[1] != 'lobby' and width == 193:
                height = 600

            # ambiant lobby
            elif brand_lower_case == 'ambiant' and material_lower_case.split(
            )[1] == 'lobby' and width == 123:
                height = 975
            elif brand_lower_case == 'ambiant' and material_lower_case.split(
            )[1] == 'lobby' and width == 200:
                height = 600

            # forbo
            elif brand_lower_case.split()[0] == 'forbo' and width == 98:
                height = 975
            elif brand_lower_case.split()[0] == 'forbo' and width == 148:
                height = 975
            elif brand_lower_case.split()[0] == 'forbo' and width == 198:
                height = 600

            # zeno protect
            elif brand_lower_case.split()[0] == 'zeno' and width == 98:
                height = 975
            elif brand_lower_case.split()[0] == 'zeno' and width == 198:
                height = 600

            # ondervloer
            elif brand_lower_case == 'ondervloer 5 mm' and width == 135:
                height = 700
            elif brand_lower_case == 'ondervloer 3,6 mm' and width == 130:
                height = 1100

            elif brand_lower_case.split()[0] == 'squid' and width == 137:
                height = 1500

            # TODO: might want to throw an exception here
            else:
                height = 980

        try:
            used_names = self.listUsedGridNames()
            sorted_names = sorted(used_names)
            unique_name = int(sorted_names[-1] + 1)
            print("Creating unique grid with number: " + str(unique_name))
            grid = Grid(width=width,
                        height=height,
                        name=unique_name,
                        article_name=article_name,
                        material=material,
                        brand=brand,
                        color=color)
            self.addGrid(grid)

        except IndexError:
            print("No grids available yet")
            print("Creating first grid")

            grid = Grid(width=width,
                        height=height,
                        name=1,
                        article_name=article_name,
                        material=material,
                        brand=brand,
                        color=color)
            print(grid.color)
            print(grid.brand)
            self.addGrid(grid)

        return grid
Exemple #11
0
from rectangle_packing.grid import Grid
from rectangle_packing.stacker import Stacker
from rectangle_packing.rectangle import Rectangle
from rectangle_packing.excel_parser import ExcelParser
from rectangle_packing.database_manager import DatabaseManager

import cProfile

if __name__ == "__main__":
    stacker = Stacker()
    excel_parser = ExcelParser("./example/paklijsten/", "paklijst.xlsx")
    grid = Grid(name="0",
                width=130,
                height=1500,
                brand="Ambiant",
                color="2400.0205")
    grid.setDxfDrawing("./example/grids/", "example.dxf")
    db_manager = DatabaseManager()

    prof = cProfile.Profile()

    db_manager.clearDatabase()
    rectangles = excel_parser.getUnstackedRectangles()
    db_manager.addRectangles(rectangles)
    stacker.setGrid(grid)

    prof.enable()
    stacker.start(automatic=False)
    prof.disable()

    prof.print_stats()