Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: fixed various problems: bugs in cloning, bugs in persistence, method names, various minor improvements of source code for readability.

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