public override DataTemplate SelectTemplate(object item, DependencyObject d)
        {
            FrameworkElement element = d as FrameworkElement;

            if (element != null && item != null && item is LogItemSchema)
            {
                LogItemSchema category = item as LogItemSchema;

                if (category.HasChildren)
                {
                    if (container == null)
                    {
                        container = element.FindResource("ContainerLogItemSchemaTemplate") as DataTemplate;
                    }
                    return(container);
                }
                else
                {
                    if (leaf == null)
                    {
                        leaf = element.FindResource("LeafLogItemSchemaTemplate") as DataTemplate;
                    }
                    return(leaf);
                }
            }

            return(null);
        }
示例#2
0
        LogItemSchema CreateSchemaItem(MessageFormat fmt)
        {
            LogItemSchema element = new LogItemSchema()
            {
                Name = fmt.name, Parent = schema
            };

            foreach (var f in fmt.fields)
            {
                LogItemSchema column = new LogItemSchema()
                {
                    Name = f.name, Parent = element, Type = f.typeName + (f.arraySize > 0 ? "[" + f.arraySize + "]" : "")
                };
                if (f.type == FieldType.Struct)
                {
                    // nested
                    var child = CreateSchemaItem(f.structType);
                    column.ChildItems = child.ChildItems;
                }
                if (element.ChildItems == null)
                {
                    element.ChildItems = new List <Model.LogItemSchema>();
                }
                element.ChildItems.Add(column);
            }
            return(element);
        }
        public override Style SelectStyle(object item, DependencyObject d)
        {
            FrameworkElement element = d as FrameworkElement;

            if (element != null && item != null && item is LogItemSchema)
            {
                LogItemSchema category = item as LogItemSchema;

                if (category.HasChildren)
                {
                    if (containerStyle == null)
                    {
                        containerStyle = element.FindResource("ContainerListItemStyle") as Style;
                    }
                    return(containerStyle);
                }
                else
                {
                    if (leafStyle == null)
                    {
                        leafStyle = element.FindResource("ChildListItemStyle") as Style;
                    }
                    return(leafStyle);
                }
            }

            return(null);
        }
示例#4
0
        IEnumerable <DataValue> GetSelectedDataValues(LogItemSchema schema)
        {
            List <DataValue> combined = new List <DataValue>();

            List <Flight> selected = GetSelectedFlights();

            if (selected.Count == 0)
            {
                // show everything.
                selected.Add(new Flight()
                {
                    StartTime = DateTime.MinValue, Duration = TimeSpan.MaxValue
                });
            }

            foreach (IDataLog log in this.logs)
            {
                if (log != null)
                {
                    foreach (var flight in selected)
                    {
                        if (flight.Log == null || flight.Log == log)
                        {
                            combined.AddRange(log.GetDataValues(schema, flight.StartTime, flight.Duration));
                        }
                    }
                }
            }

            return(combined);
        }
