using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Xml.Serialization; using Tango.Core.Commands; using Tango.BL.Entities; using Tango.SharedUI.Helpers; using System.Collections.ObjectModel; namespace Tango.MachineStudio.Technician.TechItems { /// /// Represents a motor controller item. /// /// [TechItem(6, true)] public class MotorItem : TechItem { /// /// Occurs when the user has pressed/released on of the item actions. /// public event EventHandler ActionExecuted; private static List _motorConfigurations; /// /// Gets or sets the motor configurations. /// public static List MotorConfigurations { get { return _motorConfigurations; } set { _motorConfigurations = value; } } static MotorItem() { MotorConfigurations = new List(); foreach (var motorType in BL.ObservablesStaticCollections.Instance.HardwareMotorTypes) { MotorConfigurations.Add(new HardwareMotor() { HardwareMotorType = motorType }); } } /// /// Occurs when motor homing has completed. /// public event EventHandler HomingCompleted; private HardwareMotorType _hardwareMotorType; /// /// Gets or sets the db tech motor. /// [XmlIgnore] public HardwareMotorType HardwareMotorType { get { return _hardwareMotorType; } set { _hardwareMotorType = value; RaisePropertyChangedAuto(); TechName = _hardwareMotorType != null ? _hardwareMotorType.Description : null; ItemGuid = value != null ? value.Guid : null; if (_hardwareMotorType != null) { HardwareMotor = MotorConfigurations.SingleOrDefault(x => x.HardwareMotorType == _hardwareMotorType); } } } private HardwareMotor _hardwareMotor; /// /// Gets or sets the hardware motor. /// [XmlIgnore] public HardwareMotor HardwareMotor { get { return _hardwareMotor; } set { _hardwareMotor = value; RaisePropertyChangedAuto(); } } private bool _isHoming; /// /// Gets or sets a value indicating whether the motor is currently homing. /// [XmlIgnore] public bool IsHoming { get { return _isHoming; } set { _isHoming = value; RaisePropertyChangedAuto(); } } private bool _isHomingCompleted; /// /// Gets or sets a value indicating whether the motor 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 motor speed. /// public double Speed { get { return _speed; } set { _speed = value; RaisePropertyChangedAuto(); } } /// /// Initializes a new instance of the class. /// public MotorItem() : base() { Name = "Motor"; Description = "Motor Controller"; Speed = 500; Image = ResourceHelper.GetImageFromResources("Images/engine.png"); Color = Colors.White; HardwareMotor = new HardwareMotor(); } /// /// Initializes a new instance of the class. /// /// The tech motor. public MotorItem(HardwareMotorType techMotor) : this() { HardwareMotorType = techMotor; } /// /// Clones this instance. /// /// public override TechItem Clone() { MotorItem cloned = base.Clone() as MotorItem; cloned.HardwareMotorType = HardwareMotorType; cloned.Speed = Speed; return cloned; } /// /// Raises the event with the specified action. /// /// The action. public void RaiseAction(MotorActionType action) { ActionExecuted?.Invoke(this, action); } } }