public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor, ThemeConfig theme) { this.settingData = settingData; this.uiField = uiField; this.textColor = textColor; this.theme = theme; }
private bool ValidateGoodSpeedSettingGreaterThan0(string speedSetting, string speedLocation) { string actualSpeedValueString = GetValue(speedSetting); string speedValueString = actualSpeedValueString; if (speedValueString.EndsWith("%")) { speedValueString = speedValueString.Substring(0, speedValueString.Length - 1); } bool valueWasNumber = true; double speedToCheck; if (!double.TryParse(speedValueString, out speedToCheck)) { valueWasNumber = false; } if (!valueWasNumber || (ActiveSliceSettings.Instance.Helpers.ActiveSliceEngine().MapContains(speedSetting) && speedToCheck <= 0)) { SliceSettingData data = SliceSettingsOrganizer.Instance.GetSettingsData(speedSetting); if (data != null) { string error = string.Format("The '{0}' must be greater than 0.".Localize(), data.PresentationName); string details = string.Format("It is currently set to {0}.".Localize(), actualSpeedValueString); StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2} -> '{3}'", error, details, speedLocation, data.PresentationName), "Slice Error".Localize()); } return(false); } return(true); }
private void LoadAndParseSettingsFiles() { string propertiesFileContents = StaticData.Instance.ReadAllText(Path.Combine("SliceSettings", "Properties.json")); SettingsData = JsonConvert.DeserializeObject <List <SliceSettingData> >(propertiesFileContents) as List <SliceSettingData>; OrganizerUserLevel userLevelToAddTo = null; OrganizerCategory categoryToAddTo = null; OrganizerGroup groupToAddTo = null; OrganizerSubGroup subGroupToAddTo = null; foreach (string line in StaticData.Instance.ReadAllLines(Path.Combine("SliceSettings", "Layouts.txt"))) { if (line.Length > 0) { string sanitizedLine = line.Replace('"', ' ').Trim(); switch (CountLeadingSpaces(line)) { case 0: userLevelToAddTo = new OrganizerUserLevel(sanitizedLine); UserLevels.Add(sanitizedLine, userLevelToAddTo); break; case 2: categoryToAddTo = new OrganizerCategory(sanitizedLine); userLevelToAddTo.CategoriesList.Add(categoryToAddTo); break; case 4: groupToAddTo = new OrganizerGroup(sanitizedLine); categoryToAddTo.GroupsList.Add(groupToAddTo); break; case 6: subGroupToAddTo = new OrganizerSubGroup(sanitizedLine); groupToAddTo.SubGroupsList.Add(subGroupToAddTo); break; case 8: SliceSettingData data = GetSettingsData(sanitizedLine); if (data != null) { subGroupToAddTo.SettingDataList.Add(data); } break; default: throw new Exception("Bad file, too many spaces (must be 0, 2, 4 or 6)."); } } } }
private void LoadAndParseSettingsFiles() { UserLevel userLevelToAddTo = null; Category categoryToAddTo = null; Group groupToAddTo = null; SubGroup subGroupToAddTo = null; foreach (string line in AggContext.StaticData.ReadAllLines(Path.Combine("SliceSettings", "Layouts.txt"))) { if (line.Length > 0) { string sanitizedLine = line.Replace('"', ' ').Trim(); switch (CountLeadingSpaces(line)) { case 0: userLevelToAddTo = new UserLevel(sanitizedLine); UserLevels.Add(sanitizedLine, userLevelToAddTo); break; case 2: categoryToAddTo = new Category(sanitizedLine, userLevelToAddTo); userLevelToAddTo.Categories.Add(categoryToAddTo); break; case 4: groupToAddTo = new Group(sanitizedLine, categoryToAddTo); categoryToAddTo.Groups.Add(groupToAddTo); break; case 6: subGroupToAddTo = new SubGroup(sanitizedLine, groupToAddTo); groupToAddTo.SubGroups.Add(subGroupToAddTo); break; case 8: SliceSettingData data = GetSettingsData(sanitizedLine); if (data != null) { subGroupToAddTo.Settings.Add(data); data.OrganizerSubGroup = subGroupToAddTo; userLevelToAddTo.AddSetting(data.SlicerConfigName, subGroupToAddTo); } break; default: throw new Exception("Bad file, too many spaces (must be 0, 2, 4 or 6)."); } } } }
public ulong GetLongHashCode() { var bigStringForHashCode = new StringBuilder(); foreach (var keyValue in this.BaseLayer) { // Add key/value to accumulating string for hash SliceSettingData data = PrinterSettings.SettingsData[keyValue.Key]; if (data?.RebuildGCodeOnChange == true) { bigStringForHashCode.Append(keyValue.Key); bigStringForHashCode.Append(this.GetValue(keyValue.Key)); } } return(bigStringForHashCode.ToString().GetLongHashCode()); }
public long GetLongHashCode() { var bigStringForHashCode = new StringBuilder(); foreach (var keyValue in this.BaseLayer) { SliceSettingData data = SliceSettingsOrganizer.Instance.GetSettingsData(keyValue.Key); if (data.RebuildGCodeOnChange) { string activeValue = GetValue(keyValue.Key); bigStringForHashCode.Append(keyValue.Key); bigStringForHashCode.Append(activeValue); } } string value = bigStringForHashCode.ToString(); return(agg_basics.ComputeHash(bigStringForHashCode.ToString())); }
private static GuiWidget CreateSettingInfoUIControls(SliceSettingData settingData, List<PrinterSettingsLayer> layerCascade, PrinterSettingsLayer persistenceLayer, NamedSettingsLayers viewFilter, int extruderIndex, out bool addControl, ref int tabIndexForItem) { addControl = true; GuiWidget container = new GuiWidget(); string sliceSettingValue = GetActiveValue(settingData.SlicerConfigName, layerCascade); GuiWidget nameArea = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren | VAnchor.ParentCenter); var dataArea = new FlowLayoutWidget(); GuiWidget unitsArea = new GuiWidget(HAnchor.AbsolutePosition, VAnchor.FitToChildren | VAnchor.ParentCenter) { Width = settingData.ShowAsOverride ? 50 * GuiWidget.DeviceScale : 5, }; GuiWidget restoreArea = new GuiWidget(HAnchor.AbsolutePosition, VAnchor.FitToChildren | VAnchor.ParentCenter) { Width = settingData.ShowAsOverride ? 30 * GuiWidget.DeviceScale : 0, }; var settingsRow = new SettingsRow(layerCascade) { SettingsKey = settingData.SlicerConfigName, SettingsValue = sliceSettingValue, }; settingsRow.AddChild(nameArea); settingsRow.AddChild(dataArea); settingsRow.AddChild(unitsArea); settingsRow.AddChild(restoreArea); settingsRow.Name = settingData.SlicerConfigName + " Edit Field"; if (!PrinterSettings.KnownSettings.Contains(settingData.SlicerConfigName)) { // the setting we think we are adding is not in the known settings it may have been deprecated TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in known settings", settingData.SlicerConfigName)); settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor; //settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y); nameArea.AddChild(settingName); nameArea.BackgroundColor = RGBA_Bytes.Red; } else { int intEditWidth = (int)(60 * GuiWidget.DeviceScale + .5); int doubleEditWidth = (int)(60 * GuiWidget.DeviceScale + .5); int vectorXYEditWidth = (int)(60 * GuiWidget.DeviceScale + .5); int multiLineEditHeight = (int)(120 * GuiWidget.DeviceScale + .5); if (settingData.DataEditType != SliceSettingData.DataEditTypes.MULTI_LINE_TEXT) { var nameHolder = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren | VAnchor.ParentCenter) { Padding = new BorderDouble(0, 0, 5, 0), HAnchor = HAnchor.ParentLeftRight, }; nameHolder.AddChild(new WrappedTextWidget(settingData.PresentationName.Localize(), pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor)); nameArea.AddChild(nameHolder); } switch (settingData.DataEditType) { case SliceSettingData.DataEditTypes.INT: { FlowLayoutWidget content = new FlowLayoutWidget(); int currentValue; int.TryParse(sliceSettingValue, out currentValue); var intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true, Name = settingData.PresentationName + " Edit", }; intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; content.AddChild(intEditWidget); unitsArea.AddChild(GetExtraSettingsWidget(settingData)); if (settingData.QuickMenuSettings.Count > 0) { dataArea.AddChild(CreateQuickMenu(settingData, persistenceLayer, content, intEditWidget.ActuallNumberEdit.InternalTextEditWidget, layerCascade)); } else { dataArea.AddChild(content); } settingsRow.ValueChanged = (text) => { intEditWidget.Text = text; }; } break; case SliceSettingData.DataEditTypes.DOUBLE: { double currentValue; double.TryParse(sliceSettingValue, out currentValue); var doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true }; doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(doubleEditWidget); unitsArea.AddChild(GetExtraSettingsWidget(settingData)); settingsRow.ValueChanged = (text) => { double currentValue2 = 0; double.TryParse(text, out currentValue2); doubleEditWidget.ActuallNumberEdit.Value = currentValue2; }; } break; case SliceSettingData.DataEditTypes.POSITIVE_DOUBLE: { const string multiValuesAreDiffernt = "-"; FlowLayoutWidget content = new FlowLayoutWidget(); var doubleEditWidget = new MHNumberEdit(0, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, Name = settingData.PresentationName + " Textbox", SelectAllOnFocus = true }; double currentValue; bool ChangesMultipleOtherSettings = settingData.SetSettingsOnChange.Count > 0; if (ChangesMultipleOtherSettings) { bool allTheSame = true; string setting = GetActiveValue(settingData.SetSettingsOnChange[0], layerCascade); for (int i = 1; i < settingData.SetSettingsOnChange.Count; i++) { string nextSetting = GetActiveValue(settingData.SetSettingsOnChange[i], layerCascade); if (setting != nextSetting) { allTheSame = false; break; } } if (allTheSame && setting.EndsWith("mm")) { double.TryParse(setting.Substring(0, setting.Length - 2), out currentValue); doubleEditWidget.ActuallNumberEdit.Value = currentValue; } else { doubleEditWidget.ActuallNumberEdit.InternalNumberEdit.Text = multiValuesAreDiffernt; } } else // just set the setting normally { double.TryParse(sliceSettingValue, out currentValue); doubleEditWidget.ActuallNumberEdit.Value = currentValue; } doubleEditWidget.ActuallNumberEdit.InternalTextEditWidget.MarkAsStartingState(); doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { NumberEdit numberEdit = (NumberEdit)sender; // If this setting sets other settings, then do that. if (ChangesMultipleOtherSettings && numberEdit.Text != multiValuesAreDiffernt) { foreach (string setting in settingData.SetSettingsOnChange) { ActiveSliceSettings.Instance.SetValue(setting, numberEdit.Value.ToString() + "mm", persistenceLayer); } } // also always save to the local setting ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, numberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; content.AddChild(doubleEditWidget); unitsArea.AddChild(GetExtraSettingsWidget(settingData)); if (settingData.QuickMenuSettings.Count > 0) { dataArea.AddChild(CreateQuickMenu(settingData, persistenceLayer, content, doubleEditWidget.ActuallNumberEdit.InternalTextEditWidget, layerCascade)); } else { dataArea.AddChild(content); } settingsRow.ValueChanged = (text) => { double currentValue2 = 0; double.TryParse(text, out currentValue2); doubleEditWidget.ActuallNumberEdit.Value = currentValue2; }; } break; case SliceSettingData.DataEditTypes.OFFSET: { double currentValue; double.TryParse(sliceSettingValue, out currentValue); var doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true }; doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(doubleEditWidget); unitsArea.AddChild(GetExtraSettingsWidget(settingData)); settingsRow.ValueChanged = (text) => { double currentValue2; double.TryParse(text, out currentValue2); doubleEditWidget.ActuallNumberEdit.Value = currentValue2; }; } break; case SliceSettingData.DataEditTypes.DOUBLE_OR_PERCENT: { FlowLayoutWidget content = new FlowLayoutWidget(); var stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: doubleEditWidth - 2, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true }; stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { var textEditWidget = (TextEditWidget)sender; string text = textEditWidget.Text.Trim(); bool isPercent = text.Contains("%"); if (isPercent) { text = text.Substring(0, text.IndexOf("%")); } double result; double.TryParse(text, out result); text = result.ToString(); if (isPercent) { text += "%"; } textEditWidget.Text = text; ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, textEditWidget.Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; stringEdit.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) => { // select everything up to the % (if present) InternalTextEditWidget textEditWidget = (InternalTextEditWidget)sender; int percentIndex = textEditWidget.Text.IndexOf("%"); if (percentIndex != -1) { textEditWidget.SetSelection(0, percentIndex - 1); } }; content.AddChild(stringEdit); unitsArea.AddChild(GetExtraSettingsWidget(settingData)); if (settingData.QuickMenuSettings.Count > 0) { dataArea.AddChild(CreateQuickMenu(settingData, persistenceLayer, content, stringEdit.ActualTextEditWidget.InternalTextEditWidget, layerCascade)); } else { dataArea.AddChild(content); } settingsRow.ValueChanged = (text) => { stringEdit.Text = text; }; } break; case SliceSettingData.DataEditTypes.INT_OR_MM: { FlowLayoutWidget content = new FlowLayoutWidget(); var stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: doubleEditWidth - 2, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true }; string startingText = stringEdit.Text; stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { TextEditWidget textEditWidget = (TextEditWidget)sender; // only validate when we lose focus if (!textEditWidget.ContainsFocus) { string text = textEditWidget.Text; text = text.Trim(); bool isMm = text.Contains("mm"); if (isMm) { text = text.Substring(0, text.IndexOf("mm")); } double result; double.TryParse(text, out result); text = result.ToString(); if (isMm) { text += "mm"; } else { result = (int)result; text = result.ToString(); } textEditWidget.Text = text; startingText = stringEdit.Text; } ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, textEditWidget.Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); // make sure we are still looking for the final validation before saving. if (textEditWidget.ContainsFocus) { UiThread.RunOnIdle(() => { string currentText = textEditWidget.Text; int cursorIndex = textEditWidget.InternalTextEditWidget.CharIndexToInsertBefore; textEditWidget.Text = startingText; textEditWidget.InternalTextEditWidget.MarkAsStartingState(); textEditWidget.Text = currentText; textEditWidget.InternalTextEditWidget.CharIndexToInsertBefore = cursorIndex; }); } }; stringEdit.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) => { // select everything up to the mm (if present) InternalTextEditWidget textEditWidget = (InternalTextEditWidget)sender; int mMIndex = textEditWidget.Text.IndexOf("mm"); if (mMIndex != -1) { textEditWidget.SetSelection(0, mMIndex - 1); } }; content.AddChild(stringEdit); unitsArea.AddChild(GetExtraSettingsWidget(settingData)); if (settingData.QuickMenuSettings.Count > 0) { dataArea.AddChild(CreateQuickMenu(settingData, persistenceLayer, content, stringEdit.ActualTextEditWidget.InternalTextEditWidget, layerCascade)); } else { dataArea.AddChild(content); } settingsRow.ValueChanged = (text) => { stringEdit.Text = text; }; } break; case SliceSettingData.DataEditTypes.CHECK_BOX: { var checkBoxWidget = new CheckBox("") { Name = settingData.PresentationName + " Checkbox", ToolTipText = settingData.HelpText, VAnchor = Agg.UI.VAnchor.ParentBottom, TextColor = ActiveTheme.Instance.PrimaryTextColor, Checked = sliceSettingValue == "1" }; checkBoxWidget.Click += (sender, e) => { bool isChecked = ((CheckBox)sender).Checked; ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, isChecked ? "1" : "0", persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(checkBoxWidget); settingsRow.ValueChanged = (text) => { checkBoxWidget.Checked = text == "1"; }; } break; case SliceSettingData.DataEditTypes.STRING: { var stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: settingData.ShowAsOverride ? 120 : 200, tabIndex: tabIndexForItem++) { Name = settingData.PresentationName + " Edit", }; stringEdit.ToolTipText = settingData.HelpText; stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((TextEditWidget)sender).Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(stringEdit); settingsRow.ValueChanged = (text) => { stringEdit.Text = text; }; } break; case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT: { string convertedNewLines = sliceSettingValue.Replace("\\n", "\n"); var stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++, typeFace: ApplicationController.MonoSpacedTypeFace) { HAnchor = HAnchor.ParentLeftRight, }; stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; nameArea.HAnchor = HAnchor.AbsolutePosition; nameArea.Width = 0; dataArea.AddChild(stringEdit); dataArea.HAnchor = HAnchor.ParentLeftRight; settingsRow.ValueChanged = (text) => { stringEdit.Text = text.Replace("\\n", "\n"); }; } break; case SliceSettingData.DataEditTypes.COM_PORT: { #if __ANDROID__ addControl = false; #endif // The COM_PORT control is unique in its approach to the SlicerConfigName. It uses "com_port" settings name to // bind to a context that will place it in the SliceSetting view but it binds its values to a machine // specific dictionary key that is not exposed in the UI. At runtime we lookup and store to '<machinename>_com_port' // ensuring that a single printer can be shared across different devices and we'll select the correct com port in each case var selectableOptions = new DropDownList("None", maxHeight: 200) { ToolTipText = settingData.HelpText, Margin = new BorderDouble(), Name = "Com Port Dropdown" }; selectableOptions.Click += (s, e) => { AddComMenuItems(settingData, persistenceLayer, settingsRow, selectableOptions); }; AddComMenuItems(settingData, persistenceLayer, settingsRow, selectableOptions); dataArea.AddChild(selectableOptions); settingsRow.ValueChanged = (text) => { // Lookup the machine specific comport value rather than the passed in text value selectableOptions.SelectedLabel = ActiveSliceSettings.Instance.Helpers.ComPort(); }; } break; case SliceSettingData.DataEditTypes.LIST: { var selectableOptions = new DropDownList("None", maxHeight: 200) { ToolTipText = settingData.HelpText, Margin = new BorderDouble() }; foreach (string listItem in settingData.ExtraSettings.Split(',')) { MenuItem newItem = selectableOptions.AddItem(listItem); if (newItem.Text == sliceSettingValue) { selectableOptions.SelectedLabel = sliceSettingValue; } newItem.Selected += (sender, e) => { MenuItem menuItem = ((MenuItem)sender); ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, menuItem.Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; } dataArea.AddChild(selectableOptions); settingsRow.ValueChanged = (text) => { selectableOptions.SelectedLabel = text; }; } break; case SliceSettingData.DataEditTypes.HARDWARE_PRESENT: { var checkBoxWidget = new CheckBox("") { Name = settingData.PresentationName + " Checkbox", ToolTipText = settingData.HelpText, VAnchor = Agg.UI.VAnchor.ParentBottom, TextColor = ActiveTheme.Instance.PrimaryTextColor, Checked = sliceSettingValue == "1" }; checkBoxWidget.Click += (sender, e) => { bool isChecked = ((CheckBox)sender).Checked; ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, isChecked ? "1" : "0", persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(checkBoxWidget); settingsRow.ValueChanged = (text) => { checkBoxWidget.Checked = text == "1"; }; } break; case SliceSettingData.DataEditTypes.VECTOR2: { string[] xyValueStrings = sliceSettingValue.Split(','); if (xyValueStrings.Length != 2) { xyValueStrings = new string[] { "0", "0" }; } double currentXValue; double.TryParse(xyValueStrings[0], out currentXValue); var xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true }; double currentYValue; double.TryParse(xyValueStrings[1], out currentYValue); var yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true, Margin = new BorderDouble(20, 0, 0, 0), }; xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(xEditWidget); dataArea.AddChild(new TextWidget("X", pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor) { VAnchor = VAnchor.ParentCenter, Margin = new BorderDouble(5, 0), }); yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(yEditWidget); var yLabel = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren | VAnchor.ParentCenter) { Padding = new BorderDouble(5, 0), HAnchor = HAnchor.ParentLeftRight, }; yLabel.AddChild(new WrappedTextWidget("Y", pointSize: 9, textColor: ActiveTheme.Instance.PrimaryTextColor)); unitsArea.AddChild(yLabel); settingsRow.ValueChanged = (text) => { double currentValue2; string[] xyValueStrings2 = text.Split(','); if (xyValueStrings2.Length != 2) { xyValueStrings2 = new string[] { "0", "0" }; } double.TryParse(xyValueStrings2[0], out currentValue2); xEditWidget.ActuallNumberEdit.Value = currentValue2; double.TryParse(xyValueStrings2[1], out currentValue2); yEditWidget.ActuallNumberEdit.Value = currentValue2; }; } break; case SliceSettingData.DataEditTypes.OFFSET2: { Vector2 offset = ActiveSliceSettings.Instance.Helpers.ExtruderOffset(extruderIndex); var xEditWidget = new MHNumberEdit(offset.x, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true, }; var yEditWidget = new MHNumberEdit(offset.y, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++) { ToolTipText = settingData.HelpText, SelectAllOnFocus = true, Margin = new BorderDouble(20, 0, 0, 0), }; xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { int extruderIndexLocal = extruderIndex; SaveCommaSeparatedIndexSetting(extruderIndexLocal, layerCascade, settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(xEditWidget); dataArea.AddChild(new TextWidget("X", pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor) { VAnchor = VAnchor.ParentCenter, Margin = new BorderDouble(5, 0), }); yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { int extruderIndexLocal = extruderIndex; SaveCommaSeparatedIndexSetting(extruderIndexLocal, layerCascade, settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; dataArea.AddChild(yEditWidget); var yLabel = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren | VAnchor.ParentCenter) { Padding = new BorderDouble(5, 0), HAnchor = HAnchor.ParentLeftRight, }; yLabel.AddChild(new WrappedTextWidget("Y", pointSize: 9, textColor: ActiveTheme.Instance.PrimaryTextColor)); unitsArea.AddChild(yLabel); settingsRow.ValueChanged = (text) => { Vector2 offset2 = ActiveSliceSettings.Instance.Helpers.ExtruderOffset(extruderIndex); xEditWidget.ActuallNumberEdit.Value = offset2.x; yEditWidget.ActuallNumberEdit.Value = offset2.y; }; } break; default: var missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString())) { TextColor = ActiveTheme.Instance.PrimaryTextColor, BackgroundColor = RGBA_Bytes.Red }; dataArea.AddChild(missingSetting); break; } } container.HAnchor = HAnchor.ParentLeftRight; container.VAnchor = VAnchor.FitToChildren; Button restoreButton = null; if (settingData.ShowAsOverride) { restoreButton = new Button(new ButtonViewStates(new ImageWidget(restoreNormal), new ImageWidget(restoreHover), new ImageWidget(restorePressed), new ImageWidget(restoreNormal))) { Name = "Restore " + settingData.SlicerConfigName, VAnchor = VAnchor.ParentCenter, Margin = new BorderDouble(0, 0, 5, 0), ToolTipText = "Restore Default".Localize() }; restoreButton.Click += (sender, e) => { // Revert the user override if (persistenceLayer == null) { ActiveSliceSettings.Instance.ClearValue(settingData.SlicerConfigName); } else { ActiveSliceSettings.Instance.ClearValue(settingData.SlicerConfigName, persistenceLayer); } settingsRow.RefreshValue(layerCascade); OnSettingsChanged(settingData); }; restoreArea.AddChild(restoreButton); } container.AddChild(settingsRow); // Define the UpdateStyle implementation settingsRow.UpdateStyle = () => { if (persistenceLayer.ContainsKey(settingData.SlicerConfigName)) { switch (viewFilter) { case NamedSettingsLayers.All: if (settingData.ShowAsOverride) { settingsRow.BackgroundColor = userSettingBackgroundColor; } break; case NamedSettingsLayers.Material: settingsRow.BackgroundColor = materialSettingBackgroundColor; break; case NamedSettingsLayers.Quality: settingsRow.BackgroundColor = qualitySettingBackgroundColor; break; } if(restoreButton != null) restoreButton.Visible = true; } else if (layerCascade == null) { if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, NamedSettingsLayers.Material)) { settingsRow.BackgroundColor = materialSettingBackgroundColor; } else if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, NamedSettingsLayers.Quality)) { settingsRow.BackgroundColor = qualitySettingBackgroundColor; } else { settingsRow.BackgroundColor = RGBA_Bytes.Transparent; } if (restoreButton != null) restoreButton.Visible = false; } else { if (restoreButton != null) restoreButton.Visible = false; settingsRow.BackgroundColor = RGBA_Bytes.Transparent; } }; // Invoke the UpdateStyle implementation settingsRow.UpdateStyle(); return container; }
static private void OnSettingsChanged(SliceSettingData settingData) { SettingChanged.CallEvents(null, new StringEventArgs(settingData.SlicerConfigName)); if (settingData.ReloadUiWhenChanged) { UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAll(null, null)); } }
private static GuiWidget GetExtraSettingsWidget(SliceSettingData settingData) { var nameHolder = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren | VAnchor.ParentCenter) { Padding = new BorderDouble(5, 0), HAnchor = HAnchor.ParentLeftRight, }; nameHolder.AddChild(new WrappedTextWidget(settingData.ExtraSettings.Localize(), pointSize: 8, textColor: ActiveTheme.Instance.PrimaryTextColor)); return nameHolder; }
public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, ThemeConfig theme, bool fullRowSelect = false) : base(settingData.PresentationName.Localize(), settingData.HelpText.Localize(), theme, fullRowSelect: fullRowSelect) { this.printer = printer; this.settingData = settingData; this.settingsContext = settingsContext; using (this.LayoutLock()) { this.AddChild(dataArea = new FlowLayoutWidget { VAnchor = VAnchor.Fit | VAnchor.Center, DebugShowBounds = debugLayout }); this.AddChild(unitsArea = new GuiWidget() { HAnchor = HAnchor.Absolute, VAnchor = VAnchor.Fit | VAnchor.Center, Width = 50 * GuiWidget.DeviceScale, DebugShowBounds = debugLayout }); // Populate unitsArea as appropriate // List elements contain list values in the field which normally contains label details, skip generation of invalid labels if (settingData.DataEditType != SliceSettingData.DataEditTypes.LIST && settingData.DataEditType != SliceSettingData.DataEditTypes.HARDWARE_PRESENT) { unitsArea.AddChild( new WrappedTextWidget(settingData.Units.Localize(), pointSize: theme.FontSize8, textColor: theme.TextColor) { Margin = new BorderDouble(5, 0), }); } restoreArea = new GuiWidget() { HAnchor = HAnchor.Absolute, VAnchor = VAnchor.Fit | VAnchor.Center, Width = 20 * GuiWidget.DeviceScale, DebugShowBounds = debugLayout }; this.AddChild(restoreArea); this.Name = settingData.SlicerConfigName + " Row"; if (settingData.ShowAsOverride && settingsContext.ViewFilter != NamedSettingsLayers.OEMSettings) { restoreButton = theme.CreateSmallResetButton(); restoreButton.HAnchor = HAnchor.Right; restoreButton.Margin = 0; restoreButton.Name = "Restore " + settingData.SlicerConfigName; restoreButton.ToolTipText = "Restore Default".Localize(); restoreButton.Click += (sender, e) => { // Revert the user override settingsContext.ClearValue(settingData.SlicerConfigName); }; restoreArea.AddChild(restoreButton); restoreArea.Selectable = true; } } this.PerformLayout(); }
private bool CheckIfShouldBeShown(SliceSettingData settingData) { bool settingShouldBeShown = ParseShowString(settingData.ShowIfSet, ActiveSliceSettings.Instance, layerCascade); if (viewFilter == NamedSettingsLayers.Material || viewFilter == NamedSettingsLayers.Quality) { if (!settingData.ShowAsOverride) { settingShouldBeShown = false; } } return settingShouldBeShown; }
private static GuiWidget CreateQuickMenu(SliceSettingData settingData, PrinterSettingsLayer persistenceLayer, GuiWidget content, InternalTextEditWidget internalTextWidget, List<PrinterSettingsLayer> layerCascade) { string sliceSettingValue = GetActiveValue(settingData.SlicerConfigName, layerCascade); FlowLayoutWidget totalContent = new FlowLayoutWidget(); DropDownList selectableOptions = new DropDownList("Custom", maxHeight: 200); selectableOptions.Margin = new BorderDouble(0, 0, 10, 0); foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings) { string valueLocal = nameValue.Value; MenuItem newItem = selectableOptions.AddItem(nameValue.MenuName); if (sliceSettingValue == valueLocal) { selectableOptions.SelectedLabel = nameValue.MenuName; } newItem.Selected += (sender, e) => { ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, valueLocal, persistenceLayer); OnSettingsChanged(settingData); internalTextWidget.Text = valueLocal; internalTextWidget.OnEditComplete(null); }; } // put in the custom menu to allow direct editing MenuItem customMenueItem = selectableOptions.AddItem("Custom"); totalContent.AddChild(selectableOptions); content.VAnchor = VAnchor.ParentCenter; totalContent.AddChild(content); EventHandler localUnregisterEvents = null; SettingChanged.RegisterEvent((sender, e) => { bool foundSetting = false; foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings) { string localName = nameValue.MenuName; string newSliceSettingValue = GetActiveValue(settingData.SlicerConfigName, layerCascade); if (newSliceSettingValue == nameValue.Value) { selectableOptions.SelectedLabel = localName; foundSetting = true; break; } } if (!foundSetting) { selectableOptions.SelectedLabel = "Custom"; } }, ref localUnregisterEvents); totalContent.Closed += (s, e) => { localUnregisterEvents?.Invoke(s, e); }; return totalContent; }
private static void AddComMenuItems(SliceSettingData settingData, PrinterSettingsLayer persistenceLayer, SettingsRow settingsRow, DropDownList selectableOptions) { selectableOptions.MenuItems.Clear(); string machineSpecificComPortValue = ActiveSliceSettings.Instance.Helpers.ComPort(); foreach (string listItem in FrostedSerialPort.GetPortNames()) { MenuItem newItem = selectableOptions.AddItem(listItem); if (newItem.Text == machineSpecificComPortValue) { selectableOptions.SelectedLabel = machineSpecificComPortValue; } newItem.Selected += (sender, e) => { MenuItem menuItem = ((MenuItem)sender); // Directly set the ComPort if (persistenceLayer == null) { ActiveSliceSettings.Instance.Helpers.SetComPort(menuItem.Text); } else { ActiveSliceSettings.Instance.Helpers.SetComPort(menuItem.Text, persistenceLayer); } settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; } }
public BoundDoubleField(SettingsContext settingsContext, SliceSettingData settingData, ThemeConfig theme) : base(theme) { this.settingsContext = settingsContext; this.settingData = settingData; }
public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor) { this.settingData = settingData; this.uiField = uiField; this.textColor = textColor; }
public BoundDoubleField(SettingsContext settingsContext, SliceSettingData settingData) { this.settingsContext = settingsContext; this.settingData = settingData; }
private GuiWidget AddInHelpText(FlowLayoutWidget topToBottomSettings, SliceSettingData settingData) { FlowLayoutWidget allText = new FlowLayoutWidget(FlowDirection.TopToBottom); allText.HAnchor = HAnchor.ParentLeftRight; double textRegionWidth = 380 * GuiWidget.DeviceScale; allText.Margin = new BorderDouble(0); allText.Padding = new BorderDouble(5); allText.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay; double helpPointSize = 10; GuiWidget helpWidget = new WrappedTextWidget(settingData.HelpText, pointSize: helpPointSize, textColor: RGBA_Bytes.White); helpWidget.Width = textRegionWidth; helpWidget.Margin = new BorderDouble(5, 0, 0, 0); //helpWidget.HAnchor = HAnchor.ParentLeft; allText.AddChild(helpWidget); allText.MinimumSize = new Vector2(0, allText.MinimumSize.y); return allText; }
static public SliceSettingData NewOrganizerSettingData(string slicerConfigName, string presentationName, SliceSettingData.DataEditTypes dataEditType, string extraSettings = "", string helpText = "") { return new SliceSettingData(slicerConfigName, presentationName, dataEditType, extraSettings, helpText); }
private TabControl CreateExtraSettingsSideTabsAndPages(TabControl categoryTabs, out int count) { int rightContentWidth = (int)(280 * GuiWidget.DeviceScale + .5); count = 0; TabControl leftSideGroupTabs = new TabControl(Orientation.Vertical); leftSideGroupTabs.Margin = new BorderDouble(0, 0, 0, 5); leftSideGroupTabs.TabBar.BorderColor = RGBA_Bytes.White; { TabPage groupTabPage = new TabPage("Extra Settings"); SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget(groupTabPage, "Extra Settings Tab", 14, ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), ActiveTheme.Instance.TabLabelUnselected, new RGBA_Bytes()); leftSideGroupTabs.AddTab(groupTabWidget); FlowLayoutWidget subGroupLayoutTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); subGroupLayoutTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; subGroupLayoutTopToBottom.VAnchor = VAnchor.FitToChildren; FlowLayoutWidget topToBottomSettings = new FlowLayoutWidget(FlowDirection.TopToBottom); topToBottomSettings.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; this.HAnchor = HAnchor.ParentLeftRight; foreach (var keyValue in ActiveSliceSettings.Instance.BaseLayer) { if (!SliceSettingsOrganizer.Instance.Contains(UserLevel, keyValue.Key)) { SliceSettingData settingData = new SliceSettingData(keyValue.Key, keyValue.Key, SliceSettingData.DataEditTypes.STRING); if (ActiveSliceSettings.Instance.Helpers.ActiveSliceEngine().MapContains(settingData.SlicerConfigName)) { bool addControl; GuiWidget controlsForThisSetting = CreateSettingInfoUIControls(settingData, layerCascade, persistenceLayer, viewFilter, 0, out addControl, ref tabIndexForItem); if (addControl) { topToBottomSettings.AddChild(controlsForThisSetting); } count++; } } } AltGroupBox groupBox = new AltGroupBox("Extra".Localize()); groupBox.TextColor = ActiveTheme.Instance.PrimaryTextColor; groupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor; groupBox.AddChild(topToBottomSettings); groupBox.VAnchor = VAnchor.FitToChildren; groupBox.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; subGroupLayoutTopToBottom.AddChild(groupBox); SliceSettingListControl scrollOnGroupTab = new SliceSettingListControl(); scrollOnGroupTab.AnchorAll(); scrollOnGroupTab.AddChild(subGroupLayoutTopToBottom); groupTabPage.AddChild(scrollOnGroupTab); } return leftSideGroupTabs; }