diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 221 |
1 files changed, 189 insertions, 32 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 2013de3c8..590474f9d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -7,22 +7,37 @@ using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; using Tango.DAL.Observables; +using Tango.MachineStudio.Common.Controls; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; namespace Tango.MachineStudio.Developer.ViewModels { + /// <summary> + /// Represents the developer module main view, view model. + /// </summary> + /// <seealso cref="Tango.SharedUI.ViewModel" /> public class MainViewVM : ViewModel { private INotificationProvider _notification; + #region Properties + + /// <summary> + /// Gets or sets the application manager. + /// </summary> public IStudioApplicationManager ApplicationManager { get; set; } + /// <summary> + /// Gets or sets observable entites database the adapter. + /// </summary> public ObservablesEntitiesAdapter Adapter { get; set; } private Machine _selectedMachine; - + /// <summary> + /// Gets or sets the selected machine. + /// </summary> public Machine SelectedMachine { get { return _selectedMachine; } @@ -30,7 +45,9 @@ namespace Tango.MachineStudio.Developer.ViewModels } private List<LiquidTypesRml> _liquidTypesRmls; - + /// <summary> + /// Gets or sets the liquid types RMLS. + /// </summary> public List<LiquidTypesRml> LiquidTypesRmls { get { return _liquidTypesRmls; } @@ -38,48 +55,49 @@ namespace Tango.MachineStudio.Developer.ViewModels } private ProcessParametersTablesGroup _rmlProcessParametersTablesGroup; - + /// <summary> + /// Gets or sets the RML process parameters table group (cloned). + /// </summary> public ProcessParametersTablesGroup RmlProcessParametersTableGroup { get { return _rmlProcessParametersTablesGroup; } set { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); } } - private ProcessParametersTablesGroup _selectedGroupHistory; - - public ProcessParametersTablesGroup SelectedGroupHistory - { - get { return _selectedGroupHistory; } - set { _selectedGroupHistory = value; RaisePropertyChangedAuto(); OnSelectedGroupHistoryChanged(); } - } - - private void OnSelectedGroupHistoryChanged() - { - if (SelectedGroupHistory != null) - { - RmlProcessParametersTableGroup = SelectedGroupHistory.CloneGroup(); - } - } - private ObservableCollection<ProcessParametersTablesGroup> _groupsHistory; - + /// <summary> + /// Gets or sets the RML process parameters groups history. + /// </summary> public ObservableCollection<ProcessParametersTablesGroup> GroupsHistory { get { return _groupsHistory; } set { _groupsHistory = value; RaisePropertyChangedAuto(); } } - private Job _selectedJob; + private ProcessParametersTablesGroup _selectedGroupHistory; + /// <summary> + /// Gets or sets the selected process parameters tables group history. + /// </summary> + public ProcessParametersTablesGroup SelectedGroupHistory + { + get { return _selectedGroupHistory; } + set { _selectedGroupHistory = value; RaisePropertyChangedAuto(); OnSelectedGroupHistoryChanged(); } + } + private Job _selectedJob; + /// <summary> + /// Gets or sets the selected machine job. + /// </summary> public Job SelectedJob { get { return _selectedJob; } set { _selectedJob = value; RaisePropertyChangedAuto(); } } - private Rml _selectedRML; - + /// <summary> + /// Gets or sets the selected RML. + /// </summary> public Rml SelectedRML { get { return _selectedRML; } @@ -87,43 +105,131 @@ namespace Tango.MachineStudio.Developer.ViewModels } private bool _isSideBarOpened; - + /// <summary> + /// Gets or sets a value indicating whether the configuration panels are opened. + /// </summary> public bool IsSideBarOpened { get { return _isSideBarOpened; } set { _isSideBarOpened = value; RaisePropertyChangedAuto(); } } + private ObservableCollection<Sensor> _availableSensors; + /// <summary> + /// Gets or sets the available sensors. + /// </summary> + public ObservableCollection<Sensor> AvailableSensors + { + get { return _availableSensors; } + set { _availableSensors = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection<RealTimeGraphControl> _graphs; + /// <summary> + /// Gets or sets the collection of displayed graph controls. + /// </summary> + public ObservableCollection<RealTimeGraphControl> Graphs + { + get { return _graphs; } + set { _graphs = value; RaisePropertyChangedAuto(); } + } + + #endregion + + #region Commands + + /// <summary> + /// Gets or sets the edit machine command. + /// </summary> public RelayCommand EditMachineCommand { get; set; } + /// <summary> + /// Gets or sets the edit RML command. + /// </summary> public RelayCommand EditRMLCommand { get; set; } + /// <summary> + /// Gets or sets the toggle side bar command. + /// </summary> public RelayCommand ToggleSideBarCommand { get; set; } + /// <summary> + /// Gets or sets the save process parameters command. + /// </summary> public RelayCommand SaveProcessParametersCommand { get; set; } + /// <summary> + /// Gets or sets the save liquid factors command. + /// </summary> public RelayCommand SaveLiquidFactorsCommand { get; set; } + #endregion + + #region Constructors + + /// <summary> + /// Initializes a new instance of the <see cref="MainViewVM"/> class. + /// </summary> public MainViewVM() { IsSideBarOpened = true; + + if (!this.DesignMode) + { + Adapter = ObservablesEntitiesAdapter.Instance; + AvailableSensors = Adapter.Sensors.ToObservableCollection(); + } + + Graphs = new ObservableCollection<RealTimeGraphControl>(); } + /// <summary> + /// Initializes a new instance of the <see cref="MainViewVM"/> class. + /// </summary> + /// <param name="applicationManager">The application manager.</param> + /// <param name="notificationProvider">The notification provider.</param> [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) : this() { _notification = notificationProvider; - Adapter = ObservablesEntitiesAdapter.Instance; EditMachineCommand = new RelayCommand(EditMachine, (x) => SelectedMachine != null); ApplicationManager = applicationManager; EditRMLCommand = new RelayCommand(EditRML, (x) => SelectedRML != null); ToggleSideBarCommand = new RelayCommand(() => IsSideBarOpened = !IsSideBarOpened); SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters); SaveLiquidFactorsCommand = new RelayCommand(SaveLiquidFactors); - IsSideBarOpened = true; } + #endregion + + #region Virtual Methods + + /// <summary> + /// Called when the selected group history has been changed + /// </summary> + protected virtual void OnSelectedGroupHistoryChanged() + { + if (SelectedGroupHistory != null) + { + RmlProcessParametersTableGroup = SelectedGroupHistory.CloneGroup(); + } + } + + /// <summary> + /// Called when the machine has been changed + /// </summary> + protected virtual void OnMachineChanged() + { + InvalidateLiquidFactorsAndProcessTables(); + } + + #endregion + + #region Private Methods + + /// <summary> + /// Saves the liquid factors. + /// </summary> private async void SaveLiquidFactors() { if (SelectedRML != null) @@ -141,21 +247,25 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + /// <summary> + /// Navigates to the DB Module in order to edit the selected RML. + /// </summary> private void EditRML() { ApplicationManager.RequestModule("Data Base", SelectedRML); } + /// <summary> + /// Navigates to the Machine Designer Module in order to edit the selected machine. + /// </summary> private void EditMachine() { ApplicationManager.RequestModule("Machine Designer", SelectedMachine); } - private void OnMachineChanged() - { - InvalidateLiquidFactorsAndProcessTables(); - } - + /// <summary> + /// Saves the process parameters group. + /// </summary> private async void SaveProcessParameters() { var response = _notification.ShowTextInput("Enter Group Name", "Group Name"); @@ -196,6 +306,9 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + /// <summary> + /// Invalidates the liquid factors and process parameters tables. + /// </summary> private void InvalidateLiquidFactorsAndProcessTables() { if (SelectedRML != null && SelectedMachine != null) @@ -212,5 +325,49 @@ namespace Tango.MachineStudio.Developer.ViewModels GroupsHistory = SelectedRML.ProcessParametersTablesGroups.OrderByDescending(x => x.SaveDate).OrderBy(x => !x.Active).ToObservableCollection(); } } + + #endregion + + #region Public Events + + /// <summary> + /// Add sensor graph from available sensors to displayed graphs. + /// </summary> + /// <param name="sensor">The sensor.</param> + public void OnDropAvailableSensor(Sensor sensor) + { + if (Graphs.Count < 8) + { + RealTimeGraphControl graphControl = new RealTimeGraphControl(); + graphControl.Tag = sensor; + graphControl.SensorName = sensor.Description; + graphControl.SensorUnits = sensor.Units; + graphControl.Graph.Minimum = sensor.Min; + graphControl.Graph.Maximum = sensor.Max; + graphControl.Graph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(sensor.PointsPerFrame); + graphControl.GraphRemoveButtonPressed += (sender, __) => + { + RemoveGraph(sender as RealTimeGraphControl); + }; + Graphs.Add(graphControl); + AvailableSensors.Remove(sensor); + } + else + { + _notification.ShowInfo("The maximum number of real-time graphs is eight. Please remove a graph to add another."); + } + } + + /// <summary> + /// Removes the graph. + /// </summary> + /// <param name="graph">The graph.</param> + public void RemoveGraph(RealTimeGraphControl graph) + { + Graphs.Remove(graph); + AvailableSensors.Insert(0, graph.Tag as Sensor); + } + + #endregion } } |
