From df9cd86ffccb0bd477ab7deb9d22c3bc0f908257 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 4 Jun 2018 18:54:32 +0300 Subject: Added USB baud rate to integration settings. Implemented copy params/clone on hardware versions module. --- .../ViewModels/MainViewVM.cs | 91 ++++++- .../Views/MainView.xaml | 271 ++++++++++++++++----- 2 files changed, 294 insertions(+), 68 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') 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(); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml index 361ea79b7..e22b0e71a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml @@ -19,6 +19,22 @@ + + + + + @@ -62,13 +78,36 @@ MOTORS - + - - - - + + + + + + + @@ -77,13 +116,36 @@ DANCERS - + - - - - + + + + + + + @@ -92,13 +154,36 @@ PID CONTROLS - + - - - - + + + + + + + @@ -107,32 +192,78 @@ WINDERS - + - - - - + + + + + + + - - - SPEED SENSORS - - - - - - - - - - - - + + + SPEED SENSORS + + + + + + + + + + + + + + + @@ -165,37 +296,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -218,6 +351,12 @@ NEW +