public DynamicReconfigureStringBox(DynamicReconfigureInterface dynamic, ParamDescription pd, string def)
 {
     this.def     = def;
     name         = pd.name.data;
     this.dynamic = dynamic;
     InitializeComponent();
     description.Content = name + ":";
     JustTheTip.Content  = pd.description.data;
     dynamic.Subscribe(name, changed);
     ignore = false;
 }
Esempio n. 2
0
        //Methods
        //parameter format: x0.3,x0.2,x0.6,x10 || x0.3 x0.1 x0.5 || ...
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int valueInt)
            {
                string paramStr = parameter.ToString();
                var    descr    = new ParamDescription(paramStr);
                return(descr.ToThickness(valueInt));
            }

            return(DependencyProperty.UnsetValue);
        }
Esempio n. 3
0
 public DynamicReconfigureCheckbox(DynamicReconfigureInterface dynamic, ParamDescription pd, bool def)
 {
     this.def     = def;
     name         = pd.name;
     this.dynamic = dynamic;
     InitializeComponent();
     description.Content = name + ":";
     JustTheTip.Content  = pd.description;
     _checkBox.IsChecked = def;
     dynamic.Subscribe(name, changed);
     ignore = false;
 }
 public DynamicReconfigureStringBox(DynamicReconfigureInterface dynamic, ParamDescription pd, string def)
 {
     this.def = def;
     name = pd.name;
     this.dynamic = dynamic;
     InitializeComponent();
     description.Text = name + ":";
     JustTheTip.Content = pd.description;
     dynamic.Subscribe(name, changed);
     ignore = false;
     text = Box.Text;
 }
 public DynamicReconfigureCheckbox(DynamicReconfigureInterface dynamic, ParamDescription pd, bool def)
 {
     this.def = def;
     name = pd.name;
     this.dynamic = dynamic;
     InitializeComponent();
     description.Content = name + ":";
     JustTheTip.Content = pd.description;
     _checkBox.IsChecked = def;
     dynamic.Subscribe(name, changed);
     ignore = false;
 }
        public DynamicReconfigureSlider(DynamicReconfigureInterface dynamic, ParamDescription pd, double def, double max, double min, bool isDouble)
        {
            name          = pd.name;
            this.dynamic  = dynamic;
            this.isDouble = isDouble;
            InitializeComponent();
            this.min = min;
            if (double.IsInfinity(this.min))
            {
                value.Minimum = -1000.0;
            }
            else
            {
                value.Minimum = min;
            }
            this.max = max;
            if (double.IsInfinity(this.max))
            {
                value.Maximum = 1000.0;
            }
            else
            {
                value.Maximum = max;
            }
            description.Text   = name + ":";
            JustTheTip.Content = pd.description;

            double range = value.Maximum - value.Minimum;

            minlabel.Content = Format(value.Minimum);
            maxlabel.Content = Format(value.Maximum);
            value.Value      = this.def = def;
            if (isDouble)
            {
                textBehavior.RegularExpression = @"^[\-\.0-9]+$";
                value.IsSnapToTickEnabled      = false;
                value.TickFrequency            = range / 10.0;
                value.LargeChange = range / 10.0;
                value.SmallChange = range / 100.0;
                dynamic.Subscribe(name, new Action <double>(changed));
                ignore = false;
            }
            else
            {
                textBehavior.RegularExpression = @"^[\-0-9][0-9]*$";
                value.IsSnapToTickEnabled      = true;
                value.TickFrequency            = Math.Max(1, (int)Math.Floor(range / 10.0));
                value.LargeChange = Math.Max(1, (int)Math.Floor(range / 10.0));
                value.SmallChange = 1;
                dynamic.Subscribe(name, new Action <int>(changed));
                ignore = false;
            }
        }
