Ejemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region GetData
            Models            = null;
            Nodes             = null;
            Elem1ds           = null;
            Elem2ds           = null;
            Elem3ds           = null;
            Mem1ds            = null;
            Mem2ds            = null;
            Mem3ds            = null;
            Loads             = null;
            Sections          = null;
            Prop2Ds           = null;
            GridPlaneSurfaces = null;

            // Get Model input
            List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
            if (DA.GetDataList(0, gh_types))
            {
                List <GsaModel> in_models = new List <GsaModel>();
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = gh_types[i];
                    if (gh_typ == null)
                    {
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input is null"); return;
                    }
                    if (gh_typ.Value is GsaModelGoo)
                    {
                        GsaModel in_model = new GsaModel();
                        gh_typ.CastTo(ref in_model);
                        in_models.Add(in_model);
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " +
                                                       type + " to GsaModel");
                        return;
                    }
                }
                Models = in_models;
            }

            // Get Section Property input
            gh_types = new List <GH_ObjectWrapper>();
            if (DA.GetDataList(1, gh_types))
            {
                List <GsaSection> in_sect = new List <GsaSection>();
                List <GsaProp2d>  in_prop = new List <GsaProp2d>();
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaSectionGoo)
                    {
                        GsaSection gsasection = new GsaSection();
                        gh_typ.CastTo(ref gsasection);
                        in_sect.Add(gsasection.Duplicate());
                    }
                    else if (gh_typ.Value is GsaProp2dGoo)
                    {
                        GsaProp2d gsaprop = new GsaProp2d();
                        gh_typ.CastTo(ref gsaprop);
                        in_prop.Add(gsaprop.Duplicate());
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " +
                                                       type + " to GsaSection or GsaProp2d");
                        return;
                    }
                }
                if (in_sect.Count > 0)
                {
                    Sections = in_sect;
                }
                if (in_prop.Count > 0)
                {
                    Prop2Ds = in_prop;
                }
            }

            // Get Geometry input
            gh_types = new List <GH_ObjectWrapper>();
            List <GsaNode>      in_nodes   = new List <GsaNode>();
            List <GsaElement1d> in_elem1ds = new List <GsaElement1d>();
            List <GsaElement2d> in_elem2ds = new List <GsaElement2d>();
            List <GsaElement3d> in_elem3ds = new List <GsaElement3d>();
            List <GsaMember1d>  in_mem1ds  = new List <GsaMember1d>();
            List <GsaMember2d>  in_mem2ds  = new List <GsaMember2d>();
            List <GsaMember3d>  in_mem3ds  = new List <GsaMember3d>();
            if (DA.GetDataList(2, gh_types))
            {
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaNodeGoo)
                    {
                        GsaNode gsanode = new GsaNode();
                        gh_typ.CastTo(ref gsanode);
                        in_nodes.Add(gsanode.Duplicate());
                    }
                    else if (gh_typ.Value is GsaElement1dGoo)
                    {
                        GsaElement1d gsaelem1 = new GsaElement1d();
                        gh_typ.CastTo(ref gsaelem1);
                        in_elem1ds.Add(gsaelem1.Duplicate());
                    }
                    else if (gh_typ.Value is GsaElement2dGoo)
                    {
                        GsaElement2d gsaelem2 = new GsaElement2d();
                        gh_typ.CastTo(ref gsaelem2);
                        in_elem2ds.Add(gsaelem2.Duplicate());
                    }
                    else if (gh_typ.Value is GsaElement3dGoo)
                    {
                        GsaElement3d gsaelem3 = new GsaElement3d();
                        gh_typ.CastTo(ref gsaelem3);
                        in_elem3ds.Add(gsaelem3.Duplicate());
                    }
                    else if (gh_typ.Value is GsaMember1dGoo)
                    {
                        GsaMember1d gsamem1 = new GsaMember1d();
                        gh_typ.CastTo(ref gsamem1);
                        in_mem1ds.Add(gsamem1.Duplicate());
                    }
                    else if (gh_typ.Value is GsaMember2dGoo)
                    {
                        GsaMember2d gsamem2 = new GsaMember2d();
                        gh_typ.CastTo(ref gsamem2);
                        in_mem2ds.Add(gsamem2.Duplicate());
                    }
                    else if (gh_typ.Value is GsaMember3dGoo)
                    {
                        GsaMember3d gsamem3 = new GsaMember3d();
                        gh_typ.CastTo(ref gsamem3);
                        in_mem3ds.Add(gsamem3.Duplicate());
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " +
                                                       type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D");
                        return;
                    }
                }
                if (in_nodes.Count > 0)
                {
                    Nodes = in_nodes;
                }
                if (in_elem1ds.Count > 0)
                {
                    Elem1ds = in_elem1ds;
                }
                if (in_elem2ds.Count > 0)
                {
                    Elem2ds = in_elem2ds;
                }
                if (in_elem3ds.Count > 0)
                {
                    Elem3ds = in_elem3ds;
                }
                if (in_mem1ds.Count > 0)
                {
                    Mem1ds = in_mem1ds;
                }
                if (in_mem2ds.Count > 0)
                {
                    Mem2ds = in_mem2ds;
                }
                if (in_mem3ds.Count > 0)
                {
                    Mem3ds = in_mem3ds;
                }
            }


            // Get Loads input
            gh_types = new List <GH_ObjectWrapper>();
            if (DA.GetDataList(3, gh_types))
            {
                List <GsaLoad>             in_loads = new List <GsaLoad>();
                List <GsaGridPlaneSurface> in_gps   = new List <GsaGridPlaneSurface>();
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaLoadGoo)
                    {
                        GsaLoad gsaload = null;
                        gh_typ.CastTo(ref gsaload);
                        in_loads.Add(gsaload.Duplicate());
                    }
                    else if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                    {
                        GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface();
                        gh_typ.CastTo(ref gsaGPS);
                        in_gps.Add(gsaGPS.Duplicate());
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " +
                                                       type + " to Load or GridPlaneSurface");
                        return;
                    }
                }
                if (in_loads.Count > 0)
                {
                    Loads = in_loads;
                }
                if (in_gps.Count > 0)
                {
                    GridPlaneSurfaces = in_gps;
                }
            }
            // manually add a warning if no input is set, as all inputs are optional
            if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null &
                Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null
                & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data");
                return;
            }

            #endregion

            #region DoWork
            GsaModel analysisModel = null;
            if (Models != null)
            {
                if (Models.Count > 0)
                {
                    if (Models.Count > 1)
                    {
                        analysisModel = Util.Gsa.ToGSA.Models.MergeModel(Models);
                    }
                    else
                    {
                        analysisModel = Models[0].Clone();
                    }
                }
            }
            if (analysisModel != null)
            {
                OutModel = analysisModel;
            }
            else
            {
                OutModel = new GsaModel();
            }

            // Assemble model
            Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(analysisModel, Nodes, Elem1ds, Elem2ds, Elem3ds, Mem1ds, Mem2ds, Mem3ds, Sections, Prop2Ds, Loads, GridPlaneSurfaces);
            //gsa.SaveAs(@"C:\Users\Kristjan.Nielsen\Desktop\test3.gwb");
            #region meshing
            // Create elements from members
            gsa.CreateElementsFromMembers();
            #endregion

            #region analysis

            //analysis
            IReadOnlyDictionary <int, AnalysisTask> gsaTasks = gsa.AnalysisTasks();
            if (gsaTasks.Count < 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Model contains no Analysis Tasks");
            }

            foreach (KeyValuePair <int, AnalysisTask> task in gsaTasks)
            {
                if (!(gsa.Analyse(task.Key)))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning Analysis Case " + task.Key + " could not be analysed");
                }
            }

            #endregion
            OutModel.Model = gsa;

            //gsa.SaveAs("C:\\Users\\Kristjan.Nielsen\\Desktop\\GsaGH_test.gwb");
            #endregion

            #region SetData
            DA.SetData(0, new GsaModelGoo(OutModel));
            #endregion
        }
