UpdateStrategy for Actions was added

This commit is contained in:
Evgeny Redikultsev
2023-07-09 19:46:36 +05:00
parent 03b882f54d
commit 3e0e51d0c9
30 changed files with 402 additions and 138 deletions

View File

@@ -1,5 +1,6 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Repositories;
using StructureHelperLogics.Models.Materials;
using System;
@@ -13,6 +14,8 @@ namespace StructureHelper.Services.Settings
internal static class GlobalRepository
{
private static IDataRepository<IHeadMaterial> materials;
private static IDataRepository<IAction> actions;
public static IDataRepository<IHeadMaterial> Materials
{
get
@@ -21,5 +24,13 @@ namespace StructureHelper.Services.Settings
return materials;
}
}
public static IDataRepository<IAction> Actions
{
get
{
actions ??= new ListRepository<IAction>(new ActionUpdateStrategy());
return actions;
}
}
}
}

View File

@@ -7,11 +7,12 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Forces"
d:DataContext="{d:DesignInstance vm:ForceCombinationByFactorVM}"
mc:Ignorable="d"
Title="Force Combination By Factor" Height="250" Width="350" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
Title="Force Combination By Factor" Height="290" Width="350" MinHeight="290" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="95"/>
<RowDefinition/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<!--ForceTemplates.xaml-->
<ContentControl ContentTemplate="{StaticResource ResourceKey=ForceActionTemplate}" Content="{Binding}"/>
@@ -49,5 +50,6 @@
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ULSFactor, Converter={StaticResource PlainDouble}, ValidatesOnExceptions=True}"/>
</Grid>
</StackPanel>
<ContentControl Grid.Row="2" ContentTemplate="{StaticResource OkCancelButtons}" Content="{Binding}"/>
</Grid>
</Window>

View File

@@ -27,6 +27,7 @@ namespace StructureHelper.Windows.Forces
InitializeComponent();
viewModel = new ForceCombinationByFactorVM(forceCombination);
DataContext = viewModel;
viewModel.ParentWindow = this;
}
}
}

View File

@@ -7,16 +7,18 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Forces"
d:DataContext="{d:DesignInstance vm:ForceCombinationViewModel}"
mc:Ignorable="d"
Title="Force Combination" Height="250" Width="550" MinHeight="300" MinWidth="450" MaxWidth="500" WindowStartupLocation="CenterScreen">
Title="Force Combination" Height="350" Width="550" MinHeight="300" MinWidth="450" MaxWidth="500" WindowStartupLocation="CenterScreen">
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="95"/>
<RowDefinition/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<!--ForceTemplates.xaml-->
<ContentControl ContentTemplate="{StaticResource ResourceKey=ForceActionTemplate}" Content="{Binding}"/>
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=CombinationListTemplate}" Content="{Binding}"/>
<ContentControl Grid.Row="2" ContentTemplate="{StaticResource OkCancelButtons}" Content="{Binding}"/>
</Grid>
</Window>

View File

@@ -27,13 +27,11 @@ namespace StructureHelper.Windows.Forces
viewModel = _viewModel;
DataContext = viewModel;
InitializeComponent();
viewModel.ParentWindow = this;
}
public ForceCombinationView(IForceCombinationList combinationList)
public ForceCombinationView(IForceCombinationList combinationList) : this(new ForceCombinationViewModel(combinationList))
{
viewModel = new ForceCombinationViewModel(combinationList);
DataContext = viewModel;
InitializeComponent();
}
}
}

View File

@@ -407,6 +407,10 @@ namespace StructureHelper.Windows.MainWindow
{
GlobalRepository.Materials.Create(item);
}
foreach (var item in newRepository.ForceActions)
{
GlobalRepository.Actions.Create(item);
}
return primitives;
}
return new List<PrimitiveBase>();

View File

