Fix removing primitives

This commit is contained in:
Evgeny Redikultsev
2025-12-07 18:36:50 +05:00
parent 70bfd065c4
commit 681ab17781
32 changed files with 697 additions and 224 deletions

View File

@@ -1,10 +1,4 @@
using System; namespace DataAccess.DTOs
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{ {
public enum ConvertDirection public enum ConvertDirection
{ {

View File

@@ -11,21 +11,18 @@ namespace DataAccess.DTOs
{ {
public class CurvatureCalculatorInputDataFromDTOConvertStrategy : ConvertStrategy<CurvatureCalculatorInputData, CurvatureCalculatorInputDataDTO> public class CurvatureCalculatorInputDataFromDTOConvertStrategy : ConvertStrategy<CurvatureCalculatorInputData, CurvatureCalculatorInputDataDTO>
{ {
private IHasPrimitivesProcessLogic primitivesProcessLogic; private IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesProcessLogic;
private IHasForceActionsProcessLogic actionsProcessLogic;
private IUpdateStrategy<ICurvatureCalculatorInputData> updateStrategy; private IUpdateStrategy<ICurvatureCalculatorInputData> updateStrategy;
private IConvertStrategy<DeflectionFactor, DeflectionFactorDTO> deflectionConvertStrategy; 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) 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) public override CurvatureCalculatorInputData GetNewItem(CurvatureCalculatorInputDataDTO source)
{ {
ChildClass = this;
NewItem = new(source.Id); NewItem = new(source.Id);
UpdateStrategy.Update(NewItem, source); UpdateStrategy.Update(NewItem, source);
if (source.DeflectionFactor is not DeflectionFactorDTO deflectionFactorDTO) if (source.DeflectionFactor is not DeflectionFactorDTO deflectionFactorDTO)
@@ -33,22 +30,16 @@ namespace DataAccess.DTOs
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source.DeflectionFactor) + ": deflection factor"); throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source.DeflectionFactor) + ": deflection factor");
} }
NewItem.DeflectionFactor = DeflectionConvertStrategy.Convert(deflectionFactorDTO); NewItem.DeflectionFactor = DeflectionConvertStrategy.Convert(deflectionFactorDTO);
ProcessPrimitives(source); ProcessForcesAndPrimitives(source);
ProcessActions(source);
return NewItem; return NewItem;
} }
private void ProcessPrimitives(IHasPrimitives source)
private void ProcessForcesAndPrimitives(IHasForcesAndPrimitives source)
{ {
PrimitivesProcessLogic.Source = source; ForcesAndPrimitivesProcessLogic.Source = source;
PrimitivesProcessLogic.Target = NewItem; ForcesAndPrimitivesProcessLogic.Target = NewItem;
PrimitivesProcessLogic.Process(); ForcesAndPrimitivesProcessLogic.Process();
}
private void ProcessActions(IHasForceActions source)
{
ActionsProcessLogic.Source = source;
ActionsProcessLogic.Target = NewItem;
ActionsProcessLogic.Process();
} }
} }
} }

View File

