using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; using System.Linq; using System.Text; using System.Net; using System.Windows; using System.Windows.Forms; using bbiwarg.Output.DebugOutput; using bbiwarg.Output.GlassesOutput; using bbiwarg.Input.InputProviding; using bbiwarg.Input.InputHandling; using bbiwarg.TUIO; namespace bbiwarg { class BBIWARG { private InputProvider inputProvider; private InputHandler inputHandler; private bool tuioEnabled; private String tuioIP; private Int16 tuioPort; private TuioCommunicator tuioCommunicator; private bool debugWindowEnabled; private DebugWindow debugWindow; private Thread debugWindowThread; private bool glassesWindowEnabled; private Thread glassesWindowThread; private GlassesWindow glassesWindow; static void Main(string[] args) { Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight); BBIWARG program = new BBIWARG(args); program.run(); } public BBIWARG(string[] args) { handleArgs(args); debugWindowEnabled = Parameters.DebugWindowEnabled; glassesWindowEnabled = Parameters.GlassesWindowEnabled && Screen.AllScreens.Count() >= 2; // inputProvider createInputProvider(); inputProvider.initialize(); inputProvider.DeviceStartedEvent += handleDeviceStartedEvent; // inputHandler inputHandler = new InputHandler(inputProvider); // tuioCommunicator if (tuioEnabled) { tuioCommunicator = new TuioCommunicator(tuioIP, tuioPort); inputHandler.NewProcessedFrameEvent += tuioCommunicator.handleNewFrameData; } // debug output if (debugWindowEnabled) debugWindowThread = new Thread(new ThreadStart(debugWindowThreadStart)); // glasses output if (glassesWindowEnabled) glassesWindowThread = new Thread(new ThreadStart(glassesWindowThreadStart)); } public void run() { inputProvider.start(); } private void createInputProvider() { if (Parameters.InputSource == InputType.Movie) inputProvider = new VideoInputProvider(Parameters.InputMoviePath); else inputProvider = new InputProvider(); } private void debugWindowThreadStart() { debugWindow = new DebugWindow(inputProvider, inputHandler, Parameters.DebugWindowTitle, Parameters.DebugWindowUpdateIntervall); Application.Run(debugWindow); } private void glassesWindowThreadStart() { glassesWindow = new GlassesWindow(inputProvider, inputHandler, Parameters.GlassesWindowTitle, Screen.AllScreens[1], Parameters.GlassesWindowUpdateInterval); Application.Run(glassesWindow); } private void handleDeviceStartedEvent(object sender, EventArgs e) { if (debugWindowEnabled) debugWindowThread.Start(); if (glassesWindowEnabled) glassesWindowThread.Start(); } private void handleArgs(String[] args) { if (args.Length > 0) { tuioEnabled = true; String ipString = null; String portString = null; if (args.Length == 2) { ipString = args[0]; portString = args[1]; } else if (args.Length == 1) { String[] parts = args[0].Split(':'); ipString = parts[0]; if (parts.Length == 2) portString = parts[1]; } while (!TuioCommunicator.tryParseIPAddress(ipString, out tuioIP)) { Console.WriteLine("Please insert the TUIO-Client's IP (Default is " + Parameters.TuioDefaultIP + "):"); ipString = Console.ReadLine(); } Console.WriteLine("TUIO-IP is set to:" + tuioIP); while (!TuioCommunicator.tryParsePort(portString, out tuioPort)) { Console.WriteLine("Please insert the TUIO-Client's Port (Default is " + Parameters.TuioDefaultPort + "):"); portString = Console.ReadLine(); } Console.WriteLine("TUIO-PORT is set to:" + tuioPort); } else { tuioEnabled = Parameters.TuioEnabledByDefault; tuioIP = Parameters.TuioDefaultIP; tuioPort = Parameters.TuioDefaultPort; } } } }