Esempio n. 7
0
        public DynamicReconfigureSlider(DynamicReconfigureInterface dynamic, ParamDescription pd, double def, double max, double min, bool isDouble)
        {
            name          = pd.name.data;
            this.dynamic  = dynamic;
            this.isDouble = isDouble;
            InitializeComponent();
            this.min = min;
            if (double.IsInfinity(this.min))
            {
                value.Minimum = -1000.0;
            }
            else
            {
                value.Minimum = min;
            }
            this.max = max;
            if (double.IsInfinity(this.max))
            {
                value.Maximum = 1000.0;
            }
            else
            {
                value.Maximum = max;
            }
            description.Text   = name + ":";
            JustTheTip.Content = pd.description.data;

            if (isDouble)
            {
                textBehavior.RegularExpression = @"^[\-\.0-9]+$";
                value.IsSnapToTickEnabled      = false;
                value.TickFrequency            = 0;
                minlabel.Content = string.Format("{0:N2}", value.Minimum);
                maxlabel.Content = string.Format("{0:N2}", value.Maximum);
                value.Value      = this.def = def;
                dynamic.Subscribe(name, new Action <double>(changed));
                ignore = false;
            }
            else
            {
                textBehavior.RegularExpression = @"^[\-0-9][0-9]*$";
                value.TickFrequency            = 1;
                value.IsSnapToTickEnabled      = true;
                minlabel.Content = "" + (int)value.Minimum;
                maxlabel.Content = "" + (int)value.Maximum;
                value.Value      = this.def = def;
                dynamic.Subscribe(name, new Action <int>(changed));
                ignore = false;
            }
        }
Esempio n. 8
0
        void InitParamDictionary()
        {
            parDesc = new Dictionary <int, ParamDescription>();
            foreach (string line in Resources.GrblParamDescription.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] vars = line.Split('|');
                if (line[0] == '#' || vars.Length < 4)
                {
                    continue;
                }
                try {
                    int code            = int.Parse(vars[0]);
                    ParamDescription pd = new ParamDescription();
                    pd.code        = code;
                    pd.description = vars[1];
                    pd.uints       = vars[2];
                    if (!Enum.TryParse <ParamType>(vars[3], out pd.type))
                    {
                        pd.type = ParamType.String;
                    }
                    if (vars.Length > 4)
                    {
                        pd.groups = vars[4].Split(',');
                    }
                    else
                    {
                        pd.groups = new string [] { "General" }
                    };
                    if (vars.Length > 5)
                    {
                        pd.options = vars[5].Split(',');
                    }
                    else
                    {
                        pd.options = null;
                    }

                    parDesc[code] = pd;
                }
                catch { }
            }
        }
        public DynamicReconfigureStringDropdown(DynamicReconfigureInterface dynamic, ParamDescription pd, object def, object max, object min, string edit_method)
        {
            this.def = def;
            this.max = max;
            this.min = min;
            this.edit_method = edit_method.Replace("'enum'", "'Enum'");
            Dictionary<string, string> parsed = EnumParser.Parse(this.edit_method);
            string[] vals = parsed["Enum"].Split(new[] {'}'}, StringSplitOptions.RemoveEmptyEntries);
            List<Dictionary<string, string>> descs = vals.Select(s => EnumParser.SubParse(s + "}")).ToList();
            descs = descs.Except(descs.Where(d => d.Count == 0)).ToList();
            enumdescription = new EnumDescription();
            enumdescription.Enum = new EnumValue[descs.Count];
            enumdescription.enum_description = parsed["enum_description"];
            Type tdesc = typeof (EnumValue);

            for (int i = 0; i < descs.Count; i++)
            {
                Dictionary<string, string> desc = descs[i];
                EnumValue newval = new EnumValue();
                foreach (string s in desc.Keys)
                {
                    FieldInfo fi = tdesc.GetField(s);
                    if (fi.FieldType == typeof (int))
                        fi.SetValue(newval, int.Parse(desc[s]));
                    else
                        fi.SetValue(newval, desc[s]);
                }
                enumdescription.Enum[i] = newval;
            }
            name = pd.name.data;
            this.dynamic = dynamic;
            InitializeComponent();
            for (int i = 0; i < enumdescription.Enum.Length; i++)
            {
                if (!types.ContainsKey(enumdescription.Enum[i].type))
                {
                    throw new Exception("HANDLE " + enumdescription.Enum[i].type);
                }
                switch (types[enumdescription.Enum[i].type])
                {
                    case DROPDOWN_TYPE.INT:
                    {
                        ComboBoxItem cbi = new ComboBoxItem {Tag = int.Parse(enumdescription.Enum[i].value), Content = enumdescription.Enum[i].name, ToolTip = new ToolTip {Content = enumdescription.Enum[i].description + " (" + enumdescription.Enum[i].value + ")"}};
                        @enum.Items.Add(cbi);
                        if (i == 0)
                        {
                            @enum.SelectedValue = this.def;
                            dynamic.Subscribe(name, (Action<int>) changed);
                        }
                        else if (enumdescription.Enum[i].type != enumdescription.Enum[i - 1].type)
                            throw new Exception("NO CHANGSIES MINDSIES");
                    }
                        break;
                    case DROPDOWN_TYPE.STR:
                    {
                        ComboBoxItem cbi = new ComboBoxItem {Tag = enumdescription.Enum[i].value, Content = enumdescription.Enum[i].name, ToolTip = new ToolTip {Content = enumdescription.Enum[i].description}};
                        @enum.Items.Add(cbi);
                        if (i == 0)
                        {
                            @enum.SelectedValue = this.def;
                            dynamic.Subscribe(name, (Action<string>) changed);
                        }
                        else if (enumdescription.Enum[i].type != enumdescription.Enum[i - 1].type)
                            throw new Exception("NO CHANGSIES MINDSIES");
                    }
                        break;
                }
            }
            description.Content = name + ":";
            JustTheTip.Content = pd.description.data;
            ignore = false;
        }