@@ -7,13 +7,11 @@ namespace DataAccess.DTOs
{ {
public class CurvatureCalculatorInputDataToDTOConvertStrategy : ConvertStrategy<CurvatureCalculatorInputDataDTO, ICurvatureCalculatorInputData> public class CurvatureCalculatorInputDataToDTOConvertStrategy : ConvertStrategy<CurvatureCalculatorInputDataDTO, ICurvatureCalculatorInputData>
{ {
private IHasPrimitivesProcessLogic primitivesProcessLogic; private IProcessLogic<IHasForcesAndPrimitives> actionsProcessLogic;
private IHasForceActionsProcessLogic actionsProcessLogic;
private IUpdateStrategy<ICurvatureCalculatorInputData> updateStrategy; private IUpdateStrategy<ICurvatureCalculatorInputData> updateStrategy;
private IConvertStrategy<DeflectionFactorDTO, IDeflectionFactor> deflectionConvertStrategy; private IConvertStrategy<DeflectionFactorDTO, IDeflectionFactor> deflectionConvertStrategy;
private IHasPrimitivesProcessLogic PrimitivesProcessLogic => primitivesProcessLogic ??= new HasPrimitivesProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger}; private IProcessLogic<IHasForcesAndPrimitives> ForceAndPrimitivesLogic => actionsProcessLogic ??= new HasForcesAndPrimitivesProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
private IHasForceActionsProcessLogic ActionsProcessLogic => actionsProcessLogic ??= new HasForceActionsProcessLogic(ConvertDirection.ToDTO) { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
private IUpdateStrategy<ICurvatureCalculatorInputData> UpdateStrategy => updateStrategy ??= new CurvatureCalculatorInputDataUpdateStrategy() { UpdateChildren = false}; private IUpdateStrategy<ICurvatureCalculatorInputData> UpdateStrategy => updateStrategy ??= new CurvatureCalculatorInputDataUpdateStrategy() { UpdateChildren = false};
private IConvertStrategy<DeflectionFactorDTO, IDeflectionFactor> DeflectionConvertStrategy => deflectionConvertStrategy ??= new DeflectionFactorToDTOConvertStrategy(this); private IConvertStrategy<DeflectionFactorDTO, IDeflectionFactor> DeflectionConvertStrategy => deflectionConvertStrategy ??= new DeflectionFactorToDTOConvertStrategy(this);
@@ -23,25 +21,19 @@ namespace DataAccess.DTOs
public override CurvatureCalculatorInputDataDTO GetNewItem(ICurvatureCalculatorInputData source) public override CurvatureCalculatorInputDataDTO GetNewItem(ICurvatureCalculatorInputData source)
{ {
ChildClass = this;
NewItem = new(source.Id); NewItem = new(source.Id);
UpdateStrategy.Update(NewItem, source); UpdateStrategy.Update(NewItem, source);
NewItem.DeflectionFactor = DeflectionConvertStrategy.Convert(source.DeflectionFactor); NewItem.DeflectionFactor = DeflectionConvertStrategy.Convert(source.DeflectionFactor);
ProcessPrimitives(source);
ProcessActions(source); ProcessActions(source);
return NewItem; return NewItem;
} }
private void ProcessPrimitives(IHasPrimitives source) private void ProcessActions(IHasForcesAndPrimitives source)
{ {
PrimitivesProcessLogic.Source = source; ForceAndPrimitivesLogic.Source = source;
PrimitivesProcessLogic.Target = NewItem; ForceAndPrimitivesLogic.Target = NewItem;
PrimitivesProcessLogic.Process(); ForceAndPrimitivesLogic.Process();
}
private void ProcessActions(IHasForceActions source)
{
ActionsProcessLogic.Source = source;
ActionsProcessLogic.Target = NewItem;
ActionsProcessLogic.Process();
} }
} }
} }

View File

@@ -1,12 +1,6 @@
using StructureHelper.Models.Materials; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Services; using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs namespace DataAccess.DTOs
{ {

View File

@@ -1,12 +1,7 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using System; using StructureHelperCommon.Models.Forces;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StructureHelperCommon.Infrastructures.Exceptions;
namespace DataAccess.DTOs namespace DataAccess.DTOs
{ {

View File

@@ -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();
}
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces; using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
namespace DataAccess.DTOs namespace DataAccess.DTOs
@@ -6,12 +7,7 @@ namespace DataAccess.DTOs
/// <summary> /// <summary>
/// Logic for antities which have force actions /// Logic for antities which have force actions
/// </summary> /// </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();
} }
} }

View File

@@ -4,13 +4,7 @@ using StructureHelperLogics.NdmCalculations.Primitives;
namespace DataAccess.DTOs.Converters 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();
} }
} }

View 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();
}
}

View File

