Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADSECGH-75: test coverage create point #124

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AdSecCore/Functions/IFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FuncAttribute {
public class Organisation {
public string Category { get; set; }
public string SubCategory { get; set; }
public bool Hidden { get; set; }
}

public class Attribute {
Expand Down
52 changes: 52 additions & 0 deletions AdSecCore/Functions/PointRebarFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using AdSecGHCore.Constants;

using Oasys.Profiles;

namespace AdSecCore.Functions {
public class PointRebarFunction : IFunction {

public LengthParameter Y { get; set; } = new LengthParameter {
Name = "Y",
NickName = "Y",
Description = "The local Y coordinate in yz-plane",
};
public LengthParameter Z { get; set; } = new LengthParameter {
Name = "Z",
NickName = "Z",
Description = "The local Z coordinate in yz-plane",
};

public PointParameter Point { get; set; } = new PointParameter {
Name = "Vertex Point",
NickName = "Vx",
Description = "A 2D vertex in the yz-plane for AdSec Profile and Reinforcement",
};
public FuncAttribute Metadata { get; set; } = new FuncAttribute {
Name = "Create Vertex Point",
NickName = "Vertex Point",
Description = "Create a 2D vertex in local yz-plane for AdSec Profile and Reinforcement",
};
public Organisation Organisation { get; set; } = new Organisation {
Category = CategoryName.Name(),
SubCategory = SubCategoryName.Cat3(),
Hidden = false,
};

public virtual Attribute[] GetAllInputAttributes() {
return new Attribute[] {
Y,
Z,
};
}

public virtual Attribute[] GetAllOutputAttributes() {
return new Attribute[] {
Point,
};
}

public void Compute() {
Point.Value = IPoint.Create(Y.Value, Z.Value);
}
}
}
28 changes: 28 additions & 0 deletions AdSecCoreTests/Functions/PointRebarTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using AdSecCore.Functions;

using AdSecGHCore.Constants;

namespace AdSecCoreTests.Functions {
public class PointRebarTests {
private readonly PointRebarFunction pointRebarFunction;

public PointRebarTests() {
pointRebarFunction = new PointRebarFunction();
}

[Fact]
public void ShouldStartHidden() {
Assert.False(pointRebarFunction.Organisation.Hidden);
}

[Fact]
public void ShouldBeOnSubCat3() {
Assert.Equal(SubCategoryName.Cat3(), pointRebarFunction.Organisation.SubCategory);
}

[Fact]
public void ShouldBeOnCatName() {
Assert.Equal(CategoryName.Name(), pointRebarFunction.Organisation.Category);
}
}
}
77 changes: 33 additions & 44 deletions AdSecGH/Components/2_Rebar/CreatePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,55 @@
using System.Collections.Generic;
using System.Drawing;

using AdSecCore;
using AdSecCore.Functions;

using AdSecGH.Parameters;
using AdSecGH.Properties;

using AdSecGHCore.Constants;

using Grasshopper.Kernel;

using Oasys.Profiles;
using Oasys.GH.Helpers;

using OasysGH;
using OasysGH.Components;
using OasysGH.Helpers;
using OasysGH.Units;
using OasysGH.Units.Helpers;

using OasysUnits;
using OasysUnits.Units;

using Attribute = AdSecCore.Functions.Attribute;

namespace AdSecGH.Components {
public class CreatePoint : GH_OasysDropDownComponent {
private LengthUnit _lengthUnit = DefaultUnits.LengthUnitGeometry;

public CreatePoint() : base("Create Vertex Point", "Vertex Point",
"Create a 2D vertex in local yz-plane for AdSec Profile and Reinforcement", CategoryName.Name(),
SubCategoryName.Cat3()) {
Hidden = false; // sets the initial state of the component to hidden
public class CreatePointGh : PointRebarFunction {

public CreatePointGh() {
var adSecPointAttribute = AdSecPoint as Attribute;
Point.Update(ref adSecPointAttribute);
Point.OnValueChanged += goo => {
AdSecPoint.Value = new AdSecPointGoo(Point.Value);
};

Y.Name = Y.NameWithUnits(DefaultUnits.LengthUnitGeometry);
Z.Name = Z.NameWithUnits(DefaultUnits.LengthUnitGeometry);
}

// This region handles how the component in displayed on the ribbon including name, exposure level and icon
public AdSecPointParameter AdSecPoint { get; set; } = new AdSecPointParameter();

public override Attribute[] GetAllOutputAttributes() {
return new Attribute[] {
AdSecPoint,
};
}
}

public class CreatePoint : DropdownAdapter<CreatePointGh> {
private LengthUnit _lengthUnit = DefaultUnits.LengthUnitGeometry;

public CreatePoint() { Hidden = false; }

public override Guid ComponentGuid => new Guid("1a0cdb3c-d66d-420e-a9d8-35d31587a122");
public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure;
public override OasysPluginInfo PluginInfo => AdSecGH.PluginInfo.Instance;
protected override Bitmap Icon => Resources.VertexPoint;

public override void SetSelected(int i, int j) {
Expand All @@ -44,8 +61,8 @@ public override void SetSelected(int i, int j) {

public override void VariableParameterMaintenance() {
string unitAbbreviation = Length.GetAbbreviation(_lengthUnit);
Params.Input[0].Name = $"Y [{unitAbbreviation}]";
Params.Input[1].Name = $"Z [{unitAbbreviation}]";
Params.Input[0].Name = "Y [" + unitAbbreviation + "]";
Params.Input[1].Name = "Z [" + unitAbbreviation + "]";
}

protected override void InitialiseDropdowns() {
Expand All @@ -62,34 +79,6 @@ protected override void InitialiseDropdowns() {
_isInitialised = true;
}

protected override void RegisterInputParams(GH_InputParamManager pManager) {
string unitAbbreviation = Length.GetAbbreviation(_lengthUnit);
pManager.AddGenericParameter($"Y [{unitAbbreviation}]", "Y", "The local Y coordinate in yz-plane",
GH_ParamAccess.item);
pManager.AddGenericParameter($"Z [{unitAbbreviation}]", "Z", "The local Z coordinate in yz-plane",
GH_ParamAccess.item);
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
pManager.AddGenericParameter("Vertex Point", "Vx",
"A 2D vertex in the yz-plane for AdSec Profile and Reinforcement", GH_ParamAccess.item);
}

protected override void SolveInternal(IGH_DataAccess DA) {
// get inputs
var y = (Length)Input.UnitNumber(this, DA, 0, _lengthUnit);
var z = (Length)Input.UnitNumber(this, DA, 1, _lengthUnit);

// create IPoint
var pt = IPoint.Create(y, z);

// Convert to AdSecPointGoo param
var point = new AdSecPointGoo(pt);

// set output
DA.SetData(0, point);
}

protected override void UpdateUIFromSelectedItems() {
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[0]);
base.UpdateUIFromSelectedItems();
Expand Down
Loading