Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13348 was 13032, checked in by gkronber, 9 years ago

#1966:

  • removed unused using
  • added/updated license headers
File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
26using HeuristicLab.Problems.BinPacking.PackingItem;
27using HeuristicLab.Problems.BinPacking.PackingBin;
28using HeuristicLab.Problems.BinPacking.Dimensions;
29
30namespace HeuristicLab.Problems.BinPacking.Views {
31  [View("3-dimensional packing plan View")]
32  [Content(typeof(PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>), true)]
33  public partial class PackingPlan3DView : NamedItemView {
34
35    public PackingPlan3DView() {
36      InitializeComponent();
37      this.nameTextBox.Text = "Packing Plan";
38    }
39
40
41    protected override void DeregisterContentEvents() {
42      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
43      base.DeregisterContentEvents();
44    }
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47      Content.QualityChanged += new EventHandler(Content_QualityChanged);
48    }
49
50    public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
51      get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; }
52      set { base.Content = value; }
53    }
54
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      binSelection.Items.Clear();
59      if (Content == null) {
60        packingPlan3D.InitializeContainer(0, 0, 0);
61      } else {
62        Content.Name = "Packing Plan";
63        int i = 0;
64        foreach (var bp in Content.BinPackings)
65          binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
66
67        binSelection.SelectedIndex = 0;
68        UpdateModel();
69        packingPlan3D.StartRendering();
70      }
71    }
72
73    private void UpdateModel() {
74      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
75      var bin = Content.BinPackings[currentBin].BinMeasures;
76      packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth);
77      foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) {
78        var position = Content.BinPackings[currentBin].ItemPositions[entry.Key];
79        packingPlan3D.AddItemToContainer(
80        position.Rotated ? entry.Value.Depth : entry.Value.Width,
81        entry.Value.Height,
82        position.Rotated ? entry.Value.Width : entry.Value.Depth,
83        position.X, position.Y, position.Z, entry.Key, entry.Value.Material);
84      }
85    }
86
87    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
88      UpdateModel();
89
90      itemSelection.SelectedIndex = -1;
91      itemSelection.Items.Clear();
92      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
93      //for (int i = 0; i < Content.PackingItemPositions.Count; i++) {
94      //  if (Content.PackingItemPositions[i].AssignedBin == currentBin)
95      //    itemSelection.Items.Add(i);
96      //}
97      foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) {
98        itemSelection.Items.Add(entry.Key);
99      }
100
101      packingPlan3D.Invalidate();
102      packingPlan3D.Update();
103    }
104
105    private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
106      UpdateModel();
107
108      int selectedItem = -1;
109      if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
110        packingPlan3D.SelectItem(selectedItem);
111      } else     
112        packingPlan3D.UnselectItem();
113
114      packingPlan3D.Invalidate();
115      packingPlan3D.Update();
116    }
117
118    private void Content_QualityChanged(object sender, EventArgs e) {
119      if (InvokeRequired)
120        Invoke(new EventHandler(Content_QualityChanged), sender, e);
121      else {
122        binSelection.Items.Clear();
123        if (Content == null) {
124          packingPlan3D.InitializeContainer(0, 0, 0);
125        } else {
126          Content.Name = "Packing Plan";
127          int i = 0;
128          foreach (var bp in Content.BinPackings)
129            binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
130          binSelection.SelectedIndex = 0;
131          UpdateModel();
132          packingPlan3D.StartRendering();
133        }
134      }
135    } 
136  }
137}
Note: See TracBrowser for help on using the repository browser.