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.BL.Entities;
using Tango.Core.Commands;
using Tango.SharedUI.Helpers;
namespace Tango.MachineStudio.Technician.TechItems
{
///
/// Represents a single component value controller and monitor.
///
///
[TechItem(10, true)]
public class ControllerItem : TechItem
{
public event EventHandler SetCommandClicked;
private TechController _techController;
///
/// Gets or sets the DB controller item.
///
[XmlIgnore]
public TechController TechController
{
get { return _techController; }
set
{
_techController = value;
RaisePropertyChangedAuto();
TechName = _techController != null ? _techController.Description : null; ItemGuid = value != null ? value.Guid : null;
if (_techController != null && !IsSetToDefault)
{
OptimalRangeMinimum = _techController.Min;
OptimalRangeMaximum = _techController.Min + ((_techController.Max - _techController.Min) * 0.7d);
IsSetToDefault = true;
}
}
}
private double _value;
///
/// Gets or sets the component value.
///
[XmlIgnore]
public double Value
{
get { return _value; }
set
{
_value = value; RaisePropertyChangedAuto();
}
}
private int _updateInterval;
///
/// Gets or sets the update interval.
///
public int UpdateInterval
{
get { return _updateInterval; }
set { _updateInterval = value; RaisePropertyChangedAuto(); }
}
///
/// Gets or sets the last update time.
///
[XmlIgnore]
public DateTime LastUpdateTime { get; set; }
private double _effectiveValue;
///
/// Gets or sets the effective value received from the embedded device.
///
[XmlIgnore]
public double EffectiveValue
{
get { return _effectiveValue; }
set
{
LastUpdateTime = DateTime.Now;
if (_effectiveValue != value)
{
_effectiveValue = value;
RaisePropertyChangedAuto();
}
}
}
private double _optimalRangeMinimum;
///
/// Gets or sets the optimal range.
///
public double OptimalRangeMinimum
{
get { return _optimalRangeMinimum; }
set
{
_optimalRangeMinimum = value;
RaisePropertyChangedAuto();
}
}
private double _optimalRangeMaximum;
public double OptimalRangeMaximum
{
get { return _optimalRangeMaximum; }
set { _optimalRangeMaximum = value; RaisePropertyChangedAuto(); }
}
public bool IsSetToDefault { get; set; }
///
/// Gets or sets the set command.
///
[XmlIgnore]
public RelayCommand SetCommand { get; set; }
///
/// Initializes a new instance of the class.
///
public ControllerItem() : base()
{
Name = "Value Controller";
Description = "Single component value controller";
Image = ResourceHelper.GetImageFromResources("Images/controller.png");
Color = Colors.DodgerBlue;
LastUpdateTime = DateTime.Now;
UpdateInterval = 10;
SetCommand = new RelayCommand(() => { SetCommandClicked?.Invoke(this, new EventArgs()); });
}
///
/// Initializes a new instance of the class.
///
/// The db tech controller.
public ControllerItem(TechController techController) : this()
{
TechController = techController;
}
///
/// Clones this instance.
///
///
public override TechItem Clone()
{
ControllerItem cloned = base.Clone() as ControllerItem;
cloned.TechController = TechController;
cloned.OptimalRangeMinimum = OptimalRangeMinimum;
cloned.OptimalRangeMaximum = OptimalRangeMaximum;
cloned.IsSetToDefault = IsSetToDefault;
return cloned;
}
}
}