예제 #1
0
        private bool ValidateGoodSpeedSettingGreaterThan0(string speedSetting, string speedLocation)
        {
            string actualSpeedValueString = ActiveValue(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.ActiveSliceEngine().MapContains(speedSetting) &&
                 speedToCheck <= 0))
            {
                OrganizerSettingsData 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);
        }
        void PopulateLayoutDictionary()
        {
            string UserLevel = "Advanced"; //Show all settings

            for (int categoryIndex = 0; categoryIndex < SliceSettingsOrganizer.Instance.UserLevels[UserLevel].CategoriesList.Count; categoryIndex++)
            {
                OrganizerCategory category = SliceSettingsOrganizer.Instance.UserLevels[UserLevel].CategoriesList[categoryIndex];

                for (int groupIndex = 0; groupIndex < category.GroupsList.Count; groupIndex++)
                {
                    OrganizerGroup group = category.GroupsList[groupIndex];

                    for (int subGroupIndex = 0; subGroupIndex < group.SubGroupsList.Count; subGroupIndex++)
                    {
                        OrganizerSubGroup subgroup = group.SubGroupsList[subGroupIndex];
                        for (int settingIndex = 0; settingIndex < subgroup.SettingDataList.Count; settingIndex++)
                        {
                            OrganizerSettingsData setting = subgroup.SettingDataList[settingIndex];
                            string settingDisplayName     = "{0} > {1} > {2}".FormatWith(category.Name, group.Name, setting.PresentationName).Replace("\\n", "").Replace(":", "");
                            settingLayoutData[setting.SlicerConfigName] = settingDisplayName;
                        }
                    }
                }
            }
        }
예제 #3
0
        private void AddInHelpText(FlowLayoutWidget topToBottomSettings, OrganizerSettingsData settingInfo)
        {
            FlowLayoutWidget allText         = new FlowLayoutWidget(FlowDirection.TopToBottom);
            double           textRegionWidth = 380;

            allText.Margin          = new BorderDouble(3);
            allText.Padding         = new BorderDouble(5);
            allText.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;

            double helpPointSize = 10;

            EnglishTextWrapping wrapper = new EnglishTextWrapping(helpPointSize);

            string[] wrappedText = wrapper.WrapText(settingInfo.HelpText, textRegionWidth - allText.Padding.Width);
            foreach (string line in wrappedText)
            {
                GuiWidget helpWidget = new TextWidget(line, pointSize: helpPointSize, textColor: RGBA_Bytes.White);
                helpWidget.Margin  = new BorderDouble(5, 0, 0, 0);
                helpWidget.HAnchor = HAnchor.ParentLeft;
                allText.AddChild(helpWidget);
            }

            allText.MinimumSize = new Vector2(textRegionWidth, allText.MinimumSize.y);
            if (wrappedText.Length > 0)
            {
                topToBottomSettings.AddChild(allText);
            }
        }
        void AddSettingToPreset()
        {
            UiThread.RunOnIdle((state) =>
            {
                if (addRowSettingData != null)
                {
                    if (!this.windowController.ActivePresetLayer.settingsDictionary.ContainsKey(addRowSettingData.SlicerConfigName))
                    {
                        DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
                        sliceSetting.Name  = addRowSettingData.SlicerConfigName;
                        sliceSetting.Value = ActiveSliceSettings.Instance.GetActiveValue(addRowSettingData.SlicerConfigName); //populate with current
                        sliceSetting.SettingsCollectionId = this.windowController.ActivePresetLayer.settingsCollectionData.Id;

                        this.windowController.ActivePresetLayer.settingsDictionary[addRowSettingData.SlicerConfigName] = sliceSetting;

                        OnSettingsChanged();
                        HasUncommittedChanges = true;
                    }
                    addRowSettingData = null;
                    PopulateAddSettingRow(-1, -1, "-1");
                    LoadSettingsRows();

                    duplicatePresetButton.Visible = false;
                    exportPresetButton.Visible    = false;
                }
                else
                {
                    errorMessageContainer.Visible = true;
                }
            });
        }
        void OnSettingSelected(object sender, EventArgs e)
        {
            MenuItem item = (MenuItem)sender;

            string[] valueArray = item.Value.Split(':');
            string   configName = valueArray[2];

            addRowSettingData = SliceSettingsOrganizer.Instance.GetSettingsData(configName);
            AddSettingToPreset();
        }
        private TextWidget getSettingInfoData(OrganizerSettingsData settingData)
        {
            string extraSettings = settingData.ExtraSettings;

            extraSettings = extraSettings.Replace("\\n", "\n");
            TextWidget dataTypeInfo = new TextWidget(extraSettings, pointSize: 10);

            dataTypeInfo.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            dataTypeInfo.Margin    = new BorderDouble(5, 0);
            return(dataTypeInfo);
        }
