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; }
private void AddContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; string decodedHtml = HtmlParser.UrlDecode(htmlContent); switch (elementState.TypeName) { case "p": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "p"; elementsUnderConstruction.Peek().HAnchor = HAnchor.ParentLeftRight; if (decodedHtml != null && decodedHtml != "") { WrappingTextWidget content = new WrappingTextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); //content.VAnchor = VAnchor.ParentTop; elementsUnderConstruction.Peek().AddChild(content); } } break; case "div": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "div"; if (decodedHtml != null && decodedHtml != "") { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); elementsUnderConstruction.Peek().AddChild(content); } } break; case "!DOCTYPE": break; case "body": break; case "img": { ImageBuffer image = new ImageBuffer(elementState.SizeFixed.x, elementState.SizeFixed.y, 32, new BlenderBGRA()); ImageWidget_AsyncLoadOnDraw imageWidget = new ImageWidget_AsyncLoadOnDraw(image, elementState.src); // put the image into the widget when it is done downloading. if (elementsUnderConstruction.Peek().Name == "a") { Button linkButton = new Button(0, 0, imageWidget); linkButton.Cursor = Cursors.Hand; linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } else { elementsUnderConstruction.Peek().AddChild(imageWidget); } } break; case "a": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "a"; if (decodedHtml != null && decodedHtml != "") { Button linkButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; linkButton.OriginRelativeParent = new VectorMath.Vector2(linkButton.OriginRelativeParent.x, linkButton.OriginRelativeParent.y + descentInPixels); linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } } break; case "table": break; case "td": case "span": GuiWidget widgetToAdd; if (elementState.Classes.Contains("translate")) { decodedHtml = decodedHtml.Localize(); } if (elementState.Classes.Contains("toUpper")) { decodedHtml = decodedHtml.ToUpper(); } if (elementState.Classes.Contains("versionNumber")) { decodedHtml = VersionInfo.Instance.ReleaseVersion; } if (elementState.Classes.Contains("buildNumber")) { decodedHtml = VersionInfo.Instance.BuildVersion; } Button createdButton = null; if (elementState.Classes.Contains("centeredButton")) { createdButton = textImageButtonFactory.Generate(decodedHtml); widgetToAdd = createdButton; } else if (elementState.Classes.Contains("linkButton")) { double oldFontSize = linkButtonFactory.fontSize; linkButtonFactory.fontSize = elementState.PointSize; createdButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; createdButton.OriginRelativeParent = new VectorMath.Vector2(createdButton.OriginRelativeParent.x, createdButton.OriginRelativeParent.y + descentInPixels); widgetToAdd = createdButton; linkButtonFactory.fontSize = oldFontSize; } else { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); widgetToAdd = content; } if (createdButton != null) { if (elementState.Id == "sendFeedback") { createdButton.Click += (sender, mouseEvent) => { ContactFormWindow.Open(); }; } else if (elementState.Id == "clearCache") { createdButton.Click += (sender, mouseEvent) => { AboutWidget.DeleteCacheData(); }; } } if (elementState.VerticalAlignment == ElementState.VerticalAlignType.top) { widgetToAdd.VAnchor = VAnchor.ParentTop; } elementsUnderConstruction.Peek().AddChild(widgetToAdd); break; case "tr": elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "tr"; if (elementState.SizePercent.y == 100) { elementsUnderConstruction.Peek().VAnchor = VAnchor.ParentBottomTop; } if (elementState.Alignment == ElementState.AlignType.center) { elementsUnderConstruction.Peek().HAnchor |= HAnchor.ParentCenter; } break; default: throw new NotImplementedException("Don't know what to do with '{0}'".FormatWith(elementState.TypeName)); } }
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"; }