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("2-dimensional packing plan View")]
|
---|
32 | [Content(typeof(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>), true)]
|
---|
33 | public partial class PackingPlan2DView : NamedItemView {
|
---|
34 |
|
---|
35 | public PackingPlan2DView() {
|
---|
36 | InitializeComponent();
|
---|
37 | }
|
---|
38 |
|
---|
39 | protected override void DeregisterContentEvents() {
|
---|
40 | Content.QualityChanged -= new EventHandler(Content_QualityChanged);
|
---|
41 | base.DeregisterContentEvents();
|
---|
42 | }
|
---|
43 | protected override void RegisterContentEvents() {
|
---|
44 | base.RegisterContentEvents();
|
---|
45 | Content.QualityChanged += new EventHandler(Content_QualityChanged);
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | public new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
|
---|
50 | get { return (PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>)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 | Redraw();
|
---|
60 | } else {
|
---|
61 | for (int i = 0; i < Content.NrOfBins; i++)
|
---|
62 | binSelection.Items.Add(i);
|
---|
63 | Redraw(Content);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | private void Redraw() {
|
---|
69 | packingPlan2D.InitializeContainer(0, 0);
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void Redraw(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {
|
---|
73 | int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
|
---|
74 | var bin = plan.BinPackings[currentBin].BinMeasures;
|
---|
75 | packingPlan2D.InitializeContainer(bin.Width, bin.Height);
|
---|
76 | foreach (var entry in plan.BinPackings[currentBin].ItemMeasures) {
|
---|
77 | var position = plan.BinPackings[currentBin].ItemPositions[entry.Key];
|
---|
78 | packingPlan2D.AddItemToContainer(
|
---|
79 | position.Rotated ? entry.Value.Height : entry.Value.Width,
|
---|
80 | position.Rotated ? entry.Value.Width : entry.Value.Height,
|
---|
81 | position.X, position.Y, entry.Key.ToString());
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
86 | Redraw(Content);
|
---|
87 | packingPlan2D.Refresh();
|
---|
88 | packingPlan2D.Refresh();
|
---|
89 | packingPlan2D.Refresh();
|
---|
90 | packingPlan2D.Refresh();
|
---|
91 | packingPlan2D.Refresh();
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 | private void Content_QualityChanged(object sender, EventArgs e) {
|
---|
97 | if (InvokeRequired)
|
---|
98 | Invoke(new EventHandler(Content_QualityChanged), sender, e);
|
---|
99 | else {
|
---|
100 | binSelection.Items.Clear();
|
---|
101 | if (Content == null) {
|
---|
102 | Redraw();
|
---|
103 | } else {
|
---|
104 | for (int i = 0; i < Content.NrOfBins; i++)
|
---|
105 | binSelection.Items.Add(i);
|
---|
106 | Redraw(Content);
|
---|
107 | }
|
---|
108 | packingPlan2D.Refresh();
|
---|
109 | packingPlan2D.Refresh();
|
---|
110 | packingPlan2D.Refresh();
|
---|
111 | packingPlan2D.Refresh();
|
---|
112 | packingPlan2D.Refresh();
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|