예제 #7
0
        private void LoadAndParseSettingsFiles()
        {
            string propertiesFileContents = StaticData.Instance.ReadAllText(Path.Combine("SliceSettings", "Properties.json"));

            settingsData = JsonConvert.DeserializeObject <List <OrganizerSettingsData> >(propertiesFileContents) as List <OrganizerSettingsData>;

            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:
                        OrganizerSettingsData 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 CallEventsOnSettingsChange(OrganizerSettingsData settingData)
        {
            foreach (KeyValuePair <string, RootedObjectEventHandler> keyValue in functionsToCallOnChange)
            {
                if (keyValue.Key == settingData.SlicerConfigName)
                {
                    keyValue.Value.CallEvents(null, null);
                }
            }

            if (settingToReloadUiWhenChanged.Contains(settingData.SlicerConfigName))
            {
                ApplicationController.Instance.ReloadAll(null, null);
            }
        }
        void LoadSettingsRows()
        {
            settingsRowContainer.RemoveAllChildren();
            UiThread.RunOnIdle((state) =>
            {
                foreach (KeyValuePair <String, DataStorage.SliceSetting> item in this.windowController.ActivePresetLayer.settingsDictionary)
                {
                    OrganizerSettingsData settingData = SliceSettingsOrganizer.Instance.GetSettingsData(item.Key);
                    FlowLayoutWidget row = GetSettingsRow(settingData, item.Value.Value);
                    row.Padding          = new BorderDouble(3, 3, 3, 6);

                    settingsRowContainer.AddChild(row);
                    settingsRowContainer.AddChild(new HorizontalLine());
                }
            });
        }
예제 #10
0
        private TabControl CreateExtraSettingsSideTabsAndPages(int minSettingNameWidth, TabControl categoryTabs, out int count)
        {
            count = 0;
            TabControl sideTabs = new TabControl(Orientation.Vertical);

            sideTabs.Margin             = new BorderDouble(0, 0, 0, 5);
            sideTabs.TabBar.BorderColor = RGBA_Bytes.White;
            {
                TabPage             groupTabPage   = new TabPage("Extra Settings");
                SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget(groupTabPage, 14,
                                                                             ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), ActiveTheme.Instance.TabLabelUnselected, new RGBA_Bytes());
                sideTabs.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;

                foreach (KeyValuePair <string, DataStorage.SliceSetting> item in ActiveSliceSettings.Instance.DefaultSettings)
                {
                    if (!SliceSettingsOrganizer.Instance.Contains(UserLevel, item.Key))
                    {
                        OrganizerSettingsData settingInfo            = new OrganizerSettingsData(item.Key, item.Key, OrganizerSettingsData.DataEditTypes.STRING);
                        GuiWidget             controlsForThisSetting = CreateSettingInfoUIControls(settingInfo, minSettingNameWidth);
                        topToBottomSettings.AddChild(controlsForThisSetting);
                        count++;
                    }
                }

                GroupBox groupBox = new GroupBox(LocalizedString.Get("Extra"));
                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(sideTabs);
        }
		private TextWidget getSettingInfoData(OrganizerSettingsData settingData)
		{
			string extraSettings = settingData.ExtraSettings;
			extraSettings = extraSettings.Replace("\\n", "\n");
			TextWidget dataTypeInfo = new TextWidget(extraSettings, pointSize: 10);
			dataTypeInfo.TextColor = ActiveTheme.Instance.PrimaryTextColor;
			dataTypeInfo.Margin = new BorderDouble(5, 0);
			return dataTypeInfo;
		}
		private FlowLayoutWidget GetSettingsRow(OrganizerSettingsData settingData, string sliceSettingValue = null)
		{
			FlowLayoutWidget container = new FlowLayoutWidget();
			container.HAnchor = HAnchor.ParentLeftRight;

			double minSettingNameWidth = 400;

			if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
			{
				int intEditWidth = 60;
				int doubleEditWidth = 60;
				int vectorXYEditWidth = 60;
				int multiLineEditHeight = 60;

				//Get the current value as a default value
				if (sliceSettingValue == null)
				{
					sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
				}

				//Get the presentation name from the SettingNameLookup
				TextWidget settingName = new TextWidget(SettingNameLookup[settingData.SlicerConfigName], pointSize: 10);
				settingName.AutoExpandBoundsToText = false;
				settingName.EllipsisIfClipped = true;
				settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				settingName.VAnchor = Agg.UI.VAnchor.ParentCenter;
				settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.Height);
				settingName.Width = minSettingNameWidth;

				container.AddChild(settingName);

				switch (settingData.DataEditType)
				{
					case OrganizerSettingsData.DataEditTypes.INT:
						{
							int currentValue = 0;
							int.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
							intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
							container.AddChild(intEditWidget);
							container.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.DOUBLE:
						{
							double currentValue = 0;
							double.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
							doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
							container.AddChild(doubleEditWidget);
							container.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.POSITIVE_DOUBLE:
						{
							double currentValue = 0;
							double.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
							doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
							container.AddChild(doubleEditWidget);
							container.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.OFFSET:
						{
							double currentValue = 0;
							double.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
							doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
							container.AddChild(doubleEditWidget);
							container.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
						{
							FlowLayoutWidget content = new FlowLayoutWidget();

							MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: doubleEditWidth - 2, tabIndex: tabIndexForItem++);
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								TextEditWidget textEditWidget = (TextEditWidget)sender;
								string text = textEditWidget.Text;
								text = 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;
								SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
							};
							stringEdit.SelectAllOnFocus = true;

							stringEdit.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) =>
							{
								// select evrything 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);
							content.AddChild(getSettingInfoData(settingData));

							container.AddChild(content);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.INT_OR_MM:
						{
							FlowLayoutWidget content = new FlowLayoutWidget();

							MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: doubleEditWidth - 2, tabIndex: tabIndexForItem++);
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								TextEditWidget textEditWidget = (TextEditWidget)sender;
								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;
								SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
							};
							stringEdit.SelectAllOnFocus = true;

							stringEdit.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) =>
							{
								// select evrything 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);
							content.AddChild(getSettingInfoData(settingData));

							container.AddChild(content);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
						{
							CheckBox checkBoxWidget = new CheckBox("");
							checkBoxWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
							checkBoxWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
							checkBoxWidget.Checked = (sliceSettingValue == "1");
							checkBoxWidget.CheckedStateChanged += (sender, e) =>
							{
								if (((CheckBox)sender).Checked)
								{
									SaveSetting(settingData.SlicerConfigName, "1");
								}
								else
								{
									SaveSetting(settingData.SlicerConfigName, "0");
								}
							};
							container.AddChild(checkBoxWidget);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.STRING:
						{
							MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text); };
							container.AddChild(stringEdit);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
						{
							string convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
							MHTextEditWidget stringEdit = new MHTextEditWidget(convertedNewLines, pointSize: 10, pixelWidth: 280, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n")); };
							container.AddChild(stringEdit);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.LIST:
						{
							StyledDropDownList selectableOptions = new StyledDropDownList("None", Direction.Down);
							selectableOptions.Margin = new BorderDouble();

							string[] listItems = settingData.ExtraSettings.Split(',');
							foreach (string listItem in listItems)
							{
								MenuItem newItem = selectableOptions.AddItem(listItem);
								if (newItem.Text == sliceSettingValue)
								{
									selectableOptions.SelectedLabel = sliceSettingValue;
								}

								newItem.Selected += (sender, e) =>
								{
									MenuItem menuItem = ((MenuItem)sender);
									SaveSetting(settingData.SlicerConfigName, menuItem.Text);
								};
							}
							container.AddChild(selectableOptions);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.HARDWARE_PRESENT:
						// this is not editable for a detail setting (quality or material)
						break;

					case OrganizerSettingsData.DataEditTypes.VECTOR2:
						{
							string[] xyValueStrings = sliceSettingValue.Split(',');
							if (xyValueStrings.Length != 2)
							{
								xyValueStrings = new string[] { "0", "0" };
							}
							double currentXValue = 0;
							double.TryParse(xyValueStrings[0], out currentXValue);
							MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

							double currentYValue = 0;
							double.TryParse(xyValueStrings[1], out currentYValue);
							MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
							{
								xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
								container.AddChild(xEditWidget);
								TextWidget xText = new TextWidget("x");
								xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
								xText.Margin = new BorderDouble(5, 0);
								container.AddChild(xText);
							}
							{
								yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
								container.AddChild(yEditWidget);
								TextWidget yText = new TextWidget("y");
								yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
								yText.Margin = new BorderDouble(5, 0);
								container.AddChild(yText);
							}
						}
						break;

					case OrganizerSettingsData.DataEditTypes.OFFSET2:
						{
							string[] xyValueStrings = sliceSettingValue.Split('x');
							if (xyValueStrings.Length != 2)
							{
								xyValueStrings = new string[] { "0", "0" };
							}
							double currentXValue = 0;
							double.TryParse(xyValueStrings[0], out currentXValue);
							MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

							double currentYValue = 0;
							double.TryParse(xyValueStrings[1], out currentYValue);
							MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
							{
								xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
								container.AddChild(xEditWidget);
								TextWidget xText = new TextWidget("x");
								xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
								xText.Margin = new BorderDouble(5, 0);
								container.AddChild(xText);
							}
							{
								yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
								container.AddChild(yEditWidget);
								TextWidget yText = new TextWidget("y");
								yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
								yText.Margin = new BorderDouble(5, 0);
								container.AddChild(yText);
							}
						}
						break;

					default:
						TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
						missingSetting.TextColor = ActiveTheme.Instance.PrimaryTextColor;
						missingSetting.BackgroundColor = RGBA_Bytes.Red;
						container.AddChild(missingSetting);
						break;
				}
			}
			else // the setting we think we are adding is not in the config.ini it may have been depricated
			{
				TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
				settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
				container.AddChild(settingName);
				container.BackgroundColor = RGBA_Bytes.Red;
			}
			container.AddChild(new HorizontalSpacer());
			Button removeLink = linkButtonFactory.Generate("remove");
			removeLink.Click += (sender, e) =>
			{
				RemoveSetting(settingData.SlicerConfigName);
			};
			removeLink.VAnchor = Agg.UI.VAnchor.ParentCenter;
			container.AddChild(removeLink);

			return container;
		}
		private void AddSettingToPreset()
		{
			UiThread.RunOnIdle(() =>
			{
				if (addRowSettingData != null)
				{
					if (!this.windowController.ActivePresetLayer.settingsDictionary.ContainsKey(addRowSettingData.SlicerConfigName))
					{
						DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
						sliceSetting.Name = addRowSettingData.SlicerConfigName;
						sliceSetting.Value = ActiveSliceSettings.Instance.GetActiveValue(addRowSettingData.SlicerConfigName); //populate with current
						sliceSetting.SettingsCollectionId = this.windowController.ActivePresetLayer.settingsCollectionData.Id;

						this.windowController.ActivePresetLayer.settingsDictionary[addRowSettingData.SlicerConfigName] = sliceSetting;

						OnSettingsChanged();
					}
					addRowSettingData = null;
					PopulateAddSettingRow(-1, -1, "-1");
					LoadSettingsRows();

					duplicatePresetButton.Visible = false;
					exportPresetButton.Visible = false;
				}
				else
				{
					errorMessageContainer.Visible = true;
				}
			});
		}
예제 #14
0
		private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth, int extruderIndex)
		{
			GuiWidget container = new GuiWidget();
			this.HAnchor = HAnchor.ParentLeftRight;

			string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);

			var settingsRow = new SettingsRow()
			{
				SettingsKey = settingData.SlicerConfigName,
				SettingsValue = sliceSettingValue
			};

			if (!ActiveSliceSettings.Instance.InBaseConfig(settingData.SlicerConfigName))
			{
				// the setting we think we are adding is not in the config.ini it may have been deprecated
				TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
				settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
				settingsRow.AddChild(settingName);
				settingsRow.BackgroundColor = RGBA_Bytes.Red;
			}
			else
			{
				int intEditWidth = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);
				int doubleEditWidth = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);
				if (settingData.QuickMenuSettings.Count > 0)
				{
					doubleEditWidth = (int)(35 * TextWidget.GlobalPointSizeScaleRatio + .5);
				}
				int vectorXYEditWidth = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);
				int multiLineEditHeight = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);


				if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
				{
					var nameHolder = new GuiWidget(HAnchor.AbsolutePosition, VAnchor.FitToChildren | VAnchor.ParentCenter)
					{
						Width = minSettingNameWidth,
						Padding = new BorderDouble(0, 0, 5, 0),
					};

					nameHolder.AddChild(new WrappedTextWidget(
						settingData.PresentationName.Localize(), 
						minSettingNameWidth, 
						pointSize: 10, 
						textColor: ActiveTheme.Instance.PrimaryTextColor));

					settingsRow.AddChild(nameHolder);
				}

				switch (settingData.DataEditType)
				{
					case OrganizerSettingsData.DataEditTypes.INT:
						{
							int currentValue;
							int.TryParse(sliceSettingValue, out currentValue);

							var intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++)
							{
								ToolTipText = settingData.HelpText,
								SelectAllOnFocus = true
							};
							intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};

							settingsRow.AddChild(intEditWidget);
							settingsRow.AddChild(GetExtraSettingsWidget(settingData));

							settingsRow.ValueChanged = (text) => intEditWidget.Text = text;
						}
						break;

					case OrganizerSettingsData.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) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};
							settingsRow.AddChild(doubleEditWidget);
							settingsRow.AddChild(GetExtraSettingsWidget(settingData));

							settingsRow.ValueChanged = (text) =>
							{
								double currentValue2 = 0;
								double.TryParse(text, out currentValue2);
								doubleEditWidget.ActuallNumberEdit.Value = currentValue2;
							};
						}
						break;

					case OrganizerSettingsData.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 = ActiveSliceSettings.Instance.GetActiveValue(settingData.SetSettingsOnChange[0]);
								for (int i = 1; i < settingData.SetSettingsOnChange.Count; i++)
								{
									string nextSetting = ActiveSliceSettings.Instance.GetActiveValue(settingData.SetSettingsOnChange[i]);
									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)
									{
										SaveSetting(setting, numberEdit.Value.ToString() + "mm");
									}
								}

								// also always save to the local setting
								SaveSetting(settingData.SlicerConfigName, numberEdit.Value.ToString());
								settingsRow.UpdateStyle();
								OnSettingsChanged(settingData);
							};
							content.AddChild(doubleEditWidget);
							content.AddChild(GetExtraSettingsWidget(settingData));

							if (settingData.QuickMenuSettings.Count > 0)
							{
								settingsRow.AddChild(CreateQuickMenu(settingData, content, doubleEditWidget.ActuallNumberEdit.InternalTextEditWidget));
							}
							else
							{
								settingsRow.AddChild(content);
							}

							settingsRow.ValueChanged = (text) =>
							{
								double currentValue2 = 0;
								double.TryParse(text, out currentValue2);
								doubleEditWidget.ActuallNumberEdit.Value = currentValue2;
							};
						}
						break;

					case OrganizerSettingsData.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) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
								settingsRow.UpdateStyle();
								OnSettingsChanged(settingData);
							};
							settingsRow.AddChild(doubleEditWidget);
							settingsRow.AddChild(GetExtraSettingsWidget(settingData));

							settingsRow.ValueChanged = (text) =>
							{
								double currentValue2;
								double.TryParse(text, out currentValue2);
								doubleEditWidget.ActuallNumberEdit.Value = currentValue2;
							};
						}
						break;

					case OrganizerSettingsData.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;
								SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
								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);
							content.AddChild(GetExtraSettingsWidget(settingData));

							if (settingData.QuickMenuSettings.Count > 0)
							{
								settingsRow.AddChild(CreateQuickMenu(settingData, content, stringEdit.ActualTextEditWidget.InternalTextEditWidget));
							}
							else
							{
								settingsRow.AddChild(content);
							}

							settingsRow.ValueChanged = (text) => stringEdit.Text = text;
						}
						break;

					case OrganizerSettingsData.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;
								}
								SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);

								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);
							content.AddChild(GetExtraSettingsWidget(settingData));

							if (settingData.QuickMenuSettings.Count > 0)
							{
								settingsRow.AddChild(CreateQuickMenu(settingData, content, stringEdit.ActualTextEditWidget.InternalTextEditWidget));
							}
							else
							{
								settingsRow.AddChild(content);
							}

							settingsRow.ValueChanged = (text) => stringEdit.Text = text;
						}
						break;

					case OrganizerSettingsData.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.CheckedStateChanged += (sender, e) =>
							{
								bool isChecked = ((CheckBox)sender).Checked;
								SaveSetting(settingData.SlicerConfigName, isChecked ? "1" : "0");
								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};

							settingsRow.AddChild(checkBoxWidget);

							settingsRow.ValueChanged = (text) => checkBoxWidget.Checked = text == "1";
						}
						break;

					case OrganizerSettingsData.DataEditTypes.STRING:
						{
							var stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
							stringEdit.ToolTipText = settingData.HelpText;
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text);
								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};

							settingsRow.AddChild(stringEdit);

							settingsRow.ValueChanged = (text) => stringEdit.Text = text;
						}
						break;

					case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
						{
							string convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
							var stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
							
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"));
								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};

							settingsRow.AddChild(stringEdit);

							settingsRow.ValueChanged = (text) => stringEdit.Text = text.Replace("\\n", "\n");
						}
						break;

					case OrganizerSettingsData.DataEditTypes.LIST:
						{
							var selectableOptions = new StyledDropDownList("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);
									SaveSetting(settingData.SlicerConfigName, menuItem.Text);

									settingsRow.UpdateStyle();

									OnSettingsChanged(settingData);
								};
							}

							settingsRow.AddChild(selectableOptions);

							settingsRow.ValueChanged = (text) => selectableOptions.SelectedLabel = text;
						}
						break;

					case OrganizerSettingsData.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.CheckedStateChanged += (sender, e) =>
							{
								bool isChecked = ((CheckBox)sender).Checked;
								SaveSetting(settingData.SlicerConfigName, isChecked ? "1" : "0");

								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};

							settingsRow.AddChild(checkBoxWidget);

							settingsRow.ValueChanged = (text) => checkBoxWidget.Checked = text == "1";
						}
						break;

					case OrganizerSettingsData.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,
								Margin = new BorderDouble(0, 0, 30 * TextWidget.GlobalPointSizeScaleRatio, 0),
								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
							};

							xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString());

								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};
							settingsRow.AddChild(xEditWidget);

							yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString());

								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};
							settingsRow.AddChild(yEditWidget);

							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 OrganizerSettingsData.DataEditTypes.OFFSET2:
						{
							Vector2 offset = ActiveSliceSettings.Instance.GetOffset(extruderIndex);

							var xEditWidget = new MHNumberEdit(offset.x, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++)
							{
								ToolTipText = settingData.HelpText,
								SelectAllOnFocus = true,
								Margin = new BorderDouble(0, 0, 30 * TextWidget.GlobalPointSizeScaleRatio, 0)
							};

							var yEditWidget = new MHNumberEdit(offset.y, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++)
							{
								ToolTipText = settingData.HelpText,
								SelectAllOnFocus = true
							};

							xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								int extruderIndexLocal = extruderIndex;
								SaveCommaSeparatedIndexSetting(extruderIndexLocal, settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString());

								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};
							settingsRow.AddChild(xEditWidget);


							yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								int extruderIndexLocal = extruderIndex;
								SaveCommaSeparatedIndexSetting(extruderIndexLocal, settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString());

								settingsRow.UpdateStyle();

								OnSettingsChanged(settingData);
							};
							settingsRow.AddChild(yEditWidget);

							settingsRow.ValueChanged = (text) =>
							{
								Vector2 offset2 = ActiveSliceSettings.Instance.GetOffset(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
						};
						settingsRow.AddChild(missingSetting);
						break;
				}
			}

			container.HAnchor = HAnchor.ParentLeftRight;
			container.VAnchor = VAnchor.FitToChildren;

			var 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();
			};

			settingsRow.AddChild(new GuiWidget(HAnchor.ParentLeftRight));
			settingsRow.AddChild(restoreButton);

			container.AddChild(settingsRow);

			// Define the UpdateStyle implementation
			settingsRow.UpdateStyle = () =>
			{
				if (persistenceLayer.ContainsKey(settingData.SlicerConfigName))
				{
					switch (this.viewFilter)
					{
						case NamedSettingsLayers.All:
							settingsRow.BackgroundColor = userSettingBackgroundColor;
							break;
						case NamedSettingsLayers.Material:
							settingsRow.BackgroundColor = materialSettingBackgroundColor;
							break;
						case NamedSettingsLayers.Quality:
							settingsRow.BackgroundColor = qualitySettingBackgroundColor;
							break;
					}

					restoreButton.Visible = true;
				}
				else if (layerFilters == 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;
					}

					restoreButton.Visible = false;
				}
				else
				{
					restoreButton.Visible = false;
					settingsRow.BackgroundColor = RGBA_Bytes.Transparent;
				}
			};

			// Invoke the UpdateStyle implementation
			settingsRow.UpdateStyle();

			return container;
		}
