Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan3DView.cs @ 9495

Last change on this file since 9495 was 9495, checked in by jhelm, 11 years ago

#1966: Did some major refactoring in Decoder-classes; Added MoveEvaluator classes for different encodings and dimensions; Added new crossover-class for MCV encoding;

File size: 4.2 KB
Line 
1using System;
2using System.Windows.Forms;
3using HeuristicLab.Core.Views;
4using HeuristicLab.MainForm;
5using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
6using HeuristicLab.Problems.BinPacking.Interfaces;
7using HeuristicLab.Problems.BinPacking.PackingItem;
8using HeuristicLab.Problems.BinPacking.PackingBin;
9using HeuristicLab.Problems.BinPacking.Dimensions;
10using HeuristicLab.Core;
11using HeuristicLab.Data;
12
13namespace 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        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;
56      var bin = Content.GetPackingBinMeasuresForBinNr(currentBin);
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)
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);
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();
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
95      packingPlan3D.Invalidate();
96      packingPlan3D.Update();
97    }
98
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    } 
116  }
117}
Note: See TracBrowser for help on using the repository browser.