diff --git a/AdSecGH/Helpers/AdSecProfiles.cs b/AdSecGH/Helpers/AdSecProfiles.cs index e4c38c5..55325f3 100644 --- a/AdSecGH/Helpers/AdSecProfiles.cs +++ b/AdSecGH/Helpers/AdSecProfiles.cs @@ -1,181 +1,224 @@ -using Oasys.Taxonomy.Geometry; +using System; +using System.Linq; + +using Oasys.Profiles; using Oasys.Taxonomy.Profiles; +using IAngleProfile = Oasys.Profiles.IAngleProfile; +using ICatalogueProfile = Oasys.Profiles.ICatalogueProfile; +using IChannelProfile = Oasys.Profiles.IChannelProfile; +using ICircleHollowProfile = Oasys.Profiles.ICircleHollowProfile; +using ICircleProfile = Oasys.Profiles.ICircleProfile; +using ICruciformSymmetricalProfile = Oasys.Profiles.ICruciformSymmetricalProfile; +using IEllipseHollowProfile = Oasys.Profiles.IEllipseHollowProfile; +using IEllipseProfile = Oasys.Profiles.IEllipseProfile; +using IFlange = Oasys.Profiles.IFlange; +using IGeneralCProfile = Oasys.Profiles.IGeneralCProfile; +using IGeneralZProfile = Oasys.Profiles.IGeneralZProfile; +using IIBeamAsymmetricalProfile = Oasys.Profiles.IIBeamAsymmetricalProfile; +using IIBeamCellularProfile = Oasys.Profiles.IIBeamCellularProfile; +using IIBeamProfile = Oasys.Taxonomy.Profiles.IIBeamProfile; +using IPerimeterProfile = Oasys.Profiles.IPerimeterProfile; +using IProfile = Oasys.Profiles.IProfile; +using IRectangleHollowProfile = Oasys.Profiles.IRectangleHollowProfile; +using IRectangleProfile = Oasys.Profiles.IRectangleProfile; +using IRectoEllipseProfile = Oasys.Profiles.IRectoEllipseProfile; +using ISecantPileProfile = Oasys.Profiles.ISecantPileProfile; +using ISheetPileProfile = Oasys.Profiles.ISheetPileProfile; +using ITrapezoidProfile = Oasys.Profiles.ITrapezoidProfile; +using ITSectionProfile = Oasys.Profiles.ITSectionProfile; +using IWeb = Oasys.Profiles.IWeb; +using IWebConstant = Oasys.Profiles.IWebConstant; +using IWebTapered = Oasys.Profiles.IWebTapered; + namespace AdSecGH.Helpers { public static class AdSecProfiles { - public static Oasys.Profiles.IProfile CreateProfile(IProfile profile) { + public static IProfile CreateProfile(Oasys.Taxonomy.Profiles.IProfile profile) { + if (profile == null) { + return null; + } + switch (profile.ProfileType) { - case ProfileType.Angle: - return CreateAngleProfile((IAngleProfile)profile); - case ProfileType.Catalogue: - return CreateCatalogueProfile((ICatalogueProfile)profile); - case ProfileType.Channel: - return CreateChannelProfile((IChannelProfile)profile); - case ProfileType.Circle: - return CreateCircleProfile((ICircleProfile)profile); + case ProfileType.Angle: return CreateAngleProfile((Oasys.Taxonomy.Profiles.IAngleProfile)profile); + case ProfileType.Catalogue: return CreateCatalogueProfile((Oasys.Taxonomy.Profiles.ICatalogueProfile)profile); + case ProfileType.Channel: return CreateChannelProfile((Oasys.Taxonomy.Profiles.IChannelProfile)profile); + case ProfileType.Circle: return CreateCircleProfile((Oasys.Taxonomy.Profiles.ICircleProfile)profile); case ProfileType.CircleHollow: - return CreateCircleHollowProfile((ICircleHollowProfile)profile); + return CreateCircleHollowProfile((Oasys.Taxonomy.Profiles.ICircleHollowProfile)profile); case ProfileType.CruciformSymmetrical: - return CreateCruciformSymmetricalProfile((ICruciformSymmetricalProfile)profile); - case ProfileType.Ellipse: - return CreateEllipseProfile((IEllipseProfile)profile); + return CreateCruciformSymmetricalProfile((Oasys.Taxonomy.Profiles.ICruciformSymmetricalProfile)profile); + case ProfileType.Ellipse: return CreateEllipseProfile((Oasys.Taxonomy.Profiles.IEllipseProfile)profile); case ProfileType.EllipseHollow: - return CreateEllipseHollowProfile((IEllipseHollowProfile)profile); - case ProfileType.GeneralC: - return CreateGeneralCProfile((IGeneralCProfile)profile); - case ProfileType.GeneralZ: - return CreateGeneralZProfile((IGeneralZProfile)profile); - case ProfileType.IBeam: - return CreateIBeamSymmetricalProfile((IBeamProfile)profile); - case ProfileType.IBeamAssymetrical: - return CreateIBeamAsymmetricalProfile((IBeamAsymmetricalProfile)profile); - case ProfileType.IBeamCellular: - return CreateIBeamCellularProfile((IBeamCellularProfile)profile); - case ProfileType.Perimeter: - return CreatePerimeterProfile((IPerimeterProfile)profile); - case ProfileType.Rectangle: - return CreateRectangleProfile((IRectangleProfile)profile); + return CreateEllipseHollowProfile((Oasys.Taxonomy.Profiles.IEllipseHollowProfile)profile); + case ProfileType.GeneralC: return CreateGeneralCProfile((Oasys.Taxonomy.Profiles.IGeneralCProfile)profile); + case ProfileType.GeneralZ: return CreateGeneralZProfile((Oasys.Taxonomy.Profiles.IGeneralZProfile)profile); + case ProfileType.IBeam: return CreateIBeamSymmetricalProfile((IBeamProfile)profile); + case ProfileType.IBeamAssymetrical: return CreateIBeamAsymmetricalProfile((IBeamAsymmetricalProfile)profile); + case ProfileType.IBeamCellular: return CreateIBeamCellularProfile((IBeamCellularProfile)profile); + case ProfileType.Perimeter: return CreatePerimeterProfile((Oasys.Taxonomy.Profiles.IPerimeterProfile)profile); + case ProfileType.Rectangle: return CreateRectangleProfile((Oasys.Taxonomy.Profiles.IRectangleProfile)profile); case ProfileType.RectangleHollow: - return CreateRectangleHollowProfile((IRectangleHollowProfile)profile); - case ProfileType.RectoCircle: - return CreateStadiumProfile((IRectoCircleProfile)profile); + return CreateRectangleHollowProfile((Oasys.Taxonomy.Profiles.IRectangleHollowProfile)profile); + case ProfileType.RectoCircle: return CreateStadiumProfile((IRectoCircleProfile)profile); case ProfileType.RectoEllipse: - return CreateRectoEllipseProfile((IRectoEllipseProfile)profile); + return CreateRectoEllipseProfile((Oasys.Taxonomy.Profiles.IRectoEllipseProfile)profile); case ProfileType.SecantPile: - return CreateSecantPileProfile((ISecantPileProfile)profile); - case ProfileType.SheetPile: - return CreateSheetPileProfile((ISheetPileProfile)profile); - case ProfileType.Trapezoid: - return CreateTrapezoidProfile((ITrapezoidProfile)profile); - case ProfileType.TSection: - return CreateTSectionProfile((ITSectionProfile)profile); + return CreateSecantPileProfile((Oasys.Taxonomy.Profiles.ISecantPileProfile)profile); + case ProfileType.SheetPile: return CreateSheetPileProfile((Oasys.Taxonomy.Profiles.ISheetPileProfile)profile); + case ProfileType.Trapezoid: return CreateTrapezoidProfile((Oasys.Taxonomy.Profiles.ITrapezoidProfile)profile); + case ProfileType.TSection: return CreateTSectionProfile((Oasys.Taxonomy.Profiles.ITSectionProfile)profile); case ProfileType.Undefined: default: - throw new System.NotImplementedException(); + throw new NotImplementedException(); } } - public static Oasys.Profiles.IAngleProfile CreateAngleProfile(IAngleProfile profile) { - return Oasys.Profiles.IAngleProfile.Create(profile.Depth, CreateFlange(profile.Flange), CreateWeb(profile.Web)); + public static IAngleProfile CreateAngleProfile(Oasys.Taxonomy.Profiles.IAngleProfile profile) { + return IAngleProfile.Create(profile.Depth, CreateFlange(profile.Flange), CreateWeb(profile.Web)); } - public static Oasys.Profiles.ICatalogueProfile CreateCatalogueProfile(ICatalogueProfile profile) { - return Oasys.Profiles.ICatalogueProfile.Create(profile.Description); + public static ICatalogueProfile CreateCatalogueProfile(Oasys.Taxonomy.Profiles.ICatalogueProfile profile) { + return ICatalogueProfile.Create(profile.Description); } - public static Oasys.Profiles.IChannelProfile CreateChannelProfile(IChannelProfile profile) { - return Oasys.Profiles.IChannelProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Web)); + public static IChannelProfile CreateChannelProfile(Oasys.Taxonomy.Profiles.IChannelProfile profile) { + return IChannelProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Web)); } - public static Oasys.Profiles.ICircleHollowProfile CreateCircleHollowProfile(ICircleHollowProfile profile) { - return Oasys.Profiles.ICircleHollowProfile.Create(profile.Diameter, profile.WallThickness); + public static ICircleHollowProfile CreateCircleHollowProfile(Oasys.Taxonomy.Profiles.ICircleHollowProfile profile) { + return ICircleHollowProfile.Create(profile.Diameter, profile.WallThickness); } - public static Oasys.Profiles.ICircleProfile CreateCircleProfile(ICircleProfile profile) { - return Oasys.Profiles.ICircleProfile.Create(profile.Diameter); + public static ICircleProfile CreateCircleProfile(Oasys.Taxonomy.Profiles.ICircleProfile profile) { + return ICircleProfile.Create(profile.Diameter); } - public static Oasys.Profiles.ICruciformSymmetricalProfile CreateCruciformSymmetricalProfile(ICruciformSymmetricalProfile profile) { - return Oasys.Profiles.ICruciformSymmetricalProfile.Create(profile.Depth, CreateFlange(profile.Flange), CreateWebConstant(profile.Web)); + public static ICruciformSymmetricalProfile CreateCruciformSymmetricalProfile( + Oasys.Taxonomy.Profiles.ICruciformSymmetricalProfile profile) { + return ICruciformSymmetricalProfile.Create(profile.Depth, CreateFlange(profile.Flange), + CreateWebConstant(profile.Web)); } - public static Oasys.Profiles.IEllipseHollowProfile CreateEllipseHollowProfile(IEllipseHollowProfile profile) { - return Oasys.Profiles.IEllipseHollowProfile.Create(profile.Depth, profile.Width, profile.WallThickness); + public static IEllipseHollowProfile CreateEllipseHollowProfile( + Oasys.Taxonomy.Profiles.IEllipseHollowProfile profile) { + return IEllipseHollowProfile.Create(profile.Depth, profile.Width, profile.WallThickness); } - public static Oasys.Profiles.IEllipseProfile CreateEllipseProfile(IEllipseProfile profile) { - return Oasys.Profiles.IEllipseProfile.Create(profile.Depth, profile.Width); + public static IEllipseProfile CreateEllipseProfile(Oasys.Taxonomy.Profiles.IEllipseProfile profile) { + return IEllipseProfile.Create(profile.Depth, profile.Width); } - public static Oasys.Profiles.IGeneralCProfile CreateGeneralCProfile(IGeneralCProfile profile) { - return Oasys.Profiles.IGeneralCProfile.Create(profile.Depth, profile.FlangeWidth, profile.Lip, profile.Thickness); + public static IGeneralCProfile CreateGeneralCProfile(Oasys.Taxonomy.Profiles.IGeneralCProfile profile) { + return IGeneralCProfile.Create(profile.Depth, profile.FlangeWidth, profile.Lip, profile.Thickness); } - public static Oasys.Profiles.IGeneralZProfile CreateGeneralZProfile(IGeneralZProfile profile) { - return Oasys.Profiles.IGeneralZProfile.Create(profile.Depth, profile.TopFlangeWidth, profile.BottomFlangeWidth, profile.TopLip, profile.BottomLip, profile.Thickness); + public static IGeneralZProfile CreateGeneralZProfile(Oasys.Taxonomy.Profiles.IGeneralZProfile profile) { + return IGeneralZProfile.Create(profile.Depth, profile.TopFlangeWidth, profile.BottomFlangeWidth, profile.TopLip, + profile.BottomLip, profile.Thickness); } - public static Oasys.Profiles.IIBeamAsymmetricalProfile CreateIBeamAsymmetricalProfile(IIBeamAsymmetricalProfile profile) { - return Oasys.Profiles.IIBeamAsymmetricalProfile.Create(profile.Depth, CreateFlange(profile.TopFlange), CreateFlange(profile.BottomFlange), CreateWeb(profile.Web)); + public static IIBeamAsymmetricalProfile CreateIBeamAsymmetricalProfile( + Oasys.Taxonomy.Profiles.IIBeamAsymmetricalProfile profile) { + return IIBeamAsymmetricalProfile.Create(profile.Depth, CreateFlange(profile.TopFlange), + CreateFlange(profile.BottomFlange), CreateWeb(profile.Web)); } - public static Oasys.Profiles.IIBeamCellularProfile CreateIBeamCellularProfile(IIBeamCellularProfile profile) { - return Oasys.Profiles.IIBeamCellularProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Web), profile.WebOpening); + public static IIBeamCellularProfile CreateIBeamCellularProfile( + Oasys.Taxonomy.Profiles.IIBeamCellularProfile profile) { + return IIBeamCellularProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Web), + profile.WebOpening); } - public static Oasys.Profiles.IIBeamSymmetricalProfile CreateIBeamSymmetricalProfile(IIBeamProfile profile) { - return Oasys.Profiles.IIBeamSymmetricalProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Web)); + public static IIBeamSymmetricalProfile CreateIBeamSymmetricalProfile(IIBeamProfile profile) { + return IIBeamSymmetricalProfile.Create(profile.Depth, CreateFlange(profile.Flanges), + CreateWebConstant(profile.Web)); } - public static Oasys.Profiles.IPerimeterProfile CreatePerimeterProfile(IPerimeterProfile profile) { - var perimeter = Oasys.Profiles.IPerimeterProfile.Create(); + public static IPerimeterProfile CreatePerimeterProfile(Oasys.Taxonomy.Profiles.IPerimeterProfile profile) { + var perimeter = IPerimeterProfile.Create(); perimeter.SolidPolygon = CreatePolygon(profile.Perimeter); - foreach (IPolygon polygon in profile.VoidPolygons) { + foreach (var polygon in profile.VoidPolygons) { perimeter.VoidPolygons.Add(CreatePolygon(polygon)); } + return perimeter; } - private static Oasys.Profiles.IPolygon CreatePolygon(IPolygon p) { - var polygon = Oasys.Profiles.IPolygon.Create(); - foreach (IPoint2d point in p.Points) { - polygon.Points.Add(Oasys.Profiles.IPoint.Create(point.Y, point.Z)); - } - return polygon; + public static IRectangleHollowProfile CreateRectangleHollowProfile( + Oasys.Taxonomy.Profiles.IRectangleHollowProfile profile) { + return IRectangleHollowProfile.Create(profile.Depth, CreateFlange(profile.Flanges), + CreateWebConstant(profile.Webs)); } - public static Oasys.Profiles.IRectangleHollowProfile CreateRectangleHollowProfile(IRectangleHollowProfile profile) { - return Oasys.Profiles.IRectangleHollowProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Webs)); + public static IRectangleProfile CreateRectangleProfile(Oasys.Taxonomy.Profiles.IRectangleProfile profile) { + return IRectangleProfile.Create(profile.Depth, profile.Width); } - public static Oasys.Profiles.IRectangleProfile CreateRectangleProfile(IRectangleProfile profile) { - return Oasys.Profiles.IRectangleProfile.Create(profile.Depth, profile.Width); + public static IStadiumProfile CreateStadiumProfile(IRectoCircleProfile profile) { + return IStadiumProfile.Create(profile.Depth, profile.Width); } - public static Oasys.Profiles.IFlange CreateFlange(IFlange flange) { - return Oasys.Profiles.IFlange.Create(flange.Width, flange.Thickness); + public static IRectoEllipseProfile CreateRectoEllipseProfile(Oasys.Taxonomy.Profiles.IRectoEllipseProfile profile) { + return IRectoEllipseProfile.Create(profile.Depth, profile.DepthFlat, profile.Width, profile.WidthFlat); } - public static Oasys.Profiles.IStadiumProfile CreateStadiumProfile(IRectoCircleProfile profile) { - return Oasys.Profiles.IStadiumProfile.Create(profile.Depth, profile.Width); + public static ISecantPileProfile CreateSecantPileProfile(Oasys.Taxonomy.Profiles.ISecantPileProfile profile) { + return ISecantPileProfile.Create(profile.Diameter, profile.PileCentres, profile.PileCount, profile.IsWall); } - public static Oasys.Profiles.IRectoEllipseProfile CreateRectoEllipseProfile(IRectoEllipseProfile profile) { - return Oasys.Profiles.IRectoEllipseProfile.Create(profile.Depth, profile.DepthFlat, profile.Width, profile.WidthFlat); + public static ISheetPileProfile CreateSheetPileProfile(Oasys.Taxonomy.Profiles.ISheetPileProfile profile) { + return ISheetPileProfile.Create(profile.Depth, profile.Width, profile.TopFlangeWidth, profile.BottomFlangeWidth, + profile.FlangeThickness, profile.WebThickness); } - public static Oasys.Profiles.ISecantPileProfile CreateSecantPileProfile(ISecantPileProfile profile) { - return Oasys.Profiles.ISecantPileProfile.Create(profile.Diameter, profile.PileCentres, profile.PileCount, profile.IsWall); + public static ITrapezoidProfile CreateTrapezoidProfile(Oasys.Taxonomy.Profiles.ITrapezoidProfile profile) { + return ITrapezoidProfile.Create(profile.Depth, profile.TopWidth, profile.BottomWidth); } - public static Oasys.Profiles.ISheetPileProfile CreateSheetPileProfile(ISheetPileProfile profile) { - return Oasys.Profiles.ISheetPileProfile.Create(profile.Depth, profile.Width, profile.TopFlangeWidth, profile.BottomFlangeWidth, profile.FlangeThickness, profile.WebThickness); + public static ITSectionProfile CreateTSectionProfile(Oasys.Taxonomy.Profiles.ITSectionProfile profile) { + return ITSectionProfile.Create(profile.Depth, CreateFlange(profile.Flange), CreateWeb(profile.Web)); } - public static Oasys.Profiles.ITrapezoidProfile CreateTrapezoidProfile(ITrapezoidProfile profile) { - return Oasys.Profiles.ITrapezoidProfile.Create(profile.Depth, profile.TopWidth, profile.BottomWidth); + //helpers + + public static IPolygon CreatePolygon(Oasys.Taxonomy.Geometry.IPolygon p) { + var polygon = IPolygon.Create(); + if (p == null || p.Points == null || !p.Points.Any()) { + return polygon; + } + + foreach (var point in p.Points) { + polygon.Points.Add(IPoint.Create(point.Y, point.Z)); + } + + return polygon; } - public static Oasys.Profiles.ITSectionProfile CreateTSectionProfile(ITSectionProfile profile) { - return Oasys.Profiles.ITSectionProfile.Create(profile.Depth, CreateFlange(profile.Flange), CreateWeb(profile.Web)); + public static IFlange CreateFlange(Oasys.Taxonomy.Profiles.IFlange flange) { + return flange == null ? null : IFlange.Create(flange.Width, flange.Thickness); } - public static Oasys.Profiles.IWebConstant CreateWebConstant(IWebConstant web) { - return Oasys.Profiles.IWebConstant.Create(web.Thickness); + public static IWebConstant CreateWebConstant(Oasys.Taxonomy.Profiles.IWebConstant web) { + return IWebConstant.Create(web.Thickness); } - public static Oasys.Profiles.IWebTapered CreateWebTapered(IWebTapered web) { - return Oasys.Profiles.IWebTapered.Create(web.TopThickness, web.BottomThickness); + public static IWebTapered CreateWebTapered(Oasys.Taxonomy.Profiles.IWebTapered web) { + return IWebTapered.Create(web.TopThickness, web.BottomThickness); } - public static Oasys.Profiles.IWeb CreateWeb(IWeb web) { - if (web is IWebConstant webConstant) { - return CreateWebConstant(webConstant); - } else if (web is IWebTapered webTapered) { - return CreateWebTapered(webTapered); - } else { return null; } + public static IWeb CreateWeb(Oasys.Taxonomy.Profiles.IWeb web) { + IWeb result = null; + switch (web) { + case Oasys.Taxonomy.Profiles.IWebConstant webConstant: + result = CreateWebConstant(webConstant); + break; + case Oasys.Taxonomy.Profiles.IWebTapered webTapered: + result = CreateWebTapered(webTapered); + break; + } + return result; } } } diff --git a/AdSecGHTests/Helpers/AdSecProfilesTests.cs b/AdSecGHTests/Helpers/AdSecProfilesTests.cs new file mode 100644 index 0000000..912d4d0 --- /dev/null +++ b/AdSecGHTests/Helpers/AdSecProfilesTests.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; + +using AdSecGH.Helpers; + +using Oasys.Taxonomy.Geometry; +using Oasys.Taxonomy.Profiles; + +using OasysUnits; +using OasysUnits.Units; + +using Xunit; + +namespace AdSecGHTests.Helpers { + [Collection("GrasshopperFixture collection")] + public class AdSecProfilesTests { + private class WebUnknownDummy : IWeb { } + + private class ProfileUnknownDummy : IProfile { + public ProfileType ProfileType => (ProfileType)(-1); + public Angle Rotation => new Angle(-1, AngleUnit.Gradian); + } + + private static IAngleProfile angleProfile = null; + + public AdSecProfilesTests() { + angleProfile = SampleProfiles.GetAnAngleProfile(new WebConstant(new Length(1, LengthUnit.Inch))); + } + + [Fact] + public void CreateWeb_WithUnknownIWeb_ReturnsNull() { + var unknownWeb = new WebUnknownDummy(); + var result = AdSecProfiles.CreateWeb(unknownWeb); + + Assert.Null(result); + } + + [Fact] + public void CreateWeb_WithNullIWeb_ReturnsNull() { + var result = AdSecProfiles.CreateWeb(null); + + Assert.Null(result); + } + + [Fact] + public void CreateWeb_WithIWebConstant_ReturnsIWebConstant() { + var webConstant = (WebConstant)angleProfile.Web; + + var result = AdSecProfiles.CreateWeb(webConstant); + + Assert.Equal(webConstant.Thickness.As(LengthUnit.Meter), result.TopThickness.Value); + } + + [Fact] + public void CreateWeb_WithIWebTapered_ReturnsIWebTapered() { + var webTapered = new WebTapered(new Length(1, LengthUnit.Inch), new Length(2, LengthUnit.Inch)); + var result = AdSecProfiles.CreateWeb(webTapered); + + Assert.Equal(webTapered.TopThickness.As(LengthUnit.Meter), result.TopThickness.Value); + Assert.Equal(webTapered.BottomThickness.As(LengthUnit.Meter), result.BottomThickness.Value); + } + + [Fact] + public void CreateFlange_WithNullIWeb_ReturnsNull() { + var result = AdSecProfiles.CreateFlange(null); + + Assert.Null(result); + } + + [Fact] + public void CreateFlange_ReturnsValidFlange() { + var result = AdSecProfiles.CreateFlange(angleProfile.Flange); + + Assert.Equal(angleProfile.Flange.Thickness.As(LengthUnit.Meter), result.Thickness.Value); + Assert.Equal(angleProfile.Flange.Width.As(LengthUnit.Meter), result.Width.Value); + } + + [Fact] + public void CreatePolygon_WithNullPolygon_ReturnsNull() { + var result = AdSecProfiles.CreatePolygon(null); + + Assert.Empty(result.Points); + } + + [Fact] + public void CreatePolygon_WithNullPolygonPoints_ReturnsNull() { + var result = AdSecProfiles.CreatePolygon(new Polygon() { + Points = null, + }); + + Assert.Empty(result.Points); + } + + [Fact] + public void CreatePolygon_WithEmptyPolygonPoints_ReturnsNull() { + var result = AdSecProfiles.CreatePolygon(new Polygon()); + + Assert.Empty(result.Points); + } + + [Fact] + public void CreatePolygon_WithPolygonPoints_ReturnsValidPolygon() { + var result = AdSecProfiles.CreatePolygon(new Polygon(new List() { + new Point2d(new Length(1, LengthUnit.Inch), new Length(2, LengthUnit.Inch)), + })); + + Assert.Single(result.Points); + Assert.Equal(0.0254, result.Points[0].Y.As(LengthUnit.Meter)); + Assert.Equal(0.0508, result.Points[0].Z.As(LengthUnit.Meter)); + } + + [Fact] + public void CreateProfile_WhenNullProfile_ReturnsNull() { + var result = AdSecProfiles.CreateProfile(null); + Assert.Null(result); + } + + [Fact] + public void CreateProfile_WhenUnknownProfileType_ThrowsError() { + Assert.Throws(() => AdSecProfiles.CreateProfile(new ProfileUnknownDummy())); + } + + private IProfile[] profiles = { + SampleProfiles.GetAnAngleProfile(new WebConstant(new Length(1, LengthUnit.Inch))), + SampleProfiles.GetACatalogueProfile(), + SampleProfiles.GetAChannelProfile(), + SampleProfiles.GetACircleProfile(), + SampleProfiles.GetACircleHollowProfile(), + SampleProfiles.GetACruciformSymmetricalProfile(), + SampleProfiles.GetAnEllipseProfile(), + SampleProfiles.GetAnEllipseHollowProfile(), + SampleProfiles.GetAGeneralCProfile(), + SampleProfiles.GetAGeneralZProfile(), + SampleProfiles.GetAnIBeamAssymetricalProfile(), + SampleProfiles.GetAnIBeamCellularProfile(), + SampleProfiles.GetAPerimeterProfile(), + SampleProfiles.GetARectangleProfile(), + SampleProfiles.GetARectangleHollowProfile(), + SampleProfiles.GetARectoEllipseProfile(), + SampleProfiles.GetASecantPileProfile(), + SampleProfiles.GetASheetPileProfile(), + SampleProfiles.GetATrapezoidProfile(), + SampleProfiles.GetATSectionProfile(), + }; + + [Fact] + public void CheckProfiles_NotNull() { + foreach (var profile in profiles) { + var result = AdSecProfiles.CreateProfile(profile); + Assert.NotNull(result); + } + } + + [Fact] + public void CheckProfiles_HaveTheRightType() { + foreach (var profile in profiles) { + var result = AdSecProfiles.CreateProfile(profile); + Assert.Equal($"I{profile.GetType().Name}_Implementation", result.GetType().Name); + } + } + + [Fact] + public void CreateProfile_WhenBeamProfileType_ReturnValidProfile() { + var result = AdSecProfiles.CreateProfile(SampleProfiles.GetABeamProfile()); + + Assert.NotNull(result); + Assert.Equal("IIBeamSymmetricalProfile_Implementation", result.GetType().Name); + } + + [Fact] + public void CreateProfile_WhenRectoCircleProfileType_ReturnValidProfile() { + var result = AdSecProfiles.CreateProfile(SampleProfiles.GetARectoCircleProfile()); + + Assert.NotNull(result); + Assert.Equal("IStadiumProfile_Implementation", result.GetType().Name); + } + + } +} diff --git a/AdSecGHTests/Helpers/SampleProfiles.cs b/AdSecGHTests/Helpers/SampleProfiles.cs new file mode 100644 index 0000000..f735274 --- /dev/null +++ b/AdSecGHTests/Helpers/SampleProfiles.cs @@ -0,0 +1,237 @@ +using System.Collections.Generic; + +using Oasys.Taxonomy.Geometry; +using Oasys.Taxonomy.Profiles; + +using OasysGH.Units; + +using OasysUnits; +using OasysUnits.Units; + +namespace AdSecGHTests.Helpers { + public static class SampleProfiles { + private static Length GetThickness() { + return new Length(0.2, LengthUnit.Meter); + } + + private static Flange GetFlange() { + return new Flange(GetThickness(), LengthOne()); + } + + private static Length LengthOne() { + return new Length(1, DefaultUnits.LengthUnitGeometry); + } + + private static WebConstant GetWebConstant() { + return new WebConstant(GetThickness()); + } + + public static AngleProfile GetAnAngleProfile(IWeb web) { + return new AngleProfile { + Depth = LengthOne(), + Rotation = Angle.Zero, + Flange = GetFlange(), + Web = web, + }; + } + + public static CatalogueProfile GetACatalogueProfile() { + return new CatalogueProfile() { + Rotation = Angle.Zero, + Description = "CAT BSI-IPE IPEAA80", + }; + } + + public static ChannelProfile GetAChannelProfile() { + return new ChannelProfile() { + Rotation = Angle.Zero, + Web = GetWebConstant(), + Flanges = GetFlange(), + Depth = LengthOne(), + }; + } + + public static CircleProfile GetACircleProfile() { + return new CircleProfile() { + Rotation = Angle.Zero, + Diameter = LengthOne(), + }; + } + + public static CircleHollowProfile GetACircleHollowProfile() { + return new CircleHollowProfile() { + WallThickness = GetThickness(), + Rotation = Angle.Zero, + Diameter = LengthOne(), + }; + } + + public static CruciformSymmetricalProfile GetACruciformSymmetricalProfile() { + return new CruciformSymmetricalProfile() { + Rotation = Angle.Zero, + Web = GetWebConstant(), + Depth = LengthOne(), + Flange = GetFlange(), + }; + } + + public static EllipseProfile GetAnEllipseProfile() { + return new EllipseProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Width = LengthOne(), + }; + } + + public static EllipseHollowProfile GetAnEllipseHollowProfile() { + return new EllipseHollowProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Width = LengthOne(), + WallThickness = GetThickness(), + }; + } + + public static GeneralCProfile GetAGeneralCProfile() { + return new GeneralCProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Thickness = GetThickness(), + FlangeWidth = LengthOne(), + Lip = LengthOne(), + }; + } + + public static GeneralZProfile GetAGeneralZProfile() { + return new GeneralZProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Thickness = GetThickness(), + BottomFlangeWidth = LengthOne(), + BottomLip = GetThickness(), + TopFlangeWidth = LengthOne(), + TopLip = GetThickness(), + }; + } + + public static IBeamProfile GetABeamProfile() { + return new IBeamProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Web = GetWebConstant(), + Flanges = GetFlange(), + }; + } + + public static IBeamAsymmetricalProfile GetAnIBeamAssymetricalProfile() { + return new IBeamAsymmetricalProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Web = GetWebConstant(), + BottomFlange = GetFlange(), + TopFlange = GetFlange(), + }; + } + + public static IBeamCellularProfile GetAnIBeamCellularProfile() { + return new IBeamCellularProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Web = GetWebConstant(), + Flanges = GetFlange(), + Spacing = GetThickness(), + WebOpening = GetThickness(), + OpeningType = IBeamOpeningType.Castellated, + }; + } + + public static PerimeterProfile GetAPerimeterProfile() { + return new PerimeterProfile() { + Rotation = Angle.Zero, + Perimeter = new Polygon(new List() { + new Point2d(LengthOne(), LengthOne()), + }), + VoidPolygons = new List() { + new Polygon(new List() { + new Point2d(LengthOne(), LengthOne()), + }), + }, + }; + } + + public static RectangleProfile GetARectangleProfile() { + return new RectangleProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Width = LengthOne(), + }; + } + + public static RectangleHollowProfile GetARectangleHollowProfile() { + return new RectangleHollowProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Flanges = GetFlange(), + Webs = GetWebConstant(), + }; + } + + public static RectoCircleProfile GetARectoCircleProfile() { + return new RectoCircleProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Width = LengthOne(), + }; + } + + public static RectoEllipseProfile GetARectoEllipseProfile() { + return new RectoEllipseProfile() { + Rotation = Angle.Zero, + Depth = LengthOne(), + Width = LengthOne(), + DepthFlat = GetThickness(), + WidthFlat = GetThickness(), + }; + } + + public static SecantPileProfile GetASecantPileProfile() { + return new SecantPileProfile() { + Rotation = Angle.Zero, + Diameter = LengthOne(), + IsWall = true, + PileCentres = GetThickness(), + PileCount = 2, + }; + } + + public static SheetPileProfile GetASheetPileProfile() { + return new SheetPileProfile() { + Rotation = Angle.Zero, + BottomFlangeWidth = LengthOne(), + FlangeThickness = GetThickness(), + Depth = LengthOne(), + TopFlangeWidth = LengthOne(), + WebThickness = GetThickness(), + Width = LengthOne(), + }; + } + + public static TrapezoidProfile GetATrapezoidProfile() { + return new TrapezoidProfile() { + Rotation = Angle.Zero, + BottomWidth = LengthOne(), + Depth = LengthOne(), + TopWidth = LengthOne(), + }; + } + + public static TSectionProfile GetATSectionProfile() { + return new TSectionProfile { + Depth = LengthOne(), + Rotation = Angle.Zero, + Flange = GetFlange(), + Web = GetWebConstant(), + }; + } + } +}