@@ -15,13 +15,12 @@
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="280"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}" SelectionChanged="ListBox_SelectionChanged">
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
@@ -42,19 +41,7 @@
</ListBox>
</Grid>
<StackPanel Grid.Column="1">
<Button Content="New Concrete" Command="{Binding AddNewConcreteMaterialCommand}"/>
<Button Content="New Reinforcement" Command="{Binding AddNewReinforcementMaterialCommand}"/>
<Button Content="New Elastic Material" Command="{Binding AddElasticMaterialCommand}"/>
<Button Content="Show diagram" Command="{Binding ShowMaterialDiagram}"/>
<Button Content="Edit color" Command="{Binding EditColorCommand}"/>
<Button Content="Edit" Command="{Binding EditCommand}"/>
<Button Content="Copy" Command="{Binding CopyHeadMaterialCommand}"/>
<Button Content="Delete" Command="{Binding DeleteMaterialCommand}"/>
</StackPanel>
<StackPanel x:Name="MatProps" Grid.Column="2">
<TextBlock Text="Name"/>
<TextBox Text="{Binding SelectedMaterial.Name}"/>
<StackPanel x:Name="StpMaterialProperties"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -33,37 +33,5 @@ namespace StructureHelper.Windows.MainWindow.Materials
this.DataContext = viewModel;
InitializeComponent();
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
StpMaterialProperties.Children.Clear();
var selectedMaterial = viewModel.SelectedMaterial;
if (selectedMaterial == null) { return; }
var helperMaterial = selectedMaterial.HelperMaterial;
string dataTemplateName = string.Empty;
Binding binding = new Binding();
if (helperMaterial is IConcreteLibMaterial)
{
dataTemplateName = "ConcreteLibMaterial";
binding.Source = viewModel;
}
else if (helperMaterial is IReinforcementLibMaterial)
{
dataTemplateName = "ReinforcementLibMaterial";
binding.Source = viewModel;
}
else if (helperMaterial is IElasticMaterial)
{
dataTemplateName = "ElasticMaterial";
binding.Source = viewModel.SelectedMaterial.HelperMaterial;
}
if (dataTemplateName != string.Empty)
{
ContentControl contentControl = new ContentControl();
contentControl.SetResourceReference(ContentTemplateProperty, dataTemplateName);
contentControl.SetBinding(ContentProperty, binding);
StpMaterialProperties.Children.Add(contentControl);
}
}
}
}

View File

@@ -1,8 +1,12 @@
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Models.Materials;
using StructureHelper.Services.Settings;
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
@@ -15,6 +19,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
{
public class ActionsViewModel : SelectedItemViewModel<IForceAction>
{
readonly IUpdateStrategy<IAction> updateStrategy = new ActionUpdateStrategy();
ICrossSectionRepository repository;
public override void AddMethod(object parameter)
@@ -30,7 +35,8 @@ namespace StructureHelper.Windows.ViewModels.Forces
{
NewItem = new ForceCombinationByFactor() { Name = "New Factored Combination" };
}
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}");
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}");
GlobalRepository.Actions.Create(NewItem);
base.AddMethod(parameter);
}
}
@@ -41,6 +47,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
if (dialogResult == DialogResult.Yes)
{
if (DeleteAction() != true) return;
GlobalRepository.Materials.Delete(SelectedItem.Id);
base.DeleteMethod(parameter);
}
}
@@ -49,6 +56,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
public override void EditMethod(object parameter)
{
var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction;
System.Windows.Window wnd;
if (SelectedItem is IForceCombinationList)
{
@@ -62,6 +70,14 @@ namespace StructureHelper.Windows.ViewModels.Forces
}
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"actual object type: {nameof(SelectedItem)}");
wnd.ShowDialog();
if (wnd.DialogResult == true)
{
GlobalRepository.Actions.Update(SelectedItem);
}
else
{
updateStrategy.Update(SelectedItem, copyObject);
}
base.EditMethod(parameter);
}

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Forces
{
public abstract class ForceActionVMBase : ViewModelBase
public abstract class ForceActionVMBase : OkCancelViewModelBase
{
IForceAction forceAction;

View File

@@ -0,0 +1,17 @@
using StructureHelperCommon.Models.Forces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Exceptions
{
public static class ErrorCommonProcessor
{
public static void ObjectTypeIsUnknown(Type expectedType, Type actualType)
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"\n Expected: {expectedType},\n But was: {actualType}");
}
}
}

