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.BL; using Tango.BL.Entities; using Tango.SharedUI.Components; using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { /// /// Represents a motors group item. /// /// [TechItem(7, true)] public class MotorGroupItem : TechItem { /// /// Occurs when the user has pressed/released on of the item actions. /// public event EventHandler ActionExecuted; /// /// Occurs when motor homing has completed. /// public event EventHandler HomingCompleted; private SelectedObjectCollection _selectedMotors; /// /// Gets or sets the selected db tech motors. /// [XmlIgnore] public SelectedObjectCollection SelectedMotors { get { return _selectedMotors; } set { _selectedMotors = value; RaisePropertyChangedAuto(); } } private ObservableCollection _techMotors; /// /// Gets or sets the available db tech motors. /// [XmlIgnore] public ObservableCollection TechMotors { get { return _techMotors; } set { _techMotors = value; RaisePropertyChangedAuto(); SetSelectedMotors(); } } /// /// Sets the selected motors. /// private void SetSelectedMotors() { if (TechMotors != null) { SelectedMotors = new SelectedObjectCollection(ObservablesStaticCollections.Instance.HardwareMotorTypes.ToObservableCollection(), TechMotors); } } /// /// Gets or sets the selected tech items motors guids. /// public List ItemsGuids { get; set; } private String _groupName; /// /// Gets or sets the name of the group. /// public String GroupName { get { return _groupName; } set { _groupName = value; RaisePropertyChangedAuto(); TechName = value; } } private bool _isHoming; /// /// Gets or sets a value indicating whether this motor group is currently homing. /// [XmlIgnore] public bool IsHoming { get { return _isHoming; } set { _isHoming = value; RaisePropertyChangedAuto(); } } private bool _isHomingCompleted; /// /// Gets or sets a value indicating whether this group homing has completed. /// [XmlIgnore] public bool IsHomingCompleted { get { return _isHomingCompleted; } set { _isHomingCompleted = value; RaisePropertyChangedAuto(); if (value) { HomingCompleted?.Invoke(this, new EventArgs()); } } } private double _homingProgress; /// /// Gets or sets the current homing progress. /// [XmlIgnore] public double HomingProgress { get { return _homingProgress; } set { _homingProgress = value; RaisePropertyChangedAuto(); } } private double _homingMaximumProgress; /// /// Gets or sets the homing maximum progress. /// [XmlIgnore] public double HomingMaximumProgress { get { return _homingMaximumProgress; } set { _homingMaximumProgress = value; RaisePropertyChangedAuto(); } } private double _speed; /// /// Gets or sets the motors speed. /// public double Speed { get { return _speed; } set { _speed = value; RaisePropertyChangedAuto(); } } /// /// Initializes a new instance of the class. /// 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"; } /// /// Initializes a new instance of the class. /// /// does not matter. public MotorGroupItem(object dummyConstructor) : this() { } /// /// Clones this instance. /// /// 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; } /// /// Raises the event with the specified action. /// /// The action. public void RaiseAction(MotorActionType action) { ActionExecuted?.Invoke(this, action); } } }