private void OpenExportWindow()
		{
			if (exportWindowIsOpen == false)
			{
				exportingWindow = new ExportPrintItemWindow(this.printItemWrapper);
				this.exportWindowIsOpen = true;
				exportingWindow.Closed += new EventHandler(ExportLibraryItemWindow_Closed);
				exportingWindow.ShowAsSystemWindow ();
			}
			else 
			{
				if (exportingWindow != null)
				{
					exportingWindow.BringToFront ();
				}
			}

		}
		private MatterControlApplication(double width, double height, out bool showWindow)
			: base(width, height)
		{
			Name = "MatterControl";
			showWindow = false;

			// set this at startup so that we can tell next time if it got set to true in close
			UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1;

			this.commandLineArgs = Environment.GetCommandLineArgs();
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			bool forceSofwareRendering = false;

			for (int currentCommandIndex = 0; currentCommandIndex < commandLineArgs.Length; currentCommandIndex++)
			{
				string command = commandLineArgs[currentCommandIndex];
				string commandUpper = command.ToUpper();
				switch (commandUpper)
				{
					case "TEST":
						CheckKnownAssemblyConditionalCompSymbols();
						return;

					case "FORCE_SOFTWARE_RENDERING":
						forceSofwareRendering = true;
						GL.ForceSoftwareRendering();
						break;

					case "MHSERIAL_TO_ANDROID":
						{
							Dictionary<string, string> vidPid_NameDictionary = new Dictionary<string, string>();
							string[] MHSerialLines = File.ReadAllLines(Path.Combine("..", "..", "StaticData", "Drivers", "MHSerial", "MHSerial.inf"));
							foreach (string line in MHSerialLines)
							{
								if (line.Contains("=DriverInstall,"))
								{
									string name = Regex.Match(line, "%(.*).name").Groups[1].Value;
									string vid = Regex.Match(line, "VID_(.*)&PID").Groups[1].Value;
									string pid = Regex.Match(line, "PID_([0-9a-fA-F]+)").Groups[1].Value;
									string vidPid = "{0},{1}".FormatWith(vid, pid);
									if (!vidPid_NameDictionary.ContainsKey(vidPid))
									{
										vidPid_NameDictionary.Add(vidPid, name);
									}
								}
							}

							using (StreamWriter deviceFilter = new StreamWriter("deviceFilter.txt"))
							{
								using (StreamWriter serialPort = new StreamWriter("serialPort.txt"))
								{
									foreach (KeyValuePair<string, string> vidPid_Name in vidPid_NameDictionary)
									{
										string[] vidPid = vidPid_Name.Key.Split(',');
										int vid = Int32.Parse(vidPid[0], System.Globalization.NumberStyles.HexNumber);
										int pid = Int32.Parse(vidPid[1], System.Globalization.NumberStyles.HexNumber);
										serialPort.WriteLine("customTable.AddProduct(0x{0:X4}, 0x{1:X4}, cdcDriverType);  // {2}".FormatWith(vid, pid, vidPid_Name.Value));
										deviceFilter.WriteLine("<!-- {2} -->\n<usb-device vendor-id=\"{0}\" product-id=\"{1}\" />".FormatWith(vid, pid, vidPid_Name.Value));
									}
								}
							}
						}
						return;

					case "CLEAR_CACHE":
						AboutWidget.DeleteCacheData();
						break;

					case "SHOW_MEMORY":
						ShowMemoryUsed = true;
						break;

					case "DO_GC_COLLECT_EVERY_DRAW":
						ShowMemoryUsed = true;
						DoCGCollectEveryDraw = true;
						break;

					case "CREATE_AND_SELECT_PRINTER":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							currentCommandIndex++;
							string argument = commandLineArgs[currentCommandIndex];
							string[] printerData = argument.Split(',');
							if (printerData.Length >= 2)
							{
								Printer ActivePrinter = new Printer();

								ActivePrinter.Name = "Auto: {0} {1}".FormatWith(printerData[0], printerData[1]);
								ActivePrinter.Make = printerData[0];
								ActivePrinter.Model = printerData[1];

								if (printerData.Length == 3)
								{
									ActivePrinter.ComPort = printerData[2];
								}

								PrinterSetupStatus test = new PrinterSetupStatus(ActivePrinter);
								test.LoadDefaultSliceSettings(ActivePrinter.Make, ActivePrinter.Model);
								ActivePrinterProfile.Instance.ActivePrinter = ActivePrinter;
							}
						}

						break;

					case "CONNECT_TO_PRINTER":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter();
						}
						break;

					case "START_PRINT":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							bool hasBeenRun = false;
							currentCommandIndex++;
							string fullPath = commandLineArgs[currentCommandIndex];
							QueueData.Instance.RemoveAll();
							if (!string.IsNullOrEmpty(fullPath))
							{
								string fileName = Path.GetFileNameWithoutExtension(fullPath);
								QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(fileName, fullPath)));
								PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((sender, e) =>
								{
									if (!hasBeenRun && PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Connected)
									{
										hasBeenRun = true;
										PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible();
									}
								}, ref unregisterEvent);
							}
						}
						break;

					case "SLICE_AND_EXPORT_GCODE":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							currentCommandIndex++;
							string fullPath = commandLineArgs[currentCommandIndex];
							QueueData.Instance.RemoveAll();
							if (!string.IsNullOrEmpty(fullPath))
							{
								string fileName = Path.GetFileNameWithoutExtension(fullPath);
								PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(fileName, fullPath));
								QueueData.Instance.AddItem(printItemWrapper);

								SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);
								ExportPrintItemWindow exportForTest = new ExportPrintItemWindow(printItemWrapper);
								exportForTest.ExportGcodeCommandLineUtility(fileName);
							}
						}
						break;
				}

				if (MeshFileIo.ValidFileExtensions().Contains(Path.GetExtension(command).ToUpper()))
				{
					// If we are the only instance running then do nothing.
					// Else send these to the running instance so it can load them.
				}
			}

			//WriteTestGCodeFile();
