From 2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2 Mon Sep 17 00:00:00 2001 From: Roy Date: Mon, 12 Feb 2018 09:40:08 +0200 Subject: Implemented motor group. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes Software/Graphics/motor-group.gif | Bin 0 -> 56511 bytes Software/Graphics/motor-group.png | Bin 0 -> 2215 bytes .../Editors/MotorGroupElementEditor.xaml | 270 +++++++++++++++++++++ .../Editors/MotorGroupElementEditor.xaml.cs | 177 ++++++++++++++ .../Images/motor-group.gif | Bin 0 -> 56511 bytes .../Images/motor-group.png | Bin 0 -> 2215 bytes .../PropertiesTemplates/MotorGroupTemplate.xaml | 54 +++++ .../PropertiesTemplates/MotorGroupTemplate.xaml.cs | 31 +++ .../Tango.MachineStudio.Technician.csproj | 21 ++ .../TechItems/MotorGroupItem.cs | 158 ++++++++++++ .../TechItems/TechItem.cs | 1 + .../ViewModels/MachineTechViewVM.cs | 103 +++++++- .../Views/MachineTechView.xaml | 3 + .../Tango.Editors/ElementsEditor.xaml.cs | 5 +- .../Tango.SharedUI/Components/SelectedObject.cs | 45 ++++ .../Components/SelectedObjectCollection.cs | 46 ++++ .../Tango.SharedUI/Tango.SharedUI.csproj | 2 + 19 files changed, 914 insertions(+), 2 deletions(-) create mode 100644 Software/Graphics/motor-group.gif create mode 100644 Software/Graphics/motor-group.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs create mode 100644 Software/Visual_Studio/Tango.SharedUI/Components/SelectedObject.cs create mode 100644 Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs (limited to 'Software') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index c9638a21b..d21451572 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 73277102d..fdfc48efc 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Graphics/motor-group.gif b/Software/Graphics/motor-group.gif new file mode 100644 index 000000000..682a20da7 Binary files /dev/null and b/Software/Graphics/motor-group.gif differ diff --git a/Software/Graphics/motor-group.png b/Software/Graphics/motor-group.png new file mode 100644 index 000000000..0dca92823 Binary files /dev/null and b/Software/Graphics/motor-group.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml new file mode 100644 index 000000000..64ed5bb43 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs new file mode 100644 index 000000000..4e29296b0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Editors; +using Tango.Integration.Observables; +using Tango.MachineStudio.Technician.TechItems; +using Tango.SharedUI.Components; + +namespace Tango.MachineStudio.Technician.Editors +{ + [ContentProperty("InnerContent")] + public partial class MotorGroupElementEditor : ElementEditor + { + /// + /// Initializes a new instance of the class. + /// + public MotorGroupElementEditor() + : base() + { + InitializeComponent(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The framework element. + public MotorGroupElementEditor(MotorGroupItem motorGroupItem) + : this() + { + MotorGroupItem = motorGroupItem; + DataContext = MotorGroupItem; + } + + /// + /// Initializes a new instance of the class. + /// + /// The framework element. + /// The bounds. + public MotorGroupElementEditor(MotorGroupItem monitorItem, Rect bounds) + : this(monitorItem) + { + Left = bounds.Left; + Top = bounds.Top; + Width = bounds.Width; + Height = bounds.Height; + } + + private MotorGroupItem _monitorItem; + + public MotorGroupItem MotorGroupItem + { + get { return _monitorItem; } + set + { + _monitorItem = value; RaisePropertyChanged(nameof(MotorGroupItem)); + + if (_monitorItem != null) + { + _monitorItem.HomingCompleted -= _monitorItem_HomingCompleted; + _monitorItem.HomingCompleted += _monitorItem_HomingCompleted; + } + } + } + + private void _monitorItem_HomingCompleted(object sender, EventArgs e) + { + StopAnimation(); + } + + + /// + /// Clones this instance. + /// + /// + public override IElementEditor Clone() + { + try + { + var clonedItem = MotorGroupItem.Clone() as MotorGroupItem; + MotorGroupElementEditor cloned = new MotorGroupElementEditor(clonedItem); + cloned.Top = Top; + cloned.Left = Left; + cloned.Width = Width; + cloned.Height = Height; + cloned.Angle = Angle; + return cloned; + } + catch (Exception ex) + { + throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex); + } + } + + /// + /// Gets the hosted element. + /// + [ParameterIgnore] + public override Object HostedElement + { + get { return MotorGroupItem; } + } + + private void OnForwardPressed(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.ForwardPressed); + AnimateRight(); + } + + private void OnForwardReleased(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.ForwardReleased); + StopAnimation(); + } + + private void OnBackwardPressed(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.BackwardPressed); + AnimateLeft(); + } + + private void OnBackwardReleased(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.BackwardReleased); + StopAnimation(); + } + + private void OnHomingStarted(object sender, RoutedEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.HomingStarted); + AnimateLeft(); + } + + private void OnHomingStopped(object sender, RoutedEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.HomingStopped); + StopAnimation(); + } + + private void AnimateRight() + { + WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Play(); + } + + private void AnimateLeft() + { + WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Play(); + } + + public void StopAnimation() + { + this.Dispatcher.Invoke(() => + { + WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Pause(); + }); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif new file mode 100644 index 000000000..682a20da7 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png new file mode 100644 index 000000000..0dca92823 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml new file mode 100644 index 000000000..4210d12a6 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + Selected Motors + + + + + + + + + + + + + + Motors + + + + Speed + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs new file mode 100644 index 000000000..8d2c3df8a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Integration.Observables; +using Tango.MachineStudio.Technician.TechItems; +using Tango.SharedUI.Components; + +namespace Tango.MachineStudio.Technician.PropertiesTemplates +{ + /// + /// Interaction logic for MonitorTemplate.xaml + /// + public partial class MotorGroupTemplate : UserControl + { + public MotorGroupTemplate() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index 2b90207b0..e8b14e277 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -106,6 +106,9 @@ IOElementEditor.xaml + + MotorGroupElementEditor.xaml + ThreadMotionElementEditor.xaml @@ -135,6 +138,9 @@ DispenserTemplate.xaml + + MotorGroupTemplate.xaml + ThreadMotionTemplate.xaml @@ -156,6 +162,7 @@ + @@ -193,6 +200,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -229,6 +240,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -414,5 +429,11 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs new file mode 100644 index 000000000..35aae5cd7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using System.Xml.Serialization; +using Tango.Integration.Observables; +using Tango.SharedUI.Components; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.Technician.TechItems +{ + public class MotorGroupItem : TechItem + { + public event EventHandler ActionExecuted; + public event EventHandler HomingCompleted; + + private SelectedObjectCollection _selectedMotors; + [XmlIgnore] + public SelectedObjectCollection SelectedMotors + { + get { return _selectedMotors; } + set { _selectedMotors = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection _techMotors; + [XmlIgnore] + public ObservableCollection TechMotors + { + get { return _techMotors; } + set { _techMotors = value; RaisePropertyChangedAuto(); SetSelectedMotors(); } + } + + private void SetSelectedMotors() + { + if (TechMotors != null) + { + SelectedMotors = new SelectedObjectCollection(ObservablesEntitiesAdapter.Instance.TechMotors.ToObservableCollection(), TechMotors); + } + } + + public List ItemsGuids { get; set; } + + private String _groupName; + + public String GroupName + { + get { return _groupName; } + set { _groupName = value; RaisePropertyChangedAuto(); TechName = value; } + } + + + private bool _isHoming; + [XmlIgnore] + public bool IsHoming + { + get { return _isHoming; } + set + { + _isHoming = value; + RaisePropertyChangedAuto(); + } + } + + private bool _isHomingCompleted; + + public bool IsHomingCompleted + { + get { return _isHomingCompleted; } + set + { + _isHomingCompleted = value; + RaisePropertyChangedAuto(); + + if (value) + { + HomingCompleted?.Invoke(this, new EventArgs()); + } + } + } + + private double _homingProgress; + [XmlIgnore] + public double HomingProgress + { + get { return _homingProgress; } + set + { + _homingProgress = value; + RaisePropertyChangedAuto(); + } + } + + private double _homingMaximumProgress; + [XmlIgnore] + public double HomingMaximumProgress + { + get { return _homingMaximumProgress; } + set { _homingMaximumProgress = value; RaisePropertyChangedAuto(); } + } + + private bool _isForwardPressed; + [XmlIgnore] + public bool IsForwardPressed + { + get { return _isForwardPressed; } + set { _isForwardPressed = value; RaisePropertyChangedAuto(); } + } + + private bool _isBackwardPressed; + [XmlIgnore] + public bool IsBackwardPressed + { + get { return _isBackwardPressed; } + set { _isBackwardPressed = value; RaisePropertyChangedAuto(); } + } + + private double _speed; + public double Speed + { + get { return _speed; } + set { _speed = value; RaisePropertyChangedAuto(); } + } + + public MotorGroupItem() : base() + { + ItemsGuids = new List(); + TechMotors = new ObservableCollection(); + Name = "Motor Group"; + Description = "Motor Group Controller"; + Image = ResourceHelper.GetImageFromResources("Images/motor-group.png"); + Color = Colors.White; + GroupName = "Motor Group"; + } + + public MotorGroupItem(object dummyConstructor) : this() + { + + } + + public override TechItem Clone() + { + MotorGroupItem cloned = base.Clone() as MotorGroupItem; + cloned.TechMotors = new ObservableCollection(TechMotors); + cloned.Speed = Speed; + cloned.ItemsGuids = ItemsGuids; + cloned.TechMotors = cloned.TechMotors.ToObservableCollection(); + return cloned; + } + + public void RaiseAction(MotorActionType action) + { + ActionExecuted?.Invoke(this, action); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs index 8361b6ef7..a7b5ae5b9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs @@ -21,6 +21,7 @@ namespace Tango.MachineStudio.Technician.TechItems [XmlInclude(typeof(MultiGraphItem))] [XmlInclude(typeof(SingleGraphItem))] [XmlInclude(typeof(ThreadMotionItem))] + [XmlInclude(typeof(MotorGroupItem))] public abstract class TechItem : ExtendedObject { public TechItem() 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 d87652e42..1b0ee0a56 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 @@ -362,9 +362,14 @@ namespace Tango.MachineStudio.Technician.ViewModels } else if (item is ThreadMotionItem) { - var editor = CreateElement(bounds, 0); + var editor = CreateElement(bounds, null); InitThreadMotionItem(editor.ThreadMotionItem); } + else if (item is MotorGroupItem) + { + var editor = CreateElement(bounds, null); + InitMotorGroupItem(editor.MotorGroupItem); + } } private Editor CreateElement(Rect bounds, Value value) where Editor : IElementEditor where Tech : TechItem @@ -428,6 +433,11 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement(item); InitThreadMotionItem(editor.ThreadMotionItem); } + else if (item is MotorGroupItem) + { + var editor = CreateElement(item); + InitMotorGroupItem(editor.MotorGroupItem); + } } public void OnElementsRemoved(List elements) @@ -502,6 +512,16 @@ namespace Tango.MachineStudio.Technician.ViewModels var ioItem = element.HostedElement as IOItem; InitIOItem(ioItem); } + else if (element is ThreadMotionItem) + { + var threadMotionItem = element.HostedElement as ThreadMotionItem; + InitThreadMotionItem(threadMotionItem); + } + else if (element is MotorGroupItem) + { + var motorGroupItem = element.HostedElement as MotorGroupItem; + InitMotorGroupItem(motorGroupItem); + } } } @@ -722,6 +742,76 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + private void InitMotorGroupItem(MotorGroupItem item) + { + item.ActionExecuted += async (x, action) => + { + if (action == MotorActionType.ForwardPressed) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Forward, + }))); + } + else if (action == MotorActionType.ForwardReleased) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + else if (action == MotorActionType.BackwardPressed) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Backward, + }))); + } + else if (action == MotorActionType.BackwardReleased) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + //else if (action == MotorActionType.HomingStarted) + //{ + // item.HomingProgress = 0; + // item.IsHoming = true; + // item.IsHomingCompleted = false; + + // MachineOperator.StartMotorHoming(new MotorHomingRequest() + // { + // Code = item.TechMotor.Code + // }) + // .Subscribe((response) => + // { + + // item.HomingMaximumProgress = response.Message.MaxProgress; + // item.HomingProgress = response.Message.Progress; + + // }, () => + // { + + // item.IsHoming = false; + // item.IsHomingCompleted = true; + + // }); + //} + //else if (action == MotorActionType.HomingStopped) + //{ + // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + // { + // Code = item.TechMotor.Code, + // }); + + // item.IsHoming = false; + //} + }; + } + #endregion #region Public Methods @@ -754,6 +844,11 @@ namespace Tango.MachineStudio.Technician.ViewModels foreach (var item in project.Items) { + if (item is MotorGroupItem) + { + (item as MotorGroupItem).TechMotors = ObservablesEntitiesAdapter.Instance.TechMotors.Where(x => (item as MotorGroupItem).ItemsGuids.Contains(x.Guid)).ToObservableCollection(); + } + AddTechItem(item); } } @@ -799,6 +894,12 @@ namespace Tango.MachineStudio.Technician.ViewModels foreach (var element in Elements) { + if (element.HostedElement is MotorGroupItem) + { + var group = element.HostedElement as MotorGroupItem; + group.ItemsGuids = group.TechMotors.Select(x => x.Guid).ToList(); + } + (element.HostedElement as TechItem).SetBounds(element.GetBounds()); project.Items.Add(element.HostedElement as TechItem); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml index 7042be696..1658b97d8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml @@ -355,6 +355,9 @@ + + + diff --git a/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs b/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs index cf602cac7..abd5e5929 100644 --- a/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs +++ b/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs @@ -446,7 +446,10 @@ namespace Tango.Editors { if (BringToFrontOnSelect) { - Canvas.SetZIndex(SelectedElement as UIElement, Elements.Max(x => Canvas.GetZIndex(x as UIElement) + 1)); + if (Elements.Count > 0) + { + Canvas.SetZIndex(SelectedElement as UIElement, Elements.Max(x => Canvas.GetZIndex(x as UIElement) + 1)); + } } SetElementSelection(SelectedElement, true); diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObject.cs b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObject.cs new file mode 100644 index 000000000..f91e93b5a --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObject.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.SharedUI.Components +{ + public class SelectedObject : ExtendedObject + { + public event EventHandler IsSelectedChanged; + + private bool _isSelected; + + public bool IsSelected + { + get { return _isSelected; } + set { _isSelected = value; RaisePropertyChangedAuto(); IsSelectedChanged?.Invoke(this, new EventArgs()); } + } + + private T _data; + + public T Data + { + get { return _data; } + set { _data = value; RaisePropertyChangedAuto(); } + } + + public SelectedObject() + { + + } + + public SelectedObject(T data) : this() + { + Data = data; + } + + public SelectedObject(T data, bool selected) : this(data) + { + IsSelected = selected; + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs new file mode 100644 index 000000000..c9a1a6293 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.SharedUI.Components +{ + public class SelectedObjectCollection : ObservableCollection> + { + public ObservableCollection Source { get; set; } + public ObservableCollection SynchedSource { get; set; } + + public SelectedObjectCollection(ObservableCollection source, ObservableCollection synchedSource) + { + SynchedSource = synchedSource; + Source = source; + + foreach (var item in source) + { + var selectedItem = new SelectedObject(item, synchedSource.Contains(item)); + this.Add(selectedItem); + selectedItem.IsSelectedChanged += SelectedItem_IsSelectedChanged; + } + } + + private void SelectedItem_IsSelectedChanged(object sender, EventArgs e) + { + SelectedObject item = sender as SelectedObject; + + if (item.IsSelected) + { + if (!SynchedSource.Contains(item.Data)) + { + SynchedSource.Add(item.Data); + } + } + else + { + SynchedSource.Remove(item.Data); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index b70d3143d..57bd768db 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -72,6 +72,8 @@ GlobalVersionInfo.cs + + HiveControl.xaml -- cgit v1.3.1