Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: Did some major refactoring in Decoder-classes; Added MoveEvaluator classes for different encodings and dimensions; Added new crossover-class for MCV encoding;

File size: 3.2 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    protected override void DeregisterContentEvents() {
23      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
24      base.DeregisterContentEvents();
25    }
26    protected override void RegisterContentEvents() {
27      base.RegisterContentEvents();
28      Content.QualityChanged += new EventHandler(Content_QualityChanged);
29    }
30
31
32    public new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
33      get { return (PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>)base.Content; }
34      set { base.Content = value; }
35    }
36
37
38    protected override void OnContentChanged() {
39      base.OnContentChanged();
40      binSelection.Items.Clear();
41      if (Content == null) {
42        Redraw();
43      } else {
44        for (int i = 0; i < Content.NrOfBins; i++)
45          binSelection.Items.Add(i);
46        Redraw(Content);
47      }
48    }
49
50
51    private void Redraw() {
52      packingPlan2D.InitializeContainer(0, 0);
53    }
54
55    private void Redraw(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {     
56      int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
57      var bin = plan.GetPackingBinMeasuresForBinNr(currentBin);
58      packingPlan2D.InitializeContainer(bin.Width, bin.Height);
59      int i = 0;
60      foreach (var item in plan.PackingItemMeasures) {
61        var position = plan.PackingItemPositions[i++];
62        if (position.AssignedBin == currentBin)
63          packingPlan2D.AddItemToContainer(
64            position.Rotated ? item.Height : item.Width,
65            position.Rotated ? item.Width : item.Height,
66            position.X, position.Y, i.ToString());
67      }
68    }
69
70    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
71      Redraw(Content);
72      packingPlan2D.Invalidate();
73      packingPlan2D.Update();
74    }
75
76
77
78    private void Content_QualityChanged(object sender, EventArgs e) {
79      if (InvokeRequired)
80        Invoke(new EventHandler(Content_QualityChanged), sender, e);
81      else {
82        binSelection.Items.Clear();
83        if (Content == null) {
84          Redraw();
85        } else {
86          for (int i = 0; i < Content.NrOfBins; i++)
87            binSelection.Items.Add(i);
88          Redraw(Content);
89        }
90        packingPlan2D.Invalidate();
91        packingPlan2D.Update();
92      }
93    } 
94  }
95}
Note: See TracBrowser for help on using the repository browser.