#if !DEBUG
			if (File.Exists("RunUnitTests.txt"))
#endif
			{
#if IS_WINDOWS_FORMS
				if (!Clipboard.IsInitialized)
				{
					Clipboard.SetSystemClipboard(new WindowsFormsClipboard());
				}
#endif

				// you can turn this on to debug some bounds issues
				//GuiWidget.DebugBoundsUnderMouse = true;
			}

			GuiWidget.DefaultEnforceIntegerBounds = true;

			if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
			{
				TextWidget.GlobalPointSizeScaleRatio = 1.3;
			}

			using (new PerformanceTimer("Startup", "MainView"))
			{
				this.AddChild(ApplicationController.Instance.MainView);
			}
			this.MinimumSize = minSize;
			this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off

#if false // this is to test freeing gcodefile memory
			Button test = new Button("test");
			test.Click += (sender, e) =>
			{
				//MatterHackers.GCodeVisualizer.GCodeFile gcode = new GCodeVisualizer.GCodeFile();
				//gcode.Load(@"C:\Users\lbrubaker\Downloads\drive assy.gcode");
				SystemWindow window = new SystemWindow(100, 100);
				window.ShowAsSystemWindow();
			};
			allControls.AddChild(test);
#endif
			this.AnchorAll();

			if (!forceSofwareRendering)
			{
				UseOpenGL = true;
			}
			string version = "1.4";

			Title = "MatterControl {0}".FormatWith(version);
			if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0)
			{
				Title = Title + " - {1}".FormatWith(version, OemSettings.Instance.WindowTitleExtra);
			}

			UiThread.RunOnIdle(CheckOnPrinter);

			string desktopPosition = ApplicationSettings.Instance.get("DesktopPosition");
			if (desktopPosition != null && desktopPosition != "")
			{
				string[] sizes = desktopPosition.Split(',');

				//If the desktop position is less than -10,-10, override
				int xpos = Math.Max(int.Parse(sizes[0]), -10);
				int ypos = Math.Max(int.Parse(sizes[1]), -10);

				DesktopPosition = new Point2D(xpos, ypos);
			}

			showWindow = true;
		}
        private MatterControlApplication(double width, double height, out bool showWindow)
            : base(width, height)
        {
            Name       = "MatterControl";
            showWindow = false;

            // set this at startup so that we can tell next time if it got set to true in close
            UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1;

            this.commandLineArgs = Environment.GetCommandLineArgs();
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            bool forceSofwareRendering = false;

            for (int currentCommandIndex = 0; currentCommandIndex < commandLineArgs.Length; currentCommandIndex++)
            {
                string command      = commandLineArgs[currentCommandIndex];
                string commandUpper = command.ToUpper();
                switch (commandUpper)
                {
                case "TEST":
                    CheckKnownAssemblyConditionalCompSymbols();
                    return;

                case "FORCE_SOFTWARE_RENDERING":
                    forceSofwareRendering = true;
                    GL.ForceSoftwareRendering();
                    break;

                case "MHSERIAL_TO_ANDROID":
                {
                    Dictionary <string, string> vidPid_NameDictionary = new Dictionary <string, string>();
                    string[] MHSerialLines = File.ReadAllLines(Path.Combine("..", "..", "StaticData", "Drivers", "MHSerial", "MHSerial.inf"));
                    foreach (string line in MHSerialLines)
                    {
                        if (line.Contains("=DriverInstall,"))
                        {
                            string name   = Regex.Match(line, "%(.*).name").Groups[1].Value;
                            string vid    = Regex.Match(line, "VID_(.*)&PID").Groups[1].Value;
                            string pid    = Regex.Match(line, "PID_([0-9a-fA-F]+)").Groups[1].Value;
                            string vidPid = "{0},{1}".FormatWith(vid, pid);
                            if (!vidPid_NameDictionary.ContainsKey(vidPid))
                            {
                                vidPid_NameDictionary.Add(vidPid, name);
                            }
                        }
                    }

                    using (StreamWriter deviceFilter = new StreamWriter("deviceFilter.txt"))
                    {
                        using (StreamWriter serialPort = new StreamWriter("serialPort.txt"))
                        {
                            foreach (KeyValuePair <string, string> vidPid_Name in vidPid_NameDictionary)
                            {
                                string[] vidPid = vidPid_Name.Key.Split(',');
                                int      vid    = Int32.Parse(vidPid[0], System.Globalization.NumberStyles.HexNumber);
                                int      pid    = Int32.Parse(vidPid[1], System.Globalization.NumberStyles.HexNumber);
                                serialPort.WriteLine("customTable.AddProduct(0x{0:X4}, 0x{1:X4}, cdcDriverType);  // {2}".FormatWith(vid, pid, vidPid_Name.Value));
                                deviceFilter.WriteLine("<!-- {2} -->\n<usb-device vendor-id=\"{0}\" product-id=\"{1}\" />".FormatWith(vid, pid, vidPid_Name.Value));
                            }
                        }
                    }
                }
                    return;

                case "CLEAR_CACHE":
                    AboutWidget.DeleteCacheData();
                    break;

                case "SHOW_MEMORY":
                    ShowMemoryUsed = true;
                    break;

                case "DO_GC_COLLECT_EVERY_DRAW":
                    ShowMemoryUsed       = true;
                    DoCGCollectEveryDraw = true;
                    break;

                case "CREATE_AND_SELECT_PRINTER":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        currentCommandIndex++;
                        string   argument    = commandLineArgs[currentCommandIndex];
                        string[] printerData = argument.Split(',');
                        if (printerData.Length >= 2)
                        {
                            Printer ActivePrinter = new Printer();

                            ActivePrinter.Name  = "Auto: {0} {1}".FormatWith(printerData[0], printerData[1]);
                            ActivePrinter.Make  = printerData[0];
                            ActivePrinter.Model = printerData[1];

                            if (printerData.Length == 3)
                            {
                                ActivePrinter.ComPort = printerData[2];
                            }

                            PrinterSetupStatus test = new PrinterSetupStatus(ActivePrinter);
                            test.LoadDefaultSliceSettings(ActivePrinter.Make, ActivePrinter.Model);
                            ActivePrinterProfile.Instance.ActivePrinter = ActivePrinter;
                        }
                    }

                    break;

                case "CONNECT_TO_PRINTER":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter();
                    }
                    break;

                case "START_PRINT":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        bool hasBeenRun = false;
                        currentCommandIndex++;
                        string fullPath = commandLineArgs[currentCommandIndex];
                        QueueData.Instance.RemoveAll();
                        if (!string.IsNullOrEmpty(fullPath))
                        {
                            string fileName = Path.GetFileNameWithoutExtension(fullPath);
                            QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(fileName, fullPath)));
                            PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((sender, e) =>
                            {
                                if (!hasBeenRun && PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Connected)
                                {
                                    hasBeenRun = true;
                                    PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible();
                                }
                            }, ref unregisterEvent);
                        }
                    }
                    break;

                case "SLICE_AND_EXPORT_GCODE":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        currentCommandIndex++;
                        string fullPath = commandLineArgs[currentCommandIndex];
                        QueueData.Instance.RemoveAll();
                        if (!string.IsNullOrEmpty(fullPath))
                        {
                            string           fileName         = Path.GetFileNameWithoutExtension(fullPath);
                            PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(fileName, fullPath));
                            QueueData.Instance.AddItem(printItemWrapper);

                            SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);
                            ExportPrintItemWindow exportForTest = new ExportPrintItemWindow(printItemWrapper);
                            exportForTest.ExportGcodeCommandLineUtility(fileName);
                        }
                    }
                    break;
                }

                if (MeshFileIo.ValidFileExtensions().Contains(Path.GetExtension(command).ToUpper()))
                {
                    // If we are the only instance running then do nothing.
                    // Else send these to the running instance so it can load them.
                }
            }

            //WriteTestGCodeFile();
