Trace view model was changed

This commit is contained in:
Evgeny Redikultsev
2024-02-01 07:36:44 +05:00
parent a680e67ab3
commit 79ef8c5304
47 changed files with 480 additions and 324 deletions

View File

@@ -1,10 +1,9 @@
using LoaderCalculator;
using StructureHelper.Windows.Graphs;
using StructureHelper.Windows.Graphs;
using StructureHelper.Windows.ViewModels.Errors;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Services.Units;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
@@ -15,8 +14,6 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews

View File

@@ -4,15 +4,11 @@ using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.Units;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.Services.NdmPrimitives;
using System;
using System.Collections.Generic;
using System.ComponentModel;

View File

@@ -17,7 +17,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
public static GeometryNames GeometryNames => ProgramSetting.GeometryNames;
public LimitStates LimitState { get; set; }
public CalcTerms CalcTerm { get; set; }
public ForceTuple ForceTuple { get; set; }
public IForceTuple ForceTuple { get; set; }
public IEnumerable<INdmPrimitive> ndmPrimitives { get; set; }
public void Show(IDesignForceTuple finishDesignTuple)
{
@@ -31,7 +31,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
FindCrackFactor(endDesignTuple, startDesignTuple);
}
private void FindCrackFactor(ForceTuple finishDesignTuple, ForceTuple startDesignTuple)
private void FindCrackFactor(IForceTuple finishDesignTuple, IForceTuple startDesignTuple)
{
var calculator = new CrackForceCalculator();
calculator.StartTuple = startDesignTuple;

View File

@@ -15,7 +15,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
public List<INdmPrimitive> ndmPrimitives { get; set; }
public LimitStates LimitState { get; set; }
public CalcTerms CalcTerm { get; set; }
public ForceTuple ForceTuple { get; set; }
public IForceTuple ForceTuple { get; set; }
internal void Show()
{

View File

@@ -3,7 +3,7 @@ using StructureHelper.Windows.ViewModels.Errors;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Services.Units;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;

View File

@@ -1,16 +1,11 @@
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 StructureHelperCommon.Models;
using StructureHelperCommon.Models.Tables;
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;
@@ -21,9 +16,10 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews
{
public class TraceDocumentVM : ViewModelBase
{
IEnumerable<ITraceLoggerEntry> loggerEntries;
IEnumerable<ITraceLoggerEntry> selectedLoggerEntries;
FlowDocument document;
const int tabFactor = 500;
private readonly IEnumerable<ITraceLoggerEntry> loggerEntries;
private IEnumerable<ITraceLoggerEntry> selectedLoggerEntries;
private FlowDocument document;
private ICommand rebuildCommand;
private ICommand printDocumentCommand;
private int maxPriority;
@@ -66,7 +62,7 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews
{
this.loggerEntries = loggerEntries;
maxPriority = 350;
tabGap = 50;
tabGap = 30;
}
public ICommand RebuildCommand =>
@@ -81,40 +77,82 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews
SafetyProcessor.RunSafeProcess(DocumentReader.Print, "Error of printing document");
});
public void Prepare()
{
document = new();
selectedLoggerEntries = loggerEntries.Where(x => x.Priority <= MaxPriority);
var blocks = selectedLoggerEntries.Select(x => GetBlockByEntry(x));
document.Blocks.AddRange(blocks);
}
public void ShowPrepared()
{
DocumentReader.Document = document;
}
public void Show()
{
Prepare();
ShowPrepared();
}
public void Prepare()
private Block GetBlockByEntry(ITraceLoggerEntry traceEntry)
{
document = new();
selectedLoggerEntries = loggerEntries.Where(x => x.Priority <= MaxPriority);
foreach (var item in selectedLoggerEntries)
Block block;
if (traceEntry is StringLogEntry stringEntry)
{
ProcessLoggerEntries(item);
block = GetBlockByStringEntry(stringEntry);
}
}
private void ProcessLoggerEntries(ITraceLoggerEntry item)
{
if (item is StringLoggerEntry stringEntry)
else if (traceEntry is TableLogEntry tableEntry)
{
ProcessStringEntry(stringEntry);
}
else if (item is TableLoggerEntry tableEntry)
{
ProcessTableEntry(tableEntry);
block = GetBlockByTableEntry(tableEntry);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(item));
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(traceEntry));
}
return block;
}
private void ProcessTableEntry(TableLoggerEntry tableEntry)
private Block GetBlockByStringEntry(StringLogEntry stringEntry)
{
var paragraph = new Paragraph(new Run(stringEntry.Message));
paragraph.Margin = new Thickness(stringEntry.Priority / tabFactor * tabGap, 7, 0, 7);
if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Fatal))
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Red;
paragraph.Foreground = Brushes.Black;
paragraph.FontStyle = FontStyles.Italic;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Error))
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Pink;
paragraph.Foreground = Brushes.Black;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Warning))
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Yellow;
paragraph.Foreground = Brushes.Black;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Debug))
{
paragraph.FontSize = 12;
paragraph.Foreground = Brushes.Black;
}
else
{
paragraph.FontSize = 10;
paragraph.Foreground = Brushes.Gray;
}
return paragraph;
}
private Table GetBlockByTableEntry(TableLogEntry tableEntry)
{
const int columnWidth = 150;
var rows = tableEntry.Table.GetAllRows();
int rowCount = rows.Count();
int columnCount = tableEntry.Table.RowSize;
@@ -122,96 +160,53 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews
for (int x = 0; x < columnCount; x++)
{
var tableColumn = new TableColumn();
tableColumn.Width = new GridLength(150);
tableColumn.Width = new GridLength(columnWidth);
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.Value is StringLoggerEntry stringEntry)
{
tableCell = new TableCell(GetParagraphByStringEntry(stringEntry));
tableCell.ColumnSpan = cell.ColumnSpan;
if (cell.Role == CellRole.Regular)
{
tableCell.TextAlignment = TextAlignment.Left;
tableCell.Background = Brushes.LightYellow;
}
else if (cell.Role == CellRole.Header)
{
tableCell.TextAlignment = TextAlignment.Center;
tableCell.Background = Brushes.AliceBlue;
}
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(cell));
}
}
newRow.Cells.Add(tableCell);
}
TableRow newRow = GetTableRow(row);
table.RowGroups.Add(new TableRowGroup());
table.RowGroups[0].Rows.Add(newRow);
}
document.Blocks.Add(table);
return table;
}
private void ProcessStringEntry(StringLoggerEntry stringEntry)
private TableRow GetTableRow(IShTableRow<ITraceLoggerEntry> row)
{
var paragraph = GetParagraphByStringEntry(stringEntry);
document.Blocks.Add(paragraph);
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
{
var cellvalue = GetBlockByEntry(cell.Value);
tableCell = new TableCell(cellvalue);
AdjustTableCell(cell, tableCell);
}
newRow.Cells.Add(tableCell);
}
return newRow;
}
private Paragraph GetParagraphByStringEntry(StringLoggerEntry stringEntry)
private static void AdjustTableCell(IShTableCell<ITraceLoggerEntry>? cell, TableCell tableCell)
{
var paragraph = new Paragraph(new Run(stringEntry.Message));
paragraph.Margin = new Thickness(stringEntry.Priority / tabGap);
if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Fatal))
tableCell.ColumnSpan = cell.ColumnSpan;
if (cell.Role == CellRole.Regular)
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Red;
paragraph.Foreground = Brushes.Black;
paragraph.FontStyle = FontStyles.Italic;
tableCell.TextAlignment = TextAlignment.Left;
tableCell.Background = Brushes.LightYellow;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Error))
else if (cell.Role == CellRole.Header)
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Pink;
paragraph.Foreground = Brushes.Black;
tableCell.TextAlignment = TextAlignment.Center;
tableCell.Background = Brushes.AliceBlue;
}
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;
}
}
}

View File

@@ -1,17 +1,6 @@
using StructureHelperCommon.Models.Loggers;
using System;
using StructureHelperCommon.Models;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace StructureHelper.Windows.CalculationWindows.ProgressViews
{