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