1 | using System;
|
---|
2 | using System.Windows.Forms;
|
---|
3 | using HeuristicLab.Core.Views;
|
---|
4 | using HeuristicLab.MainForm;
|
---|
5 | using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
|
---|
6 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
7 | using HeuristicLab.Problems.BinPacking.PackingItem;
|
---|
8 | using HeuristicLab.Problems.BinPacking.PackingBin;
|
---|
9 | using HeuristicLab.Problems.BinPacking.Dimensions;
|
---|
10 | using HeuristicLab.Core;
|
---|
11 | using HeuristicLab.Data;
|
---|
12 |
|
---|
13 | namespace 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.BinPackings[currentBin].BinMeasures;
|
---|
58 | packingPlan2D.InitializeContainer(bin.Width, bin.Height);
|
---|
59 | foreach (var entry in plan.BinPackings[currentBin].ItemMeasures) {
|
---|
60 | var position = plan.BinPackings[currentBin].ItemPositions[entry.Key];
|
---|
61 | packingPlan2D.AddItemToContainer(
|
---|
62 | position.Rotated ? entry.Value.Height : entry.Value.Width,
|
---|
63 | position.Rotated ? entry.Value.Width : entry.Value.Height,
|
---|
64 | position.X, position.Y, entry.Key.ToString());
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
69 | Redraw(Content);
|
---|
70 | packingPlan2D.Refresh();
|
---|
71 | packingPlan2D.Refresh();
|
---|
72 | packingPlan2D.Refresh();
|
---|
73 | packingPlan2D.Refresh();
|
---|
74 | packingPlan2D.Refresh();
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | private void Content_QualityChanged(object sender, EventArgs e) {
|
---|
80 | if (InvokeRequired)
|
---|
81 | Invoke(new EventHandler(Content_QualityChanged), sender, e);
|
---|
82 | else {
|
---|
83 | binSelection.Items.Clear();
|
---|
84 | if (Content == null) {
|
---|
85 | Redraw();
|
---|
86 | } else {
|
---|
87 | for (int i = 0; i < Content.NrOfBins; i++)
|
---|
88 | binSelection.Items.Add(i);
|
---|
89 | Redraw(Content);
|
---|
90 | }
|
---|
91 | packingPlan2D.Refresh();
|
---|
92 | packingPlan2D.Refresh();
|
---|
93 | packingPlan2D.Refresh();
|
---|
94 | packingPlan2D.Refresh();
|
---|
95 | packingPlan2D.Refresh();
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|