Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: implemented visualization for 2d packings

File size: 2.6 KB
Line 
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;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
26using HeuristicLab.Problems.BinPacking.PackingItem;
27using HeuristicLab.Problems.BinPacking.PackingBin;
28using HeuristicLab.Problems.BinPacking.Dimensions;
29
30namespace HeuristicLab.Problems.BinPacking.Views {
31  [View("2-dimensional packing plan view")]
32  [Content(typeof(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>), true)]
33  public partial class PackingPlan2DView : ItemView {
34
35    public PackingPlan2DView() {
36      InitializeComponent();
37    }
38
39    public new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Content {
40      get { return (PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>)base.Content; }
41      set { base.Content = value; }
42    }
43
44    protected override void OnContentChanged() {
45      base.OnContentChanged();
46      binSelection.Items.Clear();
47      if (Content == null) {
48        ClearState();
49      } else {
50        for (int i = 0; i < Content.NrOfBins; i++)
51          binSelection.Items.Add(i);
52        UpdateState(Content);
53      }
54    }
55
56    private void ClearState() {
57      container2DView.Packing = null;
58    }
59
60    private void UpdateState(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {
61      int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
62      container2DView.Packing = plan.BinPackings[currentBin];
63    }
64
65    private void binSelection_SelectedIndexChanged(object sender, EventArgs e) {
66      UpdateState(Content);
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.