#if !DEBUG
            if (File.Exists("RunUnitTests.txt"))
#endif
            {
#if IS_WINDOWS_FORMS
                if (!Clipboard.IsInitialized)
                {
                    Clipboard.SetSystemClipboard(new WindowsFormsClipboard());
                }
#endif

                // you can turn this on to debug some bounds issues
                //GuiWidget.DebugBoundsUnderMouse = true;
            }

            GuiWidget.DefaultEnforceIntegerBounds = true;

            if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
            {
                TextWidget.GlobalPointSizeScaleRatio = 1.3;
            }

            this.AddChild(ApplicationController.Instance.MainView);
            this.MinimumSize = minSize;
            this.Padding     = new BorderDouble(0); //To be re-enabled once native borders are turned off

#if false                                           // this is to test freeing gcodefile memory
            Button test = new Button("test");
            test.Click += (sender, e) =>
            {
                //MatterHackers.GCodeVisualizer.GCodeFile gcode = new GCodeVisualizer.GCodeFile();
                //gcode.Load(@"C:\Users\lbrubaker\Downloads\drive assy.gcode");
                SystemWindow window = new SystemWindow(100, 100);
                window.ShowAsSystemWindow();
            };
            allControls.AddChild(test);
#endif
            this.AnchorAll();

            if (!forceSofwareRendering)
            {
                UseOpenGL = true;
            }
            string version = "1.4";

            Title = "MatterControl {0}".FormatWith(version);
            if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0)
            {
                Title = Title + " - {1}".FormatWith(version, OemSettings.Instance.WindowTitleExtra);
            }

            UiThread.RunOnIdle(CheckOnPrinter);

            string desktopPosition = ApplicationSettings.Instance.get("DesktopPosition");
            if (desktopPosition != null && desktopPosition != "")
            {
                string[] sizes = desktopPosition.Split(',');

                //If the desktop position is less than -10,-10, override
                int xpos = Math.Max(int.Parse(sizes[0]), -10);
                int ypos = Math.Max(int.Parse(sizes[1]), -10);

                DesktopPosition = new Point2D(xpos, ypos);
            }

            showWindow = true;
        }