@@ -3,17 +3,9 @@ using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials; using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.NdmCalculations.Cracking;
using StructureHelperLogics.NdmCalculations.Primitives; using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs namespace DataAccess.DTOs
{ {
@@ -22,9 +14,12 @@ namespace DataAccess.DTOs
private const string convertStarted = " converting is started"; private const string convertStarted = " converting is started";
private const string convertFinished = " converting has been finished successfully"; private const string convertFinished = " converting has been finished successfully";
private CrossSectionRepository newRepository; private CrossSectionRepository newRepository;
private ICheckEntityLogic<ICrossSectionRepository> checkEntityLogic;
private ICheckEntityLogic<ICrossSectionRepository> CheckEntityLogic => checkEntityLogic ??= new CrossSectionRepositoryCheckLogic() {Entity = oldRepository};
private IHasPrimitivesProcessLogic primitivesProcessLogic = new HasPrimitivesProcessLogic(ConvertDirection.FromDTO); private IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesLogic;
private IHasForceActionsProcessLogic actionsProcessLogic = new HasForceActionsProcessLogic(ConvertDirection.FromDTO); 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) 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) 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); TraceLogger?.AddMessage("Cross-Section repository" + convertStarted);
newRepository = new(source.Id); newRepository = new(source.Id);
ProcessMaterials(source); ProcessMaterials(source);
ProcessActions(source); ProcessForcesAndPrimitives(source);
ProcessPrimitives(source);
ProcessCalculators(source); ProcessCalculators(source);
TraceLogger?.AddMessage("Cross-Section repository" + convertFinished); TraceLogger?.AddMessage("Cross-Section repository" + convertFinished);
return newRepository; return newRepository;
@@ -56,22 +57,12 @@ namespace DataAccess.DTOs
TraceLogger?.AddMessage("Calculators" + convertFinished); 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; ForcesAndPrimitivesLogic.Source = source;
actionsProcessLogic.Target = newRepository; ForcesAndPrimitivesLogic.Target = newRepository;
actionsProcessLogic.ReferenceDictionary = ReferenceDictionary; ForcesAndPrimitivesLogic.Process();
actionsProcessLogic.TraceLogger = TraceLogger;
actionsProcessLogic.Process();
} }
private void ProcessMaterials(IHasHeadMaterials source) private void ProcessMaterials(IHasHeadMaterials source)

View File

@@ -12,6 +12,10 @@ namespace DataAccess.DTOs
public class CrossSectionRepositoryToDTOConvertStrategy : IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> public class CrossSectionRepositoryToDTOConvertStrategy : IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>
{ {
private IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy; 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) public CrossSectionRepositoryToDTOConvertStrategy(IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy)
@@ -30,6 +34,13 @@ namespace DataAccess.DTOs
public CrossSectionRepositoryDTO Convert(ICrossSectionRepository source) 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(); Check();
InitializeStrategies(); InitializeStrategies();
try try

View File

@@ -11,22 +11,35 @@ namespace DataAccess.DTOs
{ {
private IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy; private IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy;
private IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO> diagramConvertStrategy; private IConvertStrategy<ValueDiagramEntity, ValueDiagramEntityDTO> diagramConvertStrategy;
private IHasPrimitivesProcessLogic primitivesProcessLogic; private IProcessLogic<IHasForcesAndPrimitives> forcesAndPrimitivesLogic;
private IHasForceActionsProcessLogic actionsProcessLogic;
private IConvertStrategy<Accuracy, AccuracyDTO> accuracyConvertStrategy; 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(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) public override ValueDiagramCalculatorInputData GetNewItem(ValueDiagramCalculatorInputDataDTO source)
{ {
ChildClass = this; ChildClass = this;
NewItem = new(source.Id); NewItem = new(source.Id);
InitializeStrategies(); UpdateStrategy.Update(NewItem, source);
updateStrategy.Update(NewItem, source); ProcessForcesAndPrimitives(source);
ProcessPrimitives(source);
ProcessActions(source);
NewItem.Diagrams.Clear(); NewItem.Diagrams.Clear();
foreach (var diagram in source.Diagrams) foreach (var diagram in source.Diagrams)
{ {
@@ -34,35 +47,16 @@ namespace DataAccess.DTOs
{ {
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(diagram)); throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(diagram));
} }
NewItem.Diagrams.Add(diagramConvertStrategy.Convert(diagramDTO)); NewItem.Diagrams.Add(DiagramConvertStrategy.Convert(diagramDTO));
} }
return NewItem; return NewItem;
} }
private void ProcessPrimitives(IHasPrimitives source) private void ProcessForcesAndPrimitives(IHasForcesAndPrimitives source)
{ {
primitivesProcessLogic.Source = source; ForcesAndPrimitivesLogic.Source = source;
primitivesProcessLogic.Target = NewItem; ForcesAndPrimitivesLogic.Target = NewItem;
primitivesProcessLogic.ReferenceDictionary = ReferenceDictionary; ForcesAndPrimitivesLogic.Process();
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 };
} }
} }
} }

View File

