#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Windows.Forms; using System.Threading; using SharpDX.Toolkit; using SharpDX.Windows; namespace PackingPlanVisualizations { public partial class PackingPlan3D : UserControl { private readonly PackingGame game; private Thread gameLoopThread; private RenderForm renderForm; public PackingPlan3D() { InitializeComponent(); using (var proc = System.Diagnostics.Process.GetCurrentProcess()) { if (proc.ProcessName == "devenv") return; game = new PackingGame(this); } } public void StartRendering() { using (var proc = System.Diagnostics.Process.GetCurrentProcess()) { if (proc.ProcessName == "devenv") return; if (!game.IsRunning) StartGameLoop(); } } private void StartGameLoop() { if (game == null || game.IsRunning) return; gameLoopThread = new Thread( () => { //this.BeginInvoke(game.Run, this); this.Invoke( new MethodInvoker( () => { var renderForm = new RenderForm("bla"); var gameContext = new GameContext(renderForm); gameContext.UseApplicationDoEvents = false; game.Run(gameContext); } ) ); } ); gameLoopThread.Start(); //this.BeginInvoke(new MethodInvoker( () => { game.Run(this); })); } public void InitializeContainer(float width, float height, float depth) { //if (game != null) { // game.Exit(); // game.Dispose(); //} //game = new PackingGame(this); game.InitializeContainer(width, height, depth); //containerShape = new BasicCuboidShape(new Vector3 (width, height, depth)); } public void AddItemToContainer(float width, float height, float depth, float x, float y, float z, int itemNr) { AddItemToContainer(width, height, depth, x, y, z, itemNr, 0); } public void AddItemToContainer(float width, float height, float depth, float x, float y, float z, int itemNr, int material) { game.AddItemToContainer(width, height, depth, x, y, z, itemNr, material); //itemShapes.Add(new BasicCuboidShape (new Vector3 (width, height, depth), new Vector3 (x, y, z))); } public void SelectItem(int itemIndex) { game.SelectItem(itemIndex); } public void UnselectItem() { game.UnselectItem(); } private void PackingPlan3D_Resize(object sender, EventArgs e) { //this.Refresh(); using (var proc = System.Diagnostics.Process.GetCurrentProcess()) { if (proc.ProcessName == "devenv") return; game.SetSize(this.Width, this.Height); } } private void PackingPlan3D_MouseEnter(object sender, EventArgs e) { } private void PackingPlan3D_MouseLeave(object sender, EventArgs e) { } } }