diff --git a/AdSecGH/AdSecGH.csproj b/AdSecGH/AdSecGH.csproj index a1de6732..50f792c3 100644 --- a/AdSecGH/AdSecGH.csproj +++ b/AdSecGH/AdSecGH.csproj @@ -1,5 +1,6 @@  + true net48 False x64 @@ -11,60 +12,59 @@ https://github.com/arup-group/AdSec-Grasshopper README.md AdSecLogo128.png - 0.9.27-beta + 0.9.28-beta Official Oasys AdSec Grasshopper Plugin -AdSecGH is pre-release and under active development, including further testing to be undertaken. It is provided "as-is" and you bear the risk of using it. Future versions may contain breaking changes. Any files, results, or other types of output information created using AdSecGH should not be relied upon without thorough and independent checking. + AdSecGH is pre-release and under active development, including further testing to be undertaken. It is provided "as-is" and you bear the risk of using it. Future versions may contain breaking changes. Any files, results, or other types of output information created using AdSecGH should not be relied upon without thorough and independent checking. -The plugin requires a licensed version of AdSec to load. + The plugin requires a licensed version of AdSec to load. -Contact oasys@arup.com to request a free trial version. + Contact oasys@arup.com to request a free trial version. -Copyright © Oasys 1985 - 2024 + Copyright © Oasys 1985 - 2024 + MIT - - - - - - + + + + + + - - - - - - - - - + + + + + + + + + True \ - - - - + + + + - - 2.0.0.21 - + all 13.0.3 - + - 1.0.0 + 1.2.1 6.27.20176.5001 @@ -73,7 +73,7 @@ Copyright © Oasys 1985 - 2024 - + @@ -82,7 +82,7 @@ Copyright © Oasys 1985 - 2024 - + C:\Program Files\Rhino 7\System\Rhino.exe @@ -90,6 +90,6 @@ Copyright © Oasys 1985 - 2024 Program - + diff --git a/AdSecGH/AdSecGHInfo.cs b/AdSecGH/AdSecGHInfo.cs index 1721529c..e4709c12 100644 --- a/AdSecGH/AdSecGHInfo.cs +++ b/AdSecGH/AdSecGHInfo.cs @@ -31,7 +31,7 @@ public string IconUrl internal const string ProductName = "AdSec"; internal const string TermsConditions = "Oasys terms and conditions apply. See https://www.oasys-software.com/terms-conditions for details. "; - internal const string Vers = "0.9.27"; + internal const string Vers = "0.9.28"; internal static string Disclaimer = PluginName + " is pre-release and under active development, including further testing to be undertaken. It is provided \"as-is\" and you bear the risk of using it. Future versions may contain breaking changes. Any files, results, or other types of output information created using " + PluginName + " should not be relied upon without thorough and independent checking. "; diff --git a/AdSecGH/Components/2_Profile/CreateProfile.cs b/AdSecGH/Components/2_Profile/CreateProfile.cs index c606505e..27a6e41d 100644 --- a/AdSecGH/Components/2_Profile/CreateProfile.cs +++ b/AdSecGH/Components/2_Profile/CreateProfile.cs @@ -2,13 +2,13 @@ using System.Collections.Generic; using System.IO; +using AdSecGH.Helpers; using AdSecGH.Helpers.GH; using AdSecGH.Parameters; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; -using Oasys.Interop; using Oasys.Taxonomy.Profiles; using OasysGH; diff --git a/AdSecGH/Components/2_Profile/ProfileProperties.cs b/AdSecGH/Components/2_Profile/ProfileProperties.cs index 7ae9c7cc..8046a8e6 100644 --- a/AdSecGH/Components/2_Profile/ProfileProperties.cs +++ b/AdSecGH/Components/2_Profile/ProfileProperties.cs @@ -74,7 +74,7 @@ protected override void SolveInstance(IGH_DataAccess DA) { var unitSystem = new UnitSystem(baseUnits); AreaUnit areaUnit = new Area(1, unitSystem).Unit; - SectionModulusUnit wUnit = SectionModulusUnit.Undefined; + SectionModulusUnit wUnit = SectionModulusUnit.CubicMeter; switch (lengthUnit) { case LengthUnit.Millimeter: wUnit = SectionModulusUnit.CubicMillimeter; diff --git a/AdSecGH/Helpers/AdSecInput.cs b/AdSecGH/Helpers/AdSecInput.cs index 804d1b11..cbe02e0b 100644 --- a/AdSecGH/Helpers/AdSecInput.cs +++ b/AdSecGH/Helpers/AdSecInput.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using AdSecGH.Parameters; @@ -12,7 +13,6 @@ using Oasys.AdSec.Reinforcement; using Oasys.AdSec.Reinforcement.Groups; using Oasys.AdSec.Reinforcement.Layers; -using Oasys.Interop; using Oasys.Profiles; using OasysGH.Helpers; @@ -27,55 +27,40 @@ namespace AdSecGH.Helpers { internal static class AdSecInput { - internal static AdSecDesignCode AdSecDesignCode( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecDesignCode AdSecDesignCode(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var designCode = new AdSecDesignCode(); var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { if (gh_typ.Value is AdSecDesignCodeGoo) { gh_typ.CastTo(ref designCode); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to DesignCode"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to DesignCode"); return null; } - return designCode; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static AdSecMaterial AdSecMaterial( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecMaterial AdSecMaterial(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var material = new AdSecMaterial(); var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { if (gh_typ.Value is AdSecMaterialGoo) { gh_typ.CastTo(ref material); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to an AdSec Material"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to an AdSec Material"); } - return material; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static AdSecPointGoo AdSecPointGoo( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecPointGoo AdSecPointGoo(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { AdSecPointGoo pt = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -85,27 +70,21 @@ internal static AdSecPointGoo AdSecPointGoo( } else if (GH_Convert.ToPoint3d(gh_typ.Value, ref ghpt, GH_Conversion.Both)) { pt = new AdSecPointGoo(ghpt); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to an Vertex Point"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to an Vertex Point"); } return pt; - } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } else if (isOptional) { return new AdSecPointGoo(Oasys.Profiles.IPoint.Create( - new Length(0, DefaultUnits.LengthUnitGeometry), - new Length(0, DefaultUnits.LengthUnitGeometry))); + new Length(0, DefaultUnits.LengthUnitGeometry), + new Length(0, DefaultUnits.LengthUnitGeometry))); } - return null; } - internal static AdSecProfileGoo AdSecProfileGoo( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecProfileGoo AdSecProfileGoo(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { AdSecProfileGoo profileGoo = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -113,26 +92,20 @@ internal static AdSecProfileGoo AdSecProfileGoo( if (gh_typ.Value is AdSecProfileGoo adsecGoo) { profileGoo = adsecGoo; } else if (gh_typ.Value is OasysProfileGoo oasysGoo) { - var profile = AdSecProfiles.CreateProfile(oasysGoo.Value); + IProfile profile = AdSecProfiles.CreateProfile(oasysGoo.Value); profileGoo = new AdSecProfileGoo(profile, Plane.WorldYZ); } else { return null; //prfl = Boundaries(owner, DA, inputid, -1, DefaultUnits.LengthUnitGeometry); } - return profileGoo; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static AdSecRebarBundleGoo AdSecRebarBundleGoo( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecRebarBundleGoo AdSecRebarBundleGoo(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { AdSecRebarBundleGoo rebar = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -140,45 +113,30 @@ internal static AdSecRebarBundleGoo AdSecRebarBundleGoo( rebar = goo; } else if (gh_typ.Value is AdSecRebarLayerGoo spacing) { rebar = new AdSecRebarBundleGoo(spacing.Value.BarBundle); - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, - "Converted " + owner.Params.Input[inputid].NickName - + " from RebarSpacing to an AdSec Rebar. All spacing information has been lost!"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Converted " + owner.Params.Input[inputid].NickName + " from RebarSpacing to an AdSec Rebar. All spacing information has been lost!"); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to Rebar"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to Rebar"); } - return rebar; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static AdSecRebarLayerGoo AdSecRebarLayerGoo( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecRebarLayerGoo AdSecRebarLayerGoo(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { AdSecRebarLayerGoo spacing = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { if (gh_typ.Value is AdSecRebarLayerGoo goo) { spacing = goo; } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to RebarSpacing"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to RebarSpacing"); } - return spacing; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } @@ -190,29 +148,21 @@ internal static AdSecRebarLayerGoo AdSecRebarLayerGoo( // } // return null; //} - internal static AdSecSection AdSecSection( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecSection AdSecSection(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { // try cast directly to quantity type if (gh_typ.Value is AdSecSectionGoo a1) { return a1.Value; - } - - if (gh_typ.Value is AdSecSubComponentGoo a2) { + } else if (gh_typ.Value is AdSecSubComponentGoo a2) { return a2._section; + } else { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to Section"); + return null; } - - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to Section"); - return null; - } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - return null; } @@ -232,8 +182,7 @@ internal static AdSecSection AdSecSection( // { // prfl = Boundaries(owner, DA, inputid, -1, DefaultUnits.LengthUnitGeometry).Profile; // } - internal static List AdSecSections( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static List AdSecSections(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var subs = new List(); var gh_typs = new List(); if (DA.GetDataList(inputid, gh_typs)) { @@ -243,25 +192,17 @@ internal static List AdSecSections( } else if (gh_typs[i].Value is AdSecSectionGoo subcomp) { subs.Add(subcomp.Value); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i - + ") to Section"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i + ") to Section"); } } - return subs; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static IConcreteCrackCalculationParameters ConcreteCrackCalculationParameters( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static IConcreteCrackCalculationParameters ConcreteCrackCalculationParameters(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { IConcreteCrackCalculationParameters concreteCrack = null; var gh_typ = new GH_ObjectWrapper(); @@ -271,37 +212,27 @@ internal static IConcreteCrackCalculationParameters ConcreteCrackCalculationPara } else if (gh_typ.Value is AdSecConcreteCrackCalculationParametersGoo adsecccp) { concreteCrack = adsecccp.Value; } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName - + " to ConcreteCrackCalculationParameters"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to ConcreteCrackCalculationParameters"); return null; } - return concreteCrack; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static List Covers( - GH_Component owner, IGH_DataAccess DA, int inputid, LengthUnit docLengthUnit) { + internal static List Covers(GH_Component owner, IGH_DataAccess DA, int inputid, LengthUnit docLengthUnit) { var covers = new List(); - var lengths = Input.UnitNumberList(owner, DA, inputid, docLengthUnit); + List lengths = Input.UnitNumberList(owner, DA, inputid, docLengthUnit); - foreach (var length in lengths.Select(v => (Length)v)) { + foreach (Length length in lengths.Select(v => (Length)v)) { covers.Add(ICover.Create(length)); } - return covers; } - internal static IFlange Flange( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static Oasys.Profiles.IFlange Flange(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { AdSecProfileFlangeGoo flange = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -311,35 +242,27 @@ internal static IFlange Flange( return flange.Value; } // try cast from web - - if (gh_typ.Value is AdSecProfileWebGoo) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " from Web to Flange"); + else if (gh_typ.Value is AdSecProfileWebGoo) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " from Web to Flange"); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to Flange"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to Flange"); return null; } } else if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - return null; } - internal static IBarBundle IBarBundle( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static IBarBundle IBarBundle(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { return AdSecRebarBundleGoo(owner, DA, inputid, isOptional).Value; } - internal static ILayer ILayer( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static ILayer ILayer(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { return AdSecRebarLayerGoo(owner, DA, inputid, isOptional).Value; } - internal static Oasys.Collections.IList ILayers( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static Oasys.Collections.IList ILayers(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var grps = Oasys.Collections.IList.Create(); var gh_typs = new List(); if (DA.GetDataList(inputid, gh_typs)) { @@ -349,35 +272,23 @@ internal static Oasys.Collections.IList ILayers( } else if (gh_typs[i].Value is AdSecRebarLayerGoo rebarGoo) { grps.Add(rebarGoo.Value); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i - + ") to RebarLayer"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i + ") to RebarLayer"); } } - return grps; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static IPoint IPoint( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { - var pt = AdSecPointGoo(owner, DA, inputid, isOptional); - if (pt == null) { - return null; - } - + internal static IPoint IPoint(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + AdSecPointGoo pt = AdSecPointGoo(owner, DA, inputid, isOptional); + if (pt == null) { return null; } return pt.AdSecPoint; } - internal static Oasys.Collections.IList IPoints( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static Oasys.Collections.IList IPoints(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var pts = Oasys.Collections.IList.Create(); var gh_typs = new List(); if (DA.GetDataList(inputid, gh_typs)) { @@ -396,64 +307,47 @@ internal static Oasys.Collections.IList IPoints( var curve = (PolylineCurve)polycurve; pts = Parameters.AdSecPointGoo.PtsFromPolylineCurve(curve); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i - + ") to StressStrainPoint or Polyline"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i + ") to StressStrainPoint or Polyline"); } } - if (tempPts.Count > 0) { if (tempPts.Count == 1) { pts.Add(Parameters.AdSecPointGoo.CreateFromPoint3d(tempPts[0], Plane.WorldYZ)); - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, - "Single Point converted to local point. Assumed that local coordinate system is in a YZ-Plane"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Single Point converted to local point. Assumed that local coordinate system is in a YZ-Plane"); } else { - Plane.FitPlaneToPoints(tempPts, out var plane); + Plane.FitPlaneToPoints(tempPts, out Plane plane); //Polyline pol = new Polyline(tempPts); //plane.Origin = pol.CenterPoint(); - foreach (var pt in tempPts) { + foreach (Point3d pt in tempPts) { pts.Add(Parameters.AdSecPointGoo.CreateFromPoint3d(pt, plane)); } - - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, - "List of Points have been converted to local points. Assumed that local coordinate system is matching best-fit plane through points"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "List of Points have been converted to local points. Assumed that local coordinate system is matching best-fit plane through points"); } } return pts; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static AdSecRebarGroupGoo ReinforcementGroup( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecRebarGroupGoo ReinforcementGroup(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { if (gh_typ.Value is AdSecRebarGroupGoo goo) { return goo; + } else { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to RebarLayout"); + return null; } - - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to RebarLayout"); - return null; - } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - return null; } - internal static List ReinforcementGroups( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static List ReinforcementGroups(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var grps = new List(); var gh_typs = new List(); if (DA.GetDataList(inputid, gh_typs)) { @@ -463,20 +357,13 @@ internal static List ReinforcementGroups( } else if (gh_typs[i].Value is AdSecRebarGroupGoo rebarGoo) { grps.Add(rebarGoo.Value); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i - + ") to RebarGroup"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i + ") to RebarGroup"); } } - return grps; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } @@ -496,31 +383,23 @@ internal static List ReinforcementGroups( // } // return null; //} - internal static AdSecSolutionGoo Solution( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static AdSecSolutionGoo Solution(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { // try cast directly to quantity type if (gh_typ.Value is AdSecSolutionGoo goo) { return goo; + } else { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to AdSec Results"); + return null; } - - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to AdSec Results"); - return null; - } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - return null; } - internal static AdSecStressStrainCurveGoo StressStrainCurveGoo( - GH_Component owner, IGH_DataAccess DA, int inputid, bool compression, - bool isOptional = false) { + internal static AdSecStressStrainCurveGoo StressStrainCurveGoo(GH_Component owner, IGH_DataAccess DA, int inputid, bool compression, bool isOptional = false) { AdSecStressStrainCurveGoo ssCrv = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -531,32 +410,23 @@ internal static AdSecStressStrainCurveGoo StressStrainCurveGoo( } else if (GH_Convert.ToCurve(gh_typ.Value, ref polycurve, GH_Conversion.Both)) { // try convert to polylinecurve var curve = (PolylineCurve)polycurve; - var pts = AdSecStressStrainCurveGoo.StressStrainPtsFromPolyline(curve); + Oasys.Collections.IList pts = AdSecStressStrainCurveGoo.StressStrainPtsFromPolyline(curve); var exCrv = IExplicitStressStrainCurve.Create(); exCrv.Points = pts; - var tuple = AdSecStressStrainCurveGoo.Create(exCrv, - AdSecStressStrainCurveGoo.StressStrainCurveType.Explicit, compression); - ssCrv = new AdSecStressStrainCurveGoo(tuple.Item1, exCrv, - AdSecStressStrainCurveGoo.StressStrainCurveType.Explicit, tuple.Item2); + Tuple> tuple = AdSecStressStrainCurveGoo.Create(exCrv, AdSecStressStrainCurveGoo.StressStrainCurveType.Explicit, compression); + ssCrv = new AdSecStressStrainCurveGoo(tuple.Item1, exCrv, AdSecStressStrainCurveGoo.StressStrainCurveType.Explicit, tuple.Item2); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to StressStrainCurve"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to StressStrainCurve"); return null; } - return ssCrv; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static IStressStrainPoint StressStrainPoint( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static IStressStrainPoint StressStrainPoint(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { IStressStrainPoint pt1 = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -568,24 +438,17 @@ internal static IStressStrainPoint StressStrainPoint( } else if (GH_Convert.ToPoint3d(gh_typ.Value, ref ghpt, GH_Conversion.Both)) { pt1 = AdSecStressStrainPointGoo.CreateFromPoint3d(ghpt); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to StressStrainPoint"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to StressStrainPoint"); return null; } - return pt1; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static Oasys.Collections.IList StressStrainPoints( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static Oasys.Collections.IList StressStrainPoints(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var pts = Oasys.Collections.IList.Create(); var gh_typs = new List(); if (DA.GetDataList(inputid, gh_typs)) { @@ -602,26 +465,17 @@ internal static Oasys.Collections.IList StressStrainPoints( var curve = (PolylineCurve)polycurve; pts = AdSecStressStrainCurveGoo.StressStrainPtsFromPolyline(curve); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Unable to convert " + owner.Params.Input[inputid].NickName - + " to StressStrainPoint or a Polyline"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert " + owner.Params.Input[inputid].NickName + " to StressStrainPoint or a Polyline"); } } - if (pts.Count < 2) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input must contain at least 2 points to create an Explicit Stress Strain Curve"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input must contain at least 2 points to create an Explicit Stress Strain Curve"); return null; } - return pts; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } @@ -644,8 +498,7 @@ internal static Oasys.Collections.IList StressStrainPoints( // owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert input " + owner.Params.Input[inputid_Voids].NickName + " (item " + i + ") to Polyline"); // } // } - internal static Oasys.Collections.IList SubComponents( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static Oasys.Collections.IList SubComponents(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { var subs = Oasys.Collections.IList.Create(); var gh_typs = new List(); if (DA.GetDataList(inputid, gh_typs)) { @@ -659,25 +512,17 @@ internal static Oasys.Collections.IList SubComponents( var sub = ISubComponent.Create(section.Value.Section, offset); subs.Add(sub); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i - + ") to SubComponent or Section"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert " + owner.Params.Input[inputid].NickName + " (item " + i + ") to SubComponent or Section"); } } - return subs; + } else if (!isOptional) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - - if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); - } - return null; } - internal static IWeb Web( - GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { + internal static Oasys.Profiles.IWeb Web(GH_Component owner, IGH_DataAccess DA, int inputid, bool isOptional = false) { AdSecProfileWebGoo web = null; var gh_typ = new GH_ObjectWrapper(); if (DA.GetData(inputid, ref gh_typ)) { @@ -687,20 +532,15 @@ internal static IWeb Web( return web.Value; } // try cast from web - - if (gh_typ.Value is AdSecProfileFlangeGoo) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " from Flange to Web"); + else if (gh_typ.Value is AdSecProfileFlangeGoo) { + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " from Flange to Web"); } else { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, - "Unable to convert " + owner.Params.Input[inputid].NickName + " to Web"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert " + owner.Params.Input[inputid].NickName + " to Web"); return null; } } else if (!isOptional) { - owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, - "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); + owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter " + owner.Params.Input[inputid].NickName + " failed to collect data!"); } - return null; } diff --git a/AdSecGH/Helpers/AdSecProfiles.cs b/AdSecGH/Helpers/AdSecProfiles.cs new file mode 100644 index 00000000..e4c38c5e --- /dev/null +++ b/AdSecGH/Helpers/AdSecProfiles.cs @@ -0,0 +1,181 @@ +using Oasys.Taxonomy.Geometry; +using Oasys.Taxonomy.Profiles; + +namespace AdSecGH.Helpers { + public static class AdSecProfiles { + public static Oasys.Profiles.IProfile CreateProfile(IProfile profile) { + 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.CircleHollow: + return CreateCircleHollowProfile((ICircleHollowProfile)profile); + case ProfileType.CruciformSymmetrical: + return CreateCruciformSymmetricalProfile((ICruciformSymmetricalProfile)profile); + case ProfileType.Ellipse: + return CreateEllipseProfile((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); + case ProfileType.RectangleHollow: + return CreateRectangleHollowProfile((IRectangleHollowProfile)profile); + case ProfileType.RectoCircle: + return CreateStadiumProfile((IRectoCircleProfile)profile); + case ProfileType.RectoEllipse: + return CreateRectoEllipseProfile((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); + case ProfileType.Undefined: + default: + throw new System.NotImplementedException(); + } + } + + public static Oasys.Profiles.IAngleProfile CreateAngleProfile(IAngleProfile profile) { + return Oasys.Profiles.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 Oasys.Profiles.IChannelProfile CreateChannelProfile(IChannelProfile profile) { + return Oasys.Profiles.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 Oasys.Profiles.ICircleProfile CreateCircleProfile(ICircleProfile profile) { + return Oasys.Profiles.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 Oasys.Profiles.IEllipseHollowProfile CreateEllipseHollowProfile(IEllipseHollowProfile profile) { + return Oasys.Profiles.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 Oasys.Profiles.IGeneralCProfile CreateGeneralCProfile(IGeneralCProfile profile) { + return Oasys.Profiles.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 Oasys.Profiles.IIBeamAsymmetricalProfile CreateIBeamAsymmetricalProfile(IIBeamAsymmetricalProfile profile) { + return Oasys.Profiles.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 Oasys.Profiles.IIBeamSymmetricalProfile CreateIBeamSymmetricalProfile(IIBeamProfile profile) { + return Oasys.Profiles.IIBeamSymmetricalProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Web)); + } + + public static Oasys.Profiles.IPerimeterProfile CreatePerimeterProfile(IPerimeterProfile profile) { + var perimeter = Oasys.Profiles.IPerimeterProfile.Create(); + perimeter.SolidPolygon = CreatePolygon(profile.Perimeter); + + foreach (IPolygon 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 Oasys.Profiles.IRectangleHollowProfile CreateRectangleHollowProfile(IRectangleHollowProfile profile) { + return Oasys.Profiles.IRectangleHollowProfile.Create(profile.Depth, CreateFlange(profile.Flanges), CreateWebConstant(profile.Webs)); + } + + public static Oasys.Profiles.IRectangleProfile CreateRectangleProfile(IRectangleProfile profile) { + return Oasys.Profiles.IRectangleProfile.Create(profile.Depth, profile.Width); + } + + public static Oasys.Profiles.IFlange CreateFlange(IFlange flange) { + return Oasys.Profiles.IFlange.Create(flange.Width, flange.Thickness); + } + + public static Oasys.Profiles.IStadiumProfile CreateStadiumProfile(IRectoCircleProfile profile) { + return Oasys.Profiles.IStadiumProfile.Create(profile.Depth, profile.Width); + } + + public static Oasys.Profiles.IRectoEllipseProfile CreateRectoEllipseProfile(IRectoEllipseProfile profile) { + return Oasys.Profiles.IRectoEllipseProfile.Create(profile.Depth, profile.DepthFlat, profile.Width, profile.WidthFlat); + } + + public static Oasys.Profiles.ISecantPileProfile CreateSecantPileProfile(ISecantPileProfile profile) { + return Oasys.Profiles.ISecantPileProfile.Create(profile.Diameter, profile.PileCentres, profile.PileCount, profile.IsWall); + } + + 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 Oasys.Profiles.ITrapezoidProfile CreateTrapezoidProfile(ITrapezoidProfile profile) { + return Oasys.Profiles.ITrapezoidProfile.Create(profile.Depth, profile.TopWidth, profile.BottomWidth); + } + + public static Oasys.Profiles.ITSectionProfile CreateTSectionProfile(ITSectionProfile profile) { + return Oasys.Profiles.ITSectionProfile.Create(profile.Depth, CreateFlange(profile.Flange), CreateWeb(profile.Web)); + } + + public static Oasys.Profiles.IWebConstant CreateWebConstant(IWebConstant web) { + return Oasys.Profiles.IWebConstant.Create(web.Thickness); + } + + public static Oasys.Profiles.IWebTapered CreateWebTapered(IWebTapered web) { + return Oasys.Profiles.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; } + + } + } +} diff --git a/AdSecGH/Helpers/Result.cs b/AdSecGH/Helpers/Result.cs index 371c3c04..ba3e5f60 100644 --- a/AdSecGH/Helpers/Result.cs +++ b/AdSecGH/Helpers/Result.cs @@ -2,6 +2,41 @@ using System.Collections.Generic; namespace AdSecGH.Helpers { + public class DoubleComparer : IEqualityComparer { + private double _epsilon = 0.01; //default accuracy in % + private bool _margin = false; + + public DoubleComparer(double epsilon = 0.01, bool useEpsilonAsMargin = false) { + _epsilon = epsilon; + _margin = useEpsilonAsMargin; + } + + public bool Equals(double x, double y) { + x = Math.Round(x, 6); + y = Math.Round(y, 6); + + if (x == y) { + return true; + } + + if (_margin) { + if (Math.Abs(x - y) < _epsilon) { + return true; + } + } else { + double error = Math.Abs(x - y) / (x + y) * 0.5; + return error < _epsilon; + } + + return false; + } + + public int GetHashCode(double obj) { + return obj.GetHashCode(); + } + + } + internal class Result { internal static double RoundToSignificantDigits(double d, int digits) { diff --git a/AdSecGHConverterTests/AdSecGHConverterTests.csproj b/AdSecGHConverterTests/AdSecGHConverterTests.csproj index cf85934e..e604c8b6 100644 --- a/AdSecGHConverterTests/AdSecGHConverterTests.csproj +++ b/AdSecGHConverterTests/AdSecGHConverterTests.csproj @@ -1,10 +1,10 @@  - net6.0 + net48 x64 - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -15,12 +15,12 @@ - + PreserveNewest - + diff --git a/AdSecGHConverters/AdSecGHConverters.csproj b/AdSecGHConverters/AdSecGHConverters.csproj index 762a5151..c9cbe1ac 100644 --- a/AdSecGHConverters/AdSecGHConverters.csproj +++ b/AdSecGHConverters/AdSecGHConverters.csproj @@ -2,17 +2,18 @@ net48 true - x64 - x64 + true + x64 + x64 - - - - - - - - + + + + + + + + - \ No newline at end of file + diff --git a/AdSecGHTests/AdSecGHTests.csproj b/AdSecGHTests/AdSecGHTests.csproj index cda12355..59a67bea 100644 --- a/AdSecGHTests/AdSecGHTests.csproj +++ b/AdSecGHTests/AdSecGHTests.csproj @@ -5,7 +5,7 @@ x64 - + diff --git a/AdSecGHTests/Helper/AdSecFileTest.cs b/AdSecGHTests/Helpers/AdSecFileTest.cs similarity index 98% rename from AdSecGHTests/Helper/AdSecFileTest.cs rename to AdSecGHTests/Helpers/AdSecFileTest.cs index 31891781..90543a87 100644 --- a/AdSecGHTests/Helper/AdSecFileTest.cs +++ b/AdSecGHTests/Helpers/AdSecFileTest.cs @@ -9,7 +9,7 @@ using Xunit; -namespace AdSecGHTests.Helper { +namespace AdSecGHTests.Helpers { [Collection("GrasshopperFixture collection")] public class AdSecFileTest { private string CreateSampleJson(string codeName, bool valid = true) { diff --git a/AdSecGHTests/Helper/ComponentTestHelper.cs b/AdSecGHTests/Helpers/ComponentTestHelper.cs similarity index 98% rename from AdSecGHTests/Helper/ComponentTestHelper.cs rename to AdSecGHTests/Helpers/ComponentTestHelper.cs index b74e6789..d2ece3a9 100644 --- a/AdSecGHTests/Helper/ComponentTestHelper.cs +++ b/AdSecGHTests/Helpers/ComponentTestHelper.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; diff --git a/AdSecGHTests/Helper/Duplicates.cs b/AdSecGHTests/Helpers/Duplicates.cs similarity index 100% rename from AdSecGHTests/Helper/Duplicates.cs rename to AdSecGHTests/Helpers/Duplicates.cs diff --git a/AdSecGHTests/Helper/OasysDropDownComponentTestHelper.cs b/AdSecGHTests/Helpers/OasysDropDownComponentTestHelper.cs similarity index 81% rename from AdSecGHTests/Helper/OasysDropDownComponentTestHelper.cs rename to AdSecGHTests/Helpers/OasysDropDownComponentTestHelper.cs index d46d5dbd..900541d7 100644 --- a/AdSecGHTests/Helper/OasysDropDownComponentTestHelper.cs +++ b/AdSecGHTests/Helpers/OasysDropDownComponentTestHelper.cs @@ -11,19 +11,19 @@ namespace AdSecGHTests.Helpers { public class OasysDropDownComponentTestHelper { public static void ChangeDropDownTest(GH_OasysDropDownComponent comp, bool ignoreSpacerDescriptionsCount = false) { - Assert.True(comp._isInitialised); + Assert.True(comp.IsInitialised); if (!ignoreSpacerDescriptionsCount) { - Assert.Equal(comp._dropDownItems.Count, comp._spacerDescriptions.Count); + Assert.Equal(comp.DropDownItems.Count, comp.SpacerDescriptions.Count); } - Assert.Equal(comp._dropDownItems.Count, comp._selectedItems.Count); + Assert.Equal(comp.DropDownItems.Count, comp.SelectedItems.Count); - for (int i = 0; i < comp._dropDownItems.Count; i++) { + for (int i = 0; i < comp.DropDownItems.Count; i++) { comp.SetSelected(i, 0); - for (int j = 0; j < comp._dropDownItems[i].Count; j++) { + for (int j = 0; j < comp.DropDownItems[i].Count; j++) { comp.SetSelected(i, j); DeserializeTest(comp); - Assert.Equal(comp._selectedItems[i], comp._dropDownItems[i][j]); + Assert.Equal(comp.SelectedItems[i], comp.DropDownItems[i][j]); } } } diff --git a/AdSecGHTests/Parameters/AdSecSectionTests.cs b/AdSecGHTests/Parameters/AdSecSectionTests.cs index e7fab5f1..947fefb1 100644 --- a/AdSecGHTests/Parameters/AdSecSectionTests.cs +++ b/AdSecGHTests/Parameters/AdSecSectionTests.cs @@ -1,13 +1,16 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.ComponentModel; using System.IO; +using AdSecGH.Helpers; + using Oasys.AdSec; using Oasys.AdSec.DesignCode; using Oasys.AdSec.IO.Serialization; using Oasys.AdSec.Materials; using Oasys.AdSec.Reinforcement; using Oasys.AdSec.Reinforcement.Groups; -using Oasys.Interop; using Oasys.Profiles; using Oasys.Taxonomy.Geometry; @@ -19,12 +22,13 @@ namespace AdSecGHTests.Parameters { [Collection("GrasshopperFixture collection")] public class AdSecSectionTests { - [Fact(Skip = "Not Implemented Yet")] + [Fact] public void SerialiseUnflattenedSectionTest() { ISection section = CreateSection(); IDesignCode designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013; var adSec = IAdSec.Create(designCode); + ISection flattened = adSec.Flatten(section); string fileName = Path.GetTempPath() + "AdSecSectionTest.ads"; @@ -37,7 +41,7 @@ public void SerialiseUnflattenedSectionTest() { var expectedProfile = (IPerimeterProfile)flattened.Profile; var actualProfile = (IPerimeterProfile)actualSection.Profile; - TestSection(flattened, actualSection); + TestFlattenedSection(flattened, actualSection); } [Fact] @@ -58,34 +62,37 @@ public void SerialiaseFlattenedSectionTest() { var expectedProfile = (IPerimeterProfile)flattened.Profile; var actualProfile = (IPerimeterProfile)actualSection.Profile; - TestSection(flattened, actualSection); + TestFlattenedSection(flattened, actualSection); } - private void TestSection(ISection expected, ISection actual) { + private void TestFlattenedSection(ISection expected, ISection actual) { + //A flattened section does not guarantee position points to be the same, as those sections may have positions relative + //to different origin sets. Additionally, the flattened section splits the bundle of bars into single bars. var expectedProfile = (IPerimeterProfile)expected.Profile; var actualProfile = (IPerimeterProfile)actual.Profile; + Assert.Equal(expectedProfile.Area().Value, actualProfile.Area().Value, new DoubleComparer()); + double actualBarArea = 0; + foreach (IGroup group in actual.ReinforcementGroups) { + var singleBar = group as ISingleBars; + actualBarArea += Math.PI * Math.Pow(singleBar.BarBundle.Diameter.Value / 2.0, 2) * singleBar.BarBundle.CountPerBundle; + } - for (int i = 0; i < expectedProfile.SolidPolygon.Points.Count; i++) { - IPoint expectedPoint = expectedProfile.SolidPolygon.Points[i]; - IPoint actualPoint = actualProfile.SolidPolygon.Points[i]; - - Assert.Equal(expectedPoint.Y.Value, actualPoint.Y.Value, 4); - Assert.Equal(expectedPoint.Z.Value, actualPoint.Z.Value, 4); + double expectedBarArea = 0; + foreach (IGroup group in expected.ReinforcementGroups) { + var singleBar = group as ISingleBars; + expectedBarArea += Math.PI * Math.Pow(singleBar.BarBundle.Diameter.Value / 2.0, 2) * singleBar.BarBundle.CountPerBundle; } - Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).Positions[0].Y.Value, ((ISingleBars)actual.ReinforcementGroups[0]).Positions[0].Y.Value, 4); - Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).Positions[0].Z.Value, ((ISingleBars)actual.ReinforcementGroups[0]).Positions[0].Z.Value, 4); - Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).BarBundle.CountPerBundle, ((ISingleBars)actual.ReinforcementGroups[0]).BarBundle.CountPerBundle); - Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).BarBundle.Diameter, ((ISingleBars)actual.ReinforcementGroups[0]).BarBundle.Diameter); - - Assert.Equal(expectedProfile.ElasticModulus().Y.Value, actualProfile.ElasticModulus().Y.Value, 10); - Assert.Equal(expectedProfile.ElasticModulus().Z.Value, actualProfile.ElasticModulus().Z.Value, 10); - Assert.Equal(expectedProfile.SurfaceAreaPerUnitLength().Value, actualProfile.SurfaceAreaPerUnitLength().Value, 10); - Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YY.Value, actualProfile.LocalAxisSecondMomentOfArea().YY.Value, 10); - Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().ZZ.Value, actualProfile.LocalAxisSecondMomentOfArea().ZZ.Value, 10); - Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YZ.Value, actualProfile.LocalAxisSecondMomentOfArea().YZ.Value, 10); - Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().UU.Value, actualProfile.PrincipalAxisSecondMomentOfArea().UU.Value, 10); - Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().VV.Value, actualProfile.PrincipalAxisSecondMomentOfArea().VV.Value, 10); + Assert.Equal(expectedBarArea, actualBarArea, new DoubleComparer()); + + Assert.Equal(expectedProfile.ElasticModulus().Y.Value, actualProfile.ElasticModulus().Y.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.ElasticModulus().Z.Value, actualProfile.ElasticModulus().Z.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.SurfaceAreaPerUnitLength().Value, actualProfile.SurfaceAreaPerUnitLength().Value, new DoubleComparer()); + Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YY.Value, actualProfile.LocalAxisSecondMomentOfArea().YY.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().ZZ.Value, actualProfile.LocalAxisSecondMomentOfArea().ZZ.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YZ.Value, actualProfile.LocalAxisSecondMomentOfArea().YZ.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().UU.Value, actualProfile.PrincipalAxisSecondMomentOfArea().UU.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().VV.Value, actualProfile.PrincipalAxisSecondMomentOfArea().VV.Value, new DoubleComparer()); } private static string CreateJson(IDesignCode designCode, ISection section) { diff --git a/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs b/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs index 874a3c98..cd2ef74b 100644 --- a/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs +++ b/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs @@ -28,16 +28,16 @@ public void NoRuntimeErrorTest() { [Theory] [InlineData("CadTest", 15)] [InlineData("NmDiagramTest", 116003.838766)] - [InlineData("ConcreteStressTest", new double[] { -0.327292, -5.108709, -0.13875, -4.642858 }, 5)] - [InlineData("RebarUlsStrainTest", new double[] { 0.262073, 0.216727, 0.166176, 0.115644, 0.145305, 0.01743, -0.134224, -0.006349, -0.104581, -0.15289, -0.201211, -0.246279 })] - [InlineData("RebarUlsStressTest", new double[] { 52.414556, 43.34542, 33.235123, 23.128806, 29.061078, 3.486051, -26.844842, -1.269816, -20.916174, -30.577941, -40.242196, -49.255725 })] + [InlineData("ConcreteStressTest", new double[] { -0.327292, -5.108709, -0.13875, -4.642858 })] + [InlineData("RebarUlsStrainTest", new double[] { 0.262073, 0.216727, 0.166176, 0.115644, 0.145305, 0.016448, -0.134224, -0.006349, -0.104581, -0.15289, -0.201211, -0.246279 })] + [InlineData("RebarUlsStressTest", new double[] { 52.414556, 43.34542, 33.235123, 23.128806, 29.061078, 3.289703, -26.844842, -1.269816, -20.916174, -30.577941, -40.242196, -49.255725 })] [InlineData("RebarSlsStrainTest", new double[] { 0.058393, 0.044786, 0.029483, 0.014066, 0.017519, -0.027111, -0.073019, -0.028389, -0.069464, -0.084162, -0.09879, -0.112358 })] [InlineData("RebarSlsStressTest", new double[] { 11.678512, 8.957159, 5.896622, 2.813283, 3.503728, -5.422205, -14.603815, -5.677882, -13.892725, -16.83249, -19.758003, -22.471527 })] [InlineData("LoadUtilisationTest", 0.137663)] [InlineData("CrackUtilisationTest", 1.423388)] - public void Test(string groupIdentifier, object expected, int tolerance = 6) { + public void Test(string groupIdentifier, object expected) { IGH_Param param = Helper.FindParameter(Document, groupIdentifier); - Helper.TestGHPrimitives(param, expected, tolerance); + Helper.TestGHPrimitives(param, expected); } private static GH_Document OpenDocument() { diff --git a/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs b/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs index ec38bb51..035b5f03 100644 --- a/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs +++ b/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs @@ -29,15 +29,15 @@ public void NoRuntimeErrorTest() { [InlineData("CadTest", 14)] [InlineData("NmDiagramTest", 120215.428945)] [InlineData("ConcreteStressTest", new double[] { -0.373978, -7.684297, -0.16744, -6.056018 })] - [InlineData("RebarUlsStrainTest", new double[] { 0.241326, 0.220247, 0.102692, -0.056334, -0.182421, -0.216571, -0.142805, 0.00436, 0.156066 })] - [InlineData("RebarUlsStressTest", new double[] { 48.265163, 44.04935, 20.538307, -11.26689, -36.484234, -43.31425, -28.561098, 0.872059, 31.213118 })] + [InlineData("RebarUlsStrainTest", new double[] { 0.241326, 0.220247, 0.102692, -0.056334, -0.182421, -0.216571, -0.142805, 0.005074, 0.156066 })] + [InlineData("RebarUlsStressTest", new double[] { 48.265163, 44.04935, 20.538307, -11.26689, -36.484234, -43.31425, -28.561098, 1.014877, 31.213118 })] [InlineData("RebarSlsStrainTest", new double[] { 0.064542, 0.055894, 0.01106, -0.04898, -0.096133, -0.108336, -0.079879, -0.024077, 0.032959 })] [InlineData("RebarSlsStressTest", new double[] { 12.908482, 11.178755, 2.212077, -9.795945, -19.226623, -21.667238, -15.9758, -4.815395, 6.591898 })] [InlineData("LoadUtilisationTest", 0.128236)] [InlineData("CrackUtilisationTest", 1.315612)] - public void Test(string groupIdentifier, object expected, int tolerance = 6) { + public void Test(string groupIdentifier, object expected) { IGH_Param param = Helper.FindParameter(Document, groupIdentifier); - Helper.TestGHPrimitives(param, expected, tolerance); + Helper.TestGHPrimitives(param, expected); } private static GH_Document OpenDocument() { diff --git a/IntegrationTests/Helper/Helper.cs b/IntegrationTests/Helper/Helper.cs index 56e7885c..1c51001e 100644 --- a/IntegrationTests/Helper/Helper.cs +++ b/IntegrationTests/Helper/Helper.cs @@ -1,6 +1,8 @@ using System; using System.IO; +using AdSecGH.Helpers; + using Grasshopper.Kernel; using Grasshopper.Kernel.Special; using Grasshopper.Kernel.Types; @@ -66,7 +68,7 @@ public static IGH_Param FindParameter(GH_Document doc, string groupIdentifier) { return null; } - public static void TestGHPrimitives(IGH_Param param, object expected, int tolerance = 6) { + public static void TestGHPrimitives(IGH_Param param, object expected) { if (expected.GetType() == typeof(string)) { var valOut = (GH_String)param.VolatileData.get_Branch(0)[0]; Assert.Equal(expected, valOut.Value); @@ -75,7 +77,7 @@ public static void TestGHPrimitives(IGH_Param param, object expected, int tolera Assert.Equal(expected, valOut.Value); } else if (expected.GetType() == typeof(double)) { var valOut = (GH_Number)param.VolatileData.get_Branch(0)[0]; - Assert.Equal((double)expected, valOut.Value, tolerance); + Assert.Equal((double)expected, valOut.Value, new DoubleComparer()); } else if (expected.GetType() == typeof(bool)) { var valOut = (GH_Boolean)param.VolatileData.get_Branch(0)[0]; Assert.Equal(expected, valOut.Value); @@ -97,7 +99,7 @@ public static void TestGHPrimitives(IGH_Param param, object expected, int tolera } else if (expected.GetType() == typeof(double[])) { for (int i = 0; i < ((double[])expected).Length; i++) { var valOut = (GH_Number)param.VolatileData.get_Branch(0)[i]; - Assert.Equal(((double[])expected)[i], valOut.Value, tolerance); + Assert.Equal(((double[])expected)[i], valOut.Value, new DoubleComparer()); } } else { Assert.Fail("Expected type not found!"); diff --git a/build-test-deploy.yml b/build-test-deploy.yml index 8255f57a..04d6c329 100644 --- a/build-test-deploy.yml +++ b/build-test-deploy.yml @@ -14,7 +14,7 @@ pool: 'rhino-compute' steps: - powershell: Remove-Item -Path C:\Users\**\AppData\Roaming\Grasshopper\Libraries\*.ghlink displayName: 'Delete orphan .ghlink files' - + - task: NuGetToolInstaller@1 - task: NuGetCommand@2 @@ -35,17 +35,17 @@ steps: MSBUILDDISABLENODEREUSE: 1 - powershell: | - dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.0\build --results-directory .\results\adsecgh .\AdSecGHTests\bin\x64\Release\net48\AdSecGHTests.dll - dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.0\build --results-directory .\results\integration .\IntegrationTests\bin\x64\Release\net48\IntegrationTests.dll + dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.2\build --results-directory .\results\adsecgh .\AdSecGHTests\bin\x64\Release\net48\AdSecGHTests.dll + dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.2\build --results-directory .\results\integration .\IntegrationTests\bin\x64\Release\net48\IntegrationTests.dll displayName: dotnet tests failOnStderr: false - powershell: | - if (200 -ne (Invoke-WebRequest -Uri https://codecov.io/validate -Body (Get-Content -Raw -LiteralPath .\codecov.yml) -Method post | Select-Object StatusCode).StatusCode) { + if (200 -ne (Invoke-WebRequest -Uri https://codecov.io/validate -Body (Get-Content -Raw -LiteralPath .\codecov.yml) -Method post | Select-Object StatusCode).StatusCode) { Write-Output "codecov.yml is invalid" Invoke-WebRequest -Uri https://codecov.io/validate -Body (Get-Content -Raw -LiteralPath .\codecov.yml) -Method post exit(1) - } else { + } else { Write-Output "codecov.yml is valid" } displayName: Validate codecov.yml @@ -56,7 +56,7 @@ steps: echo $coverage_file_adsecgh $coverage_file_integration = (Resolve-Path $(System.DefaultWorkingDirectory)/results/integration/*/coverage.cobertura.xml).Path echo $coverage_file_integration - + Copy-Item $coverage_file_adsecgh $(System.DefaultWorkingDirectory)\results\coverage_adsecgh.xml Copy-Item $coverage_file_integration $(System.DefaultWorkingDirectory)\results\coverage_integration.xml $ProgressPreference = 'SilentlyContinue' @@ -92,7 +92,7 @@ steps: $underscoreSeparatedTag = $majorVersion + "_" + $minorVersion + "_" + $spVersion + "_" + $buildNumber $tagNumbersOnlyUnderscore = $majorVersion + "_" + $minorVersion + "_" + $spVersion + "_" + $buildNumber $tagNumbersOnlydot = $majorVersion + "." + $minorVersion + "." + $spVersion + "." + $buildNumber - + Write-Host ("##vso[task.setvariable variable=dotSeparatedTag]$dotSeparatedTag") git rev-parse $dotSeparatedTag if($lastExitCode -eq 0){Write-Host ("##vso[task.setvariable variable=TAG_EXISTS]true")}