Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan2DView.cs @ 13462

Last change on this file since 13462 was 13462, checked in by gkronber, 9 years ago

#1966: PackingPlan is just an Item not a ParameterizedNamedItem

File size: 4.1 KB
RevLine 
[13032]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
22using System;
[9348]23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
[9440]25using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
[9348]26using HeuristicLab.Problems.BinPacking.PackingItem;
27using HeuristicLab.Problems.BinPacking.PackingBin;
28using HeuristicLab.Problems.BinPacking.Dimensions;
29
30namespace HeuristicLab.Problems.BinPacking.Views {
[13462]31  [View("2-dimensional packing plan view")]
[9440]32  [Content(typeof(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>), true)]
[13462]33  public partial class PackingPlan2DView : ItemView {
[9348]34
35    public PackingPlan2DView() {
36      InitializeComponent();
[9495]37    }       
38
39    protected override void DeregisterContentEvents() {
40      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
41      base.DeregisterContentEvents();
[9348]42    }
[9495]43    protected override void RegisterContentEvents() {
44      base.RegisterContentEvents();
45      Content.QualityChanged += new EventHandler(Content_QualityChanged);
46    }
[9348]47
48
[9440]49    public new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
50      get { return (PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>)base.Content; }
[9348]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
[9440]72    private void Redraw(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {     
[9348]73      int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
[9593]74      var bin = plan.BinPackings[currentBin].BinMeasures;
[9348]75      packingPlan2D.InitializeContainer(bin.Width, bin.Height);
[9593]76      foreach (var entry in plan.BinPackings[currentBin].ItemMeasures) {
77        var position = plan.BinPackings[currentBin].ItemPositions[entry.Key];
[9440]78          packingPlan2D.AddItemToContainer(
[9593]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());
[9348]82      }
83    }
84
85    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
86      Redraw(Content);
[9593]87      packingPlan2D.Refresh();
88      packingPlan2D.Refresh();
89      packingPlan2D.Refresh();
90      packingPlan2D.Refresh();
91      packingPlan2D.Refresh();
[9348]92    }
93
[9495]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        }
[9593]108        packingPlan2D.Refresh();
109        packingPlan2D.Refresh();
110        packingPlan2D.Refresh();
111        packingPlan2D.Refresh();
112        packingPlan2D.Refresh();
[9495]113      }
114    } 
[9348]115  }
116}
Note: See TracBrowser for help on using the repository browser.