@@ -9,8 +9,10 @@ namespace DataAccess.DTOs
{ {
private IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy; private IUpdateStrategy<IValueDiagramCalculatorInputData> updateStrategy;
private IConvertStrategy<ValueDiagramEntityDTO, IValueDiagramEntity> diagramConvertStrategy; private IConvertStrategy<ValueDiagramEntityDTO, IValueDiagramEntity> diagramConvertStrategy;
private IHasPrimitivesProcessLogic primitivesProcessLogic; private IConvertStrategy<ValueDiagramEntityDTO, IValueDiagramEntity> DiagramConvertStrategy => diagramConvertStrategy ??= new ValueDiagramEntityToDTOConvertStrategy(this);
private IHasForceActionsProcessLogic actionsProcessLogic; 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() public ValueDiagramCalculatorInputDataToDTOConvertStrategy() : base()
{ {
@@ -24,41 +26,21 @@ namespace DataAccess.DTOs
{ {
ChildClass = this; ChildClass = this;
NewItem = new(source.Id); NewItem = new(source.Id);
InitializeStrategies(); UpdateStrategy.Update(NewItem, source);
updateStrategy.Update(NewItem, source);
ProcessPrimitives(source);
ProcessActions(source); ProcessActions(source);
NewItem.Diagrams.Clear(); NewItem.Diagrams.Clear();
foreach (var diagram in source.Diagrams) foreach (var diagram in source.Diagrams)
{ {
NewItem.Diagrams.Add(diagramConvertStrategy.Convert(diagram)); NewItem.Diagrams.Add(DiagramConvertStrategy.Convert(diagram));
} }
return NewItem; return NewItem;
} }
private void ProcessPrimitives(IHasPrimitives source) private void ProcessActions(IHasForcesAndPrimitives source)
{ {
primitivesProcessLogic.Source = source; ActionsProcessLogic.Source = source;
primitivesProcessLogic.Target = NewItem; ActionsProcessLogic.Target = NewItem;
primitivesProcessLogic.ReferenceDictionary = ReferenceDictionary; ActionsProcessLogic.Process();
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 };
} }
} }
} }

View File

@@ -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);
}
}

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

View File