예제 #15
0
        private void AddInHelpText(FlowLayoutWidget topToBottomSettings, OrganizerSettingsData settingInfo)
        {
            FlowLayoutWidget allText = new FlowLayoutWidget(FlowDirection.TopToBottom);
            double textRegionWidth = 380;
            allText.Margin = new BorderDouble(3);
            allText.Padding = new BorderDouble(5);
            allText.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;

            double helpPointSize = 10;

            string[] wrappedText = TypeFacePrinter.WrapText(settingInfo.HelpText, textRegionWidth - allText.Padding.Width, helpPointSize);
            foreach(string line in wrappedText)
            {
                GuiWidget helpWidget = new TextWidget(line, pointSize: helpPointSize, textColor: RGBA_Bytes.White);
                allText.AddChild(helpWidget);
            }

            allText.MinimumSize = new Vector2(textRegionWidth, allText.MinimumSize.y);
            if (wrappedText.Length > 0)
            {
                topToBottomSettings.AddChild(allText);
            }
        }
        void PopulateAddSettingRow(int categoryDefaultIndex = -1, int groupDefaultIndex = -1, string settingDefaultConfigName = "-1")
        {
            errorMessageContainer.Visible = false;

            categoryDropDownList             = new SettingsDropDownList("- Select Category -");
            categoryDropDownList.Margin      = new BorderDouble(right: 3);
            categoryDropDownList.MinimumSize = new Vector2(categoryDropDownList.LocalBounds.Width, categoryDropDownList.LocalBounds.Height);
            categoryDropDownList.VAnchor     = Agg.UI.VAnchor.ParentCenter;
            categoryDropDownList.Height      = 24;

            groupDropDownList             = new SettingsDropDownList("- Select Group -");
            groupDropDownList.Margin      = new BorderDouble(right: 3);
            groupDropDownList.MinimumSize = new Vector2(groupDropDownList.LocalBounds.Width, groupDropDownList.LocalBounds.Height);
            groupDropDownList.VAnchor     = Agg.UI.VAnchor.ParentCenter;
            groupDropDownList.Height      = 24;

            settingDropDownList                  = new SettingsDropDownList("- Select Setting -");
            settingDropDownList.Margin           = new BorderDouble(right: 3);
            settingDropDownList.MinimumSize      = new Vector2(settingDropDownList.LocalBounds.Width, settingDropDownList.LocalBounds.Height);
            settingDropDownList.VAnchor          = Agg.UI.VAnchor.ParentCenter;
            settingDropDownList.HAnchor          = Agg.UI.HAnchor.ParentLeftRight;
            settingDropDownList.AlignToRightEdge = true;
            settingDropDownList.Height           = 24;

            string selectedCategoryValue = "{0}:-1:-1".FormatWith(categoryDefaultIndex);
            string selectedGroupValue    = "{0}:{1}:-1".FormatWith(categoryDefaultIndex, groupDefaultIndex);
            string selectedSettingValue  = "{0}:{1}:{2}".FormatWith(categoryDefaultIndex, groupDefaultIndex, settingDefaultConfigName);

            string UserLevel = "Advanced"; //Show all settings

            for (int categoryIndex = 0; categoryIndex < SliceSettingsOrganizer.Instance.UserLevels[UserLevel].CategoriesList.Count; categoryIndex++)
            {
                OrganizerCategory category = SliceSettingsOrganizer.Instance.UserLevels[UserLevel].CategoriesList[categoryIndex];

                //Always add all categories
                MenuItem categoryMenuItem = categoryDropDownList.AddItem(category.Name, "{0}:-1:-1".FormatWith(categoryIndex));
                categoryMenuItem.Selected += new EventHandler(OnItemSelected);

                for (int groupIndex = 0; groupIndex < category.GroupsList.Count; groupIndex++)
                {
                    OrganizerGroup group      = category.GroupsList[groupIndex];
                    string         groupValue = "{0}:{1}:-1".FormatWith(categoryIndex, groupIndex);

                    //Add groups if within selected category or no category selected
                    if (categoryIndex == categoryDefaultIndex || categoryDefaultIndex == -1)
                    {
                        MenuItem groupMenuItem = groupDropDownList.AddItem(group.Name, groupValue);
                        groupMenuItem.Selected += new EventHandler(OnItemSelected);
                    }

                    for (int subGroupIndex = 0; subGroupIndex < group.SubGroupsList.Count; subGroupIndex++)
                    {
                        OrganizerSubGroup subgroup = group.SubGroupsList[subGroupIndex];
                        for (int settingIndex = 0; settingIndex < subgroup.SettingDataList.Count; settingIndex++)
                        {
                            //Add settings if within selected category and group or no category selected
                            if (selectedGroupValue == groupValue || (groupDefaultIndex == -1 && categoryIndex == categoryDefaultIndex) || categoryDefaultIndex == -1)
                            {
                                OrganizerSettingsData setting = subgroup.SettingDataList[settingIndex];
                                string itemValue = "{0}:{1}:{2}".FormatWith(categoryIndex, groupIndex, setting.SlicerConfigName);
                                string itemName  = setting.PresentationName.Replace("\\n", "").Replace(":", "");
                                if (setting.ExtraSettings.Trim() != "" && setting.DataEditType != OrganizerSettingsData.DataEditTypes.LIST)
                                {
                                    itemName = "{0} ({1})".FormatWith(itemName, setting.ExtraSettings.Replace("\\n", " "));
                                }

                                MenuItem settingMenuItem = settingDropDownList.AddItem(itemName, itemValue);
                                settingMenuItem.Selected += new EventHandler(OnItemSelected);
                                settingMenuItem.Selected += new EventHandler(OnSettingSelected);
                            }
                        }
                    }
                }
            }

            if (categoryDefaultIndex != -1)
            {
                categoryDropDownList.SelectedValue = selectedCategoryValue;
            }
            if (groupDefaultIndex != -1)
            {
                groupDropDownList.SelectedValue = selectedGroupValue;
            }
            if (settingDefaultConfigName != "-1")
            {
                settingDropDownList.SelectedValue = selectedSettingValue;
            }

            addSettingsContainer.RemoveAllChildren();
            addSettingsContainer.AddChild(categoryDropDownList);
            addSettingsContainer.AddChild(groupDropDownList);
            addSettingsContainer.AddChild(settingDropDownList);
            //addSettingsContainer.AddChild(addButton);
        }
		private void AddInHelpText(FlowLayoutWidget topToBottomSettings, OrganizerSettingsData settingInfo)
		{
			FlowLayoutWidget allText = new FlowLayoutWidget(FlowDirection.TopToBottom);
			allText.HAnchor = HAnchor.ParentLeftRight;
			double textRegionWidth = 380 * TextWidget.GlobalPointSizeScaleRatio;
			allText.Margin = new BorderDouble(3);
			allText.Padding = new BorderDouble(5);
			allText.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;

			double helpPointSize = 10;

			GuiWidget helpWidget = new WrappedTextWidget(settingInfo.HelpText, textRegionWidth, pointSize: helpPointSize, textColor: RGBA_Bytes.White);
			helpWidget.Margin = new BorderDouble(5, 0, 0, 0);
			//helpWidget.HAnchor = HAnchor.ParentLeft;
			allText.AddChild(helpWidget);

			allText.MinimumSize = new Vector2(textRegionWidth, allText.MinimumSize.y);
			topToBottomSettings.AddChild(allText);
		}
		private GuiWidget CreateQuickMenu(OrganizerSettingsData settingData, GuiWidget content, InternalTextEditWidget internalTextWidget)
		{
			string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
			FlowLayoutWidget totalContent = new FlowLayoutWidget();

			StyledDropDownList selectableOptions = new StyledDropDownList("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) =>
				{
					SaveSetting(settingData.SlicerConfigName, valueLocal);
					CallEventsOnSettingsChange(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);

			internalTextWidget.EditComplete += (sender, e) =>
			{
				bool foundSetting = false;
				foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
				{
					string localName = nameValue.MenuName;
					string newSliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
					if (newSliceSettingValue == nameValue.Value)
					{
						selectableOptions.SelectedLabel = localName;
						foundSetting = true;
						break;
					}
				}

				if (!foundSetting)
				{
					selectableOptions.SelectedLabel = "Custom";
				}
			};

			return totalContent;
		}
예제 #19
0
        void LoadAndParseSettingsFiles(string properties, string layout)
        {
            {
                string propertiesFileContents = "";
                using (FileStream fileStream = new FileStream(properties, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader propertiesReader = new StreamReader(fileStream))
                    {
                        propertiesFileContents = propertiesReader.ReadToEnd();
                    }
                }

                string[] lines = propertiesFileContents.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Trim().Length > 0)
                    {
                        settingsData.Add(OrganizerSettingsData.NewOrganizerSettingData(line));
                    }
                }
            }

            {
                string layoutFileContents = "";
                using (FileStream fileStream = new FileStream(layout, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader layoutReader = new StreamReader(fileStream))
                    {
                        layoutFileContents = layoutReader.ReadToEnd();
                    }
                }

                OrganizerUserLevel userLevelToAddTo = null;
                OrganizerCategory  categoryToAddTo  = null;
                OrganizerGroup     groupToAddTo     = null;
                OrganizerSubGroup  subGroupToAddTo  = null;
                string[]           lines            = layoutFileContents.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Length > 0)
                    {
                        switch (CountLeadingSpaces(line))
                        {
                        case 0:
                            string userLevelText = line.Replace('"', ' ').Trim();
                            userLevelToAddTo = new OrganizerUserLevel(userLevelText);
                            UserLevels.Add(userLevelText, userLevelToAddTo);
                            break;

                        case 2:
                            categoryToAddTo = new OrganizerCategory(line.Replace('"', ' ').Trim());
                            userLevelToAddTo.CategoriesList.Add(categoryToAddTo);
                            break;

                        case 4:
                            groupToAddTo = new OrganizerGroup(line.Replace('"', ' ').Trim());
                            categoryToAddTo.GroupsList.Add(groupToAddTo);
                            break;

                        case 6:
                            subGroupToAddTo = new OrganizerSubGroup(line.Replace('"', ' ').Trim());
                            groupToAddTo.SubGroupsList.Add(subGroupToAddTo);
                            break;

                        case 8:
                            subGroupToAddTo.SettingDataList.Add(GetSettingsData(line.Replace('"', ' ').Trim()));
                            break;

                        default:
                            throw new Exception("Bad file, too many spaces (must be 0, 2, 4 or 6).");
                        }
                    }
                }
            }
        }
