Smart rounding was ajusted

This commit is contained in:
Evgeny Redikultsev
2024-06-02 16:56:44 +05:00
parent 99d5aa3608
commit 31d668b996
58 changed files with 716 additions and 274 deletions

View File

@@ -0,0 +1,13 @@
using System.Windows.Media;
namespace FieldVisualizer.Entities.ColorMaps
{
public interface IValueColorArray
{
double AverageValue { get; set; }
Color BottomColor { get; set; }
double BottomValue { get; set; }
Color TopColor { get; set; }
double TopValue { get; set; }
}
}

View File

@@ -11,25 +11,8 @@ namespace FieldVisualizer.Entities.ColorMaps
/// Flag of activity /// Flag of activity
/// </summary> /// </summary>
bool IsActive { get; set; } bool IsActive { get; set; }
/// <summary> IValueColorArray ExactValues { get; }
/// Minimum value of range IValueColorArray RoundedValues { get; }
/// </summary>
double BottomValue { get; set; }
/// <summary>
/// Average value of range
/// </summary>
double AverageValue { get; set; }
/// <summary>
/// Maximum value of range
/// </summary>
double TopValue {get;set;}
/// <summary>
/// Color correspondent to minimum value
/// </summary>
Color BottomColor { get; set; }
/// <summary>
/// Color correspondent to maximum value
/// </summary>
Color TopColor { get; set; }
} }
} }

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace FieldVisualizer.Entities.ColorMaps
{
public class ValueColorArray : IValueColorArray
{
/// <summary>
/// Minimum value of range
/// </summary>
public double BottomValue { get; set; }
/// <summary>
/// Average value of range
/// </summary>
public double AverageValue { get; set; }
/// <summary>
/// Maximum value of range
/// </summary>
public double TopValue { get; set; }
/// <summary>
/// Color correspondent to minimum value
/// </summary>
public Color BottomColor { get; set; }
/// <summary>
/// Color correspondent to maximum value
/// </summary>
public Color TopColor { get; set; }
}
}

View File

@@ -7,15 +7,10 @@ namespace FieldVisualizer.Entities.ColorMaps
{ {
/// <inheritdoc/> /// <inheritdoc/>
public bool IsActive { get; set; } public bool IsActive { get; set; }
/// <inheritdoc/>
public double BottomValue { get; set; } public IValueColorArray ExactValues { get; private set; } = new ValueColorArray();
/// <inheritdoc/>
public double AverageValue { get; set; } public IValueColorArray RoundedValues { get; private set; } = new ValueColorArray();
/// <inheritdoc/>
public double TopValue { get; set; }
/// <inheritdoc/>
public Color BottomColor { get; set; }
/// <inheritdoc/>
public Color TopColor { get; set; }
} }
} }

View File

@@ -1,6 +1,7 @@
using FieldVisualizer.Entities.ColorMaps; using FieldVisualizer.Entities.ColorMaps;
using FieldVisualizer.Entities.Values; using FieldVisualizer.Entities.Values;
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
@@ -11,6 +12,7 @@ namespace FieldVisualizer.Services.ColorServices
public static class ColorOperations public static class ColorOperations
{ {
const byte Alpha = 0xff; const byte Alpha = 0xff;
static IMathRoundLogic roundLogic = new SmartRoundLogic();
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -23,15 +25,18 @@ namespace FieldVisualizer.Services.ColorServices
var colorRanges = new List<IValueColorRange>(); var colorRanges = new List<IValueColorRange>();
foreach (var valueRange in valueRanges) foreach (var valueRange in valueRanges)
{ {
IValueColorRange valueColorRange = new ValueColorRange var valueColorRange = new ValueColorRange
{ {
IsActive = true, IsActive = true,
BottomValue = valueRange.BottomValue,
AverageValue = (valueRange.BottomValue + valueRange.TopValue) / 2,
TopValue = valueRange.TopValue
}; };
valueColorRange.BottomColor = GetColorByValue(fullRange, colorMap, valueColorRange.BottomValue); valueColorRange.ExactValues.BottomValue = valueRange.BottomValue;
valueColorRange.TopColor = GetColorByValue(fullRange, colorMap, valueColorRange.TopValue); valueColorRange.ExactValues.AverageValue = (valueRange.BottomValue + valueRange.TopValue) / 2;
valueColorRange.ExactValues.TopValue = valueRange.TopValue;
valueColorRange.ExactValues.BottomColor = GetColorByValue(fullRange, colorMap, valueColorRange.ExactValues.BottomValue);
valueColorRange.ExactValues.TopColor = GetColorByValue(fullRange, colorMap, valueColorRange.ExactValues.TopValue);
valueColorRange.RoundedValues.BottomValue = roundLogic.RoundValue(valueColorRange.ExactValues.BottomValue);
valueColorRange.RoundedValues.AverageValue = roundLogic.RoundValue(valueColorRange.ExactValues.AverageValue);
valueColorRange.RoundedValues.TopValue = roundLogic.RoundValue(valueColorRange.ExactValues.TopValue);
colorRanges.Add(valueColorRange); colorRanges.Add(valueColorRange);
} }
return colorRanges; return colorRanges;

View File

@@ -9,6 +9,7 @@ using FieldVisualizer.Services.ColorServices;
using FieldVisualizer.Services.PrimitiveServices; using FieldVisualizer.Services.PrimitiveServices;
using FieldVisualizer.Services.ValueRanges; using FieldVisualizer.Services.ValueRanges;
using FieldVisualizer.Windows.UserControls; using FieldVisualizer.Windows.UserControls;
using StructureHelperCommon.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@@ -22,6 +23,7 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels
{ {
public class FieldViewerViewModel : ViewModelBase, IDataErrorInfo public class FieldViewerViewModel : ViewModelBase, IDataErrorInfo
{ {
private IMathRoundLogic roundLogic = new SmartRoundLogic() { DigitQuant = 3 };
public ICommand RebuildCommand { get; } public ICommand RebuildCommand { get; }
public ICommand ZoomInCommand { get; } public ICommand ZoomInCommand { get; }
public ICommand ZoomOutCommand { get; } public ICommand ZoomOutCommand { get; }
@@ -159,8 +161,8 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels
private ColorMapsTypes _ColorMapType; private ColorMapsTypes _ColorMapType;
private IColorMap _ColorMap; private IColorMap _ColorMap;
private IValueRange valueRange; private IValueRange valueRange;
private IEnumerable<IValueRange> _ValueRanges; private IEnumerable<IValueRange> valueRanges;
private IEnumerable<IValueColorRange> _ValueColorRanges; private IEnumerable<IValueColorRange> valueColorRanges;
private bool setMinValue; private bool setMinValue;
private bool setMaxValue; private bool setMaxValue;
private double crossLineX; private double crossLineX;
@@ -190,7 +192,7 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels
if ((PrimitiveSet is null) == false) if ((PrimitiveSet is null) == false)
{ {
ProcessPrimitives(); ProcessPrimitives();
Legend.ValueColorRanges = _ValueColorRanges; Legend.ValueColorRanges = valueColorRanges;
Legend.Refresh(); Legend.Refresh();
} }
} }
@@ -257,14 +259,14 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels
{ {
SolidColorBrush brush = new SolidColorBrush(); SolidColorBrush brush = new SolidColorBrush();
brush.Color = ColorOperations.GetColorByValue(valueRange, _ColorMap, valuePrimitive.Value); brush.Color = ColorOperations.GetColorByValue(valueRange, _ColorMap, valuePrimitive.Value);
foreach (var valueRange in _ValueColorRanges) foreach (var valueRange in valueColorRanges)
{ {
if (valuePrimitive.Value >= valueRange.BottomValue & valuePrimitive.Value <= valueRange.TopValue & (!valueRange.IsActive)) if (valuePrimitive.Value >= valueRange.ExactValues.BottomValue & valuePrimitive.Value <= valueRange.ExactValues.TopValue & (!valueRange.IsActive))
{ {
brush.Color = Colors.Gray; brush.Color = Colors.Gray;
} }
} }
shape.ToolTip = valuePrimitive.Value; shape.ToolTip = roundLogic.RoundValue(valuePrimitive.Value);
shape.Tag = valuePrimitive; shape.Tag = valuePrimitive;
shape.Fill = brush; shape.Fill = brush;
Canvas.SetLeft(shape, valuePrimitive.CenterX - addX - dX); Canvas.SetLeft(shape, valuePrimitive.CenterX - addX - dX);
@@ -301,10 +303,24 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels
{ {
UserValueRange.TopValue = UserValueRange.BottomValue; UserValueRange.TopValue = UserValueRange.BottomValue;
} }
if (SetMinValue) { valueRange.BottomValue = UserValueRange.BottomValue; } else { UserValueRange.BottomValue = valueRange.BottomValue; } if (SetMinValue == true)
if (SetMaxValue) { valueRange.TopValue = UserValueRange.TopValue; } else { UserValueRange.TopValue = valueRange.TopValue; } {
_ValueRanges = ValueRangeOperations.DivideValueRange(valueRange, RangeNumber); valueRange.BottomValue = UserValueRange.BottomValue;
_ValueColorRanges = ColorOperations.GetValueColorRanges(valueRange, _ValueRanges, _ColorMap); }
else
{
UserValueRange.BottomValue = valueRange.BottomValue;
}
if (SetMaxValue == true)
{
valueRange.TopValue = UserValueRange.TopValue;
}
else
{
UserValueRange.TopValue = valueRange.TopValue;
}
valueRanges = ValueRangeOperations.DivideValueRange(valueRange, RangeNumber);
valueColorRanges = ColorOperations.GetValueColorRanges(valueRange, valueRanges, _ColorMap);
} }
private void SetCrossLine(object commandParameter) private void SetCrossLine(object commandParameter)
{ {

View File

@@ -20,23 +20,23 @@
<ColumnDefinition Width="10"/> <ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<CheckBox Name="ActiveCheckBox" Grid.Column="0" IsChecked="{Binding Path=IsActive}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <CheckBox Name="ActiveCheckBox" Grid.Column="0" IsChecked="{Binding Path=IsActive}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Rectangle Grid.Column="1" Margin="0,2,0,2" ToolTip="{Binding Path=BottomValue}"> <Rectangle Grid.Column="1" Margin="0,2,0,2" ToolTip="{Binding Path=RoundedValues.BottomValue}">
<Rectangle.Fill> <Rectangle.Fill>
<SolidColorBrush Color="{Binding Path=BottomColor}"/> <SolidColorBrush Color="{Binding Path=ExactValues.BottomColor}"/>
</Rectangle.Fill> </Rectangle.Fill>
</Rectangle> </Rectangle>
<Rectangle Grid.Column="2" Margin="0,2,0,2"> <Rectangle Grid.Column="2" Margin="0,2,0,2">
<Rectangle.Fill> <Rectangle.Fill>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0"> <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="{Binding Path=BottomColor}"/> <GradientStop Color="{Binding Path=ExactValues.BottomColor}"/>
<GradientStop Color="{Binding Path=TopColor}" Offset="1"/> <GradientStop Color="{Binding Path=ExactValues.TopColor}" Offset="1"/>
</LinearGradientBrush> </LinearGradientBrush>
</Rectangle.Fill> </Rectangle.Fill>
</Rectangle> </Rectangle>
<TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FF868686" Text="{Binding AverageValue}"/> <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FF868686" Text="{Binding RoundedValues.AverageValue}"/>
<Rectangle Grid.Column="3" Margin="0,2,0,2" ToolTip="{Binding Path=TopValue}"> <Rectangle Grid.Column="3" Margin="0,2,0,2" ToolTip="{Binding Path=RoundedValues.TopValue}">
<Rectangle.Fill> <Rectangle.Fill>
<SolidColorBrush Color="{Binding Path=TopColor}"/> <SolidColorBrush Color="{Binding Path=ExactValues.TopColor}"/>
</Rectangle.Fill> </Rectangle.Fill>
</Rectangle> </Rectangle>
</Grid> </Grid>

View File

@@ -6,7 +6,7 @@
xmlns:FieldViewerControl="clr-namespace:FieldVisualizer.Windows.UserControls" xmlns:FieldViewerControl="clr-namespace:FieldVisualizer.Windows.UserControls"
xmlns:local="clr-namespace:FieldVisualizer.Windows" xmlns:local="clr-namespace:FieldVisualizer.Windows"
mc:Ignorable="d" mc:Ignorable="d"
Title="FieldViewer" Height="800" Width="1200" WindowStartupLocation="CenterOwner"> Title="FieldViewer" Height="800" Width="1200" MinHeight="400" MinWidth="800" MaxHeight="1000" MaxWidth="1500" WindowStartupLocation="CenterScreen" ShowInTaskbar="False">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/> <ColumnDefinition Width="300"/>

View File

@@ -14,7 +14,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Area : UnitBase internal class Area : UnitBase
{ {
public override UnitTypes UnitType { get => UnitTypes.Area; } public override UnitTypes UnitType { get => UnitTypes.Area; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "mm2"); } public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "mm2"); }
public override string UnitName { get => "Area"; } public override string UnitName { get => "Area"; }
} }
} }

View File

@@ -0,0 +1,28 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class CrackWidth : UnitBase
{
public CrackWidth()
{
OperationLogic = new ConvertUnitLogic()
{
MathRoundLogic = new FixedRoundLogic()
{
DigitQuant = 3
}
};
}
public override UnitTypes UnitType { get => UnitTypes.Length; }
public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "mm"); }
public override string UnitName { get => "Length"; }
}
}

