Add trace of primitives and material

This commit is contained in:
Evgeny Redikultsev
2024-12-22 21:44:20 +05:00
parent 07370e6fc9
commit f10bcf6350
14 changed files with 511 additions and 116 deletions

View File

@@ -0,0 +1,183 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperCommon.Models.Tables;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;
namespace StructureHelperLogics.Models.Materials
{
public class TraceMaterialsFactory : ITraceEntityFactory<IHeadMaterial>
{
const int rowSize = 2;
private List<ITraceLoggerEntry> traceLoggerEntries;
public IEnumerable<IHeadMaterial>? Collection { get; set; }
public int Priority { get; set; } = LoggerService.GetPriorityByStatus(TraceLogStatuses.Info);
public List<ITraceLoggerEntry> GetTraceEntries()
{
Check();
traceLoggerEntries = new();
traceLoggerEntries.Add(new StringLogEntry()
{
Message = $"There are (is) {Collection.Count()} distinct material(s)",
Priority = Priority
}
);
ProcessCollection();
return traceLoggerEntries;
}
private void ProcessCollection()
{
var table = new TableLogEntry(rowSize)
{
Priority = Priority
};
table.ColumnWidth[1] = 400;
foreach (var item in Collection)
{
table.Table.AddRow(GetHeader(item));
table.Table.AddRows(GetCommonRows(item));
}
traceLoggerEntries.Add(table);
}
private void Check()
{
if (Collection is null)
{
throw new StructureHelperException(ErrorStrings.ParameterIsNull + ": Collection of primitives");
}
}
private IShTableRow<ITraceLoggerEntry> GetHeader(IHeadMaterial headMaterial)
{
const CellRole cellRole = CellRole.Header;
string[] ColumnList = new string[]
{
"Material name",
headMaterial.Name
};
var ndmRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
foreach (var item in ndmRow.Elements)
{
item.Role = cellRole;
}
for (int i = 0; i < rowSize; i++)
{
ndmRow.Elements[i].Value = new StringLogEntry()
{
Message = ColumnList[i],
Priority = Priority
};
}
return ndmRow;
}
private List<IShTableRow<ITraceLoggerEntry>> GetCommonRows(IHeadMaterial headMaterial)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
rows.AddRange(ProcessSafetyFactors(headMaterial.HelperMaterial.SafetyFactors));
return rows;
}
private List<IShTableRow<ITraceLoggerEntry>> ProcessSafetyFactors(IEnumerable<IMaterialSafetyFactor> safetyFactors)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
foreach (var item in safetyFactors)
{
if (item.Take == false) { continue; }
ShTableRow<ITraceLoggerEntry> ndmRow;
ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Factor name",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = item.Name,
Priority = Priority
};
rows.Add(ndmRow);
ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Factor description",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = item.Description,
Priority = Priority
};
rows.Add(ndmRow);
ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Partial factors",
Priority = Priority
};
var table = new TableLogEntry(rowSize)
{
Priority = Priority
};
table.ColumnWidth[0] = 150;
table.ColumnWidth[1] = 250;
table.Table.AddRows(ProcessPartialFactors(item.PartialFactors));
ndmRow.Elements[1].Value = table;
rows.Add(ndmRow);
}
return rows;
}
private List<IShTableRow<ITraceLoggerEntry>> ProcessPartialFactors(IEnumerable<IMaterialPartialFactor> partialFactors)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
foreach (var item in partialFactors)
{
rows.AddRange(ProcessPartialFactor(item));
}
return rows;
}
private List<IShTableRow<ITraceLoggerEntry>> ProcessPartialFactor(IMaterialPartialFactor item)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
ShTableRow<ITraceLoggerEntry> ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Factor conditions",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = "Limit state: " + item.LimitState.ToString() + ", Calculation term: " + item.CalcTerm + ", Stress state: " + item.StressState,
Priority = Priority
};
rows.Add(ndmRow);
ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Factor value",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = item.FactorValue.ToString(),
Priority = Priority
};
rows.Add(ndmRow);
return rows;
}
}
}

View File

