From 7ed962c7206817556e790d048bca38e4e3caf249 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 14 Feb 2018 11:47:21 +0200 Subject: Added code comments for technician module. --- .../ViewModels/MachineTechViewVM.cs | 162 +++++++++++++++++++-- 1 file changed, 153 insertions(+), 9 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels') 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 2a55d12c6..6ccc1caa0 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 @@ -29,6 +29,11 @@ using Tango.SharedUI; namespace Tango.MachineStudio.Technician.ViewModels { + /// + /// Represents the MachineTechView View Model. + /// + /// + /// public class MachineTechViewVM : ViewModel, IShutdownListener { private List _diagnoticsDataProperties; @@ -139,22 +144,42 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Commands + /// + /// Gets or sets the save as project command. + /// public RelayCommand SaveAsProjectCommand { get; set; } + /// + /// Gets or sets the save project command. + /// public RelayCommand SaveProjectCommand { get; set; } + /// + /// Gets or sets the open project command. + /// public RelayCommand OpenProjectCommand { get; set; } #endregion #region Constructors + /// + /// Initializes a new instance of the class. + /// + /// The application manager. + /// The notification provider. [PreferredConstructor] public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) : this(applicationManager, notificationProvider, true) { } + /// + /// Initializes a new instance of the class. + /// + /// The application manager. + /// The notification provider. + /// if set to true [load last project]. public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, bool loadLastProject) { _notification = notificationProvider; @@ -215,6 +240,10 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Populate Diagnostics Data + /// + /// Populates the diagnostics data to the proper elements. + /// + /// The data. private void PopulateDiagnosticsData(PushDiagnosticsResponse data) { if (DateTime.Now > _lastDiagnosticsResponseUpdate.AddMilliseconds(MIN_DIAGNOSTICS_UPDATE_MILI)) @@ -240,7 +269,7 @@ namespace Tango.MachineStudio.Technician.ViewModels if (prop != null) { - monitorItem.Value = GetLastMonitorValue(monitorItem.TechMonitor, prop.GetValue(data)); + monitorItem.Value = GetDataLastValue(monitorItem.TechMonitor, prop.GetValue(data)); } } } @@ -254,7 +283,7 @@ namespace Tango.MachineStudio.Technician.ViewModels if (prop != null) { - meterItem.Value = GetLastMonitorValue(meterItem.TechMonitor, prop.GetValue(data)); + meterItem.Value = GetDataLastValue(meterItem.TechMonitor, prop.GetValue(data)); } } } @@ -270,7 +299,7 @@ namespace Tango.MachineStudio.Technician.ViewModels if (_singleControllers.TryGetValue(graphItem, out controller)) { - controller.PushData(GetSingleGraphValues(graphItem.TechMonitor, prop.GetValue(data))); + controller.PushData(GetDataArray(graphItem.TechMonitor, prop.GetValue(data))); } } } @@ -286,7 +315,7 @@ namespace Tango.MachineStudio.Technician.ViewModels if (_multiControllers.TryGetValue(graphItem, out controller)) { - controller.PushData(GetMultiGraphValues(graphItem.TechMonitor, prop.GetValue(data))); + controller.PushData(GetDataMatrix(graphItem.TechMonitor, prop.GetValue(data))); } } } @@ -320,7 +349,13 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Private Methods - private double GetLastMonitorValue(TechMonitor monitor, object value) + /// + /// Gets the last data point from a protobuf repeated field. + /// + /// The monitor. + /// The value. + /// + private double GetDataLastValue(TechMonitor monitor, object value) { if (!monitor.MultiChannel) { @@ -334,12 +369,24 @@ namespace Tango.MachineStudio.Technician.ViewModels } } - private List GetSingleGraphValues(TechMonitor monitor, object value) + /// + /// Gets the data array from a protobuf repeated field. + /// + /// The monitor. + /// The value. + /// + private List GetDataArray(TechMonitor monitor, object value) { return (value as RepeatedField).ToList(); } - private List> GetMultiGraphValues(TechMonitor monitor, object value) + /// + /// Gets the data matrix from a protobuf repeated field of . + /// + /// The monitor. + /// The value. + /// + private List> GetDataMatrix(TechMonitor monitor, object value) { DoubleArray[] arrayOfDoubles = Enumerable.ToArray(value as IEnumerable); return arrayOfDoubles.Select(x => x.Data.ToList()).ToList(); @@ -349,6 +396,9 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Virtual Methods + /// + /// Called when the disable rendering has been changed + /// protected virtual void OnDisableRenderingChanged() { foreach (var controller in _singleControllers) @@ -366,11 +416,20 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Add/Remove Element + /// + /// Creates a new tech element by the specified bounds and the current selected element. + /// + /// The bounds. public void CreateElement(Rect bounds) { CreateElement(SelectedTechItem, bounds); } + /// + /// Creates a new tech element by the specified tech item instance and bounds. + /// + /// The item. + /// The bounds. private void CreateElement(TechItem item, Rect bounds) { if (item is MonitorItem) @@ -422,6 +481,15 @@ namespace Tango.MachineStudio.Technician.ViewModels } } + /// + /// Creates a new element by the specified editor type, tech item type, bounds and tech item constructor value. + /// + /// The type of the editor. + /// The type of the tech. + /// The type of the value. + /// The bounds. + /// The value. + /// private Editor CreateElement(Rect bounds, Value value) where Editor : IElementEditor where Tech : TechItem { TechItem item = Activator.CreateInstance(typeof(Tech), new object[] { value }) as TechItem; @@ -430,6 +498,12 @@ namespace Tango.MachineStudio.Technician.ViewModels return (Editor)editor; } + /// + /// Creates a new element by the specified editor type and tech item instance. + /// + /// The type of the editor. + /// The item. + /// private Editor CreateElement(TechItem item) where Editor : IElementEditor { IElementEditor editor = Activator.CreateInstance(typeof(Editor), new object[] { item, item.GetBounds() }) as IElementEditor; @@ -437,6 +511,10 @@ namespace Tango.MachineStudio.Technician.ViewModels return (Editor)editor; } + /// + /// Adds a new tech item. + /// + /// The item. private void AddTechItem(TechItem item) { if (item is MonitorItem) @@ -496,6 +574,10 @@ namespace Tango.MachineStudio.Technician.ViewModels } } + /// + /// Called when elements have been removed + /// + /// The elements. public void OnElementsRemoved(List elements) { //foreach (var element in elements) @@ -513,6 +595,10 @@ namespace Tango.MachineStudio.Technician.ViewModels //} } + /// + /// Called when elements have been pasted + /// + /// The elements. public void OnElementsPasted(List elements) { foreach (var element in elements) @@ -585,6 +671,10 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Init Tech Items + /// + /// Initializes the motor item. + /// + /// The item. private void InitMotorItem(MotorItem item) { item.ActionExecuted += async (x, action) => @@ -655,6 +745,10 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + /// + /// Initializes the dispenser item. + /// + /// The item. private void InitDispenserItem(DispenserItem item) { item.ActionExecuted += async (x, action) => @@ -725,6 +819,11 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + /// + /// Initializes the single graph item. + /// + /// The item. + /// The editor. private void InitSingleGraphitem(SingleGraphItem item, SingleGraphElementEditor editor) { editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(item.TechMonitor.PointsPerFrame); @@ -736,6 +835,11 @@ namespace Tango.MachineStudio.Technician.ViewModels _singleControllers.Add(item, controller); } + /// + /// Initializes the multi graph item. + /// + /// The item. + /// The editor. private void InitMultiGraphItem(MultiGraphItem item, MultiGraphElementEditor editor) { editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(item.TechMonitor.PointsPerFrame); @@ -758,6 +862,10 @@ namespace Tango.MachineStudio.Technician.ViewModels _multiControllers.Add(item, controller); } + /// + /// Initializes the thread motion item. + /// + /// The item. private void InitThreadMotionItem(ThreadMotionItem item) { item.ActionExecuted += async (x, action) => @@ -783,6 +891,10 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + /// + /// Initializes the motor group item. + /// + /// The item. private void InitMotorGroupItem(MotorGroupItem item) { item.ActionExecuted += async (x, action) => @@ -853,6 +965,10 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + /// + /// Initializes the digital out item. + /// + /// The item. private void InitDigitalOutItem(DigitalOutItem item) { item.ValueChanged += async (x, value) => @@ -872,6 +988,9 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Public Methods + /// + /// Opens a file open dialog to select a project file. + /// public void OpenProject() { OpenFileDialog dlg = new OpenFileDialog(); @@ -884,12 +1003,20 @@ namespace Tango.MachineStudio.Technician.ViewModels } } + /// + /// Opens the specified project file path. + /// + /// File path. public void OpenProjectFile(String fileName) { LoadProject(MachineTechViewProject.Load(fileName)); _lastTechProjectFile = fileName; } + /// + /// Loads the specified project. + /// + /// The project. public void LoadProject(MachineTechViewProject project) { using (_notification.PushTaskItem("Loading technician project file...")) @@ -910,6 +1037,9 @@ namespace Tango.MachineStudio.Technician.ViewModels } } + /// + /// Opens the file save dialog for selecting a project file target. + /// private void SaveAsProject() { SaveFileDialog dlg = new SaveFileDialog(); @@ -922,16 +1052,23 @@ namespace Tango.MachineStudio.Technician.ViewModels } } + /// + /// Saves the current project to the specified file path. + /// + /// Name of the file. private void SaveProjectFile(String fileName) { using (_notification.PushTaskItem("Saving technician project file...")) { - MachineTechViewProject project = CreateProjectFile(); + MachineTechViewProject project = GenerateProjectFile(); project.Save(fileName); _lastTechProjectFile = fileName; } } + /// + /// Saves the current opened project file. If not project file is opened will call . + /// private void SaveProject() { if (File.Exists(_lastTechProjectFile)) @@ -944,7 +1081,11 @@ namespace Tango.MachineStudio.Technician.ViewModels } } - private MachineTechViewProject CreateProjectFile() + /// + /// Generates a project file from the current element setup. + /// + /// + private MachineTechViewProject GenerateProjectFile() { MachineTechViewProject project = new MachineTechViewProject(); @@ -967,6 +1108,9 @@ namespace Tango.MachineStudio.Technician.ViewModels #region IShutdownListener + /// + /// Called when the application is about to terminate. + /// public void OnShuttingDown() { InvokeUINow(() => -- cgit v1.3.1