316 lines
13 KiB
C#
316 lines
13 KiB
C#
using DTS.Common.DataModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
|
|
namespace DataPROWin7.DataModel
|
|
{
|
|
/// <summary>
|
|
/// this is a test object that belongs to a test, it's different in that it can have test specific settings ...
|
|
/// </summary>
|
|
public class TestTestObject : TestObject, IComparable<TestTestObject>
|
|
{
|
|
public TestTestObject(TestObject obj)
|
|
: base(obj)
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// added a new constructor for
|
|
/// 9570 Test object and position defaulted (traditional groups) when you rename or copy a test setup
|
|
/// as old constructor missed the meta data copy
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="convertToEmbedded"></param>
|
|
public TestTestObject(TestTestObject obj, bool convertToEmbedded)
|
|
{
|
|
CommonCustructorItems(obj, convertToEmbedded);
|
|
MetaCommonConstructor(obj);
|
|
}
|
|
public TestTestObject(TestObject obj, bool convertToEmbedded)
|
|
{
|
|
CommonCustructorItems(obj, convertToEmbedded);
|
|
}
|
|
/// <summary>
|
|
/// takes care of all the non meta constructor information
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="convertToEmbedded"></param>
|
|
private void CommonCustructorItems(TestObject obj, bool convertToEmbedded)
|
|
{
|
|
var bAlreadyConverted = obj.GetISOTestObject().Embedded;
|
|
if (convertToEmbedded)
|
|
{
|
|
var guid = Guid.NewGuid();
|
|
//first grab a copy of the template and convert it
|
|
var isoTemplate = obj.Template.ToISOTestObjectTemplate();
|
|
isoTemplate.Embedded = true;
|
|
|
|
isoTemplate.OriginalTemplateName = bAlreadyConverted ? isoTemplate.OriginalTemplateName : isoTemplate.TemplateName;
|
|
|
|
isoTemplate.TemplateName = guid.ToString();
|
|
var db = ApplicationProperties.IsoDb;
|
|
var template = new TestObjectTemplate(isoTemplate, ref db);
|
|
|
|
var isoTestObject = new DTS.Common.ISO.TestObject(obj.GetISOTestObject(), isoTemplate, db);
|
|
isoTestObject.OriginalSerialNumber = obj.SerialNumber;
|
|
if (bAlreadyConverted) { isoTestObject.OriginalSerialNumber = obj.SerialNumberOrOriginalSerialNumber; }
|
|
isoTestObject.SerialNumber = guid.ToString();
|
|
isoTestObject.Embedded = true;
|
|
isoTestObject.OriginalTemplate = obj.Template.TemplateName;
|
|
if (bAlreadyConverted) { isoTestObject.OriginalTemplate = obj.Template.OriginalTemplateName; }
|
|
isoTestObject.SetTemplateOnly(guid.ToString());
|
|
var includedHardware = new Dictionary<string, DASHardware>();
|
|
foreach (var h in obj.Hardware)
|
|
{
|
|
includedHardware[h.GetHardware().GetId()] = h;
|
|
}
|
|
var to = new TestObject(isoTestObject, false, template, includedHardware);
|
|
Initialize(to);
|
|
//UGH, something resets the template properties.
|
|
//just change them back for now to the right values :/
|
|
Template.Embedded = true;
|
|
Template.OriginalTemplateName = template.OriginalTemplateName;
|
|
Template.TemplateName = template.TemplateName;
|
|
}
|
|
else
|
|
{
|
|
Initialize(obj);
|
|
}
|
|
}
|
|
private string _position = ChannelDefaultsKey;
|
|
public DTS.Common.ISO.MMEPositions Position
|
|
{
|
|
get => GetGroupPosition(_position);
|
|
set
|
|
{
|
|
SetProperty(ref _position, value.Position, "Position");
|
|
if (_position == UserSetKey)
|
|
{
|
|
GroupPositionComboBoxVisible = Visibility.Hidden;
|
|
GroupPositionButtonVisible = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
GroupPositionComboBoxVisible = Visibility.Visible;
|
|
GroupPositionButtonVisible = Visibility.Hidden;
|
|
//set the position for every sensor in the test object using this position
|
|
var isoTestObject = GetISOTestObject();
|
|
foreach (var ch in isoTestObject.AllChannels)
|
|
{
|
|
if (!ch.Required) { continue; }
|
|
if (string.IsNullOrWhiteSpace(ch.SensorSerialNumber)) { continue; }
|
|
var sd = GetSensor(ch.Name, ch.SensorSerialNumber, ch.GetId()); // now using ch.Name instead of ch.GetID(); FB 7391 - Group sensor settings not in test when you set the test obj. and position.
|
|
if (null == sd) { continue; }
|
|
sd.Position = value.Position;
|
|
SetSensor(ch.GetId(), sd);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public const string ChannelDefaultsKey = "#";
|
|
public const string UserSetKey = "@";
|
|
|
|
private DTS.Common.ISO.MMEPositions GetGroupPosition(string groupPositionKey)
|
|
{
|
|
foreach (var position in AvailableGroupPositions)
|
|
{
|
|
if (position.Position == groupPositionKey)
|
|
{
|
|
return position;
|
|
}
|
|
}
|
|
return _userSetGUID;
|
|
}
|
|
|
|
private Visibility _groupPositionComboBoxVisible = Visibility.Visible;
|
|
public Visibility GroupPositionComboBoxVisible
|
|
{
|
|
get
|
|
{
|
|
//TODO Remove Non-ISO Mode code
|
|
if (_groupPositionComboBoxVisible == Visibility.Visible)
|
|
{
|
|
return /*Common.SerializedSettings.ISOSupportLevel == Common.SerializedSettings.ISOSupportLevels.NO_ISO ? Visibility.Collapsed :*/ _groupPositionComboBoxVisible;
|
|
}
|
|
return _groupPositionComboBoxVisible;
|
|
}
|
|
set => SetProperty(ref _groupPositionComboBoxVisible, value, "GroupPositionComboBoxVisible");
|
|
}
|
|
|
|
private Visibility _groupPositionButtonVisible = Visibility.Hidden;
|
|
public Visibility GroupPositionButtonVisible
|
|
{
|
|
get
|
|
{
|
|
//TODO Remove Non-ISO Mode code
|
|
if (_groupPositionButtonVisible == Visibility.Visible)
|
|
{
|
|
return /*Common.SerializedSettings.ISOSupportLevel == Common.SerializedSettings.ISOSupportLevels.NO_ISO ? Visibility.Collapsed :*/ _groupPositionButtonVisible;
|
|
}
|
|
return _groupPositionButtonVisible;
|
|
}
|
|
set => SetProperty(ref _groupPositionButtonVisible, value, "GroupPositionButtonVisible");
|
|
}
|
|
|
|
private string _testObject = "?";
|
|
public DTS.Common.ISO.MMETestObjects TestObject
|
|
{
|
|
get => ApplicationProperties.IsoDb.GetTestObjectByIso(_testObject);
|
|
set
|
|
{
|
|
if (value == null) return;
|
|
SetProperty(ref _testObject, value.Test_Object, "TestObject");
|
|
//also set the test object for all sensors!
|
|
|
|
var isoTestObject = GetISOTestObject();
|
|
foreach (var ch in isoTestObject.AllChannels)
|
|
{
|
|
if (!ch.Required) { continue; }
|
|
if (string.IsNullOrWhiteSpace(ch.SensorSerialNumber)) { continue; }
|
|
var sd = GetSensor(ch.GetId(), ch.SensorSerialNumber, ch.GetId());
|
|
if (null == sd) { continue; }
|
|
sd.TestObject = value.Test_Object;
|
|
SetSensor(ch.GetId(), sd);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetTestObject(string s)
|
|
{
|
|
_testObject = s;
|
|
OnPropertyChanged("TestObject");
|
|
}
|
|
|
|
public void SetPosition(string s)
|
|
{
|
|
_position = s;
|
|
OnPropertyChanged("Position");
|
|
if (s == UserSetKey)
|
|
{
|
|
GroupPositionComboBoxVisible = Visibility.Hidden;
|
|
GroupPositionButtonVisible = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
GroupPositionComboBoxVisible = Visibility.Visible;
|
|
GroupPositionButtonVisible = Visibility.Hidden;
|
|
}
|
|
}
|
|
public DTS.Common.ISO.MMEPositions[] AvailablePositions => ApplicationProperties.IsoDb.GetPositions();
|
|
|
|
private const string DATAPRO_DEFINED = "DataPRO-defined";
|
|
public static DTS.Common.ISO.MMEPositions _channelDefaultsGUID = new DTS.Common.ISO.MMEPositions(Guid.NewGuid().ToString(), ChannelDefaultsKey, "(channel defaults)", "(channel defaults)", 1, DateTime.Now, DATAPRO_DEFINED, false, "", DateTime.Now,
|
|
DATAPRO_DEFINED, "", DTS.Common.ISO.MMEPossibleChannels.MMEChannelTypes.ISO13499_106);
|
|
private DTS.Common.ISO.MMEPositions _userSetGUID = new DTS.Common.ISO.MMEPositions(Guid.NewGuid().ToString(), UserSetKey, "(multiple)", "(multiple)", 1, DateTime.Now, DATAPRO_DEFINED, false, "", DateTime.Now,
|
|
DATAPRO_DEFINED, "", DTS.Common.ISO.MMEPossibleChannels.MMEChannelTypes.ISO13499_106);
|
|
public DTS.Common.ISO.MMEPositions[] AvailableGroupPositions
|
|
{
|
|
get
|
|
{
|
|
var availableGroupPositions = new List<DTS.Common.ISO.MMEPositions>();
|
|
availableGroupPositions.Add(_channelDefaultsGUID);
|
|
availableGroupPositions.AddRange(AvailablePositions);
|
|
|
|
return availableGroupPositions.ToArray();
|
|
}
|
|
}
|
|
|
|
private List<TestObject> _addedGroups = new List<TestObject>();
|
|
public TestObject[] AddedGroups
|
|
{
|
|
get => _addedGroups.ToArray();
|
|
set
|
|
{
|
|
SetProperty(ref _addedGroups, new List<TestObject>(value), "AddedSysBuiltTestObjects");
|
|
OnPropertyChanged("AddedSysBuiltTestObjectsMME");
|
|
}
|
|
}
|
|
|
|
public string[] ChannelTypes
|
|
{
|
|
get
|
|
{
|
|
var typeList = new List<string>();
|
|
typeList.Add("(no channels)"); //temp
|
|
typeList.AddRange(ApplicationProperties.IsoDb.GetUniquePossibleChannelTypes(DTS.Common.ISO.TestObjectTemplateChannel.NONISOCHANNELTYPE));
|
|
return typeList.ToArray();
|
|
}
|
|
}
|
|
|
|
public TestTestObject(TestTestObject to)
|
|
: base(to)
|
|
{
|
|
MetaCommonConstructor(to);
|
|
}
|
|
/// <summary>
|
|
/// takes care of the meta data copy constructor items
|
|
/// </summary>
|
|
/// <param name="to"></param>
|
|
private void MetaCommonConstructor(TestTestObject to)
|
|
{
|
|
ExcitationWarmupTimeMS = to.ExcitationWarmupTimeMS;
|
|
TargetSampleRate = to.TargetSampleRate;
|
|
PreTriggerSeconds = to.PreTriggerSeconds;
|
|
PostTriggerSeconds = to.PostTriggerSeconds;
|
|
_position = to._position;
|
|
Position = to.Position;
|
|
_testObject = to._testObject;
|
|
SerialNumberConverted = to.SerialNumberConverted;
|
|
SysBuilt = to.SysBuilt; //executed?
|
|
IsAdd = to.IsAdd;
|
|
DisplayOrder = to.DisplayOrder;
|
|
}
|
|
private int _excitationWarmupTime;
|
|
public int ExcitationWarmupTimeMS
|
|
{
|
|
get => _excitationWarmupTime;
|
|
set => SetProperty(ref _excitationWarmupTime, value, "ExcitationWarmupTimeMS");
|
|
}
|
|
private double _targetSampleRate;
|
|
public double TargetSampleRate
|
|
{
|
|
get => _targetSampleRate;
|
|
set => SetProperty(ref _targetSampleRate, value, "TargetSampleRate");
|
|
}
|
|
|
|
private double _preTriggerSeconds;
|
|
public double PreTriggerSeconds
|
|
{
|
|
get => _preTriggerSeconds;
|
|
set => SetProperty(ref _preTriggerSeconds, value, "PreTriggerSeconds");
|
|
}
|
|
|
|
private double _postTriggerSeconds;
|
|
public double PostTriggerSeconds
|
|
{
|
|
get => _postTriggerSeconds;
|
|
set => SetProperty(ref _postTriggerSeconds, value, "PostTriggerSeconds");
|
|
}
|
|
|
|
public void Rename(string oldName, string newName)
|
|
{
|
|
SerialNumber = SerialNumber.Replace(oldName, newName);
|
|
GetISOTestObject().OriginalSerialNumber = GetISOTestObject().OriginalSerialNumber.Replace(oldName, newName);
|
|
GetISOTestObject().OriginalTemplate = GetISOTestObject().OriginalTemplate.Replace(oldName, newName);
|
|
TestSetupName = newName;
|
|
var templateGUIDString = Guid.NewGuid().ToString();
|
|
Template.TemplateName = templateGUIDString;
|
|
Template.OriginalTemplateName = templateGUIDString;
|
|
}
|
|
|
|
public int DisplayOrder { get; set; } = -1;
|
|
|
|
public bool IsAdd { get; set; }
|
|
public int CompareTo(TestTestObject other)
|
|
{
|
|
var ret = DisplayOrder.CompareTo(other.DisplayOrder);
|
|
if (0 == ret)
|
|
{
|
|
ret = base.CompareTo(other);
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
}
|