From 796454128cb2ef99c91fd33cc7ea02325104f924 Mon Sep 17 00:00:00 2001 From: spsarras Date: Fri, 1 Nov 2024 11:23:00 +0000 Subject: [PATCH] refactor: moved test objects to separate project, only used from tests --- AdSecCoreTests/AdSecCoreTests.csproj | 9 ++- AdSecGH.sln | 6 ++ AdSecGH/Components/3_Section/FlattenRebar.cs | 61 +++++++++++------ AdSecGH/Helpers/BusinessExtensions.cs | 65 ------------------- AdSecGH/Helpers/BusinessGlue.cs | 9 ++- AdSecGHTests/AdSecGHTests.csproj | 1 + .../Helpers/BusinessComponentNameTest.cs | 4 +- AdSecGHTests/Helpers/DataConvertorTest.cs | 2 - .../Helpers/DropIntoGhDocumentTest.cs | 2 - TestGrasshopperObjects/Dummy.cs | 13 ++++ TestGrasshopperObjects/DummyBusiness.cs | 51 +++++++++++++++ TestGrasshopperObjects/DummyOasysComponent.cs | 16 +++++ .../TestGrasshopperObjects.csproj | 20 ++++++ 13 files changed, 163 insertions(+), 96 deletions(-) create mode 100644 TestGrasshopperObjects/Dummy.cs create mode 100644 TestGrasshopperObjects/DummyBusiness.cs create mode 100644 TestGrasshopperObjects/DummyOasysComponent.cs create mode 100644 TestGrasshopperObjects/TestGrasshopperObjects.csproj diff --git a/AdSecCoreTests/AdSecCoreTests.csproj b/AdSecCoreTests/AdSecCoreTests.csproj index 04cd64a..5085ebf 100644 --- a/AdSecCoreTests/AdSecCoreTests.csproj +++ b/AdSecCoreTests/AdSecCoreTests.csproj @@ -10,10 +10,13 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/AdSecGH.sln b/AdSecGH.sln index 2c81397..1bc9a7b 100644 --- a/AdSecGH.sln +++ b/AdSecGH.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCore", "AdSecCore\AdSe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCoreTests", "AdSecCoreTests\AdSecCoreTests.csproj", "{DF259C79-A298-44B9-B702-573D4206A3C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestGrasshopperObjects", "TestGrasshopperObjects\TestGrasshopperObjects.csproj", "{9D376477-DEDE-4DCC-B12F-7361BF763BFF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -51,6 +53,10 @@ Global {DF259C79-A298-44B9-B702-573D4206A3C2}.Debug|x64.Build.0 = Debug|Any CPU {DF259C79-A298-44B9-B702-573D4206A3C2}.Release|x64.ActiveCfg = Release|Any CPU {DF259C79-A298-44B9-B702-573D4206A3C2}.Release|x64.Build.0 = Release|Any CPU + {9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Debug|x64.ActiveCfg = Debug|Any CPU + {9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Debug|x64.Build.0 = Debug|Any CPU + {9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Release|x64.ActiveCfg = Release|Any CPU + {9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AdSecGH/Components/3_Section/FlattenRebar.cs b/AdSecGH/Components/3_Section/FlattenRebar.cs index 9655ece..f33694f 100644 --- a/AdSecGH/Components/3_Section/FlattenRebar.cs +++ b/AdSecGH/Components/3_Section/FlattenRebar.cs @@ -1,41 +1,61 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using AdSecGH.Helpers; using AdSecGH.Helpers.GH; using AdSecGH.Parameters; +using AdSecGH.Properties; using Grasshopper.Kernel; using Oasys.AdSec; using Oasys.AdSec.Reinforcement.Groups; using Oasys.AdSec.Reinforcement.Preloads; +using Oasys.Business; +using Oasys.GH.Helpers; using Oasys.Profiles; using OasysGH; -using OasysGH.Components; using OasysGH.Parameters; using OasysGH.Units; using OasysUnits; +using Attribute = Oasys.Business.Attribute; + namespace AdSecGH.Components { - public class FlattenRebar : GH_OasysComponent { - public override Guid ComponentGuid => new Guid("879ecac6-464d-4286-9113-c15fcf03e4e6"); - public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure; - public override OasysPluginInfo PluginInfo => AdSecGH.PluginInfo.Instance; - protected override System.Drawing.Bitmap Icon => Properties.Resources.FlattenRebar; - - public FlattenRebar() : base( - "FlattenRebars", - "FRb", - "Flatten all rebars in a section into single bars.", - CategoryName.Name(), - SubCategoryName.Cat4()) { + public class FlattenRebarComponent : IBusinessComponent { + + public ComponentAttribute Metadata { get; set; } = new ComponentAttribute { + Name = "FlattenRebar", + NickName = "FRb", + Description = "Flatten all rebars in a section into single bars.", + }; + public ComponentOrganisation Organisation { get; set; } = new ComponentOrganisation { + Category = CategoryName.Name(), + SubCategory = SubCategoryName.Cat4(), + }; + public Attribute[] GetAllInputAttributes() { throw new NotImplementedException(); } + + public Attribute[] GetAllOutputAttributes() { throw new NotImplementedException(); } + + public void UpdateInputValues(params object[] values) { throw new NotImplementedException(); } + + public void Compute() { throw new NotImplementedException(); } + } + + public class FlattenRebar : BusinessOasysGlue { + + public FlattenRebar() { Hidden = true; } + public override Guid ComponentGuid => new Guid("879ecac6-464d-4286-9113-c15fcf03e4e6"); + public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure; + public override OasysPluginInfo PluginInfo => AdSecGH.PluginInfo.Instance; + protected override Bitmap Icon => Resources.FlattenRebar; protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager.AddGenericParameter("Section", "Sec", "AdSec Section to get single rebars from", GH_ParamAccess.item); @@ -50,17 +70,20 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) { IQuantity force = new Force(0, DefaultUnits.ForceUnit); string forceUnitAbbreviation = string.Concat(force.ToString().Where(char.IsLetter)); - pManager.AddGenericParameter("Position [" + lengthUnitAbbreviation + "]", "Vx", "Rebar position as 2D vertex in the section's local yz-plane ", GH_ParamAccess.list); + pManager.AddGenericParameter("Position [" + lengthUnitAbbreviation + "]", "Vx", + "Rebar position as 2D vertex in the section's local yz-plane ", GH_ParamAccess.list); pManager.HideParameter(0); - pManager.AddGenericParameter("Diameter [" + lengthUnitAbbreviation + "]", "Ø", "Bar Diameter", GH_ParamAccess.list); + pManager.AddGenericParameter("Diameter [" + lengthUnitAbbreviation + "]", "Ø", "Bar Diameter", + GH_ParamAccess.list); pManager.AddIntegerParameter("Bundle Count", "N", "Count per bundle (1, 2, 3 or 4)", GH_ParamAccess.list); - pManager.AddGenericParameter("PreLoad", "P", "The pre-load per reinforcement bar. Positive value is tension.", GH_ParamAccess.list); + pManager.AddGenericParameter("PreLoad", "P", "The pre-load per reinforcement bar. Positive value is tension.", + GH_ParamAccess.list); pManager.AddGenericParameter("Material", "Mat", "Material Type", GH_ParamAccess.list); } protected override void SolveInstance(IGH_DataAccess DA) { // get section input - AdSecSection section = AdSecInput.AdSecSection(this, DA, 0); + var section = AdSecInput.AdSecSection(this, DA, 0); // create flattened section ISection flat = null; @@ -79,11 +102,11 @@ protected override void SolveInstance(IGH_DataAccess DA) { var materialType = new List(); // loop through rebar groups in flattened section - foreach (IGroup rebargrp in flat.ReinforcementGroups) { + foreach (var rebargrp in flat.ReinforcementGroups) { try // first try if not a link group type { var snglBrs = (ISingleBars)rebargrp; - foreach (IPoint pos in snglBrs.Positions) { + foreach (var pos in snglBrs.Positions) { // position pointGoos.Add(new AdSecPointGoo(pos)); diff --git a/AdSecGH/Helpers/BusinessExtensions.cs b/AdSecGH/Helpers/BusinessExtensions.cs index 1e7007c..fcafde6 100644 --- a/AdSecGH/Helpers/BusinessExtensions.cs +++ b/AdSecGH/Helpers/BusinessExtensions.cs @@ -88,69 +88,4 @@ public static void PopulateOutputParams(this IBusinessComponent businessComponen } } - public class DummyBusiness : IBusinessComponent { - - public DoubleParameter Alpha { get; set; } = new DoubleParameter { - Name = "Alpha", - NickName = "A", - Description = "Alpha description", - Default = 1, - }; - public DoubleParameter Beta { get; set; } = new DoubleParameter { - Name = "Beta", - NickName = "B", - Description = "Beta description", - Default = 2, - }; - - public ComponentAttribute Metadata { get; set; } = new ComponentAttribute { - Name = "Dummy Business", - NickName = "DB", - Description = "Dummy Business Description", - }; - public ComponentOrganisation Organisation { get; set; } = new ComponentOrganisation { - Category = "Dummy Category", - SubCategory = "Dummy SubCategory", - }; - - public Attribute[] GetAllInputAttributes() { - return new[] { - Alpha, - }; - } - - public Attribute[] GetAllOutputAttributes() { - return new[] { - Beta, - }; - } - - public void UpdateInputValues(params object[] values) { } - - public void Compute() { Beta.Value = (Alpha.Value * 2) + 10; } - - public void GetDefaultValues() { throw new NotImplementedException(); } - } - - public static class Test { - - public const string thisIsForTestingPurposesOnly = "this is for testing purposes only"; - } - - public class DummyOasysComponent : BusinessOasysGlue { - - public DummyOasysComponent() : base("Oasys Component Glue", "OCG", Test.thisIsForTestingPurposesOnly, "Oasys", - "dummy") { } - - public override GH_Exposure Exposure { get; } = GH_Exposure.hidden; - - public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B734-91F214C8B87F"); - - protected override void SolveInstance(IGH_DataAccess DA) { } - } - - public class Dummy : BusinessGlue { - public override GH_Exposure Exposure { get; } = GH_Exposure.hidden; - public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B704-91F214C8C871"); - } } diff --git a/AdSecGH/Helpers/BusinessGlue.cs b/AdSecGH/Helpers/BusinessGlue.cs index 93a1056..1a8a080 100644 --- a/AdSecGH/Helpers/BusinessGlue.cs +++ b/AdSecGH/Helpers/BusinessGlue.cs @@ -14,8 +14,13 @@ public abstract class BusinessOasysGlue : GH_OasysComponent, IDefaultValues w private readonly T _businessComponent = Activator.CreateInstance(); - public BusinessOasysGlue(string name, string nickname, string description, string category, string subCategory) : - base(name, nickname, description, category, subCategory) { } + public BusinessOasysGlue() : base("", "", "", "", "") { + Name = _businessComponent.Metadata.Name; + NickName = _businessComponent.Metadata.NickName; + Description = _businessComponent.Metadata.Description; + Category = _businessComponent.Organisation.Category; + SubCategory = _businessComponent.Organisation.SubCategory; + } public override OasysPluginInfo PluginInfo { get; } = AdSecGH.PluginInfo.Instance; public void SetDefaultValues() { _businessComponent.SetDefaultValues(this); } diff --git a/AdSecGHTests/AdSecGHTests.csproj b/AdSecGHTests/AdSecGHTests.csproj index badfb4d..9736b0a 100644 --- a/AdSecGHTests/AdSecGHTests.csproj +++ b/AdSecGHTests/AdSecGHTests.csproj @@ -22,6 +22,7 @@ + diff --git a/AdSecGHTests/Helpers/BusinessComponentNameTest.cs b/AdSecGHTests/Helpers/BusinessComponentNameTest.cs index 3b2d0e2..e71011c 100644 --- a/AdSecGHTests/Helpers/BusinessComponentNameTest.cs +++ b/AdSecGHTests/Helpers/BusinessComponentNameTest.cs @@ -1,6 +1,4 @@ -using Oasys.GH.Helpers; - -using Xunit; +using Xunit; namespace AdSecGHTests.Helpers { [Collection("GrasshopperFixture collection")] diff --git a/AdSecGHTests/Helpers/DataConvertorTest.cs b/AdSecGHTests/Helpers/DataConvertorTest.cs index 720801e..d7fa25a 100644 --- a/AdSecGHTests/Helpers/DataConvertorTest.cs +++ b/AdSecGHTests/Helpers/DataConvertorTest.cs @@ -1,7 +1,5 @@ using Grasshopper.Kernel; -using Oasys.GH.Helpers; - using Xunit; namespace AdSecGHTests.Helpers { diff --git a/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs b/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs index 61d4af8..9c5d02a 100644 --- a/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs +++ b/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs @@ -3,8 +3,6 @@ using Grasshopper.Kernel; -using Oasys.GH.Helpers; - using Xunit; namespace AdSecGHTests.Helpers { diff --git a/TestGrasshopperObjects/Dummy.cs b/TestGrasshopperObjects/Dummy.cs new file mode 100644 index 0000000..a34b5ef --- /dev/null +++ b/TestGrasshopperObjects/Dummy.cs @@ -0,0 +1,13 @@ +using System; + +using Grasshopper.Kernel; + +using Oasys.GH.Helpers; + +namespace AdSecGHTests.Helpers { + + public class Dummy : BusinessGlue { + public override GH_Exposure Exposure { get; } = GH_Exposure.hidden; + public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B704-91F214C8C871"); + } +} diff --git a/TestGrasshopperObjects/DummyBusiness.cs b/TestGrasshopperObjects/DummyBusiness.cs new file mode 100644 index 0000000..8daed18 --- /dev/null +++ b/TestGrasshopperObjects/DummyBusiness.cs @@ -0,0 +1,51 @@ +using System; + +using Oasys.Business; + +using Attribute = Oasys.Business.Attribute; + +namespace AdSecGHTests.Helpers { + public class DummyBusiness : IBusinessComponent { + + public DoubleParameter Alpha { get; set; } = new DoubleParameter { + Name = "Alpha", + NickName = "A", + Description = "Alpha description", + Default = 1, + }; + public DoubleParameter Beta { get; set; } = new DoubleParameter { + Name = "Beta", + NickName = "B", + Description = "Beta description", + Default = 2, + }; + + public ComponentAttribute Metadata { get; set; } = new ComponentAttribute { + Name = "Dummy Business", + NickName = "DB", + Description = "Dummy Business Description", + }; + public ComponentOrganisation Organisation { get; set; } = new ComponentOrganisation { + Category = "Dummy Category", + SubCategory = "Dummy SubCategory", + }; + + public Attribute[] GetAllInputAttributes() { + return new[] { + Alpha, + }; + } + + public Attribute[] GetAllOutputAttributes() { + return new[] { + Beta, + }; + } + + public void UpdateInputValues(params object[] values) { } + + public void Compute() { Beta.Value = (Alpha.Value * 2) + 10; } + + public void GetDefaultValues() { throw new NotImplementedException(); } + } +} diff --git a/TestGrasshopperObjects/DummyOasysComponent.cs b/TestGrasshopperObjects/DummyOasysComponent.cs new file mode 100644 index 0000000..82e9fb3 --- /dev/null +++ b/TestGrasshopperObjects/DummyOasysComponent.cs @@ -0,0 +1,16 @@ +using System; + +using Grasshopper.Kernel; + +using Oasys.GH.Helpers; + +namespace AdSecGHTests.Helpers { + public class DummyOasysComponent : BusinessOasysGlue { + + public override GH_Exposure Exposure { get; } = GH_Exposure.hidden; + + public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B734-91F214C8B87F"); + + protected override void SolveInstance(IGH_DataAccess DA) { } + } +} diff --git a/TestGrasshopperObjects/TestGrasshopperObjects.csproj b/TestGrasshopperObjects/TestGrasshopperObjects.csproj new file mode 100644 index 0000000..879a15b --- /dev/null +++ b/TestGrasshopperObjects/TestGrasshopperObjects.csproj @@ -0,0 +1,20 @@ + + + + net48 + + + + + + + + + + + + + + + +