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
/// </summary>
bool IsActive { get; set; }
/// <summary>
/// Minimum value of range
/// </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; }
IValueColorArray ExactValues { get; }
IValueColorArray RoundedValues { get; }
}
}

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/>
public bool IsActive { get; set; }
/// <inheritdoc/>
public double BottomValue { get; set; }
/// <inheritdoc/>
public double AverageValue { get; set; }
/// <inheritdoc/>
public double TopValue { get; set; }
/// <inheritdoc/>
public Color BottomColor { get; set; }
/// <inheritdoc/>
public Color TopColor { get; set; }
public IValueColorArray ExactValues { get; private set; } = new ValueColorArray();
public IValueColorArray RoundedValues { get; private set; } = new ValueColorArray();
}
}

View File

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

View File

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

View File

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

View File

@@ -6,7 +6,7 @@
xmlns:FieldViewerControl="clr-namespace:FieldVisualizer.Windows.UserControls"
xmlns:local="clr-namespace:FieldVisualizer.Windows"
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.ColumnDefinitions>
<ColumnDefinition Width="300"/>

View File

@@ -14,7 +14,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Area : UnitBase
{
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"; }
}
}

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
{
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"; }
}
}

View File

@@ -13,7 +13,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Force : UnitBase
{
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"; }
}
}

View File

@@ -5,8 +5,9 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Length : UnitBase
{
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"; }
}
}

View File

@@ -11,7 +11,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Moment : UnitBase
{
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"; }
}
}

View File

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

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
@@ -12,8 +13,19 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Stress : UnitBase
{
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 Stress()
{
OperationLogic = new ConvertUnitLogic()
{
MathRoundLogic = new SmartRoundLogic()
{
DigitQuant = 3
}
};
}
}
}

View File

@@ -1,4 +1,7 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
@@ -14,19 +17,61 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
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 IUnit CurrentUnit { 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)
{
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)
{
try
{
return CommonOperation.ConvertBack(UnitType, CurrentUnit, value);
double result = OperationLogic.ConvertBack(UnitType, CurrentUnit, value);
return result;
}
catch (Exception)
{

View File

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

View File

@@ -1,7 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<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>
<Style TargetType="TextBlock">
<Style.Triggers>

View File

@@ -12,8 +12,11 @@ namespace StructureHelper.Services.ResultViewers
public static class CrackResultFuncFactory
{
static IUnit unitStress = CommonOperation.GetUnit(UnitTypes.Stress);
static IUnit unitLength = CommonOperation.GetUnit(UnitTypes.Length, "mm");
private static readonly IConvertUnitLogic operationLogic = new ConvertUnitLogic();
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()
{

View File

@@ -20,10 +20,11 @@ namespace StructureHelper.Services.ResultViewers
}
public static class ForceResultFuncFactory
{
static IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force);
static IUnit unitStress = CommonOperation.GetUnit(UnitTypes.Stress);
static IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment);
static IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature);
static IGetUnitLogic unitLogic = new GetUnitLogic();
static IUnit unitForce = unitLogic.GetUnit(UnitTypes.Force);
static IUnit unitStress = unitLogic.GetUnit(UnitTypes.Stress);
static IUnit unitMoment = unitLogic.GetUnit(UnitTypes.Moment);
static IUnit unitCurvature = unitLogic.GetUnit(UnitTypes.Curvature);
static readonly IStressLogic stressLogic = new StressLogic();
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.Logics;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
using StructureHelperLogics.NdmCalculations.Cracking;
using StructureHelperLogics.NdmCalculations.Triangulations;
using System;
@@ -17,6 +18,7 @@ namespace StructureHelper.Services.ResultViewers
{
public static class ShowIsoFieldResult
{
static IMathRoundLogic roundLogic = new SmartRoundLogic() { DigitQuant = 3 };
public static void ShowResult(IStrainMatrix strainMatrix, IEnumerable<INdm> ndms, IEnumerable<ForceResultFunc> resultFuncs)
{
var primitiveSets = GetPrimitiveSets(strainMatrix, ndms, resultFuncs);
@@ -59,7 +61,9 @@ namespace StructureHelper.Services.ResultViewers
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;
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)
{
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;
if (ndm is IRectangleNdm shapeNdm)
{

View File

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

View File

@@ -6,13 +6,29 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews"
d:DataContext="{d:DesignInstance local:CrackCalculatorInputDataViewModel}"
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.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<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">
<ContentControl ContentTemplate="{StaticResource SourceToTarget}" Content="{Binding CombinationViewModel}"/>
</TabItem>

View File

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

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews"
d:DataContext="{d:DesignInstance local:CrackResultViewModel}"
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>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@@ -55,8 +55,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Long-term" />
<TextBlock Grid.Row="1" Text="Short-term" />
<TextBlock Grid.Row="0" Text="Long-term"/>
<TextBlock Grid.Row="1" Text="Short-term"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@@ -69,8 +69,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.Mx, Converter={StaticResource MomentConverter}}" />
<TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.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}}" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@@ -83,8 +83,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.My, Converter={StaticResource MomentConverter}}" />
<TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.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}}" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@@ -97,13 +97,13 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding InputData.LongTermTuple.Nz, Converter={StaticResource MomentConverter}}" />
<TextBlock Grid.Row="1" Text="{Binding InputData.ShortTermTuple.Nz, Converter={StaticResource ForceConverter}}" />
<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}}" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Crack width" Width="140">
<DataGridTemplateColumn Header="Crack width" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentControl ContentTemplate="{StaticResource CrackGrid}" Content="{Binding}"/>

