From 84a74bd9ea68a3f913e733a470ec64d1f8f50424 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 7 Feb 2018 19:50:40 +0200 Subject: Started working on monitoring view.. --- .../Controls/IOMonitorControl.xaml | 115 +++++++++++++++++++++ .../Controls/IOMonitorControl.xaml.cs | 109 +++++++++++++++++++ .../Images/black-screen.jpg | Bin 0 -> 15003 bytes .../Tango.MachineStudio.Developer.csproj | 19 ++++ .../ViewModelLocator.cs | 9 ++ .../ViewModels/IOVM.cs | 47 +++++++++ .../ViewModels/MonitoringViewVM.cs | 93 +++++++++++++++++ .../Views/MainView.xaml | 3 +- .../Views/MonitoringView.xaml | 76 ++++++++++++++ .../Views/MonitoringView.xaml.cs | 50 +++++++++ 10 files changed, 520 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/black-screen.jpg create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml new file mode 100644 index 000000000..c40e69d98 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs new file mode 100644 index 000000000..bc408958d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Core.Commands; + +namespace Tango.MachineStudio.Developer.Controls +{ + /// + /// Interaction logic for IOMonitorControl.xaml + /// + public partial class IOMonitorControl : UserControl + { + public ICommand ForwardPressedCommand + { + get { return (ICommand)GetValue(ForwardPressedCommandProperty); } + set { SetValue(ForwardPressedCommandProperty, value); } + } + public static readonly DependencyProperty ForwardPressedCommandProperty = + DependencyProperty.Register("ForwardPressedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); + + public ICommand ForwardReleasedCommand + { + get { return (ICommand)GetValue(ForwardReleasedCommandProperty); } + set { SetValue(ForwardReleasedCommandProperty, value); } + } + public static readonly DependencyProperty ForwardReleasedCommandProperty = + DependencyProperty.Register("ForwardReleasedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); + + public ICommand BackwardPressedCommand + { + get { return (ICommand)GetValue(BackwardPressedCommandProperty); } + set { SetValue(BackwardPressedCommandProperty, value); } + } + public static readonly DependencyProperty BackwardPressedCommandProperty = + DependencyProperty.Register("BackwardPressedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); + + public ICommand BackwardReleasedCommand + { + get { return (ICommand)GetValue(BackwardReleasedCommandProperty); } + set { SetValue(BackwardReleasedCommandProperty, value); } + } + public static readonly DependencyProperty BackwardReleasedCommandProperty = + DependencyProperty.Register("BackwardReleasedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); + + public object CommandParameter + { + get { return (object)GetValue(CommandParameterProperty); } + set { SetValue(CommandParameterProperty, value); } + } + public static readonly DependencyProperty CommandParameterProperty = + DependencyProperty.Register("CommandParameter", typeof(object), typeof(IOMonitorControl), new PropertyMetadata(null)); + + public String Value + { + get { return (String)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(String), typeof(IOMonitorControl), new PropertyMetadata("0000")); + + public IOMonitorControl() + { + InitializeComponent(); + } + + private void OnForwardPressed(object sender, MouseButtonEventArgs e) + { + if (ForwardPressedCommand != null) + { + ForwardPressedCommand.Execute(CommandParameter); + } + } + + private void OnForwardReleased(object sender, MouseButtonEventArgs e) + { + if (ForwardReleasedCommand != null) + { + ForwardReleasedCommand.Execute(CommandParameter); + } + } + + private void OnBackwardPressed(object sender, MouseButtonEventArgs e) + { + if (BackwardPressedCommand != null) + { + BackwardPressedCommand.Execute(CommandParameter); + } + } + + private void OnBackwardReleased(object sender, MouseButtonEventArgs e) + { + if (BackwardReleasedCommand != null) + { + BackwardReleasedCommand.Execute(CommandParameter); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/black-screen.jpg b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/black-screen.jpg new file mode 100644 index 000000000..7ed5c3eb2 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/black-screen.jpg differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 4ef73a918..722d8efe6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -90,6 +90,9 @@ + + IOMonitorControl.xaml + @@ -108,7 +111,9 @@ + + MainView.xaml @@ -116,6 +121,13 @@ GlobalVersionInfo.cs + + MonitoringView.xaml + + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -124,6 +136,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + @@ -267,5 +283,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs index 46c7ecf00..200c89e19 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs @@ -21,6 +21,7 @@ namespace Tango.MachineStudio.Developer SimpleIoc.Default.Register(() => MainView.Self); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); } public static MainViewVM MainViewVM @@ -30,5 +31,13 @@ namespace Tango.MachineStudio.Developer return ServiceLocator.Current.GetInstance(); } } + + public static MonitoringViewVM MonitoringViewVM + { + get + { + return ServiceLocator.Current.GetInstance(); + } + } } } \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs new file mode 100644 index 000000000..83eee1333 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class IOVM : ExtendedObject + { + private Io _io; + public Io IO + { + get { return _io; } + set { _io = value; RaisePropertyChangedAuto(); } + } + + private String _name; + public String Name + { + get { return _name; } + set { _name = value; } + } + + private bool _index; + public bool Index + { + get { return _index; } + set { _index = value; } + } + + private double _value; + public double Value + { + get { return _value; } + set { _value = value; RaisePropertyChanged(nameof(Value)); } + } + + public IOVM(Io io, String name) + { + IO = io; + Name = name; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs new file mode 100644 index 000000000..8edbd7b83 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs @@ -0,0 +1,93 @@ +using Google.Protobuf.Collections; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Observables; +using Tango.Integration.Services; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.PMR.Diagnostics; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class MonitoringViewVM : ViewModel + { + private ObservableCollection _availableControllers; + public ObservableCollection AvailableControllers + { + get { return _availableControllers; } + set { _availableControllers = value; } + } + + private ObservableCollection _controllers; + public ObservableCollection Controllers + { + get { return _controllers; } + set { _controllers = value; } + } + + private ObservablesEntitiesAdapter _adapter; + public ObservablesEntitiesAdapter Adapter + { + get { return _adapter; } + set { _adapter = value; } + } + + public IStudioApplicationManager ApplicationManager { get; set; } + + public MonitoringViewVM(IStudioApplicationManager applicationManager) + { + ApplicationManager = applicationManager; + ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; + + if (!this.DesignMode) + { + Adapter = ObservablesEntitiesAdapter.Instance; + AvailableControllers = Adapter.Ios.Select(x => new IOVM(x, x.Name)).ToObservableCollection(); + } + + Controllers = new ObservableCollection(); + } + + private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine) + { + if (machine != null) + { + machine.DiagnosticsDataAvailable -= Machine_DiagnosticsDataAvailable; + machine.DiagnosticsDataAvailable += Machine_DiagnosticsDataAvailable; + } + } + + private void Machine_DiagnosticsDataAvailable(object sender, PushDiagnosticsResponse data) + { + foreach (var prop in data.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + IOVM controller = _controllers.SingleOrDefault(x => x.IO.Name == prop.Name); + + if (controller != null) + { + if (!controller.IO.MultiChannel) + { + RepeatedField arr = prop.GetValue(data) as RepeatedField; + controller.Value = arr.Last(); + } + else + { + //DoubleArray[] arrayOfDoubles = Enumerable.ToArray(prop.GetValue(data) as IEnumerable); + //(controller as GraphMultiController).PushData(arrayOfDoubles.Select(x => x.Data.ToList()).ToList()); + } + } + } + } + + public void OnDropAvailableIO(IOVM ioVM) + { + Controllers.Add(ioVM); + AvailableControllers.Remove(ioVM); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index cdfef3b0d..1ef6928f5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -1987,7 +1987,8 @@ - MONITORING + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml new file mode 100644 index 000000000..bd78ef13e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AVAILABLE IO'S + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml.cs new file mode 100644 index 000000000..0d649237e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MonitoringView.xaml.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.DragAndDrop; +using Tango.MachineStudio.Developer.ViewModels; + +namespace Tango.MachineStudio.Developer.Views +{ + /// + /// Interaction logic for MonitoringView.xaml + /// + public partial class MonitoringView : UserControl + { + private MonitoringViewVM _vm; + + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(MonitoringView), new PropertyMetadata(null)); + + public MonitoringView() + { + InitializeComponent(); + DraggingSurface = draggingSurface; + this.Loaded += (x, y) => + { + _vm = this.DataContext as MonitoringViewVM; + }; + } + + private void OnDropAvailableIO(object sender, DropEventArgs e) + { + _vm.OnDropAvailableIO(e.Draggable.DataContext as IOVM); + } + } +} -- cgit v1.3.1