Skip to content

Commit

Permalink
Fix grid point load not being in the right location
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan Nielsen committed Oct 10, 2023
1 parent 831d016 commit cecce67
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
Binary file not shown.
28 changes: 18 additions & 10 deletions GsaGH/Components/3_Loads/CreateGridPointLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,29 @@ protected override void SolveInternal(IGH_DataAccess da) {
GH_Convert.ToPoint3d(ghPt, ref point3d, GH_Conversion.Both);
}

gridPointLoad.ApiLoad.X = point3d.X;
gridPointLoad.ApiLoad.Y = point3d.Y;

GsaGridPlaneSurface gridPlaneSurface;
Plane plane = Plane.WorldXY;
var ghTyp = new GH_ObjectWrapper();
if (da.GetData(2, ref ghTyp)) {
switch (ghTyp.Value) {
case GsaGridPlaneSurfaceGoo gridplanesurfacegoo: {
case GsaGridPlaneSurfaceGoo gridplanesurfacegoo:
gridPlaneSurface = gridplanesurfacegoo.Value.Duplicate();
gridPointLoad.GridPlaneSurface = gridPlaneSurface;
_expansionType = ExpansionType.UseGpsSettings;
UpdateMessage(gridPlaneSurface.GridSurface.ElementType
== GsaAPI.GridSurface.Element_Type.ONE_DIMENSIONAL ? "1D" : "2D");
break;
}
case Plane pln:
plane = pln;


case GH_Plane pln:
plane = pln.Value;

Check warning on line 167 in GsaGH/Components/3_Loads/CreateGridPointLoad.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/3_Loads/CreateGridPointLoad.cs#L167

Added line #L167 was not covered by tests
gridPlaneSurface = new GsaGridPlaneSurface(plane);
gridPointLoad.GridPlaneSurface = gridPlaneSurface;
UpdateMessage(gridPlaneSurface.GridSurface.ElementType
== GsaAPI.GridSurface.Element_Type.ONE_DIMENSIONAL ? "1D" : "2D");
break;

default: {
default:
if (GH_Convert.ToInt32(ghTyp.Value, out int id, GH_Conversion.Both)) {
gridPointLoad.ApiLoad.GridSurface = id;
gridPointLoad.GridPlaneSurface = null;
Expand All @@ -186,11 +184,11 @@ protected override void SolveInternal(IGH_DataAccess da) {
}

break;
}

}
} else {
plane = Plane.WorldXY;
plane.Origin = point3d;
plane.Origin = new Point3d(0, 0, point3d.Z);
gridPlaneSurface = new GsaGridPlaneSurface(plane, true);
gridPointLoad.GridPlaneSurface = gridPlaneSurface;

Expand Down Expand Up @@ -220,6 +218,16 @@ protected override void SolveInternal(IGH_DataAccess da) {
}
}

var plnNormal = new Vector3d(plane.Normal);
plnNormal.Unitize();
if (plnNormal.Z != 1) {
this.AddRuntimeRemark("The grid plane basis is not defined in world coordinates. \n" +
"The input point´s X and Y coordinates are use as the grid plane´s local coordiantes.");

Check warning on line 225 in GsaGH/Components/3_Loads/CreateGridPointLoad.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/3_Loads/CreateGridPointLoad.cs#L224-L225

Added lines #L224 - L225 were not covered by tests
}

gridPointLoad.ApiLoad.X = point3d.X;
gridPointLoad.ApiLoad.Y = point3d.Y;

string dir = "Z";
GsaAPI.Direction direc = GsaAPI.Direction.Z;

Expand Down
42 changes: 42 additions & 0 deletions IntegrationTests/2_Parameters/3_Loads/GridPointLoadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;
using System.Reflection;
using Grasshopper.Kernel;
using Xunit;

namespace IntegrationTests.Parameters {
[Collection("GrasshopperFixture collection")]
public class GridPointLoadTests {
public static GH_Document Document => document ?? (document = OpenDocument());
private static GH_Document document = null;

[Theory]
[InlineData("LoadIsEqual", 0)]
[InlineData("PointIsEqual", 0)]
public void TestTxtInput(string groupIdentifier, object expected) {
IGH_Param param = Helper.FindParameter(Document, groupIdentifier);
Helper.TestGhPrimitives(param, expected);
}

private static GH_Document OpenDocument() {
string fileName = MethodBase.GetCurrentMethod().DeclaringType + ".gh";
fileName = fileName.Replace("IntegrationTests.Parameters.", string.Empty)
.Replace("Tests", string.Empty);

string solutiondir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent
.Parent.FullName;
string path = Path.Combine(new string[] {
solutiondir,
"ExampleFiles",
"Parameters",
"3_Loads",
});
var io = new GH_DocumentIO();
Assert.True(File.Exists(Path.Combine(path, fileName)));
Assert.True(io.Open(Path.Combine(path, fileName)));
io.Document.NewSolution(true);

return io.Document;
}
}
}

0 comments on commit cecce67

Please sign in to comment.