From a9ffd8b903c9924058e3930b09d85ba5261dc384 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Sat, 27 Jan 2024 13:39:48 +0500 Subject: [PATCH] Table log Entry was added --- .../Calculators/LimitCurveVisualCalculator.cs | 2 +- StructureHelper/StructureHelper.csproj.user | 6 + .../CalculatorsViews/CrackDiagramLogic.cs | 2 +- .../InteractionDiagramLogic.cs | 2 +- .../ForceResultLogic/ShowDiagramLogic.cs | 2 +- .../LimitCurveCalculatorView.xaml | 2 +- .../ProgressViews/TraceDocumentVM.cs | 205 ++++++++++++++++++ .../ProgressViews/TraceDocumentView.xaml | 27 +++ .../ProgressViews/TraceDocumentView.xaml.cs | 34 +++ .../NdmCrossSections/AnalysisVewModelLogic.cs | 14 +- .../Interfaces/ILongProcessLogic.cs | 2 +- .../Calculators/FindParameterCalculator.cs | 18 +- .../Models/Calculators/ICalculator.cs | 2 +- .../TraceLoggerTableByPointsFactory.cs | 62 ++++++ .../Models/Loggers/IShiftTraceLogger.cs | 16 ++ .../Models/Loggers/ITraceLogger.cs | 3 +- .../Models/Loggers/LoggerService.cs | 33 +++ .../Models/Loggers/ShiftTraceLogger.cs | 55 +++++ .../Models/Loggers/TableLoggerEntry.cs | 27 +++ .../Models/Loggers/TraceLogger.cs | 31 +-- .../Models/Soils/AnchorCalculator.cs | 2 +- .../Models/Tables/IShTableRow.cs | 10 + .../Models/Tables/ListTable.cs | 77 +++++++ .../Models/Tables/ShTableRow.cs | 38 ++++ .../Analyses/ByForces/ForceCalculator.cs | 2 +- .../Analyses/ByForces/ForceTupleCalculator.cs | 2 +- .../ByForces/LimitCurve/ILimitCurveLogic.cs | 2 +- .../LimitCurve/ILimitCurveParameterLogic.cs | 2 +- .../LimitCurve/LimitCurveCalculator.cs | 19 +- .../ByForces/LimitCurve/LimitCurveLogic.cs | 7 +- .../LimitCurve/LimitCurveParameterLogic.cs | 12 +- .../LimitCurve/LimitCurvesCalculator.cs | 7 +- .../LimitCurve/StabLimitCurveLogic.cs | 2 +- .../Logics/InterpolationProgressLogic.cs | 2 +- .../Analyses/Geometry/GeometryCalculator.cs | 2 +- .../Buckling/ConcreteBucklingCalculator.cs | 2 +- .../Cracking/CrackForceCalculator.cs | 2 +- .../Cracking/CrackWidthCalculator.cs | 2 +- .../Cracking/CrackWidthSimpleCalculator.cs | 2 +- 39 files changed, 675 insertions(+), 64 deletions(-) create mode 100644 StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs create mode 100644 StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml create mode 100644 StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml.cs create mode 100644 StructureHelperCommon/Models/Loggers/Factories/TraceLoggerTableByPointsFactory.cs create mode 100644 StructureHelperCommon/Models/Loggers/IShiftTraceLogger.cs create mode 100644 StructureHelperCommon/Models/Loggers/LoggerService.cs create mode 100644 StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs create mode 100644 StructureHelperCommon/Models/Loggers/TableLoggerEntry.cs create mode 100644 StructureHelperCommon/Models/Tables/IShTableRow.cs create mode 100644 StructureHelperCommon/Models/Tables/ListTable.cs create mode 100644 StructureHelperCommon/Models/Tables/ShTableRow.cs diff --git a/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs b/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs index dc99558..0330cc8 100644 --- a/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs +++ b/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs @@ -19,7 +19,7 @@ namespace StructureHelper.Models.Calculators public IResult Result => result; - public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public IShiftTraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public void Run() { diff --git a/StructureHelper/StructureHelper.csproj.user b/StructureHelper/StructureHelper.csproj.user index dff02ba..6fee5a1 100644 --- a/StructureHelper/StructureHelper.csproj.user +++ b/StructureHelper/StructureHelper.csproj.user @@ -27,6 +27,9 @@ Code + + Code + Code @@ -89,6 +92,9 @@ Designer + + Designer + Designer diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs index ab20ba8..c3025d0 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs @@ -36,7 +36,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews public int StepCount => ValidTupleList.Count(); - public ITraceLogger? TraceLogger { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } public CrackDiagramLogic(IEnumerable tupleList, IEnumerable ndmPrimitives) { diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs index e0279ce..a4e48d2 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs @@ -41,7 +41,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu public Action SetProgress { get; set; } public bool Result { get; set; } - public ITraceLogger? TraceLogger { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } public InteractionDiagramLogic(LimitCurveInputData inputData) { diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs index 0ea4440..89a6d65 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs @@ -28,7 +28,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu public Action SetProgress { get; set; } public bool Result { get; set; } - public ITraceLogger? TraceLogger { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } public void WorkerDoWork(object sender, DoWorkEventArgs e) { diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/LimitCurveCalculatorView.xaml b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/LimitCurveCalculatorView.xaml index 90e622e..0adf251 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/LimitCurveCalculatorView.xaml +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/LimitCurveCalculatorView.xaml @@ -7,7 +7,7 @@ xmlns:fc="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews" d:DataContext ="{d:DesignInstance local:LimitCurveCalculatorViewModel}" mc:Ignorable="d" - Title="Limit Curve Calculator" Height="390" Width="400" MinHeight="300" MinWidth="400" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> + Title="Interaction Diagram Calculator" Height="390" Width="400" MinHeight="300" MinWidth="400" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs new file mode 100644 index 0000000..1415c6f --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs @@ -0,0 +1,205 @@ +using StructureHelper.Infrastructure; +using StructureHelper.Windows.AddMaterialWindow; +using StructureHelper.Windows.ViewModels.Errors; +using StructureHelper.Windows.ViewModels.Materials; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models.Loggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; + +namespace StructureHelper.Windows.CalculationWindows.ProgressViews +{ + public class TraceDocumentVM : ViewModelBase + { + IEnumerable loggerEntries; + IEnumerable selectedLoggerEntries; + FlowDocument document; + private ICommand rebuildCommand; + private ICommand printDocumentCommand; + private int maxPriority; + private int tabGap; + + public FlowDocumentReader DocumentReader { get; set; } + public int MaxPriority + { + get => maxPriority; set + { + var oldValue = maxPriority; + try + { + maxPriority = Math.Max(value, 0); + OnPropertyChanged(nameof(MaxPriority)); + } + catch (Exception) + { + maxPriority = oldValue; + } + } + } + public int TabGap + { + get => tabGap; set + { + var oldValue = tabGap; + try + { + tabGap = Math.Max(value, 0); + OnPropertyChanged(nameof(TabGap)); + } + catch (Exception) + { + tabGap = oldValue; + } + } + } + public TraceDocumentVM(IEnumerable loggerEntries) + { + this.loggerEntries = loggerEntries; + maxPriority = 350; + tabGap = 50; + } + + public ICommand RebuildCommand => + rebuildCommand ??= new RelayCommand(o => + { + Show(); + }); + + public ICommand PrintDocumentCommand => + printDocumentCommand ??= new RelayCommand(o => + { + SafetyProcessor.RunSafeProcess(DocumentReader.Print, "Error of printing document"); + }); + + public void Show() + { + Prepare(); + ShowPrepared(); + } + + public void Prepare() + { + document = new(); + selectedLoggerEntries = loggerEntries.Where(x => x.Priority <= MaxPriority); + foreach (var item in selectedLoggerEntries) + { + ProcessLoggerEntries(item); + } + } + + private void ProcessLoggerEntries(ITraceLoggerEntry item) + { + if (item is StringLoggerEntry stringEntry) + { + ProcessStringEntry(stringEntry); + } + else if (item is TableLoggerEntry tableEntry) + { + ProcessTableEntry(tableEntry); + } + else + { + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(item)); + } + } + + private void ProcessTableEntry(TableLoggerEntry tableEntry) + { + var rows = tableEntry.Table.GetAllRows(); + int rowCount = rows.Count(); + int columnCount = tableEntry.Table.RowSize; + var table = new Table(); + for (int x = 0; x < columnCount; x++) + { + var tableColumn = new TableColumn(); + tableColumn.Width = new GridLength(150); + table.Columns.Add(tableColumn); + } + foreach (var row in rows) + { + var newRow = new TableRow(); + foreach (var cell in row.Elements) + { + TableCell tableCell; + if (cell is null) + { + tableCell = new TableCell(new Paragraph(new Run(string.Empty))); + } + else + { + if (cell is StringLoggerEntry stringEntry) + { + tableCell = new TableCell(GetParagraphByStringEntry(stringEntry)); + } + else + { + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(cell)); + } + } + newRow.Cells.Add(tableCell); + } + table.RowGroups.Add(new TableRowGroup()); + table.RowGroups[0].Rows.Add(newRow); + } + document.Blocks.Add(table); + } + + private void ProcessStringEntry(StringLoggerEntry stringEntry) + { + var paragraph = GetParagraphByStringEntry(stringEntry); + document.Blocks.Add(paragraph); + } + + private Paragraph GetParagraphByStringEntry(StringLoggerEntry stringEntry) + { + var paragraph = new Paragraph(new Run(stringEntry.Message)); + paragraph.Margin = new Thickness(stringEntry.Priority / tabGap); + if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Fatal)) + { + paragraph.FontSize = 14; + paragraph.Background = Brushes.Red; + paragraph.Foreground = Brushes.Black; + paragraph.FontStyle = FontStyles.Italic; + } + else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Error)) + { + paragraph.FontSize = 14; + paragraph.Background = Brushes.Pink; + paragraph.Foreground = Brushes.Black; + } + else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Warning)) + { + paragraph.FontSize = 14; + paragraph.Background = Brushes.Yellow; + paragraph.Foreground = Brushes.Black; + } + else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Debug)) + { + paragraph.FontSize = 12; + paragraph.Foreground = Brushes.Black; + } + else + { + paragraph.FontSize = 8; + paragraph.Foreground = Brushes.Gray; + + } + + return paragraph; + } + + public void ShowPrepared() + { + DocumentReader.Document = document; + } + } +} diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml new file mode 100644 index 0000000..c1c5a39 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + +