diff --git a/GhSA/Components/1_Properties/CreateProfile.cs b/GhSA/Components/1_Properties/CreateProfile.cs index c44020314..ee53bb16e 100644 --- a/GhSA/Components/1_Properties/CreateProfile.cs +++ b/GhSA/Components/1_Properties/CreateProfile.cs @@ -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; @@ -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) { @@ -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); @@ -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; @@ -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); @@ -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"; diff --git a/GhSA/GsaGHInfo.cs b/GhSA/GsaGHInfo.cs index 6c216d455..0b425137d 100644 --- a/GhSA/GsaGHInfo.cs +++ b/GhSA/GsaGHInfo.cs @@ -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"; diff --git a/GhSA/Parameters/_Units.cs b/GhSA/Parameters/_Units.cs index 290e3528f..519fb59a9 100644 --- a/GhSA/Parameters/_Units.cs +++ b/GhSA/Parameters/_Units.cs @@ -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;