Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14045 was 14045, checked in by gkronber, 8 years ago

#1966: removed types for *PackingBin because PackingBins and PackingShapes have the same capabilities

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