diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-04 18:54:32 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-04 18:54:32 +0300 |
| commit | df9cd86ffccb0bd477ab7deb9d22c3bc0f908257 (patch) | |
| tree | c51cf0b7a56401a3df13f5e3b9c5b923a0d88a5b /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels | |
| parent | 583c1a2cf5cb065e3f17c1bfe0f4464b82e0ee4e (diff) | |
| download | Tango-df9cd86ffccb0bd477ab7deb9d22c3bc0f908257.tar.gz Tango-df9cd86ffccb0bd477ab7deb9d22c3bc0f908257.zip | |
Added USB baud rate to integration settings.
Implemented copy params/clone on hardware versions module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs | 91 |
1 files changed, 89 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 305d7a37f..f91badebe 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -10,6 +10,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.SharedUI; using Tango.BL; using Tango.SharedUI.Components; +using System.Runtime.CompilerServices; namespace Tango.MachineStudio.HardwareDesigner.ViewModels { @@ -142,17 +143,53 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels public RelayCommand NewCommand { get; set; } + public RelayCommand CloneCommand { get; set; } + + public RelayCommand CopyParametersCommand { get; set; } + public MainViewVM(INotificationProvider notification) { _notification = notification; Adapter = ObservablesEntitiesAdapter.Instance; - SaveCommand = new RelayCommand(Save, () => CurrentVersion != null); + SaveCommand = new RelayCommand(Save, () => SelectedVersion != null); NewCommand = new RelayCommand(New); - DeleteCommand = new RelayCommand(Delete, () => !_isNew && CurrentVersion != null); + DeleteCommand = new RelayCommand(Delete, () => !_isNew && SelectedVersion != null); CurrentVersion = new HardwareVersion(); CreateTemplate(CurrentVersion); + + CopyParametersCommand = new RelayCommand(CopyParameters,(x) => SelectedVersion != null && SelectedHardwareObjectType != null); + CloneCommand = new RelayCommand(CloneCurrentVersion, () => SelectedVersion != null); + } + + private void CopyParameters(object obj) + { + IObservableEntity source = obj.GetType().GetProperty("Data").GetValue(obj) as IObservableEntity; + IObservableEntity target = null; + + if (source is HardwareMotorType) + { + target = CurrentVersion.HardwareMotors.SingleOrDefault(x => x.HardwareMotorType == source); + } + else if (source is HardwareDancerType) + { + target = CurrentVersion.HardwareDancers.SingleOrDefault(x => x.HardwareDancerType == source); + } + else if (source is HardwarePidControlType) + { + target = CurrentVersion.HardwarePidControls.SingleOrDefault(x => x.HardwarePidControlType == source); + } + else if (source is HardwareWinderType) + { + target = CurrentVersion.HardwareWinders.SingleOrDefault(x => x.HardwareWinderType == source); + } + else if (source is HardwareSpeedSensorType) + { + target = CurrentVersion.HardwareSpeedSensors.SingleOrDefault(x => x.HardwareSpeedSensorType == source); + } + + target.MapPrimitivesTo(SelectedHardwareObject); } private void OnSelectedHardwareObjectTypeChanged() @@ -452,6 +489,50 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels } } + private async void CloneCurrentVersion() + { + if (CurrentVersion != null) + { + String name = _notification.ShowTextInput("Enter new hardware configuration name", "Name", CurrentVersion.Name + " - Copy"); + + if (!String.IsNullOrWhiteSpace(name)) + { + using (_notification.PushTaskItem("Cloning hardware configuration...")) + { + await Task.Factory.StartNew(() => + { + var realVersion = CurrentVersion.Clone(); + realVersion.Name = name; + realVersion.Version = 1; + + realVersion.HardwareMotors.ToList().Where(x => !SelectedMotorTypes.Contains(x.HardwareMotorType)).ToList().ForEach(x => realVersion.HardwareMotors.Remove(x)); + realVersion.HardwareDancers.ToList().Where(x => !SelectedDancerTypes.Contains(x.HardwareDancerType)).ToList().ForEach(x => realVersion.HardwareDancers.Remove(x)); + realVersion.HardwarePidControls.ToList().Where(x => !SelectedPidControlTypes.Contains(x.HardwarePidControlType)).ToList().ForEach(x => realVersion.HardwarePidControls.Remove(x)); + realVersion.HardwareWinders.ToList().Where(x => !SelectedWinderTypes.Contains(x.HardwareWinderType)).ToList().ForEach(x => realVersion.HardwareWinders.Remove(x)); + realVersion.HardwareSpeedSensors.ToList().Where(x => !SelectedSpeedSensorTypes.Contains(x.HardwareSpeedSensorType)).ToList().ForEach(x => realVersion.HardwareSpeedSensors.Remove(x)); + + realVersion.HardwareMotors.ToList().ForEach(x => x.HardwareVersionGuid = realVersion.Guid); + realVersion.HardwareDancers.ToList().ForEach(x => x.HardwareVersionGuid = realVersion.Guid); + realVersion.HardwarePidControls.ToList().ForEach(x => x.HardwareVersionGuid = realVersion.Guid); + realVersion.HardwareWinders.ToList().ForEach(x => x.HardwareVersionGuid = realVersion.Guid); + realVersion.HardwareSpeedSensors.ToList().ForEach(x => x.HardwareVersionGuid = realVersion.Guid); + + realVersion.HardwareMotors.ToList().ForEach(x => x.HardwareVersion = realVersion); + realVersion.HardwareDancers.ToList().ForEach(x => x.HardwareVersion = realVersion); + realVersion.HardwarePidControls.ToList().ForEach(x => x.HardwareVersion = realVersion); + realVersion.HardwareWinders.ToList().ForEach(x => x.HardwareVersion = realVersion); + realVersion.HardwareSpeedSensors.ToList().ForEach(x => x.HardwareVersion = realVersion); + + Adapter.Context.HardwareVersions.Add(realVersion); + realVersion.Save(Adapter.Context); + + SelectedVersion = Adapter.HardwareVersions.SingleOrDefault(x => x.Guid == realVersion.Guid); + }); + } + } + } + } + private void Delete() { if (_notification.ShowQuestion("Are you sure you want to delete this hardware version?")) @@ -464,5 +545,11 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels } } } + + protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) + { + base.RaisePropertyChangedAuto(caller); + InvalidateRelayCommands(); + } } } |