@@ -5,17 +5,16 @@ using FieldVisualizer.Services.ColorServices;
using HelixToolkit.Geometry; using HelixToolkit.Geometry;
using HelixToolkit.Maths; using HelixToolkit.Maths;
using HelixToolkit.SharpDX; using HelixToolkit.SharpDX;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.Wpf.SharpDX; using HelixToolkit.Wpf.SharpDX;
using System; using StructureHelper.Services.Reports.Services;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Text;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews
{ {
public class GetModels3dByValuePrimivesLogic : IGetModels3dLogic public class GetModels3dByValuePrimivesLogic : IGetModels3dLogic
{ {
private MaterialService materialService = new();
public double ZoomValue { get; set; } public double ZoomValue { get; set; }
public bool InvertNormal { get; set; } public bool InvertNormal { get; set; }
public IColorMap ColorMap { get; set; } public IColorMap ColorMap { get; set; }
@@ -53,8 +52,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
var builder = new MeshBuilder(); var builder = new MeshBuilder();
Vector3 p0 = new Vector3((float)circle.CenterX, (float)circle.CenterY, 0); // bottom center 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, (float)(circle.Value * ZoomValue)); // top center
Vector3 p1 = new Vector3((float)circle.CenterX, (float)circle.CenterY, cylinderHeight); // top center
builder.AddCylinder(p0, p1, (float)circle.Diameter, 8); builder.AddCylinder(p0, p1, (float)circle.Diameter, 8);
@@ -62,11 +60,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
var cylinderGeometry = builder.ToMeshGeometry3D(); var cylinderGeometry = builder.ToMeshGeometry3D();
// Create material (constant grey) // Create material (constant grey)
var material = new PhongMaterial var material = materialService.CreateValueMaterial(circle.Value, ValueRange, ColorMap);
{
DiffuseColor = ToColor4(ColorOperations.GetColorByValue(ValueRange, ColorMap, circle.Value)),
SpecularShininess = 50f
};
// Create model // Create model
var cylinderModel = new MeshGeometryModel3D var cylinderModel = new MeshGeometryModel3D
@@ -79,24 +73,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
private MeshGeometryModel3D CreateZeroTriangle(ITrianglePrimitive triangle) private MeshGeometryModel3D CreateZeroTriangle(ITrianglePrimitive triangle)
{ {
// Triangle vertices var mesh = CreateTriangleMesh(triangle, false);
Vector3 p0 = new Vector3((float)triangle.Point1.X, (float)triangle.Point1.Y, 0); var material = materialService.CreateTransparentPlaneMaterial(0.4f);
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 model = new MeshGeometryModel3D var model = new MeshGeometryModel3D
{ {
Geometry = mesh, Geometry = mesh,
@@ -109,23 +87,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
private MeshGeometryModel3D CreateTriangle(ITrianglePrimitive triangle) private MeshGeometryModel3D CreateTriangle(ITrianglePrimitive triangle)
{ {
// Triangle vertices var mesh = CreateTriangleMesh(triangle, true);
Vector3 p0 = new Vector3((float)triangle.Point1.X, (float)triangle.Point1.Y, (float)(triangle.ValuePoint1 * ZoomValue)); var material = materialService.CreateValueMaterial(triangle.Value, ValueRange, ColorMap);
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 model = new MeshGeometryModel3D var model = new MeshGeometryModel3D
{ {
Geometry = mesh, Geometry = mesh,
@@ -136,7 +99,24 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
return model; 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( return new Color4(
c.R / 255f, c.R / 255f,

View File

@@ -14,8 +14,6 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
bool ShowZeroPlane { get; set; } bool ShowZeroPlane { get; set; }
IValueRange ValueRange { get; set; } IValueRange ValueRange { get; set; }
double ZoomValue { get; set; } double ZoomValue { get; set; }
static abstract Color4 ToColor4(System.Windows.Media.Color c);
void GetModels3d(IEnumerable<IValuePrimitive> valuePrimitives, Viewport3DX viewport); void GetModels3d(IEnumerable<IValuePrimitive> valuePrimitives, Viewport3DX viewport);
} }
} }

View File

@@ -9,6 +9,7 @@ using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Primitives; using StructureHelperLogics.Models.Primitives;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Analyses.Curvatures;
using StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams; using StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams;
using StructureHelperLogics.NdmCalculations.Cracking; using StructureHelperLogics.NdmCalculations.Cracking;
using StructureHelperLogics.NdmCalculations.Primitives; 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); var dialogResult = MessageBox.Show("Delete all primitives?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
repository.Primitives.Clear(); ClearRepository();
Items.Clear();
Refresh(); Refresh();
OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(Items));
OnPropertyChanged(nameof(PrimitivesCount)); 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); public ICommand DeleteSelectedCommand => deleteSelectedCommand ??= new RelayCommand(DeleteSelected, o => Items.Count > 0);
private void DeleteSelected(object commandParameter) private void DeleteSelected(object commandParameter)
@@ -98,8 +128,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
.ToList(); .ToList();
foreach (var item in deletePrimitivesList) foreach (var item in deletePrimitivesList)
{ {
repository.Primitives.Remove(item.NdmPrimitive); RemoveFromRepository(item);
Items.Remove(item);
} }
Refresh(); Refresh();
OnPropertyChanged(nameof(Items)); 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) private void SetMaterialToPrimitives(object obj)
{ {
if (SelectedItem is null) { return; } if (SelectedItem is null) { return; }

View File

@@ -1,14 +1,7 @@
using StructureHelper.Models.Materials; using StructureHelper.Models.Materials;
using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Primitives;
using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Primitives; using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperLogics.Models.CrossSections namespace StructureHelperLogics.Models.CrossSections
{ {

View File

@@ -6,7 +6,7 @@ using StructureHelperLogics.NdmCalculations.Primitives;
namespace StructureHelperLogics.Models.CrossSections namespace StructureHelperLogics.Models.CrossSections
{ {
public interface ICrossSectionRepository : ISaveable, IHasHeadMaterials, IHasPrimitives, IHasForceActions, IHasCalculators public interface ICrossSectionRepository : ISaveable, IHasHeadMaterials, IHasForcesAndPrimitives, IHasCalculators
{ {
} }

View File

@@ -10,7 +10,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
/// <summary> /// <summary>
/// Input data fo roce tuple calculator /// Input data fo roce tuple calculator
/// </summary> /// </summary>
public interface IForceCalculatorInputData : IInputData, ISaveable, IHasPrimitives, IHasForceActions public interface IForceCalculatorInputData : IInputData, ISaveable, IHasForcesAndPrimitives
{ {
/// <summary> /// <summary>
/// Accuracy of calculating /// Accuracy of calculating

View File

@@ -24,6 +24,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
private Calculator calculator; private Calculator calculator;
private ILoaderResults calcResult; private ILoaderResults calcResult;
private IStressLogic stressLogic = new StressLogic(); private IStressLogic stressLogic = new StressLogic();
private IStressPointsLogic stressPointsLogic;
private IStressPointsLogic StressPointsLogic => stressPointsLogic ??= new StressPointsLogic();
public IForceTupleInputData InputData { get; set; } public IForceTupleInputData InputData { get; set; }
@@ -138,10 +140,11 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
List<INdm> overStrainedNdms = new(); List<INdm> overStrainedNdms = new();
foreach (var ndm in InputData.NdmCollection) foreach (var ndm in InputData.NdmCollection)
{ {
var strain = stressLogic.GetTotalStrain(calcResult.ForceStrainPair.StrainMatrix, ndm); IStrainMatrix strainMatrix = calcResult.ForceStrainPair.StrainMatrix;
if (strain < ndm.Material.LimitNegativeStrain || strain > ndm.Material.LimitPositiveStrain) 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); overStrainedNdms.Add(ndm);
} }
}; };

View File

@@ -1,6 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Primitives; using StructureHelperLogics.NdmCalculations.Primitives;
namespace StructureHelperLogics.NdmCalculations.Analyses.Curvatures namespace StructureHelperLogics.NdmCalculations.Analyses.Curvatures
@@ -8,7 +7,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.Curvatures
/// <summary> /// <summary>
/// Input data for calculator of curvature of cross-section /// Input data for calculator of curvature of cross-section
/// </summary> /// </summary>
public interface ICurvatureCalculatorInputData : IInputData, ISaveable, IHasForceActions, IHasPrimitives public interface ICurvatureCalculatorInputData : IInputData, ISaveable, IHasForcesAndPrimitives
{ {
IDeflectionFactor DeflectionFactor { get; set; } IDeflectionFactor DeflectionFactor { get; set; }
bool ConsiderSofteningFactor { get; set; } bool ConsiderSofteningFactor { get; set; }

View File

@@ -8,7 +8,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ValueDiagrams
/// <summary> /// <summary>
/// Implements input data for Value diagram calculator /// Implements input data for Value diagram calculator
/// </summary> /// </summary>
public interface IValueDiagramCalculatorInputData : ISaveable, IInputData, IHasForceActions, IHasPrimitives public interface IValueDiagramCalculatorInputData : ISaveable, IInputData, IHasForcesAndPrimitives
{ {
IStateCalcTermPair StateTermPair { get; set; } IStateCalcTermPair StateTermPair { get; set; }
/// <summary> /// <summary>

View File

@@ -11,7 +11,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
/// <summary> /// <summary>
/// Input data for crack calculator /// Input data for crack calculator
/// </summary> /// </summary>
public interface ICrackCalculatorInputData : IInputData, IHasPrimitives, IHasForceActions, ISaveable public interface ICrackCalculatorInputData : IInputData, IHasForcesAndPrimitives, ISaveable
{ {
/// <summary> /// <summary>
/// Used difined data for crack width calculation /// Used difined data for crack width calculation

View File

@@ -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
{
}
}

View File

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

View File

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

View File

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

View File

@@ -33,7 +33,6 @@
<ItemGroup> <ItemGroup>
<Folder Include="FunctionalTests\Ndms\SteelSections\" /> <Folder Include="FunctionalTests\Ndms\SteelSections\" />
<Folder Include="FunctionalTests\RCs\Anchorage\" /> <Folder Include="FunctionalTests\RCs\Anchorage\" />
<Folder Include="UnitTests\ConvertStrategiesTest\" />
<Folder Include="UnitTests\WindowTests\Calculations\CalculationProperties\" /> <Folder Include="UnitTests\WindowTests\Calculations\CalculationProperties\" />
</ItemGroup> </ItemGroup>

View File

@@ -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);
}
}
}

View File

@@ -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]));
}
}
}