Ejemplo n.º 2
0
            public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
            {
                #region GetData
                Models            = null;
                Nodes             = null;
                Elem1ds           = null;
                Elem2ds           = null;
                Elem3ds           = null;
                Mem1ds            = null;
                Mem2ds            = null;
                Mem3ds            = null;
                Loads             = null;
                Sections          = null;
                Prop2Ds           = null;
                GridPlaneSurfaces = null;
                OutModel          = null;
                component         = Params.Owner;

                // Get Model input
                List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(0, gh_types))
                {
                    List <GsaModel> in_models = new List <GsaModel>();
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaModelGoo)
                        {
                            GsaModel in_model = new GsaModel();
                            gh_typ.CastTo(ref in_model);
                            in_models.Add(in_model);
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " +
                                                           type + " to GsaModel");
                            return;
                        }
                    }
                    Models = in_models;
                }

                // Get Section Property input
                gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(1, gh_types))
                {
                    List <GsaSection> in_sect = new List <GsaSection>();
                    List <GsaProp2d>  in_prop = new List <GsaProp2d>();
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaSectionGoo)
                        {
                            GsaSection gsasection = new GsaSection();
                            gh_typ.CastTo(ref gsasection);
                            in_sect.Add(gsasection.Duplicate());
                        }
                        else if (gh_typ.Value is GsaProp2dGoo)
                        {
                            GsaProp2d gsaprop = new GsaProp2d();
                            gh_typ.CastTo(ref gsaprop);
                            in_prop.Add(gsaprop.Duplicate());
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " +
                                                           type + " to GsaSection or GsaProp2d");
                            return;
                        }
                    }
                    if (in_sect.Count > 0)
                    {
                        Sections = in_sect;
                    }
                    if (in_prop.Count > 0)
                    {
                        Prop2Ds = in_prop;
                    }
                }

                // Get Geometry input
                gh_types = new List <GH_ObjectWrapper>();
                List <GsaNode>      in_nodes   = new List <GsaNode>();
                List <GsaElement1d> in_elem1ds = new List <GsaElement1d>();
                List <GsaElement2d> in_elem2ds = new List <GsaElement2d>();
                List <GsaElement3d> in_elem3ds = new List <GsaElement3d>();
                List <GsaMember1d>  in_mem1ds  = new List <GsaMember1d>();
                List <GsaMember2d>  in_mem2ds  = new List <GsaMember2d>();
                List <GsaMember3d>  in_mem3ds  = new List <GsaMember3d>();
                if (DA.GetDataList(2, gh_types))
                {
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaNodeGoo)
                        {
                            GsaNode gsanode = new GsaNode();
                            gh_typ.CastTo(ref gsanode);
                            in_nodes.Add(gsanode.Duplicate());
                        }
                        else if (gh_typ.Value is GsaElement1dGoo)
                        {
                            GsaElement1d gsaelem1 = new GsaElement1d();
                            gh_typ.CastTo(ref gsaelem1);
                            in_elem1ds.Add(gsaelem1.Duplicate());
                        }
                        else if (gh_typ.Value is GsaElement2dGoo)
                        {
                            GsaElement2d gsaelem2 = new GsaElement2d();
                            gh_typ.CastTo(ref gsaelem2);
                            in_elem2ds.Add(gsaelem2.Duplicate());
                        }
                        else if (gh_typ.Value is GsaElement3dGoo)
                        {
                            GsaElement3d gsaelem3 = new GsaElement3d();
                            gh_typ.CastTo(ref gsaelem3);
                            in_elem3ds.Add(gsaelem3.Duplicate());
                        }
                        else if (gh_typ.Value is GsaMember1dGoo)
                        {
                            GsaMember1d gsamem1 = new GsaMember1d();
                            gh_typ.CastTo(ref gsamem1);
                            in_mem1ds.Add(gsamem1.Duplicate());
                        }
                        else if (gh_typ.Value is GsaMember2dGoo)
                        {
                            GsaMember2d gsamem2 = new GsaMember2d();
                            gh_typ.CastTo(ref gsamem2);
                            in_mem2ds.Add(gsamem2.Duplicate());
                        }
                        else if (gh_typ.Value is GsaMember3dGoo)
                        {
                            GsaMember3d gsamem3 = new GsaMember3d();
                            gh_typ.CastTo(ref gsamem3);
                            in_mem3ds.Add(gsamem3.Duplicate());
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " +
                                                           type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D");
                            return;
                        }
                    }
                    if (in_nodes.Count > 0)
                    {
                        Nodes = in_nodes;
                    }
                    if (in_elem1ds.Count > 0)
                    {
                        Elem1ds = in_elem1ds;
                    }
                    if (in_elem2ds.Count > 0)
                    {
                        Elem2ds = in_elem2ds;
                    }
                    if (in_elem3ds.Count > 0)
                    {
                        Elem3ds = in_elem3ds;
                    }
                    if (in_mem1ds.Count > 0)
                    {
                        Mem1ds = in_mem1ds;
                    }
                    if (in_mem2ds.Count > 0)
                    {
                        Mem2ds = in_mem2ds;
                    }
                    if (in_mem3ds.Count > 0)
                    {
                        Mem3ds = in_mem3ds;
                    }
                }


                // Get Loads input
                gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(3, gh_types))
                {
                    List <GsaLoad>             in_loads = new List <GsaLoad>();
                    List <GsaGridPlaneSurface> in_gps   = new List <GsaGridPlaneSurface>();
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaLoadGoo)
                        {
                            GsaLoad gsaload = null;
                            gh_typ.CastTo(ref gsaload);
                            in_loads.Add(gsaload.Duplicate());
                        }
                        else if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                        {
                            GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface();
                            gh_typ.CastTo(ref gsaGPS);
                            in_gps.Add(gsaGPS.Duplicate());
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " +
                                                           type + " to Load or GridPlaneSurface");
                            return;
                        }
                    }
                    if (in_loads.Count > 0)
                    {
                        Loads = in_loads;
                    }
                    if (in_gps.Count > 0)
                    {
                        GridPlaneSurfaces = in_gps;
                    }
                }

                #endregion

                // manually add a warning if no input is set, as all inputs are optional
                if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null &
                    Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null
                    & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null)
                {
                    hasInput = false;
                    Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data");
                    return;
                }
                else
                {
                    hasInput = true;
                }
            }
