Exemple #1
0
        private static void ShowFileDialog(Action <string> dialogClosedHandler)
        {
            var systemWindow = new SystemWindow(600, 200)
            {
                Title           = "TestAutomation File Input",
                BackgroundColor = RGBA_Bytes.DarkGray
            };

            var warningLabel = new TextWidget("This dialog should not appear outside of automation tests.\nNotify technical support if visible", pointSize: 15, textColor: RGBA_Bytes.Pink)
            {
                Margin  = new BorderDouble(20),
                VAnchor = VAnchor.ParentTop,
                HAnchor = HAnchor.ParentLeftRight
            };

            systemWindow.AddChild(warningLabel);

            var fileNameInput = new TextEditWidget(pixelWidth: 400)
            {
                VAnchor = VAnchor.ParentCenter,
                HAnchor = HAnchor.ParentLeftRight,
                Margin  = new BorderDouble(30, 15)
            };

            fileNameInput.EnterPressed += (s, e) => systemWindow.CloseOnIdle();
            systemWindow.AddChild(fileNameInput);

            systemWindow.Load   += (s, e) => fileNameInput.Focus();
            systemWindow.Closed += (s, e) =>
            {
                dialogClosedHandler(fileNameInput.Text);
            };

            systemWindow.ShowAsSystemWindow();
        }
Exemple #2
0
        public void CreateWidgetAndRunInWindow(SystemWindow.PixelTypes bitDepth = SystemWindow.PixelTypes.Depth32, RenderSurface surfaceType = RenderSurface.Bitmap)
		{
			AppWidgetInfo appWidgetInfo = GetAppParameters();
            SystemWindow systemWindow = new SystemWindow(appWidgetInfo.width, appWidgetInfo.height);
            systemWindow.PixelType = bitDepth;
            systemWindow.Title = appWidgetInfo.title;
            if (surfaceType == RenderSurface.OpenGL)
            {
                systemWindow.UseOpenGL = true;
            }
            systemWindow.AddChild(NewWidget());
            systemWindow.ShowAsSystemWindow();
        }
        public void CreateWidgetAndRunInWindow(SystemWindow.PixelTypes bitDepth = SystemWindow.PixelTypes.Depth32, RenderSurface surfaceType = RenderSurface.Bitmap)
        {
            AppWidgetInfo appWidgetInfo = GetAppParameters();
            SystemWindow  systemWindow  = new SystemWindow(appWidgetInfo.width, appWidgetInfo.height);

            systemWindow.PixelType = bitDepth;
            systemWindow.Title     = appWidgetInfo.title;
            if (surfaceType == RenderSurface.OpenGL)
            {
                systemWindow.UseOpenGL = true;
            }
            systemWindow.AddChild(NewWidget());
            systemWindow.ShowAsSystemWindow();
        }
		public AboutWidget()
		{
			this.HAnchor = HAnchor.ParentLeftRight;
			this.VAnchor = VAnchor.ParentTop;

			this.Padding = new BorderDouble(5);
			this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			FlowLayoutWidget customInfoTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			customInfoTopToBottom.Name = "AboutPageCustomInfo";
			customInfoTopToBottom.HAnchor = HAnchor.ParentLeftRight;
			customInfoTopToBottom.VAnchor = VAnchor.Max_FitToChildren_ParentHeight;
			customInfoTopToBottom.Padding = new BorderDouble(5, 10, 5, 0);

			if (UserSettings.Instance.IsTouchScreen)
			{
				customInfoTopToBottom.AddChild(new UpdateControlView());
			}

			//AddMatterHackersInfo(customInfoTopToBottom);
			customInfoTopToBottom.AddChild(new GuiWidget(1, 10));

			string aboutHtmlFile = Path.Combine("OEMSettings", "AboutPage.html");
			string htmlContent = StaticData.Instance.ReadAllText(aboutHtmlFile);

#if false // test
			{
				SystemWindow releaseNotes = new SystemWindow(640, 480);
				string releaseNotesFile = Path.Combine("OEMSettings", "ReleaseNotes.html");
				string releaseNotesContent = StaticData.Instance.ReadAllText(releaseNotesFile);
				HtmlWidget content = new HtmlWidget(releaseNotesContent, RGBA_Bytes.Black);
				content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop));
				content.VAnchor |= VAnchor.ParentTop;
				content.BackgroundColor = RGBA_Bytes.White;
				releaseNotes.AddChild(content);
				releaseNotes.BackgroundColor = RGBA_Bytes.Cyan;
				UiThread.RunOnIdle((state) =>
				{
					releaseNotes.ShowAsSystemWindow();
				}, 1);
			}
