Ejemplo n.º 1
0
        internal void processToScreen()
        {
            toolTip1.RemoveAll();
            Params.Items.Clear();

            Params.Objects.ForEach(x => { Params.RemoveObject(x); });

            Params.CellEditActivation = ObjectListView.CellEditActivateMode.SingleClick;

            Params.CanExpandGetter = delegate(object x)
            {
                var y = (data)x;
                if (y.children != null && y.children.Count > 0)
                {
                    return(true);
                }
                return(false);
            };

            Params.ChildrenGetter = delegate(object x)
            {
                var y = (data)x;
                return(new ArrayList(y.children));
            };

            //Params.Sort(Params.Columns[0], ListSortDirection.Ascending);

            var sorted = new List <string>();

            foreach (string item in MainV2.comPort.MAV.param.Keys)
            {
                sorted.Add(item);
            }

            sorted.Sort(ComparisonTree);

            var roots    = new List <data>();
            var lastroot = new data();

            // process hashdefines and update display
            foreach (var value in sorted)
            {
                if (value == null || value == "")
                {
                    continue;
                }

                //System.Diagnostics.Debug.WriteLine("Doing: " + value);

                var data = new data();

                var split = value.Split('_');
                data.root = split[0];

                data.paramname = value;
                data.Value     = MainV2.comPort.MAV.param[value].ToString();
                try
                {
                    var metaDataDescription = ParameterMetaDataRepository.GetParameterMetaData(value,
                                                                                               ParameterMetaDataConstants.Description, MainV2.comPort.MAV.cs.firmware.ToString());
                    if (!string.IsNullOrEmpty(metaDataDescription))
                    {
                        var range = ParameterMetaDataRepository.GetParameterMetaData(value,
                                                                                     ParameterMetaDataConstants.Range, MainV2.comPort.MAV.cs.firmware.ToString());
                        var options = ParameterMetaDataRepository.GetParameterMetaData(value,
                                                                                       ParameterMetaDataConstants.Values, MainV2.comPort.MAV.cs.firmware.ToString());
                        var units = ParameterMetaDataRepository.GetParameterMetaData(value,
                                                                                     ParameterMetaDataConstants.Units, MainV2.comPort.MAV.cs.firmware.ToString());

                        data.unit  = (units);
                        data.range = (range + options.Replace(",", " "));
                        data.desc  = (metaDataDescription);
                    }

                    if (lastroot.root == split[0])
                    {
                        lastroot.children.Add(data);
                    }
                    else
                    {
                        var newroot = new data {
                            root = split[0], paramname = split[0]
                        };
                        newroot.children.Add(data);
                        roots.Add(newroot);
                        lastroot = newroot;
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }

            foreach (var item in roots)
            {
                // if the child has no children, we dont need the root.
                if (item.children.Count == 1)
                {
                    Params.AddObject(item.children[0]);
                    continue;
                }

                Params.AddObject(item);
            }
        }
        internal void processToScreen()
        {
            toolTip1.RemoveAll();
            Params.Items.Clear();

            Params.Objects.ForEach(x => { Params.RemoveObject(x); });

            Params.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.SingleClick;

            Params.CanExpandGetter = delegate(object x)
            {
                data y = (data)x;
                if (y.children != null && y.children.Count > 0)
                {
                    return(true);
                }
                return(false);
            };

            Params.ChildrenGetter = delegate(object x)
            {
                data y = (data)x;
                return(new ArrayList(y.children));
            };

            //Params.Sort(Params.Columns[0], ListSortDirection.Ascending);

            List <string> sorted = new List <string>();

            foreach (string item in MainV2.comPort.MAV.param.Keys)
            {
                sorted.Add(item);
            }

            sorted.Sort();

            List <data> roots    = new List <data>();
            data        lastroot = new data();

            // process hashdefines and update display
            foreach (string value in sorted)
            {
                if (value == null || value == "")
                {
                    continue;
                }

                //System.Diagnostics.Debug.WriteLine("Doing: " + value);

                data data = new ConfigRawParamsTree.data();

                string[] split = value.Split('_');
                data.root = split[0];

                data.paramname = value;
                data.Value     = ((float)MainV2.comPort.MAV.param[value]).ToString();
                try
                {
                    string metaDataDescription = ParameterMetaDataRepository.GetParameterMetaData(value, ParameterMetaDataConstants.Description, MainV2.comPort.MAV.cs.firmware.ToString());
                    if (!String.IsNullOrEmpty(metaDataDescription))
                    {
                        string range   = ParameterMetaDataRepository.GetParameterMetaData(value, ParameterMetaDataConstants.Range, MainV2.comPort.MAV.cs.firmware.ToString());
                        string options = ParameterMetaDataRepository.GetParameterMetaData(value, ParameterMetaDataConstants.Values, MainV2.comPort.MAV.cs.firmware.ToString());
                        string units   = ParameterMetaDataRepository.GetParameterMetaData(value, ParameterMetaDataConstants.Units, MainV2.comPort.MAV.cs.firmware.ToString());

                        data.unit  = (units);
                        data.range = (range + options.Replace(",", " "));
                        data.desc  = (metaDataDescription);
                    }
                    else if (tooltips[value] != null)
                    {
                        //Params.Rows[Params.RowCount - 1].Cells[Command.Index].ToolTipText = ((paramsettings)tooltips[value]).desc;
                        //Params.Rows[Params.RowCount - 1].Cells[RawValue.Index].ToolTipText = ((paramsettings)tooltips[value]).desc;
                        // Params.Rows[Params.RowCount - 1].Cells[Value.Index].ToolTipText = ((paramsettings)tooltips[value]).desc;

                        //  Params.Rows[Params.RowCount - 1].Cells[Desc.Index].Value = "Old: "+((paramsettings)tooltips[value]).desc;

                        //Params.Rows[Params.RowCount - 1].Cells[Default.Index].Value = ((paramsettings)tooltips[value]).normalvalue;
                        //Params.Rows[Params.RowCount - 1].Cells[mavScale.Index].Value = ((paramsettings)tooltips[value]).scale;
                        //Params.Rows[Params.RowCount - 1].Cells[Value.Index].Value = float.Parse(Params.Rows[Params.RowCount - 1].Cells[RawValue.Index].Value.ToString()) / float.Parse(Params.Rows[Params.RowCount - 1].Cells[mavScale.Index].Value.ToString());
                    }


                    if (lastroot.root == split[0])
                    {
                        lastroot.children.Add(data);
                    }
                    else
                    {
                        data newroot = new ConfigRawParamsTree.data()
                        {
                            root = split[0], paramname = split[0]
                        };
                        newroot.children.Add(data);
                        roots.Add(newroot);
                        lastroot = newroot;
                    }
                }
                catch (Exception ex) { log.Error(ex); }
            }

            foreach (var item in roots)
            {
                // if the child has no children, we dont need the root.
                if (((List <data>)item.children).Count == 1)
                {
                    Params.AddObject(((List <data>)item.children)[0]);
                    continue;
                }

                Params.AddObject(item);
            }
        }