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,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;
}
}
}