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

@@ -157,13 +157,19 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews
{ {
const int columnWidth = 150; const int columnWidth = 150;
var rows = tableEntry.Table.GetAllRows(); var rows = tableEntry.Table.GetAllRows();
int rowCount = rows.Count();
int columnCount = tableEntry.Table.RowSize; int columnCount = tableEntry.Table.RowSize;
var table = new Table(); var table = new Table();
for (int x = 0; x < columnCount; x++) for (int x = 0; x < columnCount; x++)
{ {
var tableColumn = new TableColumn(); var tableColumn = new TableColumn();
tableColumn.Width = new GridLength(columnWidth); if (tableEntry.ColumnWidth[x] > 0d)
{
tableColumn.Width = new GridLength(tableEntry.ColumnWidth[x]);
}
else
{
tableColumn.Width = new GridLength(columnWidth);
}
table.Columns.Add(tableColumn); table.Columns.Add(tableColumn);
} }
foreach (var row in rows) foreach (var row in rows)

View File

@@ -7,7 +7,7 @@
xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls" xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls"
d:DataContext="{d:DesignInstance local:TraceDocumentVM}" d:DataContext="{d:DesignInstance local:TraceDocumentVM}"
mc:Ignorable="d" mc:Ignorable="d"
Title="Trace Document Viewer" Height="600" Width="800" MinHeight="400" MinWidth="600" WindowStartupLocation="CenterScreen"> Title="Document Viewer" Height="600" Width="800" MinHeight="400" MinWidth="600" WindowStartupLocation="CenterScreen">
<Grid> <Grid>
<DockPanel> <DockPanel>
<ToolBarTray DockPanel.Dock="Top"> <ToolBarTray DockPanel.Dock="Top">

View File

@@ -103,36 +103,6 @@
</ContextMenu> </ContextMenu>
</Window.Resources> </Window.Resources>
<DockPanel> <DockPanel>
<!--<Menu DockPanel.Dock="Top" x:Name="menu">
<MenuItem Header="File">
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Primitives">
<MenuItem Header="Add">
<Button Content="Rectangle" Command="{Binding PrimitiveLogic.Add}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/>
<Button Content="Circle" Command="{Binding PrimitiveLogic.Add}" CommandParameter="{x:Static enums:PrimitiveType.Circle}"/>
<Button Content="Reinforcement" Command="{Binding PrimitiveLogic.Add}" CommandParameter="{x:Static enums:PrimitiveType.Reinforcement}"/>
<Button Content="Point" Command="{Binding PrimitiveLogic.Add}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
</MenuItem>
<Button Content="Edit primitive" Command="{Binding PrimitiveLogic.Edit}"/>
<Button Content="Delete primitive" Command="{Binding PrimitiveLogic.Delete}"/>
</MenuItem>
<Button Content="Materials" Command="{Binding EditHeadMaterialsCommand}"/>
<Button Content="Move primitives to center" Command="{Binding MovePrimitiveToGravityCenterCommand}"/>
<MenuItem Header="Templates">
<Button Content="Concrete beam" Command="{Binding AddBeamCase}"/>
<Button Content="Concrete column" Command="{Binding AddColumnCase}"/>
<Button Content="Concrete slab" Command="{Binding AddSlabCase}"/>
<Button Content="Concrete circle" Command="{Binding AddRCCircleCase}"/>
</MenuItem>
</MenuItem>
<MenuItem Header="Tools">
<Button Content="Settings" Command="{Binding ShowVisualProperty}"/>
</MenuItem>
<MenuItem Header="Help">
<Button Content="About..." Command="{Binding HelpLogic.ShowAbout}"/>
</MenuItem>
</Menu>-->
<ToolBarTray DockPanel.Dock="Top"> <ToolBarTray DockPanel.Dock="Top">
<ToolBar DataContext="{Binding CombinationsLogic}" ToolTip="Actions"> <ToolBar DataContext="{Binding CombinationsLogic}" ToolTip="Actions">
<Button Style="{StaticResource ToolButton}" <Button Style="{StaticResource ToolButton}"

View File

@@ -21,6 +21,11 @@ using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace StructureHelper.Windows.MainWindow namespace StructureHelper.Windows.MainWindow
{ {
public class CrossSectionViewModel : ViewModelBase public class CrossSectionViewModel : ViewModelBase

View File

@@ -5,43 +5,56 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow.Materials" xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow.Materials"
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Materials" xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Materials"
xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls"
d:DataContext="{d:DesignInstance vm:HeadMaterialsViewModel}" d:DataContext="{d:DesignInstance vm:HeadMaterialsViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="Materials" Height="350" Width="680" MinHeight="350" MinWidth="680" WindowStartupLocation="CenterScreen"> Title="Materials" Height="350" Width="480" MinHeight="350" MinWidth="480" WindowStartupLocation="CenterScreen">
<Window.Resources> <Window.Resources>
<ResourceDictionary Source="/Infrastructure/UI/Resources/Materials.xaml"/> <ResourceDictionary Source="/Infrastructure/UI/Resources/Materials.xaml"/>
</Window.Resources> </Window.Resources>
<Grid> <DockPanel>
<Grid.ColumnDefinitions> <ToolBarTray DockPanel.Dock="Top">
<ColumnDefinition/> <ToolBar>
<ColumnDefinition Width="120"/> <Button Style="{DynamicResource ToolButton}" Command="{Binding ShowMaterialDiagram}">
</Grid.ColumnDefinitions> <Button.ToolTip>
<uc:ButtonToolTipEh HeaderText="Show material diagram"
IconContent="{StaticResource MomentCurvatureDiagram}"
DescriptionText="Show stress-strain diagram for selected material"/>
</Button.ToolTip>
<Viewbox>
<ContentControl ContentTemplate="{DynamicResource MomentCurvatureDiagram}"/>
</Viewbox>
</Button>
</ToolBar>
</ToolBarTray>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.ColumnDefinitions>
<RowDefinition/> <ColumnDefinition/>
</Grid.RowDefinitions> </Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}"> <Grid>
<ListBox.ItemTemplate> <Grid.RowDefinitions>
<DataTemplate> <RowDefinition/>
<Grid> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}">
<ColumnDefinition Width="20"/> <ListBox.ItemTemplate>
<ColumnDefinition/> <DataTemplate>
<ColumnDefinition/> <Grid>
</Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Margin="3"> <ColumnDefinition Width="20"/>
<Rectangle.Fill> <ColumnDefinition/>
<SolidColorBrush Color="{Binding Color}"/> <ColumnDefinition/>
</Rectangle.Fill> </Grid.ColumnDefinitions>
</Rectangle> <Rectangle Grid.Column="0" Margin="3">
<TextBlock Grid.Column="1" Text="{Binding Name}"/> <Rectangle.Fill>
</Grid> <SolidColorBrush Color="{Binding Color}"/>
</DataTemplate> </Rectangle.Fill>
</ListBox.ItemTemplate> </Rectangle>
</ListBox> <TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid> </Grid>
<StackPanel Grid.Column="1"> </DockPanel>
<Button Content="Show diagram" Command="{Binding ShowMaterialDiagram}"/>
</StackPanel>
</Grid>
</Window> </Window>

View File

@@ -9,6 +9,11 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace StructureHelper.Windows.ViewModels.Materials namespace StructureHelper.Windows.ViewModels.Materials
{ {
public class MaterialsViewModel : SelectItemVM<IHeadMaterial> public class MaterialsViewModel : SelectItemVM<IHeadMaterial>

View File

@@ -14,6 +14,7 @@ namespace StructureHelperCommon.Models
/// </summary> /// </summary>
public class TraceTablesFactory public class TraceTablesFactory
{ {
public int Priority { get; set; } public int Priority { get; set; }
/// <summary> /// <summary>
/// Generates table entry for Point2D (2 columns, 2 rows) /// Generates table entry for Point2D (2 columns, 2 rows)
@@ -64,8 +65,10 @@ namespace StructureHelperCommon.Models
/// <returns>Table entry</returns> /// <returns>Table entry</returns>
public TableLogEntry GetByForceTuple(IEnumerable<IForceTuple> forceTuples) public TableLogEntry GetByForceTuple(IEnumerable<IForceTuple> forceTuples)
{ {
var table = new TableLogEntry(6); var table = new TableLogEntry(6)
table.Priority = Priority; {
Priority = Priority
};
//type of force tuple for creating a header is taken by first member //type of force tuple for creating a header is taken by first member
var firstMember = forceTuples.First(); var firstMember = forceTuples.First();
table.Table.AddRow(GetForceTupleHeaderRow(firstMember)); table.Table.AddRow(GetForceTupleHeaderRow(firstMember));
@@ -86,54 +89,26 @@ namespace StructureHelperCommon.Models
private ShTableRow<ITraceLoggerEntry> GetForceTupleHeaderRow(IForceTuple forceTuple) private ShTableRow<ITraceLoggerEntry> GetForceTupleHeaderRow(IForceTuple forceTuple)
{ {
const CellRole cellRole = CellRole.Header; const CellRole cellRole = CellRole.Header;
const int rowSize = 6;
string[] ColumnList = new string[] { "Mx", "My", "Nz", "Qx", "Qy", "Mz" }; string[] ColumnList = new string[] { "Mx", "My", "Nz", "Qx", "Qy", "Mz" };
if (forceTuple is StrainTuple) if (forceTuple is StrainTuple)
{ {
ColumnList = new string[] { "Kx", "Ky", "EpsZ", "GammaX", "GammaY", "Kz" }; ColumnList = new string[] { "Kx", "Ky", "EpsZ", "GammaX", "GammaY", "Kz" };
} }
var forceTupleRow = new ShTableRow<ITraceLoggerEntry>(6); var forceTupleRow = new ShTableRow<ITraceLoggerEntry>(rowSize);
foreach (var item in forceTupleRow.Elements) foreach (var item in forceTupleRow.Elements)
{ {
item.Role = cellRole; item.Role = cellRole;
} }
for (int i = 0; i < rowSize; i++)
forceTupleRow.Elements[0].Value = new StringLogEntry()
{ {
Message = ColumnList[0], forceTupleRow.Elements[i].Value = new StringLogEntry()
Priority = Priority {
}; Message = ColumnList[i],
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; return forceTupleRow;
} }
private ShTableRow<ITraceLoggerEntry> GetForceTupleRow(IForceTuple forceTuple) private ShTableRow<ITraceLoggerEntry> GetForceTupleRow(IForceTuple forceTuple)
@@ -181,7 +156,6 @@ namespace StructureHelperCommon.Models
return forceTupleRow; return forceTupleRow;
} }
private ShTableRow<ITraceLoggerEntry> GetPoint2DHeaderRow() private ShTableRow<ITraceLoggerEntry> GetPoint2DHeaderRow()
{ {
const CellRole cellRole = CellRole.Header; const CellRole cellRole = CellRole.Header;
@@ -228,5 +202,6 @@ namespace StructureHelperCommon.Models
}; };
return pointRow; return pointRow;
} }
} }
} }

View File

@@ -0,0 +1,13 @@
using StructureHelperCommon.Models;
using System.Collections.Generic;
namespace StructureHelperCommon.Models
{
public interface ITraceEntityFactory<T> where T : class
{
IEnumerable<T>? Collection { get; set; }
int Priority { get; set; }
List<ITraceLoggerEntry> GetTraceEntries();
}
}

View File

@@ -12,6 +12,7 @@ namespace StructureHelperCommon.Models
private ShTable<ITraceLoggerEntry> table; private ShTable<ITraceLoggerEntry> table;
public ShTable<ITraceLoggerEntry> Table {get => table;} public ShTable<ITraceLoggerEntry> Table {get => table;}
public DateTime TimeStamp { get; } public DateTime TimeStamp { get; }
public double[] ColumnWidth { get; }
public int Priority { get; set; } public int Priority { get; set; }
public TableLogEntry(int rowSize) public TableLogEntry(int rowSize)
@@ -20,6 +21,7 @@ namespace StructureHelperCommon.Models
{ {
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize)); throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
} }
ColumnWidth = new double[rowSize];
table = new(rowSize); table = new(rowSize);
TimeStamp = DateTime.Now; TimeStamp = DateTime.Now;
} }