@@ -7,7 +7,9 @@ using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Sections;
using StructureHelperCommon.Models.Sections.Logics;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.NdmCalculations.Buckling;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.Services.NdmPrimitives;
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
@@ -29,11 +31,34 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
public ForcesResults GetForcesResults()
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Service);
TraceInputData();
GetCombinations();
CalculateResult();
return result;
}
private void TraceInputData()
{
TracePrimitiveFactory tracePrimitiveFactory = new()
{
Collection = InputData.Primitives
};
List<ITraceLoggerEntry> traceEntries = tracePrimitiveFactory.GetTraceEntries();
foreach (var item in traceEntries)
{
TraceLogger?.AddEntry(item);
}
TraceMaterialsFactory traceMaterialFactory = new()
{
Collection = InputData.Primitives.Select(x => x.NdmElement.HeadMaterial).Distinct()
};
traceEntries = traceMaterialFactory.GetTraceEntries();
foreach (var item in traceEntries)
{
TraceLogger?.AddEntry(item);
}
}
private void CalculateResult()
{
result = new ForcesResults()

View File

@@ -1,16 +1,6 @@
using LoaderCalculator;
using LoaderCalculator.Data.Matrix;
using LoaderCalculator.Data.Ndms;
using LoaderCalculator.Data.ResultData;
using LoaderCalculator.Data.SourceData;
using LoaderCalculator.Logics;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Services;
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
{

View File

@@ -0,0 +1,200 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Models.Tables;
namespace StructureHelperLogics.NdmCalculations.Primitives
{
/// <summary>
/// Logic for creating of trace entries of primitives
/// </summary>
public class TracePrimitiveFactory : ITraceEntityFactory<INdmPrimitive>
{
const int rowSize = 2;
private List<ITraceLoggerEntry> traceLoggerEntries;
public int Priority { get; set; } = LoggerService.GetPriorityByStatus(TraceLogStatuses.Info);
public IEnumerable<INdmPrimitive>? Collection { get; set; }
public List<ITraceLoggerEntry> GetTraceEntries()
{
Check();
traceLoggerEntries = new();
traceLoggerEntries.Add(new StringLogEntry()
{
Message = $"There are (is) {Collection.Count()} primitive(s)",
Priority = Priority
}
);
ProcessCollection();
return traceLoggerEntries;
}
private void Check()
{
if (Collection is null)
{
throw new StructureHelperException(ErrorStrings.ParameterIsNull + ": Collection of primitives");
}
}
private void ProcessCollection()
{
foreach (var item in Collection)
{
var table = new TableLogEntry(rowSize)
{
Priority = Priority
};
table.ColumnWidth[1] = 200;
table.Table.AddRow(GetHeader(item));
table.Table.AddRows(GetCommonRows(item));
if (item is IRectangleNdmPrimitive rectangle)
{
table.Table.AddRows(ProcessRectangle(rectangle.Shape as IRectangleShape));
}
if (item is IEllipseNdmPrimitive ellipse)
{
IRectangleShape? rectShape = ellipse.Shape as IRectangleShape;
if (rectShape.Width == rectShape.Height)
{
table.Table.AddRows(ProcessCircle(rectShape));
}
else
{
table.Table.AddRows(ProcessRectangle(rectShape));
}
}
if (item is IPointNdmPrimitive point)
{
table.Table.AddRows(ProcessPoint(point));
}
traceLoggerEntries.Add(table);
}
}
private IEnumerable<IShTableRow<ITraceLoggerEntry>> ProcessCircle(IRectangleShape rectShape)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
ShTableRow<ITraceLoggerEntry> ndmRow;
ndmRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Diameter",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = rectShape.Width.ToString(),
Priority = Priority
};
rows.Add(ndmRow);
return rows;
}
private List<IShTableRow<ITraceLoggerEntry>> ProcessPoint(IPointNdmPrimitive point)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
ShTableRow<ITraceLoggerEntry> ndmRow;
ndmRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Area",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = point.Area.ToString(),
Priority = Priority
};
rows.Add(ndmRow);
return rows;
}
private List<IShTableRow<ITraceLoggerEntry>> GetCommonRows(INdmPrimitive ndmPrimitive)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
ShTableRow<ITraceLoggerEntry> ndmRow;
ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Material",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = ndmPrimitive.NdmElement.HeadMaterial.Name,
Priority = Priority
};
rows.Add(ndmRow);
ndmRow = new(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Center",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = "X = " + ndmPrimitive.Center.X.ToString() + ", Y = " + ndmPrimitive.Center.Y.ToString(),
Priority = Priority
};
rows.Add(ndmRow);
return rows;
}
private List<IShTableRow<ITraceLoggerEntry>> ProcessRectangle(IRectangleShape rectShape)
{
List<IShTableRow<ITraceLoggerEntry>> rows = new();
ShTableRow<ITraceLoggerEntry> ndmRow;
ndmRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Height",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = rectShape.Width.ToString(),
Priority = Priority
};
rows.Add(ndmRow);
ndmRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
ndmRow.Elements[0].Value = new StringLogEntry()
{
Message = "Width",
Priority = Priority
};
ndmRow.Elements[1].Value = new StringLogEntry()
{
Message = rectShape.Height.ToString(),
Priority = Priority
};
rows.Add(ndmRow);
return rows;
}
private IShTableRow<ITraceLoggerEntry> GetHeader(INdmPrimitive ndmPrimitive)
{
const CellRole cellRole = CellRole.Header;
string[] ColumnList = new string[]
{
"Primitive name",
ndmPrimitive.Name
};
var ndmRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
foreach (var item in ndmRow.Elements)
{
item.Role = cellRole;
}
for (int i = 0; i < rowSize; i++)
{
ndmRow.Elements[i].Value = new StringLogEntry()
{
Message = ColumnList[i],
Priority = Priority
};
}
return ndmRow;
}
}
}