From 79eb19cbd10785a7dbc972bc0b26817932237419 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 10 Oct 2018 16:55:44 +0300 Subject: Sign-out works ! Fixed issue where color conversion was busy while not in research module but research module in job view. Added new RealTimeGraphX ! --- .../ViewModels/MachineTechViewVM.cs | 123 +++++++++++++-------- 1 file changed, 77 insertions(+), 46 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs') 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 2ca5aa43b..1e1638928 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 @@ -35,6 +35,9 @@ using Tango.MachineStudio.Technician.Helpers; using Tango.MachineStudio.Technician.Models; using Tango.Logging; using Microsoft.WindowsAPICodePack.Dialogs; +using RealTimeGraphX; +using RealTimeGraphX.WPF.DataSeries; +using RealTimeGraphX.DataPoints; namespace Tango.MachineStudio.Technician.ViewModels { @@ -47,8 +50,8 @@ namespace Tango.MachineStudio.Technician.ViewModels { private List _diagnoticsMonitorsDataProperties; private IDiagnosticsFrameProvider _diagnosticsFrameProvider; - private Dictionary _singleControllers; - private Dictionary _multiControllers; + private Dictionary _singleControllers; + private Dictionary _multiControllers; private static object _elementsLock = new object(); private String _lastTechProjectFile; private INotificationProvider _notification; @@ -62,6 +65,8 @@ namespace Tango.MachineStudio.Technician.ViewModels private List _single_monitors_recordings; private List _multi_monitors_recordings; + private DateTime _start_time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); + private DateTime _last_time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); #region Properties @@ -290,8 +295,8 @@ namespace Tango.MachineStudio.Technician.ViewModels _notification = notificationProvider; _eventLogger = eventLogger; - _singleControllers = new Dictionary(); - _multiControllers = new Dictionary(); + _singleControllers = new Dictionary(); + _multiControllers = new Dictionary(); AvailableTechItems = TechItem.GetAvailableTechItems().ToObservableCollection(); SelectedTechItem = AvailableTechItems.FirstOrDefault(); _diagnoticsMonitorsDataProperties = typeof(DiagnosticsMonitors).GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); @@ -376,6 +381,10 @@ namespace Tango.MachineStudio.Technician.ViewModels /// The data. private void PopulateDiagnosticsData(StartDiagnosticsResponse data) { + TimeSpan delta_base = DateTime.Now - _start_time; + double delta_mili = (DateTime.Now - _last_time).TotalMilliseconds; + _last_time = DateTime.Now; + if (DateTime.Now > _lastDiagnosticsResponseUpdate.AddMilliseconds(MIN_DIAGNOSTICS_UPDATE_MILI)) { CurrentDiagnosticsResponse = data; @@ -451,20 +460,21 @@ namespace Tango.MachineStudio.Technician.ViewModels if (prop != null) { - GraphController controller = null; + TechGraphController controller = null; if (_singleControllers.TryGetValue(graphItem, out controller)) { var points = GetDataArray(graphItem.TechMonitor, prop.GetValue(data.Monitors)); - int maxPoints = (int)(_diagnosticsFrameProvider.FrameRate * GraphsDurationSeconds * points.Count); + List times = new List(); + var dPoints = points.Select(x => new DoubleDataPoint(x)).ToList(); - InvokeUI(() => + for (int i = 0; i < points.Count; i++) { - graphItem.Editor.InnerGraph.InnerGraph.MaxPoints = maxPoints; - }); + times.Add(delta_base.Add(TimeSpan.FromMilliseconds((delta_mili / points.Count) * i))); + } - controller.PushData(points); + controller.PushData(times, dPoints); var _graph_recording = _single_graphs_recordings.SingleOrDefault(x => x.Tag == graphItem); if (_graph_recording != null) @@ -482,7 +492,7 @@ namespace Tango.MachineStudio.Technician.ViewModels if (prop != null) { - GraphMultiController controller = null; + TechGraphController controller = null; if (_multiControllers.TryGetValue(graphItem, out controller)) { @@ -490,15 +500,23 @@ namespace Tango.MachineStudio.Technician.ViewModels if (points.Count > 0) { - int maxPoints = (int)(_diagnosticsFrameProvider.FrameRate * GraphsDurationSeconds * points[0].Count); + List times = new List(); + var dPoints = points.Select(x => new List(x.Select(y => new DoubleDataPoint(y)))).ToList(); - InvokeUI(() => + for (int i = 0; i < points[0].Count; i++) { - graphItem.Editor.InnerGraph.InnerGraph.MaxPoints = maxPoints; - }); - } + times.Add(delta_base.Add(TimeSpan.FromMilliseconds((delta_mili / points[0].Count) * i))); + } - controller.PushData(points); + List> timesMat = new List>(); + + for (int i = 0; i < controller.DataSeriesCollection.Count; i++) + { + timesMat.Add(times); + } + + controller.PushData(timesMat, dPoints); + } var _graph_recording = _multi_graph_recordings.SingleOrDefault(x => x.Tag == graphItem); if (_graph_recording != null) @@ -624,15 +642,15 @@ namespace Tango.MachineStudio.Technician.ViewModels /// protected virtual void OnDisableRenderingChanged() { - foreach (var controller in _singleControllers) - { - controller.Value.ChangeRenderMode(!DisableRendering); - } - - foreach (var controller in _multiControllers) - { - controller.Value.ChangeRenderMode(!DisableRendering); - } + //foreach (var controller in _singleControllers) + //{ + // controller.Value.ChangeRenderMode(!DisableRendering); + //} + + //foreach (var controller in _multiControllers) + //{ + // controller.Value.ChangeRenderMode(!DisableRendering); + //} } #endregion @@ -956,36 +974,38 @@ namespace Tango.MachineStudio.Technician.ViewModels { var graphItem = element.HostedElement as SingleGraphItem; var editor = element as SingleGraphElementEditor; - graphItem.Editor = editor; - editor.InnerGraph.InnerGraph.MaxPoints = GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); - GraphController controller = new GraphController(); + TechGraphController controller = new TechGraphController(); + controller.AddDataSeries(new WpfDataSeries() + { + Stroke = Colors.DodgerBlue, + }); editor.InnerGraph.Controller = controller; + graphItem.Editor = editor; + _singleControllers.Add(graphItem, controller); } else if (element is MultiGraphElementEditor) { var graphItem = element.HostedElement as MultiGraphItem; var editor = element as MultiGraphElementEditor; - editor.InnerGraph.InnerGraph.MaxPoints = GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); - graphItem.Editor = editor; - - GraphMultiController controller = new GraphMultiController(); + TechGraphController controller = new TechGraphController(500); for (int i = 0; i < graphItem.TechMonitor.ChannelCount; i++) { - controller.AddSeries(new RealTimeGraphEx.DataSeries.DataYSeries() + controller.AddDataSeries(new WpfDataSeries() { - UseFillAndStroke = true, + Stroke = ColorHelper.GetRandomColor(), Name = graphItem.TechMonitor.Name.First() + (i + 1).ToString(), - Stroke = new SolidColorBrush(ColorHelper.GetRandomColor()), }); } editor.InnerGraph.Controller = controller; + graphItem.Editor = editor; + _multiControllers.Add(graphItem, controller); } else if (element is MotorElementEditor) @@ -1300,12 +1320,21 @@ namespace Tango.MachineStudio.Technician.ViewModels /// The editor. private void InitSingleGraphitem(SingleGraphItem item, SingleGraphElementEditor editor) { - editor.InnerGraph.InnerGraph.MaxPoints = GraphsHelper.GetMaxPoints(item.TechMonitor.PointsPerFrame); - item.Editor = editor; + TechGraphController controller = new TechGraphController(); + controller.Range.AutoY = true; + controller.Range.MinimumY = item.TechMonitor.Min; + controller.Range.MaximumY = item.TechMonitor.Max; + controller.Range.MaximumX = TimeSpan.FromSeconds(10); + + controller.AddDataSeries(new WpfDataSeries() + { + Stroke = Colors.DodgerBlue, + }); - GraphController controller = new GraphController(); editor.InnerGraph.Controller = controller; + item.Editor = editor; + _singleControllers.Add(item, controller); item.RecordingStarted += () => @@ -1350,23 +1379,25 @@ namespace Tango.MachineStudio.Technician.ViewModels /// The editor. private void InitMultiGraphItem(MultiGraphItem item, MultiGraphElementEditor editor) { - editor.InnerGraph.InnerGraph.MaxPoints = GraphsHelper.GetMaxPoints(item.TechMonitor.PointsPerFrame); - item.Editor = editor; - - GraphMultiController controller = new GraphMultiController(); + TechGraphController controller = new TechGraphController(500); + controller.Range.AutoY = true; + controller.Range.MinimumY = item.TechMonitor.Min; + controller.Range.MaximumY = item.TechMonitor.Max; + controller.Range.MaximumX = TimeSpan.FromSeconds(10); for (int i = 0; i < item.TechMonitor.ChannelCount; i++) { - controller.AddSeries(new RealTimeGraphEx.DataSeries.DataYSeries() + controller.AddDataSeries(new WpfDataSeries() { - UseFillAndStroke = true, + Stroke = ColorHelper.GetRandomColor(), Name = item.TechMonitor.Name.First() + (i + 1).ToString(), - Stroke = new SolidColorBrush(ColorHelper.GetRandomColor()), }); } editor.InnerGraph.Controller = controller; + item.Editor = editor; + _multiControllers.Add(item, controller); item.RecordingStarted += () => -- cgit v1.3.1 From a909429b932b76f4310933c1dba6e3e77f88c92d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 10 Oct 2018 20:58:55 +0300 Subject: Done Implementing Valves !!! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes Software/Graphics/valve.png | Bin 0 -> 850 bytes .../ValveStateComparerToBooleanConverter.cs | 34 ++++ .../Editors/ValveElementEditor.xaml | 191 +++++++++++++++++++++ .../Editors/ValveElementEditor.xaml.cs | 103 +++++++++++ .../Images/valve.png | Bin 0 -> 850 bytes .../PropertiesTemplates/BreakSensorTemplate.xaml | 2 +- .../PropertiesTemplates/HeaterTemplate.xaml | 2 +- .../PropertiesTemplates/ValveTemplate.xaml | 43 +++++ .../PropertiesTemplates/ValveTemplate.xaml.cs | 28 +++ .../Tango.MachineStudio.Technician.csproj | 19 ++ .../TechItems/TechItem.cs | 1 + .../TechItems/ValveItem.cs | 117 +++++++++++++ .../ViewModels/MachineTechViewVM.cs | 79 ++++++++- .../Views/MachineTechView.xaml | 5 +- .../Resources/MaterialDesign.xaml | 4 +- .../Tango.BL/ObservablesStaticCollections.cs | 1 + .../Tango.Emulations/Emulators/MachineEmulator.cs | 27 +++ 19 files changed, 647 insertions(+), 9 deletions(-) create mode 100644 Software/Graphics/valve.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/ValveStateComparerToBooleanConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/valve.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ValveItem.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index b153be3ad..4518123b5 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 4491ab69c..046eaa9f2 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Graphics/valve.png b/Software/Graphics/valve.png new file mode 100644 index 000000000..5c08d0fc5 Binary files /dev/null and b/Software/Graphics/valve.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/ValveStateComparerToBooleanConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/ValveStateComparerToBooleanConverter.cs new file mode 100644 index 000000000..a05afe42e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/ValveStateComparerToBooleanConverter.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using Tango.PMR.Diagnostics; + +namespace Tango.MachineStudio.Technician.Converters +{ + public class ValveStateComparerToBooleanConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 2 && values[0] != DependencyProperty.UnsetValue && values[1] != DependencyProperty.UnsetValue) + { + ValveStateCode v1 = (ValveStateCode)values[0]; + ValveStateCode v2 = (ValveStateCode)Enum.Parse(typeof(ValveStateCode), values[1].ToString().Replace(" ", ""), true); + return v1 == v2; + } + else + { + return false; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml new file mode 100644 index 000000000..aed779d4b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml.cs new file mode 100644 index 000000000..8f364ce01 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ValveElementEditor.xaml.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Editors; +using Tango.BL.Entities; +using Tango.MachineStudio.Technician.TechItems; +using Tango.Core; + +namespace Tango.MachineStudio.Technician.Editors +{ + [ContentProperty("InnerContent")] + public partial class ValveElementEditor : ElementEditor + { + /// + /// Initializes a new instance of the class. + /// + public ValveElementEditor() + : base() + { + InitializeComponent(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The framework element. + public ValveElementEditor(ValveItem valveItem) + : this() + { + ValveItem = valveItem; + DataContext = ValveItem; + } + + /// + /// Initializes a new instance of the class. + /// + /// The framework element. + /// The bounds. + public ValveElementEditor(ValveItem valveItem, Rect bounds) + : this(valveItem) + { + Left = bounds.Left; + Top = bounds.Top; + Width = bounds.Width; + Height = bounds.Height; + } + + private ValveItem _valveItem; + + public ValveItem ValveItem + { + get { return _valveItem; } + set { _valveItem = value; RaisePropertyChanged(nameof(ValveItem)); } + } + + + /// + /// Clones this instance. + /// + /// + public override IElementEditor Clone() + { + try + { + var clonedItem = ValveItem.Clone() as ValveItem; + ValveElementEditor cloned = new ValveElementEditor(clonedItem); + cloned.Top = Top; + cloned.Left = Left; + cloned.Width = Width; + cloned.Height = Height; + cloned.Angle = Angle; + return cloned; + } + catch (Exception ex) + { + throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex); + } + } + + /// + /// Gets the hosted element. + /// + [ParameterIgnore] + public override Object HostedElement + { + get { return ValveItem; } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/valve.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/valve.png new file mode 100644 index 000000000..5c08d0fc5 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/valve.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/BreakSensorTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/BreakSensorTemplate.xaml index 7914c5a52..3e0ab9061 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/BreakSensorTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/BreakSensorTemplate.xaml @@ -24,7 +24,7 @@ - + Selected Break Sensor diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/HeaterTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/HeaterTemplate.xaml index 416428a0e..846500042 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/HeaterTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/HeaterTemplate.xaml @@ -24,7 +24,7 @@ - + Selected Heater diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml new file mode 100644 index 000000000..9c0a063e7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + Selected Valve + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml.cs new file mode 100644 index 000000000..9366464e7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ValveTemplate.xaml.cs @@ -0,0 +1,28 @@ +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; + +namespace Tango.MachineStudio.Technician.PropertiesTemplates +{ + /// + /// Interaction logic for MonitorTemplate.xaml + /// + public partial class ValveTemplate : UserControl + { + public ValveTemplate() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index c507b84f6..aca44f07f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -111,6 +111,10 @@ + + + ValveElementEditor.xaml + MonitorRecorderElementEditor.xaml @@ -192,6 +196,9 @@ HeaterTemplate.xaml + + ValveTemplate.xaml + TextTemplate.xaml @@ -268,6 +275,7 @@ + @@ -286,6 +294,10 @@ MachineTechView.xaml + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -382,6 +394,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -695,6 +711,9 @@ + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs index 54fbc8175..f59107ca2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs @@ -41,6 +41,7 @@ namespace Tango.MachineStudio.Technician.TechItems [XmlInclude(typeof(TextItem))] [XmlInclude(typeof(HeaterItem))] [XmlInclude(typeof(MonitorRecorderItem))] + [XmlInclude(typeof(ValveItem))] public abstract class TechItem : ExtendedObject { /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ValveItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ValveItem.cs new file mode 100644 index 000000000..e2f01565a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ValveItem.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using System.Xml.Serialization; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.PMR.Diagnostics; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.Technician.TechItems +{ + [TechItem(10)] + public class ValveItem : TechItem + { + /// + /// Occurs when the user has changed the current value. + /// + public event EventHandler StateChanged; + + /// + /// Gets or sets the set command. + /// + [XmlIgnore] + public RelayCommand SetCommand { get; set; } + + private TechValve _techValve; + /// + /// Gets or sets the db tech item. + /// + [XmlIgnore] + public TechValve TechValve + { + get { return _techValve; } + set + { + _techValve = value; RaisePropertyChangedAuto(); TechName = _techValve != null ? _techValve.Description : null; ItemGuid = value != null ? value.Guid : null; + + if (_techValve != null) + { + State = (ValveStateCode)Enum.Parse(typeof(ValveStateCode), _techValve.State1.Replace(" ", ""), true); + } + } + } + + private ValveStateCode _state; + /// + /// Gets or sets a value indicating whether this is on. + /// + [XmlIgnore] + public ValveStateCode State + { + get { return _state; } + set { _state = value; RaisePropertyChangedAuto(); } + } + + private ValveStateCode _effectiveState; + /// + /// Gets or sets the effective value received from the embedded device. + /// + [XmlIgnore] + public ValveStateCode EffectiveState + { + get { return _effectiveState; } + set + { + if (_effectiveState != value) + { + _effectiveState = value; + RaisePropertyChangedAuto(); + _state = value; + RaisePropertyChanged(nameof(State)); + } + } + } + + /// + /// Initializes a new instance of the class. + /// + public ValveItem() : base() + { + Name = "Valve Controller"; + Description = "Valve Controller"; + Image = ResourceHelper.GetImageFromResources("Images/valve.png"); + Color = Colors.White; + + SetCommand = new RelayCommand((x) => + { + State = (ValveStateCode)Enum.Parse(typeof(ValveStateCode), x.Replace(" ", ""), true); + StateChanged?.Invoke(this, State); + }); + } + + /// + /// Initializes a new instance of the class. + /// + /// The db tech item. + public ValveItem(TechValve techValve) : this() + { + TechValve = techValve; + } + + /// + /// Clones this instance. + /// + /// + public override TechItem Clone() + { + ValveItem cloned = base.Clone() as ValveItem; + cloned.TechValve = TechValve; + cloned.State = State; + return cloned; + } + } +} 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 1e1638928..59cd6fe19 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 @@ -559,6 +559,17 @@ namespace Tango.MachineStudio.Technician.ViewModels heaterItem.HeaterState = heaterState; } } + else if (item.GetType() == typeof(ValveItem)) + { + ValveItem valveItem = item as ValveItem; + + var valveState = data.ValvesStates.SingleOrDefault(x => x.ValveType == (ValveType)valveItem.TechValve.Code); + + if (valveState != null) + { + valveItem.EffectiveState = valveState.State; + } + } else if (item.GetType() == typeof(BlowerItem)) { BlowerItem blowerItem = item as BlowerItem; @@ -686,6 +697,11 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement(bounds, Adapter.TechHeaters.FirstOrDefault()); InitTechHeater(editor.HeaterItem); } + else if (item is ValveItem) + { + var editor = CreateElement(bounds, Adapter.TechValves.FirstOrDefault()); + InitTechValveItem(editor.ValveItem); + } else if (item is SingleGraphItem) { var editor = CreateElement(bounds, Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); @@ -822,6 +838,11 @@ namespace Tango.MachineStudio.Technician.ViewModels (item as HeaterItem).TechHeater = Adapter.TechHeaters.FirstOrDefault(x => x.Guid == item.ItemGuid); CreateElement(item); } + else if (item is ValveItem) + { + (item as ValveItem).TechValve = Adapter.TechValves.FirstOrDefault(x => x.Guid == item.ItemGuid); + CreateElement(item); + } else if (item is MeterItem) { (item as MeterItem).TechMonitor = Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault(x => x.Guid == item.ItemGuid); @@ -1018,26 +1039,51 @@ namespace Tango.MachineStudio.Technician.ViewModels var dispenser = element.HostedElement as DispenserItem; InitDispenserItem(dispenser); } - else if (element is DigitalOutItem) + else if (element is DigitalOutElementEditor) { var ioItem = element.HostedElement as DigitalOutItem; InitDigitalOutItem(ioItem); } - else if (element is ThreadMotionItem) + else if (element is ThreadMotionElementEditor) { var threadMotionItem = element.HostedElement as ThreadMotionItem; InitThreadMotionItem(threadMotionItem); } - else if (element is MotorGroupItem) + else if (element is MotorGroupElementEditor) { var motorGroupItem = element.HostedElement as MotorGroupItem; InitMotorGroupItem(motorGroupItem); } - else if (element is ControllerItem) + else if (element is ControllerElementEditor) { var controllerItem = element.HostedElement as ControllerItem; InitControllerItem(controllerItem); } + else if (element is MonitorRecorderElementEditor) + { + var item = element.HostedElement as MonitorRecorderItem; + InitMonitorRecorderItem(item); + } + else if (element is ValveElementEditor) + { + var item = element.HostedElement as ValveItem; + InitTechValveItem(item); + } + else if (element is BlowerElementEditor) + { + var item = element.HostedElement as BlowerItem; + InitBlowerItem(item); + } + else if (element is HeaterElementEditor) + { + var item = element.HostedElement as HeaterItem; + InitTechHeater(item); + } + else if (element is ProcessParametersElementEditor) + { + var item = element.HostedElement as ProcessParametersItem; + InitProcessParameterItem(item); + } } } @@ -1045,6 +1091,10 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Init Tech Items + /// + /// Initializes the monitor recorder item. + /// + /// The item. private void InitMonitorRecorderItem(MonitorRecorderItem item) { item.RecordingStarted += () => @@ -1089,6 +1139,27 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + /// + /// Initializes the tech valve. + /// + /// The valve item. + private void InitTechValveItem(ValveItem item) + { + item.StateChanged += async (x, state) => + { + try + { + CheckMachineOperator(); + await MachineOperator.SetValveState((ValveType)item.TechValve.Code, state); + } + catch (Exception ex) + { + LogManager.Log(ex, String.Format("Error executing technician set valve state command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set valve state command on '{0}'.", item.TechName)); + } + }; + } + /// /// Initializes the blower item. /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml index 2168018d1..3d129a252 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml @@ -289,7 +289,7 @@ - +