View File

@@ -11,7 +11,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Curvature : UnitBase internal class Curvature : UnitBase
{ {
public override UnitTypes UnitType { get => UnitTypes.Curvature; } public override UnitTypes UnitType { get => UnitTypes.Curvature; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "1/mm"); } public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "1/mm"); }
public override string UnitName { get => "Curvature"; } public override string UnitName { get => "Curvature"; }
} }
} }

View File

@@ -13,7 +13,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Force : UnitBase internal class Force : UnitBase
{ {
public override UnitTypes UnitType { get => UnitTypes.Force; } public override UnitTypes UnitType { get => UnitTypes.Force; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "kN"); } public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "kN"); }
public override string UnitName { get => "Force"; } public override string UnitName { get => "Force"; }
} }
} }

View File

@@ -5,8 +5,9 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{ {
internal class Length : UnitBase internal class Length : UnitBase
{ {
public override UnitTypes UnitType { get => UnitTypes.Length; } public override UnitTypes UnitType { get => UnitTypes.Length; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "mm"); } public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "mm"); }
public override string UnitName { get => "Length"; } public override string UnitName { get => "Length"; }
} }
} }

View File

@@ -11,7 +11,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Moment : UnitBase internal class Moment : UnitBase
{ {
public override UnitTypes UnitType { get => UnitTypes.Moment; } public override UnitTypes UnitType { get => UnitTypes.Moment; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "kNm"); } public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "kNm"); }
public override string UnitName { get => "Moment"; } public override string UnitName { get => "Moment"; }
} }
} }

View File

