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 |
|
---|
40 | protected override void DeregisterContentEvents() {
|
---|
41 | Content.QualityChanged -= new EventHandler(Content_QualityChanged);
|
---|
42 | base.DeregisterContentEvents();
|
---|
43 | }
|
---|
44 | protected override void RegisterContentEvents() {
|
---|
45 | base.RegisterContentEvents();
|
---|
46 | Content.QualityChanged += new EventHandler(Content_QualityChanged);
|
---|
47 | }
|
---|
48 |
|
---|
49 | public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
|
---|
50 | get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; }
|
---|
51 | set { base.Content = value; }
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | protected override void OnContentChanged() {
|
---|
56 | base.OnContentChanged();
|
---|
57 | binSelection.Items.Clear();
|
---|
58 | if (Content == null) {
|
---|
59 | packingPlan3D.InitializeContainer(0, 0, 0);
|
---|
60 | } else {
|
---|
61 | int i = 0;
|
---|
62 | foreach (var bp in Content.BinPackings)
|
---|
63 | binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
|
---|
64 |
|
---|
65 | binSelection.SelectedIndex = 0;
|
---|
66 | UpdateModel();
|
---|
67 | packingPlan3D.StartRendering();
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void UpdateModel() {
|
---|
72 | int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
|
---|
73 | var bin = Content.BinPackings[currentBin].BinMeasures;
|
---|
74 | packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth);
|
---|
75 | foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) {
|
---|
76 | var position = Content.BinPackings[currentBin].ItemPositions[entry.Key];
|
---|
77 | packingPlan3D.AddItemToContainer(
|
---|
78 | position.Rotated ? entry.Value.Depth : entry.Value.Width,
|
---|
79 | entry.Value.Height,
|
---|
80 | position.Rotated ? entry.Value.Width : entry.Value.Depth,
|
---|
81 | position.X, position.Y, position.Z, entry.Key, entry.Value.Material);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
86 | UpdateModel();
|
---|
87 |
|
---|
88 | itemSelection.SelectedIndex = -1;
|
---|
89 | itemSelection.Items.Clear();
|
---|
90 | int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
|
---|
91 | //for (int i = 0; i < Content.PackingItemPositions.Count; i++) {
|
---|
92 | // if (Content.PackingItemPositions[i].AssignedBin == currentBin)
|
---|
93 | // itemSelection.Items.Add(i);
|
---|
94 | //}
|
---|
95 | foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) {
|
---|
96 | itemSelection.Items.Add(entry.Key);
|
---|
97 | }
|
---|
98 |
|
---|
99 | packingPlan3D.Invalidate();
|
---|
100 | packingPlan3D.Update();
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
104 | UpdateModel();
|
---|
105 |
|
---|
106 | int selectedItem = -1;
|
---|
107 | if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
|
---|
108 | packingPlan3D.SelectItem(selectedItem);
|
---|
109 | } else
|
---|
110 | packingPlan3D.UnselectItem();
|
---|
111 |
|
---|
112 | packingPlan3D.Invalidate();
|
---|
113 | packingPlan3D.Update();
|
---|
114 | }
|
---|
115 |
|
---|
116 | private void Content_QualityChanged(object sender, EventArgs e) {
|
---|
117 | if (InvokeRequired)
|
---|
118 | Invoke(new EventHandler(Content_QualityChanged), sender, e);
|
---|
119 | else {
|
---|
120 | binSelection.Items.Clear();
|
---|
121 | if (Content == null) {
|
---|
122 | packingPlan3D.InitializeContainer(0, 0, 0);
|
---|
123 | } else {
|
---|
124 | int i = 0;
|
---|
125 | foreach (var bp in Content.BinPackings)
|
---|
126 | binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
|
---|
127 | binSelection.SelectedIndex = 0;
|
---|
128 | UpdateModel();
|
---|
129 | packingPlan3D.StartRendering();
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|