Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.cs @ 15400

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

#2641:

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