#endif

			HtmlWidget htmlWidget = new HtmlWidget(htmlContent, ActiveTheme.Instance.PrimaryTextColor);

			customInfoTopToBottom.AddChild(htmlWidget);

			this.AddChild(customInfoTopToBottom);
		}
		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 static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
		{
			PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

			LevelWizardBase printLevelWizardWindow;
			switch (levelingData.levelingSystem)
			{
				case PrintLevelingData.LevelingSystem.Probe2Points:
					printLevelWizardWindow = new LevelWizard2Point(runningState);
					break;

				case PrintLevelingData.LevelingSystem.Probe3Points:
					printLevelWizardWindow = new LevelWizard3Point(runningState);
					break;

				default:
					throw new NotImplementedException();
			}

			printLevelWizardWindow.ShowAsSystemWindow();
			return printLevelWizardWindow;
		}
		public void ShowContentInWindow()
		{
			if(widgetWithPopContent.HasBeenClosed)
			{
				if(systemWindowWithPopContent != null)
				{
					systemWindowWithPopContent.Close();
				}

				return;
			}

			if (systemWindowWithPopContent == null)
			{
				// So the window is open now only change this is we close it.
				UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, true);

				string windowSize = UserSettings.Instance.get(WindowSizeKey);
				int width = 600;
				int height = 400;
				if (windowSize != null && windowSize != "")
				{
					string[] sizes = windowSize.Split(',');
					width = Math.Max(int.Parse(sizes[0]), (int)minSize.x);
					height = Math.Max(int.Parse(sizes[1]), (int)minSize.y);
				}

				systemWindowWithPopContent = new SystemWindow(width, height);
				systemWindowWithPopContent.Padding = new BorderDouble(3);
				systemWindowWithPopContent.Title = windowTitle;
				systemWindowWithPopContent.AlwaysOnTopOfMain = true;
				systemWindowWithPopContent.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
				systemWindowWithPopContent.Closing += SystemWindow_Closing;
				if (widgetWithPopContent.Children.Count == 1)
				{
					GuiWidget child = widgetWithPopContent.Children[0];
					widgetWithPopContent.RemoveChild(child);
					child.ClearRemovedFlag();
					widgetWithPopContent.AddChild(CreateContentForEmptyControl());
					systemWindowWithPopContent.AddChild(child);
				}
				systemWindowWithPopContent.ShowAsSystemWindow();

				systemWindowWithPopContent.MinimumSize = minSize;
				string desktopPosition = UserSettings.Instance.get(PositionKey);
				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);
					systemWindowWithPopContent.DesktopPosition = new Point2D(xpos, ypos);
				}
			}
			else
			{
				systemWindowWithPopContent.BringToFront();
			}
		}
Exemple #8
0
        public override void OnDraw(Graphics2D graphics2D)
        {
#if false
            if (firstDraw)
            {
                firstDraw = false;
                SystemWindow testAbout = new SystemWindow(600, 300);

                string path = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "AboutPage.html");
                string htmlText = File.ReadAllText(path);
                HTMLCanvas canvas = new HTMLCanvas(htmlText);
                canvas.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

                canvas.AddReplacementString("textColor", RGBA_Bytes.White.GetAsHTMLString());

                canvas.AnchorAll();
                testAbout.AddChild(canvas);

                testAbout.ShowAsSystemWindow();
            }
