static void CreateSlicedPartsThread() { while (!haltSlicingThread) { if (PrinterCommunication.Instance.ActivePrintItem != null && listOfSlicingItems.Count > 0) { PrintItemWrapper itemToSlice = listOfSlicingItems[0]; itemToSlice.CurrentlySlicing = true; string currentConfigurationFileAndPath = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, "config_" + ActiveSliceSettings.Instance.GetHashCode().ToString() + ".ini"); ActiveSliceSettings.Instance.GenerateConfigFile(currentConfigurationFileAndPath); string gcodePathAndFileName = itemToSlice.GCodePathAndFileName; bool gcodeFileIsComplete = itemToSlice.IsGCodeFileComplete(gcodePathAndFileName); if (!File.Exists(gcodePathAndFileName) || !gcodeFileIsComplete) { slicerProcess = new Process(); switch (PrinterCommunication.Instance.ActiveSliceEngine) { case PrinterCommunication.SlicingEngine.Slic3r: slicerProcess.StartInfo.Arguments = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; break; case PrinterCommunication.SlicingEngine.CuraEngine: slicerProcess.StartInfo.Arguments = "-v -o \"" + gcodePathAndFileName + "\" " + CuraEngineMappings.GetCuraCommandLineSettings() + " \"" + itemToSlice.PartToSlicePathAndFileName + "\""; //Debug.Write(slicerProcess.StartInfo.Arguments); break; case PrinterCommunication.SlicingEngine.MatterSlice: slicerProcess.StartInfo.Arguments = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; break; } string slicerFullPath = getSlicerFullPath(); slicerProcess.StartInfo.CreateNoWindow = true; slicerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; slicerProcess.StartInfo.RedirectStandardError = true; slicerProcess.StartInfo.RedirectStandardOutput = true; slicerProcess.StartInfo.FileName = slicerFullPath; slicerProcess.StartInfo.UseShellExecute = false; slicerProcess.OutputDataReceived += (sender, args) => { if (args.Data != null) { string message = args.Data; message = message.Replace("=>", "").Trim(); if (message.Contains(".gcode")) { message = "Saving intermediate file"; } message += "..."; itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); } }; slicerProcess.Start(); slicerProcess.BeginOutputReadLine(); string stdError = slicerProcess.StandardError.ReadToEnd(); slicerProcess.WaitForExit(); using (TimedLock.Lock(slicerProcess, "SlicingProcess")) { slicerProcess = null; } } itemToSlice.CurrentlySlicing = false; itemToSlice.DoneSlicing = true; using (TimedLock.Lock(listOfSlicingItems, "CreateSlicedPartsThread()")) { listOfSlicingItems.RemoveAt(0); } } Thread.Sleep(100); } }
static void CreateSlicedPartsThread() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; while (!haltSlicingThread) { if (PrinterConnectionAndCommunication.Instance.ActivePrintItem != null && listOfSlicingItems.Count > 0) { PrintItemWrapper itemToSlice = listOfSlicingItems[0]; string[] stlFileLocations = GetStlFileLocations(itemToSlice.FileLocation); string fileToSlice = stlFileLocations[0]; // check that the STL file is currently on disk if (File.Exists(fileToSlice)) { itemToSlice.CurrentlySlicing = true; string currentConfigurationFileAndPath = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, "config_" + ActiveSliceSettings.Instance.GetHashCode().ToString() + ".ini"); ActiveSliceSettings.Instance.GenerateConfigFile(currentConfigurationFileAndPath); string gcodePathAndFileName = itemToSlice.GetGCodePathAndFileName(); bool gcodeFileIsComplete = itemToSlice.IsGCodeFileComplete(gcodePathAndFileName); if (!File.Exists(gcodePathAndFileName) || !gcodeFileIsComplete) { string commandArgs = ""; switch (ActivePrinterProfile.Instance.ActiveSliceEngineType) { case ActivePrinterProfile.SlicingEngineTypes.Slic3r: commandArgs = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + fileToSlice + "\""; break; case ActivePrinterProfile.SlicingEngineTypes.CuraEngine: commandArgs = "-v -o \"" + gcodePathAndFileName + "\" " + EngineMappingCura.GetCuraCommandLineSettings() + " \"" + fileToSlice + "\""; break; case ActivePrinterProfile.SlicingEngineTypes.MatterSlice: { EngineMappingsMatterSlice.WriteMatterSliceSettingsFile(currentConfigurationFileAndPath); commandArgs = "-v -o \"" + gcodePathAndFileName + "\" -c \"" + currentConfigurationFileAndPath + "\""; foreach (string filename in stlFileLocations) { commandArgs = commandArgs + " \"" + filename + "\""; } } break; } if (OsInformation.OperatingSystem == OSType.Android || ((OsInformation.OperatingSystem == OSType.Mac || runInProcess) && ActivePrinterProfile.Instance.ActiveSliceEngineType == ActivePrinterProfile.SlicingEngineTypes.MatterSlice)) { itemCurrentlySlicing = itemToSlice; MatterHackers.MatterSlice.LogOutput.GetLogWrites += SendProgressToItem; MatterSlice.MatterSlice.ProcessArgs(commandArgs); MatterHackers.MatterSlice.LogOutput.GetLogWrites -= SendProgressToItem; itemCurrentlySlicing = null; } else { slicerProcess = new Process(); slicerProcess.StartInfo.Arguments = commandArgs; string slicerFullPath = getSlicerFullPath(); slicerProcess.StartInfo.CreateNoWindow = true; slicerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; slicerProcess.StartInfo.RedirectStandardError = true; slicerProcess.StartInfo.RedirectStandardOutput = true; slicerProcess.StartInfo.FileName = slicerFullPath; slicerProcess.StartInfo.UseShellExecute = false; slicerProcess.OutputDataReceived += (sender, args) => { if (args.Data != null) { string message = args.Data; message = message.Replace("=>", "").Trim(); if (message.Contains(".gcode")) { message = "Saving intermediate file"; } message += "..."; UiThread.RunOnIdle((state) => { itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); }); } }; slicerProcess.Start(); slicerProcess.BeginOutputReadLine(); string stdError = slicerProcess.StandardError.ReadToEnd(); slicerProcess.WaitForExit(); using (TimedLock.Lock(slicerProcess, "SlicingProcess")) { slicerProcess = null; } } } try { if (File.Exists(gcodePathAndFileName) && File.Exists(currentConfigurationFileAndPath)) { using (StreamWriter gcodeWirter = File.AppendText(gcodePathAndFileName)) { string oemName = "MatterControl"; if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0) { oemName = oemName + " - {0}".FormatWith(OemSettings.Instance.WindowTitleExtra); } gcodeWirter.WriteLine("; {0} Version {1} Build {2} : GCode settings used".FormatWith(oemName, VersionInfo.Instance.ReleaseVersion, VersionInfo.Instance.BuildVersion)); gcodeWirter.WriteLine("; Date {0} Time {1}:{2:00}".FormatWith(DateTime.Now.Date, DateTime.Now.Hour, DateTime.Now.Minute)); foreach (string line in File.ReadLines(currentConfigurationFileAndPath)) { gcodeWirter.WriteLine("; {0}".FormatWith(line)); } } } } catch (Exception) { } } UiThread.RunOnIdle((state) => { itemToSlice.CurrentlySlicing = false; itemToSlice.DoneSlicing = true; }); using (TimedLock.Lock(listOfSlicingItems, "CreateSlicedPartsThread()")) { listOfSlicingItems.RemoveAt(0); } } Thread.Sleep(100); } }
private static void CreateSlicedPartsThread() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; while (!haltSlicingThread) { if (listOfSlicingItems.Count > 0) { PrintItemWrapper itemToSlice = listOfSlicingItems[0]; bool doMergeInSlicer = false; string mergeRules = ""; doMergeInSlicer = ActiveSliceSettings.Instance.ActiveSliceEngineType() == SlicingEngineTypes.MatterSlice; string[] stlFileLocations = GetStlFileLocations(itemToSlice.FileLocation, doMergeInSlicer, ref mergeRules); string fileToSlice = stlFileLocations[0]; // check that the STL file is currently on disk if (File.Exists(fileToSlice)) { itemToSlice.CurrentlySlicing = true; string currentConfigurationFileAndPath = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, "config_" + ActiveSliceSettings.Instance.GetLongHashCode().ToString() + ".ini"); ActiveSliceSettings.Instance.GenerateConfigFile(currentConfigurationFileAndPath, true); string gcodePathAndFileName = itemToSlice.GetGCodePathAndFileName(); bool gcodeFileIsComplete = itemToSlice.IsGCodeFileComplete(gcodePathAndFileName); if (!File.Exists(gcodePathAndFileName) || !gcodeFileIsComplete) { string commandArgs = ""; switch (ActiveSliceSettings.Instance.ActiveSliceEngineType()) { case SlicingEngineTypes.Slic3r: commandArgs = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + fileToSlice + "\""; break; case SlicingEngineTypes.CuraEngine: commandArgs = "-v -o \"" + gcodePathAndFileName + "\" " + EngineMappingCura.GetCuraCommandLineSettings() + " \"" + fileToSlice + "\""; break; case SlicingEngineTypes.MatterSlice: { EngineMappingsMatterSlice.WriteMatterSliceSettingsFile(currentConfigurationFileAndPath); if (mergeRules == "") { commandArgs = "-v -o \"" + gcodePathAndFileName + "\" -c \"" + currentConfigurationFileAndPath + "\""; } else { commandArgs = "-b {0} -v -o \"".FormatWith(mergeRules) + gcodePathAndFileName + "\" -c \"" + currentConfigurationFileAndPath + "\""; } foreach (string filename in stlFileLocations) { commandArgs = commandArgs + " \"" + filename + "\""; } } break; } #if false Mesh loadedMesh = StlProcessing.Load(fileToSlice); SliceLayers layers = new SliceLayers(); layers.GetPerimetersForAllLayers(loadedMesh, .2, .2); layers.DumpSegmentsToGcode("test.gcode"); #endif if (OsInformation.OperatingSystem == OSType.Android || ((OsInformation.OperatingSystem == OSType.Mac || runInProcess) && ActiveSliceSettings.Instance.ActiveSliceEngineType() == SlicingEngineTypes.MatterSlice)) { itemCurrentlySlicing = itemToSlice; MatterHackers.MatterSlice.LogOutput.GetLogWrites += SendProgressToItem; MatterSlice.MatterSlice.ProcessArgs(commandArgs); MatterHackers.MatterSlice.LogOutput.GetLogWrites -= SendProgressToItem; itemCurrentlySlicing = null; } else { slicerProcess = new Process(); slicerProcess.StartInfo.Arguments = commandArgs; string slicerFullPath = getSlicerFullPath(); slicerProcess.StartInfo.CreateNoWindow = true; slicerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; slicerProcess.StartInfo.RedirectStandardError = true; slicerProcess.StartInfo.RedirectStandardOutput = true; slicerProcess.StartInfo.FileName = slicerFullPath; slicerProcess.StartInfo.UseShellExecute = false; slicerProcess.OutputDataReceived += (sender, args) => { if (args.Data != null) { string message = args.Data; message = message.Replace("=>", "").Trim(); if (message.Contains(".gcode")) { message = "Saving intermediate file"; } message += "..."; UiThread.RunOnIdle(() => { itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); }); } }; slicerProcess.Start(); slicerProcess.BeginOutputReadLine(); string stdError = slicerProcess.StandardError.ReadToEnd(); slicerProcess.WaitForExit(); lock (slicerProcess) { slicerProcess = null; } } } try { if (File.Exists(gcodePathAndFileName) && File.Exists(currentConfigurationFileAndPath)) { // make sure we have not already written the settings onto this file bool fileHaseSettings = false; int bufferSize = 32000; using (Stream fileStream = File.OpenRead(gcodePathAndFileName)) { byte[] buffer = new byte[bufferSize]; fileStream.Seek(Math.Max(0, fileStream.Length - bufferSize), SeekOrigin.Begin); int numBytesRead = fileStream.Read(buffer, 0, bufferSize); string fileEnd = System.Text.Encoding.UTF8.GetString(buffer); if (fileEnd.Contains("GCode settings used")) { fileHaseSettings = true; } } if (!fileHaseSettings) { using (StreamWriter gcodeWirter = File.AppendText(gcodePathAndFileName)) { string oemName = "MatterControl"; if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0) { oemName = oemName + " - {0}".FormatWith(OemSettings.Instance.WindowTitleExtra); } gcodeWirter.WriteLine("; {0} Version {1} Build {2} : GCode settings used".FormatWith(oemName, VersionInfo.Instance.ReleaseVersion, VersionInfo.Instance.BuildVersion)); gcodeWirter.WriteLine("; Date {0} Time {1}:{2:00}".FormatWith(DateTime.Now.Date, DateTime.Now.Hour, DateTime.Now.Minute)); foreach (string line in File.ReadLines(currentConfigurationFileAndPath)) { gcodeWirter.WriteLine("; {0}".FormatWith(line)); } } } } } catch (Exception) { } } UiThread.RunOnIdle(() => { itemToSlice.CurrentlySlicing = false; itemToSlice.DoneSlicing = true; }); lock (listOfSlicingItems) { listOfSlicingItems.RemoveAt(0); } } Thread.Sleep(100); } }
void CreateAndAddChildren(object state) { TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor; CloseAndRemoveAllChildren(); gcodeViewWidget = null; gcodeProcessingStateInfoText = null; FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight; buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight; buttonBottomPanel.Padding = new BorderDouble(3, 3); buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; generateGCodeButton = textImageButtonFactory.Generate(LocalizedString.Get("Generate")); generateGCodeButton.Click += new EventHandler(generateButton_Click); buttonBottomPanel.AddChild(generateGCodeButton); layerSelectionButtonsPanel = new FlowLayoutWidget(FlowDirection.RightToLeft); layerSelectionButtonsPanel.HAnchor = HAnchor.ParentLeftRight; layerSelectionButtonsPanel.Padding = new BorderDouble(0); GuiWidget holdPanelOpen = new GuiWidget(1, generateGCodeButton.Height); layerSelectionButtonsPanel.AddChild(holdPanelOpen); if (widgetHasCloseButton) { Button closeButton = textImageButtonFactory.Generate(LocalizedString.Get("Close")); layerSelectionButtonsPanel.AddChild(closeButton); closeButton.Click += (sender, e) => { CloseOnIdle(); }; } FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight); centerPartPreviewAndControls.AnchorAll(); gcodeDisplayWidget = new GuiWidget(HAnchor.ParentLeftRight, Agg.UI.VAnchor.ParentBottomTop); SetProcessingMessage("Press 'Add' to select an item.".Localize()); if (printItem != null) { SetProcessingMessage(LocalizedString.Get("Loading GCode...")); if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE") { gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation)); } else { if (File.Exists(printItem.FileLocation)) { string gcodePathAndFileName = printItem.GetGCodePathAndFileName(); bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName); if (printItem.SlicingHadError) { SetProcessingMessage(slicingErrorMessage); } else { SetProcessingMessage(pressGenerateMessage); } if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete) { gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName)); } // we only hook these up to make sure we can regenerate the gcode when we want printItem.SlicingOutputMessage.RegisterEvent(sliceItem_SlicingOutputMessage, ref unregisterEvents); printItem.SlicingDone.RegisterEvent(sliceItem_Done, ref unregisterEvents); } else { SetProcessingMessage(string.Format("{0}\n'{1}'", fileNotFoundMessage, printItem.Name)); } } } else { generateGCodeButton.Visible = false; } centerPartPreviewAndControls.AddChild(gcodeDisplayWidget); buttonRightPanel = CreateRightButtonPanel(); buttonRightPanel.Visible = false; centerPartPreviewAndControls.AddChild(buttonRightPanel); // add in a spacer layerSelectionButtonsPanel.AddChild(new GuiWidget(HAnchor.ParentLeftRight)); buttonBottomPanel.AddChild(layerSelectionButtonsPanel); mainContainerTopToBottom.AddChild(centerPartPreviewAndControls); mainContainerTopToBottom.AddChild(buttonBottomPanel); this.AddChild(mainContainerTopToBottom); meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape, "".Localize()); meshViewerWidget.AnchorAll(); meshViewerWidget.AllowBedRenderingWhenEmpty = true; gcodeDisplayWidget.AddChild(meshViewerWidget); meshViewerWidget.Visible = false; meshViewerWidget.TrackballTumbleWidget.DrawGlContent += new EventHandler(TrackballTumbleWidget_DrawGlContent); viewControls2D = new ViewControls2D(); AddChild(viewControls2D); viewControls3D = new ViewControls3D(meshViewerWidget); viewControls3D.PartSelectVisible = false; AddChild(viewControls3D); viewControls3D.rotateButton.ClickButton(null); viewControls3D.Visible = false; viewControlsToggle = new ViewControlsToggle(); viewControlsToggle.HAnchor = Agg.UI.HAnchor.ParentRight; AddChild(viewControlsToggle); viewControlsToggle.Visible = false; //viewControls3D.translateButton.ClickButton(null); // move things into the right place and scale { Vector3 bedCenter3D = new Vector3(bedCenter, 0); meshViewerWidget.PrinterBed.Translate(bedCenter3D); meshViewerWidget.TrackballTumbleWidget.TrackBallController.Scale = .05; meshViewerWidget.TrackballTumbleWidget.TrackBallController.Translate(-bedCenter3D); } viewControls2D.translateButton.Click += (sender, e) => { gcodeViewWidget.TransformState = ViewGcodeWidget.ETransformState.Move; }; viewControls2D.scaleButton.Click += (sender, e) => { gcodeViewWidget.TransformState = ViewGcodeWidget.ETransformState.Scale; }; AddHandlers(); }
static void CreateSlicedPartsThread() { while (!haltSlicingThread) { if (PrinterCommunication.Instance.ActivePrintItem != null && listOfSlicingItems.Count > 0) { PrintItemWrapper itemToSlice = listOfSlicingItems[0]; // check that the STL file is currently on disk if (File.Exists(itemToSlice.FileLocation)) { itemToSlice.CurrentlySlicing = true; string currentConfigurationFileAndPath = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, "config_" + ActiveSliceSettings.Instance.GetHashCode().ToString() + ".ini"); ActiveSliceSettings.Instance.GenerateConfigFile(currentConfigurationFileAndPath); string gcodePathAndFileName = itemToSlice.GCodePathAndFileName; bool gcodeFileIsComplete = itemToSlice.IsGCodeFileComplete(gcodePathAndFileName); if (!File.Exists(gcodePathAndFileName) || !gcodeFileIsComplete) { string commandArgs = ""; switch (ActivePrinterProfile.Instance.ActiveSliceEngineType) { case ActivePrinterProfile.SlicingEngineTypes.Slic3r: commandArgs = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; break; case ActivePrinterProfile.SlicingEngineTypes.CuraEngine: commandArgs = "-v -o \"" + gcodePathAndFileName + "\" " + EngineMappingCura.GetCuraCommandLineSettings() + " \"" + itemToSlice.PartToSlicePathAndFileName + "\""; break; case ActivePrinterProfile.SlicingEngineTypes.MatterSlice: { EngineMappingsMatterSlice.WriteMatterSliceSettingsFile(currentConfigurationFileAndPath); commandArgs = "-v -o \"" + gcodePathAndFileName + "\" -c \"" + currentConfigurationFileAndPath + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; } break; } #if RUN_MATTER_SLICE_IN_PROCESS if (ActivePrinterProfile.Instance.ActiveSliceEngineType == ActivePrinterProfile.SlicingEngineTypes.MatterSlice) { itemCurrentlySlicing = itemToSlice; MatterHackers.MatterSlice.LogOutput.GetLogWrites += SendProgressToItem; MatterSlice.MatterSlice.ProcessArgs(commandArgs); MatterHackers.MatterSlice.LogOutput.GetLogWrites -= SendProgressToItem; itemCurrentlySlicing = null; } else #endif { slicerProcess = new Process(); slicerProcess.StartInfo.Arguments = commandArgs; string slicerFullPath = getSlicerFullPath(); slicerProcess.StartInfo.CreateNoWindow = true; slicerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; slicerProcess.StartInfo.RedirectStandardError = true; slicerProcess.StartInfo.RedirectStandardOutput = true; slicerProcess.StartInfo.FileName = slicerFullPath; slicerProcess.StartInfo.UseShellExecute = false; slicerProcess.OutputDataReceived += (sender, args) => { if (args.Data != null) { string message = args.Data; message = message.Replace("=>", "").Trim(); if (message.Contains(".gcode")) { message = "Saving intermediate file"; } message += "..."; UiThread.RunOnIdle((state) => { itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); }); } }; slicerProcess.Start(); slicerProcess.BeginOutputReadLine(); string stdError = slicerProcess.StandardError.ReadToEnd(); slicerProcess.WaitForExit(); using (TimedLock.Lock(slicerProcess, "SlicingProcess")) { slicerProcess = null; } } } } UiThread.RunOnIdle((state) => { itemToSlice.CurrentlySlicing = false; itemToSlice.DoneSlicing = true; }); using (TimedLock.Lock(listOfSlicingItems, "CreateSlicedPartsThread()")) { listOfSlicingItems.RemoveAt(0); } } Thread.Sleep(100); } }
void CreateAndAddChildren(object state) { RemoveAllChildren(); FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight; buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight; buttonBottomPanel.Padding = new BorderDouble(3, 3); buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; generateGCodeButton = textImageButtonFactory.Generate(new LocalizedString("Generate").Translated); generateGCodeButton.Click += new ButtonBase.ButtonEventHandler(generateButton_Click); buttonBottomPanel.AddChild(generateGCodeButton); layerSelectionButtonsPannel = new FlowLayoutWidget(FlowDirection.RightToLeft); layerSelectionButtonsPannel.HAnchor = HAnchor.ParentLeftRight; layerSelectionButtonsPannel.Padding = new BorderDouble(0); closeButton = textImageButtonFactory.Generate(new LocalizedString("Close").Translated); layerSelectionButtonsPannel.AddChild(closeButton); FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight); centerPartPreviewAndControls.AnchorAll(); gcodeDispalyWidget = new GuiWidget(HAnchor.ParentLeftRight, Agg.UI.VAnchor.ParentBottomTop); string startingMessage = new LocalizedString("Loading GCode...").Translated; if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE") { gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation)); } else { string gcodePathAndFileName = printItem.GCodePathAndFileName; bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName); if (gcodeProcessingStateInfoText != null && gcodeProcessingStateInfoText.Text == "Slicing Error") { startingMessage = "Slicing Error. Please review your slice settings."; } else { startingMessage = new LocalizedString("Press 'generate' to view layers").Translated; } if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete) { gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName)); } // we only hook these up to make sure we can regenerate the gcode when we want printItem.SlicingOutputMessage += sliceItem_SlicingOutputMessage; printItem.Done += new EventHandler(sliceItem_Done); } centerPartPreviewAndControls.AddChild(gcodeDispalyWidget); buttonRightPanel = CreateRightButtonPannel(); centerPartPreviewAndControls.AddChild(buttonRightPanel); // add in a spacer layerSelectionButtonsPannel.AddChild(new GuiWidget(HAnchor.ParentLeftRight)); buttonBottomPanel.AddChild(layerSelectionButtonsPannel); mainContainerTopToBottom.AddChild(centerPartPreviewAndControls); mainContainerTopToBottom.AddChild(buttonBottomPanel); this.AddChild(mainContainerTopToBottom); AddProcessingMessage(startingMessage); AddViewControls(); AddHandlers(); }
void CreateAndAddChildren(object state) { RemoveAllChildren(); gcodeViewWidget = null; gcodeProcessingStateInfoText = null; FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight; buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight; buttonBottomPanel.Padding = new BorderDouble(3, 3); buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; generateGCodeButton = textImageButtonFactory.Generate(LocalizedString.Get("Generate")); generateGCodeButton.Click += new ButtonBase.ButtonEventHandler(generateButton_Click); buttonBottomPanel.AddChild(generateGCodeButton); layerSelectionButtonsPanel = new FlowLayoutWidget(FlowDirection.RightToLeft); layerSelectionButtonsPanel.HAnchor = HAnchor.ParentLeftRight; layerSelectionButtonsPanel.Padding = new BorderDouble(0); GuiWidget holdPanelOpen = new GuiWidget(1, generateGCodeButton.Height); layerSelectionButtonsPanel.AddChild(holdPanelOpen); if (widgetHasCloseButton) { Button closeButton = textImageButtonFactory.Generate(LocalizedString.Get("Close")); layerSelectionButtonsPanel.AddChild(closeButton); closeButton.Click += (sender, e) => { CloseOnIdle(); }; } FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight); centerPartPreviewAndControls.AnchorAll(); gcodeDispalyWidget = new GuiWidget(HAnchor.ParentLeftRight, Agg.UI.VAnchor.ParentBottomTop); SetProcessingMessage("Press 'Add' to select an item.".Localize()); if (printItem != null) { SetProcessingMessage(LocalizedString.Get("Loading GCode...")); if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE") { gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation)); } else { if (File.Exists(printItem.FileLocation)) { string gcodePathAndFileName = printItem.GCodePathAndFileName; bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName); if (printItem.SlicingHadError) { SetProcessingMessage(slicingErrorMessage); } else { SetProcessingMessage(pressGenerateMessage); } if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete) { gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName)); } // we only hook these up to make sure we can regenerate the gcode when we want printItem.SlicingOutputMessage.RegisterEvent(sliceItem_SlicingOutputMessage, ref unregisterEvents); printItem.SlicingDone.RegisterEvent(sliceItem_Done, ref unregisterEvents); } else { SetProcessingMessage(string.Format("{0}\n'{1}'", fileNotFoundMessage, printItem.Name)); } } } else { generateGCodeButton.Visible = false; } centerPartPreviewAndControls.AddChild(gcodeDispalyWidget); buttonRightPanel = CreateRightButtonPanel(); centerPartPreviewAndControls.AddChild(buttonRightPanel); // add in a spacer layerSelectionButtonsPanel.AddChild(new GuiWidget(HAnchor.ParentLeftRight)); buttonBottomPanel.AddChild(layerSelectionButtonsPanel); mainContainerTopToBottom.AddChild(centerPartPreviewAndControls); mainContainerTopToBottom.AddChild(buttonBottomPanel); this.AddChild(mainContainerTopToBottom); Add2DViewControls(); translateButton.Click += (sender, e) => { gcodeViewWidget.TransformState = GCodeViewWidget.ETransformState.Move; }; scaleButton.Click += (sender, e) => { gcodeViewWidget.TransformState = GCodeViewWidget.ETransformState.Scale; }; AddHandlers(); }