Files
StructureHelper/StructureHelperLogics/Services/NdmPrimitives/NdmPrimitivesService.cs
2023-06-10 22:26:15 +05:00

95 lines
4.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using LoaderCalculator.Data.Ndms;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using StructureHelperLogics.Models.Primitives;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.NdmCalculations.Triangulations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using static System.Collections.Specialized.BitVector32;
namespace StructureHelperLogics.Services.NdmPrimitives
{
public static class NdmPrimitivesService
{
public static void CopyVisualProperty(IVisualProperty source, IVisualProperty target)
{
target.IsVisible = source.IsVisible;
target.Color = source.Color;
target.SetMaterialColor = source.SetMaterialColor;
target.Opacity = source.Opacity;
target.ZIndex = source.ZIndex;
}
public static void CopyNdmProperties (INdmPrimitive source, INdmPrimitive target)
{
target.Name = source.Name + " copy" ;
if (source.HeadMaterial != null) target.HeadMaterial = source.HeadMaterial;
CopyVisualProperty(source.VisualProperty, target.VisualProperty);
target.CenterX = source.CenterX;
target.CenterY = source.CenterY;
target.Triangulate = source.Triangulate;
ForceTupleService.CopyProperties(source.UsersPrestrain, target.UsersPrestrain);
}
public static void CopyDivisionProperties(IHasDivisionSize source, IHasDivisionSize target)
{
target.NdmMaxSize = source.NdmMaxSize;
target.NdmMinDivision = source.NdmMinDivision;
target.ClearUnderlying = source.ClearUnderlying;
}
public static List<INdm> GetNdms(INdmPrimitive primitive, LimitStates limitState, CalcTerms calcTerm)
{
//Формируем коллекцию элементарных участков для расчета в библитеке (т.е. выполняем триангуляцию)
List<INdm> ndmCollection = new List<INdm>();
var material = primitive.HeadMaterial.GetLoaderMaterial(limitState, calcTerm);
ndmCollection.AddRange(primitive.GetNdms(material));
return ndmCollection;
}
public static List<INdm> GetNdms(IEnumerable<INdmPrimitive> primitives, LimitStates limitState, CalcTerms calcTerm)
{
var orderedNdmPrimitives = primitives.OrderBy(x => x.VisualProperty.ZIndex);
var ndms = new List<INdm>();
foreach (var item in orderedNdmPrimitives)
{
if (item is IHasDivisionSize)
{
var hasDivision = item as IHasDivisionSize;
if (hasDivision.ClearUnderlying == true)
{
ndms.RemoveAll(x => hasDivision.IsPointInside(new Point2D() { X = x.CenterX, Y = x.CenterY }) == true);
}
}
if (item.Triangulate == true)
{
ndms.AddRange(GetNdms(item, limitState, calcTerm));
}
}
return ndms;
}
public static bool CheckPrimitives(IEnumerable<INdmPrimitive> primitives)
{
if (primitives.Count() == 0) { throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": Count of primitive must be greater than zero"); }
if (primitives.Count(x => x.Triangulate == true) == 0) { throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": There are not primitives to triangulate"); }
foreach (var item in primitives)
{
if (item.Triangulate == true &
item.HeadMaterial is null)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": Primitive: {item.Name} can't be triangulated since material is null");
}
}
return true;
}
}
}