source: branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/PackingPlan3D.cs @ 13465

Last change on this file since 13465 was 13465, checked in by gkronber, 5 years ago

#1966: general code cleanup ...

File size: 3.3 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 System.Windows.Forms;
24using System.Threading;
25
26
27namespace PackingPlanVisualizations {
28  public partial class PackingPlan3D : UserControl {
29    private PackingGame game;
30    private Thread gameLoopThread;
31
32    public PackingPlan3D() {
33      InitializeComponent();
34      if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
35        game = new PackingGame(this);
36      }
37    }
38
39
40    public void StartRendering() {
41      if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
42        if (!game.IsRunning)
43          StartGameLoop();
44      }
45    }
46
47    private void StartGameLoop() {
48      if (game == null || game.IsRunning)
49        return;
50      gameLoopThread =
51        new Thread(
52            () => {
53              //this.BeginInvoke(game.Run, this);
54              this.Invoke(
55                new MethodInvoker(
56                  () => {
57                    game.Run(this);
58                  }
59                )
60              );
61            }
62        );
63
64      gameLoopThread.Start();
65      //this.BeginInvoke(new MethodInvoker( () => {  game.Run(this);  }));
66    }
67
68
69    public void InitializeContainer(float width, float height, float depth) {
70      //if (game != null) {
71      //  game.Exit();
72      //  game.Dispose();
73      //}
74      //game = new PackingGame(this);
75      game.InitializeContainer(width, height, depth);
76      //containerShape = new BasicCuboidShape(new Vector3 (width, height, depth));
77    }
78
79    public void AddItemToContainer(float width, float height, float depth, float x, float y, float z, int itemNr) {
80      AddItemToContainer(width, height, depth, x, y, z, itemNr, 0);
81    }
82    public void AddItemToContainer(float width, float height, float depth, float x, float y, float z, int itemNr, int material) {
83      game.AddItemToContainer(width, height, depth, x, y, z, itemNr, material);
84      //itemShapes.Add(new BasicCuboidShape (new Vector3 (width, height, depth), new Vector3 (x, y, z)));
85    }
86
87    public void SelectItem(int itemIndex) {
88      game.SelectItem(itemIndex);
89    }
90    public void UnselectItem() {
91      game.UnselectItem();
92    }
93
94
95    private void PackingPlan3D_Resize(object sender, EventArgs e) {
96      //this.Refresh();                                         
97      if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
98        game.SetSize(this.Width, this.Height);
99      }
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.