[9348] | 1 | using System;
|
---|
| 2 | using System.Windows.Forms;
|
---|
| 3 | using HeuristicLab.Core.Views;
|
---|
| 4 | using HeuristicLab.MainForm;
|
---|
[9440] | 5 | using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
|
---|
[9348] | 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")]
|
---|
[9440] | 15 | [Content(typeof(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>), true)]
|
---|
[9348] | 16 | public partial class PackingPlan2DView : NamedItemView {
|
---|
| 17 |
|
---|
| 18 | public PackingPlan2DView() {
|
---|
| 19 | InitializeComponent();
|
---|
[9495] | 20 | }
|
---|
| 21 |
|
---|
| 22 | protected override void DeregisterContentEvents() {
|
---|
| 23 | Content.QualityChanged -= new EventHandler(Content_QualityChanged);
|
---|
| 24 | base.DeregisterContentEvents();
|
---|
[9348] | 25 | }
|
---|
[9495] | 26 | protected override void RegisterContentEvents() {
|
---|
| 27 | base.RegisterContentEvents();
|
---|
| 28 | Content.QualityChanged += new EventHandler(Content_QualityChanged);
|
---|
| 29 | }
|
---|
[9348] | 30 |
|
---|
| 31 |
|
---|
[9440] | 32 | public new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
|
---|
| 33 | get { return (PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>)base.Content; }
|
---|
[9348] | 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 |
|
---|
[9440] | 55 | private void Redraw(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {
|
---|
[9348] | 56 | int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
|
---|
[9495] | 57 | var bin = plan.GetPackingBinMeasuresForBinNr(currentBin);
|
---|
[9348] | 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)
|
---|
[9440] | 63 | packingPlan2D.AddItemToContainer(
|
---|
| 64 | position.Rotated ? item.Height : item.Width,
|
---|
| 65 | position.Rotated ? item.Width : item.Height,
|
---|
| 66 | position.X, position.Y, i.ToString());
|
---|
[9348] | 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 71 | Redraw(Content);
|
---|
| 72 | packingPlan2D.Invalidate();
|
---|
| 73 | packingPlan2D.Update();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[9495] | 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 | }
|
---|
[9348] | 94 | }
|
---|
| 95 | }
|
---|