diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 2be98e619..8bbebdfb7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -8,6 +8,8 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media; +using Tango.Core.Helpers; using Tango.Editors; using Tango.Integration.Observables; using Tango.Integration.Operators; @@ -23,6 +25,7 @@ namespace Tango.MachineStudio.Technician.ViewModels { private List<PropertyInfo> _diagnoticsDataProperties; private Dictionary<SingleGraphItem, GraphController> _singleControllers; + private Dictionary<MultiGraphItem, GraphMultiController> _multiControllers; private static object _elementsLock = new object(); private ObservableCollection<IElementEditor> _elements; @@ -62,6 +65,7 @@ namespace Tango.MachineStudio.Technician.ViewModels public MachineTechViewVM(IStudioApplicationManager applicationManager) { _singleControllers = new Dictionary<SingleGraphItem, GraphController>(); + _multiControllers = new Dictionary<MultiGraphItem, GraphMultiController>(); AvailableTechItems = TechItem.GetAvailableTechItems().ToObservableCollection(); SelectedTechItem = AvailableTechItems.FirstOrDefault(); _diagnoticsDataProperties = typeof(PushDiagnosticsResponse).GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); @@ -127,6 +131,22 @@ namespace Tango.MachineStudio.Technician.ViewModels } } } + else if (item.GetType() == typeof(MultiGraphItem)) + { + MultiGraphItem graphItem = item as MultiGraphItem; + + var prop = _diagnoticsDataProperties.SingleOrDefault(x => x.Name == graphItem.TechMonitor.Name); + + if (prop != null) + { + GraphMultiController controller = null; + + if (_multiControllers.TryGetValue(graphItem, out controller)) + { + controller.PushData(GetMultiGraphValues(graphItem.TechMonitor, prop.GetValue(data))); + } + } + } } } } @@ -150,20 +170,26 @@ namespace Tango.MachineStudio.Technician.ViewModels return (value as RepeatedField<double>).ToList(); } + private List<List<double>> GetMultiGraphValues(TechMonitor monitor,object value) + { + DoubleArray[] arrayOfDoubles = Enumerable.ToArray(value as IEnumerable<DoubleArray>); + return arrayOfDoubles.Select(x => x.Data.ToList()).ToList(); + } + public void AddElement(Rect bounds) { lock (_elementsLock) { if (SelectedTechItem is MonitorItem) { - var monitorItem = new MonitorItem(Adapter.TechMonitors.FirstOrDefault()); + var monitorItem = new MonitorItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); MonitorElementEditor editor = new MonitorElementEditor(monitorItem, bounds); editor.DataContext = monitorItem; Elements.Add(editor); } else if (SelectedTechItem is SingleGraphItem) { - var graphItem = new SingleGraphItem(Adapter.TechMonitors.FirstOrDefault()); + var graphItem = new SingleGraphItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); SingleGraphElementEditor editor = new SingleGraphElementEditor(graphItem, bounds); editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); editor.DataContext = graphItem; @@ -177,6 +203,33 @@ namespace Tango.MachineStudio.Technician.ViewModels Elements.Add(editor); } + else if (SelectedTechItem is MultiGraphItem) + { + var graphItem = new MultiGraphItem(Adapter.TechMonitors.Where(x => x.MultiChannel).FirstOrDefault()); + MultiGraphElementEditor editor = new MultiGraphElementEditor(graphItem, bounds); + editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); + editor.DataContext = graphItem; + graphItem.Editor = editor; + + + GraphMultiController controller = new GraphMultiController(); + + for (int i = 0; i < graphItem.TechMonitor.ChannelCount; i++) + { + controller.AddSeries(new RealTimeGraphEx.DataSeries.DataYSeries() + { + UseFillAndStroke = true, + Name = graphItem.TechMonitor.Name.First() + (i + 1).ToString(), + Stroke = new SolidColorBrush(ColorHelper.GetRandomColor()), + }); + } + + editor.InnerGraph.Controller = controller; + + _multiControllers.Add(graphItem, controller); + + Elements.Add(editor); + } } } } |