示例#4
0
        private MatterControlApplication(double width, double height)
            : base(width, height)
        {
            ApplicationSettings.Instance.set("HardwareHasCamera", "false");

            Name = "MatterControl";

            // set this at startup so that we can tell next time if it got set to true in close
            UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1;

            this.commandLineArgs = Environment.GetCommandLineArgs();
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            for (int currentCommandIndex = 0; currentCommandIndex < commandLineArgs.Length; currentCommandIndex++)
            {
                string command      = commandLineArgs[currentCommandIndex];
                string commandUpper = command.ToUpper();
                switch (commandUpper)
                {
                case "FORCE_SOFTWARE_RENDERING":
                    GL.HardwareAvailable = false;
                    break;

                case "CLEAR_CACHE":
                    AboutWidget.DeleteCacheData(0);
                    break;

                case "SHOW_MEMORY":
                    ShowMemoryUsed = true;
                    break;

                case "DO_GC_COLLECT_EVERY_DRAW":
                    ShowMemoryUsed       = true;
                    DoCGCollectEveryDraw = true;
                    break;

                //case "CREATE_AND_SELECT_PRINTER":
                //	if (currentCommandIndex + 1 <= commandLineArgs.Length)
                //	{
                //		currentCommandIndex++;
                //		string argument = commandLineArgs[currentCommandIndex];
                //		string[] printerData = argument.Split(',');
                //		if (printerData.Length >= 2)
                //		{
                //			Printer ActivePrinter = new Printer();

                //			ActivePrinter.Name = "Auto: {0} {1}".FormatWith(printerData[0], printerData[1]);
                //			ActivePrinter.Make = printerData[0];
                //			ActivePrinter.Model = printerData[1];

                //			if (printerData.Length == 3)
                //			{
                //				ActivePrinter.ComPort = printerData[2];
                //			}

                //			PrinterSetupStatus test = new PrinterSetupStatus(ActivePrinter);
                //			test.LoadSettingsFromConfigFile(ActivePrinter.Make, ActivePrinter.Model);
                //			ActiveSliceSettings.Instance = ActivePrinter;
                //		}
                //	}

                //	break;

                case "CONNECT_TO_PRINTER":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter();
                    }
                    break;

                case "START_PRINT":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        bool hasBeenRun = false;
                        currentCommandIndex++;
                        string fullPath = commandLineArgs[currentCommandIndex];
                        QueueData.Instance.RemoveAll();
                        if (!string.IsNullOrEmpty(fullPath))
                        {
                            string fileName = Path.GetFileNameWithoutExtension(fullPath);
                            QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(fileName, fullPath)));
                            PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((sender, e) =>
                            {
                                if (!hasBeenRun && PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Connected)
                                {
                                    hasBeenRun = true;
                                    PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible();
                                }
                            }, ref unregisterEvent);
                        }
                    }
                    break;

                case "SLICE_AND_EXPORT_GCODE":
                    if (currentCommandIndex + 1 <= commandLineArgs.Length)
                    {
                        currentCommandIndex++;
                        string fullPath = commandLineArgs[currentCommandIndex];
                        QueueData.Instance.RemoveAll();
                        if (!string.IsNullOrEmpty(fullPath))
                        {
                            string           fileName         = Path.GetFileNameWithoutExtension(fullPath);
                            PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(fileName, fullPath));
                            QueueData.Instance.AddItem(printItemWrapper);

                            SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);
                            ExportPrintItemWindow exportForTest = new ExportPrintItemWindow(printItemWrapper);
                            exportForTest.ExportGcodeCommandLineUtility(fileName);
                        }
                    }
                    break;
                }

                if (MeshFileIo.ValidFileExtensions().Contains(Path.GetExtension(command).ToUpper()))
                {
                    // If we are the only instance running then do nothing.
                    // Else send these to the running instance so it can load them.
                }
            }

            //WriteTestGCodeFile();
