Force combination was added
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using StructureHelper.Infrastructure.UI.Converters.Units;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -12,6 +16,8 @@ namespace StructureHelper.Infrastructure.UI.Converters
|
||||
{
|
||||
internal static class CommonOperation
|
||||
{
|
||||
private static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
||||
|
||||
public static double ConvertToDoubleChangeComma(string s)
|
||||
{
|
||||
double result;
|
||||
@@ -26,6 +32,7 @@ namespace StructureHelper.Infrastructure.UI.Converters
|
||||
|
||||
public static IStringDoublePair DivideIntoStringDoublePair(string s)
|
||||
{
|
||||
s = s.Replace(" ", "");
|
||||
string digitPattern = @"\d+(\.?|\,?)\d+";
|
||||
string textPattern = @"[0-9]|\.|\,";
|
||||
string caracterPattern = "[a-z]+$";
|
||||
@@ -43,5 +50,51 @@ namespace StructureHelper.Infrastructure.UI.Converters
|
||||
}
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
|
||||
public static IUnit GetUnit(UnitTypes unitType, string unitName)
|
||||
{
|
||||
return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -11,33 +13,8 @@ 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 string unitName { get => "Area"; }
|
||||
|
||||
public override string MeasureUnit => throw new NotImplementedException();
|
||||
|
||||
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
if (value != null) { val = (double)value; }
|
||||
else { throw new Exception($"{unitName} value is null"); }
|
||||
val *= UnitConstatnts.Length * UnitConstatnts.Length;
|
||||
return val;
|
||||
}
|
||||
|
||||
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
val = CommonOperation.ConvertToDoubleChangeComma(strVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= (UnitConstatnts.Length * UnitConstatnts.Length);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
Infrastructure/UI/Converters/Units/Curvature.cs
Normal file
17
Infrastructure/UI/Converters/Units/Curvature.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
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 Curvature : UnitBase
|
||||
{
|
||||
public override UnitTypes unitType { get => UnitTypes.Curvature; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "1/mm"); }
|
||||
public override string unitName { get => "Curvature"; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -10,35 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Force : UnitBase
|
||||
{
|
||||
private double coeffficient = UnitConstatnts.Force;
|
||||
|
||||
public override UnitTypes unitType { get => UnitTypes.Force; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "kN"); }
|
||||
public override string unitName { get => "Force"; }
|
||||
|
||||
public override string MeasureUnit => throw new NotImplementedException();
|
||||
|
||||
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
if (value != null) { val = (double)value; }
|
||||
else { throw new Exception($"{unitName} value is null"); }
|
||||
val *= coeffficient;
|
||||
return val;
|
||||
}
|
||||
|
||||
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
val = CommonOperation.ConvertToDoubleChangeComma(strVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= coeffficient;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -14,60 +15,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Length : UnitBase
|
||||
{
|
||||
private IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
||||
private UnitTypes type = UnitTypes.Length;
|
||||
private IUnit currentUnit => units.Where(u => u.UnitType == type & u.Name == "mm").Single();
|
||||
public override string MeasureUnit => currentUnit.Name;
|
||||
private double coeffficient => currentUnit.Multiplyer;
|
||||
|
||||
public override string unitName { get => "Length"; }
|
||||
|
||||
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
if (value != null) { val = (double)value; }
|
||||
else { throw new Exception($"{unitName} value is null"); }
|
||||
val *= coeffficient;
|
||||
string strValue = $"{val} {MeasureUnit}";
|
||||
return strValue;
|
||||
}
|
||||
|
||||
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
IStringDoublePair pair = CommonOperation.DivideIntoStringDoublePair(strVal);
|
||||
double multy;
|
||||
try
|
||||
{
|
||||
multy = coeffficient / GetMultiplyer(units, type, pair.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
multy = 1d;
|
||||
}
|
||||
val = pair.Digit * multy;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= coeffficient;
|
||||
return val;
|
||||
}
|
||||
|
||||
private double GetMultiplyer(IEnumerable<IUnit> units, 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);
|
||||
}
|
||||
}
|
||||
public override UnitTypes unitType { get => UnitTypes.Length; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "mm"); }
|
||||
public override string unitName { get => "Length"; }
|
||||
}
|
||||
}
|
||||
|
||||
17
Infrastructure/UI/Converters/Units/Moment.cs
Normal file
17
Infrastructure/UI/Converters/Units/Moment.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
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 Moment : UnitBase
|
||||
{
|
||||
public override UnitTypes unitType { get => UnitTypes.Moment; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "kNm"); }
|
||||
public override string unitName { get => "Moment"; }
|
||||
}
|
||||
}
|
||||
39
Infrastructure/UI/Converters/Units/PlainDouble.cs
Normal file
39
Infrastructure/UI/Converters/Units/PlainDouble.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class PlainDouble : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (double)value;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CommonOperation.ConvertToDoubleChangeComma((string)value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -10,35 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Stress : UnitBase
|
||||
{
|
||||
private double coeffficient = UnitConstatnts.Stress;
|
||||
|
||||
public override UnitTypes unitType { get => UnitTypes.Stress; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "MPa"); }
|
||||
public override string unitName { get => "Stress"; }
|
||||
|
||||
public override string MeasureUnit => throw new NotImplementedException();
|
||||
|
||||
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
if (value != null) { val = (double)value; }
|
||||
else { throw new Exception($"{unitName} value is null"); }
|
||||
val *= coeffficient;
|
||||
return val;
|
||||
}
|
||||
|
||||
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
val = CommonOperation.ConvertToDoubleChangeComma(strVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= coeffficient;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -10,9 +12,17 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal abstract class UnitBase : IValueConverter
|
||||
{
|
||||
public abstract UnitTypes unitType { get; }
|
||||
public abstract IUnit currentUnit { get; }
|
||||
public abstract string unitName { get;}
|
||||
public abstract string MeasureUnit { get; }
|
||||
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
|
||||
public abstract object ConvertBack(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);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return CommonOperation.ConvertBack(unitType, currentUnit, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
primitive.Area = value;
|
||||
OnPropertyChanged(nameof(Area));
|
||||
OnPropertyChanged(nameof(Diameter));
|
||||
OnPropertyChanged(nameof(CenterX));
|
||||
OnPropertyChanged(nameof(CenterY));
|
||||
OnPropertyChanged(nameof(PrimitiveLeft));
|
||||
OnPropertyChanged(nameof(PrimitiveTop));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -243,5 +243,10 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void RefreshColor()
|
||||
{
|
||||
OnPropertyChanged(nameof(Color));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Name: "/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
|
||||
<TextBlock Grid.Row="1" Text="Material Name: "/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding HeadMaterial.Name}"/>
|
||||
<TextBlock Text="Name: " FontWeight="Bold"/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}" FontWeight="Bold"/>
|
||||
<TextBlock Grid.Row="1" Text="Material Name: " FontWeight="Bold"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding HeadMaterial.Name}" FontWeight="Bold"/>
|
||||
<TextBlock Grid.Row="2" Text="Center X: "/>
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding CenterX, Converter={StaticResource LengthConverter}}"/>
|
||||
<TextBlock Grid.Row="3" Text="Center Y: "/>
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Name: "/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
|
||||
<TextBlock Grid.Row="1" Text="Material Name: "/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding HeadMaterial.Name}"/>
|
||||
<TextBlock Text="Name: " FontWeight="Bold"/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}" FontWeight="Bold"/>
|
||||
<TextBlock Grid.Row="1" Text="Material Name: " FontWeight="Bold"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding HeadMaterial.Name}" FontWeight="Bold"/>
|
||||
<TextBlock Grid.Row="2" Text="Center X: "/>
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding CenterX, Converter={StaticResource LengthConverter}}"/>
|
||||
<TextBlock Grid.Row="3" Text="Center Y: "/>
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
xmlns:convertersUnits ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Units">
|
||||
|
||||
<convertersCommon:InvertBoolConverter x:Key="InvertBoolConverter"/>
|
||||
<convertersUnits:PlainDouble x:Key="PlainDouble"/>
|
||||
<convertersUnits:Length x:Key="LengthConverter"/>
|
||||
<convertersUnits:Area x:Key="AreaConverter"/>
|
||||
<convertersUnits:Force x:Key="ForceConverter"/>
|
||||
<convertersUnits:Moment x:Key="MomentConverter"/>
|
||||
<convertersUnits:Stress x:Key="StressConverter"/>
|
||||
<convertersUnits:Curvature x:Key="Curvature"/>
|
||||
</ResourceDictionary>
|
||||
@@ -26,6 +26,14 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Opacity" Value="{Binding Opacity, Mode=TwoWay}"/>
|
||||
<Setter Property="Stroke" Value="Black"/>
|
||||
<Setter Property="StrokeThickness" Value="0.001"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter Property="Stroke" Value="Red"/>
|
||||
<Setter Property="StrokeThickness" Value="0.002"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="EllipseStyle" TargetType="Ellipse" BasedOn="{StaticResource ShapeStyle}">
|
||||
|
||||
Reference in New Issue
Block a user