示例#1
0
        /// <summary>
        /// Overrides the current value to display the ValuesDifferToken if they are not all equal
        /// </summary>
        /// <param name="currentValue"></param>
        /// <returns>The current value cast to double or the ValuesDifferToken (-)</returns>
        private string FilterValue(string currentValue)
        {
            string text = currentValue.Trim();

            if (ChangesMultipleOtherSettings)
            {
                bool   allTheSame = true;
                string setting    = settingsContext.GetValue(settingData.SetSettingsOnChange[0]["TargetSetting"]);
                for (int i = 1; i < settingData.SetSettingsOnChange.Count; i++)
                {
                    string nextSetting = settingsContext.GetValue(settingData.SetSettingsOnChange[i]["TargetSetting"]);
                    if (setting != nextSetting)
                    {
                        allTheSame = false;
                        break;
                    }
                }

                if (allTheSame && setting.EndsWith("mm"))
                {
                    double.TryParse(setting.Substring(0, setting.Length - 2), out double castValue);
                    return(castValue.ToString());
                }
                else
                {
                    return(ValuesDifferToken);
                }
            }
            else             // just set the setting normally
            {
                double.TryParse(this.Value, out double castValue);
                return(castValue.ToString());
            }
        }
        public override void Initialize(int tabIndex)
        {
            childFields = new List <Vector2Field>();

            var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Margin  = new BorderDouble(20, 0, 0, 0),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            this.Content = column;

            int.TryParse(settingsContext.GetValue(SettingsKey.extruder_count), out int extruderCount);

            // If extruders_share_temperature is enabled, override the extruder count
            if (settingsContext.GetValue(SettingsKey.extruders_share_temperature) == "1")
            {
                extruderCount = 1;
            }

            for (int i = 0; i < extruderCount; i++)
            {
                var row = new FlowLayoutWidget()
                {
                    HAnchor     = HAnchor.Fit | HAnchor.Right,
                    VAnchor     = VAnchor.Fit,
                    MinimumSize = new Vector2(0, 28)
                };
                column.AddChild(row);

                var labelWidget = SettingsRow.CreateSettingsLabel($"Nozzle {i + 1}", "", textColor);
                labelWidget.Name   = $"Nozzle {i}";
                labelWidget.Margin = new BorderDouble(right: 60);
                row.AddChild(labelWidget);

                var field = new Vector2Field();
                field.Initialize(tabIndex++);
                field.Content.Margin  = new BorderDouble(right: 55);
                field.Content.VAnchor = VAnchor.Center;
                field.ValueChanged   += (s, e) =>
                {
                    if (e.UserInitiated)
                    {
                        // Stuff multiple CSV values into single text field
                        this.SetValue(
                            string.Join(",", this.childFields.Select(f => f.Value.Replace(",", "x")).ToArray()),
                            true);
                    }
                };
                row.AddChild(field.Content);

                childFields.Add(field);
            }

            base.Initialize(tabIndex);
        }