diff --git a/Profiles/CatalogueProfiles/American/SingletonAmericanBase.cs b/Profiles/CatalogueProfiles/American/SingletonAmericanBase.cs index 402d94f8..b802fb0a 100644 --- a/Profiles/CatalogueProfiles/American/SingletonAmericanBase.cs +++ b/Profiles/CatalogueProfiles/American/SingletonAmericanBase.cs @@ -9,5 +9,6 @@ public abstract class SingletonAmericanBase : SingletonCatalogueBase, IAme public Catalogue Catalogue => Catalogue.AmericanAISC; public abstract AmericanShape Shape { get; } public abstract string Label { get; } + public virtual string Description => Label.Replace(" ", "\u2009"); } } diff --git a/Profiles/CatalogueProfiles/European/SingletonEuropeanBase.cs b/Profiles/CatalogueProfiles/European/SingletonEuropeanBase.cs index 2d27906c..baee40b5 100644 --- a/Profiles/CatalogueProfiles/European/SingletonEuropeanBase.cs +++ b/Profiles/CatalogueProfiles/European/SingletonEuropeanBase.cs @@ -9,5 +9,6 @@ public abstract class SingletonEuropeanBase : SingletonCatalogueBase, IEur public Catalogue Catalogue => Catalogue.EuropeanEN10365; public abstract EuropeanShape Shape { get; } public abstract string Label { get; } + public virtual string Description => Label.Replace(" ", "\u2009"); } } diff --git a/Profiles/IProfiles/IProfile.cs b/Profiles/IProfiles/IProfile.cs index 637917dd..ae82392a 100644 --- a/Profiles/IProfiles/IProfile.cs +++ b/Profiles/IProfiles/IProfile.cs @@ -2,5 +2,8 @@ namespace MagmaWorks.Taxonomy.Profiles { - public interface IProfile : ITaxonomySerializable { } + public interface IProfile : ITaxonomySerializable + { + string Description { get; } + } } diff --git a/Profiles/Perimeter/Perimeter.cs b/Profiles/Perimeter/Perimeter.cs index 9a1882b2..cbde4314 100644 --- a/Profiles/Perimeter/Perimeter.cs +++ b/Profiles/Perimeter/Perimeter.cs @@ -28,6 +28,8 @@ public IList VoidEdges } } + public string Description => GetDescription(); + private ILocalPolyline2d _outerEdge; private IList _voidEdges; @@ -84,5 +86,15 @@ private static ILocalPolyline2d EnsureClosedPolygon(ILocalPolyline2d polygon) closed.Points.Add(closed.Points[0]); return closed; } + + private string GetDescription() + { + if (VoidEdges != null && VoidEdges.Count > 0) + { + return $"Outer Edge with {OuterEdge.Points.Count} Vertices and {VoidEdges.Count} void(s)"; + } + + return $"{OuterEdge.Points.Count} Vertices"; + } } } diff --git a/Profiles/ProfileTests/IParallelFlangeTests.cs b/Profiles/ProfileTests/IParallelFlangeTests.cs index 65739cde..beaf440b 100644 --- a/Profiles/ProfileTests/IParallelFlangeTests.cs +++ b/Profiles/ProfileTests/IParallelFlangeTests.cs @@ -247,6 +247,8 @@ public class MockHEB500 : IIParallelFlange public Length FlangeThickness => new Length(28, LengthUnit.Millimeter); public Length WebThickness => new Length(14.5, LengthUnit.Millimeter); + public string Description => "HE 500 B"; + public MockHEB500() { } } } diff --git a/Profiles/ProfileTests/Utility/DescriptionTests.cs b/Profiles/ProfileTests/Utility/DescriptionTests.cs new file mode 100644 index 00000000..b0c6566a --- /dev/null +++ b/Profiles/ProfileTests/Utility/DescriptionTests.cs @@ -0,0 +1,118 @@ +using MagmaWorks.Taxonomy.Profiles; +using OasysUnits; +using OasysUnits.Units; + +namespace ProfileTests +{ + public class DescriptionTests + { + [Fact] + public void RectangleProfileDescriptionTest() + { + // Assemble + var h = new Length(20, LengthUnit.Centimeter); + var w = new Length(500.4, LengthUnit.Millimeter); + var prfl = new Rectangle(w, h); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("500 × 200 mm", description); + } + + [Fact] + public void CircleProfileDescriptionTest() + { + // Assemble + var dia = new Length(2.3, LengthUnit.Centimeter); + ICircle prfl = new Circle(dia); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("Ø 2.3 cm", description); + } + + [Fact] + public void CircularHollowProfileDescriptionTest() + { + // Assemble + var dia = new Length(2.3, LengthUnit.Centimeter); + var thk = new Length(10.9, LengthUnit.Millimeter); + ICircularHollow prfl = new CircularHollow(dia, thk); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("Ø 2.3 × 1.1 cm", description); + } + + [Fact] + public void BackToBackAngleProfileDescriptionTest() + { + // Assemble + var h = new Length(2.3, LengthUnit.Centimeter); + var w = new Length(5.4, LengthUnit.Centimeter); + var webThk = new Length(10.9, LengthUnit.Millimeter); + var flangeThk = new Length(15, LengthUnit.Millimeter); + var dist = new Length(2.5, LengthUnit.Millimeter); + IDoubleAngle prfl = new DoubleAngle(h, w, webThk, flangeThk, dist); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("2.3 × 5.4 × 1.1 × 1.5 cm B2B 2.5 mm", description); + } + + [Fact] + public void BackToBackChannelProfileDescriptionTest() + { + // Assemble + var h = new Length(2.3, LengthUnit.Centimeter); + var w = new Length(5.4, LengthUnit.Centimeter); + var webThk = new Length(10.9, LengthUnit.Millimeter); + var flangeThk = new Length(15, LengthUnit.Millimeter); + var dist = new Length(2.5, LengthUnit.Millimeter); + IDoubleChannel prfl = new DoubleChannel(h, w, webThk, flangeThk, dist); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("2.3 × 5.4 × 1.1 × 1.5 cm B2B 2.5 mm", description); + } + + [Fact] + public void TrapezoidProfileDescriptionTest() + { + // Assemble + var h = new Length(2.3, LengthUnit.Centimeter); + var wTop = new Length(5.4, LengthUnit.Centimeter); + var wBottom = new Length(0.5, LengthUnit.Meter); + ITrapezoid prfl = new Trapezoid(wTop, wBottom, h); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("5.4 / 50.0 × 2.3 cm", description); + } + + [Fact] + public void HE300BProfileDescriptionTest() + { + // Assemble + var prfl = new HE300B(); + + // Act + string description = prfl.Description; + + // Assert + Assert.Equal("HE 300 B", description); + } + } +} diff --git a/Profiles/Profiles/Angle.cs b/Profiles/Profiles/Angle.cs index 50801f02..8038192f 100644 --- a/Profiles/Profiles/Angle.cs +++ b/Profiles/Profiles/Angle.cs @@ -8,6 +8,8 @@ public class Angle : IAngle public Length Width { get; set; } public Length WebThickness { get; set; } public Length FlangeThickness { get; set; } + public string Description + => Utility.Describe(Height, Width, WebThickness, FlangeThickness); public Angle(Length height, Length width, Length webThickness, Length flangeThickness) { diff --git a/Profiles/Profiles/C.cs b/Profiles/Profiles/C.cs index 6b7069d5..a8708b9e 100644 --- a/Profiles/Profiles/C.cs +++ b/Profiles/Profiles/C.cs @@ -9,6 +9,8 @@ public class C : IC public Length WebThickness { get; set; } public Length FlangeThickness { get; set; } public Length Lip { get; set; } + public string Description + => Utility.Describe(Height, Width, WebThickness, FlangeThickness, Lip); public C(Length height, Length width, Length webThickness, Length flangeThickness, Length lip) { diff --git a/Profiles/Profiles/Channel.cs b/Profiles/Profiles/Channel.cs index 9f6c11e5..9e39a0bd 100644 --- a/Profiles/Profiles/Channel.cs +++ b/Profiles/Profiles/Channel.cs @@ -8,6 +8,8 @@ public class Channel : IChannel public Length Width { get; set; } public Length WebThickness { get; set; } public Length FlangeThickness { get; set; } + public string Description + => Utility.Describe(Height, Width, WebThickness, FlangeThickness); public Channel(Length height, Length width, Length webThickness, Length flangeThickness) { diff --git a/Profiles/Profiles/Circle.cs b/Profiles/Profiles/Circle.cs index 5fd30413..373b1a33 100644 --- a/Profiles/Profiles/Circle.cs +++ b/Profiles/Profiles/Circle.cs @@ -5,6 +5,7 @@ namespace MagmaWorks.Taxonomy.Profiles public class Circle : ICircle { public Length Diameter { get; set; } + public string Description => $"Ø\u2009{Utility.Describe(Diameter)}"; public Circle(Length diameter) { diff --git a/Profiles/Profiles/CircularHollow.cs b/Profiles/Profiles/CircularHollow.cs index 2353af9f..fcb6d99a 100644 --- a/Profiles/Profiles/CircularHollow.cs +++ b/Profiles/Profiles/CircularHollow.cs @@ -5,8 +5,9 @@ namespace MagmaWorks.Taxonomy.Profiles public class CircularHollow : ICircularHollow { public Length Diameter { get; set; } - public Length Thickness { get; set; } + public string Description + => $"Ø\u2009{Utility.Describe(Diameter, Thickness)}"; public CircularHollow(Length diameter, Length thickness) { diff --git a/Profiles/Profiles/Cruciform.cs b/Profiles/Profiles/Cruciform.cs index b7ac0969..83a2479e 100644 --- a/Profiles/Profiles/Cruciform.cs +++ b/Profiles/Profiles/Cruciform.cs @@ -8,6 +8,8 @@ public class Cruciform : ICruciform public Length Width { get; set; } public Length FlangeThickness { get; set; } public Length WebThickness { get; set; } + public string Description + => Utility.Describe(Height, Width, FlangeThickness, WebThickness); public Cruciform(Length height, Length width, Length flangeThickness, Length webThickness) { diff --git a/Profiles/Profiles/CustomI.cs b/Profiles/Profiles/CustomI.cs index 2703da56..225b179d 100644 --- a/Profiles/Profiles/CustomI.cs +++ b/Profiles/Profiles/CustomI.cs @@ -10,6 +10,9 @@ public class CustomI : ICustomI public Length TopFlangeThickness { get; set; } public Length BottomFlangeThickness { get; set; } public Length WebThickness { get; set; } + public string Description + => Utility.Describe(Height, TopFlangeWidth, BottomFlangeWidth, + BottomFlangeThickness, TopFlangeThickness, WebThickness); public CustomI(Length height, Length topFlangeWidth, Length bottomFlangeWidth, Length topFlangeThickness, Length bottomFlangeThickness, Length webThickness) { diff --git a/Profiles/Profiles/DoubleAngle.cs b/Profiles/Profiles/DoubleAngle.cs index 80764a44..1750905b 100644 --- a/Profiles/Profiles/DoubleAngle.cs +++ b/Profiles/Profiles/DoubleAngle.cs @@ -9,6 +9,7 @@ public class DoubleAngle : IDoubleAngle public Length WebThickness { get; set; } public Length FlangeThickness { get; set; } public Length BackToBackDistance { get; set; } + public string Description => GetDescription(); public DoubleAngle(Length height, Length width, Length webThickness, Length flangeThickness, Length backToBackDistance) { @@ -18,5 +19,16 @@ public DoubleAngle(Length height, Length width, Length webThickness, Length flan FlangeThickness = flangeThickness; BackToBackDistance = backToBackDistance; } + + private string GetDescription() + { + string description = $"{Utility.Describe(Height, Width, WebThickness, FlangeThickness)} B2B\u2009"; + if (BackToBackDistance.Value != 0) + { + description += $"{BackToBackDistance.ToString().Replace(" ", "\u2009")}"; + } + + return description; + } } } diff --git a/Profiles/Profiles/DoubleChannel.cs b/Profiles/Profiles/DoubleChannel.cs index ce9e4896..785e1043 100644 --- a/Profiles/Profiles/DoubleChannel.cs +++ b/Profiles/Profiles/DoubleChannel.cs @@ -9,6 +9,7 @@ public class DoubleChannel : IDoubleChannel public Length WebThickness { get; set; } public Length FlangeThickness { get; set; } public Length BackToBackDistance { get; set; } + public string Description => GetDescription(); public DoubleChannel(Length height, Length width, Length webThickness, Length flangeThickness, Length backToBackDistance) { @@ -18,5 +19,16 @@ public DoubleChannel(Length height, Length width, Length webThickness, Length fl FlangeThickness = flangeThickness; BackToBackDistance = backToBackDistance; } + + private string GetDescription() + { + string description = $"{Utility.Describe(Height, Width, WebThickness, FlangeThickness)} B2B\u2009"; + if (BackToBackDistance.Value != 0) + { + description += $"{BackToBackDistance.ToString().Replace(" ", "\u2009")}"; + } + + return description; + } } } diff --git a/Profiles/Profiles/Ellipse.cs b/Profiles/Profiles/Ellipse.cs index aab21024..55777baa 100644 --- a/Profiles/Profiles/Ellipse.cs +++ b/Profiles/Profiles/Ellipse.cs @@ -6,6 +6,7 @@ public class Ellipse : IEllipse { public Length Height { get; set; } public Length Width { get; set; } + public string Description => Utility.Describe(Height, Width); public Ellipse(Length width, Length height) { diff --git a/Profiles/Profiles/EllipseHollow.cs b/Profiles/Profiles/EllipseHollow.cs index 8b5fb090..b489149e 100644 --- a/Profiles/Profiles/EllipseHollow.cs +++ b/Profiles/Profiles/EllipseHollow.cs @@ -7,6 +7,7 @@ public class EllipseHollow : IEllipseHollow public Length Height { get; set; } public Length Width { get; set; } public Length Thickness { get; set; } + public string Description => Utility.Describe(Height, Width, Thickness); public EllipseHollow(Length width, Length height, Length thickness) { diff --git a/Profiles/Profiles/I.cs b/Profiles/Profiles/I.cs index 5ff45c0c..08e08573 100644 --- a/Profiles/Profiles/I.cs +++ b/Profiles/Profiles/I.cs @@ -8,6 +8,7 @@ public class I : II public Length Width { get; set; } public Length FlangeThickness { get; set; } public Length WebThickness { get; set; } + public string Description => Utility.Describe(Height, Width, FlangeThickness, WebThickness); public I(Length height, Length width, Length flangeThickness, Length webThickness) { diff --git a/Profiles/Profiles/Rectangle.cs b/Profiles/Profiles/Rectangle.cs index c0a3c87a..4f43320f 100644 --- a/Profiles/Profiles/Rectangle.cs +++ b/Profiles/Profiles/Rectangle.cs @@ -6,6 +6,7 @@ public class Rectangle : IRectangle { public Length Height { get; set; } public Length Width { get; set; } + public string Description => Utility.Describe(Width, Height); public Rectangle(Length width, Length height) { diff --git a/Profiles/Profiles/RectangularHollow.cs b/Profiles/Profiles/RectangularHollow.cs index a35f3901..810d4851 100644 --- a/Profiles/Profiles/RectangularHollow.cs +++ b/Profiles/Profiles/RectangularHollow.cs @@ -7,6 +7,7 @@ public class RectangularHollow : IRectangularHollow public Length Height { get; set; } public Length Width { get; set; } public Length Thickness { get; set; } + public string Description => Utility.Describe(Width, Height, Thickness); public RectangularHollow(Length width, Length height, Length thickness) { diff --git a/Profiles/Profiles/RoundedRectangle.cs b/Profiles/Profiles/RoundedRectangle.cs index 4500d1e9..664079e7 100644 --- a/Profiles/Profiles/RoundedRectangle.cs +++ b/Profiles/Profiles/RoundedRectangle.cs @@ -8,6 +8,7 @@ public class RoundedRectangle : IRoundedRectangle public Length Width { get; set; } public Length FlatHeight { get; set; } public Length FlatWidth { get; set; } + public string Description => Utility.Describe(Width, Height, FlatHeight, FlatWidth); public RoundedRectangle(Length width, Length height, Length flatWidth, Length flatHeight) { diff --git a/Profiles/Profiles/RoundedRectangularHollow.cs b/Profiles/Profiles/RoundedRectangularHollow.cs index 1e9de4be..19d792e2 100644 --- a/Profiles/Profiles/RoundedRectangularHollow.cs +++ b/Profiles/Profiles/RoundedRectangularHollow.cs @@ -9,6 +9,8 @@ public class RoundedRectangularHollow : IRoundedRectangularHollow public Length FlatHeight { get; set; } public Length FlatWidth { get; set; } public Length Thickness { get; set; } + public string Description + => Utility.Describe(Width, Height, FlatHeight, FlatWidth, Thickness); public RoundedRectangularHollow(Length width, Length height, Length flatWidth, Length flatHeight, Length thickness) { diff --git a/Profiles/Profiles/Tee.cs b/Profiles/Profiles/Tee.cs index 1cabd586..b6b413c5 100644 --- a/Profiles/Profiles/Tee.cs +++ b/Profiles/Profiles/Tee.cs @@ -8,6 +8,8 @@ public class Tee : ITee public Length Width { get; set; } public Length FlangeThickness { get; set; } public Length WebThickness { get; set; } + public string Description + => Utility.Describe(Height, Width, FlangeThickness, WebThickness); public Tee(Length height, Length width, Length flangeThickness, Length webThickness) { diff --git a/Profiles/Profiles/Trapezoid.cs b/Profiles/Profiles/Trapezoid.cs index d9cb6541..edad1f9e 100644 --- a/Profiles/Profiles/Trapezoid.cs +++ b/Profiles/Profiles/Trapezoid.cs @@ -1,4 +1,5 @@ using OasysUnits; +using OasysUnits.Units; namespace MagmaWorks.Taxonomy.Profiles { @@ -7,6 +8,7 @@ public class Trapezoid : ITrapezoid public Length Height { get; set; } public Length TopWidth { get; set; } public Length BottomWidth { get; set; } + public string Description => GetDescription(); public Trapezoid(Length topWidth, Length bottomWidth, Length height) { @@ -14,5 +16,14 @@ public Trapezoid(Length topWidth, Length bottomWidth, Length height) TopWidth = topWidth; BottomWidth = bottomWidth; } + + private string GetDescription() + { + LengthUnit u = Height.Unit; + string topAndBottom = Utility.Describe("/", TopWidth.ToUnit(u), BottomWidth); + topAndBottom = topAndBottom.Replace(Length.GetAbbreviation(u), string.Empty); + string height = Utility.Describe(Height); + return $"{topAndBottom}× {height}"; + } } } diff --git a/Profiles/Profiles/Utility/Utility.cs b/Profiles/Profiles/Utility/Utility.cs new file mode 100644 index 00000000..ced2d40d --- /dev/null +++ b/Profiles/Profiles/Utility/Utility.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Linq; +using OasysUnits; +using OasysUnits.Units; + +namespace MagmaWorks.Taxonomy.Profiles +{ + internal static class Utility + { + internal static string Describe(params Length[] values) + { + return Describe("×", values); + } + + internal static string Describe(string separator, params Length[] values) + { + var lengths = values.ToList(); + LengthUnit u = lengths.FirstOrDefault().Unit; + int significantDigitsAfterRadix = 3; + switch (u) + { + case LengthUnit.Millimeter: + significantDigitsAfterRadix = 0; + break; + + case LengthUnit.Centimeter: + significantDigitsAfterRadix = 1; + break; + } + + List strings = lengths.Select(s + => FormatDoubleWithSignificantDigits(s.As(u), significantDigitsAfterRadix)).ToList(); + return $"{string.Join($"\u2009{separator}\u2009", strings)}\u2009{Length.GetAbbreviation(u)}"; + } + + internal static string FormatDoubleWithSignificantDigits(double value, int significantDigitsAfterRadix) + { + return value.ToString($"N{significantDigitsAfterRadix}"); + } + } +} diff --git a/Profiles/Profiles/Z.cs b/Profiles/Profiles/Z.cs index d4b2d5d5..a39f0459 100644 --- a/Profiles/Profiles/Z.cs +++ b/Profiles/Profiles/Z.cs @@ -10,6 +10,9 @@ public class Z : IZ public Length Thickness { get; set; } public Length TopLip { get; set; } public Length BottomLip { get; set; } + public string Description => Utility.Describe( + Height, TopFlangeWidth, BottomFlangeWidth, Thickness, TopLip, BottomLip); + public Z(Length height, Length topFlangeWidth, Length bottomFlangeWidth, Length thickness, Length topLip, Length bottomLip) { Height = height;