Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.cs @ 15816

Last change on this file since 15816 was 15554, checked in by rhanghof, 7 years ago

#2817:

  • Unittests
  • Bugfixes on the line projection based extreme point creation method
File size: 3.8 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;
26using System.Collections.Generic;
27
28namespace HeuristicLab.Problems.BinPacking.Views {
29  [View("3-dimensional packing plan View")]
30  [Content(typeof(PackingPlan<BinPacking3D.PackingPosition, PackingShape, PackingItem>), true)]
31  public partial class PackingPlan3DView : ItemView {
32
33    public PackingPlan3DView() {
34      InitializeComponent();
35    }
36
37    public new PackingPlan<BinPacking3D.PackingPosition, PackingShape, PackingItem> Content {
38      get { return (PackingPlan<BinPacking3D.PackingPosition, PackingShape, PackingItem>)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.Bins) {
51          binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
52        }
53
54
55        binSelection.SelectedIndex = 0;
56        ShowSelectedPacking();
57      }
58    }
59
60    private void ShowSelectedPacking() {
61      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
62      packingPlan3D.Packing = Content.Bins[currentBin];
63    }
64
65    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
66      itemSelection.SelectedIndex = -1;
67      itemSelection.Items.Clear();
68      extremePointsSelection.Items.Clear();
69      packingPlan3D.ResidualSpaces.Clear();
70      packingPlan3D.ExtremePoints.Clear();
71
72      // add items of this container
73      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
74      var packing = Content.Bins[currentBin];
75      foreach (var item in packing.Items) {
76        itemSelection.Items.Add(item.Key);
77      }
78      foreach (var extremPoint in ((BinPacking3D.BinPacking3D)packing).ExtremePoints) {
79        var ep = extremPoint.Key;
80        extremePointsSelection.Items.Add($"({ep.X}, {ep.Y}, {ep.Z})");
81        packingPlan3D.ExtremePoints.Add(ep);
82        packingPlan3D.ResidualSpaces.Add(ep, extremPoint.Value as IList<ResidualSpace>);
83      }
84
85      ShowSelectedPacking();
86    }
87
88    private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
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.ClearSelection();
94    }
95
96    private void extremePointsSelection_SelectedIndexChanged(object sender, EventArgs e) {
97      if (extremePointsSelection != null && extremePointsSelection.SelectedIndex >= 0) {
98        packingPlan3D.SelectExtremePoint(extremePointsSelection.SelectedIndex);
99      } else {
100        packingPlan3D.ClearSelection();
101      }
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.