Check logic for rebar ndm was created
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Materials;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives.Logics
|
||||
{
|
||||
public class CheckPrimitiveCollectionLogic : ICheckPrimitiveCollectionLogic
|
||||
{
|
||||
private const string collectionDoesntHaveAnyPrimitives = "Calculator does not contain any primitives\n";
|
||||
private const string checkRebarLogic = ": check rebar logic";
|
||||
|
||||
private string checkResult;
|
||||
private bool result;
|
||||
private ICheckRebarPrimitiveLogic checkRebarPrimitiveLogic;
|
||||
|
||||
public IHasPrimitives HasPrimitives { get; set; }
|
||||
|
||||
public string CheckResult => checkResult;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public CheckPrimitiveCollectionLogic(IShiftTraceLogger shiftTraceLogger, ICheckRebarPrimitiveLogic checkRebarPrimitiveLogic)
|
||||
{
|
||||
TraceLogger = shiftTraceLogger;
|
||||
this.checkRebarPrimitiveLogic = checkRebarPrimitiveLogic;
|
||||
}
|
||||
|
||||
public CheckPrimitiveCollectionLogic() : this (new ShiftTraceLogger(), new CheckRebarPrimitiveLogic())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Check()
|
||||
{
|
||||
result = true;
|
||||
checkResult = string.Empty;
|
||||
CheckPrimitives();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckPrimitives()
|
||||
{
|
||||
if (HasPrimitives.Primitives is null || (!HasPrimitives.Primitives.Any()))
|
||||
{
|
||||
result = false;
|
||||
checkResult += collectionDoesntHaveAnyPrimitives;
|
||||
TraceLogger?.AddMessage(collectionDoesntHaveAnyPrimitives, TraceLogStatuses.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var primitive in HasPrimitives.Primitives)
|
||||
{
|
||||
if (primitive is IRebarPrimitive rebar)
|
||||
{
|
||||
CheckRebar(rebar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckRebar(IRebarPrimitive rebar)
|
||||
{
|
||||
if (checkRebarPrimitiveLogic is null)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ParameterIsNull + checkRebarLogic);
|
||||
}
|
||||
checkRebarPrimitiveLogic.RebarPrimitive = rebar;
|
||||
checkRebarPrimitiveLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger();
|
||||
if (checkRebarPrimitiveLogic.Check() == false)
|
||||
{
|
||||
result = false;
|
||||
checkResult += checkRebarPrimitiveLogic.CheckResult;
|
||||
return;
|
||||
}
|
||||
bool isPrimitivesContainRebarHost = HasPrimitives.Primitives.Contains(rebar.HostPrimitive);
|
||||
if (isPrimitivesContainRebarHost == false)
|
||||
{
|
||||
result = false;
|
||||
string message = $"Host {rebar.Name} ({rebar.HostPrimitive.Name}) is not included in primitives\n";
|
||||
checkResult += message;
|
||||
TraceLogger?.AddMessage(message, TraceLogStatuses.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Materials;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives.Logics
|
||||
{
|
||||
public class CheckRebarPrimitiveLogic : ICheckRebarPrimitiveLogic
|
||||
{
|
||||
private string checkResult;
|
||||
private bool result;
|
||||
|
||||
public IRebarPrimitive RebarPrimitive { get; set; }
|
||||
|
||||
public string CheckResult => checkResult;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public CheckRebarPrimitiveLogic(IShiftTraceLogger traceLogger)
|
||||
{
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public CheckRebarPrimitiveLogic() : this (new ShiftTraceLogger())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Check()
|
||||
{
|
||||
result = true;
|
||||
checkResult = string.Empty;
|
||||
CheckRebar();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckRebar()
|
||||
{
|
||||
if (RebarPrimitive.HostPrimitive is null)
|
||||
{
|
||||
result = false;
|
||||
string message = $"Primitive {RebarPrimitive.Name} does not have a host\n";
|
||||
checkResult += message;
|
||||
TraceLogger?.AddMessage(message, TraceLogStatuses.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (RebarPrimitive.HostPrimitive is IHasDivisionSize division)
|
||||
{
|
||||
if (!division.IsPointInside(RebarPrimitive.Center))
|
||||
{
|
||||
result = false;
|
||||
string message = $"Primitive of rebar {RebarPrimitive.Name} is out of its host {RebarPrimitive.HostPrimitive.Name}";
|
||||
checkResult += message;
|
||||
TraceLogger?.AddMessage(message, TraceLogStatuses.Error);
|
||||
}
|
||||
}
|
||||
|
||||
if (RebarPrimitive.HostPrimitive.HeadMaterial.HelperMaterial is not ICrackedMaterial)
|
||||
{
|
||||
result = false;
|
||||
string message = $"Material of host of {RebarPrimitive.Name} ({RebarPrimitive.HostPrimitive.HeadMaterial.Name}) does not support cracking\n";
|
||||
checkResult += message;
|
||||
TraceLogger?.AddMessage(message, TraceLogStatuses.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives.Logics
|
||||
{
|
||||
public interface ICheckPrimitiveCollectionLogic : ICheckLogic
|
||||
{
|
||||
IHasPrimitives HasPrimitives { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives.Logics
|
||||
{
|
||||
public interface ICheckRebarPrimitiveLogic : ICheckLogic
|
||||
{
|
||||
IRebarPrimitive RebarPrimitive { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user