View File

@@ -1,7 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<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>
<Style TargetType="TextBlock">
<Style.Triggers>

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews"
d:DataContext="{d:DesignInstance local:TupleCrackResultViewModel}"
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>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@@ -51,7 +51,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Softening factor" Width="120">
<DataGridTemplateColumn Header="Softening factor" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
@@ -59,13 +59,13 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.SofteningFactor, Converter={StaticResource PlainDouble}}" />
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.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}, StringFormat=F3}" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Rebar stress" Width="120">
<DataGridTemplateColumn Header="Rebar stress" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
@@ -73,13 +73,13 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStress, Converter={StaticResource StressConverter}}"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.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}, ConverterParameter='Smart3'}" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Rebar strain" Width="120">
<DataGridTemplateColumn Header="Rebar strain" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
@@ -87,8 +87,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStrain}"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.RebarStrain}"/>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.RebarStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.RebarStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@@ -101,13 +101,13 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.ConcreteStrain}"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.ConcreteStrain}"/>
<TextBlock Grid.Row="0" Text="{Binding LongTermResult.RebarStressResult.ConcreteStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Text="{Binding ShortTermResult.RebarStressResult.ConcreteStrain, StringFormat=F5}" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Crack width" Width="140">
<DataGridTemplateColumn Header="Crack width" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentControl ContentTemplate="{StaticResource CrackGrid}" Content="{Binding}"/>

View File

@@ -27,7 +27,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
public TupleCrackResult CrackResult => crackResult;
public List<RebarCrackResult> RebarResults => crackResult.RebarResults;
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
{
get

View File

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

View File

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

View File

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

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews"
d:DataContext="{d:DesignInstance local:ForcesResultsViewModel}"
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>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>

View File

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

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.ProgressViews"
d:DataContext="{d:DesignInstance local:TraceDocumentVM}"
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.ColumnDefinitions>
<ColumnDefinition Width="*"/>

View File

@@ -25,6 +25,7 @@ namespace StructureHelper.Windows.UserControls
/// </summary>
public partial class MultiplyDouble : UserControl
{
IConvertUnitLogic operationLogic = new ConvertUnitLogic();
public event EventHandler ValueChanged;
public MultiplyDouble()
@@ -40,7 +41,7 @@ namespace StructureHelper.Windows.UserControls
try
{
string s = (string)o;
double factor = CommonOperation.ConvertToDoubleChangeComma(s);
double factor = ProcessString.ConvertCommaToCultureSettings(s);
ChangeValue(factor);
}
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
{
public interface IValueParameter<T>
public interface IValueParameter<T> : IValuePair<T>
{
bool IsValid { get; set; }
string Name { get; set; }
string ShortName { get; set; }
Color Color { get; set; }
string MeasurementUnit { get; set; }
T Value { 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.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 T Value { get; set; }
}
}

View File

@@ -13,7 +13,7 @@ namespace StructureHelperCommon.Models.Parameters
public string Name { get; set; }
public string ShortName { get; set; }
public Color Color { get; set; }
public string MeasurementUnit { get; set; }
public string Text { get; set; }
public T Value { 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
{
/// <summary>
/// Returns collection of unit
/// </summary>
/// <returns></returns>
public static List<IUnit> GetUnitCollection()
{
List<IUnit> units = new List<IUnit>();
@@ -28,8 +32,8 @@ namespace StructureHelperCommon.Services.Units
type = UnitTypes.Moment;
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 = "kgfm", Multiplyer = 9.8d });
units.Add(new Unit() { UnitType = type, Name = "tfm", Multiplyer = 9.8e-3d });
units.Add(new Unit() { UnitType = type, Name = "kgfm", Multiplyer = 9.81d });
units.Add(new Unit() { UnitType = type, Name = "tfm", Multiplyer = 9.81e-3d });
type = UnitTypes.Curvature;
units.Add(new Unit() { UnitType = type, Name = "1/m", Multiplyer = 1d });
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.ShortName,
item.MeasurementUnit,
item.Text,
item.Value.ToString(),
item.Description
};

View File

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