init
This commit is contained in:
@@ -0,0 +1,257 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using DTS.Common.Events.RegionOfInterest;
|
||||
using DTS.Common.Events.RegionOfInterest.RegionOfInterestChannels;
|
||||
using DTS.Common.Interface.RegionOfInterest;
|
||||
using Microsoft.Practices.Prism.Events;
|
||||
using Microsoft.Practices.ServiceLocation;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
|
||||
namespace DTS.Common.Classes.TestSetups
|
||||
{
|
||||
[Serializable]
|
||||
public class RegionOfInterest : IRegionOfInterest
|
||||
{
|
||||
/// <summary>
|
||||
/// holds whether a test setup is currently deserializing ROIs or not
|
||||
/// this was necessary to prevent deserialization from firing property changed notifications on construction
|
||||
/// 27034 ROI channel assignments are not saved when modifying and clicking save in test setup
|
||||
/// </summary>
|
||||
public static bool Deserializing { get; set; } = false;
|
||||
public RegionOfInterest()
|
||||
{
|
||||
Suffix = string.Empty;
|
||||
_start = double.NegativeInfinity;
|
||||
_end = double.PositiveInfinity;
|
||||
IsEnabled = true;
|
||||
IsDefault = true;
|
||||
_channelNames = null;
|
||||
}
|
||||
|
||||
public RegionOfInterest(bool isDefault = false)
|
||||
: this()
|
||||
{
|
||||
IsDefault = isDefault;
|
||||
}
|
||||
public RegionOfInterest(string suffix = "", bool isDefault = false, double start = -1D, double end = 1D)
|
||||
: this(isDefault)
|
||||
{
|
||||
Suffix = suffix;
|
||||
_start = start;
|
||||
_end = end;
|
||||
_channelNames = new string[0];
|
||||
}
|
||||
|
||||
private string _suffix = string.Empty;
|
||||
public string Suffix
|
||||
{
|
||||
get => _suffix;
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value) && !(value.StartsWith("_") && string.IsNullOrWhiteSpace(value.Substring(1))))
|
||||
{
|
||||
_suffix = value.StartsWith("_") ? value : "_" + value;
|
||||
}
|
||||
OnPropertyChanged("Suffix");
|
||||
}
|
||||
}
|
||||
|
||||
private double _start = double.MinValue;
|
||||
public double Start
|
||||
{
|
||||
get => _start;
|
||||
set
|
||||
{
|
||||
if (value >= End)
|
||||
{
|
||||
value = End - 0.01;
|
||||
}
|
||||
|
||||
if (value != _start)
|
||||
{
|
||||
_start = value;
|
||||
OnPropertyChanged("Start");
|
||||
NotifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _end = double.MaxValue;
|
||||
public double End
|
||||
{
|
||||
get => _end;
|
||||
set
|
||||
{
|
||||
if (value <= Start)
|
||||
{
|
||||
value = Start + 0.01;
|
||||
}
|
||||
|
||||
if (value != _end)
|
||||
{
|
||||
_end = value;
|
||||
OnPropertyChanged("End");
|
||||
NotifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// notifies any consumers that ROI has changed (if it should notify)
|
||||
/// 27034 ROI channel assignments are not saved when modifying and clicking save in test setup
|
||||
/// </summary>
|
||||
private void NotifyChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Deserializing) { return; }
|
||||
if (null == ServiceLocator.Current) { return; }
|
||||
var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
|
||||
eventAggregator.GetEvent<RegionOfInterestChangedEvent>().Publish(this);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
private bool _isEnabled = true;
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set { _isEnabled = value; OnPropertyChanged("IsEnabled"); }
|
||||
}
|
||||
|
||||
//17954 Modify ROI does not show in UI
|
||||
//deserialize wasn't setting this, seems like it should
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public void ResetSuffix()
|
||||
{
|
||||
_suffix = string.Empty;
|
||||
}
|
||||
|
||||
private string[] _channelNames = new string[0];
|
||||
public string[] ChannelNames
|
||||
{
|
||||
get => _channelNames;
|
||||
set
|
||||
{
|
||||
if (_channelNames != value)
|
||||
{
|
||||
_channelNames = value ?? new string[] { };
|
||||
OnPropertyChanged("ChannelNames");
|
||||
NotifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// return a TSA_Embedded channel on a TSR AIR differently than a TSA_Embedded channel
|
||||
/// on other DAS (it's a Voltage input channel if on non-TSR AIR DAS).
|
||||
/// </summary>
|
||||
/// <param name="serialNumber"></param>
|
||||
/// <param name="hardwareChannelName"></param>
|
||||
/// <param name="startOfHardware"></param>
|
||||
/// <param name="originalChannelName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetAnalogChanName(string serialNumber, string hardwareChannelName, string startOfHardware, string originalChannelName="")
|
||||
{
|
||||
var chanName = string.Empty;
|
||||
|
||||
if ((serialNumber == SensorConstants.TEST_SPECIFIC_ANALOG_SERIAL) &&
|
||||
!hardwareChannelName.StartsWith($"[{startOfHardware}") ||
|
||||
(serialNumber == SensorConstants.VOLTAGE_INPUT))
|
||||
{
|
||||
//34350 This is a Voltage input channel, so parse it differently
|
||||
chanName = GetChanName(SensorConstants.VOLTAGE_INPUT, hardwareChannelName, originalChannelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
chanName = GetChanName(serialNumber, hardwareChannelName, originalChannelName);
|
||||
}
|
||||
|
||||
return chanName;
|
||||
}
|
||||
/// <summary>
|
||||
/// Takes a Serial Number, Hardware Channel Name, and Original Channel Name and prepends the hardware channel
|
||||
/// based on whether or not it's an embedded (TSR AIR channel), or has a parent DAS.
|
||||
/// </summary>
|
||||
/// <param name="aic"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetChanName(string serialNumber, string hardwareChannelName, string originalChannelName = "")
|
||||
{
|
||||
var chanName = string.Empty;
|
||||
|
||||
if (serialNumber == SensorConstants.TEST_SPECIFIC_ANALOG_SERIAL)
|
||||
{
|
||||
chanName = hardwareChannelName + "\\" + originalChannelName;
|
||||
}
|
||||
else
|
||||
{
|
||||
var indexOfColon = hardwareChannelName.IndexOf(":");
|
||||
if (indexOfColon == -1)
|
||||
{
|
||||
chanName = hardwareChannelName + "\\" + serialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
var dasSerialNumber = hardwareChannelName.Substring(indexOfColon).Replace(':', '[');
|
||||
chanName = dasSerialNumber + "\\" + serialNumber;
|
||||
}
|
||||
}
|
||||
|
||||
return chanName;
|
||||
}
|
||||
public static string RemoveParentDASName(string entireChannelName)
|
||||
{
|
||||
var chanName = entireChannelName;
|
||||
|
||||
var indexOfColon = entireChannelName.IndexOf(":");
|
||||
if (indexOfColon > -1)
|
||||
{
|
||||
chanName = entireChannelName.Substring(indexOfColon).Replace(':', '[');
|
||||
}
|
||||
|
||||
return chanName;
|
||||
}
|
||||
/// <summary>
|
||||
/// sets the channel names without notifying of a change
|
||||
/// allows a constructor to bypass notifications
|
||||
/// 27034 ROI channel assignments are not saved when modifying and clicking save in test setup
|
||||
/// </summary>
|
||||
/// <param name="names"></param>
|
||||
public void SetChannelNamesNoNotify(string [] names)
|
||||
{
|
||||
_channelNames = names;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns string after "Assigned by ID"
|
||||
/// </summary>
|
||||
/// <param name="chHardware"></param>
|
||||
/// <returns></returns>
|
||||
public static string RemoveAssignedByIDFromHardwareString(string chHardware)
|
||||
{
|
||||
var newChHardware = string.Empty;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(chHardware))
|
||||
{
|
||||
newChHardware = chHardware.TrimStart();
|
||||
if (chHardware.StartsWith("Assigned by ID"))
|
||||
{
|
||||
newChHardware = chHardware.Replace("Assigned by ID", "");
|
||||
newChHardware = newChHardware.TrimStart();
|
||||
}
|
||||
if (newChHardware.Contains("["))
|
||||
{
|
||||
newChHardware = newChHardware.TrimStart();
|
||||
newChHardware = newChHardware.TrimStart('\\').Trim();
|
||||
}
|
||||
}
|
||||
|
||||
return newChHardware;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user