예제 #20
0
        private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth)
        {
            GuiWidget        container         = new GuiWidget();
            FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();

            bool addQualityOverlay  = false;
            bool addMaterialOverlay = false;

            RGBA_Bytes qualityOverlayColor  = new RGBA_Bytes(255, 255, 0, 40);
            RGBA_Bytes materialOverlayColor = new RGBA_Bytes(255, 127, 0, 40);

            if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
            {
                int intEditWidth        = 60;
                int doubleEditWidth     = 60;
                int vectorXYEditWidth   = 60;
                int multiLineEditHeight = 60;



                string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
                leftToRightLayout.Margin  = new BorderDouble(0, 2);
                leftToRightLayout.Padding = new BorderDouble(3);
                leftToRightLayout.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

                if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
                {
                    string convertedNewLines = settingData.PresentationName.Replace("\\n ", "\n");
                    convertedNewLines = convertedNewLines.Replace("\\n", "\n");
                    convertedNewLines = LocalizedString.Get(convertedNewLines);
                    TextWidget settingName = new TextWidget(convertedNewLines);
                    settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;

                    if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, 3))
                    {
                        addMaterialOverlay = true;
                    }
                    else if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, 2))
                    {
                        addQualityOverlay = true;
                    }

                    settingName.Width = minSettingNameWidth;
                    //settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                    leftToRightLayout.AddChild(settingName);
                }

                switch (settingData.DataEditType)
                {
                case OrganizerSettingsData.DataEditTypes.INT:
                {
                    int currentValue = 0;
                    int.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
                    intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(intEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.POSITIVE_DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 60, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                    {
                        TextEditWidget textEditWidget = (TextEditWidget)sender;
                        string         text           = textEditWidget.Text;
                        text = 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;
                        SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
                    };

                    leftToRightLayout.AddChild(stringEdit);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
                {
                    CheckBox checkBoxWidget = new CheckBox("");
                    checkBoxWidget.VAnchor              = Agg.UI.VAnchor.ParentBottom;
                    checkBoxWidget.TextColor            = ActiveTheme.Instance.PrimaryTextColor;
                    checkBoxWidget.Checked              = (sliceSettingValue == "1");
                    checkBoxWidget.CheckedStateChanged += (sender, e) =>
                    {
                        if (((CheckBox)sender).Checked)
                        {
                            SaveSetting(settingData.SlicerConfigName, "1");
                        }
                        else
                        {
                            SaveSetting(settingData.SlicerConfigName, "0");
                        }
                    };
                    leftToRightLayout.AddChild(checkBoxWidget);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.STRING:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text); };
                    leftToRightLayout.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
                {
                    string           convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
                    MHTextEditWidget stringEdit        = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n")); };
                    leftToRightLayout.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.LIST:
                {
                    StyledDropDownList selectableOptions = new StyledDropDownList("None", maxHeight: 200);
                    selectableOptions.Margin = new BorderDouble();

                    string[] listItems = settingData.ExtraSettings.Split(',');
                    foreach (string listItem in listItems)
                    {
                        MenuItem newItem = selectableOptions.AddItem(listItem);
                        if (newItem.Text == sliceSettingValue)
                        {
                            selectableOptions.SelectedLabel = sliceSettingValue;
                        }

                        newItem.Selected += (sender, e) =>
                        {
                            MenuItem menuItem = ((MenuItem)sender);
                            SaveSetting(settingData.SlicerConfigName, menuItem.Text);
                        };
                    }
                    leftToRightLayout.AddChild(selectableOptions);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.VECTOR2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split(',');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(yText);
                    }
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split('x');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(yText);
                    }
                }
                break;

                default:
                    TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
                    missingSetting.TextColor       = ActiveTheme.Instance.PrimaryTextColor;
                    missingSetting.BackgroundColor = RGBA_Bytes.Red;
                    leftToRightLayout.AddChild(missingSetting);
                    break;
                }
            }
            else // the setting we think we are adding is not in the config.ini it may have been depricated
            {
                TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
                settingName.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                leftToRightLayout.AddChild(settingName);
                leftToRightLayout.BackgroundColor = RGBA_Bytes.Red;
            }

            container.HAnchor = HAnchor.ParentLeftRight;
            container.VAnchor = VAnchor.FitToChildren;

            container.AddChild(leftToRightLayout);

            if (addQualityOverlay || addMaterialOverlay)
            {
                SettingPresetOverlay overlay = new SettingPresetOverlay();
                overlay.HAnchor = HAnchor.ParentLeftRight;
                overlay.VAnchor = Agg.UI.VAnchor.ParentBottomTop;

                SettingPresetClick clickToEdit = new SettingPresetClick();
                clickToEdit.HAnchor = HAnchor.ParentLeftRight;
                clickToEdit.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
                clickToEdit.Visible = false;

                Button editButton = buttonFactory.Generate("Edit Preset".Localize().ToUpper());
                editButton.HAnchor = Agg.UI.HAnchor.ParentCenter;
                editButton.VAnchor = Agg.UI.VAnchor.ParentCenter;

                clickToEdit.AddChild(editButton);

                if (addQualityOverlay)
                {
                    overlay.OverlayColor     = qualityOverlayColor;
                    clickToEdit.OverlayColor = qualityOverlayColor;
                    editButton.Click        += (sender, e) =>
                    {
                        if (ApplicationWidget.Instance.EditSlicePresetsWindow == null)
                        {
                            ApplicationWidget.Instance.EditSlicePresetsWindow         = new SlicePresetsWindow(ReloadOptions, "Quality", "quality", false, ActivePrinterProfile.Instance.ActiveQualitySettingsID);
                            ApplicationWidget.Instance.EditSlicePresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationWidget.Instance.EditSlicePresetsWindow = null; };
                        }
                        else
                        {
                            ApplicationWidget.Instance.EditSlicePresetsWindow.ChangeToSlicePresetFromID(ActivePrinterProfile.Instance.ActiveQualitySettingsID);
                            ApplicationWidget.Instance.EditSlicePresetsWindow.BringToFront();
                        }
                    };
                }
                else if (addMaterialOverlay)
                {
                    overlay.OverlayColor     = materialOverlayColor;
                    clickToEdit.OverlayColor = materialOverlayColor;
                    editButton.Click        += (sender, e) =>
                    {
                        if (ApplicationWidget.Instance.EditSlicePresetsWindow == null)
                        {
                            ApplicationWidget.Instance.EditSlicePresetsWindow         = new SlicePresetsWindow(ReloadOptions, "Material", "material", false, ActivePrinterProfile.Instance.GetMaterialSetting(1));
                            ApplicationWidget.Instance.EditSlicePresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationWidget.Instance.EditSlicePresetsWindow = null; };
                        }
                        else
                        {
                            ApplicationWidget.Instance.EditSlicePresetsWindow.ChangeToSlicePresetFromID(ActivePrinterProfile.Instance.GetMaterialSetting(1));
                            ApplicationWidget.Instance.EditSlicePresetsWindow.BringToFront();
                        }
                    };
                }

                container.MouseEnterBounds += (sender, e) =>
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        overlay.Visible     = false;
                        clickToEdit.Visible = true;
                    });
                };

                container.MouseLeaveBounds += (sender, e) =>
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        overlay.Visible     = true;
                        clickToEdit.Visible = false;
                    });
                };

                container.AddChild(overlay);
                container.AddChild(clickToEdit);
            }



            return(container);
        }
