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 { /// /// Main class which creates and starts the input, tuio and window objects. /// class BBIWARG { /// /// the input provider /// private InputProvider inputProvider; /// /// the input handler /// private InputHandler inputHandler; /// /// true iff the tuio server is enabled /// private bool tuioEnabled; /// /// the ip address for the tuio server /// private String tuioIP; /// /// the port for the tuio server /// private Int16 tuioPort; /// /// the tuio communicator /// private TuioCommunicator tuioCommunicator; /// /// true iff the debug window is enabled /// private bool debugWindowEnabled; /// /// the debug window /// private DebugWindow debugWindow; /// /// the thread the debug window runs in /// private Thread debugWindowThread; /// /// true iff the glasses window is enabled /// private bool glassesWindowEnabled; /// /// the thread the glasses window runs in /// private Thread glassesWindowThread; /// /// the glasses window /// private GlassesWindow glassesWindow; /// /// Starts the program. /// /// static void Main(string[] args) { Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight); BBIWARG program = new BBIWARG(args); program.run(); } /// /// Parses the command line arguments and depending on them creates the input, tuio and window objects. /// /// command line arguments 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)); } /// /// Runs the main program. /// public void run() { inputProvider.start(); } /// /// Creates the input provider. /// private void createInputProvider() { if (Parameters.InputSource == InputType.Movie) inputProvider = new VideoInputProvider(Parameters.InputMoviePath); else inputProvider = new InputProvider(); } /// /// Runs the debug window in its own thread. /// private void debugWindowThreadStart() { debugWindow = new DebugWindow(inputProvider, inputHandler, Parameters.DebugWindowTitle, Parameters.DebugWindowUpdateIntervall); Application.Run(debugWindow); } /// /// Runs the glasses window in its own thread. /// private void glassesWindowThreadStart() { glassesWindow = new GlassesWindow(inputProvider, inputHandler, Parameters.GlassesWindowTitle, Screen.AllScreens[1], Parameters.GlassesWindowUpdateInterval); Application.Run(glassesWindow); } /// /// Handles the event that the device has started by starting the enabled windows. /// /// event sender /// event arguments private void handleDeviceStartedEvent(object sender, EventArgs e) { if (debugWindowEnabled) debugWindowThread.Start(); if (glassesWindowEnabled) glassesWindowThread.Start(); } /// /// Parses the command line arguments and sets parameters depending on them. /// /// command line arguments 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; } } } }