46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
from py3dbp import Packer, Bin, Item
|
|
|
|
from logger import logger
|
|
|
|
|
|
class PalletPacker:
|
|
def __init__(self, pallet: dict, box: dict):
|
|
self.pallet_width = pallet.get("x", 1.2)
|
|
self.pallet_height = pallet.get("y", 0.8)
|
|
self.pallet_depth = pallet.get("z", 0.144)
|
|
|
|
gap = 0
|
|
self.box_width = box.get("x", 0.2) + gap
|
|
self.box_height = box.get("y", 0.2) + gap
|
|
self.box_depth = box.get("z", 0.2)
|
|
|
|
def pack(self):
|
|
packer = Packer()
|
|
packer.add_bin(
|
|
Bin(
|
|
"pallet", self.pallet_width, self.pallet_height, self.pallet_depth, 1000
|
|
)
|
|
)
|
|
|
|
# Вычисляем, сколько коробок поместится на паллете в один слой
|
|
num_boxes_x = self.pallet_width // self.box_width
|
|
num_boxes_y = self.pallet_height // self.box_height
|
|
num_boxes = int(num_boxes_x * num_boxes_y)
|
|
|
|
# Добавляем коробки в пакер
|
|
for i in range(num_boxes):
|
|
packer.add_item(
|
|
Item(f"box{i}", self.box_width, self.box_height, self.box_depth, 1)
|
|
)
|
|
|
|
# Упаковываем коробки
|
|
packer.pack()
|
|
|
|
# Получаем результат
|
|
coordinates = []
|
|
for b in packer.bins:
|
|
for item in b.items:
|
|
coordinates.append([float(i) for i in item.position])
|
|
|
|
return coordinates
|