Skip to content

Commit

Permalink
Merge pull request #155 from arup-group/GSAGH-102-fix-perimeter-profile
Browse files Browse the repository at this point in the history
Gsagh 102 fix perimeter profile
  • Loading branch information
kpne authored Aug 19, 2022
2 parents 86c5c00 + aa63346 commit c629a84
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 21 deletions.
108 changes: 90 additions & 18 deletions GhSA/Components/1_Properties/CreateProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,22 +841,72 @@ protected override void SolveInstance(IGH_DataAccess DA)
return;
}

Point3d origin = new Point3d(ctrl_pts[0]);
double x1 = ctrl_pts[ctrl_pts.Count - 2].X - origin.X;
double y1 = ctrl_pts[ctrl_pts.Count - 2].Y - origin.Y;
double z1 = ctrl_pts[ctrl_pts.Count - 2].Z - origin.Z;
Vector3d xDirection = new Vector3d(x1, y1, z1);
xDirection.Unitize();

double x2 = ctrl_pts[1].X - origin.X;
double y2 = ctrl_pts[1].Y - origin.Y;
double z2 = ctrl_pts[1].Z - origin.Z;
Vector3d yDirection = new Vector3d(x2, y2, z2);
yDirection.Unitize();

Plane plane = new Plane(Point3d.Origin, xDirection, yDirection);
bool localPlaneNotSet = true;
Plane plane = Plane.Unset;
if (DA.GetData(1, ref plane))
localPlaneNotSet = false;

Point3d origin = new Point3d();
if (localPlaneNotSet)
{
foreach (Point3d p in ctrl_pts)
{
origin.X += p.X;
origin.Y += p.Y;
origin.Z += p.Z;
}
origin.X = origin.X / ctrl_pts.Count;
origin.Y = origin.Y / ctrl_pts.Count;
origin.Z = origin.Z / ctrl_pts.Count;

Plane.FitPlaneToPoints(ctrl_pts, out plane);

Vector3d xDirection = new Vector3d(
Math.Abs(plane.XAxis.X),
Math.Abs(plane.XAxis.Y),
Math.Abs(plane.XAxis.Z));
xDirection.Unitize();
Vector3d yDirection = new Vector3d(
Math.Abs(plane.YAxis.X),
Math.Abs(plane.YAxis.Y),
Math.Abs(plane.YAxis.Z));
xDirection.Unitize();

Vector3d normal = plane.Normal;
normal.Unitize();
if (normal.X == 1)
plane = Plane.WorldYZ;
else if (normal.Y == 1)
plane = Plane.WorldZX;
else if (normal.Z == 1)
plane = Plane.WorldXY;
else
plane = new Plane(Point3d.Origin, xDirection, yDirection);
plane.Origin = origin;

//double x1 = ctrl_pts[ctrl_pts.Count - 2].X - origin.X;
//double y1 = ctrl_pts[ctrl_pts.Count - 2].Y - origin.Y;
//double z1 = ctrl_pts[ctrl_pts.Count - 2].Z - origin.Z;
//Vector3d xDirection = new Vector3d(x1, y1, z1);
//xDirection.Unitize();

//double x2 = ctrl_pts[1].X - origin.X;
//double y2 = ctrl_pts[1].Y - origin.Y;
//double z2 = ctrl_pts[1].Z - origin.Z;
//Vector3d yDirection = new Vector3d(x2, y2, z2);
//yDirection.Unitize();

//plane = new Plane(Point3d.Origin, xDirection, yDirection);
}
else
{
origin = plane.Origin;
}

Transform translation = Transform.Translation(-origin.X, -origin.Y, -origin.Z);
Transform rotation = Transform.ChangeBasis(Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, plane.XAxis, plane.YAxis, plane.ZAxis);
if (localPlaneNotSet)
rotation = Transform.ChangeBasis(Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, plane.YAxis, plane.XAxis, plane.ZAxis);

perimeter.geoType = Profile.GeoTypes.Perim;