View File

@@ -33,6 +33,14 @@ namespace StructureHelperCommon.Models.Tables
table.Add(new ShTableRow<T>(RowSize)); table.Add(new ShTableRow<T>(RowSize));
} }
public void AddRows(IEnumerable<IShTableRow<T>> tableRows)
{
foreach (var item in tableRows)
{
AddRow(item);
}
}
/// <summary> /// <summary>
/// Get all rows in the table /// Get all rows in the table
/// </summary> /// </summary>

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;
using StructureHelperCommon.Models.Sections.Logics; using StructureHelperCommon.Models.Sections.Logics;
using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.NdmCalculations.Buckling; using StructureHelperLogics.NdmCalculations.Buckling;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.Services.NdmPrimitives; using StructureHelperLogics.Services.NdmPrimitives;
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
@@ -29,11 +31,34 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
public ForcesResults GetForcesResults() public ForcesResults GetForcesResults()
{ {
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Service); TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Service);
TraceInputData();
GetCombinations(); GetCombinations();
CalculateResult(); CalculateResult();
return result; 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() private void CalculateResult()
{ {
result = new ForcesResults() result = new ForcesResults()

View File

@@ -1,16 +1,6 @@
using LoaderCalculator; using StructureHelperCommon.Infrastructures.Interfaces;
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.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Services;
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces 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;
}
}
}