#if !DEBUG
            if (File.Exists("RunUnitTests.txt"))
#endif
            {
#if IS_WINDOWS_FORMS
                if (!Clipboard.IsInitialized)
                {
                    Clipboard.SetSystemClipboard(new WindowsFormsClipboard());
                }
#endif

                // you can turn this on to debug some bounds issues
                //GuiWidget.DebugBoundsUnderMouse = true;
            }

            GuiWidget.DefaultEnforceIntegerBounds = true;

            if (UserSettings.Instance.IsTouchScreen)
            {
                GuiWidget.DeviceScale            = 1.3;
                SystemWindow.ShareSingleOsWindow = true;
            }
            //GuiWidget.DeviceScale = 2;

            using (new PerformanceTimer("Startup", "MainView"))
            {
                this.AddChild(ApplicationController.Instance.MainView);
            }
            this.MinimumSize = minSize;
            this.Padding     = new BorderDouble(0); //To be re-enabled once native borders are turned off

#if false                                           // this is to test freeing gcodefile memory
            Button test = new Button("test");
            test.Click += (sender, e) =>
            {
                //MatterHackers.GCodeVisualizer.GCodeFile gcode = new GCodeVisualizer.GCodeFile();
                //gcode.Load(@"C:\Users\lbrubaker\Downloads\drive assy.gcode");
                SystemWindow window = new SystemWindow(100, 100);
                window.ShowAsSystemWindow();
            };
            allControls.AddChild(test);
