protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0 Plane
            Plane pln = Plane.Unset;
            GsaGridPlaneSurface gps;
            bool idSet = false;

            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                {
                    GsaGridPlaneSurface temppln = new GsaGridPlaneSurface();
                    gh_typ.CastTo(ref temppln);
                    gps = temppln.Duplicate();
                }
                else
                {
                    if (gh_typ.CastTo(ref pln))
                    {
                        gps = new GsaGridPlaneSurface(pln);
                    }
                    else
                    {
                        int id = 0;
                        if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                        {
                            gps = new GsaGridPlaneSurface();
                            gps.GridSurface.GridPlane = id;
                            gps.GridPlane             = null;
                            idSet = true;
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Cannot convert your input to GridPlaneSurface or Plane");
                            return;
                        }
                    }
                }
            }
            else
            {
                pln = Plane.WorldXY;
                gps = new GsaGridPlaneSurface(pln);
            }

            // record if changes has been made from default type
            bool        changeGS = false;
            GridSurface gs       = new GridSurface(); // new GridSurface to make changes to, set it back to GPS in the end

            if (idSet)
            {
                gs.GridPlane = gps.GridSurface.GridPlane;
            }

            // 1 ID
            GH_Integer ghint = new GH_Integer();

            if (DA.GetData(1, ref ghint))
            {
                int id = 0;
                GH_Convert.ToInt32(ghint, out id, GH_Conversion.Both);
                gps.GridSurfaceID = id;
            }

            // 2 Elements
            GH_String ghelem = new GH_String();

            if (DA.GetData(2, ref ghelem))
            {
                string elem = "";
                if (GH_Convert.ToString(ghelem, out elem, GH_Conversion.Both))
                {
                    gs.Elements = elem;
                    changeGS    = true;
                }
            }

            // 3 Name
            GH_String ghtxt = new GH_String();

            if (DA.GetData(3, ref ghtxt))
            {
                string name = "";
                if (GH_Convert.ToString(ghtxt, out name, GH_Conversion.Both))
                {
                    gs.Name  = name;
                    changeGS = true;
                }
            }

            // 4 Tolerance
            GH_Number ghtol = new GH_Number();

            if (DA.GetData(4, ref ghtol))
            {
                double tol = 10;
                if (GH_Convert.ToDouble(ghtol, out tol, GH_Conversion.Both))
                {
                    gs.Tolerance = tol;
                    changeGS     = true;
                }
            }

            switch (_mode)
            {
            case FoldMode.One_Dimensional_One_Way:
                gs.ElementType = GridSurface.Element_Type.ONE_DIMENSIONAL;
                gs.SpanType    = GridSurface.Span_Type.ONE_WAY;

                // 5 span direction
                GH_Number ghdir = new GH_Number();
                if (DA.GetData(5, ref ghdir))
                {
                    double dir = 0;
                    if (GH_Convert.ToDouble(ghdir, out dir, GH_Conversion.Both))
                    {
                        if (dir > 180 || dir < -180)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Angle value must be between -180 and 180 degrees");     // to be updated when GsaAPI support units
                        }
                        gs.Direction = dir;
                        if (dir != 0)
                        {
                            changeGS = true;
                        }
                    }
                }
                break;

            case FoldMode.One_Dimensional_Two_Way:
                changeGS       = true;
                gs.ElementType = GridSurface.Element_Type.ONE_DIMENSIONAL;

                // 5 expansion method
                int        exp   = 0;
                GH_Integer ghexp = new GH_Integer();
                if (DA.GetData(5, ref ghexp))
                {
                    GH_Convert.ToInt32_Primary(ghexp, ref exp);
                }
                gs.ExpansionType = GridSurfaceExpansionType.PLANE_CORNER;
                if (exp == 1)
                {
                    gs.ExpansionType = GridSurfaceExpansionType.PLANE_SMOOTH;
                }
                if (exp == 2)
                {
                    gs.ExpansionType = GridSurfaceExpansionType.PLANE_ASPECT;
                }
                if (exp == 3)
                {
                    gs.ExpansionType = GridSurfaceExpansionType.LEGACY;
                }

                // 6 simplify tributary area
                bool       simple = true;
                GH_Boolean ghsim  = new GH_Boolean();
                if (DA.GetData(6, ref ghsim))
                {
                    GH_Convert.ToBoolean(ghsim, out simple, GH_Conversion.Both);
                }
                if (simple)
                {
                    gs.SpanType = GridSurface.Span_Type.TWO_WAY_SIMPLIFIED_TRIBUTARY_AREAS;
                }
                else
                {
                    gs.SpanType = GridSurface.Span_Type.TWO_WAY;
                }
                break;

            case FoldMode.Two_Dimensional:
                changeGS       = true;
                gs.ElementType = GridSurface.Element_Type.TWO_DIMENSIONAL;
                break;
            }
            if (changeGS)
            {
                gps.GridSurface = gs;
            }

            DA.SetData(0, new GsaGridPlaneSurfaceGoo(gps));
        }
