Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan2DView.cs @ 9348

Last change on this file since 9348 was 9348, checked in by jhelm, 11 years ago

#1966: First working version of bin-packing problems.

File size: 2.3 KB
Line 
1using System;
2using System.Windows.Forms;
3using HeuristicLab.Core.Views;
4using HeuristicLab.MainForm;
5using HeuristicLab.Problems.BinPacking.PackingPlans;
6using HeuristicLab.Problems.BinPacking.Interfaces;
7using HeuristicLab.Problems.BinPacking.PackingItem;
8using HeuristicLab.Problems.BinPacking.PackingBin;
9using HeuristicLab.Problems.BinPacking.Dimensions;
10using HeuristicLab.Core;
11using HeuristicLab.Data;
12
13namespace HeuristicLab.Problems.BinPacking.Views {
14  [View("2-dimensional packing plan View")]
15  [Content(typeof(RegularSimpleRotationPackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>), true)]
16  public partial class PackingPlan2DView : NamedItemView {
17
18    public PackingPlan2DView() {
19      InitializeComponent();
20    }
21
22
23    public new RegularSimpleRotationPackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
24      get { return (RegularSimpleRotationPackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>)base.Content; }
25      set { base.Content = value; }
26    }
27
28
29    protected override void OnContentChanged() {
30      base.OnContentChanged();
31      binSelection.Items.Clear();
32      if (Content == null) {
33        Redraw();
34      } else {
35        for (int i = 0; i < Content.NrOfBins; i++)
36          binSelection.Items.Add(i);
37        Redraw(Content);
38      }
39    }
40
41
42    private void Redraw() {
43      packingPlan2D.InitializeContainer(0, 0);
44    }
45
46    private void Redraw(RegularSimpleRotationPackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {     
47      int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
48      var bin = plan.PackingBinMeasures;
49      packingPlan2D.InitializeContainer(bin.Width, bin.Height);
50      int i = 0;
51      foreach (var item in plan.PackingItemMeasures) {
52        var position = plan.PackingItemPositions[i++];
53        if (position.AssignedBin == currentBin)
54          packingPlan2D.AddItemToContainer(item.Width, item.Height, position.X, position.Y, i.ToString());
55      }
56    }
57
58    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
59      Redraw(Content);
60      packingPlan2D.Invalidate();
61      packingPlan2D.Update();
62    }
63
64  }
65}
Note: See TracBrowser for help on using the repository browser.