예제 #21
0
		private static bool CheckIfShouldBeShown(OrganizerSettingsData settingInfo)
		{
			bool settingShouldBeShown = true;
			if (settingInfo.ShowIfSet != null
				&& settingInfo.ShowIfSet != "")
			{
				string showValue = "0";
				string checkName = settingInfo.ShowIfSet;
				if (checkName.StartsWith("!"))
				{
					showValue = "1";
					checkName = checkName.Substring(1);
				}
				string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(checkName);
				if (sliceSettingValue == showValue)
				{
					settingShouldBeShown = false;
				}
			}

			return settingShouldBeShown;
		}
		static public OrganizerSettingsData NewOrganizerSettingData(string slicerConfigName, string presentationName, OrganizerSettingsData.DataEditTypes dataEditType, string extraSettings = "", string helpText = "")
		{
			return new OrganizerSettingsData(slicerConfigName, presentationName, dataEditType, extraSettings, helpText);
		}
예제 #23
0
        private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth)
        {
            FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();

            if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
            {
                int intEditWidth        = 60;
                int doubleEditWidth     = 60;
                int vectorXYEditWidth   = 60;
                int multiLineEditHeight = 60;

                string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
                leftToRightLayout.Margin   = new BorderDouble(0, 5);
                leftToRightLayout.HAnchor |= Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
                {
                    string convertedNewLines = settingData.PresentationName.Replace("\\n ", "\n");
                    convertedNewLines = convertedNewLines.Replace("\\n", "\n");
                    convertedNewLines = new LocalizedString(convertedNewLines).Translated;
                    TextWidget settingName = new TextWidget(convertedNewLines);
                    settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                    settingName.Width     = minSettingNameWidth;
                    //settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                    leftToRightLayout.AddChild(settingName);
                }

                switch (settingData.DataEditType)
                {
                case OrganizerSettingsData.DataEditTypes.INT:
                {
                    int currentValue = 0;
                    int.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
                    intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(intEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.POSITVE_DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 60, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                    {
                        TextEditWidget textEditWidget = (TextEditWidget)sender;
                        string         text           = textEditWidget.Text;
                        text = 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;
                        SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
                    };

                    leftToRightLayout.AddChild(stringEdit);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
                {
                    CheckBox checkBoxWidget = new CheckBox("");
                    checkBoxWidget.VAnchor              = Agg.UI.VAnchor.ParentBottom;
                    checkBoxWidget.TextColor            = ActiveTheme.Instance.PrimaryTextColor;
                    checkBoxWidget.Checked              = (sliceSettingValue == "1");
                    checkBoxWidget.CheckedStateChanged += (sender, e) =>
                    {
                        if (((CheckBox)sender).Checked)
                        {
                            SaveSetting(settingData.SlicerConfigName, "1");
                        }
                        else
                        {
                            SaveSetting(settingData.SlicerConfigName, "0");
                        }
                    };
                    leftToRightLayout.AddChild(checkBoxWidget);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.STRING:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text); };
                    leftToRightLayout.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
                {
                    string           convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
                    MHTextEditWidget stringEdit        = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n")); };
                    leftToRightLayout.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.LIST:
                {
                    StyledDropDownList selectableOptions = new StyledDropDownList("None", Direction.Up);
                    selectableOptions.Margin = new BorderDouble();

                    string[] listItems = settingData.ExtraSettings.Split(',');
                    foreach (string listItem in listItems)
                    {
                        MenuItem newItem = selectableOptions.AddItem(listItem);
                        if (newItem.Text == sliceSettingValue)
                        {
                            selectableOptions.SelectedValue = sliceSettingValue;
                        }

                        newItem.Selected += (sender, e) =>
                        {
                            MenuItem menuItem = ((MenuItem)sender);
                            SaveSetting(settingData.SlicerConfigName, menuItem.Text);
                        };
                    }
                    leftToRightLayout.AddChild(selectableOptions);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.VECTOR2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split(',');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(yText);
                    }
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split('x');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(yText);
                    }
                }
                break;

                default:
                    TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
                    missingSetting.TextColor       = ActiveTheme.Instance.PrimaryTextColor;
                    missingSetting.BackgroundColor = RGBA_Bytes.Red;
                    leftToRightLayout.AddChild(missingSetting);
                    break;
                }
            }
            else // the setting we think we are adding is not in the config.ini it may have been depricated
            {
                TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
                settingName.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                leftToRightLayout.AddChild(settingName);
                leftToRightLayout.BackgroundColor = RGBA_Bytes.Red;
            }

            return(leftToRightLayout);
        }
        private FlowLayoutWidget GetSettingsRow(OrganizerSettingsData settingData, string sliceSettingValue = null)
        {
            FlowLayoutWidget container = new FlowLayoutWidget();

            container.HAnchor = HAnchor.ParentLeftRight;

            double minSettingNameWidth = 400;

            if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
            {
                int intEditWidth        = 60;
                int doubleEditWidth     = 60;
                int vectorXYEditWidth   = 60;
                int multiLineEditHeight = 60;

                //Get the current value as a default value
                if (sliceSettingValue == null)
                {
                    sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
                }

                //Get the presentation name from the SettingNameLookup
                TextWidget settingName = new TextWidget(SettingNameLookup[settingData.SlicerConfigName], pointSize: 10);
                settingName.AutoExpandBoundsToText = false;
                settingName.EllipsisIfClipped      = true;
                settingName.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                settingName.VAnchor     = Agg.UI.VAnchor.ParentCenter;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.Height);
                settingName.Width       = minSettingNameWidth;

                container.AddChild(settingName);


                switch (settingData.DataEditType)
                {
                case OrganizerSettingsData.DataEditTypes.INT:
                {
                    int currentValue = 0;
                    int.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
                    intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    container.AddChild(intEditWidget);
                    container.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    container.AddChild(doubleEditWidget);
                    container.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.POSITIVE_DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    container.AddChild(doubleEditWidget);
                    container.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    container.AddChild(doubleEditWidget);
                    container.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 60, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                    {
                        TextEditWidget textEditWidget = (TextEditWidget)sender;
                        string         text           = textEditWidget.Text;
                        text = 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;
                        SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
                    };

                    container.AddChild(stringEdit);
                    container.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
                {
                    CheckBox checkBoxWidget = new CheckBox("");
                    checkBoxWidget.VAnchor              = Agg.UI.VAnchor.ParentBottom;
                    checkBoxWidget.TextColor            = ActiveTheme.Instance.PrimaryTextColor;
                    checkBoxWidget.Checked              = (sliceSettingValue == "1");
                    checkBoxWidget.CheckedStateChanged += (sender, e) =>
                    {
                        if (((CheckBox)sender).Checked)
                        {
                            SaveSetting(settingData.SlicerConfigName, "1");
                        }
                        else
                        {
                            SaveSetting(settingData.SlicerConfigName, "0");
                        }
                    };
                    container.AddChild(checkBoxWidget);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.STRING:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text); };
                    container.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
                {
                    string           convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
                    MHTextEditWidget stringEdit        = new MHTextEditWidget(convertedNewLines, pointSize: 10, pixelWidth: 280, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n")); };
                    container.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.LIST:
                {
                    StyledDropDownList selectableOptions = new StyledDropDownList("None", Direction.Down);
                    selectableOptions.Margin = new BorderDouble();

                    string[] listItems = settingData.ExtraSettings.Split(',');
                    foreach (string listItem in listItems)
                    {
                        MenuItem newItem = selectableOptions.AddItem(listItem);
                        if (newItem.Text == sliceSettingValue)
                        {
                            selectableOptions.SelectedLabel = sliceSettingValue;
                        }

                        newItem.Selected += (sender, e) =>
                        {
                            MenuItem menuItem = ((MenuItem)sender);
                            SaveSetting(settingData.SlicerConfigName, menuItem.Text);
                        };
                    }
                    container.AddChild(selectableOptions);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.VECTOR2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split(',');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        container.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        container.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        container.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        container.AddChild(yText);
                    }
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split('x');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        container.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        container.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        container.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        container.AddChild(yText);
                    }
                }
                break;

                default:
                    TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
                    missingSetting.TextColor       = ActiveTheme.Instance.PrimaryTextColor;
                    missingSetting.BackgroundColor = RGBA_Bytes.Red;
                    container.AddChild(missingSetting);
                    break;
                }
            }
            else // the setting we think we are adding is not in the config.ini it may have been depricated
            {
                TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
                settingName.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                container.AddChild(settingName);
                container.BackgroundColor = RGBA_Bytes.Red;
            }
            container.AddChild(new HorizontalSpacer());
            Button removeLink = linkButtonFactory.Generate("remove");

            removeLink.Click += (sender, e) => {
                RemoveSetting(settingData.SlicerConfigName);
            };
            removeLink.VAnchor = Agg.UI.VAnchor.ParentCenter;
            container.AddChild(removeLink);

            return(container);
        }