View File

@@ -6,8 +6,17 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
/// <summary>
/// Logic for update object of type <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Type of object</typeparam>
public interface IUpdateStrategy<T>
{
/// <summary>
/// Update properties of target object from source object
/// </summary>
/// <param name="targetObject">Target object</param>
/// <param name="sourceObject">Source object</param>
void Update(T targetObject, T sourceObject);
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using System;
using System.Collections.Generic;
@@ -10,6 +11,8 @@ namespace StructureHelperCommon.Models.Forces
{
public class DesignForcePair : IDesignForcePair
{
readonly IUpdateStrategy<IAction> updateStrategy = new ActionUpdateStrategy();
public Guid Id { get; }
public string Name { get; set; }
public IPoint2D ForcePoint { get; set; }
public bool SetInGravityCenter { get; set; }
@@ -17,12 +20,16 @@ namespace StructureHelperCommon.Models.Forces
public IForceTuple LongForceTuple { get; set; }
public IForceTuple FullForceTuple { get; set; }
public DesignForcePair()
public DesignForcePair(Guid id)
{
Id = id;
LongForceTuple = new ForceTuple();
FullForceTuple = new ForceTuple();
}
public DesignForcePair() : this(Guid.NewGuid()) {}
public IForceCombinationList GetCombinations()
{
throw new NotImplementedException();
@@ -30,7 +37,9 @@ namespace StructureHelperCommon.Models.Forces
public object Clone()
{
throw new NotImplementedException();
var newItem = new DesignForcePair();
updateStrategy.Update(newItem, this);
return newItem;
}
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.Forces;
using System;
@@ -12,6 +13,9 @@ namespace StructureHelperCommon.Models.Forces
/// <inheritdoc/>
public class ForceCombinationByFactor : IForceCombinationByFactor
{
readonly IUpdateStrategy<IAction> updateStrategy = new ActionUpdateStrategy();
/// <inheritdoc/>
public Guid Id { get; }
/// <inheritdoc/>
public string Name { get; set; }
public bool SetInGravityCenter { get; set; }
@@ -23,8 +27,11 @@ namespace StructureHelperCommon.Models.Forces
public double ULSFactor { get; set; }
/// <inheritdoc/>
public double LongTermFactor { get; set; }
public ForceCombinationByFactor()
public ForceCombinationByFactor(Guid id)
{
Id = id;
Name = "New Factored Load";
SetInGravityCenter = true;
ForcePoint = new Point2D();
@@ -32,6 +39,7 @@ namespace StructureHelperCommon.Models.Forces
LongTermFactor = 1d;
ULSFactor = 1.2d;
}
public ForceCombinationByFactor() : this (Guid.NewGuid()) { }
public IForceCombinationList GetCombinations()
{
var result = new ForceCombinationList();
@@ -57,10 +65,7 @@ namespace StructureHelperCommon.Models.Forces
public object Clone()
{
var newItem = new ForceCombinationByFactor();
ForceActionService.CopyActionProps(this, newItem);
newItem.FullSLSForces = FullSLSForces.Clone() as IForceTuple;
newItem.LongTermFactor = LongTermFactor;
newItem.ULSFactor = ULSFactor;
updateStrategy.Update(newItem, this);
return newItem;
}
}

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.Forces;
@@ -10,6 +12,9 @@ namespace StructureHelperCommon.Models.Forces
/// <inheritdoc/>
public class ForceCombinationList : IForceCombinationList
{
readonly IUpdateStrategy<IAction> updateStrategy = new ActionUpdateStrategy();
/// <inheritdoc/>
public Guid Id { get; }
/// <inheritdoc/>
public string Name { get; set; }
/// <inheritdoc/>
@@ -18,9 +23,11 @@ namespace StructureHelperCommon.Models.Forces
public IPoint2D ForcePoint { get; set; }
/// <inheritdoc/>
public List<IDesignForceTuple> DesignForces { get; private set; }
public ForceCombinationList()
public ForceCombinationList(Guid id)
{
Id = id;
SetInGravityCenter = true;
ForcePoint = new Point2D() { X = 0, Y = 0 };
DesignForces = new List<IDesignForceTuple>
@@ -31,17 +38,12 @@ namespace StructureHelperCommon.Models.Forces
new DesignForceTuple(LimitStates.SLS, CalcTerms.LongTerm)
};
}
public ForceCombinationList() : this (Guid.NewGuid()) { }
/// <inheritdoc/>
public object Clone()
{
var newItem = new ForceCombinationList();
ForceActionService.CopyActionProps(this, newItem);
newItem.DesignForces.Clear();
foreach (var item in DesignForces)
{
var newForce = item.Clone() as IDesignForceTuple;
newItem.DesignForces.Add(newForce);
}
updateStrategy.Update(newItem, this);
return newItem;
}
/// <inheritdoc/>

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Services.Forces;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services.Forces;
using System.ComponentModel.DataAnnotations;
namespace StructureHelperCommon.Models.Forces
@@ -6,6 +7,7 @@ namespace StructureHelperCommon.Models.Forces
/// <inheritdoc/>
public class ForceTuple : IForceTuple
{
private readonly IUpdateStrategy<IForceTuple> updateStrategy = new ForceTupleUpdateStrategy();
/// <inheritdoc/>
public double Mx { get; set; }
/// <inheritdoc/>
@@ -22,8 +24,9 @@ namespace StructureHelperCommon.Models.Forces
/// <inheritdoc/>
public object Clone()
{
ForceTuple forceTuple = new ForceTuple() { Mx = Mx, My = My, Nz = Nz, Qx = Qx, Qy = Qy, Mz = Mz};
return forceTuple;
var newItem = new ForceTuple();
updateStrategy.Update(newItem, this);
return newItem;
}
public static ForceTuple operator +(ForceTuple first) => first;
public static ForceTuple operator +(ForceTuple first, ForceTuple second)

View File

@@ -1,4 +1,5 @@
using System;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,7 +7,7 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public interface IAction
public interface IAction : ISaveable, ICloneable
{
string Name { get; set; }
}

View File

@@ -7,10 +7,23 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public interface IForceAction : IAction, ICloneable
/// <summary>
/// Action as force load
/// </summary>
public interface IForceAction : IAction
{
/// <summary>
/// True means force action is put in center of gravity
/// </summary>
bool SetInGravityCenter { get; set; }
/// <summary>
/// Point of applying of force load
/// </summary>
IPoint2D ForcePoint { get; set; }
/// <summary>
/// Return combination of forces
/// </summary>
/// <returns></returns>
IForceCombinationList GetCombinations();
}
}

View File

@@ -0,0 +1,29 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public class ActionUpdateStrategy : IUpdateStrategy<IAction>
{
readonly IUpdateStrategy<IForceAction> forceUpdateStrategy = new ForceActionUpdateStrategy();
public void Update(IAction targetObject, IAction sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
targetObject.Name = sourceObject.Name;
if (targetObject is IForceAction forceAction)
{
forceUpdateStrategy.Update(forceAction, (IForceAction)sourceObject);
}
else
{
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(IAction), sourceObject.GetType());
}
}
}
}

View File

@@ -0,0 +1,22 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public class FactorCombinationUpdateStrategy : IUpdateStrategy<IForceCombinationByFactor>
{
readonly IUpdateStrategy<IForceTuple> tupleUpdateStrategy = new ForceTupleUpdateStrategy();
public void Update(IForceCombinationByFactor targetObject, IForceCombinationByFactor sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
tupleUpdateStrategy.Update(targetObject.FullSLSForces, sourceObject.FullSLSForces);
targetObject.ULSFactor = sourceObject.ULSFactor;
targetObject.LongTermFactor = sourceObject.LongTermFactor;
}
}
}

View File

@@ -0,0 +1,48 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes.Logics;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StructureHelperCommon.Infrastructures.Exceptions;
namespace StructureHelperCommon.Models.Forces
{
public class ForceActionUpdateStrategy : IUpdateStrategy<IForceAction>
{
private readonly IUpdateStrategy<IPoint2D> pointStrategy = new PointUpdateStrategy();
private readonly IUpdateStrategy<IDesignForcePair> forcePairUpdateStrategy = new ForcePairUpdateStrategy();
private readonly IUpdateStrategy<IForceCombinationByFactor> factorUpdateStrategy = new FactorCombinationUpdateStrategy();
private readonly IUpdateStrategy<IForceCombinationList> forceListUpdateStrategy = new ForceCombinationListUpdateStrategy();
public void Update(IForceAction targetObject, IForceAction sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
targetObject.SetInGravityCenter = sourceObject.SetInGravityCenter;
pointStrategy.Update(targetObject.ForcePoint, sourceObject.ForcePoint);
UpdateChildProperties(targetObject, sourceObject);
}
private void UpdateChildProperties(IForceAction targetObject, IForceAction sourceObject)
{
if (targetObject is IDesignForcePair pair)
{
forcePairUpdateStrategy.Update(pair, (IDesignForcePair)sourceObject);
}
else if (targetObject is IForceCombinationByFactor combination)
{
factorUpdateStrategy.Update(combination, (IForceCombinationByFactor)sourceObject);
}
else if (targetObject is IForceCombinationList forceCombinationList)
{
forceListUpdateStrategy.Update(forceCombinationList, (IForceCombinationList)sourceObject);
}
else
{
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(IForceAction), targetObject.GetType());
}
}
}
}

View File

@@ -0,0 +1,24 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public class ForceCombinationListUpdateStrategy : IUpdateStrategy<IForceCombinationList>
{
public void Update(IForceCombinationList targetObject, IForceCombinationList sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
var forcesList = new List<IDesignForceTuple>(sourceObject.DesignForces);
targetObject.DesignForces.Clear();
foreach (var item in forcesList)
{
targetObject.DesignForces.Add((IDesignForceTuple)item.Clone());
}
}
}
}