#endif

            graphics2D.FillRectangle(new RectangleDouble(0, this.Height - 1, this.Width, this.Height), RGBA_Bytes.White);
            base.OnDraw(graphics2D);
        }
		private static void HtmlWindowTest()
		{
			try
			{
				SystemWindow htmlTestWindow = new SystemWindow(640, 480);
				string htmlContent = "";
				if (true)
				{
					string releaseNotesFile = Path.Combine("C:\\Users\\lbrubaker\\Downloads", "test1.html");
					htmlContent = File.ReadAllText(releaseNotesFile);
				}
				else
				{
					WebClient webClient = new WebClient();
					htmlContent = webClient.DownloadString("http://www.matterhackers.com/s/store?q=pla");
				}

				HtmlWidget content = new HtmlWidget(htmlContent, RGBA_Bytes.Black);
				content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop));
				content.VAnchor |= VAnchor.ParentTop;
				content.BackgroundColor = RGBA_Bytes.White;
				htmlTestWindow.AddChild(content);
				htmlTestWindow.BackgroundColor = RGBA_Bytes.Cyan;
				UiThread.RunOnIdle((state) =>
				{
					htmlTestWindow.ShowAsSystemWindow();
				}, 1);
			}
			catch
			{
				int stop = 1;
			}
		}
		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);
			}
		}
        public override void OnDraw(Graphics2D graphics2D)
		{
			totalDrawTime.Restart();
			GuiWidget.DrawCount = 0;
			using (new PerformanceTimer("Draw Timer", "MC Draw"))
			{
				base.OnDraw(graphics2D);
			}
			totalDrawTime.Stop();

			millisecondTimer.Update((int)totalDrawTime.ElapsedMilliseconds);

			if (ShowMemoryUsed)
			{
				long memory = GC.GetTotalMemory(false);
				this.Title = "Allocated = {0:n0} : {1:000}ms, d{2} Size = {3}x{4}, onIdle = {5:00}:{6:00}, widgetsDrawn = {7}".FormatWith(memory, millisecondTimer.GetAverage(), drawCount++, this.Width, this.Height, UiThread.CountExpired, UiThread.Count, GuiWidget.DrawCount);
				if (DoCGCollectEveryDraw)
				{
					GC.Collect();
				}
			}

			if (firstDraw)
			{
				UiThread.RunOnIdle(DoAutoConnectIfRequired);

				firstDraw = false;
				foreach (string arg in commandLineArgs)
				{
					string argExtension = Path.GetExtension(arg).ToUpper();
					if (argExtension.Length > 1
						&& MeshFileIo.ValidFileExtensions().Contains(argExtension))
					{
						QueueData.Instance.AddItem(new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileName(arg), Path.GetFullPath(arg))));
					}
				}

				TerminalWindow.ShowIfLeftOpen();

#if false
			{
				SystemWindow releaseNotes = new SystemWindow(640, 480);
				string releaseNotesFile = Path.Combine("C:/Users/LarsBrubaker/Downloads", "test1.html");
				string releaseNotesContent = StaticData.Instance.ReadAllText(releaseNotesFile);
				HtmlWidget content = new HtmlWidget(releaseNotesContent, RGBA_Bytes.Black);
				content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop));
				content.VAnchor |= VAnchor.ParentTop;
				content.BackgroundColor = RGBA_Bytes.White;
				releaseNotes.AddChild(content);
				releaseNotes.BackgroundColor = RGBA_Bytes.Cyan;
				UiThread.RunOnIdle((state) =>
				{
					releaseNotes.ShowAsSystemWindow();
				}, 1);
			}
