Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14046 was 14046, checked in by gkronber, 8 years ago

#1966: unified namespaces

File size: 3.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.Encodings.PackingEncoding;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.BinPacking3D;
27
28namespace HeuristicLab.Problems.BinPacking.Views {
29  [View("3-dimensional packing plan View")]
30  [Content(typeof(PackingPlan<ThreeDimensionalPacking, CuboidPackingShape, CuboidPackingItem>), true)]
31  public partial class PackingPlan3DView : ItemView {
32
33    public PackingPlan3DView() {
34      InitializeComponent();
35    }
36
37    public new PackingPlan<ThreeDimensionalPacking, CuboidPackingShape, CuboidPackingItem> Content {
38      get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingShape, CuboidPackingItem>)base.Content; }
39      set { base.Content = value; }
40    }
41
42
43    protected override void OnContentChanged() {
44      base.OnContentChanged();
45      binSelection.Items.Clear();
46      if (Content == null) {
47        packingPlan3D.Packing = null;
48      } else {
49        int i = 0;
50        foreach (var bp in Content.BinPackings)
51          binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
52
53        binSelection.SelectedIndex = 0;
54        ShowSelectedPacking();
55      }
56    }
57
58    private void ShowSelectedPacking() {
59      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
60      packingPlan3D.Packing = Content.BinPackings[currentBin];
61    }
62
63    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
64      itemSelection.SelectedIndex = -1;
65      itemSelection.Items.Clear();
66
67      // add items of this container
68      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
69      var packing = Content.BinPackings[currentBin];
70      foreach (var item in packing.ItemMeasures) {
71        itemSelection.Items.Add(item.Key);
72      }
73
74      ShowSelectedPacking();
75    }
76
77    private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
78      int selectedItem = -1;
79      if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
80        packingPlan3D.SelectItem(selectedItem);
81      } else
82        packingPlan3D.ClearSelection();
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.