#endif
            this.AnchorAll();

            if (GL.HardwareAvailable)
            {
                UseOpenGL = true;
            }
            string version = "1.6";

            Title = "MatterHackers: MatterControl {0}".FormatWith(version);
            if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0)
            {
                Title = Title + " - {1}".FormatWith(version, OemSettings.Instance.WindowTitleExtra);
            }

            UiThread.RunOnIdle(CheckOnPrinter);

            string desktopPosition = ApplicationSettings.Instance.get(ApplicationSettingsKey.DesktopPosition);
            if (!string.IsNullOrEmpty(desktopPosition))
            {
                string[] sizes = desktopPosition.Split(',');

                //If the desktop position is less than -10,-10, override
                int xpos = Math.Max(int.Parse(sizes[0]), -10);
                int ypos = Math.Max(int.Parse(sizes[1]), -10);

                DesktopPosition = new Point2D(xpos, ypos);
            }
            else
            {
                DesktopPosition = new Point2D(-1, -1);
            }

            this.Maximized = ApplicationSettings.Instance.get(ApplicationSettingsKey.MainWindowMaximized) == "true";
        }
		private MatterControlApplication(double width, double height)
			: base(width, height)
		{
			ApplicationSettings.Instance.set("HardwareHasCamera", "false");

			Name = "MatterControl";

			// set this at startup so that we can tell next time if it got set to true in close
			UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1;

			this.commandLineArgs = Environment.GetCommandLineArgs();
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			for (int currentCommandIndex = 0; currentCommandIndex < commandLineArgs.Length; currentCommandIndex++)
			{
				string command = commandLineArgs[currentCommandIndex];
				string commandUpper = command.ToUpper();
				switch (commandUpper)
				{
					case "FORCE_SOFTWARE_RENDERING":
						GL.HardwareAvailable = false;
						break;

					case "CLEAR_CACHE":
						AboutWidget.DeleteCacheData(0);
						break;

					case "SHOW_MEMORY":
						ShowMemoryUsed = true;
						break;

					case "DO_GC_COLLECT_EVERY_DRAW":
						ShowMemoryUsed = true;
						DoCGCollectEveryDraw = true;
						break;

					//case "CREATE_AND_SELECT_PRINTER":
					//	if (currentCommandIndex + 1 <= commandLineArgs.Length)
					//	{
					//		currentCommandIndex++;
					//		string argument = commandLineArgs[currentCommandIndex];
					//		string[] printerData = argument.Split(',');
					//		if (printerData.Length >= 2)
					//		{
					//			Printer ActivePrinter = new Printer();

					//			ActivePrinter.Name = "Auto: {0} {1}".FormatWith(printerData[0], printerData[1]);
					//			ActivePrinter.Make = printerData[0];
					//			ActivePrinter.Model = printerData[1];

					//			if (printerData.Length == 3)
					//			{
					//				ActivePrinter.ComPort = printerData[2];
					//			}

					//			PrinterSetupStatus test = new PrinterSetupStatus(ActivePrinter);
					//			test.LoadSettingsFromConfigFile(ActivePrinter.Make, ActivePrinter.Model);
					//			ActiveSliceSettings.Instance = ActivePrinter;
					//		}
					//	}

					//	break;

					case "CONNECT_TO_PRINTER":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter();
						}
						break;

					case "START_PRINT":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							bool hasBeenRun = false;
							currentCommandIndex++;
							string fullPath = commandLineArgs[currentCommandIndex];
							QueueData.Instance.RemoveAll();
							if (!string.IsNullOrEmpty(fullPath))
							{
								string fileName = Path.GetFileNameWithoutExtension(fullPath);
								QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(fileName, fullPath)));
								PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((sender, e) =>
								{
									if (!hasBeenRun && PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Connected)
									{
										hasBeenRun = true;
										PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible();
									}
								}, ref unregisterEvent);
							}
						}
						break;

					case "SLICE_AND_EXPORT_GCODE":
						if (currentCommandIndex + 1 <= commandLineArgs.Length)
						{
							currentCommandIndex++;
							string fullPath = commandLineArgs[currentCommandIndex];
							QueueData.Instance.RemoveAll();
							if (!string.IsNullOrEmpty(fullPath))
							{
								string fileName = Path.GetFileNameWithoutExtension(fullPath);
								PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(fileName, fullPath));
								QueueData.Instance.AddItem(printItemWrapper);

								SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);
								ExportPrintItemWindow exportForTest = new ExportPrintItemWindow(printItemWrapper);
								exportForTest.ExportGcodeCommandLineUtility(fileName);
							}
						}
						break;
				}

				if (MeshFileIo.ValidFileExtensions().Contains(Path.GetExtension(command).ToUpper()))
				{
					// If we are the only instance running then do nothing.
					// Else send these to the running instance so it can load them.
				}
			}

			//WriteTestGCodeFile();