Esempio n. 10
0
        public void ParseParam(string stparam)
        {
            string[] vars = stparam.Split(new char[] { '$', '=' }, StringSplitOptions.RemoveEmptyEntries);
            if (vars.Length != 2)
            {
                return;
            }
            int parcode;

            try
            {
                parcode = int.Parse(vars[0]);
            }
            catch
            {
                return;
            }
            // see if we already have this param
            GrblParam par = GetParam(parcode);

            if (par == null)
            {
                par = new GrblParam(parcode, vars[1]);
                parameters.Add(par);
                parameters.Sort();
            }
            else
            {
                par.strVal = vars[1];
            }

            // see if we know this val
            if (parDesc.ContainsKey(parcode))
            {
                ParamDescription pd = parDesc[parcode];
                par.type = pd.type;
                switch (pd.type)
                {
                case ParamType.Float:
                    try { par.floatVal = Utils.ParseFloatInvariant(par.strVal); }
                    catch { }
                    break;

                case ParamType.Int:
                case ParamType.Mask:
                case ParamType.Boolean:
                    try { par.intVal = int.Parse(par.strVal); }
                    catch { }
                    break;
                }

                /*switch (pd.uints)
                 * {
                 *  case "mm":
                 *  case "mm/min":
                 *  case "RPM":
                 *  case "steps/mm":
                 *  case "steps/deg":
                 *  case "mm/deg":
                 *  case "mm/sec^2":
                 *  case "deg/sec^2":
                 *  case "percent":
                 *      par.type = ParamType.Float;
                 *      try { par.floatVal = Utils.ParseFloatInvariant(par.strVal); }
                 *      catch { }
                 *      break;
                 *  case "us":
                 *  case "ms":
                 *  case "int":
                 *      par.type = ParamType.Int;
                 *      try { par.intVal = int.Parse(par.strVal); }
                 *      catch { }
                 *      break;
                 *  case "mask":
                 *      par.type = ParamType.Mask;
                 *      try { par.intVal = int.Parse(par.strVal); }
                 *      catch { }
                 *      break;
                 *  case "bool":
                 *      par.type = ParamType.Boolean;
                 *      try { par.intVal = int.Parse(par.strVal); }
                 *      catch { }
                 *      break;
                 * }
                 */
            }
        }
