#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;
namespace PackingPlanVisualizations {
public partial class PackingPlan3D : UserControl {
private PackingGame game;
private Thread gameLoopThread;
public PackingPlan3D() {
InitializeComponent();
if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
game = new PackingGame(this);
}
}
public void StartRendering() {
if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
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(
() => {
game.Run(this);
}
)
);
}
);
gameLoopThread.Start();
//this.BeginInvoke(new MethodInvoker( () => { game.Run(this); }));
}
#region Archive ..
//private BasicCuboidShape containerShape;
//private List itemShapes;
//private void RunGame() {
// if (containerShape == null)
// return;
// game = new PackingGame(this);
// game.InitializeContainer(containerShape);
// foreach (BasicCuboidShape shape in itemShapes)
// game.AddItemToContainer(shape);
// game.Run(this);
//}
#endregion
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();
if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
game.SetSize(this.Width, this.Height);
}
}
}
}