#endif

				AfterFirstDraw?.Invoke();
			}

			//msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds);
			//msGraph.Draw(MatterHackers.Agg.Transform.Affine.NewIdentity(), graphics2D);
		}
		private static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
		{
			// turn off print leveling
			ActiveSliceSettings.Instance.Helpers.DoPrintLeveling(false);
			// clear any data that we are going to be acquiring (sampled positions, after z home offset)
			PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();
			levelingData.SampledPositions.Clear();
			ActiveSliceSettings.Instance.SetValue(SettingsKey.z_offset_after_home, 0.ToString());
			ApplicationController.Instance.ReloadAdvancedControlsPanel();

			LevelWizardBase printLevelWizardWindow;
			switch (levelingData.CurrentPrinterLevelingSystem)
			{
				case PrintLevelingData.LevelingSystem.Probe3Points:
					printLevelWizardWindow = new LevelWizard3Point(runningState);
					break;

				case PrintLevelingData.LevelingSystem.Probe7PointRadial:
					printLevelWizardWindow = new LevelWizard7PointRadial(runningState);
					break;

				case PrintLevelingData.LevelingSystem.Probe13PointRadial:
					printLevelWizardWindow = new LevelWizard13PointRadial(runningState);
					break;

				default:
					throw new NotImplementedException();
			}

			printLevelWizardWindow.ShowAsSystemWindow();
			return printLevelWizardWindow;
		}
		private static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
		{
			PrintLevelingData levelingData = ActiveSliceSettings.Instance.PrintLevelingData;

			LevelWizardBase printLevelWizardWindow;
			switch (levelingData.CurrentPrinterLevelingSystem)
			{
				case PrintLevelingData.LevelingSystem.Probe2Points:
					printLevelWizardWindow = new LevelWizard2Point(runningState);
					break;

				case PrintLevelingData.LevelingSystem.Probe3Points:
					printLevelWizardWindow = new LevelWizard3Point(runningState);
					break;

				case PrintLevelingData.LevelingSystem.Probe7PointRadial:
					printLevelWizardWindow = new LevelWizard7PointRadial(runningState);
					break;

				case PrintLevelingData.LevelingSystem.Probe13PointRadial:
					printLevelWizardWindow = new LevelWizard13PointRadial(runningState);
					break;

				default:
					throw new NotImplementedException();
			}

			printLevelWizardWindow.Closed += (sender, e) =>
			{
				ApplicationController.Instance.ReloadAll(null, null);
			};

			printLevelWizardWindow.ShowAsSystemWindow();
			return printLevelWizardWindow;
		}
        public MatterControlApplication(double width, double height)
            : base(width, height)
        {
            this.commandLineArgs = Environment.GetCommandLineArgs();
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            if (commandLineArgs.Length > 1)
            {
                switch (commandLineArgs[1].ToUpper())
                {
                    case "TEST":
                        Testing.TestingDispatch testDispatch = new Testing.TestingDispatch();
                        string[] testCommands = new string[commandLineArgs.Length - 2];
                        if (commandLineArgs.Length > 2)
                        {
                            commandLineArgs.CopyTo(testCommands, 2);
                        }
                        testDispatch.RunTests(testCommands);
                        return;

                    case "SHOW_MEMORY":
                        ShowMemoryUsed = true;
                        break;

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

                    case "SHOW_DRAW_TIMING":
                        ShowDrawTimingWindow = true;
                        break;
                }
            }

            //WriteTestGCodeFile();
            if (File.Exists("RunUnitTests.txt"))
            {
                GuiHalWidget.SetClipboardFunctions(System.Windows.Forms.Clipboard.GetText, System.Windows.Forms.Clipboard.SetText, System.Windows.Forms.Clipboard.ContainsText);

                MatterHackers.Agg.Tests.UnitTests.Run();
                MatterHackers.VectorMath.Tests.UnitTests.Run();
                MatterHackers.Agg.UI.Tests.UnitTests.Run();
                MatterHackers.PolygonMesh.UnitTests.UnitTests.Run();

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

            GuiWidget.DefaultEnforceIntegerBounds = true;

            FlowLayoutWidget allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);
            allControls.AnchorAll();

            this.AddChild(allControls);
            this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off

            //allControls.AddChild(CreateMenues());
            allControls.AddChild(new ActionBarPlus());
            allControls.AddChild(MainSlidePanel.Instance);

#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();

            UseOpenGL = true;
            Title = "MatterControl (beta)";

            ActivePrinterProfile.CheckForAndDoAutoConnect();
            UiThread.RunOnIdle(CheckOnPrinter);

            ShowAsSystemWindow();
        }