Beispiel #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            ///input parameters
            List <Mesh> Rhino_Mesh             = new List <Mesh>();
            GH_Structure <GH_Integer> Rhino_si = new GH_Structure <GH_Integer>();
            GH_Structure <GH_Integer> Rhino_sj = new GH_Structure <GH_Integer>();
            double         t             = 0.8;
            DataTree <int> Rhino_Cluster = new DataTree <int>();///output

            ///import data
            if (!DA.GetDataList("Mesh", Rhino_Mesh))
            {
                return;
            }
            if (!DA.GetDataTree("Mesh_si", out Rhino_si))
            {
                return;
            }
            if (!DA.GetDataTree("Mesh_sj", out Rhino_sj))
            {
                return;
            }
            if (!DA.GetData("Threshold_Thickness", ref t))
            {
                return;
            }

            /// 0. loop through si[]
            ///     Add largest si to "cluster[]"
            ///     compute initial interval_0
            /// 1. loop through cluster[a]
            ///    select seed= cluster[a]
            ///    search all occurances of seed in si
            ///    select corresponding indices in sj => add to queue[]
            ///    delete si.occurances
            ///    delete sj.occurances
            /// 2. loop through queue[i]
            ///     select next largest mesh in "queue[]"
            ///     compute queue[i].BB given plane of s0
            ///     if length.interval within t =>
            ///         add queue[i] to cluster[]
            ///         update interval
            ///     else
            ///         add queue[i] to si and sj
            ///     remove queue[i]
            ///
            ///

            /// local parameters
            ///Datatree<int> cluster = new List<int>();
            Box      box_0      = new Box();
            Box      box_i      = new Box();
            Plane    Plane_mesh = new Plane();
            Interval t_test     = new Interval();
            int      seed;


            for (int i = 0; i < Rhino_si.Branches.Count; i++)
            {
                int     a = 0;
                var     Rhino_si_branch = new List <int>();
                var     Rhino_sj_branch = new List <int>();
                GH_Path gH_Path         = Rhino_si.Paths[i];

                int d = new int(); int e = new int();
                for (int j = 0; j < Rhino_si.get_Branch(gH_Path).Count; j++)
                {
                    GH_Convert.ToInt32_Primary(Rhino_si.get_DataItem(gH_Path, j), ref d);
                    Rhino_si_branch.Add(d);
                    GH_Convert.ToInt32_Primary(Rhino_sj.get_DataItem(gH_Path, j), ref e);
                    Rhino_sj_branch.Add(e);
                }


                ///0.
                while (Rhino_si_branch.Any())
                {
                    seed = Rhino_si_branch[0];

                    GH_Path path = new GH_Path(i, a);
                    Rhino_Cluster.Add(seed, path);

                    /// create initial BB based on largest surface
                    var            Mesh_0        = Rhino_Mesh.ElementAt(Rhino_Cluster[path, 0]); /// select largest mesh
                    var            bbox          = Mesh_0.GetBoundingBox(false);                 /// create world BB
                    var            Mesh_centroid = bbox.Center;                                  /// retrieve centre
                    List <Point3d> centroids     = new List <Point3d>();
                    for (int l = 0; l < Mesh_0.Faces.Count; l++)                                 /// retrieve best fit plane
                    {
                        centroids.Add(Mesh_0.Faces.GetFaceCenter(l));
                    }
                    Plane Plane_temp = new Plane();
                    Plane.FitPlaneToPoints(centroids, out Plane_temp);
                    Plane_mesh = Plane_temp;                      /// plane to rhino.plane (just a neccesity)
                    Mesh_0.GetBoundingBox(Plane_mesh, out box_0); /// realign BB according plane mesh
                    var t_0 = box_0.Z;
                    t_test.Grow(t_0.Min);
                    t_test.Grow(t_0.Max);
                    int b = 0;

                    ///1.
                    while (Rhino_Cluster.Branch(path).Count > b)
                    {
                        seed = Rhino_Cluster.Branch(path)[b];
                        /// find all occurances of seed in si

                        List <string> test = new List <string>();
                        test.Add("test");
                        var aret = "t";
                        var A    = test.FindIndex(k => k == aret);

                        var si    = Rhino_si_branch.FindIndex(s => s == seed);
                        var sj    = Rhino_sj_branch.FindIndex(s => s == seed);
                        var queue = new List <int>();
                        /// select corresponding sj and add to queue
                        while (si != -1 || sj != -1)
                        {
                            si = Rhino_si_branch.FindIndex(s => s == seed);

                            if (si != -1)
                            {
                                Rhino_si_branch.RemoveAt(si);
                                if (Rhino_Cluster.Branch(path).FindIndex(s => s == Rhino_sj_branch[si]) == -1)
                                {
                                    queue.Add((int)Rhino_sj_branch[si]);
                                }
                                Rhino_sj_branch.RemoveAt(si);
                            }
                            sj = Rhino_sj_branch.FindIndex(s => s == seed);
                            if (sj != -1)
                            {
                                Rhino_sj_branch.RemoveAt(sj);
                                if (Rhino_Cluster.Branch(path).FindIndex(s => s == Rhino_si_branch[sj]) == -1)
                                {
                                    queue.Add((int)Rhino_si_branch[sj]);
                                }
                                Rhino_si_branch.RemoveAt(sj);
                            }
                        }

                        var t_i = t_0;
                        while (queue.Count != 0)
                        {
                            Rhino_Mesh.ElementAt(queue[0]).GetBoundingBox(Plane_mesh, out box_i); /// select largest mesh
                            t_test = t_i;
                            t_test.Grow(box_i.Z.Max);
                            t_test.Grow(box_i.Z.Min);
                            if (Math.Abs(t_test.Length) <= t)
                            {
                                t_i = t_test;

                                if (Rhino_Cluster.Branch(path).FindIndex(s => s == queue[0]) == -1)
                                {
                                    Rhino_Cluster.Add((int)queue[0], path);
                                }
                            }
                            else
                            {
                                Rhino_si_branch.Add(queue[0]);
                                Rhino_sj_branch.Add(queue[0]);
                            }

                            queue.RemoveAt(0);
                        }
                        b++;
                    }
                    a++;
                }
            }
            /// output
            DA.SetDataTree(0, Rhino_Cluster);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaProp2d prop = new GsaProp2d();

            // element type (picked in dropdown)
            prop.Prop2d.Type = Property2D_Type.UNDEF;
            if (_mode == FoldMode.PlaneStress)
            {
                prop.Prop2d.Type = Property2D_Type.PL_STRESS;
            }
            if (_mode == FoldMode.Fabric)
            {
                prop.Prop2d.Type = Property2D_Type.FABRIC;
            }
            if (_mode == FoldMode.FlatPlate)
            {
                prop.Prop2d.Type = Property2D_Type.PLATE;
            }
            if (_mode == FoldMode.Shell)
            {
                prop.Prop2d.Type = Property2D_Type.SHELL;
            }
            if (_mode == FoldMode.CurvedShell)
            {
                prop.Prop2d.Type = Property2D_Type.CURVED_SHELL;
            }
            if (_mode == FoldMode.LoadPanel)
            {
                prop.Prop2d.Type = Property2D_Type.LOAD;
            }

            //id
            GH_Integer gh_ID = new GH_Integer();

            DA.GetData(0, ref gh_ID);
            int idd = 0;

            GH_Convert.ToInt32_Primary(gh_ID, ref idd);
            prop.ID = idd;

            //name
            GH_String gh_Name = new GH_String();

            DA.GetData(1, ref gh_Name);
            string name = "";

            GH_Convert.ToString_Primary(gh_Name, ref name);
            prop.Prop2d.Name = name;

            //colour
            GH_Colour gh_Colour = new GH_Colour();

            DA.GetData(2, ref gh_Colour);
            System.Drawing.Color colour = new System.Drawing.Color();
            GH_Convert.ToColor_Primary(gh_Colour, ref colour);
            prop.Prop2d.Colour = (ValueType)colour;

            if (_mode != FoldMode.LoadPanel)
            {
                //axis
                GH_Integer gh_Axis = new GH_Integer();
                DA.GetData(3, ref gh_Axis);
                int axis = 0;
                GH_Convert.ToInt32_Primary(gh_Axis, ref axis);
                prop.Prop2d.AxisProperty = axis;


                if (_mode != FoldMode.Fabric)
                {
                    //Material type
                    GH_ObjectWrapper gh_typ  = new GH_ObjectWrapper();
                    MaterialType     matType = MaterialType.CONCRETE;
                    if (DA.GetData(4, ref gh_typ))
                    {
                        if (gh_typ.Value is MaterialType)
                        {
                            gh_typ.CastTo(ref matType);
                        }
                        if (gh_typ.Value is GH_String)
                        {
                            string typ = "CONCRETE";
                            GH_Convert.ToString_Primary(gh_typ, ref typ);
                            if (typ.ToUpper() == "STEEL")
                            {
                                matType = MaterialType.STEEL;
                            }
                            if (typ.ToUpper() == "CONCRETE")
                            {
                                matType = MaterialType.CONCRETE;
                            }
                            if (typ.ToUpper() == "FRP")
                            {
                                matType = MaterialType.FRP;
                            }
                            if (typ.ToUpper() == "ALUMINIUM")
                            {
                                matType = MaterialType.ALUMINIUM;
                            }
                            if (typ.ToUpper() == "TIMBER")
                            {
                                matType = MaterialType.TIMBER;
                            }
                            if (typ.ToUpper() == "GLASS")
                            {
                                matType = MaterialType.GLASS;
                            }
                            if (typ.ToUpper() == "FABRIC")
                            {
                                matType = MaterialType.FABRIC;
                            }
                            if (typ.ToUpper() == "GENERIC")
                            {
                                matType = MaterialType.GENERIC;
                            }
                        }
                    }
                    prop.Prop2d.MaterialType = matType;

                    //thickness
                    GH_Number gh_THK = new GH_Number();

                    double thickness = 0.2;
                    if (DA.GetData(7, ref gh_THK))
                    {
                        GH_Convert.ToDouble_Primary(gh_THK, ref thickness);
                    }
                    //prop.Prop2d.Thickness = thickness;
                }
                else
                {
                    prop.Prop2d.MaterialType = MaterialType.FABRIC;
                }

                //handle that the last two inputs are at different -1 index for fabric mode
                int fab = 0;
                if (_mode == FoldMode.Fabric)
                {
                    fab = 1;
                }

                //grade
                GH_Integer gh_grd = new GH_Integer();
                DA.GetData(5 - fab, ref gh_grd);
                int grade = 1;
                GH_Convert.ToInt32_Primary(gh_grd, ref grade);
                prop.Prop2d.MaterialGradeProperty = grade;

                //analysis
                GH_Integer gh_anal = new GH_Integer();
                DA.GetData(6 - fab, ref gh_anal);
                int analysis = 1;
                GH_Convert.ToInt32_Primary(gh_anal, ref analysis);
                prop.Prop2d.MaterialAnalysisProperty = analysis;
            }

            DA.SetData(0, new GsaProp2dGoo(prop));
        }