Esempio n. 11
0
        public DynamicReconfigureStringDropdown(DynamicReconfigureInterface dynamic, ParamDescription pd, object def, object max, object min, string edit_method)
        {
            this.def         = def;
            this.max         = max;
            this.min         = min;
            this.edit_method = edit_method.Replace("'enum'", "'Enum'");
            Dictionary <string, string> parsed = EnumParser.Parse(this.edit_method);

            string[] vals = parsed["Enum"].Split(new[] { '}' }, StringSplitOptions.RemoveEmptyEntries);
            List <Dictionary <string, string> > descs = vals.Select(s => EnumParser.SubParse(s + "}")).ToList();

            descs                            = descs.Except(descs.Where(d => d.Count == 0)).ToList();
            enumdescription                  = new EnumDescription();
            enumdescription.Enum             = new EnumValue[descs.Count];
            enumdescription.enum_description = parsed["enum_description"];
            Type tdesc = typeof(EnumValue);

            for (int i = 0; i < descs.Count; i++)
            {
                Dictionary <string, string> desc = descs[i];
                EnumValue newval = new EnumValue();
                foreach (string s in desc.Keys)
                {
                    FieldInfo fi = tdesc.GetField(s);
                    if (fi.FieldType == typeof(int))
                    {
                        fi.SetValue(newval, int.Parse(desc[s]));
                    }
                    else
                    {
                        fi.SetValue(newval, desc[s]);
                    }
                }
                enumdescription.Enum[i] = newval;
            }
            name         = pd.name;
            this.dynamic = dynamic;
            InitializeComponent();
            for (int i = 0; i < enumdescription.Enum.Length; i++)
            {
                if (!types.ContainsKey(enumdescription.Enum[i].type))
                {
                    throw new Exception("HANDLE " + enumdescription.Enum[i].type);
                }
                switch (types[enumdescription.Enum[i].type])
                {
                case DROPDOWN_TYPE.INT:
                {
                    ComboBoxItem cbi = new ComboBoxItem {
                        Tag = int.Parse(enumdescription.Enum[i].value), Content = enumdescription.Enum[i].name, ToolTip = new ToolTip {
                            Content = enumdescription.Enum[i].description + " (" + enumdescription.Enum[i].value + ")"
                        }
                    };
                    @enum.Items.Add(cbi);
                    if (i == 0)
                    {
                        @enum.SelectedValue = this.def;
                        dynamic.Subscribe(name, (Action <int>)changed);
                    }
                    else if (enumdescription.Enum[i].type != enumdescription.Enum[i - 1].type)
                    {
                        throw new Exception("NO CHANGSIES MINDSIES");
                    }
                }
                break;

                case DROPDOWN_TYPE.STR:
                {
                    ComboBoxItem cbi = new ComboBoxItem {
                        Tag = enumdescription.Enum[i].value, Content = enumdescription.Enum[i].name, ToolTip = new ToolTip {
                            Content = enumdescription.Enum[i].description
                        }
                    };
                    @enum.Items.Add(cbi);
                    if (i == 0)
                    {
                        @enum.SelectedValue = this.def;
                        dynamic.Subscribe(name, (Action <string>)changed);
                    }
                    else if (enumdescription.Enum[i].type != enumdescription.Enum[i - 1].type)
                    {
                        throw new Exception("NO CHANGSIES MINDSIES");
                    }
                }
                break;
                }
            }
            description.Content = name + ":";
            JustTheTip.Content  = pd.description;
            ignore = false;
        }