From 1dd0d4988fb99109765b956adc6a371f5cb036e0 Mon Sep 17 00:00:00 2001 From: Roy Date: Sun, 11 Feb 2018 14:55:39 +0200 Subject: More work on technician view... Added auto loading of last project. Added IShutdownListener interface. Added TechName to Tech Items. Fixed issue with tech name of IO port. --- .../ViewModels/MachineTechViewVM.cs | 97 +++++++++++++++++++--- 1 file changed, 85 insertions(+), 12 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 ca318f029..a4a9f0965 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 @@ -4,6 +4,7 @@ using RealTimeGraphEx.Controllers; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -15,21 +16,25 @@ using Tango.Core.Helpers; using Tango.Editors; using Tango.Integration.Observables; using Tango.Integration.Operators; +using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.MachineStudio.Technician.Editors; using Tango.MachineStudio.Technician.Project; using Tango.MachineStudio.Technician.TechItems; using Tango.PMR.Diagnostics; +using Tango.Settings; using Tango.SharedUI; namespace Tango.MachineStudio.Technician.ViewModels { - public class MachineTechViewVM : ViewModel + public class MachineTechViewVM : ViewModel, IShutdownListener { private List _diagnoticsDataProperties; private Dictionary _singleControllers; private Dictionary _multiControllers; private static object _elementsLock = new object(); + private String _lastTechProjectFile; + private INotificationProvider _notification; #region Properties @@ -83,6 +88,16 @@ namespace Tango.MachineStudio.Technician.ViewModels set { _machineOperator = value; RaisePropertyChangedAuto(); } } + private bool _disableRendering; + /// + /// Gets or sets a value indicating whether [disable rendering]. + /// + public bool DisableRendering + { + get { return _disableRendering; } + set { _disableRendering = value; RaisePropertyChangedAuto(); OnDisableRenderingChanged(); } + } + #endregion #region Commands @@ -97,8 +112,9 @@ namespace Tango.MachineStudio.Technician.ViewModels #region Constructors - public MachineTechViewVM(IStudioApplicationManager applicationManager) + public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) { + _notification = notificationProvider; _singleControllers = new Dictionary(); _multiControllers = new Dictionary(); AvailableTechItems = TechItem.GetAvailableTechItems().ToObservableCollection(); @@ -112,6 +128,14 @@ namespace Tango.MachineStudio.Technician.ViewModels OpenProjectCommand = new RelayCommand(OpenProject); SaveAsProjectCommand = new RelayCommand(SaveAsProject); + SaveProjectCommand = new RelayCommand(SaveProject); + + _lastTechProjectFile = SettingsManager.Default.MachineStudio.TechnicianModule.LasTechProjectFile; + + if (File.Exists(_lastTechProjectFile)) + { + OpenProjectFile(_lastTechProjectFile); + } } #endregion @@ -260,6 +284,23 @@ namespace Tango.MachineStudio.Technician.ViewModels #endregion + #region Virtual Methods + + protected virtual void OnDisableRenderingChanged() + { + foreach (var controller in _singleControllers) + { + controller.Value.ChangeRenderMode(!DisableRendering); + } + + foreach (var controller in _multiControllers) + { + controller.Value.ChangeRenderMode(!DisableRendering); + } + } + + #endregion + #region Add/Remove Element public void CreateElement(Rect bounds) @@ -648,17 +689,21 @@ namespace Tango.MachineStudio.Technician.ViewModels public void OpenProjectFile(String fileName) { LoadProject(MachineTechViewProject.Load(fileName)); + _lastTechProjectFile = fileName; } public void LoadProject(MachineTechViewProject project) { - Elements.Clear(); - _singleControllers.Clear(); - _multiControllers.Clear(); - - foreach (var item in project.Items) + using (_notification.PushTaskItem("Loading technician project file...")) { - AddTechItem(item); + Elements.Clear(); + _singleControllers.Clear(); + _multiControllers.Clear(); + + foreach (var item in project.Items) + { + AddTechItem(item); + } } } @@ -670,14 +715,30 @@ namespace Tango.MachineStudio.Technician.ViewModels if (dlg.ShowDialog().Value) { - SaveProject(dlg.FileName); + SaveProjectFile(dlg.FileName); + } + } + + private void SaveProjectFile(String fileName) + { + using (_notification.PushTaskItem("Saving technician project file...")) + { + MachineTechViewProject project = CreateProjectFile(); + project.Save(fileName); + _lastTechProjectFile = fileName; } } - private void SaveProject(String fileName) + private void SaveProject() { - MachineTechViewProject project = CreateProjectFile(); - project.Save(fileName); + if (File.Exists(_lastTechProjectFile)) + { + SaveProjectFile(_lastTechProjectFile); + } + else + { + SaveAsProject(); + } } private MachineTechViewProject CreateProjectFile() @@ -694,5 +755,17 @@ namespace Tango.MachineStudio.Technician.ViewModels } #endregion + + #region IShutdownListener + + public void OnShuttingDown() + { + InvokeUINow(() => + { + SettingsManager.Default.MachineStudio.TechnicianModule.LasTechProjectFile = _lastTechProjectFile; + }); + } + + #endregion } } -- cgit v1.3.1