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 |
|
---|
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 | }
|
---|