@@ -12,6 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{ {
internal class PlainDouble : IValueConverter internal class PlainDouble : IValueConverter
{ {
IConvertUnitLogic operationLogic = new ConvertUnitLogic();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
try try
@@ -28,7 +30,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{ {
try try
{ {
return CommonOperation.ConvertToDoubleChangeComma((string)value); return ProcessString.ConvertCommaToCultureSettings((string)value);
} }
catch (Exception) catch (Exception)
{ {

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units; using StructureHelperCommon.Services.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -12,8 +13,19 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{ {
internal class Stress : UnitBase internal class Stress : UnitBase
{ {
public override UnitTypes UnitType { get => UnitTypes.Stress; } public override UnitTypes UnitType { get => UnitTypes.Stress; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "MPa"); } public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "MPa"); }
public override string UnitName { get => "Stress"; } public override string UnitName { get => "Stress"; }
public Stress()
{
OperationLogic = new ConvertUnitLogic()
{
MathRoundLogic = new SmartRoundLogic()
{
DigitQuant = 3
}
};
}
} }
} }

View File

@@ -1,4 +1,7 @@
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units; using StructureHelperCommon.Services.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -14,19 +17,61 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{ {
internal abstract class UnitBase : IValueConverter internal abstract class UnitBase : IValueConverter
{ {
IMathRoundLogic roundLogic = new DirectRoundLogic();
public IConvertUnitLogic OperationLogic { get; set; } = new ConvertUnitLogic();
public IGetUnitLogic UnitLogic { get; set; } = new GetUnitLogic();
public abstract UnitTypes UnitType { get; } public abstract UnitTypes UnitType { get; }
public abstract IUnit CurrentUnit { get; } public abstract IUnit CurrentUnit { get; }
public abstract string UnitName { get;} public abstract string UnitName { get;}
/// <summary>
/// From variable to user
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
return CommonOperation.Convert(CurrentUnit, UnitName, value); var pair = OperationLogic.Convert(CurrentUnit, UnitName, value);
var result = pair.Value;
if (parameter is not null)
{
if (parameter is string paramString)
{
var logic = new ProcessDoublePairLogic() { DigitPlace = DigitPlace.Any };
var paramPair = logic.GetValuePairByString(paramString);
string paramTextPart = paramPair.Text.ToLower();
int paramValuePart = (int)paramPair.Value;
if (paramTextPart == "smart")
{
roundLogic = new SmartRoundLogic() { DigitQuant = paramValuePart };
} }
else if (paramTextPart == "fixed")
{
roundLogic = new FixedRoundLogic() { DigitQuant = paramValuePart };
}
result = roundLogic.RoundValue(result);
}
}
string strValue = $"{result} {pair.Text}";
return strValue;
}
/// <summary>
/// From user to variable
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
try try
{ {
return CommonOperation.ConvertBack(UnitType, CurrentUnit, value); double result = OperationLogic.ConvertBack(UnitType, CurrentUnit, value);
return result;
} }
catch (Exception) catch (Exception)
{ {

View File

@@ -12,5 +12,6 @@
<convertersUnits:Moment x:Key="MomentConverter"/> <convertersUnits:Moment x:Key="MomentConverter"/>
<convertersUnits:Stress x:Key="StressConverter"/> <convertersUnits:Stress x:Key="StressConverter"/>
<convertersUnits:Curvature x:Key="Curvature"/> <convertersUnits:Curvature x:Key="Curvature"/>
<convertersUnits:CrackWidth x:Key="CrackWidth"/>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -1,7 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="CrackTextBox"> <DataTemplate x:Key="CrackTextBox">
<TextBlock Grid.Row="0" Text="{Binding CrackWidth, Converter={StaticResource LengthConverter}}"> <TextBlock Grid.Row="0" Text="{Binding CrackWidth, Converter={StaticResource LengthConverter}}" HorizontalAlignment="Right">
<TextBlock.Style> <TextBlock.Style>
<Style TargetType="TextBlock"> <Style TargetType="TextBlock">
<Style.Triggers> <Style.Triggers>

View File

@@ -12,8 +12,11 @@ namespace StructureHelper.Services.ResultViewers
public static class CrackResultFuncFactory public static class CrackResultFuncFactory
{ {
static IUnit unitStress = CommonOperation.GetUnit(UnitTypes.Stress); private static readonly IConvertUnitLogic operationLogic = new ConvertUnitLogic();
static IUnit unitLength = CommonOperation.GetUnit(UnitTypes.Length, "mm"); private static readonly IGetUnitLogic UnitLogic = new GetUnitLogic();
static IUnit unitStress = UnitLogic.GetUnit(UnitTypes.Stress);
static IUnit unitLength = UnitLogic.GetUnit(UnitTypes.Length, "mm");
public static List<CrackResultFunc> GetResultFuncs() public static List<CrackResultFunc> GetResultFuncs()
{ {

View File

@@ -20,10 +20,11 @@ namespace StructureHelper.Services.ResultViewers
} }
public static class ForceResultFuncFactory public static class ForceResultFuncFactory
{ {
static IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force); static IGetUnitLogic unitLogic = new GetUnitLogic();
static IUnit unitStress = CommonOperation.GetUnit(UnitTypes.Stress); static IUnit unitForce = unitLogic.GetUnit(UnitTypes.Force);
static IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment); static IUnit unitStress = unitLogic.GetUnit(UnitTypes.Stress);
static IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); static IUnit unitMoment = unitLogic.GetUnit(UnitTypes.Moment);
static IUnit unitCurvature = unitLogic.GetUnit(UnitTypes.Curvature);
static readonly IStressLogic stressLogic = new StressLogic(); static readonly IStressLogic stressLogic = new StressLogic();
public static List<ForceResultFunc> GetResultFuncs(FuncsTypes funcsType = FuncsTypes.Full) public static List<ForceResultFunc> GetResultFuncs(FuncsTypes funcsType = FuncsTypes.Full)

View File

@@ -5,6 +5,7 @@ using LoaderCalculator.Data.Ndms;
using LoaderCalculator.Data.ResultData; using LoaderCalculator.Data.ResultData;
using LoaderCalculator.Logics; using LoaderCalculator.Logics;
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
using StructureHelperLogics.NdmCalculations.Cracking; using StructureHelperLogics.NdmCalculations.Cracking;
using StructureHelperLogics.NdmCalculations.Triangulations; using StructureHelperLogics.NdmCalculations.Triangulations;
using System; using System;
@@ -17,6 +18,7 @@ namespace StructureHelper.Services.ResultViewers
{ {
public static class ShowIsoFieldResult public static class ShowIsoFieldResult
{ {
static IMathRoundLogic roundLogic = new SmartRoundLogic() { DigitQuant = 3 };
public static void ShowResult(IStrainMatrix strainMatrix, IEnumerable<INdm> ndms, IEnumerable<ForceResultFunc> resultFuncs) public static void ShowResult(IStrainMatrix strainMatrix, IEnumerable<INdm> ndms, IEnumerable<ForceResultFunc> resultFuncs)
{ {
var primitiveSets = GetPrimitiveSets(strainMatrix, ndms, resultFuncs); var primitiveSets = GetPrimitiveSets(strainMatrix, ndms, resultFuncs);
@@ -59,7 +61,9 @@ namespace StructureHelper.Services.ResultViewers
private static IValuePrimitive ProcessNdm(CrackResultFunc valDelegate, RebarCrackResult rebarResult) private static IValuePrimitive ProcessNdm(CrackResultFunc valDelegate, RebarCrackResult rebarResult)
{ {
var val = valDelegate.ResultFunction.Invoke(rebarResult) * valDelegate.UnitFactor; double delegateResult = valDelegate.ResultFunction.Invoke(rebarResult);
var val = delegateResult * valDelegate.UnitFactor;
//val = roundLogic.RoundValue(val);
IValuePrimitive valuePrimitive; IValuePrimitive valuePrimitive;
var rebarNdm = rebarResult.RebarPrimitive.GetRebarNdm(new TriangulationOptions() var rebarNdm = rebarResult.RebarPrimitive.GetRebarNdm(new TriangulationOptions()
{ {
@@ -73,7 +77,9 @@ namespace StructureHelper.Services.ResultViewers
private static IValuePrimitive ProcessNdm(IStrainMatrix strainMatrix, ForceResultFunc valDelegate, INdm ndm) private static IValuePrimitive ProcessNdm(IStrainMatrix strainMatrix, ForceResultFunc valDelegate, INdm ndm)
{ {
double val = valDelegate.ResultFunction.Invoke(strainMatrix, ndm) * valDelegate.UnitFactor; double delegateResult = valDelegate.ResultFunction.Invoke(strainMatrix, ndm);
double val = delegateResult * valDelegate.UnitFactor;
//val = roundLogic.RoundValue(val);
IValuePrimitive valuePrimitive; IValuePrimitive valuePrimitive;
if (ndm is IRectangleNdm shapeNdm) if (ndm is IRectangleNdm shapeNdm)
{ {

View File

@@ -21,6 +21,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
{ {
internal class CrackDiagramLogic : ILongProcessLogic internal class CrackDiagramLogic : ILongProcessLogic
{ {
static IConvertUnitLogic operationLogic = new ConvertUnitLogic();
static IGetUnitLogic unitLogic = new GetUnitLogic();
static readonly CrackForceCalculator calculator = new(); static readonly CrackForceCalculator calculator = new();
private ITriangulatePrimitiveLogic triangulateLogic; private ITriangulatePrimitiveLogic triangulateLogic;
@@ -67,9 +69,9 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
arrayParameter = new ArrayParameter<double>(ValidTupleList.Count(), labels); arrayParameter = new ArrayParameter<double>(ValidTupleList.Count(), labels);
CalculateWithCrack(ValidTupleList, CalculateWithCrack(ValidTupleList,
NdmPrimitives, NdmPrimitives,
CommonOperation.GetUnit(UnitTypes.Force), unitLogic.GetUnit(UnitTypes.Force),
CommonOperation.GetUnit(UnitTypes.Moment), unitLogic.GetUnit(UnitTypes.Moment),
CommonOperation.GetUnit(UnitTypes.Curvature)); unitLogic.GetUnit(UnitTypes.Curvature));
} }
public void ShowWindow() public void ShowWindow()
@@ -152,7 +154,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
const string crc = "Crc"; const string crc = "Crc";
const string crcFactor = "CrcSofteningFactor"; const string crcFactor = "CrcSofteningFactor";
var labels = LabelsFactory.GetCommonLabels(); var labels = LabelsFactory.GetCommonLabels();
IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); IUnit unitCurvature = unitLogic.GetUnit(UnitTypes.Curvature);
var crclabels = new List<string> var crclabels = new List<string>
{ {
$"{crc}{GeometryNames.CurvFstName}, {unitCurvature.Name}", $"{crc}{GeometryNames.CurvFstName}, {unitCurvature.Name}",

View File

@@ -6,13 +6,29 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews" xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews"
d:DataContext="{d:DesignInstance local:CrackCalculatorInputDataViewModel}" d:DataContext="{d:DesignInstance local:CrackCalculatorInputDataViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="CrackCalculatorInputDataView" Height="390" Width="400" MinHeight="300" MinWidth="400" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Closing="Window_Closing"> Title="{Binding WindowTitle}" Height="390" Width="400" MinHeight="300" MinWidth="400"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
Closing="Window_Closing" ShowInTaskbar="False" Icon="{Binding Mode=OneWay, Source={StaticResource CrackCalculator}}"
>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition/>
<RowDefinition Height="35"/> <RowDefinition Height="35"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TabControl> <TabControl>
<TabItem Header="General">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Name"/>
<TextBox Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</StackPanel>
</TabItem>
<TabItem Header="Forces"> <TabItem Header="Forces">
<ContentControl ContentTemplate="{StaticResource SourceToTarget}" Content="{Binding CombinationViewModel}"/> <ContentControl ContentTemplate="{StaticResource SourceToTarget}" Content="{Binding CombinationViewModel}"/>
</TabItem> </TabItem>

View File

@@ -14,12 +14,25 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
{ {
public class CrackCalculatorInputDataViewModel : OkCancelViewModelBase public class CrackCalculatorInputDataViewModel : OkCancelViewModelBase
{ {
private CrackCalculator calculator;
CrackInputData crackInputData; CrackInputData crackInputData;
private bool setUserValueSofteningFactor; private bool setUserValueSofteningFactor;
private double softeningFactor; private double softeningFactor;
private string name;
public SourceTargetVM<IForceAction> CombinationViewModel { get; } public SourceTargetVM<IForceAction> CombinationViewModel { get; }
public SourceTargetVM<PrimitiveBase> PrimitivesViewModel { get; private set; } public SourceTargetVM<PrimitiveBase> PrimitivesViewModel { get; private set; }
public string WindowTitle => "Crack calculator: " + Name;
public string Name
{
get => calculator.Name;
set
{
calculator.Name = value;
OnPropertyChanged(nameof(Name));
OnPropertyChanged(nameof(WindowTitle));
}
}
public bool SetSofteningFactor public bool SetSofteningFactor
{ {
get => crackInputData.UserCrackInputData.SetSofteningFactor; get => crackInputData.UserCrackInputData.SetSofteningFactor;
@@ -78,7 +91,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
public CrackCalculatorInputDataViewModel(IEnumerable<INdmPrimitive> allowedPrimitives, IEnumerable<IForceAction> allowedCombinations, CrackCalculator crackCalculator) public CrackCalculatorInputDataViewModel(IEnumerable<INdmPrimitive> allowedPrimitives, IEnumerable<IForceAction> allowedCombinations, CrackCalculator crackCalculator)
{ {
crackInputData = crackCalculator.InputData; calculator = crackCalculator;
crackInputData = calculator.InputData;
CombinationViewModel = SourceTargetFactory.GetSourceTargetVM(allowedCombinations, crackInputData.ForceActions); CombinationViewModel = SourceTargetFactory.GetSourceTargetVM(allowedCombinations, crackInputData.ForceActions);
PrimitivesViewModel = SourceTargetFactory.GetSourceTargetVM(allowedPrimitives, crackInputData.Primitives); PrimitivesViewModel = SourceTargetFactory.GetSourceTargetVM(allowedPrimitives, crackInputData.Primitives);
} }

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews" xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews"
d:DataContext="{d:DesignInstance local:CrackResultViewModel}" d:DataContext="{d:DesignInstance local:CrackResultViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="Result of calculations of crack" Height="450" Width="800" MinHeight="300" MinWidth="600" MaxHeight="800" MaxWidth="1000" WindowStartupLocation="CenterScreen"> Title="Result of calculations of crack" Height="450" Width="800" MinHeight="300" MinWidth="600" MaxHeight="800" MaxWidth="1000" WindowStartupLocation="CenterScreen" ShowInTaskbar="False">
<Window.Resources> <Window.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
@@ -55,8 +55,8 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Long-term" /> <TextBlock Grid.Row="0" Text="Long-term"/>
<TextBlock Grid.Row="1" Text="Short-term" /> <TextBlock Grid.Row="1" Text="Short-term"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@@ -69,8 +69,8 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.Mx, Converter={StaticResource MomentConverter}}" /> <TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.Mx, Converter={StaticResource MomentConverter}}" HorizontalAlignment="Right" />
<TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.Mx, Converter={StaticResource MomentConverter}}" /> <TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.Mx, Converter={StaticResource MomentConverter}}" HorizontalAlignment="Right" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@@ -83,8 +83,8 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.My, Converter={StaticResource MomentConverter}}" /> <TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.My, Converter={StaticResource MomentConverter}}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.My, Converter={StaticResource MomentConverter}}" /> <TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.My, Converter={StaticResource MomentConverter}}" HorizontalAlignment="Right" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@@ -97,13 +97,13 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.Nz, Converter={StaticResource MomentConverter}}" /> <TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.Nz, Converter={StaticResource ForceConverter}}" HorizontalAlignment="Right" />
<TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.Nz, Converter={StaticResource ForceConverter}}" /> <TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.Nz, Converter={StaticResource ForceConverter}}" HorizontalAlignment="Right" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTemplateColumn Header="Crack width" Width="140"> <DataGridTemplateColumn Header="Crack width" Width="80">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ContentControl ContentTemplate="{StaticResource CrackGrid}" Content="{Binding}"/> <ContentControl ContentTemplate="{StaticResource CrackGrid}" Content="{Binding}"/>

View File

@@ -1,7 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="CrackTextBox"> <DataTemplate x:Key="CrackTextBox">
<TextBlock Grid.Row="0" Text="{Binding CrackWidth, Converter={StaticResource LengthConverter}}"> <TextBlock Grid.Row="0" Text="{Binding CrackWidth, Converter={StaticResource CrackWidth}, ConverterParameter='Fixed3'}" HorizontalAlignment="Right">
<TextBlock.Style> <TextBlock.Style>
<Style TargetType="TextBlock"> <Style TargetType="TextBlock">
<Style.Triggers> <Style.Triggers>

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews" xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews"
d:DataContext="{d:DesignInstance local:TupleCrackResultViewModel}" d:DataContext="{d:DesignInstance local:TupleCrackResultViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="{Binding WindowName}" Height="450" Width="1000" MinHeight="300" MinWidth="500" MaxHeight="1000" MaxWidth="1200" WindowStartupLocation="CenterScreen"> Title="{Binding WindowTitle}" Height="450" Width="900" MinHeight="300" MinWidth="500" MaxHeight="1000" MaxWidth="1400" WindowStartupLocation="CenterScreen" ShowInTaskbar="False">
<Window.Resources> <Window.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
@@ -51,7 +51,7 @@
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTemplateColumn Header="Softening factor" Width="120"> <DataGridTemplateColumn Header="Softening factor" Width="100">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
@@ -59,13 +59,13 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.SofteningFactor, Converter={StaticResource PlainDouble}}" /> <TextBlock Grid.Row="0" Text="{Binding LongTermResult.SofteningFactor, Converter={StaticResource PlainDouble}, StringFormat=F3}" HorizontalAlignment="Right" />
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.SofteningFactor, Converter={StaticResource PlainDouble}}" /> <TextBlock Grid.Row="1" Text="{Binding ShortTermResult.SofteningFactor, Converter={StaticResource PlainDouble}, StringFormat=F3}" HorizontalAlignment="Right" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTemplateColumn Header="Rebar stress" Width="120"> <DataGridTemplateColumn Header="Rebar stress" Width="80">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
@@ -73,13 +73,13 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStress, Converter={StaticResource StressConverter}}"/> <TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStress, Converter={StaticResource StressConverter}, ConverterParameter='Smart3'}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.RebarStress, Converter={StaticResource StressConverter}}"/> <TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.RebarStress, Converter={StaticResource StressConverter}, ConverterParameter='Smart3'}" HorizontalAlignment="Right"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTemplateColumn Header="Rebar strain" Width="120"> <DataGridTemplateColumn Header="Rebar strain" Width="80">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
@@ -87,8 +87,8 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStrain}"/> <TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.RebarStrain}"/> <TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.RebarStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@@ -101,13 +101,13 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.ConcreteStrain}"/> <TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.ConcreteStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.ConcreteStrain}"/> <TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.ConcreteStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTemplateColumn Header="Crack width" Width="140"> <DataGridTemplateColumn Header="Crack width" Width="80">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ContentControl ContentTemplate="{StaticResource CrackGrid}" Content="{Binding}"/> <ContentControl ContentTemplate="{StaticResource CrackGrid}" Content="{Binding}"/>

View File

@@ -27,7 +27,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
public TupleCrackResult CrackResult => crackResult; public TupleCrackResult CrackResult => crackResult;
public List<RebarCrackResult> RebarResults => crackResult.RebarResults; public List<RebarCrackResult> RebarResults => crackResult.RebarResults;
public RebarCrackResult SelectedResult { get; set; } public RebarCrackResult SelectedResult { get; set; }
public string WindowName => "Result of calculation of cracks for action " + crackResult.InputData.TupleName; public string WindowTitle => "Result of calculation of cracks for action " + crackResult.InputData.TupleName;
public ICommand ShowIsoFieldCommand public ICommand ShowIsoFieldCommand
{ {
get get

View File

@@ -15,6 +15,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
/// </summary> /// </summary>
public class DiagramFactory public class DiagramFactory
{ {
IConvertUnitLogic operationLogic = new ConvertUnitLogic();
IGetUnitLogic unitLogic = new GetUnitLogic();
private ArrayParameter<double> arrayParameter; private ArrayParameter<double> arrayParameter;
/// <summary> /// <summary>
/// Collection of force results /// Collection of force results
@@ -48,9 +50,9 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
private List<double> ProcessResult(int i) private List<double> ProcessResult(int i)
{ {
var unitForce = CommonOperation.GetUnit(UnitTypes.Force); var unitForce = unitLogic.GetUnit(UnitTypes.Force);
var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment); var unitMoment = unitLogic.GetUnit(UnitTypes.Moment);
var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); var unitCurvature = unitLogic.GetUnit(UnitTypes.Curvature);
return new List<double> return new List<double>
{ {

View File

@@ -25,10 +25,12 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
const string ForceUnitString = "kN"; const string ForceUnitString = "kN";
const string MomentUnitString = "kNm"; const string MomentUnitString = "kNm";
IConvertUnitLogic operationLogic;
//private List<ArrayParameter<double>> arrayParameters; //private List<ArrayParameter<double>> arrayParameters;
private IResult result; private IResult result;
private IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force, ForceUnitString); private IUnit unitForce;
private IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, MomentUnitString); private IUnit unitMoment;
private int stepCount; private int stepCount;
private static GeometryNames GeometryNames => ProgramSetting.GeometryNames; private static GeometryNames GeometryNames => ProgramSetting.GeometryNames;
@@ -48,6 +50,10 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
stepCount *= InputData.CalcTerms.Count(); stepCount *= InputData.CalcTerms.Count();
stepCount *= InputData.PredicateEntries.Count(); stepCount *= InputData.PredicateEntries.Count();
//arrayParameters = new(); //arrayParameters = new();
operationLogic = new ConvertUnitLogic();
IGetUnitLogic unitLogic = new GetUnitLogic();
unitForce = unitLogic.GetUnit(UnitTypes.Force, ForceUnitString);
unitMoment = unitLogic.GetUnit(UnitTypes.Moment, MomentUnitString);
} }
private void DoCalculations() private void DoCalculations()

View File

@@ -11,9 +11,11 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
{ {
public static class LabelsFactory public static class LabelsFactory
{ {
private static IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force); static IConvertUnitLogic operationLogic = new ConvertUnitLogic();
private static IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment); static IGetUnitLogic unitLogic = new GetUnitLogic();
private static IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); private static IUnit unitForce = unitLogic.GetUnit(UnitTypes.Force);
private static IUnit unitMoment = unitLogic.GetUnit(UnitTypes.Moment);
private static IUnit unitCurvature = unitLogic.GetUnit(UnitTypes.Curvature);
private static GeometryNames GeometryNames => ProgramSetting.GeometryNames; private static GeometryNames GeometryNames => ProgramSetting.GeometryNames;
public static List<string> GetCommonLabels() public static List<string> GetCommonLabels()
{ {

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews" xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews"
d:DataContext="{d:DesignInstance local:ForcesResultsViewModel}" d:DataContext="{d:DesignInstance local:ForcesResultsViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="Calculation Results" Height="350" Width="850" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen"> Title="Calculation Results" Height="350" Width="850" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen" ShowInTaskbar="False">
<DockPanel> <DockPanel>
<ToolBarTray DockPanel.Dock="Top"> <ToolBarTray DockPanel.Dock="Top">
<ToolBar> <ToolBar>

View File

@@ -21,7 +21,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
{ {
const string ForceUnitString = "kN"; const string ForceUnitString = "kN";
const string MomentUnitString = "kNm"; const string MomentUnitString = "kNm";
static IConvertUnitLogic operationLogic = new ConvertUnitLogic();
static IGetUnitLogic unitLogic = new GetUnitLogic();
public SurroundData SurroundData public SurroundData SurroundData
{ {
get => surroundData; set get => surroundData; set
@@ -47,8 +48,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
OnPropertyChanged(nameof(ZUnitLabel)); OnPropertyChanged(nameof(ZUnitLabel));
} }
private static readonly IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force, ForceUnitString); private static IUnit unitForce = unitLogic.GetUnit(UnitTypes.Force, ForceUnitString);
private static readonly IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, MomentUnitString); private static IUnit unitMoment = unitLogic.GetUnit(UnitTypes.Moment, MomentUnitString);
private SurroundData surroundData; private SurroundData surroundData;
public IValueConverter ForceConverter { get => new Force(); } public IValueConverter ForceConverter { get => new Force(); }

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.ProgressViews" xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.ProgressViews"
d:DataContext="{d:DesignInstance local:TraceDocumentVM}" d:DataContext="{d:DesignInstance local:TraceDocumentVM}"
mc:Ignorable="d" mc:Ignorable="d"
Title="Trace Document Viewer" Height="450" Width="800" MinHeight="400" MinWidth="600" WindowStartupLocation="CenterScreen"> Title="Trace Document Viewer" Height="450" Width="800" MinHeight="400" MinWidth="600" WindowStartupLocation="CenterScreen" ShowInTaskbar="False">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>

View File

@@ -25,6 +25,7 @@ namespace StructureHelper.Windows.UserControls
/// </summary> /// </summary>
public partial class MultiplyDouble : UserControl public partial class MultiplyDouble : UserControl
{ {
IConvertUnitLogic operationLogic = new ConvertUnitLogic();
public event EventHandler ValueChanged; public event EventHandler ValueChanged;
public MultiplyDouble() public MultiplyDouble()
@@ -40,7 +41,7 @@ namespace StructureHelper.Windows.UserControls
try try
{ {
string s = (string)o; string s = (string)o;
double factor = CommonOperation.ConvertToDoubleChangeComma(s); double factor = ProcessString.ConvertCommaToCultureSettings(s);
ChangeValue(factor); ChangeValue(factor);
} }
catch(Exception ex) catch(Exception ex)

View File

@@ -0,0 +1,7 @@
namespace StructureHelperCommon.Models.Parameters
{
public interface IProcessValuePairLogic<T>
{
ValuePair<T> GetValuePairByString(string s);
}
}

View File

@@ -0,0 +1,12 @@
namespace StructureHelperCommon.Models.Parameters
{
/// <summary>
/// Represent pair of value with text
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IValuePair<T>
{
string Text { get; set; }
T Value { get; set; }
}
}

View File

@@ -7,14 +7,12 @@ using System.Windows.Media;
namespace StructureHelperCommon.Models.Parameters namespace StructureHelperCommon.Models.Parameters
{ {
public interface IValueParameter<T> public interface IValueParameter<T> : IValuePair<T>
{ {
bool IsValid { get; set; } bool IsValid { get; set; }
string Name { get; set; } string Name { get; set; }
string ShortName { get; set; } string ShortName { get; set; }
Color Color { get; set; } Color Color { get; set; }
string MeasurementUnit { get; set; }
T Value { get; set; }
string Description { get; set; } string Description { get; set; }
} }
} }

View File

@@ -0,0 +1,65 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;
namespace StructureHelperCommon.Models.Parameters
{
public enum DigitPlace
{
Start,
Any
}
public class ProcessDoublePairLogic : IProcessValuePairLogic<double>
{
const string digitalPattern = @"^[-]?[+]?\d*\.?\,?\d*";
const string allowedPattern = @"[0-9]|\.|\,";
const string characterPattern = "[a-z]+$";
const string target = "";
public DigitPlace DigitPlace { get; set; } = DigitPlace.Start;
public ValuePair<double> GetValuePairByString(string s)
{
s = s.Replace(" ", string.Empty);
Regex regexText = new (allowedPattern);
string textString = regexText.Replace(s, target);
var textMatch = Regex.Match(textString, characterPattern, RegexOptions.IgnoreCase);
if (textMatch.Success == true)
{
textString = textMatch.Value.ToLower();
}
var digitalOnlyString = DigitPlace == DigitPlace.Start ? s : s.ToLower().Replace(textString, string.Empty);
var match = Regex.Match(digitalOnlyString, digitalPattern);
if (match.Success == true)
{
return GetDoubleValue(textString, match);
}
throw new StructureHelperException(ErrorStrings.DataIsInCorrect);
}
private static ValuePair<double> GetDoubleValue(string textString, Match match)
{
string digitalString = match.Value;
if (digitalString != string.Empty || digitalString != "")
{
double digit = ProcessString.ConvertCommaToCultureSettings(digitalString);
return new ValuePair<double>()
{
Value = digit,
Text = textString
};
}
else
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": value does not contain digital simbols");
}
}
}
}

View File

@@ -4,11 +4,12 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StructureHelperCommon.Services.Units namespace StructureHelperCommon.Models.Parameters
{ {
internal class StringDoublePair : IStringDoublePair /// <inheritdoc/>
public class ValuePair<T> : IValuePair<T>
{ {
public double Digit { get; set; }
public string Text { get; set; } public string Text { get; set; }
public T Value { get; set; }
} }
} }

View File

@@ -13,7 +13,7 @@ namespace StructureHelperCommon.Models.Parameters
public string Name { get; set; } public string Name { get; set; }
public string ShortName { get; set; } public string ShortName { get; set; }
public Color Color { get; set; } public Color Color { get; set; }
public string MeasurementUnit { get; set; } public string Text { get; set; }
public T Value { get; set; } public T Value { get; set; }
public string Description { get; set; } public string Description { get; set; }
} }

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services
{
public class DirectRoundLogic : IMathRoundLogic
{
public double RoundValue(double value)
{
return value;
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services
{
public class FixedRoundLogic : IDigitRoundLogic
{
public int DigitQuant { get; set; }
/// <summary>
/// Умное окруление до нужного числа значащих цифр, например (12345, 3) дает результат 12300, например (0.12345, 3) дает результат 0,123
/// </summary>
/// <param name="value"></param>
/// <param name="quant"></param>
/// <returns></returns>
public double RoundValue(double value)
{
double roundedValue = Math.Round(value, DigitQuant);
return roundedValue;
}
}
}

View File

@@ -0,0 +1,7 @@
namespace StructureHelperCommon.Services
{
public interface IDigitRoundLogic : IMathRoundLogic
{
int DigitQuant { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace StructureHelperCommon.Services
{
public interface IMathRoundLogic
{
double RoundValue(double value);
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services
{
public class SmartRoundLogic : IDigitRoundLogic
{
public int DigitQuant { get; set; } = 3;
/// <summary>
/// Умное окруление до нужного числа значащих цифр, например (12345, 3) дает результат 12300, например (0.12345, 3) дает результат 0,123
/// </summary>
/// <param name="value"></param>
/// <param name="quant"></param>
/// <returns></returns>
public double RoundValue(double value)
{
if (value == 0d) return 0d;
double valueOrder = Math.Log10(Math.Abs(value));
int order = Convert.ToInt32(Math.Ceiling(valueOrder));
double requiredOrder = Math.Pow(10, DigitQuant - order);
double roundedAbsValue = Math.Round(Math.Abs(value) * requiredOrder) / requiredOrder;
double roundedValue = Math.Sign(value) * roundedAbsValue;
return roundedValue;
}
}
}

View File

@@ -1,116 +0,0 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Documents;
namespace StructureHelperCommon.Services.Units
{
public static class CommonOperation
{
private static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
public static double ConvertToDoubleChangeComma(string s)
{
double result;
if (!double.TryParse(s, NumberStyles.Any, CultureInfo.CurrentCulture, out result) &&
!double.TryParse(s, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out result) &&
!double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
{
throw new StructureHelperException($"{ErrorStrings.IncorrectValue}: {s}");
}
return result;
}
public static IStringDoublePair DivideIntoStringDoublePair(string s)
{
s = s.Replace(" ", "");
//string digitPattern = @"^[-]?[+]?\d+(\.?)|(\,?)\d*";
string digitPattern = @"^[-]?[+]?\d*\.?\,?\d*";
string textPattern = @"[0-9]|\.|\,";
string caracterPattern = "[a-z]+$";
string target = "";
Regex regexText = new Regex(textPattern);
string textString = regexText.Replace(s, target);
var textMatch = Regex.Match(textString, caracterPattern, RegexOptions.IgnoreCase);
if (textMatch.Success) {textString = textMatch.Value.ToLower();}
var match = Regex.Match(s, digitPattern);
if (match.Success)
{
string digitString = match.Value;
double digit = ConvertToDoubleChangeComma(digitString);
return new StringDoublePair() { Digit = digit, Text = textString };
}
throw new StructureHelperException(ErrorStrings.DataIsInCorrect);
}
public static IUnit GetUnit(UnitTypes unitType, string unitName = null)
{
if (unitName is null)
{
var boolResult = DefaultUnitNames.TryGetValue(unitType, out unitName);
if (boolResult == false)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": unit type{unitType} is unknown");
}
}
return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single();
}
public static Dictionary<UnitTypes, string> DefaultUnitNames => new()
{
{ UnitTypes.Length, "m"},
{ UnitTypes.Area, "m2"},
{ UnitTypes.Force, "kN" },
{ UnitTypes.Moment, "kNm"},
{ UnitTypes.Stress, "MPa"},
{ UnitTypes.Curvature, "1/m"},
};
public static string Convert(IUnit unit, string unitName, object value)
{
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= unit.Multiplyer;
string strValue = $"{val} {unit.Name}";
return strValue;
}
public static double ConvertBack(UnitTypes unitType, IUnit unit, object value)
{
double val;
double multy;
double coefficient = unit.Multiplyer;
var strVal = value as string;
IStringDoublePair pair = DivideIntoStringDoublePair(strVal);
try
{
multy = GetMultiplyer(unitType, pair.Text);
}
catch (Exception ex)
{
multy = coefficient;
}
val = pair.Digit / multy;
return val;
}
public static double GetMultiplyer(UnitTypes unitType, string unitName)
{
try
{
return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single().Multiplyer;
}
catch (Exception ex)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ex);
}
}
}
}

View File

@@ -0,0 +1,85 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Documents;
namespace StructureHelperCommon.Services.Units
{
public class ConvertUnitLogic : IConvertUnitLogic
{
private static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
private static IProcessValuePairLogic<double> pairLogic = new ProcessDoublePairLogic();
public IMathRoundLogic MathRoundLogic { get; set; } = new DirectRoundLogic();
public ValuePair<double> Convert(IUnit unit, string unitName, object value)
{
double val;
if (value != null)
{
try
{
val = (double)value;
}
catch (Exception ex)
{
throw new StructureHelperException($"{ErrorStrings.IncorrectValue}");
}
}
else
{
throw new StructureHelperException($"{ErrorStrings.ParameterIsNull}: {unitName}");
}
val *= unit.Multiplyer;
var pair = new ValuePair<double>
{
Text = unit.Name,
Value = val
};
return pair;
}
public double ConvertBack(UnitTypes unitType, IUnit unit, object value)
{
double val;
double multy;
double factor = unit.Multiplyer;
var strVal = value as string;
var pair = pairLogic.GetValuePairByString(strVal);
try
{
multy = GetMultiplyer(unitType, pair.Text);
}
catch (Exception ex)
{
multy = factor;
}
val = pair.Value / multy;
return val;
}
private double GetMultiplyer(UnitTypes unitType, string unitName)
{
try
{
return units
.Where(u =>
u.UnitType == unitType
&
u.Name == unitName)
.Single()
.Multiplyer;
}
catch (Exception ex)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ex);
}
}
}
}

View File

@@ -0,0 +1,50 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services.Units
{
public class GetUnitLogic : IGetUnitLogic
{
private static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
private Dictionary<UnitTypes, string> defaultUnitNames;
public GetUnitLogic()
{
defaultUnitNames = new()
{
{ UnitTypes.Length, "m"},
{ UnitTypes.Area, "m2"},
{ UnitTypes.Force, "kN" },
{ UnitTypes.Moment, "kNm"},
{ UnitTypes.Stress, "MPa"},
{ UnitTypes.Curvature, "1/m"},
};
}
public IUnit GetUnit(UnitTypes unitType, string unitName = null)
{
if (unitName is null)
{
var boolResult = defaultUnitNames.TryGetValue(unitType, out unitName);
if (boolResult == false)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": unit type{unitType} is unknown");
}
}
return units
.Where(u =>
u.UnitType == unitType
&
u.Name == unitName)
.Single();
}
}
}

View File

@@ -0,0 +1,13 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Parameters;
using System.Collections.Generic;
namespace StructureHelperCommon.Services.Units
{
public interface IConvertUnitLogic
{
IMathRoundLogic MathRoundLogic { get; set; }
ValuePair<double> Convert(IUnit unit, string unitName, object value);
double ConvertBack(UnitTypes unitType, IUnit unit, object value);
}
}

View File

@@ -0,0 +1,9 @@
using StructureHelperCommon.Infrastructures.Enums;
namespace StructureHelperCommon.Services.Units
{
public interface IGetUnitLogic
{
IUnit GetUnit(UnitTypes unitType, string unitName = null);
}
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services.Units
{
public interface IStringDoublePair
{
double Digit { get; }
string Text { get; }
}
}

View File

@@ -0,0 +1,25 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services.Units
{
public static class ProcessString
{
public static double ConvertCommaToCultureSettings(string s)
{
double result;
if (!double.TryParse(s, NumberStyles.Any, CultureInfo.CurrentCulture, out result) &&
!double.TryParse(s, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out result) &&
!double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
{
throw new StructureHelperException($"{ErrorStrings.IncorrectValue}: {s}");
}
return result;
}
}
}

View File

@@ -5,6 +5,10 @@ namespace StructureHelperCommon.Services.Units
{ {
public static class UnitsFactory public static class UnitsFactory
{ {
/// <summary>
/// Returns collection of unit
/// </summary>
/// <returns></returns>
public static List<IUnit> GetUnitCollection() public static List<IUnit> GetUnitCollection()
{ {
List<IUnit> units = new List<IUnit>(); List<IUnit> units = new List<IUnit>();
@@ -28,8 +32,8 @@ namespace StructureHelperCommon.Services.Units
type = UnitTypes.Moment; type = UnitTypes.Moment;
units.Add(new Unit() { UnitType = type, Name = "Nm", Multiplyer = 1d }); units.Add(new Unit() { UnitType = type, Name = "Nm", Multiplyer = 1d });
units.Add(new Unit() { UnitType = type, Name = "kNm", Multiplyer = 1e-3d }); units.Add(new Unit() { UnitType = type, Name = "kNm", Multiplyer = 1e-3d });
units.Add(new Unit() { UnitType = type, Name = "kgfm", Multiplyer = 9.8d }); units.Add(new Unit() { UnitType = type, Name = "kgfm", Multiplyer = 9.81d });
units.Add(new Unit() { UnitType = type, Name = "tfm", Multiplyer = 9.8e-3d }); units.Add(new Unit() { UnitType = type, Name = "tfm", Multiplyer = 9.81e-3d });
type = UnitTypes.Curvature; type = UnitTypes.Curvature;
units.Add(new Unit() { UnitType = type, Name = "1/m", Multiplyer = 1d }); units.Add(new Unit() { UnitType = type, Name = "1/m", Multiplyer = 1d });
units.Add(new Unit() { UnitType = type, Name = "1/mm", Multiplyer = 1e-3d }); units.Add(new Unit() { UnitType = type, Name = "1/mm", Multiplyer = 1e-3d });

View File

@@ -55,7 +55,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
{ {
item.Name, item.Name,
item.ShortName, item.ShortName,
item.MeasurementUnit, item.Text,
item.Value.ToString(), item.Value.ToString(),
item.Description item.Description
}; };

View File

@@ -18,6 +18,9 @@ namespace StructureHelperLogics.Services.NdmPrimitives
{ {
const string prefixInitial = "Initial"; const string prefixInitial = "Initial";
const string prefixActual = "Actual"; const string prefixActual = "Actual";
IConvertUnitLogic operationLogic = new ConvertUnitLogic();
IGetUnitLogic unitLogic = new GetUnitLogic();
static string firstAxisName => ProgramSetting.GeometryNames.FstAxisName; static string firstAxisName => ProgramSetting.GeometryNames.FstAxisName;
static string secondAxisName => ProgramSetting.GeometryNames.SndAxisName; static string secondAxisName => ProgramSetting.GeometryNames.SndAxisName;
static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection(); static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
@@ -42,7 +45,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
const string name = "Summary Area"; const string name = "Summary Area";
const string shortName = "A"; const string shortName = "A";
var parameters = new List<IValueParameter<string>>(); var parameters = new List<IValueParameter<string>>();
var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2"); var unitArea = unitLogic.GetUnit(UnitTypes.Area, "mm2");
var unitName = $"{unitArea.Name}"; var unitName = $"{unitArea.Name}";
var unitMultiPlayer = unitArea.Multiplyer; var unitMultiPlayer = unitArea.Multiplyer;
var firstParameter = new ValueParameter<string>() var firstParameter = new ValueParameter<string>()
@@ -50,7 +53,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{name}", Name = $"{name}",
ShortName = $"{shortName}", ShortName = $"{shortName}",
MeasurementUnit = unitName, Text = unitName,
Description = $"{name} of cross-section without reduction" Description = $"{name} of cross-section without reduction"
}; };
try try
@@ -71,8 +74,8 @@ namespace StructureHelperLogics.Services.NdmPrimitives
const string name = "Bending stiffness"; const string name = "Bending stiffness";
const string shortName = "EI"; const string shortName = "EI";
var parameters = new List<IValueParameter<string>>(); var parameters = new List<IValueParameter<string>>();
var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2"); var unitArea = unitLogic.GetUnit(UnitTypes.Area, "mm2");
var unitStress = CommonOperation.GetUnit(UnitTypes.Stress, "MPa"); var unitStress = unitLogic.GetUnit(UnitTypes.Stress, "MPa");
var unitName = $"{unitStress.Name} * {unitArea.Name} * {unitArea.Name}"; var unitName = $"{unitStress.Name} * {unitArea.Name} * {unitArea.Name}";
var unitMultiPlayer = unitArea.Multiplyer * unitArea.Multiplyer * unitStress.Multiplyer; var unitMultiPlayer = unitArea.Multiplyer * unitArea.Multiplyer * unitStress.Multiplyer;
var firstParameter = new ValueParameter<string>() var firstParameter = new ValueParameter<string>()
@@ -80,7 +83,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefix} {name} {firstAxisName.ToUpper()}", Name = $"{prefix} {name} {firstAxisName.ToUpper()}",
ShortName = $"{shortName}{firstAxisName}", ShortName = $"{shortName}{firstAxisName}",
MeasurementUnit = unitName, Text = unitName,
Description = $"{prefix} {name} of cross-section arbitrary {firstAxisName}-axis multiplied by {prefix} modulus" Description = $"{prefix} {name} of cross-section arbitrary {firstAxisName}-axis multiplied by {prefix} modulus"
}; };
var secondParameter = new ValueParameter<string>() var secondParameter = new ValueParameter<string>()
@@ -88,7 +91,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefix} {name} {secondAxisName}", Name = $"{prefix} {name} {secondAxisName}",
ShortName = $"{shortName}{secondAxisName}", ShortName = $"{shortName}{secondAxisName}",
MeasurementUnit = unitName, Text = unitName,
Description = $"{prefix} {name} of cross-section arbitrary {secondAxisName}-axis multiplied by {prefix} modulus" Description = $"{prefix} {name} of cross-section arbitrary {secondAxisName}-axis multiplied by {prefix} modulus"
}; };
try try
@@ -120,7 +123,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefixActual}/{prefixInitial} {name} {firstAxisName.ToUpper()} ratio", Name = $"{prefixActual}/{prefixInitial} {name} {firstAxisName.ToUpper()} ratio",
ShortName = $"{shortName}{firstAxisName}-ratio", ShortName = $"{shortName}{firstAxisName}-ratio",
MeasurementUnit = "-", Text = "-",
Description = $"{prefixActual}/{prefixInitial} {name} of cross-section arbitrary {firstAxisName}-axis ratio" Description = $"{prefixActual}/{prefixInitial} {name} of cross-section arbitrary {firstAxisName}-axis ratio"
}; };
var secondParameter = new ValueParameter<string>() var secondParameter = new ValueParameter<string>()
@@ -128,7 +131,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefixActual}/{prefixInitial} {name} {secondAxisName} ratio", Name = $"{prefixActual}/{prefixInitial} {name} {secondAxisName} ratio",
ShortName = $"{shortName}{secondAxisName}-ratio", ShortName = $"{shortName}{secondAxisName}-ratio",
MeasurementUnit = "-", Text = "-",
Description = $"{prefixActual}/{prefixInitial} {name} of cross-section arbitrary {secondAxisName}-axis ratio" Description = $"{prefixActual}/{prefixInitial} {name} of cross-section arbitrary {secondAxisName}-axis ratio"
}; };
try try
@@ -155,8 +158,8 @@ namespace StructureHelperLogics.Services.NdmPrimitives
const string name = "Longitudinal stiffness"; const string name = "Longitudinal stiffness";
const string shortName = "EA"; const string shortName = "EA";
var parameters = new List<IValueParameter<string>>(); var parameters = new List<IValueParameter<string>>();
var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2"); var unitArea = unitLogic.GetUnit(UnitTypes.Area, "mm2");
var unitStress = CommonOperation.GetUnit(UnitTypes.Stress, "MPa"); var unitStress = unitLogic.GetUnit(UnitTypes.Stress, "MPa");
var unitName = $"{unitStress.Name} * {unitArea.Name}" ; var unitName = $"{unitStress.Name} * {unitArea.Name}" ;
var unitMultiPlayer = unitArea.Multiplyer * unitStress.Multiplyer; var unitMultiPlayer = unitArea.Multiplyer * unitStress.Multiplyer;
var firstParameter = new ValueParameter<string>() var firstParameter = new ValueParameter<string>()
@@ -164,7 +167,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefix} {name}", Name = $"{prefix} {name}",
ShortName = $"{shortName}", ShortName = $"{shortName}",
MeasurementUnit = unitName, Text = unitName,
Description = $"{prefix} {name} of cross-section multiplied by {prefix} modulus" Description = $"{prefix} {name} of cross-section multiplied by {prefix} modulus"
}; };
try try
@@ -190,7 +193,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefixActual}/{prefixInitial} {name} ratio", Name = $"{prefixActual}/{prefixInitial} {name} ratio",
ShortName = $"{shortName}-ratio", ShortName = $"{shortName}-ratio",
MeasurementUnit = "-", Text = "-",
Description = $"{prefixActual}/{prefixInitial} {name}-ratio of cross-section" Description = $"{prefixActual}/{prefixInitial} {name}-ratio of cross-section"
}; };
try try
@@ -216,7 +219,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
{ {
var parameters = new List<IValueParameter<string>>(); var parameters = new List<IValueParameter<string>>();
var unitType = UnitTypes.Length; var unitType = UnitTypes.Length;
var unit = CommonOperation.GetUnit(unitType, "mm"); var unit = unitLogic.GetUnit(unitType, "mm");
var unitName = unit.Name; var unitName = unit.Name;
var unitMultiPlayer = unit.Multiplyer; var unitMultiPlayer = unit.Multiplyer;
var firstParameter = new ValueParameter<string>() var firstParameter = new ValueParameter<string>()
@@ -224,7 +227,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefix} Center{firstAxisName.ToUpper()}", Name = $"{prefix} Center{firstAxisName.ToUpper()}",
ShortName = $"{firstAxisName.ToUpper()}c", ShortName = $"{firstAxisName.ToUpper()}c",
MeasurementUnit = unitName, Text = unitName,
Description = $"{prefix} Displacement of center of gravity of cross-section along {firstAxisName}-axis" Description = $"{prefix} Displacement of center of gravity of cross-section along {firstAxisName}-axis"
}; };
var secondParameter = new ValueParameter<string>() var secondParameter = new ValueParameter<string>()
@@ -232,7 +235,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
IsValid = true, IsValid = true,
Name = $"{prefix} Center{secondAxisName.ToUpper()}", Name = $"{prefix} Center{secondAxisName.ToUpper()}",
ShortName = $"{secondAxisName.ToUpper()}c", ShortName = $"{secondAxisName.ToUpper()}c",
MeasurementUnit = unitName, Text = unitName,
Description = $"{prefix} Displacement of center of gravity of cross-section along {secondAxisName}-axis" Description = $"{prefix} Displacement of center of gravity of cross-section along {secondAxisName}-axis"
}; };
try try

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using StructureHelperCommon.Models.Parameters;
namespace StructureHelperTests.UnitTests.ParamTests
{
public class ProcessDoublePairTest
{
[TestCase("100mm", DigitPlace.Start, "mm", 100d)] //Without backspace
[TestCase("100 mm", DigitPlace.Start, "mm", 100d)] //With backspace
[TestCase("Fixed3", DigitPlace.Any, "fixed", 3d)]
public void Run_ShouldPass(string inputString, DigitPlace digitPlace, string expectedText, double expectedValue)
{
//Arrange
var logic = new ProcessDoublePairLogic() { DigitPlace = digitPlace};
//Act
var result = logic.GetValuePairByString(inputString);
//Assert
Assert.AreEqual(expectedText, result.Text);
Assert.AreEqual(expectedValue, result.Value, 0.001d);
}
}
}