Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: Implemented new encoding (MultiComponentVector/MCV); Implemented move-operators for MCV and GV encodings; Implemented new decoding-methods for PS, GV and MCV encodings (ExtremePoint-based packing);

File size: 2.3 KB
Line 
1using System;
2using System.Windows.Forms;
3using HeuristicLab.Core.Views;
4using HeuristicLab.MainForm;
5using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
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(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>), true)]
16  public partial class PackingPlan2DView : NamedItemView {
17
18    public PackingPlan2DView() {
19      InitializeComponent();
20    }
21
22
23    public new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
24      get { return (PackingPlan<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(PackingPlan<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(
55            position.Rotated ? item.Height : item.Width,
56            position.Rotated ? item.Width : item.Height,
57            position.X, position.Y, i.ToString());
58      }
59    }
60
61    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
62      Redraw(Content);
63      packingPlan2D.Invalidate();
64      packingPlan2D.Update();
65    }
66
67  }
68}
Note: See TracBrowser for help on using the repository browser.