using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Models.Tables; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StructureHelperCommon.Models { /// /// Factory for creating trace table entries /// public class TraceTablesFactory { public int Priority { get; set; } /// /// Generates table entry for Point2D (2 columns, 2 rows) /// /// Point fo creating a table /// Table entry public TableLogEntry GetByPoint2D(IPoint2D point2D) { var table = new TableLogEntry(2); table.Priority = Priority; table.Table.AddRow(GetPoint2DHeaderRow()); table.Table.AddRow(GetPoint2DRow(point2D)); return table; } /// /// Generates a table representation for the provided force tuple /// /// Force tuple to create the table for /// Table entry public TableLogEntry GetByForceTuple(IForceTuple forceTuple) { var table = new TableLogEntry(6); table.Priority = Priority; table.Table.AddRow(GetForceTupleHeaderRow(forceTuple)); table.Table.AddRow(GetForceTupleRow(forceTuple)); return table; } /// /// Generates table entry for Point2D (2 columns, (number of poins + 1) rows) /// /// Collection of points for creating a table /// Table entry public TableLogEntry GetByPoint2D(IEnumerable points) { var table = new TableLogEntry(2); table.Priority = Priority; table.Table.AddRow(GetPoint2DHeaderRow()); foreach (var item in points) { table.Table.AddRow(GetPoint2DRow(item)); } return table; } /// /// Generates a table representation for the provided force tuple collection /// /// Force tuple collection to create the table for /// Table entry public TableLogEntry GetByForceTuple(IEnumerable forceTuples) { var table = new TableLogEntry(6); table.Priority = Priority; //type of force tuple for creating a header is taken by first member var firstMember = forceTuples.First(); table.Table.AddRow(GetForceTupleHeaderRow(firstMember)); foreach (var forceTuple in forceTuples) { table.Table.AddRow(GetForceTupleRow(forceTuple)); } return table; } /// /// Generates new trace table entry /// /// Default status = info public TraceTablesFactory(TraceLogStatuses status = TraceLogStatuses.Info) { Priority = LoggerService.GetPriorityByStatus(status); } private ShTableRow GetForceTupleHeaderRow(IForceTuple forceTuple) { const CellRole cellRole = CellRole.Header; string[] ColumnList = new string[] { "Mx", "My", "Nz", "Qx", "Qy", "Mz" }; if (forceTuple is StrainTuple) { ColumnList = new string[] { "Kx", "Ky", "EpsZ", "GammaX", "GammaY", "Kz" }; } var forceTupleRow = new ShTableRow(6); foreach (var item in forceTupleRow.Elements) { item.Role = cellRole; } forceTupleRow.Elements[0].Value = new StringLogEntry() { Message = ColumnList[0], Priority = Priority }; forceTupleRow.Elements[1].Value = new StringLogEntry() { Message = ColumnList[1], Priority = Priority }; forceTupleRow.Elements[2].Value = new StringLogEntry() { Message = ColumnList[2], Priority = Priority }; forceTupleRow.Elements[3].Value = new StringLogEntry() { Message = ColumnList[3], Priority = Priority }; forceTupleRow.Elements[4].Value = new StringLogEntry() { Message = ColumnList[4], Priority = Priority }; forceTupleRow.Elements[5].Value = new StringLogEntry() { Message = ColumnList[5], Priority = Priority }; return forceTupleRow; } private ShTableRow GetForceTupleRow(IForceTuple forceTuple) { var forceTupleRow = new ShTableRow(6); forceTupleRow.Elements[0].Value = new StringLogEntry() { Message = forceTuple.Mx.ToString(), Priority = Priority }; forceTupleRow.Elements[1].Value = new StringLogEntry() { Message = forceTuple.My.ToString(), Priority = Priority }; forceTupleRow.Elements[2].Value = new StringLogEntry() { Message = forceTuple.Nz.ToString(), Priority = Priority }; forceTupleRow.Elements[3].Value = new StringLogEntry() { Message = forceTuple.Qx.ToString(), Priority = Priority }; forceTupleRow.Elements[4].Value = new StringLogEntry() { Message = forceTuple.Qy.ToString(), Priority = Priority }; forceTupleRow.Elements[5].Value = new StringLogEntry() { Message = forceTuple.Mz.ToString(), Priority = Priority }; return forceTupleRow; } private ShTableRow GetPoint2DHeaderRow() { const CellRole cellRole = CellRole.Header; var headerRow = new ShTableRow(2); IShTableCell tableCell; ITraceLoggerEntry loggerEntry; loggerEntry = new StringLogEntry() { Message = "X", Priority = Priority }; tableCell = new ShTableCell() { Value = loggerEntry, Role = cellRole, }; headerRow.Elements[0] = tableCell; loggerEntry = new StringLogEntry() { Message = "Y", Priority = Priority }; tableCell = new ShTableCell() { Value = loggerEntry, Role = cellRole, }; headerRow.Elements[1] = tableCell; return headerRow; } private ShTableRow GetPoint2DRow(IPoint2D point2D) { var pointRow = new ShTableRow(2); pointRow.Elements[0].Value = new StringLogEntry() { Message = Convert.ToString(point2D.X), Priority = LoggerService.GetPriorityByStatus(TraceLogStatuses.Info) }; pointRow.Elements[1].Value = new StringLogEntry() { Message = Convert.ToString(point2D.Y), Priority = LoggerService.GetPriorityByStatus(TraceLogStatuses.Info) }; return pointRow; } } }