Fix removing primitives
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public enum ConvertDirection
|
||||
{
|
||||
|
||||
@@ -11,21 +11,18 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
public class CurvatureCalculatorInputDataFromDTOConvertStrategy : ConvertStrategy<CurvatureCalculatorInputData, CurvatureCalculatorInputDataDTO>
|
||||
{
|
||||
private IHasPrimitivesProcessLogic primitivesProcessLogic;
|
||||
private IHasForceActionsProcessLogic actionsProcessLogic;
|
||||
private IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesProcessLogic;
|
||||
private IUpdateStrategy<ICurvatureCalculatorInputData> updateStrategy;
|
||||
private IConvertStrategy<DeflectionFactor, DeflectionFactorDTO> deflectionConvertStrategy;
|
||||
|
||||
private IProcessLogic<IHasForcesAndPrimitives> ForcesAndPrimitivesProcessLogic => forcesAndPrimitivesProcessLogic ??= new HasForcesAndPrimitivesProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
private IUpdateStrategy<ICurvatureCalculatorInputData> UpdateStrategy => updateStrategy ??= new CurvatureCalculatorInputDataUpdateStrategy() { UpdateChildren = false };
|
||||
private IConvertStrategy<DeflectionFactor, DeflectionFactorDTO> DeflectionConvertStrategy => deflectionConvertStrategy ??= new DeflectionFactorFromDTOConvertStrategy(this);
|
||||
public CurvatureCalculatorInputDataFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
private IHasPrimitivesProcessLogic PrimitivesProcessLogic => primitivesProcessLogic ??= new HasPrimitivesProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
private IHasForceActionsProcessLogic ActionsProcessLogic => actionsProcessLogic ??= new HasForceActionsProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
private IUpdateStrategy<ICurvatureCalculatorInputData> UpdateStrategy => updateStrategy ??= new CurvatureCalculatorInputDataUpdateStrategy() { UpdateChildren = false };
|
||||
private IConvertStrategy<DeflectionFactor, DeflectionFactorDTO> DeflectionConvertStrategy => deflectionConvertStrategy ??= new DeflectionFactorFromDTOConvertStrategy(this);
|
||||
public override CurvatureCalculatorInputData GetNewItem(CurvatureCalculatorInputDataDTO source)
|
||||
{
|
||||
ChildClass = this;
|
||||
NewItem = new(source.Id);
|
||||
UpdateStrategy.Update(NewItem, source);
|
||||
if (source.DeflectionFactor is not DeflectionFactorDTO deflectionFactorDTO)
|
||||
@@ -33,22 +30,16 @@ namespace DataAccess.DTOs
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source.DeflectionFactor) + ": deflection factor");
|
||||
}
|
||||
NewItem.DeflectionFactor = DeflectionConvertStrategy.Convert(deflectionFactorDTO);
|
||||
ProcessPrimitives(source);
|
||||
ProcessActions(source);
|
||||
ProcessForcesAndPrimitives(source);
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
private void ProcessPrimitives(IHasPrimitives source)
|
||||
|
||||
private void ProcessForcesAndPrimitives(IHasForcesAndPrimitives source)
|
||||
{
|
||||
PrimitivesProcessLogic.Source = source;
|
||||
PrimitivesProcessLogic.Target = NewItem;
|
||||
PrimitivesProcessLogic.Process();
|
||||
}
|
||||
private void ProcessActions(IHasForceActions source)
|
||||
{
|
||||
ActionsProcessLogic.Source = source;
|
||||
ActionsProcessLogic.Target = NewItem;
|
||||
ActionsProcessLogic.Process();
|
||||
ForcesAndPrimitivesProcessLogic.Source = source;
|
||||
ForcesAndPrimitivesProcessLogic.Target = NewItem;
|
||||
ForcesAndPrimitivesProcessLogic.Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,11 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
public class CurvatureCalculatorInputDataToDTOConvertStrategy : ConvertStrategy<CurvatureCalculatorInputDataDTO, ICurvatureCalculatorInputData>
|
||||
{
|
||||
private IHasPrimitivesProcessLogic primitivesProcessLogic;
|
||||
private IHasForceActionsProcessLogic actionsProcessLogic;
|
||||
private IProcessLogic<IHasForcesAndPrimitives> actionsProcessLogic;
|
||||
private IUpdateStrategy<ICurvatureCalculatorInputData> updateStrategy;
|
||||
private IConvertStrategy<DeflectionFactorDTO, IDeflectionFactor> deflectionConvertStrategy;
|
||||
|
||||
private IHasPrimitivesProcessLogic PrimitivesProcessLogic => primitivesProcessLogic ??= new HasPrimitivesProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
private IHasForceActionsProcessLogic ActionsProcessLogic => actionsProcessLogic ??= new HasForceActionsProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
private IProcessLogic<IHasForcesAndPrimitives> ForceAndPrimitivesLogic => actionsProcessLogic ??= new HasForcesAndPrimitivesProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
private IUpdateStrategy<ICurvatureCalculatorInputData> UpdateStrategy => updateStrategy ??= new CurvatureCalculatorInputDataUpdateStrategy() { UpdateChildren = false};
|
||||
private IConvertStrategy<DeflectionFactorDTO, IDeflectionFactor> DeflectionConvertStrategy => deflectionConvertStrategy ??= new DeflectionFactorToDTOConvertStrategy(this);
|
||||
|
||||
@@ -23,25 +21,19 @@ namespace DataAccess.DTOs
|
||||
|
||||
public override CurvatureCalculatorInputDataDTO GetNewItem(ICurvatureCalculatorInputData source)
|
||||
{
|
||||
ChildClass = this;
|
||||
NewItem = new(source.Id);
|
||||
UpdateStrategy.Update(NewItem, source);
|
||||
NewItem.DeflectionFactor = DeflectionConvertStrategy.Convert(source.DeflectionFactor);
|
||||
ProcessPrimitives(source);
|
||||
ProcessActions(source);
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
private void ProcessPrimitives(IHasPrimitives source)
|
||||
private void ProcessActions(IHasForcesAndPrimitives source)
|
||||
{
|
||||
PrimitivesProcessLogic.Source = source;
|
||||
PrimitivesProcessLogic.Target = NewItem;
|
||||
PrimitivesProcessLogic.Process();
|
||||
}
|
||||
private void ProcessActions(IHasForceActions source)
|
||||
{
|
||||
ActionsProcessLogic.Source = source;
|
||||
ActionsProcessLogic.Target = NewItem;
|
||||
ActionsProcessLogic.Process();
|
||||
ForceAndPrimitivesLogic.Source = source;
|
||||
ForceAndPrimitivesLogic.Target = NewItem;
|
||||
ForceAndPrimitivesLogic.Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using DataAccess.DTOs.Converters;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Services;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class HasForcesAndPrimitivesProcessLogic : IProcessLogic<IHasForcesAndPrimitives>
|
||||
{
|
||||
private ConvertDirection convertDirection;
|
||||
private IProcessLogic<IHasForceActions> forcesLogic;
|
||||
private IProcessLogic<IHasPrimitives> primitivesLogic;
|
||||
private IProcessLogic<IHasForceActions> ForcesLogic => forcesLogic ??= new HasForceActionsProcessLogic(convertDirection) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
private IProcessLogic<IHasPrimitives> PrimitivesLogic => primitivesLogic ??=new HasPrimitivesProcessLogic(convertDirection) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IHasForcesAndPrimitives Source { get; set; }
|
||||
public IHasForcesAndPrimitives Target { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public HasForcesAndPrimitivesProcessLogic(ConvertDirection convertDirection)
|
||||
{
|
||||
this.convertDirection = convertDirection;
|
||||
}
|
||||
|
||||
public HasForcesAndPrimitivesProcessLogic(
|
||||
ConvertDirection convertDirection,
|
||||
IProcessLogic<IHasForceActions> forcesLogic,
|
||||
IProcessLogic<IHasPrimitives> primitivesLogic)
|
||||
{
|
||||
this.convertDirection = convertDirection;
|
||||
this.forcesLogic = forcesLogic;
|
||||
this.primitivesLogic = primitivesLogic;
|
||||
}
|
||||
|
||||
public void Process()
|
||||
{
|
||||
Check();
|
||||
ProcessForces();
|
||||
ProcessPrimitives();
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
CheckObject.ThrowIfNull(ReferenceDictionary, ": reference dictionary");
|
||||
CheckObject.ThrowIfNull(Source, ": source object");
|
||||
CheckObject.ThrowIfNull(Target, ": target object");
|
||||
}
|
||||
|
||||
private void ProcessPrimitives()
|
||||
{
|
||||
PrimitivesLogic.Source = Source;
|
||||
PrimitivesLogic.Target = Target;
|
||||
PrimitivesLogic.Process();
|
||||
}
|
||||
|
||||
private void ProcessForces()
|
||||
{
|
||||
ForcesLogic.Source = Source;
|
||||
ForcesLogic.Target = Target;
|
||||
ForcesLogic.Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using DataAccess.DTOs.Converters;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
@@ -6,12 +7,7 @@ namespace DataAccess.DTOs
|
||||
/// <summary>
|
||||
/// Logic for antities which have force actions
|
||||
/// </summary>
|
||||
public interface IHasForceActionsProcessLogic
|
||||
public interface IHasForceActionsProcessLogic : IProcessLogic<IHasForceActions>
|
||||
{
|
||||
Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
IHasForceActions Source { get; set; }
|
||||
IHasForceActions Target { get; set; }
|
||||
IShiftTraceLogger TraceLogger { get; set; }
|
||||
void Process();
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,7 @@ using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public interface IHasPrimitivesProcessLogic
|
||||
public interface IHasPrimitivesProcessLogic : IProcessLogic<IHasPrimitives>
|
||||
{
|
||||
Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
IHasPrimitives Source { get; set; }
|
||||
IHasPrimitives Target { get; set; }
|
||||
IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
void Process();
|
||||
}
|
||||
}
|
||||
17
DataAccess/DTOs/Converters/IProcessLogic.cs
Normal file
17
DataAccess/DTOs/Converters/IProcessLogic.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public interface IProcessLogic<T>
|
||||
{
|
||||
Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
T Source { get; set; }
|
||||
T Target { get; set; }
|
||||
IShiftTraceLogger TraceLogger { get; set; }
|
||||
void Process();
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,9 @@ using StructureHelper.Models.Materials;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
@@ -22,9 +14,12 @@ namespace DataAccess.DTOs
|
||||
private const string convertStarted = " converting is started";
|
||||
private const string convertFinished = " converting has been finished successfully";
|
||||
private CrossSectionRepository newRepository;
|
||||
private ICheckEntityLogic<ICrossSectionRepository> checkEntityLogic;
|
||||
private ICheckEntityLogic<ICrossSectionRepository> CheckEntityLogic => checkEntityLogic ??= new CrossSectionRepositoryCheckLogic() {Entity = oldRepository};
|
||||
|
||||
private IHasPrimitivesProcessLogic primitivesProcessLogic = new HasPrimitivesProcessLogic(ConvertDirection.FromDTO);
|
||||
private IHasForceActionsProcessLogic actionsProcessLogic = new HasForceActionsProcessLogic(ConvertDirection.FromDTO);
|
||||
private IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesLogic;
|
||||
private IProcessLogic<IHasForcesAndPrimitives> ForcesAndPrimitivesLogic => forcesAndPrimitivesLogic ??= new HasForcesAndPrimitivesProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
private ICrossSectionRepository oldRepository;
|
||||
|
||||
public CrossSectionRepositoryFromDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger)
|
||||
{
|
||||
@@ -32,11 +27,17 @@ namespace DataAccess.DTOs
|
||||
|
||||
public override CrossSectionRepository GetNewItem(ICrossSectionRepository source)
|
||||
{
|
||||
oldRepository = source;
|
||||
if (CheckEntityLogic.Check() == false)
|
||||
{
|
||||
TraceLogger.AddMessage(CheckEntityLogic.CheckResult, TraceLogStatuses.Error);
|
||||
TraceLogger.AddMessage("All calculators will be removed", TraceLogStatuses.Error);
|
||||
oldRepository.Calculators.Clear();
|
||||
}
|
||||
TraceLogger?.AddMessage("Cross-Section repository" + convertStarted);
|
||||
newRepository = new(source.Id);
|
||||
ProcessMaterials(source);
|
||||
ProcessActions(source);
|
||||
ProcessPrimitives(source);
|
||||
ProcessForcesAndPrimitives(source);
|
||||
ProcessCalculators(source);
|
||||
TraceLogger?.AddMessage("Cross-Section repository" + convertFinished);
|
||||
return newRepository;
|
||||
@@ -56,22 +57,12 @@ namespace DataAccess.DTOs
|
||||
TraceLogger?.AddMessage("Calculators" + convertFinished);
|
||||
}
|
||||
|
||||
private void ProcessPrimitives(IHasPrimitives source)
|
||||
{
|
||||
primitivesProcessLogic.Source = source;
|
||||
primitivesProcessLogic.Target = newRepository;
|
||||
primitivesProcessLogic.ReferenceDictionary = ReferenceDictionary;
|
||||
primitivesProcessLogic.TraceLogger = TraceLogger;
|
||||
primitivesProcessLogic.Process();
|
||||
}
|
||||
|
||||
private void ProcessActions(IHasForceActions source)
|
||||
private void ProcessForcesAndPrimitives(IHasForcesAndPrimitives source)
|
||||
{
|
||||
actionsProcessLogic.Source = source;
|
||||
actionsProcessLogic.Target = newRepository;
|
||||
actionsProcessLogic.ReferenceDictionary = ReferenceDictionary;
|
||||
actionsProcessLogic.TraceLogger = TraceLogger;
|
||||
actionsProcessLogic.Process();
|
||||
ForcesAndPrimitivesLogic.Source = source;
|
||||
ForcesAndPrimitivesLogic.Target = newRepository;
|
||||
ForcesAndPrimitivesLogic.Process();
|
||||
}
|
||||
|
||||
private void ProcessMaterials(IHasHeadMaterials source)
|
||||
|
||||
@@ -12,6 +12,10 @@ namespace DataAccess.DTOs
|
||||
public class CrossSectionRepositoryToDTOConvertStrategy : IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>
|
||||
{
|
||||
private IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy;
|
||||
private ICheckEntityLogic<ICrossSectionRepository> checkEntityLogic;
|
||||
private ICrossSectionRepository oldRepository;
|
||||
|
||||
private ICheckEntityLogic<ICrossSectionRepository> CheckEntityLogic => checkEntityLogic ??= new CrossSectionRepositoryCheckLogic() { Entity = oldRepository };
|
||||
|
||||
|
||||
public CrossSectionRepositoryToDTOConvertStrategy(IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy)
|
||||
@@ -30,6 +34,13 @@ namespace DataAccess.DTOs
|
||||
|
||||
public CrossSectionRepositoryDTO Convert(ICrossSectionRepository source)
|
||||
{
|
||||
oldRepository = source;
|
||||
if (CheckEntityLogic.Check() == false)
|
||||
{
|
||||
TraceLogger.AddMessage(CheckEntityLogic.CheckResult, TraceLogStatuses.Error);
|
||||
TraceLogger.AddMessage("All calculators will be removed", TraceLogStatuses.Error);
|
||||
oldRepository.Calculators.Clear();
|
||||
}
|
||||
Check();
|
||||
InitializeStrategies();
|
||||
try
|
||||
|
||||
@@ -11,22 +11,35 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
private IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy;
|
||||
private IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO> diagramConvertStrategy;
|
||||
private IHasPrimitivesProcessLogic primitivesProcessLogic;
|
||||
private IHasForceActionsProcessLogic actionsProcessLogic;
|
||||
private IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesLogic;
|
||||
private IConvertStrategy<Accuracy, AccuracyDTO> accuracyConvertStrategy;
|
||||
private IUpdateStrategy<IValueDiagramCalculatorInputData> UpdateStrategy => updateStrategy ??= new ValueDiagramCalculatorInputDataUpdateStrategy() { UpdateChildren = false };
|
||||
private IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO> DiagramConvertStrategy => diagramConvertStrategy ??= new ValueDiagramEntityFromDTOConvertStrategy(this);
|
||||
private IProcessLogic<IHasForcesAndPrimitives> ForcesAndPrimitivesLogic => forcesAndPrimitivesLogic ??= new HasForcesAndPrimitivesProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
private IConvertStrategy<Accuracy, AccuracyDTO> AccuracyConvertStrategy => accuracyConvertStrategy ??= new AccuracyFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
|
||||
public ValueDiagramCalculatorInputDataFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public ValueDiagramCalculatorInputDataFromDTOConvertStrategy(
|
||||
IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy,
|
||||
IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO> diagramConvertStrategy,
|
||||
IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesLogic,
|
||||
IConvertStrategy<Accuracy, AccuracyDTO> accuracyConvertStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.diagramConvertStrategy = diagramConvertStrategy;
|
||||
this.forcesAndPrimitivesLogic = forcesAndPrimitivesLogic;
|
||||
this.accuracyConvertStrategy = accuracyConvertStrategy;
|
||||
}
|
||||
|
||||
public override ValueDiagramCalculatorInputData GetNewItem(ValueDiagramCalculatorInputDataDTO source)
|
||||
{
|
||||
ChildClass = this;
|
||||
NewItem = new(source.Id);
|
||||
InitializeStrategies();
|
||||
updateStrategy.Update(NewItem, source);
|
||||
ProcessPrimitives(source);
|
||||
ProcessActions(source);
|
||||
UpdateStrategy.Update(NewItem, source);
|
||||
ProcessForcesAndPrimitives(source);
|
||||
NewItem.Diagrams.Clear();
|
||||
foreach (var diagram in source.Diagrams)
|
||||
{
|
||||
@@ -34,35 +47,16 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(diagram));
|
||||
}
|
||||
NewItem.Diagrams.Add(diagramConvertStrategy.Convert(diagramDTO));
|
||||
NewItem.Diagrams.Add(DiagramConvertStrategy.Convert(diagramDTO));
|
||||
}
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
private void ProcessPrimitives(IHasPrimitives source)
|
||||
private void ProcessForcesAndPrimitives(IHasForcesAndPrimitives source)
|
||||
{
|
||||
primitivesProcessLogic.Source = source;
|
||||
primitivesProcessLogic.Target = NewItem;
|
||||
primitivesProcessLogic.ReferenceDictionary = ReferenceDictionary;
|
||||
primitivesProcessLogic.TraceLogger = TraceLogger;
|
||||
primitivesProcessLogic.Process();
|
||||
}
|
||||
private void ProcessActions(IHasForceActions source)
|
||||
{
|
||||
actionsProcessLogic.Source = source;
|
||||
actionsProcessLogic.Target = NewItem;
|
||||
actionsProcessLogic.ReferenceDictionary = ReferenceDictionary;
|
||||
actionsProcessLogic.TraceLogger = TraceLogger;
|
||||
actionsProcessLogic.Process();
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new ValueDiagramCalculatorInputDataUpdateStrategy() { UpdateChildren = false };
|
||||
diagramConvertStrategy ??= new ValueDiagramEntityFromDTOConvertStrategy(this);
|
||||
primitivesProcessLogic ??= new HasPrimitivesProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
actionsProcessLogic ??= new HasForceActionsProcessLogic(ConvertDirection.FromDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
accuracyConvertStrategy ??= new AccuracyFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
ForcesAndPrimitivesLogic.Source = source;
|
||||
ForcesAndPrimitivesLogic.Target = NewItem;
|
||||
ForcesAndPrimitivesLogic.Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
private IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy;
|
||||
private IConvertStrategy<ValueDiagramEntityDTO, IValueDiagramEntity> diagramConvertStrategy;
|
||||
private IHasPrimitivesProcessLogic primitivesProcessLogic;
|
||||
private IHasForceActionsProcessLogic actionsProcessLogic;
|
||||
private IConvertStrategy<ValueDiagramEntityDTO, IValueDiagramEntity> DiagramConvertStrategy => diagramConvertStrategy ??= new ValueDiagramEntityToDTOConvertStrategy(this);
|
||||
private IProcessLogic<IHasForcesAndPrimitives> actionsProcessLogic;
|
||||
private IUpdateStrategy<IValueDiagramCalculatorInputData> UpdateStrategy => updateStrategy ??= new ValueDiagramCalculatorInputDataUpdateStrategy() { UpdateChildren = false };
|
||||
private IProcessLogic<IHasForcesAndPrimitives> ActionsProcessLogic => actionsProcessLogic ??= new HasForcesAndPrimitivesProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
|
||||
public ValueDiagramCalculatorInputDataToDTOConvertStrategy() : base()
|
||||
{
|
||||
@@ -24,41 +26,21 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
ChildClass = this;
|
||||
NewItem = new(source.Id);
|
||||
InitializeStrategies();
|
||||
updateStrategy.Update(NewItem, source);
|
||||
ProcessPrimitives(source);
|
||||
UpdateStrategy.Update(NewItem, source);
|
||||
ProcessActions(source);
|
||||
NewItem.Diagrams.Clear();
|
||||
foreach (var diagram in source.Diagrams)
|
||||
{
|
||||
NewItem.Diagrams.Add(diagramConvertStrategy.Convert(diagram));
|
||||
NewItem.Diagrams.Add(DiagramConvertStrategy.Convert(diagram));
|
||||
}
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
private void ProcessPrimitives(IHasPrimitives source)
|
||||
private void ProcessActions(IHasForcesAndPrimitives source)
|
||||
{
|
||||
primitivesProcessLogic.Source = source;
|
||||
primitivesProcessLogic.Target = NewItem;
|
||||
primitivesProcessLogic.ReferenceDictionary = ReferenceDictionary;
|
||||
primitivesProcessLogic.TraceLogger = TraceLogger;
|
||||
primitivesProcessLogic.Process();
|
||||
}
|
||||
private void ProcessActions(IHasForceActions source)
|
||||
{
|
||||
actionsProcessLogic.Source = source;
|
||||
actionsProcessLogic.Target = NewItem;
|
||||
actionsProcessLogic.ReferenceDictionary = ReferenceDictionary;
|
||||
actionsProcessLogic.TraceLogger = TraceLogger;
|
||||
actionsProcessLogic.Process();
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new ValueDiagramCalculatorInputDataUpdateStrategy() { UpdateChildren = false};
|
||||
diagramConvertStrategy ??= new ValueDiagramEntityToDTOConvertStrategy(this);
|
||||
primitivesProcessLogic ??= new HasPrimitivesProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
actionsProcessLogic ??= new HasForceActionsProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
ActionsProcessLogic.Source = source;
|
||||
ActionsProcessLogic.Target = NewItem;
|
||||
ActionsProcessLogic.Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using HelixToolkit.Wpf.SharpDX;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelper.Services.Reports.Services
|
||||
{
|
||||
public interface IMaterialService
|
||||
{
|
||||
PhongMaterial CreateValueMaterial(double value, IValueRange range, IColorMap colorMap);
|
||||
PBRMaterial CreateTransparentPlaneMaterial(float opacity);
|
||||
}
|
||||
|
||||
}
|
||||
35
StructureHelper/Services/Reports/Services/MaterialService.cs
Normal file
35
StructureHelper/Services/Reports/Services/MaterialService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Services.ColorServices;
|
||||
using HelixToolkit.Maths;
|
||||
using HelixToolkit.Wpf.SharpDX;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelper.Services.Reports.Services
|
||||
{
|
||||
public class MaterialService : IMaterialService
|
||||
{
|
||||
public PhongMaterial CreateValueMaterial(double value, IValueRange range, IColorMap colorMap)
|
||||
{
|
||||
var c = ColorOperations.GetColorByValue(range, colorMap, value);
|
||||
return new PhongMaterial
|
||||
{
|
||||
DiffuseColor = new Color4(c.R / 255f, c.G / 255f, c.B / 255f, c.A / 255f),
|
||||
SpecularShininess = 50f
|
||||
};
|
||||
}
|
||||
|
||||
public PBRMaterial CreateTransparentPlaneMaterial(float opacity)
|
||||
{
|
||||
return new PBRMaterial
|
||||
{
|
||||
AlbedoColor = new Color4(0.5f, 0.5f, 0.5f, opacity),
|
||||
RoughnessFactor = 0.8f,
|
||||
MetallicFactor = 0.0f
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,17 +5,16 @@ using FieldVisualizer.Services.ColorServices;
|
||||
using HelixToolkit.Geometry;
|
||||
using HelixToolkit.Maths;
|
||||
using HelixToolkit.SharpDX;
|
||||
using HelixToolkit.SharpDX.Core;
|
||||
using HelixToolkit.Wpf.SharpDX;
|
||||
using System;
|
||||
using StructureHelper.Services.Reports.Services;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews
|
||||
{
|
||||
public class GetModels3dByValuePrimivesLogic : IGetModels3dLogic
|
||||
{
|
||||
private MaterialService materialService = new();
|
||||
public double ZoomValue { get; set; }
|
||||
public bool InvertNormal { get; set; }
|
||||
public IColorMap ColorMap { get; set; }
|
||||
@@ -53,8 +52,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
var builder = new MeshBuilder();
|
||||
|
||||
Vector3 p0 = new Vector3((float)circle.CenterX, (float)circle.CenterY, 0); // bottom center
|
||||
float cylinderHeight = (float)(circle.Value * ZoomValue);
|
||||
Vector3 p1 = new Vector3((float)circle.CenterX, (float)circle.CenterY, cylinderHeight); // top center
|
||||
Vector3 p1 = new Vector3((float)circle.CenterX, (float)circle.CenterY, (float)(circle.Value * ZoomValue)); // top center
|
||||
|
||||
builder.AddCylinder(p0, p1, (float)circle.Diameter, 8);
|
||||
|
||||
@@ -62,11 +60,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
var cylinderGeometry = builder.ToMeshGeometry3D();
|
||||
|
||||
// Create material (constant grey)
|
||||
var material = new PhongMaterial
|
||||
{
|
||||
DiffuseColor = ToColor4(ColorOperations.GetColorByValue(ValueRange, ColorMap, circle.Value)),
|
||||
SpecularShininess = 50f
|
||||
};
|
||||
var material = materialService.CreateValueMaterial(circle.Value, ValueRange, ColorMap);
|
||||
|
||||
// Create model
|
||||
var cylinderModel = new MeshGeometryModel3D
|
||||
@@ -79,24 +73,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
|
||||
private MeshGeometryModel3D CreateZeroTriangle(ITrianglePrimitive triangle)
|
||||
{
|
||||
// Triangle vertices
|
||||
Vector3 p0 = new Vector3((float)triangle.Point1.X, (float)triangle.Point1.Y, 0);
|
||||
Vector3 p1 = new Vector3((float)triangle.Point2.X, (float)triangle.Point2.Y, 0);
|
||||
Vector3 p2 = new Vector3((float)triangle.Point3.X, (float)triangle.Point3.Y, 0);
|
||||
|
||||
var builder = new MeshBuilder();
|
||||
builder.AddTriangle(p0, p1, p2);
|
||||
|
||||
var mesh = builder.ToMeshGeometry3D();
|
||||
|
||||
var material = new PBRMaterial
|
||||
{
|
||||
AlbedoColor = new Color4(0.5f, 0.5f, 0.5f, 0.4f), // 40% opacity
|
||||
RoughnessFactor = 0.8f,
|
||||
MetallicFactor = 0.0f
|
||||
};
|
||||
|
||||
|
||||
var mesh = CreateTriangleMesh(triangle, false);
|
||||
var material = materialService.CreateTransparentPlaneMaterial(0.4f);
|
||||
var model = new MeshGeometryModel3D
|
||||
{
|
||||
Geometry = mesh,
|
||||
@@ -109,23 +87,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
|
||||
private MeshGeometryModel3D CreateTriangle(ITrianglePrimitive triangle)
|
||||
{
|
||||
// Triangle vertices
|
||||
Vector3 p0 = new Vector3((float)triangle.Point1.X, (float)triangle.Point1.Y, (float)(triangle.ValuePoint1 * ZoomValue));
|
||||
Vector3 p1 = new Vector3((float)triangle.Point2.X, (float)triangle.Point2.Y, (float)(triangle.ValuePoint2 * ZoomValue));
|
||||
Vector3 p2 = new Vector3((float)triangle.Point3.X, (float)triangle.Point3.Y, (float)(triangle.ValuePoint3 * ZoomValue));
|
||||
|
||||
var builder = new MeshBuilder();
|
||||
builder.AddTriangle(p0, p1, p2);
|
||||
|
||||
var mesh = builder.ToMeshGeometry3D();
|
||||
|
||||
var material = new PhongMaterial
|
||||
{
|
||||
DiffuseColor = ToColor4(ColorOperations.GetColorByValue(ValueRange, ColorMap, triangle.Value)),
|
||||
SpecularShininess = 50f
|
||||
};
|
||||
|
||||
|
||||
var mesh = CreateTriangleMesh(triangle, true);
|
||||
var material = materialService.CreateValueMaterial(triangle.Value, ValueRange, ColorMap);
|
||||
var model = new MeshGeometryModel3D
|
||||
{
|
||||
Geometry = mesh,
|
||||
@@ -136,7 +99,24 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
return model;
|
||||
}
|
||||
|
||||
public static Color4 ToColor4(System.Windows.Media.Color c)
|
||||
private HelixToolkit.SharpDX.MeshGeometry3D CreateTriangleMesh(ITrianglePrimitive triangle, bool scaleByValue)
|
||||
{
|
||||
float z1 = scaleByValue ? (float)(triangle.ValuePoint1 * ZoomValue) : 0;
|
||||
float z2 = scaleByValue ? (float)(triangle.ValuePoint2 * ZoomValue) : 0;
|
||||
float z3 = scaleByValue ? (float)(triangle.ValuePoint3 * ZoomValue) : 0;
|
||||
|
||||
Vector3 p0 = new((float)triangle.Point1.X, (float)triangle.Point1.Y, z1);
|
||||
Vector3 p1 = new((float)triangle.Point2.X, (float)triangle.Point2.Y, z2);
|
||||
Vector3 p2 = new((float)triangle.Point3.X, (float)triangle.Point3.Y, z3);
|
||||
|
||||
var builder = new MeshBuilder();
|
||||
builder.AddTriangle(p0, p1, p2);
|
||||
|
||||
return builder.ToMeshGeometry3D();
|
||||
}
|
||||
|
||||
|
||||
private Color4 ToColor4(System.Windows.Media.Color c)
|
||||
{
|
||||
return new Color4(
|
||||
c.R / 255f,
|
||||
|
||||
@@ -14,8 +14,6 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
bool ShowZeroPlane { get; set; }
|
||||
IValueRange ValueRange { get; set; }
|
||||
double ZoomValue { get; set; }
|
||||
|
||||
static abstract Color4 ToColor4(System.Windows.Media.Color c);
|
||||
void GetModels3d(IEnumerable<IValuePrimitive> valuePrimitives, Viewport3DX viewport);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using StructureHelperLogics.Models.Primitives;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.Curvatures;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
@@ -76,13 +77,42 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
var dialogResult = MessageBox.Show("Delete all primitives?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
repository.Primitives.Clear();
|
||||
Items.Clear();
|
||||
ClearRepository();
|
||||
Refresh();
|
||||
OnPropertyChanged(nameof(Items));
|
||||
OnPropertyChanged(nameof(PrimitivesCount));
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearRepository()
|
||||
{
|
||||
repository.Primitives.Clear();
|
||||
foreach (var calculator in repository.Calculators)
|
||||
{
|
||||
if (calculator is IForceCalculator forceCalculator)
|
||||
{
|
||||
forceCalculator.InputData.Primitives.Clear();
|
||||
}
|
||||
else if (calculator is ICrackCalculator crackCalculator)
|
||||
{
|
||||
crackCalculator.InputData.Primitives.Clear();
|
||||
}
|
||||
else if (calculator is IValueDiagramCalculator valueDiagramCalculator)
|
||||
{
|
||||
valueDiagramCalculator.InputData.Primitives.Clear();
|
||||
}
|
||||
else if (calculator is ICurvatureCalculator curvatureCalculator)
|
||||
{
|
||||
curvatureCalculator.InputData.Primitives.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// skip
|
||||
}
|
||||
}
|
||||
Items.Clear();
|
||||
}
|
||||
|
||||
public ICommand DeleteSelectedCommand => deleteSelectedCommand ??= new RelayCommand(DeleteSelected, o => Items.Count > 0);
|
||||
|
||||
private void DeleteSelected(object commandParameter)
|
||||
@@ -98,8 +128,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
.ToList();
|
||||
foreach (var item in deletePrimitivesList)
|
||||
{
|
||||
repository.Primitives.Remove(item.NdmPrimitive);
|
||||
Items.Remove(item);
|
||||
RemoveFromRepository(item);
|
||||
}
|
||||
Refresh();
|
||||
OnPropertyChanged(nameof(Items));
|
||||
@@ -107,6 +136,35 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveFromRepository(PrimitiveBase item)
|
||||
{
|
||||
repository.Primitives.Remove(item.NdmPrimitive);
|
||||
foreach (var calculator in repository.Calculators)
|
||||
{
|
||||
if (calculator is IForceCalculator forceCalculator)
|
||||
{
|
||||
forceCalculator.InputData.Primitives.Remove(item.NdmPrimitive);
|
||||
}
|
||||
else if (calculator is ICrackCalculator crackCalculator)
|
||||
{
|
||||
crackCalculator.InputData.Primitives.Remove(item.NdmPrimitive);
|
||||
}
|
||||
else if (calculator is IValueDiagramCalculator valueDiagramCalculator)
|
||||
{
|
||||
valueDiagramCalculator.InputData.Primitives.Remove(item.NdmPrimitive);
|
||||
}
|
||||
else if (calculator is ICurvatureCalculator curvatureCalculator)
|
||||
{
|
||||
curvatureCalculator.InputData.Primitives.Remove(item.NdmPrimitive);
|
||||
}
|
||||
else
|
||||
{
|
||||
// skip
|
||||
}
|
||||
}
|
||||
Items.Remove(item);
|
||||
}
|
||||
|
||||
private void SetMaterialToPrimitives(object obj)
|
||||
{
|
||||
if (SelectedItem is null) { return; }
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperLogics.Models.Primitives;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.CrossSections
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
|
||||
namespace StructureHelperLogics.Models.CrossSections
|
||||
{
|
||||
public interface ICrossSectionRepository : ISaveable, IHasHeadMaterials, IHasPrimitives, IHasForceActions, IHasCalculators
|
||||
public interface ICrossSectionRepository : ISaveable, IHasHeadMaterials, IHasForcesAndPrimitives, IHasCalculators
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
/// <summary>
|
||||
/// Input data fo roce tuple calculator
|
||||
/// </summary>
|
||||
public interface IForceCalculatorInputData : IInputData, ISaveable, IHasPrimitives, IHasForceActions
|
||||
public interface IForceCalculatorInputData : IInputData, ISaveable, IHasForcesAndPrimitives
|
||||
{
|
||||
/// <summary>
|
||||
/// Accuracy of calculating
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
private Calculator calculator;
|
||||
private ILoaderResults calcResult;
|
||||
private IStressLogic stressLogic = new StressLogic();
|
||||
private IStressPointsLogic stressPointsLogic;
|
||||
private IStressPointsLogic StressPointsLogic => stressPointsLogic ??= new StressPointsLogic();
|
||||
|
||||
public IForceTupleInputData InputData { get; set; }
|
||||
|
||||
@@ -138,10 +140,11 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
List<INdm> overStrainedNdms = new();
|
||||
foreach (var ndm in InputData.NdmCollection)
|
||||
{
|
||||
var strain = stressLogic.GetTotalStrain(calcResult.ForceStrainPair.StrainMatrix, ndm);
|
||||
if (strain < ndm.Material.LimitNegativeStrain || strain > ndm.Material.LimitPositiveStrain)
|
||||
IStrainMatrix strainMatrix = calcResult.ForceStrainPair.StrainMatrix;
|
||||
var strains = StressPointsLogic.GetTotalStrains(strainMatrix, ndm);
|
||||
if (strains.Min() < ndm.Material.LimitNegativeStrain || strains.Max() > ndm.Material.LimitPositiveStrain)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Elementary part x = {ndm.CenterX}, y = {ndm.CenterY} has strain epsilon = {strain}, positive limit strain epsilon+,max = {ndm.Material.LimitPositiveStrain}, negative limit strain epsilon-,min = {ndm.Material.LimitNegativeStrain}", TraceLogStatuses.Warning);
|
||||
TraceLogger?.AddMessage($"Elementary part x = {ndm.CenterX}, y = {ndm.CenterY} has max strain epsilon,max = {strains.Max()}, min strain epsilon,min = {strains.Min()}, positive limit strain epsilon+,max = {ndm.Material.LimitPositiveStrain}, negative limit strain epsilon-,min = {ndm.Material.LimitNegativeStrain}", TraceLogStatuses.Warning);
|
||||
overStrainedNdms.Add(ndm);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.Curvatures
|
||||
@@ -8,7 +7,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.Curvatures
|
||||
/// <summary>
|
||||
/// Input data for calculator of curvature of cross-section
|
||||
/// </summary>
|
||||
public interface ICurvatureCalculatorInputData : IInputData, ISaveable, IHasForceActions, IHasPrimitives
|
||||
public interface ICurvatureCalculatorInputData : IInputData, ISaveable, IHasForcesAndPrimitives
|
||||
{
|
||||
IDeflectionFactor DeflectionFactor { get; set; }
|
||||
bool ConsiderSofteningFactor { get; set; }
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
|
||||
/// <summary>
|
||||
/// Implements input data for Value diagram calculator
|
||||
/// </summary>
|
||||
public interface IValueDiagramCalculatorInputData : ISaveable, IInputData, IHasForceActions, IHasPrimitives
|
||||
public interface IValueDiagramCalculatorInputData : ISaveable, IInputData, IHasForcesAndPrimitives
|
||||
{
|
||||
IStateCalcTermPair StateTermPair { get; set; }
|
||||
/// <summary>
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
/// <summary>
|
||||
/// Input data for crack calculator
|
||||
/// </summary>
|
||||
public interface ICrackCalculatorInputData : IInputData, IHasPrimitives, IHasForceActions, ISaveable
|
||||
public interface ICrackCalculatorInputData : IInputData, IHasForcesAndPrimitives, ISaveable
|
||||
{
|
||||
/// <summary>
|
||||
/// Used difined data for crack width calculation
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives
|
||||
{
|
||||
public interface IHasForcesAndPrimitives : IHasPrimitives, IHasForceActions
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using netDxf.Entities;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Services;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.Curvatures;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives
|
||||
{
|
||||
public class CrossSectionRepositoryCheckLogic : CheckEntityLogic<ICrossSectionRepository>
|
||||
{
|
||||
private bool result;
|
||||
private
|
||||
ICheckEntityLogic<IHasForcesAndPrimitives> primitivesCheckLogic;
|
||||
ICheckEntityLogic<IHasForcesAndPrimitives> PrimitivesCheckLogic => primitivesCheckLogic ??= new RepositoryHasForcesAndPrimitivesCheckLogic(Entity) { TraceLogger = TraceLogger};
|
||||
public override bool Check()
|
||||
{
|
||||
result = true;
|
||||
CheckObject.ThrowIfNull(Entity);
|
||||
foreach (var item in Entity.Calculators)
|
||||
{
|
||||
if (item is IForceCalculator forceCalculator)
|
||||
{
|
||||
ProcessCalculatorInputData(forceCalculator.InputData);
|
||||
}
|
||||
else if (item is ICrackCalculator crackCalculator)
|
||||
{
|
||||
ProcessCalculatorInputData(crackCalculator.InputData);
|
||||
}
|
||||
else if (item is IValueDiagramCalculator valueDiagramCalculator)
|
||||
{
|
||||
ProcessCalculatorInputData(valueDiagramCalculator.InputData);
|
||||
}
|
||||
else if (item is ICurvatureCalculator curvatureCalculator)
|
||||
{
|
||||
ProcessCalculatorInputData(curvatureCalculator.InputData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// skip
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ProcessCalculatorInputData(IHasForcesAndPrimitives inputData)
|
||||
{
|
||||
PrimitivesCheckLogic.Entity = inputData;
|
||||
if (PrimitivesCheckLogic.Check() == false)
|
||||
{
|
||||
CheckResult += "\n" + PrimitivesCheckLogic.CheckResult;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Services;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives
|
||||
{
|
||||
public class RepositoryHasForcesAndPrimitivesCheckLogic : CheckEntityLogic<IHasForcesAndPrimitives>
|
||||
{
|
||||
|
||||
ICheckEntityLogic<IHasPrimitives> primitivesCheckLogic;
|
||||
ICheckEntityLogic<IHasPrimitives> PrimitivesCheckLogic => primitivesCheckLogic ??= new RepositoryHasPrimitivesCheckLogic(Repository) { TraceLogger = TraceLogger };
|
||||
public ICrossSectionRepository Repository { get; }
|
||||
|
||||
public RepositoryHasForcesAndPrimitivesCheckLogic(ICrossSectionRepository repository)
|
||||
{
|
||||
Repository = repository;
|
||||
}
|
||||
|
||||
public override bool Check()
|
||||
{
|
||||
CheckObject.ThrowIfNull(Repository);
|
||||
CheckObject.ThrowIfNull(Entity);
|
||||
bool result = true;
|
||||
PrimitivesCheckLogic.Entity = Entity;
|
||||
if (PrimitivesCheckLogic.Check() == false)
|
||||
{
|
||||
CheckResult += "\n";
|
||||
CheckResult += PrimitivesCheckLogic.CheckResult;
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Services;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Primitives
|
||||
{
|
||||
public class RepositoryHasPrimitivesCheckLogic : CheckEntityLogic<IHasPrimitives>
|
||||
{
|
||||
public ICrossSectionRepository Repository { get; }
|
||||
|
||||
public RepositoryHasPrimitivesCheckLogic(ICrossSectionRepository crossSectionRepository)
|
||||
{
|
||||
Repository = crossSectionRepository;
|
||||
}
|
||||
|
||||
public override bool Check()
|
||||
{
|
||||
bool result = true;
|
||||
CheckObject.ThrowIfNull(Repository);
|
||||
CheckObject.ThrowIfNull(Entity);
|
||||
foreach (var primitive in Entity.Primitives)
|
||||
{
|
||||
if (! Repository.Primitives.Contains(primitive))
|
||||
{
|
||||
TraceMessage($"Repository does not contain primitive Id = {primitive.Id}, Name = {primitive.Name}");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,6 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="FunctionalTests\Ndms\SteelSections\" />
|
||||
<Folder Include="FunctionalTests\RCs\Anchorage\" />
|
||||
<Folder Include="UnitTests\ConvertStrategiesTest\" />
|
||||
<Folder Include="UnitTests\WindowTests\Calculations\CalculationProperties\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using DataAccess.DTOs;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.ConvertStrategiesTest
|
||||
{
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class HasForceAndPrimitivesProcessLogicTests
|
||||
{
|
||||
private Mock<IProcessLogic<IHasForceActions>> mockForcesLogic;
|
||||
private Mock<IProcessLogic<IHasPrimitives>> mockPrimitivesLogic;
|
||||
private Mock<IHasForcesAndPrimitives> mockSource;
|
||||
private Mock<IHasForcesAndPrimitives> mockTarget;
|
||||
private Mock<Dictionary<(Guid id, Type type), ISaveable>> mockDictionary;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mockForcesLogic = new Mock<IProcessLogic<IHasForceActions>>(MockBehavior.Strict);
|
||||
mockPrimitivesLogic = new Mock<IProcessLogic<IHasPrimitives>>(MockBehavior.Strict);
|
||||
mockDictionary = new Mock<Dictionary<(Guid id, Type type), ISaveable>>();
|
||||
|
||||
mockSource = new Mock<IHasForcesAndPrimitives>();
|
||||
mockTarget = new Mock<IHasForcesAndPrimitives>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Process_WhenUsingDIInjects_ShouldCallBothInternalLogics()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new HasForcesAndPrimitivesProcessLogic(
|
||||
ConvertDirection.FromDTO,
|
||||
mockForcesLogic.Object,
|
||||
mockPrimitivesLogic.Object
|
||||
)
|
||||
{
|
||||
Source = mockSource.Object,
|
||||
Target = mockTarget.Object
|
||||
};
|
||||
|
||||
// Setup mocked behavior
|
||||
mockForcesLogic.SetupSet(x => x.Source = mockSource.Object);
|
||||
mockForcesLogic.SetupSet(x => x.Target = mockTarget.Object);
|
||||
mockForcesLogic.SetupSet(x => x.ReferenceDictionary = mockDictionary.Object);
|
||||
mockForcesLogic.Setup(x => x.Process());
|
||||
|
||||
mockPrimitivesLogic.SetupSet(x => x.Source = mockSource.Object);
|
||||
mockPrimitivesLogic.SetupSet(x => x.Target = mockTarget.Object);
|
||||
mockPrimitivesLogic.SetupSet(x => x.ReferenceDictionary = mockDictionary.Object);
|
||||
mockPrimitivesLogic.Setup(x => x.Process());
|
||||
sut.ReferenceDictionary = new Dictionary<(Guid id, Type type), ISaveable>();
|
||||
|
||||
// Act
|
||||
sut.Process();
|
||||
|
||||
// Assert
|
||||
mockForcesLogic.Verify(x => x.Process(), Times.Once);
|
||||
mockPrimitivesLogic.Verify(x => x.Process(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Process_PassesSourceAndTargetCorrectly_ToBothSubLogics()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new HasForcesAndPrimitivesProcessLogic(
|
||||
ConvertDirection.ToDTO,
|
||||
mockForcesLogic.Object,
|
||||
mockPrimitivesLogic.Object)
|
||||
{
|
||||
Source = mockSource.Object,
|
||||
Target = mockTarget.Object,
|
||||
};
|
||||
|
||||
mockForcesLogic.SetupSet(x => x.Source = mockSource.Object);
|
||||
mockForcesLogic.SetupSet(x => x.Target = mockTarget.Object);
|
||||
mockForcesLogic.Setup(x => x.Process());
|
||||
|
||||
mockPrimitivesLogic.SetupSet(x => x.Source = mockSource.Object);
|
||||
mockPrimitivesLogic.SetupSet(x => x.Target = mockTarget.Object);
|
||||
mockPrimitivesLogic.Setup(x => x.Process());
|
||||
sut.ReferenceDictionary = new Dictionary<(Guid id, Type type), ISaveable>();
|
||||
|
||||
// Act
|
||||
sut.Process();
|
||||
|
||||
// Assert
|
||||
mockForcesLogic.VerifySet(x => x.Source = mockSource.Object);
|
||||
mockForcesLogic.VerifySet(x => x.Target = mockTarget.Object);
|
||||
|
||||
mockPrimitivesLogic.VerifySet(x => x.Source = mockSource.Object);
|
||||
mockPrimitivesLogic.VerifySet(x => x.Target = mockTarget.Object);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using DataAccess.DTOs;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.ConvertStrategiesTest
|
||||
{
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class ValueDiagramCalculatorInputDataFromDTOConvertStrategyTests
|
||||
{
|
||||
private Mock<IUpdateStrategy<IValueDiagramCalculatorInputData>> mockUpdate;
|
||||
private Mock<IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO>> mockDiagramConvert;
|
||||
private Mock<IProcessLogic<IHasForcesAndPrimitives>> mockForcePrimLogic;
|
||||
private Mock<IConvertStrategy<Accuracy, AccuracyDTO>> mockAccuracyConvert;
|
||||
|
||||
private ValueDiagramCalculatorInputDataFromDTOConvertStrategy sut;
|
||||
|
||||
private ValueDiagramCalculatorInputDataDTO sampleDTO;
|
||||
private ValueDiagramEntityDTO diagramDTO;
|
||||
private ValueDiagramEntity sampleDiagramEntity;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mockUpdate = new Mock<IUpdateStrategy<IValueDiagramCalculatorInputData>>(MockBehavior.Strict);
|
||||
mockDiagramConvert = new Mock<IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO>>(MockBehavior.Strict);
|
||||
mockForcePrimLogic = new Mock<IProcessLogic<IHasForcesAndPrimitives>>(MockBehavior.Strict);
|
||||
mockAccuracyConvert = new Mock<IConvertStrategy<Accuracy, AccuracyDTO>>(MockBehavior.Strict);
|
||||
|
||||
sut = new ValueDiagramCalculatorInputDataFromDTOConvertStrategy(
|
||||
mockUpdate.Object,
|
||||
mockDiagramConvert.Object,
|
||||
mockForcePrimLogic.Object,
|
||||
mockAccuracyConvert.Object
|
||||
);
|
||||
|
||||
diagramDTO = new ValueDiagramEntityDTO(Guid.Empty);
|
||||
sampleDiagramEntity = new ValueDiagramEntity(Guid.NewGuid());
|
||||
|
||||
sampleDTO = new ValueDiagramCalculatorInputDataDTO(Guid.NewGuid())
|
||||
{
|
||||
};
|
||||
sampleDTO.Diagrams.Add(diagramDTO);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetNewItem_ShouldReturnItemWithSameId()
|
||||
{
|
||||
// Arrange
|
||||
mockUpdate.Setup(x => x.Update(It.IsAny<IValueDiagramCalculatorInputData>(), sampleDTO));
|
||||
mockForcePrimLogic.SetupSet(x => x.Source = sampleDTO);
|
||||
mockForcePrimLogic.SetupSet(x => x.Target = It.IsAny<IValueDiagramCalculatorInputData>());
|
||||
mockForcePrimLogic.Setup(x => x.Process());
|
||||
mockDiagramConvert.Setup(x => x.Convert(diagramDTO)).Returns(sampleDiagramEntity);
|
||||
|
||||
// Act
|
||||
var result = sut.GetNewItem(sampleDTO);
|
||||
|
||||
// Assert
|
||||
Assert.That(sampleDTO.Id, Is.EqualTo(result.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetNewItem_ShouldCallUpdateStrategy()
|
||||
{
|
||||
// Arrange
|
||||
mockUpdate.Setup(x => x.Update(It.IsAny<IValueDiagramCalculatorInputData>(), sampleDTO));
|
||||
mockForcePrimLogic.SetupSet(x => x.Source = sampleDTO);
|
||||
mockForcePrimLogic.SetupSet(x => x.Target = It.IsAny<IValueDiagramCalculatorInputData>());
|
||||
mockForcePrimLogic.Setup(x => x.Process());
|
||||
mockDiagramConvert.Setup(x => x.Convert(diagramDTO)).Returns(sampleDiagramEntity);
|
||||
|
||||
// Act
|
||||
sut.GetNewItem(sampleDTO);
|
||||
|
||||
// Assert
|
||||
mockUpdate.Verify(x => x.Update(It.IsAny<IValueDiagramCalculatorInputData>(), sampleDTO), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetNewItem_ShouldCallForcePrimitiveProcessing()
|
||||
{
|
||||
// Arrange
|
||||
mockUpdate.Setup(x => x.Update(It.IsAny<IValueDiagramCalculatorInputData>(), sampleDTO));
|
||||
|
||||
mockForcePrimLogic.SetupSet(x => x.Source = sampleDTO);
|
||||
mockForcePrimLogic.SetupSet(x => x.Target = It.IsAny<IValueDiagramCalculatorInputData>());
|
||||
mockForcePrimLogic.Setup(x => x.Process());
|
||||
|
||||
mockDiagramConvert.Setup(x => x.Convert(diagramDTO)).Returns(sampleDiagramEntity);
|
||||
|
||||
// Act
|
||||
sut.GetNewItem(sampleDTO);
|
||||
|
||||
// Assert
|
||||
mockForcePrimLogic.Verify(x => x.Process(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetNewItem_ShouldConvertAllDiagrams()
|
||||
{
|
||||
// Arrange
|
||||
mockUpdate.Setup(x => x.Update(It.IsAny<IValueDiagramCalculatorInputData>(), sampleDTO));
|
||||
|
||||
mockForcePrimLogic.SetupSet(x => x.Source = sampleDTO);
|
||||
mockForcePrimLogic.SetupSet(x => x.Target = It.IsAny<IValueDiagramCalculatorInputData>());
|
||||
mockForcePrimLogic.Setup(x => x.Process());
|
||||
|
||||
mockDiagramConvert.Setup(x => x.Convert(diagramDTO)).Returns(sampleDiagramEntity);
|
||||
|
||||
// Act
|
||||
var result = sut.GetNewItem(sampleDTO);
|
||||
|
||||
// Assert
|
||||
Assert.That(1, Is.EqualTo(result.Diagrams.Count));
|
||||
Assert.That(sampleDiagramEntity, Is.SameAs(result.Diagrams[0]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user