示例#5
0
        public IEnumerable <DataValue> GetDataValues(LogItemSchema schema, DateTime startTime, TimeSpan duration)
        {
            List <LogItemSchema> path = new List <Model.LogItemSchema>();

            while (schema != null)
            {
                path.Insert(0, schema);
                schema = schema.Parent;
            }

            LogItemSchema root = path[0];

            foreach (var m in msgs)
            {
                if (m is MessageData)
                {
                    MessageData data = (MessageData)m;
                    if (data.format.name == root.Name)
                    {
                        // matching root schema, so drill down if necessary.
                        for (int i = 1, n = path.Count; i < n; i++)
                        {
                            LogItemSchema child = path[i];
                            foreach (var field in data.format.fields)
                            {
                                if (field.name == child.Name)
                                {
                                    yield return(data.GetValue(field));
                                }
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        private void ShowSchema()
        {
            UiDispatcher.RunOnUIThread(() =>
            {
                LogItemSchema schema = null;

                // todo: compute combined schema for selected logs, but for now just show the first one.
                if (this.currentFlightLog != null)
                {
                    schema = currentFlightLog.Schema;
                }
                else if (this.logs.Count > 0)
                {
                    schema = this.logs[0].Schema;
                }
                if (schema == null || schema.ChildItems == null || schema.ChildItems.Count == 0)
                {
                    CategoryList.ItemsSource = null;
                }
                else
                {
                    // todo: compute combined schema for selected logs, but for now just show the first one.
                    List <LogItemSchema> list = new List <Model.LogItemSchema>(schema.ChildItems);
                    list.Sort((a, b) => { return(string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase)); });
                    CategoryList.ItemsSource = list;
                }
            });
        }
示例#7
0
        private void LiveUpdate(SimpleLineChart chart, MavlinkLog currentFlightLog, LogItemSchema schema)
        {
            // this method is running on a background task and it's job is to read an infinite stream of
            // data values from the log and show them in the live scrolling chart.

            CancellationTokenSource canceller = new CancellationTokenSource();

            chart.Closed += (s, e) =>
            {
                canceller.Cancel();
            };

            var query = currentFlightLog.LiveQuery(schema, canceller.Token);

            foreach (DataValue item in query)
            {
                if (item == null)
                {
                    return;
                }
                chart.SetCurrentValue(item);
            }

            chart.Closed += (sender, e) =>
            {
                canceller.Cancel();
            };

            Debug.WriteLine("LiveUpdate terminating on schema item " + schema.Name);
        }
示例#8
0
 private void InitializeChartData(LogItemSchema schema, SimpleLineChart chart, List <DataValue> values)
 {
     chart.SetData(new Model.DataSeries()
     {
         Name   = schema.Name,
         Values = values
     });
 }
示例#9
0
        public IEnumerable <DataValue> GetDataValues(LogItemSchema schema, DateTime startTime, TimeSpan duration)
        {
            List <LogItemSchema> path = new List <Model.LogItemSchema>();

            while (schema != null)
            {
                path.Insert(0, schema);
                schema = schema.Parent;
            }

            LogItemSchema root = path[0];

            foreach (var m in msgs)
            {
                if (m is MessageData)
                {
                    MessageData data = (MessageData)m;
                    //if (data.subscription.id == root.Id)
                    {
                        MessageFormat f = data.format;
                        // matching root schema, so drill down if necessary.
                        for (int i = 1, n = path.Count; i < n; i++)
                        {
                            bool found = false;
                            if (path[i].Name == f.name && i + 1 < n)
                            {
                                LogItemSchema child = path[i + 1];
                                foreach (var field in f.fields)
                                {
                                    if (field.name == child.Name)
                                    {
                                        found = true;
                                        if (i + 1 < n && child.HasChildren)
                                        {
                                            // still need to drill down, so we need a MessageData and MessageFormat for the child item.
                                            data = data.GetNestedData(field.name);
                                            f    = data.format;
                                        }
                                        else
                                        {
                                            yield return(data.GetValue(field));

                                            found = false; // done drilling down
                                        }
                                        break;
                                    }
                                }
                            }
                            if (!found)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
示例#10
0
 private void OnChildListItemSelected(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems != null && e.AddedItems.Count > 0 && e.OriginalSource == sender)
     {
         childLists.Add((ListView)sender);
         LogItemSchema item = (LogItemSchema)e.AddedItems[0];
         GraphItem(item);
     }
 }
示例#11
0
        private void OnItemExpanded(object sender, RoutedEventArgs e)
        {
            Expander expander  = (Expander)sender;
            ListView childView = expander.Content as ListView;

            if (childView != null)
            {
                LogItemSchema item = (LogItemSchema)expander.DataContext;
                childView.ItemsSource = item.ChildItems;
            }
        }
示例#12
0
        private void OnChartClosed(object sender, EventArgs e)
        {
            SimpleLineChart chart = sender as SimpleLineChart;

            ChartStack.RemoveChart(chart);
            chart.LiveScrolling = false;
            liveScrolling.Remove(chart);
            LayoutCharts();

            LogItemSchema item = (chart.Tag as LogItemSchema);

            if (item != null)
            {
                UnselectCategory(item);
            }
        }
示例#13
0
        private void CreateSchema()
        {
            LogItemSchema schema = new LogItemSchema()
            {
                Name = "Px4ULog", Type = "Root", ChildItems = new List <Model.LogItemSchema>()
            };

            // only need to show formats that we actually have subscriptions on.
            foreach (var sub in this.subscriptions.Values)
            {
                var element = CreateSchemaItem(sub.format);
                schema.ChildItems.Add(element);
            }

            this.schema = schema;
        }
示例#14
0
        private void CreateSchema()
        {
            LogItemSchema schema = new LogItemSchema()
            {
                Name = "Px4ULog", Type = "Root"
            };

            // only need to show formats that we actually have subscriptions on.
            foreach (var sub in this.subscriptions.Values)
            {
                // we can have "multi_id" subscriptions on the same format.
                var element = CreateSchemaItem(sub, sub.format);
                schema.AddChild(element);
            }

            this.schema = schema;
        }
示例#15
0
 private void UnselectCategory(LogItemSchema item)
 {
     if (CategoryList.SelectedItems.Contains(item))
     {
         CategoryList.SelectedItems.Remove(item);
     }
     else
     {
         // might be a child category item...
         foreach (var childList in childLists)
         {
             if (childList.SelectedItems.Contains(item))
             {
                 childList.SelectedItems.Remove(item);
             }
         }
     }
 }
示例#16
0
        LogItemSchema CreateSchemaItem(MessageSubscription sub, MessageFormat fmt)
        {
            LogItemSchema element = new LogItemSchema()
            {
                Name = fmt.name, Parent = schema, Id = sub.id
            };

            foreach (var f in fmt.fields)
            {
                LogItemSchema column = new LogItemSchema()
                {
                    Name = f.name, Parent = element, Type = f.typeName + (f.arraySize > 0 ? "[" + f.arraySize + "]" : ""), Id = sub.id
                };
                if (f.type == FieldType.Struct)
                {
                    // nested
                    var child = CreateSchemaItem(sub, f.structType);
                    column.ChildItems = child.ChildItems;
                }
                else if (f.arraySize > 0)
                {
                    List <LogItemSchema> arrayItems = new List <LogItemSchema>();
                    // break out the elements of the array as separate items.
                    for (int i = 0; i < f.arraySize; i++)
                    {
                        arrayItems.Add(new LogItemSchema()
                        {
                            Name = i.ToString(), Parent = column, Type = f.typeName, Id = sub.id
                        });
                    }
                    column.ChildItems = arrayItems;
                }
                if (element.ChildItems == null)
                {
                    element.ChildItems = new List <Model.LogItemSchema>();
                }
                element.ChildItems.Add(column);
            }
            return(element);
        }
示例#17
0
        LogItemSchema CreateSchemaItem(MessageSubscription sub, MessageFormat fmt)
        {
            LogItemSchema element = new LogItemSchema()
            {
                Name = fmt.name, Id = sub.id
            };

            foreach (var f in fmt.fields)
            {
                LogItemSchema column = new LogItemSchema()
                {
                    Name = f.name, Type = f.typeName + (f.arraySize > 0 ? "[" + f.arraySize + "]" : ""), Id = sub.id
                };
                if (f.type == FieldType.Struct)
                {
                    // nested
                    var child = CreateSchemaItem(sub, f.structType);
                    foreach (var item in child.CopyChildren())
                    {
                        column.AddChild(item);
                    }
                }
                else if (f.arraySize > 0)
                {
                    column.IsArray = true;
                    // break out the elements of the array as separate items.
                    for (int i = 0; i < f.arraySize; i++)
                    {
                        column.AddChild(new LogItemSchema()
                        {
                            Name = i.ToString(), Type = f.typeName, Id = sub.id
                        });
                    }
                }
                element.AddChild(column);
            }
            return(element);
        }
示例#18
0
        private void OnListItemSelected(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems != null && e.AddedItems.Count > 0)
            {
                LogItemSchema item = (LogItemSchema)e.AddedItems[0];
                if (sender == CategoryList && item.ChildItems != null)
                {
                    ListViewItem listItem = CategoryList.ItemContainerGenerator.ContainerFromItem(item) as ListViewItem;
                    if (listItem != null)
                    {
                        // make sure expander is toggled.
                        Expander expander = listItem.FindDescendantsOfType <Expander>().FirstOrDefault();
                        expander.IsExpanded = true;
                    }
                }
                else if (item.ChildItems == null || item.ChildItems.Count == 0)
                {
                    if (item.Parent == null)
                    {
                        GraphItem(item);
                    }
                }
            }

            if (e.RemovedItems != null && e.RemovedItems.Count > 0)
            {
                LogItemSchema item = (LogItemSchema)e.RemovedItems[0];
                if (sender == CategoryList && item.ChildItems != null)
                {
                    ListViewItem listItem = CategoryList.ItemContainerGenerator.ContainerFromItem(item) as ListViewItem;
                    if (listItem != null)
                    {
                        Expander expander = listItem.FindDescendantsOfType <Expander>().FirstOrDefault();
                        expander.IsExpanded = false;
                    }
                }
            }
        }
示例#19
0
        private void GraphItem(LogItemSchema schema)
        {
            if (schema.IsNumeric)
            {
                ChartStack.Visibility = Visibility.Visible;
                ChartStack.UpdateLayout();
                SimpleLineChart chart = new SimpleLineChart();
                chart.Margin          = defaultChartMargin;
                chart.Focusable       = false;
                chart.Closed         += OnChartClosed;
                chart.LineColor       = GetRandomColor();
                chart.StrokeThickness = 1;
                chart.Tag             = schema;

                if (currentFlightLog != null && schema.Root == currentFlightLog.Schema)
                {
                    List <DataValue> values = new List <DataValue>(currentFlightLog.GetDataValues(schema, DateTime.MinValue, TimeSpan.MaxValue));
                    InitializeChartData(schema, chart, values);

                    // now turn on live scrolling...
                    chart.LiveScrolling = true;
                    // the X values are in microseconds (s0 the numerator is the speed of scrolling).
                    chart.LiveScrollingXScale = 50.0 / 1000000.0;

                    liveScrolling.Add(chart);

                    // now start watching the live update for new values that need to be added to this chart.
                    Task.Run(() =>
                    {
                        LiveUpdate(chart, currentFlightLog, schema);
                    });
                }
                else
                {
                    List <DataValue> values = new List <DataValue>(GetSelectedDataValues(schema));
                    if (values.Count > 0)
                    {
                        InitializeChartData(schema, chart, values);
                    }
                    else
                    {
                        chart = null;
                    }
                    ShowStatus(string.Format("Found {0} data values", values.Count));
                }

                if (chart != null)
                {
                    if (chartGroup != null)
                    {
                        chartGroup.AddChart(chart);
                        if (chartGroup.Parent == null)
                        {
                            ChartStack.AddChartGroup(chartGroup);
                        }
                    }
                    else
                    {
                        ChartStack.AddChart(chart);
                    }
                    LayoutCharts();
                }

                ConsoleButton.IsChecked = false;
                SystemConsole.Hide();
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (var value in GetSelectedDataValues(schema))
                {
                    sb.AppendLine(value.Label);
                }

                SystemConsole.Write(sb.ToString());
                ConsoleButton.IsChecked = true;
                SystemConsole.Show();
            }
        }
示例#20
0
 public IEnumerable <DataValue> LiveQuery(LogItemSchema schema, CancellationToken token)
 {
     throw new NotImplementedException();
 }