Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 15488 was 15488, checked in by rhanghof, 6 years ago

#2817:

  • Added line projection based bin packing
  • Added residual spaces to the view
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;
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
53
54        binSelection.SelectedIndex = 0;
55        ShowSelectedPacking();
56      }
57    }
58
59    private void ShowSelectedPacking() {
60      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
61      packingPlan3D.Packing = Content.Bins[currentBin];
62    }
63
64    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
65      itemSelection.SelectedIndex = -1;
66      itemSelection.Items.Clear();
67      extremePointsSelection.Items.Clear();
68      packingPlan3D.ResidualSpaces.Clear();
69      packingPlan3D.ExtremePoints.Clear();
70
71      // add items of this container
72      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
73      var packing = Content.Bins[currentBin];
74      foreach (var item in packing.Items) {
75        itemSelection.Items.Add(item.Key);
76      }
77      foreach (var ep in packing.ExtremePoints) {
78        var rs = ((BinPacking3D.BinPacking3D)packing).ResidualSpace[ep];
79        extremePointsSelection.Items.Add($"({ep.X}, {ep.Y}, {ep.Z})");
80        packingPlan3D.ExtremePoints.Add(ep);
81        packingPlan3D.ResidualSpaces.Add(ep, rs);
82      }
83
84      ShowSelectedPacking();
85    }
86
87    private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
88      int selectedItem = -1;
89      if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
90        packingPlan3D.SelectItem(selectedItem);
91      } else
92        packingPlan3D.ClearSelection();
93    }
94
95    private void extremePointsSelection_SelectedIndexChanged(object sender, EventArgs e) {
96      if (extremePointsSelection != null && extremePointsSelection.SelectedIndex >= 0) {
97        packingPlan3D.SelectExtremePoint(extremePointsSelection.SelectedIndex);
98      } else {
99        packingPlan3D.ClearSelection();
100      }
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.