def test_rotation(self): """Test newPacker rotation argument""" p = packer.newPacker(rotation=False) p.add_rect(100, 10) p.add_bin(10, 100) p.pack() self.assertEqual(len(p.rect_list()), 0) p = packer.newPacker(rotation=True) p.add_rect(100, 10) p.add_bin(10, 100) p.pack() self.assertEqual(len(p.rect_list()), 1)
def test_offline_sorting(self): """Test newPacker uses provided sort algorithm""" p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF, sort_algo=packer.SORT_RATIO) self.assertEqual(p._sort_algo, packer.SORT_RATIO) # Test sort_algo is ignored when not applicable p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.Global, sort_algo=packer.SORT_RATIO) p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BFF, sort_algo=packer.SORT_RATIO)
def test_pack_algo(self): """Test NewPacker use correct PackingAlgorithm""" p = packer.newPacker(pack_algo=skyline.SkylineMwfl) p.add_rect(10, 10) p.add_bin(100, 100) p.pack() self.assertIsInstance(p[0], skyline.SkylineMwfl)
def test_mode_online(self): """Test newPacker return correct Packer when in online mode""" p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BNF) self.assertIsInstance(p, packer.PackerOnlineBNF) p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BFF) self.assertIsInstance(p, packer.PackerOnlineBFF) p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BBF) self.assertIsInstance(p, packer.PackerOnlineBBF) with self.assertRaises(AttributeError): p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.Global)
def test_mode_offline(self): """Test newPacker returns correct Packer when in offline mode""" p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BNF) self.assertIsInstance(p, packer.PackerBNF) p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF) self.assertIsInstance(p, packer.PackerBFF) p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BBF) self.assertIsInstance(p, packer.PackerBBF) p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.Global) self.assertIsInstance(p, packer.PackerGlobal)
def __init__(self, _inputFileName, _algorithmName): # init bacis structures self.resources = Resources() self.inputFileName = _inputFileName self.algorithmName = _algorithmName self.packer = newPacker(mode=PackingMode.Online, pack_algo=self.getAlgotithmClass()) self.packerHandler = PackerHandler() self.shipVisualizer = ShipVisualizer(_algorithmName)
def _common(self, mode, bin_algo, width, height): # create a new packer p = newPacker(mode, bin_algo) # as many bins as rectangles should be enough p.add_bin(width, height, count=len(self.rectangles)) # try to add the rectangles for r in self.rectangles: p.add_rect(*r) # pack them, if in offline mode if mode == PackingMode.Offline: p.pack() # provide the results for validation return p
def test_bin_default_id(self): """Test default bin id is None""" bins = [(100, 50, 1), (50, 50, 1), (200, 200, 10)] rects = [(199, 199), (100, 40), (40, 40), (20, 20), (180, 179)] p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF) for b in bins: p.add_bin(b[0], b[1], count=b[2]) for r in rects: p.add_rect(r[0], r[1]) p.pack() # verify bin ids correctly assigned for abin in p: self.assertEqual(abin.bid, None)
def test_default_options(self): """Test newPacker default options""" # Test default options p = packer.newPacker() # Default mode Online BBF self.assertIsInstance(p, packer.PackerBBF) # Default rotations True self.assertEqual(p._rotation, True) # Default packing algorithm SkylineBlWm p.add_rect(100, 10) p.add_bin(10, 100) p.pack() self.assertIsInstance(p[0], maxrects.MaxRectsBssf) self.assertEqual(len(p[0]), 1) # Default sortin algorithm SORT_LSIDE self.assertEqual(p._sort_algo, packer.SORT_AREA)
def test_bin_id(self): """Test correct bin id is assigned to each bin""" # width, height, count, bid bins = [(100, 50, 1, "first"), (50, 50, 1, "second"), (200, 200, 10, "many")] binIdx = {(b[0], b[1]): b[3] for b in bins} rects = [(199, 199), (100, 40), (40, 40), (20, 20), (180, 179)] p = packer.newPacker(mode=packer.PackingMode.Offline, bin_algo=packer.PackingBin.BFF) for b in bins: p.add_bin(b[0], b[1], count=b[2], bid=b[3]) for r in rects: p.add_rect(r[0], r[1]) p.pack() # verify bin ids correctly assigned for abin in p: self.assertEqual(binIdx[(abin.width, abin.height)], abin.bid)
def __init__(self, width, height): self.width = width self.height = height self.p = packer.newPacker(mode=packer.PackingMode.Online, bin_algo=packer.PackingBin.BFF) self.p.add_bin(self.width, self.height)
def checkName1(name): wb = open_workbook(name) f_dr='E:/Junks/Chinmay/New folder/Rectangles/'; sheet=wb.sheets()[0] number_of_rows = sheet.nrows number_of_columns = sheet.ncols length=(sheet.cell(1,1).value) breadth=(sheet.cell(2,1).value) blade=(sheet.cell(3,1).value) rectangles=[]; for k in range(6,number_of_rows): quantity=int((sheet.cell(k,3).value)) if(quantity>1): for n in range(0,quantity): r=(int((sheet.cell(k,1).value))+blade,int((sheet.cell(k,2).value))+blade,str((sheet.cell(k,0).value))+'_'+str(n)); rectangles.append(r) else: r=(int((sheet.cell(k,1).value))+blade,int((sheet.cell(k,2).value))+blade,str((sheet.cell(k,0).value))); rectangles.append(r) packerr = packer.newPacker(bin_algo=packer.PackingBin.Global,rotation=True,pack_algo = guillotine.GuillotineBssfSas) for r in rectangles: packerr.add_rect(*r) packerr.add_bin(length,breadth,count=float("inf")) packerr.pack() all_rects = packerr.rect_list() for rect in all_rects: b, x, y, w, h, rid = rect for sheet in range(0,len(packerr)): h = packerr[sheet].height + 400 w = packerr[sheet].width + 400 txt = Image.new('RGB', (int(w),int(h)), (255,255,255)) fnt = ImageFont.truetype("arial.ttf",50) d = ImageDraw.Draw(txt) d.line([200,200,int(w)-200,200], fill=(0,0,0), width=5) d.line([200,200,200,int(h)-200], fill=(0,0,0), width=5) d.line([200,int(h)-200,int(w)-200,int(h)-200], fill=(0,0,0), width=5) d.line([int(w)-200,200,int(w)-200,int(h)-200], fill=(0,0,0), width=5) for i in range(0,int(w)-400+1,200): d.line([i+200,185,i+200,215], fill=(0,0,0), width=5) wi,hi = fnt.getsize(str(i)) d.text((i+200-wi/2,185-5-hi), str(i), font=fnt, fill=(50,55,25)) d.line([i+200,h-185,i+200,h-215], fill=(0,0,0), width=5) wi,hi = fnt.getsize(str(i)) d.text((i+200-wi/2,h-180), str(i), font=fnt, fill=(50,55,25)) for i in range(0,int(h)-400+1,200): d.line([185,i+200,215,i+200], fill=(0,0,0), width=5) wi,hi = fnt.getsize(str(i)) d.text((185-wi-5,i+200-hi/2), str(i), font=fnt, fill=(50,55,25)) d.line([w-185,i+200,w-215,i+200], fill=(0,0,0), width=5) wi,hi = fnt.getsize(str(i)) d.text((w-180,i+200-hi/2), str(i), font=fnt, fill=(50,55,25)) for r in packerr[sheet]: rect_draw(r.x+200,r.y+200,r.x+r.width+200,r.y+r.height+200,d) wi,hi = fnt.getsize(r.rid) d.text((r.x+r.width/2-wi/2+200,r.y+r.height/2-hi/2+200),r.rid,font=fnt, fill=(50,55,25)) # rect_draw(900,900,1200,1250,d) txt.save(f_dr+str(sheet)+'.jpg') path.append(f_dr+str(sheet)+'.jpg') text_file = open("E:/Junks/Chinmay/New folder/cutting.txt", "w") text_file.write(str(packerr.rect_list())) path.append("E:/Junks/Chinmay/New folder/cutting.txt") text_file.close() dst='E:/Junks/Chinmay/New folder/temp.zip'; zip(dst) del path[:] return send_file(dst,attachment_filename='Cutting_Plan.zip',as_attachment=True)
detailsArray = req_data['details'] detailsArraylength = len(detailsArray) rectangles=[]; for k in range(detailsArraylength): quantity=int(detailsArray[k]['quantity']) if(quantity>1): for n in range(0,quantity): r=(int((detailsArray[k]['length']))+blade,int((detailsArray[k]['height']))+blade,str((detailsArray[k]['unique_id']))+'_'+str(n)); rectangles.append(r) else: r=(int((detailsArray[k]['length']))+blade,int((detailsArray[k]['height']))+blade,str((detailsArray[k]['unique_id']))); rectangles.append(r) packerr = packer.newPacker(bin_algo=packer.PackingBin.Global,rotation=True,pack_algo = guillotine.GuillotineBssfSas) for r in rectangles: packerr.add_rect(*r) packerr.add_bin(length,breadth,count=float("inf")) packerr.pack() all_rects = packerr.rect_list() for rect in all_rects: b, x, y, w, h, rid = rect for sheet in range(0,len(packerr)): h = packerr[sheet].height + 400 w = packerr[sheet].width + 400 txt = Image.new('RGB', (int(w),int(h)), (255,255,255)) fnt = ImageFont.truetype("arial.ttf",50)