Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan3DView.cs @ 13554

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

#1966 work in progress WPF control to visualize packings

File size: 4.7 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("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      base.DeregisterContentEvents();
42    }
43    protected override void RegisterContentEvents() {
44      base.RegisterContentEvents();
45    }
46
47    public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
48      get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; }
49      set { base.Content = value; }
50    }
51
52
53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      binSelection.Items.Clear();
56      if (Content == null) {
57         packingPlan3D.Clear();
58      } else {
59        int i = 0;
60        foreach (var bp in Content.BinPackings)
61          binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
62
63        binSelection.SelectedIndex = 0;
64        UpdateModel();
65        packingPlan3D.Focus(); // for mouse wheel?
66        // packingPlan3D.StartRendering();
67      }
68    }
69
70    private void UpdateModel() {
71      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
72      packingPlan3D.ShowContainer(Content.BinPackings[currentBin]);
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      packingPlan3D.ShowContainer(Content.BinPackings[currentBin]);
92
93    }
94
95    private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
96      UpdateModel();
97
98      int selectedItem = -1;
99      if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
100        packingPlan3D.SelectItem(selectedItem);
101      } else
102        packingPlan3D.ClearSelection();
103    }
104
105    // private void Content_QualityChanged(object sender, EventArgs e) {
106    //   if (InvokeRequired)
107    //     Invoke(new EventHandler(Content_QualityChanged), sender, e);
108    //   else {
109    //     binSelection.Items.Clear();
110    //     if (Content == null) {
111    //       packingPlan3D.InitializeContainer(0, 0, 0);
112    //     } else {
113    //       int i = 0;
114    //       foreach (var bp in Content.BinPackings)
115    //         binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
116    //       binSelection.SelectedIndex = 0;
117    //       UpdateModel();
118    //       // packingPlan3D.StartRendering();
119    //     }
120    //   }
121    // }
122  }
123}
Note: See TracBrowser for help on using the repository browser.