Ejemplo n.º 3
0
        public void TestDuplicateMem2d()
        {
            // create a list of corner points
            List <Point3d> pts = new List <Point3d>();

            pts.Add(new Point3d(1, 1, 0));
            pts.Add(new Point3d(0, 5, 0));
            pts.Add(new Point3d(6, 7, 0));
            pts.Add(new Point3d(4, 2, 0));
            pts.Add(pts[0]);                  // add initial point to close curve
            Polyline pol = new Polyline(pts); // create edge-crv from pts
            // create planar brep from polyline
            Brep brep = Brep.CreatePlanarBreps(pol.ToNurbsCurve(), 0.001)[0];

            // lists for inclusion points and lines
            List <Point3d> inclpts = new List <Point3d>();

            inclpts.Add(new Point3d(1, 1, 0));
            List <Curve> inclcrvs = new List <Curve>();
            LineCurve    line     = new LineCurve(new Point3d(1, 2, 0), new Point3d(3, 2, 0));

            inclcrvs.Add(line);

            // create 2d member from brep
            GsaMember2d original = new GsaMember2d(brep, inclcrvs, inclpts);

            // set some members
            original.Colour           = System.Drawing.Color.Blue;
            original.ID               = 13;
            original.Member.MeshSize  = 1.56;
            original.Member.Name      = "ehbaba";
            original.Member.IsDummy   = false;
            original.Member.Offset.X1 = 0.33;
            original.Member.Property  = 1;
            original.Property         = new GsaProp2d();
            original.Property.ID      = 3;
            original.Member.Type2D    = AnalysisOrder.RIGID_DIAPHRAGM;
            original.Member.Type      = MemberType.GENERIC_2D;

            // create duplicate
            GsaMember2d dup = original.Duplicate();

            Assert.AreEqual(original.Brep.Vertices[0].Location.X, dup.Topology[0].X);
            Assert.AreEqual(original.Brep.Vertices[0].Location.Y, dup.Topology[0].Y);
            Assert.AreEqual(original.Brep.Vertices[1].Location.X, dup.Topology[1].X);
            Assert.AreEqual(original.Brep.Vertices[1].Location.Y, dup.Topology[1].Y);
            Assert.AreEqual(original.Brep.Vertices[2].Location.X, dup.Topology[2].X);
            Assert.AreEqual(original.Brep.Vertices[2].Location.Y, dup.Topology[2].Y);
            Assert.AreEqual(original.Brep.Vertices[3].Location.X, dup.Topology[3].X);
            Assert.AreEqual(original.Brep.Vertices[3].Location.Y, dup.Topology[3].Y);
            Assert.AreEqual(original.Brep.Vertices[0].Location.X, dup.Topology[4].X);
            Assert.AreEqual(original.Brep.Vertices[0].Location.Y, dup.Topology[4].Y);
            Assert.AreEqual(1, dup.IncLinesTopology[0][0].X);
            Assert.AreEqual(2, dup.IncLinesTopology[0][0].Y);
            Assert.AreEqual(3, dup.IncLinesTopology[0][1].X);
            Assert.AreEqual(2, dup.IncLinesTopology[0][1].Y);
            Assert.AreEqual(1, dup.InclusionPoints[0].X);
            Assert.AreEqual(1, dup.InclusionPoints[0].Y);

            Assert.AreEqual(System.Drawing.Color.FromArgb(255, 0, 0, 255), dup.Member.Colour);
            Assert.AreEqual(13, dup.ID);
            Assert.AreEqual(1.56, dup.Member.MeshSize);
            Assert.AreEqual("ehbaba", dup.Member.Name);
            Assert.IsFalse(dup.Member.IsDummy);
            Assert.AreEqual(0.33, dup.Member.Offset.X1);
            Assert.AreEqual(1, dup.Member.Property);
            Assert.AreEqual(3, dup.Property.ID);
            Assert.AreEqual(AnalysisOrder.RIGID_DIAPHRAGM, dup.Member.Type2D);
            Assert.AreEqual(MemberType.GENERIC_2D, dup.Member.Type);

            // make some changes to original
            // create a list of corner points
            List <Point3d> pts2 = new List <Point3d>();

            pts2.Add(new Point3d(0, 0, 0));
            pts2.Add(new Point3d(5, 0, 0));
            pts2.Add(new Point3d(7, 6, 0));
            pts2.Add(new Point3d(2, 4, 0));
            pts2.Add(pts2[0]);                  // add initial point to close curve
            Polyline pol2 = new Polyline(pts2); // create edge-crv from pts
            // create planar brep from polyline
            Brep brep2 = Brep.CreatePlanarBreps(pol2.ToNurbsCurve(), 0.001)[0];

            // set new brep
            original.Brep = brep2;
            // changes to class members
            original.Colour           = System.Drawing.Color.Black;
            original.ID               = 7;
            original.Member.MeshSize  = 0;
            original.Member.Name      = "Persepolis";
            original.Member.IsDummy   = true;
            original.Member.Offset.X1 = 0.12;
            original.Member.Property  = 3;
            original.Property.ID      = 44;
            original.Member.Type2D    = AnalysisOrder.QUADRATIC;
            original.Member.Type      = MemberType.WALL;

            // check that orignal are not equal to duplicate
            Assert.AreNotEqual(original.Brep.Vertices[0].Location.X, dup.Topology[0].X);
            Assert.AreNotEqual(original.Brep.Vertices[0].Location.Y, dup.Topology[0].Y);
            Assert.AreNotEqual(original.Brep.Vertices[1].Location.X, dup.Topology[1].X);
            Assert.AreNotEqual(original.Brep.Vertices[1].Location.Y, dup.Topology[1].Y);
            Assert.AreNotEqual(original.Brep.Vertices[2].Location.X, dup.Topology[2].X);
            Assert.AreNotEqual(original.Brep.Vertices[2].Location.Y, dup.Topology[2].Y);
            Assert.AreNotEqual(original.Brep.Vertices[3].Location.X, dup.Topology[3].X);
            Assert.AreNotEqual(original.Brep.Vertices[3].Location.Y, dup.Topology[3].Y);
            Assert.AreNotEqual(original.Brep.Vertices[0].Location.X, dup.Topology[4].X);
            Assert.AreNotEqual(original.Brep.Vertices[0].Location.Y, dup.Topology[4].Y);

            // check that duplicate keeps it's member values
            Assert.AreEqual(System.Drawing.Color.FromArgb(255, 0, 0, 255), dup.Member.Colour);
            Assert.AreEqual(13, dup.ID);
            Assert.AreEqual(1.56, dup.Member.MeshSize);
            Assert.AreEqual("ehbaba", dup.Member.Name);
            Assert.IsFalse(dup.Member.IsDummy);
            Assert.AreEqual(0.33, dup.Member.Offset.X1);
            Assert.AreEqual(1, dup.Member.Property);
            Assert.AreEqual(3, dup.Property.ID);
            Assert.AreEqual(AnalysisOrder.RIGID_DIAPHRAGM, dup.Member.Type2D);
            Assert.AreEqual(MemberType.GENERIC_2D, dup.Member.Type);

            // check that changes are made to original
            Assert.AreEqual(System.Drawing.Color.FromArgb(255, 0, 0, 0), original.Member.Colour);
            Assert.AreEqual(7, original.ID);
            Assert.AreEqual(0, original.Member.MeshSize);
            Assert.AreEqual("Persepolis", original.Member.Name);
            Assert.IsTrue(original.Member.IsDummy);
            Assert.AreEqual(0.12, original.Member.Offset.X1);
            Assert.AreEqual(3, original.Member.Property);
            Assert.AreEqual(44, original.Property.ID);
            Assert.AreEqual(AnalysisOrder.QUADRATIC, original.Member.Type2D);
            Assert.AreEqual(MemberType.WALL, original.Member.Type);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember2d gsaMember2d = new GsaMember2d();

            if (DA.GetData(0, ref gsaMember2d))
            {
                GsaMember2d mem = gsaMember2d.Duplicate();

                // #### inputs ####

                // 1 brep
                Brep brep = mem.Brep; //existing brep

                GH_Brep ghbrep = new GH_Brep();
                if (DA.GetData(1, ref ghbrep))
                {
                    if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                    {
                        mem.Brep = brep;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

                if (DA.GetData(2, ref gh_typ))
                {
                    GsaProp2d prop2d = new GsaProp2d();
                    if (gh_typ.Value is GsaProp2d)
                    {
                        gh_typ.CastTo(ref prop2d);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            prop2d.ID = idd;
                        }
                    }
                    mem.Property = prop2d;
                }

                // 3 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(3, ref offset))
                {
                    mem.Member.Offset.Z = offset.Z;
                }

                // 4 inclusion points
                List <Point3d>  pts   = mem.InclusionPoints;
                List <GH_Point> ghpts = new List <GH_Point>();
                if (DA.GetDataList(4, ghpts))
                {
                    for (int i = 0; i < ghpts.Count; i++)
                    {
                        Point3d pt = new Point3d();
                        if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                        {
                            pts.Add(pt);
                        }
                    }
                }

                // 5 inclusion lines
                CurveList       crvlist = new CurveList(mem.InclusionLines);
                List <Curve>    crvs    = crvlist.ToList();
                List <GH_Curve> ghcrvs  = new List <GH_Curve>();
                if (DA.GetDataList(5, ghcrvs))
                {
                    for (int i = 0; i < ghcrvs.Count; i++)
                    {
                        Curve crv = null;
                        if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                        {
                            crvs.Add(crv);
                        }
                    }
                }

                GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts)
                {
                    ID       = mem.ID,
                    Member   = mem.Member,
                    Property = mem.Property
                };
                mem = tmpmem;

                // 6 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(6, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 7 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(7, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 8 type
                GH_Integer ghint = new GH_Integer();
                if (DA.GetData(8, ref ghint))
                {
                    if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type = Util.Gsa.GsaToModel.Member2dType(type);
                    }
                }

                // 9 element type / analysis order
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(9, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type2D = Util.Gsa.GsaToModel.Element2dType(type);
                    }
                }

                // 10 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(10, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 11 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(11, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 12 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(12, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 13 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(13, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 14 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(14, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####

                DA.SetData(0, new GsaMember2dGoo(mem));

                DA.SetData(1, mem.Brep);

                DA.SetData(2, mem.Property);

                GsaOffset gsaOffset = new GsaOffset
                {
                    Z = mem.Member.Offset.Z
                };
                DA.SetData(3, gsaOffset);

                DA.SetDataList(4, mem.InclusionPoints);
                DA.SetDataList(5, mem.InclusionLines);

                DA.SetData(6, mem.Member.MeshSize);
                //DA.SetData(7, mem.member.MeshWithOthers);

                DA.SetData(8, mem.Member.Type);
                DA.SetData(9, mem.Member.Type2D);

                DA.SetData(10, mem.ID);
                DA.SetData(11, mem.Member.Name);
                DA.SetData(12, mem.Member.Group);
                DA.SetData(13, mem.Member.Colour);

                DA.SetData(14, mem.Member.IsDummy);
            }
        }
