1 | using System;
|
---|
2 | using System.Windows.Forms;
|
---|
3 | using HeuristicLab.Core.Views;
|
---|
4 | using HeuristicLab.MainForm;
|
---|
5 | using HeuristicLab.Problems.BinPacking.PackingPlans;
|
---|
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(RegularSimpleRotationPackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>), true)]
|
---|
16 | public partial class PackingPlan3DView : NamedItemView {
|
---|
17 |
|
---|
18 | public PackingPlan3DView() {
|
---|
19 | InitializeComponent();
|
---|
20 | this.nameTextBox.Text = "XX";
|
---|
21 | }
|
---|
22 |
|
---|
23 |
|
---|
24 | public new RegularSimpleRotationPackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
|
---|
25 | get { return (RegularSimpleRotationPackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; }
|
---|
26 | set { base.Content = value; }
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | protected override void OnContentChanged() {
|
---|
31 | base.OnContentChanged();
|
---|
32 | binSelection.Items.Clear();
|
---|
33 | if (Content == null) {
|
---|
34 | packingPlan3D.InitializeContainer(0, 0, 0);
|
---|
35 | } else {
|
---|
36 | Content.Name = "XX";
|
---|
37 | for (int i = 0; i < Content.NrOfBins; i++)
|
---|
38 | binSelection.Items.Add(i);
|
---|
39 | binSelection.SelectedIndex = 0;
|
---|
40 | UpdateModel();
|
---|
41 | packingPlan3D.StartRendering();
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void UpdateModel() {
|
---|
46 | int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
|
---|
47 | var bin = Content.PackingBinMeasures;
|
---|
48 | packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth);
|
---|
49 | int i = 0;
|
---|
50 | foreach (var item in Content.PackingItemMeasures) {
|
---|
51 | var position = Content.PackingItemPositions[i];
|
---|
52 | if (position.AssignedBin == currentBin)
|
---|
53 | packingPlan3D.AddItemToContainer(item.Width, item.Height, item.Depth, position.X, position.Y, position.Z, i);
|
---|
54 | i++;
|
---|
55 | }
|
---|
56 |
|
---|
57 | int selectedItem = -1;
|
---|
58 | if ((itemSelection != null && itemSelection.SelectedItem != null)) {
|
---|
59 | if (!Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
|
---|
60 | //if (itemSelection.SelectedItem.ToString().Equals("enum"))
|
---|
61 | // packingPlan3D.StartItemEnumeration();
|
---|
62 | selectedItem = -1;
|
---|
63 | } else
|
---|
64 | packingPlan3D.SelectItem(selectedItem);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
69 | UpdateModel();
|
---|
70 |
|
---|
71 | itemSelection.SelectedIndex = -1;
|
---|
72 | itemSelection.Items.Clear();
|
---|
73 | int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
|
---|
74 | for (int i = 0; i < Content.PackingItemPositions.Count; i++) {
|
---|
75 | if (Content.PackingItemPositions[i].AssignedBin == currentBin)
|
---|
76 | itemSelection.Items.Add(i);
|
---|
77 | }
|
---|
78 | itemSelection.Items.Add("enum");
|
---|
79 |
|
---|
80 | packingPlan3D.Invalidate();
|
---|
81 | packingPlan3D.Update();
|
---|
82 | }
|
---|
83 |
|
---|
84 | private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
85 | UpdateModel();
|
---|
86 | packingPlan3D.Invalidate();
|
---|
87 | packingPlan3D.Update();
|
---|
88 | }
|
---|
89 |
|
---|
90 | }
|
---|
91 | }
|
---|