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("3-dimensional packing plan View")]
|
---|
15 | [Content(typeof(PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>), true)]
|
---|
16 | public partial class PackingPlan3DView : NamedItemView {
|
---|
17 |
|
---|
18 | public PackingPlan3DView() {
|
---|
19 | InitializeComponent();
|
---|
20 | this.nameTextBox.Text = "Packing Plan";
|
---|
21 | }
|
---|
22 |
|
---|
23 |
|
---|
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 |
|
---|
33 | public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
|
---|
34 | get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; }
|
---|
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 {
|
---|
45 | Content.Name = "Packing Plan";
|
---|
46 | int i = 0;
|
---|
47 | foreach (var bp in Content.BinPackings)
|
---|
48 | binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
|
---|
49 |
|
---|
50 | binSelection.SelectedIndex = 0;
|
---|
51 | UpdateModel();
|
---|
52 | packingPlan3D.StartRendering();
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void UpdateModel() {
|
---|
57 | int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
|
---|
58 | var bin = Content.BinPackings[currentBin].BinMeasures;
|
---|
59 | packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth);
|
---|
60 | foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) {
|
---|
61 | var position = Content.BinPackings[currentBin].ItemPositions[entry.Key];
|
---|
62 | packingPlan3D.AddItemToContainer(
|
---|
63 | position.Rotated ? entry.Value.Depth : entry.Value.Width,
|
---|
64 | entry.Value.Height,
|
---|
65 | position.Rotated ? entry.Value.Width : entry.Value.Depth,
|
---|
66 | position.X, position.Y, position.Z, entry.Key, entry.Value.Material);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
71 | UpdateModel();
|
---|
72 |
|
---|
73 | itemSelection.SelectedIndex = -1;
|
---|
74 | itemSelection.Items.Clear();
|
---|
75 | int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
|
---|
76 | //for (int i = 0; i < Content.PackingItemPositions.Count; i++) {
|
---|
77 | // if (Content.PackingItemPositions[i].AssignedBin == currentBin)
|
---|
78 | // itemSelection.Items.Add(i);
|
---|
79 | //}
|
---|
80 | foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) {
|
---|
81 | itemSelection.Items.Add(entry.Key);
|
---|
82 | }
|
---|
83 |
|
---|
84 | packingPlan3D.Invalidate();
|
---|
85 | packingPlan3D.Update();
|
---|
86 | }
|
---|
87 |
|
---|
88 | private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
89 | UpdateModel();
|
---|
90 |
|
---|
91 | int selectedItem = -1;
|
---|
92 | if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
|
---|
93 | packingPlan3D.SelectItem(selectedItem);
|
---|
94 | } else
|
---|
95 | packingPlan3D.UnselectItem();
|
---|
96 |
|
---|
97 | packingPlan3D.Invalidate();
|
---|
98 | packingPlan3D.Update();
|
---|
99 | }
|
---|
100 |
|
---|
101 | private void Content_QualityChanged(object sender, EventArgs e) {
|
---|
102 | if (InvokeRequired)
|
---|
103 | Invoke(new EventHandler(Content_QualityChanged), sender, e);
|
---|
104 | else {
|
---|
105 | binSelection.Items.Clear();
|
---|
106 | if (Content == null) {
|
---|
107 | packingPlan3D.InitializeContainer(0, 0, 0);
|
---|
108 | } else {
|
---|
109 | Content.Name = "Packing Plan";
|
---|
110 | int i = 0;
|
---|
111 | foreach (var bp in Content.BinPackings)
|
---|
112 | binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
|
---|
113 | binSelection.SelectedIndex = 0;
|
---|
114 | UpdateModel();
|
---|
115 | packingPlan3D.StartRendering();
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|