diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-22 14:21:23 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-22 14:21:23 +0300 |
| commit | 10692d6af49f30f6a4eb5054945a6368dd181022 (patch) | |
| tree | 9c68c1ba303aeed3be03f18ed01f72563bed644a /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner | |
| parent | 24149160c17fabe143f143de2796f9485d64410b (diff) | |
| download | Tango-10692d6af49f30f6a4eb5054945a6368dd181022.tar.gz Tango-10692d6af49f30f6a4eb5054945a6368dd181022.zip | |
Refactored Machine Versions Module !!!!
Embedded sqlexaminer.msi to repo.
Implemented precompiled views ?
Fixed an issue with RemoteDB DAL.
Added Active field to hardware components.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner')
2 files changed, 246 insertions, 554 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 3dd4e62a3..ab2b99dbd 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 @@ -11,118 +11,15 @@ using Tango.SharedUI; using Tango.BL; using Tango.SharedUI.Components; using System.Runtime.CompilerServices; +using Tango.MachineStudio.Common; namespace Tango.MachineStudio.HardwareDesigner.ViewModels { - public class MainViewVM : ViewModel + public class MainViewVM : StudioViewModel<HardwareDesignerModule> { private INotificationProvider _notification; private bool _isNew; - - private ObservablesEntitiesAdapter _adapter; - public ObservablesEntitiesAdapter Adapter - { - get { return _adapter; } - set { _adapter = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwareMotorType> _motorTypes; - public SelectedObjectCollection<HardwareMotorType> MotorTypes - { - get { return _motorTypes; } - set { _motorTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwareMotorType> _selectedMotorTypes; - public ObservableCollection<HardwareMotorType> SelectedMotorTypes - { - get { return _selectedMotorTypes; } - set { _selectedMotorTypes = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwareDancerType> _dancerTypes; - public SelectedObjectCollection<HardwareDancerType> DancerTypes - { - get { return _dancerTypes; } - set { _dancerTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwareDancerType> _selectedDancerTypes; - public ObservableCollection<HardwareDancerType> SelectedDancerTypes - { - get { return _selectedDancerTypes; } - set { _selectedDancerTypes = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwarePidControlType> _pidControlTypes; - public SelectedObjectCollection<HardwarePidControlType> PidControlTypes - { - get { return _pidControlTypes; } - set { _pidControlTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwarePidControlType> _selectedPidControlTypes; - public ObservableCollection<HardwarePidControlType> SelectedPidControlTypes - { - get { return _selectedPidControlTypes; } - set { _selectedPidControlTypes = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwareWinderType> _winderTypes; - public SelectedObjectCollection<HardwareWinderType> WinderTypes - { - get { return _winderTypes; } - set { _winderTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwareWinderType> _selectedWinderTypes; - public ObservableCollection<HardwareWinderType> SelectedWinderTypes - { - get { return _selectedWinderTypes; } - set { _selectedWinderTypes = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwareSpeedSensorType> _speedSensorTypes; - public SelectedObjectCollection<HardwareSpeedSensorType> SpeedSensorTypes - { - get { return _speedSensorTypes; } - set { _speedSensorTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwareSpeedSensorType> _selectedSpeedSensorTypes; - public ObservableCollection<HardwareSpeedSensorType> SelectedSpeedSensorTypes - { - get { return _selectedSpeedSensorTypes; } - set { _selectedSpeedSensorTypes = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwareBlowerType> _blowerTypes; - public SelectedObjectCollection<HardwareBlowerType> BlowerTypes - { - get { return _blowerTypes; } - set { _blowerTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwareBlowerType> _selectedBlowerTypes; - public ObservableCollection<HardwareBlowerType> SelectedBlowerTypes - { - get { return _selectedBlowerTypes; } - set { _selectedBlowerTypes = value; RaisePropertyChangedAuto(); } - } - - private SelectedObjectCollection<HardwareBreakSensorType> _breakSensorTypes; - public SelectedObjectCollection<HardwareBreakSensorType> BreakSensorTypes - { - get { return _breakSensorTypes; } - set { _breakSensorTypes = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection<HardwareBreakSensorType> _selectedBreakSensorTypes; - public ObservableCollection<HardwareBreakSensorType> SelectedBreakSensorTypes - { - get { return _selectedBreakSensorTypes; } - set { _selectedBreakSensorTypes = value; RaisePropertyChangedAuto(); } - } + private ObservablesContext _db; private HardwareVersion _selectedVersion; public HardwareVersion SelectedVersion @@ -144,25 +41,16 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels get { return _selectedHardwareObject; } set { - _selectedHardwareObject = null; - RaisePropertyChangedAuto(); _selectedHardwareObject = value; RaisePropertyChangedAuto(); } } - private Object _selectedHardwareObjectType; - public Object SelectedHardwareObjectType + private ObservableCollection<HardwareVersion> _hardwareVersions; + public ObservableCollection<HardwareVersion> HardwareVersions { - get { return _selectedHardwareObjectType; } - set - { - _selectedHardwareObjectType = null; - RaisePropertyChangedAuto(); - _selectedHardwareObjectType = value; - RaisePropertyChangedAuto(); - OnSelectedHardwareObjectTypeChanged(); - } + get { return _hardwareVersions; } + set { _hardwareVersions = value; RaisePropertyChangedAuto(); } } public RelayCommand SaveCommand { get; set; } @@ -179,429 +67,229 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels { _notification = notification; - Adapter = ObservablesEntitiesAdapter.Instance; + CurrentVersion = new HardwareVersion(); + SaveCommand = new RelayCommand(Save, () => SelectedVersion != null); NewCommand = new RelayCommand(New); DeleteCommand = new RelayCommand(Delete, () => !_isNew && SelectedVersion != null); CurrentVersion = new HardwareVersion(); - CreateTemplate(CurrentVersion); - CopyParametersCommand = new RelayCommand(CopyParameters, (x) => SelectedVersion != null && SelectedHardwareObjectType != null); + CopyParametersCommand = new RelayCommand(CopyParameters, (x) => SelectedVersion != null); CloneCommand = new RelayCommand(CloneCurrentVersion, () => SelectedVersion != null); } - private void CopyParameters(object obj) + public override void OnApplicationReady() { - IObservableEntity source = obj.GetType().GetProperty("Data").GetValue(obj) as IObservableEntity; - IObservableEntity target = null; + base.OnApplicationReady(); - if (source is HardwareMotorType) + Task.Factory.StartNew(() => { - 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); - } - else if (source is HardwareBlowerType) - { - target = CurrentVersion.HardwareBlowers.SingleOrDefault(x => x.HardwareBlowerType == source); - } - else if (source is HardwareBreakSensorType) - { - target = CurrentVersion.HardwareBreakSensors.SingleOrDefault(x => x.HardwareBreakSensorType == source); - } + RefreshVersions(); + CreateDefaultView(); + }); + } + + private void CopyParameters(object obj) + { + obj.MapPrimitivesTo(SelectedHardwareObject, + (prop) => + !prop.PropertyType.IsEnum + && + !prop.Name.ToLower().Contains("guid")); + } + + private void CreateDefaultView() + { + if (_db != null) _db.Dispose(); + + _db = ObservablesContext.CreateDefault(); + _db.Configuration.LazyLoadingEnabled = false; - target.MapPrimitivesTo(SelectedHardwareObject); + CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).ToObservableCollection(); + CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).ToObservableCollection(); + CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).ToObservableCollection(); + CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).ToObservableCollection(); + CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).ToObservableCollection(); + CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).ToObservableCollection(); + CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).ToObservableCollection(); } - private void OnSelectedHardwareObjectTypeChanged() + private void RefreshVersions() { - if (SelectedHardwareObjectType != null) + using (var db = ObservablesContext.CreateDefault()) { - if (SelectedHardwareObjectType is SelectedObject<HardwareMotorType>) + db.Configuration.LazyLoadingEnabled = false; + _hardwareVersions = db.HardwareVersions.ToObservableCollection(); + InvokeUI(() => { - var type = (SelectedHardwareObjectType as SelectedObject<HardwareMotorType>).Data; - var hardwareObj = CurrentVersion.HardwareMotors.SingleOrDefault(x => x.HardwareMotorType == type); + RaisePropertyChanged(nameof(HardwareVersions)); + }); + } + } - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwareMotor() { HardwareMotorType = type }; - CurrentVersion.HardwareMotors.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - else if (SelectedHardwareObjectType is SelectedObject<HardwareDancerType>) - { - var type = (SelectedHardwareObjectType as SelectedObject<HardwareDancerType>).Data; - var hardwareObj = CurrentVersion.HardwareDancers.SingleOrDefault(x => x.HardwareDancerType == type); + private void CreateVersionView(HardwareVersion selectedVersion) + { + if (_db != null) _db.Dispose(); - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwareDancer() { HardwareDancerType = type }; - CurrentVersion.HardwareDancers.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - else if (SelectedHardwareObjectType is SelectedObject<HardwarePidControlType>) - { - var type = (SelectedHardwareObjectType as SelectedObject<HardwarePidControlType>).Data; - var hardwareObj = CurrentVersion.HardwarePidControls.SingleOrDefault(x => x.HardwarePidControlType == type); + _db = ObservablesContext.CreateDefault(); + _db.Configuration.LazyLoadingEnabled = false; - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwarePidControl() { HardwarePidControlType = type }; - CurrentVersion.HardwarePidControls.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - else if (SelectedHardwareObjectType is SelectedObject<HardwareWinderType>) + CurrentVersion = _db.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); + + ObservablesStaticCollections.Instance.HardwareMotorTypes.Where(x => !CurrentVersion.HardwareMotors.ToList().Exists(y => y.HardwareMotorType.Code == x.Code)).ToList().ForEach(x => + { + CurrentVersion.HardwareMotors.Add(new HardwareMotor() { - var type = (SelectedHardwareObjectType as SelectedObject<HardwareWinderType>).Data; - var hardwareObj = CurrentVersion.HardwareWinders.SingleOrDefault(x => x.HardwareWinderType == type); + HardwareMotorType = _db.HardwareMotorTypes.SingleOrDefault(y => y.Code == x.Code), + }); + }); - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwareWinder() { HardwareWinderType = type }; - CurrentVersion.HardwareWinders.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - else if (SelectedHardwareObjectType is SelectedObject<HardwareSpeedSensorType>) + CurrentVersion.HardwareMotors = CurrentVersion.HardwareMotors.OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection(); + + ObservablesStaticCollections.Instance.HardwareDancerTypes.Where(x => !CurrentVersion.HardwareDancers.ToList().Exists(y => y.HardwareDancerType.Code == x.Code)).ToList().ForEach(x => + { + CurrentVersion.HardwareDancers.Add(new HardwareDancer() { - var type = (SelectedHardwareObjectType as SelectedObject<HardwareSpeedSensorType>).Data; - var hardwareObj = CurrentVersion.HardwareSpeedSensors.SingleOrDefault(x => x.HardwareSpeedSensorType == type); + HardwareDancerType = _db.HardwareDancerTypes.SingleOrDefault(y => y.Code == x.Code) + }); + }); - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwareSpeedSensor() { HardwareSpeedSensorType = type }; - CurrentVersion.HardwareSpeedSensors.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - else if (SelectedHardwareObjectType is SelectedObject<HardwareBlowerType>) + CurrentVersion.HardwareDancers = CurrentVersion.HardwareDancers.OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection(); + + ObservablesStaticCollections.Instance.HardwarePidControlTypes.Where(x => !CurrentVersion.HardwarePidControls.ToList().Exists(y => y.HardwarePidControlType.Code == x.Code)).ToList().ForEach(x => + { + CurrentVersion.HardwarePidControls.Add(new HardwarePidControl() { - var type = (SelectedHardwareObjectType as SelectedObject<HardwareBlowerType>).Data; - var hardwareObj = CurrentVersion.HardwareBlowers.SingleOrDefault(x => x.HardwareBlowerType == type); + HardwarePidControlType = _db.HardwarePidControlTypes.SingleOrDefault(y => y.Code == x.Code) + }); + }); - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwareBlower() { HardwareBlowerType = type }; - CurrentVersion.HardwareBlowers.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - else if (SelectedHardwareObjectType is SelectedObject<HardwareBreakSensorType>) + CurrentVersion.HardwarePidControls = CurrentVersion.HardwarePidControls.OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection(); + + ObservablesStaticCollections.Instance.HardwareWinderTypes.Where(x => !CurrentVersion.HardwareWinders.ToList().Exists(y => y.HardwareWinderType.Code == x.Code)).ToList().ForEach(x => + { + CurrentVersion.HardwareWinders.Add(new HardwareWinder() { - var type = (SelectedHardwareObjectType as SelectedObject<HardwareBreakSensorType>).Data; - var hardwareObj = CurrentVersion.HardwareBreakSensors.SingleOrDefault(x => x.HardwareBreakSensorType == type); + HardwareWinderType = _db.HardwareWinderTypes.SingleOrDefault(y => y.Code == x.Code) + }); + }); - if (hardwareObj != null) - { - SelectedHardwareObject = hardwareObj; - } - else - { - hardwareObj = new HardwareBreakSensor() { HardwareBreakSensorType = type }; - CurrentVersion.HardwareBreakSensors.Add(hardwareObj); - SelectedHardwareObject = hardwareObj; - } - } - } - } + CurrentVersion.HardwareWinders = CurrentVersion.HardwareWinders.OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection(); - private void CreateTemplate(HardwareVersion version) - { - if (version == null) + ObservablesStaticCollections.Instance.HardwareSpeedSensorTypes.Where(x => !CurrentVersion.HardwareSpeedSensors.ToList().Exists(y => y.HardwareSpeedSensorType.Code == x.Code)).ToList().ForEach(x => { - SelectedMotorTypes = new ObservableCollection<HardwareMotorType>(); - SelectedDancerTypes = new ObservableCollection<HardwareDancerType>(); - SelectedPidControlTypes = new ObservableCollection<HardwarePidControlType>(); - SelectedWinderTypes = new ObservableCollection<HardwareWinderType>(); - SelectedSpeedSensorTypes = new ObservableCollection<HardwareSpeedSensorType>(); - SelectedBlowerTypes = new ObservableCollection<HardwareBlowerType>(); - SelectedBreakSensorTypes = new ObservableCollection<HardwareBreakSensorType>(); - } - else + CurrentVersion.HardwareSpeedSensors.Add(new HardwareSpeedSensor() + { + HardwareSpeedSensorType = _db.HardwareSpeedSensorTypes.SingleOrDefault(y => y.Code == x.Code) + }); + }); + + CurrentVersion.HardwareSpeedSensors = CurrentVersion.HardwareSpeedSensors.OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection(); + + ObservablesStaticCollections.Instance.HardwareBlowerTypes.Where(x => !CurrentVersion.HardwareBlowers.ToList().Exists(y => y.HardwareBlowerType.Code == x.Code)).ToList().ForEach(x => { - SelectedMotorTypes = version.HardwareMotors.Select(x => x.HardwareMotorType).ToObservableCollection(); - SelectedDancerTypes = version.HardwareDancers.Select(x => x.HardwareDancerType).ToObservableCollection(); - SelectedPidControlTypes = version.HardwarePidControls.Select(x => x.HardwarePidControlType).ToObservableCollection(); - SelectedWinderTypes = version.HardwareWinders.Select(x => x.HardwareWinderType).ToObservableCollection(); - SelectedSpeedSensorTypes = version.HardwareSpeedSensors.Select(x => x.HardwareSpeedSensorType).ToObservableCollection(); - SelectedBlowerTypes = version.HardwareBlowers.Select(x => x.HardwareBlowerType).ToObservableCollection(); - SelectedBreakSensorTypes = version.HardwareBreakSensors.Select(x => x.HardwareBreakSensorType).ToObservableCollection(); - } + CurrentVersion.HardwareBlowers.Add(new HardwareBlower() + { + HardwareBlowerType = _db.HardwareBlowerTypes.SingleOrDefault(y => y.Code == x.Code) + }); + }); - MotorTypes = new SelectedObjectCollection<HardwareMotorType>(Adapter.HardwareMotorTypes, SelectedMotorTypes); - DancerTypes = new SelectedObjectCollection<HardwareDancerType>(Adapter.HardwareDancerTypes, SelectedDancerTypes); - PidControlTypes = new SelectedObjectCollection<HardwarePidControlType>(Adapter.HardwarePidControlTypes, SelectedPidControlTypes); - WinderTypes = new SelectedObjectCollection<HardwareWinderType>(Adapter.HardwareWinderTypes, SelectedWinderTypes); - SpeedSensorTypes = new SelectedObjectCollection<HardwareSpeedSensorType>(Adapter.HardwareSpeedSensorTypes, SelectedSpeedSensorTypes); - BlowerTypes = new SelectedObjectCollection<HardwareBlowerType>(Adapter.HardwareBlowerTypes, SelectedBlowerTypes); - BreakSensorTypes = new SelectedObjectCollection<HardwareBreakSensorType>(Adapter.HardwareBreakSensorTypes, SelectedBreakSensorTypes); - } + CurrentVersion.HardwareBlowers = CurrentVersion.HardwareBlowers.OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection(); - private void OnSelectedVersionChanged() - { - if (SelectedVersion != null) + ObservablesStaticCollections.Instance.HardwareBreakSensorTypes.Where(x => !CurrentVersion.HardwareBreakSensors.ToList().Exists(y => y.HardwareBreakSensorType.Code == x.Code)).ToList().ForEach(x => { - _isNew = false; - CurrentVersion = SelectedVersion.Clone(); - CreateTemplate(CurrentVersion); - } + CurrentVersion.HardwareBreakSensors.Add(new HardwareBreakSensor() + { + HardwareBreakSensorType = _db.HardwareBreakSensorTypes.SingleOrDefault(y => y.Code == x.Code) + }); + }); - InvalidateRelayCommands(); + CurrentVersion.HardwareBreakSensors = CurrentVersion.HardwareBreakSensors.OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection(); } - private bool CheckCurrentVersionNull() + private async void OnSelectedVersionChanged() { - if (CurrentVersion == null) + if (SelectedVersion != null) { - _notification.ShowInfo("Please select a hardware version before attempting to insert any components."); - return true; + using (_notification.PushTaskItem("Loading hardware version...")) + { + await Task.Factory.StartNew(() => + { + _isNew = false; + var selectedVersion = SelectedVersion; + RefreshVersions(); + var version = _hardwareVersions.SingleOrDefault(X => X.Guid == selectedVersion.Guid); + CreateVersionView(SelectedVersion); + + InvokeUI(() => + { + _selectedVersion = version; + RaisePropertyChanged(nameof(SelectedVersion)); + }); + }); + } } - return false; + InvalidateRelayCommands(); } - private void New() + private async void New() { String name = _notification.ShowTextInput("Enter hardware version name", "Name"); if (!String.IsNullOrWhiteSpace(name)) { - SelectedVersion = null; - CurrentVersion = new HardwareVersion(); - CurrentVersion.Version = Adapter.HardwareVersions.Max(x => x.Version) + 1; - CurrentVersion.Name = name; - CreateTemplate(CurrentVersion); - _isNew = true; - InvalidateRelayCommands(); + using (_notification.PushTaskItem("Creating new machine versions...")) + { + await Task.Factory.StartNew(() => + { + SelectedVersion = null; + CurrentVersion = new HardwareVersion(); + CurrentVersion.Version = HardwareVersions.Max(x => x.Version) + 1; + CurrentVersion.Name = name; + CreateDefaultView(); + + _db.HardwareVersions.Add(CurrentVersion); + _db.SaveChanges(); + + RefreshVersions(); + + InvokeUI(() => + { + _selectedVersion = HardwareVersions.SingleOrDefault(x => x.Guid == CurrentVersion.Guid); + RaisePropertyChanged(nameof(SelectedVersion)); + }); + + _isNew = true; + InvalidateRelayCommands(); + }); + } } } private async void Save() { - if (CurrentVersion != null) + using (_notification.PushTaskItem("Saving hardware version...")) { - using (_notification.PushTaskItem("Saving hardware version...")) + try { await Task.Factory.StartNew(() => { - HardwareVersion realVersion = null; + _db.SaveChanges(); + RefreshVersions(); - if (_isNew) - { - realVersion = CurrentVersion.Clone(); - - 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.HardwareBlowers.ToList().Where(x => !SelectedBlowerTypes.Contains(x.HardwareBlowerType)).ToList().ForEach(x => realVersion.HardwareBlowers.Remove(x)); - realVersion.HardwareBreakSensors.ToList().Where(x => !SelectedBreakSensorTypes.Contains(x.HardwareBreakSensorType)).ToList().ForEach(x => realVersion.HardwareBreakSensors.Remove(x)); - } - else + InvokeUI(() => { - realVersion = Adapter.HardwareVersions.SingleOrDefault(x => x.Guid == SelectedVersion.Guid); - - realVersion.Version = CurrentVersion.Version; - realVersion.Name = CurrentVersion.Name; - - realVersion.HardwareDancers.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - realVersion.HardwareMotors.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - realVersion.HardwarePidControls.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - realVersion.HardwareWinders.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - realVersion.HardwareSpeedSensors.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - realVersion.HardwareBlowers.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - realVersion.HardwareBreakSensors.ToList().ForEach(x => x.DefferedDelete(Adapter.Context)); - - realVersion.HardwareDancers.Clear(); - realVersion.HardwareMotors.Clear(); - realVersion.HardwarePidControls.Clear(); - realVersion.HardwareWinders.Clear(); - realVersion.HardwareSpeedSensors.Clear(); - realVersion.HardwareBlowers.Clear(); - realVersion.HardwareBreakSensors.Clear(); - - foreach (var type in SelectedDancerTypes) - { - var item = CurrentVersion.HardwareDancers.SingleOrDefault(x => x.HardwareDancerType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwareDancers.Add(item); - } - else - { - realVersion.HardwareDancers.Add(new HardwareDancer() - { - HardwareVersionGuid = realVersion.Guid, - HardwareDancerType = type - }); - } - } - - foreach (var type in SelectedMotorTypes) - { - var item = CurrentVersion.HardwareMotors.SingleOrDefault(x => x.HardwareMotorType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwareMotors.Add(item); - } - else - { - realVersion.HardwareMotors.Add(new HardwareMotor() - { - HardwareVersionGuid = realVersion.Guid, - HardwareMotorType = type - }); - } - } - - foreach (var type in SelectedPidControlTypes) - { - var item = CurrentVersion.HardwarePidControls.SingleOrDefault(x => x.HardwarePidControlType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwarePidControls.Add(item); - } - else - { - realVersion.HardwarePidControls.Add(new HardwarePidControl() - { - HardwareVersionGuid = realVersion.Guid, - HardwarePidControlType = type - }); - } - } - - foreach (var type in SelectedWinderTypes) - { - var item = CurrentVersion.HardwareWinders.SingleOrDefault(x => x.HardwareWinderType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwareWinders.Add(item); - } - else - { - realVersion.HardwareWinders.Add(new HardwareWinder() - { - HardwareVersionGuid = realVersion.Guid, - HardwareWinderType = type - }); - } - } - - foreach (var type in SelectedSpeedSensorTypes) - { - var item = CurrentVersion.HardwareSpeedSensors.SingleOrDefault(x => x.HardwareSpeedSensorType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwareSpeedSensors.Add(item); - } - else - { - realVersion.HardwareSpeedSensors.Add(new HardwareSpeedSensor() - { - HardwareVersionGuid = realVersion.Guid, - HardwareSpeedSensorType = type - }); - } - } - - foreach (var type in SelectedBlowerTypes) - { - var item = CurrentVersion.HardwareBlowers.SingleOrDefault(x => x.HardwareBlowerType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwareBlowers.Add(item); - } - else - { - realVersion.HardwareBlowers.Add(new HardwareBlower() - { - HardwareVersionGuid = realVersion.Guid, - HardwareBlowerType = type - }); - } - } - - foreach (var type in SelectedBreakSensorTypes) - { - var item = CurrentVersion.HardwareBreakSensors.SingleOrDefault(x => x.HardwareBreakSensorType == type); - if (item != null) - { - item.HardwareVersionGuid = realVersion.Guid; - realVersion.HardwareBreakSensors.Add(item); - } - else - { - realVersion.HardwareBreakSensors.Add(new HardwareBreakSensor() - { - HardwareVersionGuid = realVersion.Guid, - HardwareBreakSensorType = type - }); - } - } - } - - - - if (_isNew) - { - Adapter.Context.HardwareVersions.Add(realVersion); - } - - realVersion.Save(Adapter.Context); - - SelectedVersion = Adapter.HardwareVersions.SingleOrDefault(x => x.Guid == realVersion.Guid); + SelectedVersion = HardwareVersions.SingleOrDefault(x => x.Guid == CurrentVersion.Guid); + }); }); } + catch (Exception ex) + { + LogManager.Log(ex, "Could not save hardware version."); + _notification.ShowError($"An error occurred while trying to save this hardware version.\n{ex.Message}"); + } } } @@ -615,55 +303,59 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels { using (_notification.PushTaskItem("Cloning hardware configuration...")) { - await Task.Factory.StartNew(() => + try { - 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.HardwareBlowers.ToList().Where(x => !SelectedBlowerTypes.Contains(x.HardwareBlowerType)).ToList().ForEach(x => realVersion.HardwareBlowers.Remove(x)); - realVersion.HardwareBreakSensors.ToList().Where(x => !SelectedBreakSensorTypes.Contains(x.HardwareBreakSensorType)).ToList().ForEach(x => realVersion.HardwareBreakSensors.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.HardwareBlowers.ToList().ForEach(x => x.HardwareVersionGuid = realVersion.Guid); - realVersion.HardwareBreakSensors.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); - realVersion.HardwareBlowers.ToList().ForEach(x => x.HardwareVersion = realVersion); - realVersion.HardwareBreakSensors.ToList().ForEach(x => x.HardwareVersion = realVersion); - - Adapter.Context.HardwareVersions.Add(realVersion); - realVersion.Save(Adapter.Context); + await Task.Factory.StartNew(() => + { + var cloned = CurrentVersion.Clone(); + cloned.Name = name; + cloned.Version = HardwareVersions.Max(x => x.Version) + 1; + _db.HardwareVersions.Add(cloned); + _db.SaveChanges(); + RefreshVersions(); - SelectedVersion = Adapter.HardwareVersions.SingleOrDefault(x => x.Guid == realVersion.Guid); - }); + InvokeUI(() => + { + SelectedVersion = HardwareVersions.SingleOrDefault(x => x.Guid == cloned.Guid); + }); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not clone hardware version."); + _notification.ShowError($"An error occurred while trying to clone this hardware version.\n{ex.Message}"); + } } } } + } - private void Delete() + private async void Delete() { if (_notification.ShowQuestion("Are you sure you want to delete this hardware version?")) { using (_notification.PushTaskItem("Deleting hardware version...")) { - SelectedVersion.DeleteAsync(Adapter.Context); - SelectedVersion = null; - CurrentVersion = null; + try + { + await CurrentVersion.DeleteCascadeAsync(_db); + + await Task.Factory.StartNew(() => + { + SelectedVersion = null; + RefreshVersions(); + + CurrentVersion = new HardwareVersion(); + CreateDefaultView(); + InvalidateRelayCommands(); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not delete hardware version."); + _notification.ShowError($"An error occurred while trying to delete this hardware version.\n{ex.Message}"); + } } } } 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 86e0da5b5..8df9e465d 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 @@ -14,7 +14,7 @@ xmlns:observables="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:global="clr-namespace:Tango.MachineStudio.HardwareDesigner" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="2000" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> <UserControl.Resources> <converters:DoubleToIntConverter x:Key="DoubleToIntConverter" /> @@ -57,7 +57,7 @@ <TextBlock FontSize="30" FontStyle="Italic" VerticalAlignment="Center" Margin="50 10 10 0" Foreground="Silver" FontWeight="Bold">HARDWARE DESIGNER</TextBlock> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10 10 0 0"> <materialDesign:PackIcon Kind="Pencil" Width="32" Height="32" Foreground="Silver" /> - <ComboBox ItemsSource="{Binding Adapter.HardwareVersions}" SelectedItem="{Binding SelectedVersion}" Width="300" FontSize="16" FontWeight="Bold" Margin="5 0 0 0" materialDesign:HintAssist.Hint="Hardware Version"> + <ComboBox ItemsSource="{Binding HardwareVersions}" SelectedItem="{Binding SelectedVersion}" Width="300" FontSize="16" FontWeight="Bold" Margin="5 0 0 0" materialDesign:HintAssist.Hint="Hardware Version"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock><Run Text="{Binding Name}"></Run> <Run></Run> <Run Foreground="Gray" FontSize="14">v</Run><Run Foreground="Gray" FontSize="14" Text="{Binding Version}"></Run></TextBlock> @@ -78,16 +78,16 @@ <Image VerticalAlignment="Center" Source="../Images/engine.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">MOTORS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding MotorTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwareMotors}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwareMotorType}"> + <DataTemplate DataType="{x:Type entities:HardwareMotor}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwareMotorType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwareMotor}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -104,8 +104,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwareMotorType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> @@ -116,16 +116,16 @@ <Image VerticalAlignment="Center" Source="../Images/compass.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">DANCERS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding DancerTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwareDancers}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwareDancerType}"> + <DataTemplate DataType="{x:Type entities:HardwareDancer}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwareDancerType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwareDancer}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -142,8 +142,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwareDancerType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> @@ -154,16 +154,16 @@ <Image VerticalAlignment="Center" Source="../Images/balance.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">PID CONTROLS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding PidControlTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwarePidControls}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwarePidControlType}"> + <DataTemplate DataType="{x:Type entities:HardwarePidControl}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwarePidControlType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwarePidControl}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -180,8 +180,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwarePidControlType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> @@ -192,16 +192,16 @@ <Image VerticalAlignment="Center" Source="../Images/thread.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">WINDERS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding WinderTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwareWinders}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwareWinderType}"> + <DataTemplate DataType="{x:Type entities:HardwareWinder}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwareWinderType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwareWinder}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -218,8 +218,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwareWinderType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> @@ -230,16 +230,16 @@ <Image VerticalAlignment="Center" Source="../Images/speed.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">SPEED SENSORS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding SpeedSensorTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwareSpeedSensors}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwareSpeedSensorType}"> + <DataTemplate DataType="{x:Type entities:HardwareSpeedSensor}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwareSpeedSensorType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwareSpeedSensor}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -256,8 +256,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwareSpeedSensorType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> @@ -268,16 +268,16 @@ <Image VerticalAlignment="Center" Source="../Images/blower.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">BLOWERS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding BlowerTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwareBlowers}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwareBlowerType}"> + <DataTemplate DataType="{x:Type entities:HardwareBlower}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwareBlowerType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwareBlower}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -294,8 +294,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwareBlowerType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> @@ -306,16 +306,16 @@ <Image VerticalAlignment="Center" Source="../Images/break.png" Width="32"></Image> <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold">BREAK SENSORS</TextBlock> </StackPanel> - <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding BreakSensorTypes}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObjectType}"> + <ListBox Style="{StaticResource typesList}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentVersion.HardwareBreakSensors}" Margin="60 15" SelectedItem="{Binding SelectedHardwareObject}"> <ListBox.ItemTemplate> - <DataTemplate DataType="{x:Type entities:HardwareBreakSensorType}"> + <DataTemplate DataType="{x:Type entities:HardwareBreakSensor}"> <DockPanel> <Button DockPanel.Dock="Right" Cursor="Hand" Foreground="DimGray" Height="20" FontSize="10" ToolTip="Copy this item parameters to the selected item" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CopyParametersCommand}" CommandParameter="{Binding}"> <Button.Style> <Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}"> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObjectType.Data.ObjectType.BaseType}" Value="{x:Type entities:HardwareBreakSensorType}"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SelectedHardwareObject.ObjectType.BaseType}" Value="{x:Type entities:HardwareBreakSensor}"> <Setter Property="Visibility" Value="Visible"></Setter> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> @@ -332,8 +332,8 @@ </Button.Content> </Button> <StackPanel Orientation="Horizontal"> - <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"></CheckBox> - <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + <CheckBox VerticalAlignment="Center" IsChecked="{Binding Active}"></CheckBox> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding HardwareBreakSensorType.Description}"></TextBlock> </StackPanel> </DockPanel> </DataTemplate> |
