using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace DTS.Slice.PedestrianAndHeadReports { /// /// top level report class, contains multiple sub reports /// public class PedestrianAndHeadTest: INotifyPropertyChanged { /// /// these methods make the class wpf/depedency property friendly, lets us notify listeners when data changes ... /// public event PropertyChangedEventHandler PropertyChanged; protected bool SetProperty(ref T storage, T value, String propertyName) { if (object.Equals(storage, value)) return false; storage = value; this.OnPropertyChanged(propertyName); return true; } protected void OnPropertyChanged(string propertyName) { var eventHandler = this.PropertyChanged; if (eventHandler != null) { eventHandler(this, new PropertyChangedEventArgs(propertyName)); } } /// /// these are all fields known of in the reports. Some are shared, some are specific to a specific report /// public enum Fields { TestNumber, TestDate, CarName, Model, TestTemperature, ClassificationAngle, MeasurementPoint, CollisionSpeed, ImpactorId, ImpactorType, StudyPersonnel, And1, And2, FrequencyClass, AccelerationUnits, TimeUnits, HeadX, HeadY, HeadZ, ForceUnits, MomentUnits, CombinedForce, UpperForce, LowerForce, UpperMoment, MidMoment, LowerMoment, ImpactorWeight, BendingMomentUnits, ShearDisplacementUnits, AccelerationChannel, BendingMomentChannel, ShearDisplacementChannel, TibiaUnits, MCLPCLLCLUnits, Tibia1, Tibia2, Tibia3, Tibia4, ACLChannel, MCLChannel, PCLChannel, LCLChannel, AxialUnits, XAxial, YAxial, ZAxial, Femur1, Femur2, Femur3, HeadDisplacementUnits, HeadDisplacementChannel } /// /// sets a specific field for a specific report /// also aggregates the field to other reports if it's a shared field ... /// /// /// /// public void SetField(ReportBase.ReportTypes type, Fields field, object obj) { string value = obj as string; MeasurementUnit mu = obj as MeasurementUnit; switch (field) { case Fields.XAxial: switch (type) { case ReportBase.ReportTypes.LWRLegARS: GetReport(ReportBase.ReportTypes.LWRLegARS).SetChannel(ReportBase.KnownGraphs.ARS_ARS, LWRLegARSReport.XAxialChannelId, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.YAxial: switch (type) { case ReportBase.ReportTypes.LWRLegARS: GetReport(ReportBase.ReportTypes.LWRLegARS).SetChannel(ReportBase.KnownGraphs.ARS_ARS, LWRLegARSReport.YAxialChannelId, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.ZAxial: switch (type) { case ReportBase.ReportTypes.LWRLegARS: GetReport(ReportBase.ReportTypes.LWRLegARS).SetChannel(ReportBase.KnownGraphs.ARS_ARS, LWRLegARSReport.ZAxialChannelId, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.AxialUnits: switch (type) { case ReportBase.ReportTypes.LWRLegARS: GetReport(ReportBase.ReportTypes.LWRLegARS).SetUnits(ReportBase.KnownGraphs.ARS_ARS, mu); break; default: throw new NotImplementedException(); } break; case Fields.ACLChannel: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_ACLPCL, LWRLegFlexReport.ACL_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.MCLChannel: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_MCL, LWRLegFlexReport.MCL_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.PCLChannel: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_ACLPCL, LWRLegFlexReport.PCL_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.LCLChannel: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_LCL, LWRLegFlexReport.LCL_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Tibia1: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_TIBIA, LWRLegFlexReport.TIBIA1_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Tibia2: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_TIBIA, LWRLegFlexReport.TIBIA2_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Tibia3: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_TIBIA, LWRLegFlexReport.TIBIA3_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Tibia4: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetChannel(ReportBase.KnownGraphs.FLEX_TIBIA, LWRLegFlexReport.TIBIA4_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.MCLPCLLCLUnits: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetUnits(ReportBase.KnownGraphs.FLEX_MCL, mu); GetReport(ReportBase.ReportTypes.LWRLegFlex).SetUnits(ReportBase.KnownGraphs.FLEX_LCL, mu); GetReport(ReportBase.ReportTypes.LWRLegFlex).SetUnits(ReportBase.KnownGraphs.FLEX_ACLPCL, mu); break; default: throw new NotImplementedException(); } break; case Fields.TibiaUnits: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: GetReport(ReportBase.ReportTypes.LWRLegFlex).SetUnits(ReportBase.KnownGraphs.FLEX_TIBIA, mu); break; default: throw new NotImplementedException(); } break; case Fields.ShearDisplacementChannel: switch(type) { case ReportBase.ReportTypes.LWRLegTRL: (GetReport(ReportBase.ReportTypes.LWRLegTRL) as LWRLegTRLReport).SetChannel(ReportBase.KnownGraphs.LWR_LEG_TRL_ShearAngle, LWRLegTRLReport.ShearingChannelId, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.BendingMomentChannel: switch( type) { case ReportBase.ReportTypes.LWRLegTRL: (GetReport(ReportBase.ReportTypes.LWRLegTRL) as LWRLegTRLReport).SetChannel(ReportBase.KnownGraphs.LWR_LEG_TRL_BendingAngle, LWRLegTRLReport.BendingChannelId, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Femur1: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: (GetReport(ReportBase.ReportTypes.LWRLegFlex) as LWRLegFlexReport).SetChannel(ReportBase.KnownGraphs.FLEX_FEMUR, LWRLegFlexReport.FEMUR1_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Femur2: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: (GetReport(ReportBase.ReportTypes.LWRLegFlex) as LWRLegFlexReport).SetChannel(ReportBase.KnownGraphs.FLEX_FEMUR, LWRLegFlexReport.FEMUR2_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.Femur3: switch (type) { case ReportBase.ReportTypes.LWRLegFlex: (GetReport(ReportBase.ReportTypes.LWRLegFlex) as LWRLegFlexReport).SetChannel(ReportBase.KnownGraphs.FLEX_FEMUR, LWRLegFlexReport.FEMUR3_ID, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.AccelerationChannel: switch (type) { case ReportBase.ReportTypes.LWRLegTRL: GetReport(ReportBase.ReportTypes.LWRLegTRL).SetChannel(ReportBase.KnownGraphs.LWR_LEG_TRL_Acceleration, LWRLegTRLReport.AccelerationChannelId, obj as ReviewTestChannel); break; case ReportBase.ReportTypes.LWRLegARS: GetReport(ReportBase.ReportTypes.LWRLegARS).SetChannel(ReportBase.KnownGraphs.ARS_Acceleration, LWRLegARSReport.XAccelerationId, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.HeadDisplacementChannel: switch (type) { case ReportBase.ReportTypes.Head: (GetReport(ReportBase.ReportTypes.Head) as HeadReport).SetChannel(ReportBase.KnownGraphs.HEAD_StrokeDisplacement, HeadReport.HEAD_Displacement, obj as ReviewTestChannel); break; default: throw new NotImplementedException(); } break; case Fields.HeadDisplacementUnits: switch (type) { case ReportBase.ReportTypes.Head: (GetReport(ReportBase.ReportTypes.Head) as HeadReport).SetUnits(ReportBase.KnownGraphs.HEAD_StrokeDisplacement, mu); break; default: throw new NotImplementedException(); } break; case Fields.ShearDisplacementUnits: switch(type) { case ReportBase.ReportTypes.LWRLegTRL: (GetReport(ReportBase.ReportTypes.LWRLegTRL) as LWRLegTRLReport).SetUnits(ReportBase.KnownGraphs.LWR_LEG_TRL_ShearAngle, mu); break; default: throw new NotImplementedException(); } break; case Fields.BendingMomentUnits: switch( type ) { case ReportBase.ReportTypes.LWRLegTRL: (GetReport(ReportBase.ReportTypes.LWRLegTRL) as LWRLegTRLReport).SetUnits(ReportBase.KnownGraphs.LWR_LEG_TRL_BendingAngle, mu); break; default: throw new NotImplementedException(); } break; case Fields.MomentUnits: switch (type) { case ReportBase.ReportTypes.UPRLeg: GetReport(ReportBase.ReportTypes.UPRLeg).SetUnits(ReportBase.KnownGraphs.UPRLeg_Moment, mu); break; default: throw new NotImplementedException(); } break; case Fields.ForceUnits: if (type != ReportBase.ReportTypes.UPRLeg) { throw new NotImplementedException(); } GetReport(type).SetUnits(ReportBase.KnownGraphs.UPRLEG_Force, mu); break; case Fields.AccelerationUnits: switch (type) { case ReportBase.ReportTypes.Head: GetReport(ReportBase.ReportTypes.Head).SetUnits(ReportBase.KnownGraphs.HEAD_Acceleration, mu); break; case ReportBase.ReportTypes.LWRLegTRL: GetReport(ReportBase.ReportTypes.LWRLegTRL).SetUnits(ReportBase.KnownGraphs.LWR_LEG_TRL_Acceleration, mu); break; case ReportBase.ReportTypes.LWRLegARS: GetReport(ReportBase.ReportTypes.LWRLegARS).SetUnits(ReportBase.KnownGraphs.ARS_Acceleration, mu); break; default: throw new NotImplementedException(); } break; case Fields.ClassificationAngle: if (type != ReportBase.ReportTypes.Head) { throw new NotImplementedException(); } (GetReport(ReportBase.ReportTypes.Head) as HeadReport).ClassificationAngle = value; break; case Fields.And1: GetReport(ReportBase.ReportTypes.Head).And1 = value; GetReport(ReportBase.ReportTypes.LWRLegARS).And1 = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).And1 = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).And1 = value; GetReport(ReportBase.ReportTypes.UPRLeg).And1 = value; break; case Fields.And2: GetReport(ReportBase.ReportTypes.Head).And2 = value; GetReport(ReportBase.ReportTypes.LWRLegARS).And2 = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).And2 = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).And2 = value; GetReport(ReportBase.ReportTypes.UPRLeg).And2 = value; break; case Fields.CarName: GetReport(ReportBase.ReportTypes.Head).CarName = value; GetReport(ReportBase.ReportTypes.LWRLegARS).CarName = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).CarName = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).CarName = value; GetReport(ReportBase.ReportTypes.UPRLeg).CarName = value; break; case Fields.CollisionSpeed: GetReport(ReportBase.ReportTypes.Head).CollisionSpeed = value; GetReport(ReportBase.ReportTypes.LWRLegARS).CollisionSpeed = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).CollisionSpeed = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).CollisionSpeed = value; GetReport(ReportBase.ReportTypes.UPRLeg).CollisionSpeed = value; break; case Fields.FrequencyClass: GetReport(type).ChannelFilterClass = value; break; case Fields.ImpactorId: GetReport(ReportBase.ReportTypes.Head).ImpactorID = value; GetReport(ReportBase.ReportTypes.LWRLegARS).ImpactorID = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).ImpactorID = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).ImpactorID = value; GetReport(ReportBase.ReportTypes.UPRLeg).ImpactorID = value; break; case Fields.ImpactorType: GetReport(type).ImpactorType = value; break; case Fields.MeasurementPoint: GetReport(ReportBase.ReportTypes.Head).MeasurementPoint = value; GetReport(ReportBase.ReportTypes.LWRLegARS).MeasurementPoint = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).MeasurementPoint = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).MeasurementPoint = value; GetReport(ReportBase.ReportTypes.UPRLeg).MeasurementPoint = value; break; case Fields.Model: GetReport(ReportBase.ReportTypes.Head).Model = value; GetReport(ReportBase.ReportTypes.LWRLegARS).Model = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).Model = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).Model = value; GetReport(ReportBase.ReportTypes.UPRLeg).Model = value; break; case Fields.StudyPersonnel: GetReport(ReportBase.ReportTypes.Head).StudyPersonnel = value; GetReport(ReportBase.ReportTypes.LWRLegARS).StudyPersonnel = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).StudyPersonnel = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).StudyPersonnel = value; GetReport(ReportBase.ReportTypes.UPRLeg).StudyPersonnel = value; break; case Fields.TestDate: try { DateTime dt = (DateTime)obj; GetReport(ReportBase.ReportTypes.Head).TestDate = dt; GetReport(ReportBase.ReportTypes.LWRLegARS).TestDate = dt; GetReport(ReportBase.ReportTypes.LWRLegFlex).TestDate = dt; GetReport(ReportBase.ReportTypes.LWRLegTRL).TestDate = dt; GetReport(ReportBase.ReportTypes.UPRLeg).TestDate = dt; } catch (System.Exception) { } break; case Fields.TestNumber: GetReport(ReportBase.ReportTypes.Head).TestNumber = value; GetReport(ReportBase.ReportTypes.LWRLegARS).TestNumber = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).TestNumber = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).TestNumber = value; GetReport(ReportBase.ReportTypes.UPRLeg).TestNumber = value; break; case Fields.TestTemperature: GetReport(ReportBase.ReportTypes.Head).TestTemperature = value; GetReport(ReportBase.ReportTypes.LWRLegARS).TestTemperature = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).TestTemperature = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).TestTemperature = value; GetReport(ReportBase.ReportTypes.UPRLeg).TestTemperature = value; break; case Fields.TimeUnits: GetReport(ReportBase.ReportTypes.Head).TimeUnits = value; GetReport(ReportBase.ReportTypes.LWRLegARS).TimeUnits = value; GetReport(ReportBase.ReportTypes.LWRLegFlex).TimeUnits = value; GetReport(ReportBase.ReportTypes.LWRLegTRL).TimeUnits = value; GetReport(ReportBase.ReportTypes.UPRLeg).TimeUnits = value; break; case Fields.HeadX: if (type != ReportBase.ReportTypes.Head) { throw new NotSupportedException(); } GetReport(ReportBase.ReportTypes.Head).SetChannel(ReportBase.KnownGraphs.HEAD_Acceleration, HeadReport.HEAD_X_ChannelID, obj as ReviewTestChannel); break; case Fields.HeadY: if (type != ReportBase.ReportTypes.Head) { throw new NotSupportedException(); } GetReport(ReportBase.ReportTypes.Head).SetChannel(ReportBase.KnownGraphs.HEAD_Acceleration, HeadReport.HEAD_Y_ChannelID, obj as ReviewTestChannel); break; case Fields.HeadZ: if (type != ReportBase.ReportTypes.Head) { throw new NotSupportedException(); } GetReport(ReportBase.ReportTypes.Head).SetChannel(ReportBase.KnownGraphs.HEAD_Acceleration, HeadReport.HEAD_Z_ChannelID, obj as ReviewTestChannel); break; case Fields.CombinedForce: if( type != ReportBase.ReportTypes.UPRLeg) { throw new NotImplementedException();} GetReport(type).SetChannel(ReportBase.KnownGraphs.UPRLEG_Force, UprLegReport.UPR_TOTALFORCE_ID, obj as ReviewTestChannel); break; case Fields.UpperForce: if( type != ReportBase.ReportTypes.UPRLeg){ throw new NotImplementedException();} GetReport(type).SetChannel(ReportBase.KnownGraphs.UPRLEG_Force, UprLegReport.UPR_FORCE_ID, obj as ReviewTestChannel); break; case Fields.LowerForce: if( type != ReportBase.ReportTypes.UPRLeg){ throw new NotImplementedException();} GetReport(type).SetChannel(ReportBase.KnownGraphs.UPRLEG_Force, UprLegReport.LWR_FORCE_ID, obj as ReviewTestChannel); break; case Fields.UpperMoment: if( type != ReportBase.ReportTypes.UPRLeg ){ throw new NotImplementedException();} GetReport(ReportBase.ReportTypes.UPRLeg).SetChannel(ReportBase.KnownGraphs.UPRLeg_Moment, UprLegReport.UPR_MOMENT_ID, obj as ReviewTestChannel); break; case Fields.MidMoment: if( type != ReportBase.ReportTypes.UPRLeg){ throw new NotImplementedException();} GetReport(type).SetChannel(ReportBase.KnownGraphs.UPRLeg_Moment, UprLegReport.MID_MOMENT_ID, obj as ReviewTestChannel); break; case Fields.LowerMoment: if( type != ReportBase.ReportTypes.UPRLeg) { throw new NotImplementedException();} GetReport(type).SetChannel(ReportBase.KnownGraphs.UPRLeg_Moment, UprLegReport.LWR_MOMENT_ID, obj as ReviewTestChannel); break; case Fields.ImpactorWeight: /*if( type != ReportBase.ReportTypes.LWRLegTRL){ throw new NotImplementedException();} (GetReport(ReportBase.ReportTypes.LWRLegTRL) as LWRLegTRLReport).ImpactorWeight = value;*/ GetReport(type).SetValue(Fields.ImpactorWeight.ToString(), value); break; default: System.Diagnostics.Trace.WriteLine("unknown field " + field.ToString()); break; } } /// /// contains the test data to operate on ... /// private ReviewTest _test; public ReviewTest Test { get { return _test; } set { if (null != _test) { _test.Cleanup(); _test = null; } SetProperty(ref _test, value, "Test"); } } /// /// list of reports the pedestrian test is aware of. /// private Dictionary _reports = new Dictionary(); public ReportBase GetReport(ReportBase.ReportTypes type) { return _reports[type]; } /// /// constructs a report aware of head,ars, flex, trl, uprleg reports /// public PedestrianAndHeadTest() { _reports.Add(ReportBase.ReportTypes.Head, new HeadReport(this)); _reports.Add(ReportBase.ReportTypes.LWRLegARS, new LWRLegARSReport(this)); _reports.Add(ReportBase.ReportTypes.LWRLegFlex, new LWRLegFlexReport(this)); _reports.Add(ReportBase.ReportTypes.LWRLegTRL, new LWRLegTRLReport(this)); _reports.Add(ReportBase.ReportTypes.UPRLeg, new UprLegReport(this)); } public void ToStringOutput(string filename) { System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = "\r\n"; settings.NewLineHandling = System.Xml.NewLineHandling.Replace; System.Xml.XmlWriter xt = System.Xml.XmlTextWriter.Create(filename, settings); xt.WriteStartDocument(true); xt.WriteStartElement("PedestrianAndHeadSafetyReport"); var e = _reports.GetEnumerator(); while (e.MoveNext()) { e.Current.Value.ToStringOutput(ref xt); } xt.WriteEndElement(); xt.WriteEndDocument(); xt.Flush(); xt.Close(); } public void SaveTo(string filename) { ToStringOutput(filename); } public void SetField(ReportBase.ReportTypes type, ReportBase.KnownGraphs graph, ReportGraph.Fields field, string value) { _reports[type].SetField(graph, field, value); } public void LoadFrom(string filename) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(filename))) { System.Xml.XmlReader tr = System.Xml.XmlTextReader.Create(ms, null); ReportBase.ReportTypes _currentReport = ReportBase.ReportTypes.Head; while (tr.Read()) { if (tr.IsStartElement()) { if (tr.Name == "Report") { } else if (tr.Name == "ReportType") { _currentReport = (ReportBase.ReportTypes)Enum.Parse(typeof(ReportBase.ReportTypes), tr.ReadString()); } else if (tr.Name == "PedestrianAndHeadSafetyReport") { } else if (tr.Name == "InUse") { bool bInUse = Boolean.Parse(tr.ReadString()); _reports[_currentReport].InUse = bInUse; } else { try { Fields field = (Fields)Enum.Parse(typeof(Fields),tr.Name); if (field == Fields.TestDate) { SetField(_currentReport, field, new DateTime(Convert.ToInt64(tr.ReadString()))); } else { SetField(_currentReport, field, tr.ReadString()); } } catch (System.Exception) { } } } } } } } }