#if !DEBUG
			if (File.Exists("RunUnitTests.txt"))
#endif
			{
#if IS_WINDOWS_FORMS
				if (!Clipboard.IsInitialized)
				{
					Clipboard.SetSystemClipboard(new WindowsFormsClipboard());
				}
#endif

				// you can turn this on to debug some bounds issues
				//GuiWidget.DebugBoundsUnderMouse = true;
			}

			GuiWidget.DefaultEnforceIntegerBounds = true;

			if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen)
			{
				GuiWidget.DeviceScale = 1.3;
			}
			//GuiWidget.DeviceScale = 2;

			using (new PerformanceTimer("Startup", "MainView"))
			{
				this.AddChild(ApplicationController.Instance.MainView);
			}
			this.MinimumSize = minSize;
			this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off

#if false // this is to test freeing gcodefile memory
			Button test = new Button("test");
			test.Click += (sender, e) =>
			{
				//MatterHackers.GCodeVisualizer.GCodeFile gcode = new GCodeVisualizer.GCodeFile();
				//gcode.Load(@"C:\Users\lbrubaker\Downloads\drive assy.gcode");
				SystemWindow window = new SystemWindow(100, 100);
				window.ShowAsSystemWindow();
			};
			allControls.AddChild(test);
#endif
			this.AnchorAll();

			if (GL.HardwareAvailable)
			{
				UseOpenGL = true;
			}
			string version = "1.6";

			Title = "MatterHackers: MatterControl {0}".FormatWith(version);
			if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0)
			{
				Title = Title + " - {1}".FormatWith(version, OemSettings.Instance.WindowTitleExtra);
			}

			UiThread.RunOnIdle(CheckOnPrinter);

			string desktopPosition = ApplicationSettings.Instance.get(ApplicationSettingsKey.DesktopPosition);
			if (desktopPosition != null && desktopPosition != "")
			{
				string[] sizes = desktopPosition.Split(',');

				//If the desktop position is less than -10,-10, override
				int xpos = Math.Max(int.Parse(sizes[0]), -10);
				int ypos = Math.Max(int.Parse(sizes[1]), -10);

				DesktopPosition = new Point2D(xpos, ypos);
			}
		}