[14162] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14162] | 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.Problems.BinPacking3D;
|
---|
| 26 |
|
---|
| 27 | namespace 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;
|
---|
[14170] | 49 | foreach (var bp in Content.Bins)
|
---|
[14162] | 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;
|
---|
[14170] | 59 | packingPlan3D.Packing = Content.Bins[currentBin];
|
---|
[14162] | 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;
|
---|
[14170] | 68 | var packing = Content.Bins[currentBin];
|
---|
[14162] | 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 | }
|
---|