예제 #25
0
        private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth)
        {
            FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();
            if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
            {
                int intEditWidth = 60;
                int doubleEditWidth = 60;
                int vectorXYEditWidth = 60;
                int multiLineEditHeight = 60;

                string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
                leftToRightLayout.Margin = new BorderDouble(0, 5);
                leftToRightLayout.HAnchor |= Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
                {
                    string convertedNewLines = settingData.PresentationName.Replace("\\n ", "\n");
                    convertedNewLines = convertedNewLines.Replace("\\n", "\n");
					convertedNewLines = new LocalizedString (convertedNewLines).Translated;
                    TextWidget settingName = new TextWidget(convertedNewLines);
                    settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                    settingName.Width = minSettingNameWidth;
                    //settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                    leftToRightLayout.AddChild(settingName);
                }
                
                switch (settingData.DataEditType)
                {
                    case OrganizerSettingsData.DataEditTypes.INT:
                        {
                            int currentValue = 0;
                            int.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
                            intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                            leftToRightLayout.AddChild(intEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.DOUBLE:
                        {
                            double currentValue = 0;
                            double.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                            doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                            leftToRightLayout.AddChild(doubleEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.POSITVE_DOUBLE:
                        {
                            double currentValue = 0;
                            double.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                            doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                            leftToRightLayout.AddChild(doubleEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.OFFSET:
                        {
                            double currentValue = 0;
                            double.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                            doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                            leftToRightLayout.AddChild(doubleEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
                        {
                            MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 60, tabIndex: tabIndexForItem++);
                            stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                            {
                                TextEditWidget textEditWidget = (TextEditWidget)sender;
                                string text = textEditWidget.Text;
                                text = 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;
                                SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
                            };

                            leftToRightLayout.AddChild(stringEdit);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
                        {
                            CheckBox checkBoxWidget = new CheckBox("");
                            checkBoxWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
                            checkBoxWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                            checkBoxWidget.Checked = (sliceSettingValue == "1");
                            checkBoxWidget.CheckedStateChanged += (sender, e) =>
                            {
                                if (((CheckBox)sender).Checked)
                                {
                                    SaveSetting(settingData.SlicerConfigName, "1");
                                }
                                else
                                {
                                    SaveSetting(settingData.SlicerConfigName, "0");
                                }
                            };
                            leftToRightLayout.AddChild(checkBoxWidget);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.STRING:
                        {
                            MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
                            stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text); };
                            leftToRightLayout.AddChild(stringEdit);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
                        {
                            string convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
                            MHTextEditWidget stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
                            stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n")); };
                            leftToRightLayout.AddChild(stringEdit);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.LIST:
                        {
                            StyledDropDownList selectableOptions = new StyledDropDownList("None", Direction.Up);
                            selectableOptions.Margin = new BorderDouble();
                            
                            string[] listItems = settingData.ExtraSettings.Split(',');
                            foreach (string listItem in listItems)
                            {
                                MenuItem newItem = selectableOptions.AddItem(listItem);
                                if (newItem.Text == sliceSettingValue)
                                {
                                    selectableOptions.SelectedValue = sliceSettingValue;
                                }

                                newItem.Selected += (sender, e) =>
                                {
                                    MenuItem menuItem = ((MenuItem)sender);
                                    SaveSetting(settingData.SlicerConfigName, menuItem.Text);
                                };
                            }
                            leftToRightLayout.AddChild(selectableOptions);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.VECTOR2:
                        {
                            string[] xyValueStrings = sliceSettingValue.Split(',');
                            if (xyValueStrings.Length != 2)
                            {
                                xyValueStrings = new string[] { "0", "0" };
                            }
                                double currentXValue = 0;
                                double.TryParse(xyValueStrings[0], out currentXValue);
                                MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                                double currentYValue = 0;
                                double.TryParse(xyValueStrings[1], out currentYValue);
                                MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                            {
                                xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                                leftToRightLayout.AddChild(xEditWidget);
                                TextWidget xText = new TextWidget("x");
                                xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                                xText.Margin = new BorderDouble(5, 0);
                                leftToRightLayout.AddChild(xText);
                            }
                            {
                                yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                                leftToRightLayout.AddChild(yEditWidget);
                                TextWidget yText = new TextWidget("y");
                                yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                                yText.Margin = new BorderDouble(5, 0);
                                leftToRightLayout.AddChild(yText);
                            }
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.OFFSET2:
                        {
                            string[] xyValueStrings = sliceSettingValue.Split('x');
                            if (xyValueStrings.Length != 2)
                            {
                                xyValueStrings = new string[] { "0", "0" };
                            }
                            double currentXValue = 0;
                            double.TryParse(xyValueStrings[0], out currentXValue);
                            MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                            double currentYValue = 0;
                            double.TryParse(xyValueStrings[1], out currentYValue);
                            MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                            {
                                xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                                leftToRightLayout.AddChild(xEditWidget);
                                TextWidget xText = new TextWidget("x");
                                xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                                xText.Margin = new BorderDouble(5, 0);
                                leftToRightLayout.AddChild(xText);
                            }
                            {
                                yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                                leftToRightLayout.AddChild(yEditWidget);
                                TextWidget yText = new TextWidget("y");
                                yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                                yText.Margin = new BorderDouble(5, 0);
                                leftToRightLayout.AddChild(yText);
                            }
                        }
                        break;

                    default:
                        TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
                        missingSetting.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        missingSetting.BackgroundColor = RGBA_Bytes.Red;
                        leftToRightLayout.AddChild(missingSetting);
                        break;
                }
            }
            else // the setting we think we are adding is not in the config.ini it may have been depricated
            {
                TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
                settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                leftToRightLayout.AddChild(settingName);
                leftToRightLayout.BackgroundColor = RGBA_Bytes.Red;
            }

            return leftToRightLayout;
        }
        private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth)
        {
            GuiWidget container = new GuiWidget();
            FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();

            bool addQualityOverlay = false;
            bool addMaterialOverlay = false;

            RGBA_Bytes qualityOverlayColor = new RGBA_Bytes(255, 255, 0, 40);
            RGBA_Bytes materialOverlayColor = new RGBA_Bytes(255, 127, 0, 40);


            if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
            {
                int intEditWidth = 60;
                int doubleEditWidth = 60;
                int vectorXYEditWidth = 60;
                int multiLineEditHeight = 60;

                string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
                leftToRightLayout.Margin = new BorderDouble(0, 2);
                leftToRightLayout.Padding = new BorderDouble(3);
                leftToRightLayout.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

                if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
                {
                    string convertedNewLines = settingData.PresentationName.Replace("\\n ", "\n");
                    convertedNewLines = convertedNewLines.Replace("\\n", "\n");
                    convertedNewLines = LocalizedString.Get(convertedNewLines);
                    TextWidget settingName = new TextWidget(convertedNewLines);
                    settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;

                    if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, 3))
                    {
                        addMaterialOverlay = true;
                    }
                    else if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, 2))
                    {
                        addQualityOverlay = true;
                    }

                    settingName.Width = minSettingNameWidth;
                    //settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                    leftToRightLayout.AddChild(settingName);
                }

                switch (settingData.DataEditType)
                {
                    case OrganizerSettingsData.DataEditTypes.INT:
                        {
                            int currentValue = 0;
                            int.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
                            intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                            {
                                SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(intEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.DOUBLE:
                        {
                            double currentValue = 0;
                            double.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                            doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                            {
                                SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(doubleEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.POSITIVE_DOUBLE:
                        {
                            double currentValue = 0;
                            double.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                            doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                                {
                                    SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
                                    CallEventsOnSettingsChange(settingData);
                                };
                            leftToRightLayout.AddChild(doubleEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.OFFSET:
                        {
                            double currentValue = 0;
                            double.TryParse(sliceSettingValue, out currentValue);
                            MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                            doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                            {
                                SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(doubleEditWidget);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
                        {
                            MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 60, tabIndex: tabIndexForItem++);
                            stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                            {
                                TextEditWidget textEditWidget = (TextEditWidget)sender;
                                string text = textEditWidget.Text;
                                text = 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;
                                SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
                                CallEventsOnSettingsChange(settingData);
                            };

                            leftToRightLayout.AddChild(stringEdit);
                            leftToRightLayout.AddChild(getSettingInfoData(settingData));
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
                        {
                            CheckBox checkBoxWidget = new CheckBox("");
                            checkBoxWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
                            checkBoxWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                            checkBoxWidget.Checked = (sliceSettingValue == "1");
                            checkBoxWidget.CheckedStateChanged += (sender, e) =>
                            {
                                if (((CheckBox)sender).Checked)
                                {
                                    SaveSetting(settingData.SlicerConfigName, "1");
                                }
                                else
                                {
                                    SaveSetting(settingData.SlicerConfigName, "0");
                                }
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(checkBoxWidget);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.STRING:
                        {
                            MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
                            stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                            {
                                SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text);
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(stringEdit);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
                        {
                            string convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
                            MHTextEditWidget stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
                            stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                            {
                                SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"));
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(stringEdit);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.LIST:
                        {
                            StyledDropDownList selectableOptions = new StyledDropDownList("None", maxHeight: 200);
                            selectableOptions.Margin = new BorderDouble();

                            string[] listItems = settingData.ExtraSettings.Split(',');

                            foreach (string listItem in listItems)
                            {
                                MenuItem newItem = selectableOptions.AddItem(listItem);
                                if (newItem.Text == sliceSettingValue)
                                {
                                    selectableOptions.SelectedLabel = sliceSettingValue;
                                }

                                newItem.Selected += (sender, e) =>
                                {
                                    MenuItem menuItem = ((MenuItem)sender);
                                    SaveSetting(settingData.SlicerConfigName, menuItem.Text);
                                    CallEventsOnSettingsChange(settingData);
                                };
                            }
                            leftToRightLayout.AddChild(selectableOptions);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.HARDWARE_PRESENT:
                        {
                            CheckBox checkBoxWidget = new CheckBox("");
                            checkBoxWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
                            checkBoxWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                            checkBoxWidget.Checked = (sliceSettingValue == "1");
                            checkBoxWidget.CheckedStateChanged += (sender, e) =>
                            {
                                if (((CheckBox)sender).Checked)
                                {
                                    SaveSetting(settingData.SlicerConfigName, "1");
                                    // Now show all of the settings that this control is associated with.
                                }
                                else
                                {
                                    SaveSetting(settingData.SlicerConfigName, "0");
                                    // Now hide all of the settings that this control is associated with.
                                }
                                CallEventsOnSettingsChange(settingData);
                            };
                            leftToRightLayout.AddChild(checkBoxWidget);
                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.VECTOR2:
                        {
                            string[] xyValueStrings = sliceSettingValue.Split(',');
                            if (xyValueStrings.Length != 2)
                            {
                                xyValueStrings = new string[] { "0", "0" };
                            }
                            double currentXValue = 0;
                            double.TryParse(xyValueStrings[0], out currentXValue);
                            MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                            double currentYValue = 0;
                            double.TryParse(xyValueStrings[1], out currentYValue);
                            MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                            xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                            {
                                SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString());
                                CallEventsOnSettingsChange(settingData);
                            };

                            leftToRightLayout.AddChild(xEditWidget);
                            TextWidget xText = new TextWidget("x");
                            xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                            xText.Margin = new BorderDouble(5, 0);
                            leftToRightLayout.AddChild(xText);

                            yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                                {
                                    SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString());
                                    CallEventsOnSettingsChange(settingData);
                                };
                            leftToRightLayout.AddChild(yEditWidget);
                            TextWidget yText = new TextWidget("y");
                            yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                            yText.Margin = new BorderDouble(5, 0);
                            leftToRightLayout.AddChild(yText);

                        }
                        break;

                    case OrganizerSettingsData.DataEditTypes.OFFSET2:
                        {
                            string[] xyValueStrings = sliceSettingValue.Split('x');
                            if (xyValueStrings.Length != 2)
                            {
                                xyValueStrings = new string[] { "0", "0" };
                            }
                            double currentXValue = 0;
                            double.TryParse(xyValueStrings[0], out currentXValue);
                            MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                            double currentYValue = 0;
                            double.TryParse(xyValueStrings[1], out currentYValue);
                            MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                            {
                                xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                                {
                                    SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString());
                                    CallEventsOnSettingsChange(settingData);
                                };
                                leftToRightLayout.AddChild(xEditWidget);
                                TextWidget xText = new TextWidget("x");
                                xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                                xText.Margin = new BorderDouble(5, 0);
                                leftToRightLayout.AddChild(xText);
                            }
                            {
                                yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
                                {
                                    SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString());
                                    CallEventsOnSettingsChange(settingData);
                                };
                                leftToRightLayout.AddChild(yEditWidget);
                                TextWidget yText = new TextWidget("y");
                                yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                                yText.Margin = new BorderDouble(5, 0);
                                leftToRightLayout.AddChild(yText);
                            }
                        }
                        break;

                    default:
                        TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
                        missingSetting.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        missingSetting.BackgroundColor = RGBA_Bytes.Red;
                        leftToRightLayout.AddChild(missingSetting);
                        break;
                }
            }
            else // the setting we think we are adding is not in the config.ini it may have been depricated
            {
                TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
                settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                leftToRightLayout.AddChild(settingName);
                leftToRightLayout.BackgroundColor = RGBA_Bytes.Red;
            }

            container.HAnchor = HAnchor.ParentLeftRight;
            container.VAnchor = VAnchor.FitToChildren;

            container.AddChild(leftToRightLayout);

            if (addQualityOverlay || addMaterialOverlay)
            {
                SettingPresetOverlay overlay = new SettingPresetOverlay();
                overlay.HAnchor = HAnchor.ParentLeftRight;
                overlay.VAnchor = Agg.UI.VAnchor.ParentBottomTop;

                SettingPresetClick clickToEdit = new SettingPresetClick();
                clickToEdit.HAnchor = HAnchor.ParentLeftRight;
                clickToEdit.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
                clickToEdit.Visible = false;

                Button editButton = buttonFactory.Generate("Edit Preset".Localize().ToUpper());
                editButton.HAnchor = Agg.UI.HAnchor.ParentCenter;
                editButton.VAnchor = Agg.UI.VAnchor.ParentCenter;

                clickToEdit.AddChild(editButton);

                if (addQualityOverlay)
                {
                    overlay.OverlayColor = qualityOverlayColor;
                    clickToEdit.OverlayColor = qualityOverlayColor;
                    editButton.Click += (sender, e) =>
                    {
                        if (ApplicationWidget.Instance.EditQualityPresetsWindow == null)
                        {
                            ApplicationWidget.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(ReloadOptions, "Quality", "quality", false, ActivePrinterProfile.Instance.ActiveQualitySettingsID);
                            ApplicationWidget.Instance.EditQualityPresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationWidget.Instance.EditQualityPresetsWindow = null; };
                        }
                        else
                        {
                            ApplicationWidget.Instance.EditQualityPresetsWindow.ChangeToSlicePresetFromID(ActivePrinterProfile.Instance.ActiveQualitySettingsID);
                            ApplicationWidget.Instance.EditQualityPresetsWindow.BringToFront();
                        }
                    };
                }
                else if (addMaterialOverlay)
                {
                    overlay.OverlayColor = materialOverlayColor;
                    clickToEdit.OverlayColor = materialOverlayColor;
                    editButton.Click += (sender, e) =>
                    {
                        if (ApplicationWidget.Instance.EditMaterialPresetsWindow == null)
                        {
                            ApplicationWidget.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(ReloadOptions, "Material", "material", false, ActivePrinterProfile.Instance.GetMaterialSetting(1));
                            ApplicationWidget.Instance.EditMaterialPresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationWidget.Instance.EditMaterialPresetsWindow = null; };
                        }
                        else
                        {
                            ApplicationWidget.Instance.EditMaterialPresetsWindow.ChangeToSlicePresetFromID(ActivePrinterProfile.Instance.GetMaterialSetting(1));
                            ApplicationWidget.Instance.EditMaterialPresetsWindow.BringToFront();
                        }
                    };
                }

                container.MouseEnterBounds += (sender, e) =>
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        overlay.Visible = false;
                        clickToEdit.Visible = true;
                    });
                };

                container.MouseLeaveBounds += (sender, e) =>
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        overlay.Visible = true;
                        clickToEdit.Visible = false;
                    });
                };

                container.AddChild(overlay);
                container.AddChild(clickToEdit);
            }



            return container;
        }
		private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth, int extruderIndex)
		{
			GuiWidget container = new GuiWidget();
			FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();

			bool addQualityOverlay = false;
			bool addMaterialOverlay = false;

			RGBA_Bytes qualityOverlayColor = new RGBA_Bytes(255, 255, 0, 40);
			RGBA_Bytes materialOverlayColor = new RGBA_Bytes(255, 127, 0, 40);

			if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
			{
				int intEditWidth = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);
				int doubleEditWidth = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);
				if (settingData.QuickMenuSettings.Count > 0)
				{
					doubleEditWidth = (int)(35 * TextWidget.GlobalPointSizeScaleRatio + .5);
				}
				int vectorXYEditWidth = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);
				int multiLineEditHeight = (int)(60 * TextWidget.GlobalPointSizeScaleRatio + .5);

				string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
				leftToRightLayout.Margin = new BorderDouble(0, 2);
				leftToRightLayout.Padding = new BorderDouble(3);
				leftToRightLayout.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

				if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
				{
					string convertedNewLines = settingData.PresentationName.Replace("\\n ", "\n");
					convertedNewLines = convertedNewLines.Replace("\\n", "\n");
					convertedNewLines = LocalizedString.Get(convertedNewLines);
					TextWidget settingName = new TextWidget(convertedNewLines, pointSize: 10);
					settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
					settingName.VAnchor = Agg.UI.VAnchor.ParentCenter;

#if DO_IN_PLACE_EDIT
                    if (SettingsIndexBeingEdited != 0)
                    {
                        if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, SettingsIndexBeingEdited))
                        {
                            CheckBox removeFromSettingCheckBox = new CheckBox("");
                            removeFromSettingCheckBox.Checked = true;
                            removeFromSettingCheckBox.VAnchor = VAnchor.ParentCenter;
                            leftToRightLayout.AddChild(removeFromSettingCheckBox);
                        }
                        else
                        {
                            CheckBox addToSettingCheckBox = new CheckBox("");
                            addToSettingCheckBox.VAnchor = VAnchor.ParentCenter;
                            leftToRightLayout.AddChild(addToSettingCheckBox);
                        }
                    }
#endif
					settingName.Width = minSettingNameWidth;
					//settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
					leftToRightLayout.AddChild(settingName);
				}

				if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, 3))
				{
					addMaterialOverlay = true;
				}
				else if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, 2))
				{
					addQualityOverlay = true;
				}

				switch (settingData.DataEditType)
				{
					case OrganizerSettingsData.DataEditTypes.INT:
						{
							int currentValue = 0;
							int.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
							intEditWidget.ToolTipText = settingData.HelpText;
							intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
								CallEventsOnSettingsChange(settingData);
							};
							intEditWidget.SelectAllOnFocus = true;

							leftToRightLayout.AddChild(intEditWidget);
							leftToRightLayout.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.DOUBLE:
						{
							double currentValue = 0;
							double.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
							doubleEditWidget.ToolTipText = settingData.HelpText;
							doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
								CallEventsOnSettingsChange(settingData);
							};
							doubleEditWidget.SelectAllOnFocus = true;
							leftToRightLayout.AddChild(doubleEditWidget);
							leftToRightLayout.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.POSITIVE_DOUBLE:
						{
							const string multiValuesAreDiffernt = "-";
							FlowLayoutWidget content = new FlowLayoutWidget();

							MHNumberEdit doubleEditWidget = new MHNumberEdit(0, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
							doubleEditWidget.ToolTipText = settingData.HelpText;

							double currentValue = 0;
							bool ChangesMultipleOtherSettings = settingData.SetSettingsOnChange.Count > 0;
							if (ChangesMultipleOtherSettings)
							{
								bool allTheSame = true;
								string setting = ActiveSliceSettings.Instance.GetActiveValue(settingData.SetSettingsOnChange[0]);								
								for (int i = 1; i < settingData.SetSettingsOnChange.Count; i++)
								{
									string nextSetting = ActiveSliceSettings.Instance.GetActiveValue(settingData.SetSettingsOnChange[i]);
									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 nomrmaly
							{
								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)
									{
										SaveSetting(setting, numberEdit.Value.ToString() + "mm");
									}
								}

								// also always save to the local setting
								SaveSetting(settingData.SlicerConfigName, numberEdit.Value.ToString());
								CallEventsOnSettingsChange(settingData);
							};
							doubleEditWidget.SelectAllOnFocus = true;

							content.AddChild(doubleEditWidget);
							content.AddChild(getSettingInfoData(settingData));

							if (settingData.QuickMenuSettings.Count > 0)
							{
								leftToRightLayout.AddChild(CreateQuickMenu(settingData, content, doubleEditWidget.ActuallNumberEdit.InternalTextEditWidget));
							}
							else
							{
								leftToRightLayout.AddChild(content);
							}
						}
						break;

					case OrganizerSettingsData.DataEditTypes.OFFSET:
						{
							double currentValue = 0;
							double.TryParse(sliceSettingValue, out currentValue);
							MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
							doubleEditWidget.ToolTipText = settingData.HelpText;
							doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
								CallEventsOnSettingsChange(settingData);
							};
							doubleEditWidget.SelectAllOnFocus = true;
							leftToRightLayout.AddChild(doubleEditWidget);
							leftToRightLayout.AddChild(getSettingInfoData(settingData));
						}
						break;

					case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
						{
							FlowLayoutWidget content = new FlowLayoutWidget();

							MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: doubleEditWidth - 2, tabIndex: tabIndexForItem++);
							stringEdit.ToolTipText = settingData.HelpText;
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								TextEditWidget textEditWidget = (TextEditWidget)sender;
								string text = textEditWidget.Text;
								text = 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;
								SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
								CallEventsOnSettingsChange(settingData);
							};
							stringEdit.SelectAllOnFocus = true;

							stringEdit.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) =>
							{
								// select evrything 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);
							content.AddChild(getSettingInfoData(settingData));

							if (settingData.QuickMenuSettings.Count > 0)
							{
								leftToRightLayout.AddChild(CreateQuickMenu(settingData, content, stringEdit.ActualTextEditWidget.InternalTextEditWidget));
							}
							else
							{
								leftToRightLayout.AddChild(content);
							}
						}
						break;

					case OrganizerSettingsData.DataEditTypes.INT_OR_MM:
						{
							FlowLayoutWidget content = new FlowLayoutWidget();

							MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: doubleEditWidth - 2, tabIndex: tabIndexForItem++);
							stringEdit.ToolTipText = settingData.HelpText;
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								TextEditWidget textEditWidget = (TextEditWidget)sender;
								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;
								SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
								CallEventsOnSettingsChange(settingData);
							};
							stringEdit.SelectAllOnFocus = true;

							stringEdit.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) =>
							{
								// select evrything 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);
							content.AddChild(getSettingInfoData(settingData));

							if (settingData.QuickMenuSettings.Count > 0)
							{
								leftToRightLayout.AddChild(CreateQuickMenu(settingData, content, stringEdit.ActualTextEditWidget.InternalTextEditWidget));
							}
							else
							{
								leftToRightLayout.AddChild(content);
							}
						}
						break;

					case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
						{
							CheckBox checkBoxWidget = new CheckBox("");
							checkBoxWidget.ToolTipText = settingData.HelpText;
							checkBoxWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
							checkBoxWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
							checkBoxWidget.Checked = (sliceSettingValue == "1");
							checkBoxWidget.CheckedStateChanged += (sender, e) =>
							{
								if (((CheckBox)sender).Checked)
								{
									SaveSetting(settingData.SlicerConfigName, "1");
								}
								else
								{
									SaveSetting(settingData.SlicerConfigName, "0");
								}
								CallEventsOnSettingsChange(settingData);
							};
							leftToRightLayout.AddChild(checkBoxWidget);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.STRING:
						{
							MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
							stringEdit.ToolTipText = settingData.HelpText;
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text);
								CallEventsOnSettingsChange(settingData);
							};
							leftToRightLayout.AddChild(stringEdit);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
						{
							string convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
							MHTextEditWidget stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
							stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"));
								CallEventsOnSettingsChange(settingData);
							};
							leftToRightLayout.AddChild(stringEdit);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.LIST:
						{
							StyledDropDownList selectableOptions = new StyledDropDownList("None", maxHeight: 200);
							selectableOptions.ToolTipText = settingData.HelpText;
							selectableOptions.Margin = new BorderDouble();

							string[] listItems = settingData.ExtraSettings.Split(',');

							foreach (string listItem in listItems)
							{
								MenuItem newItem = selectableOptions.AddItem(listItem);
								if (newItem.Text == sliceSettingValue)
								{
									selectableOptions.SelectedLabel = sliceSettingValue;
								}

								newItem.Selected += (sender, e) =>
								{
									MenuItem menuItem = ((MenuItem)sender);
									SaveSetting(settingData.SlicerConfigName, menuItem.Text);
									CallEventsOnSettingsChange(settingData);
								};
							}
							leftToRightLayout.AddChild(selectableOptions);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.HARDWARE_PRESENT:
						{
							CheckBox checkBoxWidget = new CheckBox("");
							checkBoxWidget.ToolTipText = settingData.HelpText;
							checkBoxWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
							checkBoxWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
							checkBoxWidget.Checked = (sliceSettingValue == "1");
							checkBoxWidget.CheckedStateChanged += (sender, e) =>
							{
								if (((CheckBox)sender).Checked)
								{
									SaveSetting(settingData.SlicerConfigName, "1");
									// Now show all of the settings that this control is associated with.
								}
								else
								{
									SaveSetting(settingData.SlicerConfigName, "0");
									// Now hide all of the settings that this control is associated with.
								}
								CallEventsOnSettingsChange(settingData);
							};
							leftToRightLayout.AddChild(checkBoxWidget);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.VECTOR2:
						{
							string[] xyValueStrings = sliceSettingValue.Split(',');
							if (xyValueStrings.Length != 2)
							{
								xyValueStrings = new string[] { "0", "0" };
							}
							double currentXValue = 0;
							double.TryParse(xyValueStrings[0], out currentXValue);
							MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
							xEditWidget.ToolTipText = settingData.HelpText;

							double currentYValue = 0;
							double.TryParse(xyValueStrings[1], out currentYValue);
							MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
							yEditWidget.ToolTipText = settingData.HelpText;

							xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString());
								CallEventsOnSettingsChange(settingData);
							};
							xEditWidget.SelectAllOnFocus = true;

							leftToRightLayout.AddChild(xEditWidget);
							leftToRightLayout.AddChild(new HorizontalSpacer());

							yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
							{
								SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString());
								CallEventsOnSettingsChange(settingData);
							};
							yEditWidget.SelectAllOnFocus = true;
							leftToRightLayout.AddChild(yEditWidget);
						}
						break;

					case OrganizerSettingsData.DataEditTypes.OFFSET2:
						{
							Vector2 offset = ActiveSliceSettings.Instance.GetOffset(extruderIndex);
							MHNumberEdit xEditWidget = new MHNumberEdit(offset.x, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
							xEditWidget.ToolTipText = settingData.HelpText;
							MHNumberEdit yEditWidget = new MHNumberEdit(offset.y, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
							yEditWidget.ToolTipText = settingData.HelpText;
							{
								xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
								{
									int extruderIndexLocal = extruderIndex;
									SaveCommaSeparatedIndexSetting(extruderIndexLocal, settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString());
									CallEventsOnSettingsChange(settingData);
								};
								xEditWidget.SelectAllOnFocus = true;
								leftToRightLayout.AddChild(xEditWidget);
								leftToRightLayout.AddChild(new HorizontalSpacer());
							}
							{
								yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
								{
									int extruderIndexLocal = extruderIndex;
									SaveCommaSeparatedIndexSetting(extruderIndexLocal, settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString());
									CallEventsOnSettingsChange(settingData);
								};
								yEditWidget.SelectAllOnFocus = true;
								leftToRightLayout.AddChild(yEditWidget);
							}
						}
						break;

					default:
						TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
						missingSetting.TextColor = ActiveTheme.Instance.PrimaryTextColor;
						missingSetting.BackgroundColor = RGBA_Bytes.Red;
						leftToRightLayout.AddChild(missingSetting);
						break;
				}
			}
			else // the setting we think we are adding is not in the config.ini it may have been depricated
			{
				TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
				settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
				leftToRightLayout.AddChild(settingName);
				leftToRightLayout.BackgroundColor = RGBA_Bytes.Red;
			}

			container.HAnchor = HAnchor.ParentLeftRight;
			container.VAnchor = VAnchor.FitToChildren;

			container.AddChild(leftToRightLayout);

			if (addQualityOverlay || addMaterialOverlay)
			{
				SettingPresetOverlay overlay = new SettingPresetOverlay();
				overlay.HAnchor = HAnchor.ParentLeftRight;
				overlay.VAnchor = Agg.UI.VAnchor.ParentBottomTop;

				SettingPresetClick clickToEdit = new SettingPresetClick();
				clickToEdit.HAnchor = HAnchor.ParentLeftRight;
				clickToEdit.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
				clickToEdit.Visible = false;

				Button editButton = buttonFactory.Generate("Edit Preset".Localize().ToUpper());
				editButton.HAnchor = Agg.UI.HAnchor.ParentCenter;
				editButton.VAnchor = Agg.UI.VAnchor.ParentCenter;

				clickToEdit.AddChild(editButton);

				if (addQualityOverlay)
				{
					overlay.OverlayColor = qualityOverlayColor;
					clickToEdit.OverlayColor = qualityOverlayColor;
					editButton.Click += (sender, e) =>
					{
						if (ApplicationController.Instance.EditQualityPresetsWindow == null)
						{
							ApplicationController.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(ReloadOptions, "Quality", "quality", false, ActivePrinterProfile.Instance.ActiveQualitySettingsID);
							ApplicationController.Instance.EditQualityPresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationController.Instance.EditQualityPresetsWindow = null; };
						}
						else
						{
							ApplicationController.Instance.EditQualityPresetsWindow.ChangeToSlicePresetFromID(ActivePrinterProfile.Instance.ActiveQualitySettingsID);
							ApplicationController.Instance.EditQualityPresetsWindow.BringToFront();
						}
					};
				}
				else if (addMaterialOverlay)
				{
					overlay.OverlayColor = materialOverlayColor;
					clickToEdit.OverlayColor = materialOverlayColor;
					editButton.Click += (sender, e) =>
					{
						if (ApplicationController.Instance.EditMaterialPresetsWindow == null)
						{
							ApplicationController.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(ReloadOptions, "Material", "material", false, ActivePrinterProfile.Instance.GetMaterialSetting(1));
							ApplicationController.Instance.EditMaterialPresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationController.Instance.EditMaterialPresetsWindow = null; };
						}
						else
						{
							ApplicationController.Instance.EditMaterialPresetsWindow.ChangeToSlicePresetFromID(ActivePrinterProfile.Instance.GetMaterialSetting(1));
							ApplicationController.Instance.EditMaterialPresetsWindow.BringToFront();
						}
					};
				}

				container.MouseEnterBounds += (sender, e) =>
				{
					UiThread.RunOnIdle(() =>
					{
						overlay.Visible = false;
						clickToEdit.Visible = true;
					});
				};

				container.MouseLeaveBounds += (sender, e) =>
				{
					UiThread.RunOnIdle(() =>
					{
						overlay.Visible = true;
						clickToEdit.Visible = false;
					});
				};

				container.AddChild(overlay);
				container.AddChild(clickToEdit);
			}

			return container;
		}
		private void OnSettingSelected(object sender, EventArgs e)
		{
			MenuItem item = (MenuItem)sender;
			string[] valueArray = item.Value.Split(':');
			string configName = valueArray[2];
			addRowSettingData = SliceSettingsOrganizer.Instance.GetSettingsData(configName);

			AddSettingToPreset();
		}
		private TabControl CreateExtraSettingsSideTabsAndPages(int minSettingNameWidth, TabControl categoryTabs, out int count)
		{
			count = 0;
			TabControl sideTabs = new TabControl(Orientation.Vertical);
			sideTabs.Margin = new BorderDouble(0, 0, 0, 5);
			sideTabs.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());
				sideTabs.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;

				foreach (KeyValuePair<string, DataStorage.SliceSetting> item in ActiveSliceSettings.Instance.DefaultSettings)
				{
					if (!SliceSettingsOrganizer.Instance.Contains(UserLevel, item.Key))
					{
						OrganizerSettingsData settingInfo = new OrganizerSettingsData(item.Key, item.Key, OrganizerSettingsData.DataEditTypes.STRING);
						GuiWidget controlsForThisSetting = CreateSettingInfoUIControls(settingInfo, minSettingNameWidth, 0);
						topToBottomSettings.AddChild(controlsForThisSetting);
						count++;
					}
				}

				AltGroupBox groupBox = new AltGroupBox(LocalizedString.Get("Extra"));
				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 sideTabs;
		}
