Change value diagram calculator
This commit is contained in:
@@ -21,7 +21,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
|
||||
public void Update(IValueDiagramCalculatorInputData targetObject, IValueDiagramCalculatorInputData sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(targetObject, sourceObject);
|
||||
CheckObject.ThrowIfNull(targetObject, sourceObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.CheckStrainLimit = sourceObject.CheckStrainLimit;
|
||||
targetObject.StateTermPair.LimitState = sourceObject.StateTermPair.LimitState;
|
||||
@@ -32,12 +32,12 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
targetObject.Primitives.AddRange(sourceObject.Primitives);
|
||||
targetObject.ForceActions.Clear();
|
||||
targetObject.ForceActions.AddRange(sourceObject.ForceActions);
|
||||
targetObject.Digrams.Clear();
|
||||
targetObject.Diagrams.Clear();
|
||||
entityUpdateStrategy ??= new ValueDiagramEntityUpdateStrategy();
|
||||
foreach (var entity in sourceObject.Digrams)
|
||||
foreach (var entity in sourceObject.Diagrams)
|
||||
{
|
||||
var newItem = entity.Clone() as IValueDiagramEntity;
|
||||
targetObject.Digrams.Add(newItem);
|
||||
targetObject.Diagrams.Add(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
|
||||
private void GetEntitiesResults()
|
||||
{
|
||||
var entities = InputData.Digrams
|
||||
var entities = InputData.Diagrams
|
||||
.Where(x => x.IsTaken == true);
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
|
||||
@@ -31,9 +31,9 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
|
||||
public void Update(IValueDiagramCalculator targetObject, IValueDiagramCalculator sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(cloningStrategy);
|
||||
CheckObject.IsNull(sourceObject);
|
||||
CheckObject.IsNull(targetObject);
|
||||
CheckObject.ThrowIfNull(cloningStrategy);
|
||||
CheckObject.ThrowIfNull(sourceObject);
|
||||
CheckObject.ThrowIfNull(targetObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
var sourceData = sourceObject.InputData;
|
||||
var targetData = targetObject.InputData;
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
|
||||
public void Update(IValueDiagramCalculator targetObject, IValueDiagramCalculator sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(targetObject, sourceObject);
|
||||
CheckObject.ThrowIfNull(targetObject, sourceObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.Name = sourceObject.Name;
|
||||
targetObject.ShowTraceData = sourceObject.ShowTraceData;
|
||||
if (UpdateChildren == true)
|
||||
{
|
||||
CheckObject.IsNull(targetObject.InputData, ": target value diagram calculator input data");
|
||||
CheckObject.IsNull(sourceObject.InputData, ": source value diagram calculator input data");
|
||||
CheckObject.ThrowIfNull(targetObject.InputData, ": target value diagram calculator input data");
|
||||
CheckObject.ThrowIfNull(sourceObject.InputData, ": source value diagram calculator input data");
|
||||
inputDataUpdateStrategy ??= new ValueDiagramCalculatorInputDataUpdateStrategy();
|
||||
inputDataUpdateStrategy.Update(targetObject.InputData, sourceObject.InputData);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams.Logics
|
||||
{
|
||||
public class ValueDiagramCheckLogic : CheckEntityLogic<IValueDiagram>
|
||||
{
|
||||
private const double minDistance = 1e-3;
|
||||
private bool result;
|
||||
|
||||
public override bool Check()
|
||||
{
|
||||
result = true;
|
||||
if (Entity is null)
|
||||
{
|
||||
string errorString = ErrorStrings.ParameterIsNull + ": value diagram";
|
||||
TraceMessage(errorString);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
double dx = Entity.Point2DRange.StartPoint.X - Entity.Point2DRange.EndPoint.X;
|
||||
double dy = Entity.Point2DRange.StartPoint.Y - Entity.Point2DRange.EndPoint.Y;
|
||||
if (Math.Abs(dx) < minDistance && Math.Abs(dy) < minDistance)
|
||||
{
|
||||
result = false;
|
||||
TraceMessage($"Distance between point of diagram is too small");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams.Logics;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
{
|
||||
public class ValueDiagramEntityCheckLogic : CheckEntityLogic<IValueDiagramEntity>
|
||||
{
|
||||
private ICheckEntityLogic<IValueDiagram> valueDiagramCheckLogic;
|
||||
|
||||
public ValueDiagramEntityCheckLogic(IShiftTraceLogger? traceLogger)
|
||||
{
|
||||
valueDiagramCheckLogic = new ValueDiagramCheckLogic();
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public ValueDiagramEntityCheckLogic(ICheckEntityLogic<IValueDiagram> valueDiagramCheckLogic, IShiftTraceLogger? traceLogger)
|
||||
{
|
||||
TraceLogger = traceLogger;
|
||||
this.valueDiagramCheckLogic = valueDiagramCheckLogic;
|
||||
}
|
||||
|
||||
public override bool Check()
|
||||
{
|
||||
bool result = true;
|
||||
if (Entity is null)
|
||||
{
|
||||
string errorString = ErrorStrings.ParameterIsNull + ": value diagram entity";
|
||||
TraceMessage(errorString);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
valueDiagramCheckLogic.Entity = Entity.ValueDiagram;
|
||||
bool IsValid = valueDiagramCheckLogic.Check();
|
||||
if (IsValid == false)
|
||||
{
|
||||
result = false;
|
||||
string name = string.IsNullOrWhiteSpace(Entity.Name)
|
||||
? "<unnamed>"
|
||||
: Entity.Name;
|
||||
TraceMessage($"Diagram: {name} has error: {valueDiagramCheckLogic.CheckResult}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,12 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
private List<IPoint2D> GetPoints()
|
||||
{
|
||||
TraceLogger?.AddMessage($"Getting point for diagram {ValueDiagramEntity.Name} has been started");
|
||||
var startPoint = ValueDiagramEntity.ValueDigram.Point2DRange.StartPoint;
|
||||
var endPoint = ValueDiagramEntity.ValueDigram.Point2DRange.EndPoint;
|
||||
double dx = (endPoint.X - startPoint.X) / ValueDiagramEntity.ValueDigram.StepNumber;
|
||||
double dy = (endPoint.Y - startPoint.Y) / ValueDiagramEntity.ValueDigram.StepNumber;
|
||||
var startPoint = ValueDiagramEntity.ValueDiagram.Point2DRange.StartPoint;
|
||||
var endPoint = ValueDiagramEntity.ValueDiagram.Point2DRange.EndPoint;
|
||||
double dx = (endPoint.X - startPoint.X) / ValueDiagramEntity.ValueDiagram.StepNumber;
|
||||
double dy = (endPoint.Y - startPoint.Y) / ValueDiagramEntity.ValueDiagram.StepNumber;
|
||||
List<IPoint2D> point2Ds = [];
|
||||
for (int i = 0; i < ValueDiagramEntity.ValueDigram.StepNumber + 1; i++)
|
||||
for (int i = 0; i < ValueDiagramEntity.ValueDiagram.StepNumber + 1; i++)
|
||||
{
|
||||
double x = startPoint.X + dx * i;
|
||||
double y = startPoint.Y + dy * i;
|
||||
|
||||
@@ -21,14 +21,14 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
|
||||
public void Update(IValueDiagramEntity targetObject, IValueDiagramEntity sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(targetObject, sourceObject);
|
||||
CheckObject.ThrowIfNull(targetObject, sourceObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.IsTaken = sourceObject.IsTaken;
|
||||
targetObject.Name = sourceObject.Name;
|
||||
if (UpdateChildren == true)
|
||||
{
|
||||
valueDiagramUpdateStrategy ??= new ValueDiagramUpdateStrategy();
|
||||
valueDiagramUpdateStrategy.Update(targetObject.ValueDigram, sourceObject.ValueDigram);
|
||||
valueDiagramUpdateStrategy.Update(targetObject.ValueDiagram, sourceObject.ValueDiagram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Forces.Logics;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives.Logics;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
{
|
||||
public class ValueDiagramInputDataCheckLogic : CheckEntityLogic<IValueDiagramCalculatorInputData>
|
||||
{
|
||||
private ICheckEntityLogic<IValueDiagramEntity> checkEntityLogic;
|
||||
private ICheckEntityLogic<IHasPrimitives> primitivesCheckLogic;
|
||||
private ICheckEntityLogic<IEnumerable<IForceAction>> actionsCheckLogic;
|
||||
|
||||
private bool result;
|
||||
|
||||
public ValueDiagramInputDataCheckLogic(
|
||||
ICheckEntityLogic<IValueDiagramEntity> checkEntityLogic,
|
||||
ICheckEntityLogic<IHasPrimitives> primitivesCheckLogic,
|
||||
ICheckEntityLogic<IEnumerable<IForceAction>> actionsCheckLogic)
|
||||
{
|
||||
this.checkEntityLogic = checkEntityLogic;
|
||||
this.primitivesCheckLogic = primitivesCheckLogic;
|
||||
this.actionsCheckLogic = actionsCheckLogic;
|
||||
}
|
||||
|
||||
public ValueDiagramInputDataCheckLogic()
|
||||
{
|
||||
checkEntityLogic = new ValueDiagramEntityCheckLogic(TraceLogger);
|
||||
CheckRebarPrimitiveLogic checkRebarPrimitiveLogic = new()
|
||||
{
|
||||
CheckRebarHostMaterial = false,
|
||||
CheckRebarPlacement = false
|
||||
};
|
||||
primitivesCheckLogic = new CheckPrimitiveCollectionLogic(TraceLogger, checkRebarPrimitiveLogic);
|
||||
actionsCheckLogic = new CheckForceActionsLogic(TraceLogger);
|
||||
}
|
||||
|
||||
public override bool Check()
|
||||
{
|
||||
result = true;
|
||||
if (Entity is null)
|
||||
{
|
||||
string errorString = ErrorStrings.ParameterIsNull + ": input data";
|
||||
TraceMessage(errorString);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
if (Entity.Primitives is null || !Entity.Primitives.Any())
|
||||
{
|
||||
TraceMessage("Calculator does not contain any primitives");
|
||||
result = false;
|
||||
}
|
||||
if (Entity.ForceActions is null || !Entity.ForceActions.Any())
|
||||
{
|
||||
TraceMessage("Calculator does not contain any forces");
|
||||
result = false;
|
||||
}
|
||||
if (Entity.Diagrams is null || !Entity.Diagrams.Any() || !Entity.Diagrams.Where(x=> x.IsTaken == true).Any())
|
||||
{
|
||||
TraceMessage("Calculator does not contain any diagrams for calculation");
|
||||
result = false;
|
||||
}
|
||||
foreach (var entity in Entity.Diagrams)
|
||||
{
|
||||
checkEntityLogic.Entity = entity;
|
||||
bool isValid = checkEntityLogic.Check();
|
||||
if (isValid == false)
|
||||
{
|
||||
result = false;
|
||||
TraceMessage(checkEntityLogic.CheckResult);
|
||||
}
|
||||
}
|
||||
CheckPrimitives();
|
||||
CheckActions();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckPrimitives()
|
||||
{
|
||||
primitivesCheckLogic.Entity = Entity;
|
||||
if (primitivesCheckLogic.Check() == false)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
TraceMessage(primitivesCheckLogic.CheckResult);
|
||||
|
||||
}
|
||||
|
||||
private void CheckActions()
|
||||
{
|
||||
actionsCheckLogic.Entity = Entity.ForceActions;
|
||||
if (actionsCheckLogic.Check() == false)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
TraceMessage(actionsCheckLogic.CheckResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Services;
|
||||
|
||||
@@ -6,19 +7,36 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
{
|
||||
public class ValueDiagramUpdateStrategy : IParentUpdateStrategy<IValueDiagram>
|
||||
{
|
||||
private IUpdateStrategy<IPoint2DRange> rangeUpdateStrategy;
|
||||
private IUpdateStrategy<IPoint2DRange>? _rangeUpdateStrategy;
|
||||
|
||||
public ValueDiagramUpdateStrategy(IUpdateStrategy<IPoint2DRange> rangeUpdateStrategy)
|
||||
{
|
||||
_rangeUpdateStrategy = rangeUpdateStrategy ?? throw new StructureHelperException("rangeUpdateStrategy cannot be null");
|
||||
}
|
||||
|
||||
public ValueDiagramUpdateStrategy() { }
|
||||
|
||||
public bool UpdateChildren { get; set; } = true;
|
||||
|
||||
private IUpdateStrategy<IPoint2DRange> RangeUpdateStrategy
|
||||
=> _rangeUpdateStrategy ??= new Point2DRangeUpdateStrategy();
|
||||
|
||||
public void Update(IValueDiagram targetObject, IValueDiagram sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(targetObject, sourceObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
CheckObject.ThrowIfNull(targetObject, nameof(targetObject));
|
||||
CheckObject.ThrowIfNull(sourceObject, nameof(sourceObject));
|
||||
|
||||
if (ReferenceEquals(targetObject, sourceObject))
|
||||
return;
|
||||
|
||||
targetObject.StepNumber = sourceObject.StepNumber;
|
||||
if (UpdateChildren == true)
|
||||
|
||||
if (UpdateChildren)
|
||||
{
|
||||
rangeUpdateStrategy ??= new Point2DRangeUpdateStrategy();
|
||||
rangeUpdateStrategy.Update(targetObject.Point2DRange, sourceObject.Point2DRange);
|
||||
// Use property for lazy initialization
|
||||
RangeUpdateStrategy.Update(targetObject.Point2DRange, sourceObject.Point2DRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user