Expand Down Expand Up @@ -984,12 +1034,12 @@ private void Mode1Clicked()
Params.OnParametersChanged();
ExpireSolution(true);
}
private void SetNumberOfGenericInputs(int inputs, bool isSecantPile = false)
private void SetNumberOfGenericInputs(int inputs, bool isSecantPile = false, bool isPerimeter = false)
{
numberOfInputs = inputs;

// if last input previously was a bool and we no longer need that
if (lastInputWasSecant || isSecantPile)
if (lastInputWasSecant || isSecantPile || isPerimeter)
{
if (Params.Input.Count > 0)
{
Expand Down Expand Up @@ -1020,8 +1070,19 @@ private void SetNumberOfGenericInputs(int inputs, bool isSecantPile = false)
Params.RegisterInputParam(new Param_Boolean());
lastInputWasSecant = true;
}
else
lastInputWasSecant = false;

if (isPerimeter)
{
Params.RegisterInputParam(new Param_Plane());
lastInputWasPerimeter = true;
}
else
lastInputWasPerimeter = false;
}
private bool lastInputWasSecant;
private bool lastInputWasPerimeter;
private int numberOfInputs;
// temporary
//private Type typ = typeof(IRectangleProfile);
Expand Down Expand Up @@ -1181,7 +1242,8 @@ private void Mode2Clicked()
// IPerimeterProfile
else if (typ == "IPerimeterProfile") //(typ.Name.Equals(typeof(IPerimeterProfile).Name))
{
SetNumberOfGenericInputs(1);
SetNumberOfGenericInputs(1, false, true);

//dup = IPerimeterProfile.Create();
//solidPolygon;
//voidPolygons;
Expand Down Expand Up @@ -1687,7 +1749,7 @@ void IGH_VariableParameterComponent.VariableParameterMaintenance()
i++;
Params.Input[i].NickName = "B";
Params.Input[i].Name = "Width [" + unitAbbreviation + "]";
Params.Input[i].Description = "Width of the rectangle, in loca y-axis direction.";
Params.Input[i].Description = "Width of the rectangle, in local y-axis direction.";
Params.Input[i].Access = GH_ParamAccess.item;
Params.Input[i].Optional = false;
//dup = IRectangleProfile.Create(rectangle.Depth, rectangle.Width);
Expand Down Expand Up @@ -1887,6 +1949,16 @@ void IGH_VariableParameterComponent.VariableParameterMaintenance()
Params.Input[i].Access = GH_ParamAccess.item;
Params.Input[i].Optional = false;

if (Params.Input.Count == 1) // handle backwards compatability
Params.RegisterInputParam(new Param_Plane());

i++;
Params.Input[i].NickName = "P";
Params.Input[i].Name = "Plane";
Params.Input[i].Description = "Optional plane in which to project boundary onto. Profile will get coordinates in this plane.";
Params.Input[i].Access = GH_ParamAccess.item;
Params.Input[i].Optional = true;

//i++;
//Params.Input[i].NickName = "V";
//Params.Input[i].Name = "[Optional] VoidPolylines";
Expand Down
2 changes: 1 addition & 1 deletion GhSA/GsaGHInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public class GsaGHInfo : GH_AssemblyInfo
internal const string Company = "Oasys";
internal const string Copyright = "Copyright © Oasys 1985 - 2022";
internal const string Contact = "https://www.oasys-software.com/";
internal const string Vers = "0.9.25";
internal const string Vers = "0.9.26";
internal static bool isBeta = true;
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. ";
internal const string ProductName = "GSA";
Expand Down
7 changes: 5 additions & 2 deletions GhSA/Parameters/_Units.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,16 @@ public static DurationUnit TimeLongUnit
private static BaseUnits SI = UnitsNet.UnitSystem.SI.BaseUnits;

#region methods
internal static void SetupUnitsDuringLoad()
public static void SetupUnitsDuringLoad(bool headless = false)
{
bool settingsExist = ReadSettings();
if (!settingsExist)
{
// get rhino document length unit
m_length_geometry = GetRhinoLengthUnit(RhinoDoc.ActiveDoc.ModelUnitSystem);
if (headless)
m_length_geometry = LengthUnit.Meter;
else
m_length_geometry = GetRhinoLengthUnit(RhinoDoc.ActiveDoc.ModelUnitSystem);
m_length_section = LengthUnit.Centimeter;
m_length_result = LengthUnit.Millimeter;

Expand Down

0 comments on commit c629a84

Please sign in to comment.