Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: removed types for *PackingBin because PackingBins and PackingShapes have the same capabilities

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