[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("3-dimensional packing plan View")]
|
---|
[9440] | 15 | [Content(typeof(PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>), true)]
|
---|
[9348] | 16 | public partial class PackingPlan3DView : NamedItemView {
|
---|
| 17 |
|
---|
| 18 | public PackingPlan3DView() {
|
---|
| 19 | InitializeComponent();
|
---|
[9495] | 20 | this.nameTextBox.Text = "Packing Plan";
|
---|
[9348] | 21 | }
|
---|
| 22 |
|
---|
| 23 |
|
---|
[9495] | 24 | protected override void DeregisterContentEvents() {
|
---|
| 25 | Content.QualityChanged -= new EventHandler(Content_QualityChanged);
|
---|
| 26 | base.DeregisterContentEvents();
|
---|
| 27 | }
|
---|
| 28 | protected override void RegisterContentEvents() {
|
---|
| 29 | base.RegisterContentEvents();
|
---|
| 30 | Content.QualityChanged += new EventHandler(Content_QualityChanged);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[9440] | 33 | public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
|
---|
| 34 | get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; }
|
---|
[9348] | 35 | set { base.Content = value; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | protected override void OnContentChanged() {
|
---|
| 40 | base.OnContentChanged();
|
---|
| 41 | binSelection.Items.Clear();
|
---|
| 42 | if (Content == null) {
|
---|
| 43 | packingPlan3D.InitializeContainer(0, 0, 0);
|
---|
| 44 | } else {
|
---|
[9495] | 45 | Content.Name = "Packing Plan";
|
---|
[9348] | 46 | for (int i = 0; i < Content.NrOfBins; i++)
|
---|
| 47 | binSelection.Items.Add(i);
|
---|
| 48 | binSelection.SelectedIndex = 0;
|
---|
| 49 | UpdateModel();
|
---|
| 50 | packingPlan3D.StartRendering();
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | private void UpdateModel() {
|
---|
| 55 | int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
|
---|
[9495] | 56 | var bin = Content.GetPackingBinMeasuresForBinNr(currentBin);
|
---|
[9348] | 57 | packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth);
|
---|
| 58 | int i = 0;
|
---|
| 59 | foreach (var item in Content.PackingItemMeasures) {
|
---|
| 60 | var position = Content.PackingItemPositions[i];
|
---|
| 61 | if (position.AssignedBin == currentBin)
|
---|
[9440] | 62 | packingPlan3D.AddItemToContainer(
|
---|
| 63 | position.Rotated ? item.Depth : item.Width,
|
---|
| 64 | item.Height,
|
---|
| 65 | position.Rotated ? item.Width : item.Depth,
|
---|
| 66 | position.X, position.Y, position.Z, i);
|
---|
[9348] | 67 | i++;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 72 | UpdateModel();
|
---|
| 73 |
|
---|
| 74 | itemSelection.SelectedIndex = -1;
|
---|
| 75 | itemSelection.Items.Clear();
|
---|
| 76 | int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
|
---|
| 77 | for (int i = 0; i < Content.PackingItemPositions.Count; i++) {
|
---|
| 78 | if (Content.PackingItemPositions[i].AssignedBin == currentBin)
|
---|
| 79 | itemSelection.Items.Add(i);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | packingPlan3D.Invalidate();
|
---|
| 83 | packingPlan3D.Update();
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 87 | UpdateModel();
|
---|
[9495] | 88 |
|
---|
| 89 | int selectedItem = -1;
|
---|
| 90 | if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
|
---|
| 91 | packingPlan3D.SelectItem(selectedItem);
|
---|
| 92 | } else
|
---|
| 93 | packingPlan3D.UnselectItem();
|
---|
| 94 |
|
---|
[9348] | 95 | packingPlan3D.Invalidate();
|
---|
| 96 | packingPlan3D.Update();
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[9495] | 99 | private void Content_QualityChanged(object sender, EventArgs e) {
|
---|
| 100 | if (InvokeRequired)
|
---|
| 101 | Invoke(new EventHandler(Content_QualityChanged), sender, e);
|
---|
| 102 | else {
|
---|
| 103 | binSelection.Items.Clear();
|
---|
| 104 | if (Content == null) {
|
---|
| 105 | packingPlan3D.InitializeContainer(0, 0, 0);
|
---|
| 106 | } else {
|
---|
| 107 | Content.Name = "Packing Plan";
|
---|
| 108 | for (int i = 0; i < Content.NrOfBins; i++)
|
---|
| 109 | binSelection.Items.Add(i);
|
---|
| 110 | binSelection.SelectedIndex = 0;
|
---|
| 111 | UpdateModel();
|
---|
| 112 | packingPlan3D.StartRendering();
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
[9348] | 116 | }
|
---|
| 117 | }
|
---|