Ejemplo n.º 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember2d gsaMember2d = new GsaMember2d();

            if (DA.GetData(0, ref gsaMember2d))
            {
                if (gsaMember2d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member2D input is null");
                }
                GsaMember2d mem = gsaMember2d.Duplicate();

                // #### inputs ####

                // 1 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(1, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 2/3/4 Brep, incl.pts and incl.lns
                Brep            brep    = mem.Brep; //existing brep
                GH_Brep         ghbrep  = new GH_Brep();
                CurveList       crvlist = new CurveList(mem.InclusionLines);
                List <Curve>    crvs    = crvlist.ToList();
                List <GH_Curve> ghcrvs  = new List <GH_Curve>();
                List <GH_Point> ghpts   = new List <GH_Point>();
                List <Point3d>  pts     = mem.InclusionPoints;

                if ((DA.GetData(2, ref ghbrep)) || (DA.GetDataList(3, ghpts)) || (DA.GetDataList(4, ghcrvs)))
                {
                    // 2 brep
                    if (DA.GetData(2, ref ghbrep))
                    {
                        if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                        {
                            mem.Brep = brep;
                        }
                    }

                    // 3 inclusion points
                    if (DA.GetDataList(3, ghpts))
                    {
                        for (int i = 0; i < ghpts.Count; i++)
                        {
                            Point3d pt = new Point3d();
                            if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                            {
                                pts.Add(pt);
                            }
                        }
                    }

                    // 4 inclusion lines
                    if (DA.GetDataList(4, ghcrvs))
                    {
                        for (int i = 0; i < ghcrvs.Count; i++)
                        {
                            Curve crv = null;
                            if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                            {
                                crvs.Add(crv);
                            }
                        }
                    }

                    GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts);
                    mem.PolyCurve            = tmpmem.PolyCurve;
                    mem.Topology             = tmpmem.Topology;
                    mem.TopologyType         = tmpmem.TopologyType;
                    mem.VoidTopology         = tmpmem.VoidTopology;
                    mem.VoidTopologyType     = tmpmem.VoidTopologyType;
                    mem.InclusionLines       = tmpmem.InclusionLines;
                    mem.IncLinesTopology     = tmpmem.IncLinesTopology;
                    mem.IncLinesTopologyType = tmpmem.IncLinesTopologyType;
                    mem.InclusionPoints      = tmpmem.InclusionPoints;

                    mem = tmpmem;
                }

                // 5 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

                if (DA.GetData(5, ref gh_typ))
                {
                    GsaProp2d prop2d = new GsaProp2d();
                    if (gh_typ.Value is GsaProp2dGoo)
                    {
                        gh_typ.CastTo(ref prop2d);
                        mem.Property        = prop2d;
                        mem.Member.Property = 0;
                    }
                    else
                    {
                        if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            mem.Member.Property = idd;
                            mem.Property        = null;
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                            return;
                        }
                    }
                }
        /// <summary>
        /// Method to import 1D and 2D Members from a GSA model.
        /// Will output a tuple of GhSA GsaMember1d and GsaMember2d.
        /// Filter members to import using memList input;
        /// "all" or empty string ("") will import all elements. Default is "all"
        /// "propGraft" bool = true; will put members in Grasshopper branch corrosponding to its property
        /// </summary>
        /// <param name="model"></param>
        /// <param name="memList"></param>
        /// <param name="propGraft"></param>
        /// <returns></returns>
        public static Tuple <DataTree <GsaMember1dGoo>, DataTree <GsaMember2dGoo> > GsaGetMemb(Model model, string memList = "all", bool propGraft = true)
        {
            // Create dictionaries to read list of elements and nodes:
            IReadOnlyDictionary <int, Member> mDict;

            mDict = model.Members(memList);
            IReadOnlyDictionary <int, Node> nDict;

            nDict = model.Nodes("all");
            IReadOnlyDictionary <int, Section> sDict;

            sDict = model.Sections();
            IReadOnlyDictionary <int, Prop2D> pDict;

            pDict = model.Prop2Ds();

            // Create lists for Rhino lines and meshes
            DataTree <GsaMember1dGoo> mem1ds = new DataTree <GsaMember1dGoo>();
            DataTree <GsaMember2dGoo> mem2ds = new DataTree <GsaMember2dGoo>();

            if (!propGraft)
            {
                mem1ds.EnsurePath(0);
                mem2ds.EnsurePath(0);
                int max = mDict.Count;
                if (max > 0)
                {
                    for (int i = 0; i < mDict.Keys.ElementAt(max - 1); i++)
                    {
                        mem1ds.Branches[0].Add(null);
                        mem2ds.Branches[0].Add(null);
                    }
                }
            }

            // Loop through all members in Member dictionary
            foreach (var key in mDict.Keys)
            {
                if (mDict.TryGetValue(key, out Member mem))
                {
                    int prop = 0;
                    if (propGraft)
                    {
                        prop = mem.Property - 1;
                    }

                    // Build topology lists
                    string toporg = mem.Topology; //original topology list

                    Tuple <Tuple <List <int>, List <string> >, Tuple <List <List <int> >, List <List <string> > >,
                           Tuple <List <List <int> >, List <List <string> > >, List <int> > topologyTuple = Topology_detangler(toporg);
                    Tuple <List <int>, List <string> > topoTuple = topologyTuple.Item1;
                    Tuple <List <List <int> >, List <List <string> > > voidTuple = topologyTuple.Item2;
                    Tuple <List <List <int> >, List <List <string> > > lineTuple = topologyTuple.Item3;

                    List <int>    topo_int = topoTuple.Item1;
                    List <string> topoType = topoTuple.Item2; //list of polyline curve type (arch or line) for member1d/2d

                    List <List <int> >    void_topo_int = voidTuple.Item1;
                    List <List <string> > void_topoType = voidTuple.Item2; //list of polyline curve type (arch or line) for void /member2d

                    List <List <int> >    incLines_topo_int  = lineTuple.Item1;
                    List <List <string> > inclLines_topoType = lineTuple.Item2; //list of polyline curve type (arch or line) for inclusion /member2d

                    List <int> inclpts = topologyTuple.Item4;

                    // replace topology integers with actual points
                    List <Point3d> topopts = new List <Point3d>(); // list of topology points for visualisation /member1d/member2d
                    for (int i = 0; i < topo_int.Count; i++)
                    {
                        if (nDict.TryGetValue(topo_int[i], out Node node))
                        {
                            var p = node.Position;
                            topopts.Add(new Point3d(p.X, p.Y, p.Z));
                        }
                        node.Dispose();
                    }

                    //list of lists of void points /member2d
                    List <List <Point3d> > void_topo = new List <List <Point3d> >();
                    for (int i = 0; i < void_topo_int.Count; i++)
                    {
                        void_topo.Add(new List <Point3d>());
                        for (int j = 0; j < void_topo_int[i].Count; j++)
                        {
                            if (nDict.TryGetValue(void_topo_int[i][j], out Node node))
                            {
                                var p = node.Position;
                                void_topo[i].Add(new Point3d(p.X, p.Y, p.Z));
                            }
                            node.Dispose();
                        }
                    }

                    //list of lists of line inclusion topology points /member2d
                    List <List <Point3d> > incLines_topo = new List <List <Point3d> >();
                    for (int i = 0; i < incLines_topo_int.Count; i++)
                    {
                        incLines_topo.Add(new List <Point3d>());
                        for (int j = 0; j < incLines_topo_int[i].Count; j++)
                        {
                            if (nDict.TryGetValue(incLines_topo_int[i][j], out Node node))
                            {
                                var p = node.Position;
                                incLines_topo[i].Add(new Point3d(p.X, p.Y, p.Z));
                            }
                            node.Dispose();
                        }
                    }

                    //list of points for inclusion /member2d
                    List <Point3d> incl_pts = new List <Point3d>();
                    for (int i = 0; i < inclpts.Count; i++)
                    {
                        if (nDict.TryGetValue(inclpts[i], out Node node))
                        {
                            var p = node.Position;
                            incl_pts.Add(new Point3d(p.X, p.Y, p.Z));
                        }
                        node.Dispose();
                    }

                    if (mem.Type == MemberType.GENERIC_1D | mem.Type == MemberType.BEAM | mem.Type == MemberType.CANTILEVER |
                        mem.Type == MemberType.COLUMN | mem.Type == MemberType.COMPOS | mem.Type == MemberType.PILE)
                    {
                        GsaMember1d mem1d = new GsaMember1d(topopts, topoType)
                        {
                            ID     = key,
                            Member = mem
                        };
                        GsaSection section = new GsaSection
                        {
                            ID = mem.Property
                        };
                        if (sDict.TryGetValue(section.ID, out Section tempSection))
                        {
                            section.Section = tempSection;
                        }
                        mem1d.Section = section;
                        mem1ds.EnsurePath(prop);
                        GH_Path path = new GH_Path(prop);
                        if (propGraft)
                        {
                            mem1ds.Add(new GsaMember1dGoo(mem1d.Duplicate()), path);
                        }
                        else
                        {
                            mem1ds[path, key - 1] = new GsaMember1dGoo(mem1d.Duplicate());
                        }
                    }
                    else
                    {
                        GsaMember2d mem2d = new GsaMember2d(topopts, topoType, void_topo, void_topoType, incLines_topo, inclLines_topoType, incl_pts)
                        {
                            Member = mem,
                            ID     = key
                        };
                        GsaProp2d prop2d = new GsaProp2d
                        {
                            ID = mem.Property
                        };
                        if (pDict.TryGetValue(prop2d.ID, out Prop2D tempProp))
                        {
                            prop2d.Prop2d = tempProp;
                        }
                        mem2d.Property = prop2d;
                        mem2ds.EnsurePath(prop);
                        GH_Path path = new GH_Path(prop);
                        if (propGraft)
                        {
                            mem2ds.Add(new GsaMember2dGoo(mem2d.Duplicate()), path);
                        }
                        else
                        {
                            mem2ds[path, key - 1] = new GsaMember2dGoo(mem2d.Duplicate());
                        }
                    }

                    topopts.Clear();
                    topoType.Clear();
                    void_topo.Clear();
                    void_topoType.Clear();
                    incLines_topo.Clear();
                    inclLines_topoType.Clear();
                    incl_pts.Clear();
                }
            }

            return(new Tuple <DataTree <GsaMember1dGoo>, DataTree <GsaMember2dGoo> >(mem1ds, mem2ds));
        }