View File

@@ -0,0 +1,24 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Models.Shapes.Logics;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public class ForcePairUpdateStrategy : IUpdateStrategy<IDesignForcePair>
{
private readonly IUpdateStrategy<IForceTuple> tupleUpdateStrategy = new ForceTupleUpdateStrategy();
public void Update(IDesignForcePair targetObject, IDesignForcePair sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
targetObject.LimitState = sourceObject.LimitState;
tupleUpdateStrategy.Update(targetObject.LongForceTuple, sourceObject.LongForceTuple);
tupleUpdateStrategy.Update(targetObject.FullForceTuple, sourceObject.FullForceTuple);
}
}
}

View File

@@ -0,0 +1,27 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
internal class ForceTupleUpdateStrategy : IUpdateStrategy<IForceTuple>
{
public void Update(IForceTuple targetObject, IForceTuple sourceObject)
{
CheckObject.IsNull(targetObject, ": target object ");
CheckObject.IsNull(sourceObject, ": source object ");
targetObject.Mx = sourceObject.Mx;
targetObject.My = sourceObject.My;
targetObject.Nz = targetObject.Nz;
targetObject.Qx = targetObject.Qx;
targetObject.Qy = targetObject.Qy;
targetObject.Mz = sourceObject.Mz;
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
namespace StructureHelperCommon.Models.Shapes
{
@@ -6,15 +7,15 @@ namespace StructureHelperCommon.Models.Shapes
/// Interface for point of center of some shape
/// Интерфейс для точки центра некоторой формы
/// </summary>
public interface IPoint2D : ICloneable
public interface IPoint2D : ISaveable, ICloneable
{
/// <summary>
/// Coordinate of center of rectangle by local axis X, m
/// Coordinate of center of point by local axis X, m
/// Координата центра вдоль локальной оси X, м
/// </summary>
double X { get; set; }
/// <summary>
/// Coordinate of center of rectangle by local axis Y, m
/// Coordinate of center of point by local axis Y, m
/// Координата центра вдоль локальной оси Y, м
/// </summary>
double Y { get; set; }

View File

@@ -0,0 +1,20 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Shapes.Logics
{
/// <inheritdoc />
public class PointUpdateStrategy : IUpdateStrategy<IPoint2D>
{
/// <inheritdoc />
public void Update(IPoint2D targetObject, IPoint2D sourceObject)
{
targetObject.X = sourceObject.X;
targetObject.Y = sourceObject.Y;
}
}
}

View File

@@ -1,17 +1,32 @@
namespace StructureHelperCommon.Models.Shapes
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes.Logics;
using System;
namespace StructureHelperCommon.Models.Shapes
{
/// <inheritdoc />
public class Point2D : IPoint2D
{
private readonly IUpdateStrategy<IPoint2D> updateStrategy = new PointUpdateStrategy();
/// <inheritdoc />
public Guid Id { get; }
/// <inheritdoc />
public double X { get; set; }
/// <inheritdoc />
public double Y { get; set; }
public Point2D(Guid id)
{
Id = id;
}
public Point2D() : this(Guid.NewGuid()) { }
public object Clone()
{
var point = new Point2D() { X = X, Y = Y };
return point;
var newItem = new Point2D();
updateStrategy.Update(newItem, this);
return newItem;
}
}
}

View File

@@ -0,0 +1,38 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services
{
/// <summary>
/// Processor for checking objects
/// </summary>
public static class CheckObject
{
/// <summary>
/// Compares types of two objects, throws exception if result is not valid
/// </summary>
/// <param name="targetObject"></param>
/// <param name="sourceObject"></param>
/// <exception cref="StructureHelperException"></exception>
public static void CompareTypes(object targetObject, object sourceObject)
{
IsNull(targetObject, "target object");
IsNull(targetObject, "source object");
if (targetObject.GetType() != sourceObject.GetType())
{
throw new StructureHelperException
($"{ErrorStrings.DataIsInCorrect}: target type is {targetObject.GetType()},\n does not coinside with source type {sourceObject.GetType()}");
}
}
public static void IsNull(object item, string message = "")
{
if (item is null) {throw new StructureHelperException (ErrorStrings.ParameterIsNull + message);}
}
}
}

View File

@@ -13,14 +13,6 @@ namespace StructureHelperCommon.Services.Forces
{
internal static class ForceActionService
{
public static void CopyActionProps(IForceAction source, IForceAction target)
{
target.Name = source.Name;
target.SetInGravityCenter = source.SetInGravityCenter;
target.ForcePoint.X = source.ForcePoint.X;
target.ForcePoint.Y = source.ForcePoint.Y;
}
public static List<IDesignForcePair> ConvertCombinationToPairs(IForceCombinationList combinations)
{
var resultList = new List<IDesignForcePair>();

View File

@@ -1,6 +1,8 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,6 +13,10 @@ namespace StructureHelperLogics.Models.Materials
{
public class MaterialUpdateStrategy : IUpdateStrategy<IHeadMaterial>
{
private readonly IUpdateStrategy<IElasticMaterial> elasticStrategy = new ElasticUpdateStrategy();
private readonly IUpdateStrategy<IFRMaterial> frStrategy = new FRUpdateStrategy();
private readonly IUpdateStrategy<IConcreteLibMaterial> concreteStrategy = new ConcreteLibUpdateStrategy();
private readonly IUpdateStrategy<IReinforcementLibMaterial> reinforcementStrategy = new ReinforcementLibUpdateStrategy();
public void Update(IHeadMaterial targetObject, IHeadMaterial sourceObject)
{
targetObject.Name = sourceObject.Name;
@@ -19,70 +25,40 @@ namespace StructureHelperLogics.Models.Materials
UpdateHelperMaterial(targetObject.HelperMaterial, sourceObject.HelperMaterial);
}
private static void UpdateHelperMaterial(IHelperMaterial target, IHelperMaterial source)
private void UpdateHelperMaterial(IHelperMaterial targetObject, IHelperMaterial sourceObject)
{
Check(target, source);
UpdateMaterial(target, source);
}
private static void Check(IHelperMaterial target, IHelperMaterial source)
{
if (target.GetType() != source.GetType())
CheckObject.CompareTypes(targetObject, sourceObject);
if (sourceObject is ILibMaterial)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $"target type is {target.GetType()}, \n is no coinside with source type {source.GetType()}");
UpdateLibMaterial(targetObject, sourceObject);
}
}
private static void UpdateMaterial(IHelperMaterial target, IHelperMaterial source)
{
if (source is ILibMaterial)
else if (sourceObject is IElasticMaterial)
{
UpdateLibMaterial(target, source);
elasticStrategy.Update(targetObject as IElasticMaterial, sourceObject as IElasticMaterial);
}
else if (source is IElasticMaterial)
else if (sourceObject is IFRMaterial)
{
UpdateElastic(target, source);
}
else if (source is IFRMaterial)
{
UpdateFR(target, source);
frStrategy.Update(targetObject as IFRMaterial, sourceObject as IFRMaterial);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"\n Expected: {typeof(IHelperMaterial)},\n But was: {source.GetType()}");
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(IHelperMaterial), sourceObject.GetType());
}
}
private static void UpdateFR(IHelperMaterial target, IHelperMaterial source)
private void UpdateLibMaterial(IHelperMaterial targetObject, IHelperMaterial sourceObject)
{
var targetMaterial = target as IFRMaterial;
var sourceMaterial = source as IFRMaterial;
var logic = new FRUpdateStrategy();
logic.Update(targetMaterial, sourceMaterial);
}
private static void UpdateElastic(IHelperMaterial target, IHelperMaterial source)
{
var targetMaterial = target as IElasticMaterial;
var sourceMaterial = source as IElasticMaterial;
var logic = new ElasticUpdateStrategy();
logic.Update(targetMaterial, sourceMaterial);
}
private static void UpdateLibMaterial(IHelperMaterial target, IHelperMaterial source)
{
if (source is IConcreteLibMaterial)
if (sourceObject is IConcreteLibMaterial)
{
var targetMaterial = target as IConcreteLibMaterial;
var sourceMaterial = source as IConcreteLibMaterial;
var logic = new ConcreteLibUpdateStrategy();
logic.Update(targetMaterial, sourceMaterial);
concreteStrategy.Update(targetObject as IConcreteLibMaterial, sourceObject as IConcreteLibMaterial);
}
else if (source is IReinforcementLibMaterial)
else if (sourceObject is IReinforcementLibMaterial)
{
var targetMaterial = target as IReinforcementLibMaterial;
var sourceMaterial = source as IReinforcementLibMaterial;
var logic = new ReinforcementLibUpdateStrategy();
logic.Update(targetMaterial, sourceMaterial);
reinforcementStrategy.Update(targetObject as IReinforcementLibMaterial, sourceObject as IReinforcementLibMaterial);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"\n Expected: {typeof(ILibMaterial)},\n But was: {source.GetType()}");
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(ILibMaterial), sourceObject.GetType());
}
}
}