예제 #30
0
		private void OnSettingsChanged(OrganizerSettingsData settingData)
		{
			SettingChanged.CallEvents(this, new StringEventArgs(settingData.SlicerConfigName));

			if (settingToReloadUiWhenChanged.Contains(settingData.SlicerConfigName))
			{
				ApplicationController.Instance.ReloadAll(null, null);
			}
		}
		private void CallEventsOnSettingsChange(OrganizerSettingsData settingData)
		{
			foreach (KeyValuePair<string, RootedObjectEventHandler> keyValue in functionsToCallOnChange)
			{
				if (keyValue.Key == settingData.SlicerConfigName)
				{
					keyValue.Value.CallEvents(null, null);
				}
			}

			if (settingToReloadUiWhenChanged.Contains(settingData.SlicerConfigName))
			{
				ApplicationController.Instance.ReloadAll(null, null);
			}
		}
        private void CallEventsOnSettingsChange(OrganizerSettingsData settingData)
        {
            if (settingToReloadUiWhenChanged.Contains(settingData.SlicerConfigName))
            {
                ApplicationWidget.Instance.ReloadAll(null, null);
            }

            if (settingsRequiringPreviewUpdate.Contains(settingData.SlicerConfigName))
            {
                PartPreviewSettingsChanged.CallEvents(this, null);
            }
        }