Example #1
0
        public static void ConvertElement1D(GsaElement1d element1d,
                                            ref Dictionary <int, Element> existingElements, ref int elementidcounter,
                                            ref Dictionary <int, Node> existingNodes, ref int nodeidcounter,
                                            ref Dictionary <int, Section> existingSections, ref Dictionary <Guid, int> sections_guid)
        {
            LineCurve line       = element1d.Line;
            Element   apiElement = element1d.Element;

            // update topology list to fit model nodes
            List <int> topo = new List <int>();
            //Start node
            int id = Nodes.GetExistingNodeID(existingNodes, line.PointAtStart);

            if (id > 0)
            {
                topo.Add(id);
            }
            else
            {
                existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(line.PointAtStart));
                topo.Add(nodeidcounter);
                nodeidcounter++;
            }

            //End node
            id = Nodes.GetExistingNodeID(existingNodes, line.PointAtEnd);
            if (id > 0)
            {
                topo.Add(id);
            }
            else
            {
                existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(line.PointAtEnd));
                topo.Add(nodeidcounter);
                nodeidcounter++;
            }
            // update topology in Element
            apiElement.Topology = new ReadOnlyCollection <int>(topo.ToList());

            // section
            if (apiElement.Property == 0)
            {
                apiElement.Property = Sections.ConvertSection(element1d.Section, ref existingSections, ref sections_guid);
            }

            // set apielement in dictionary
            if (element1d.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list
            {
                existingElements[element1d.ID] = apiElement;
            }
            else
            {
                existingElements.Add(elementidcounter, apiElement);
                elementidcounter++;
            }
        }
Example #2
0
        public void TestCreateGsaElem1dGetReleases()
        {
            // create new line
            Line ln = new Line(new Point3d(1, 4, 6), new Point3d(-2, 3, -5));

            // create element
            GsaElement1d elem = new GsaElement1d(new LineCurve(ln));

            GsaBool6 rel1 = elem.ReleaseStart;

            Assert.IsFalse(rel1.X);
            Assert.IsFalse(rel1.Y);
            Assert.IsFalse(rel1.Z);
            Assert.IsFalse(rel1.XX);
            Assert.IsFalse(rel1.YY);
            Assert.IsFalse(rel1.ZZ);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Line ghln = new GH_Line();

            if (DA.GetData(0, ref ghln))
            {
                if (ghln == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Line input is null");
                }
                Line ln = new Line();
                if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both))
                {
                    GsaElement1d elem = new GsaElement1d(new LineCurve(ln));

                    // 1 section
                    GH_ObjectWrapper gh_typ  = new GH_ObjectWrapper();
                    GsaSection       section = new GsaSection();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaSectionGoo)
                        {
                            gh_typ.CastTo(ref section);
                            elem.Section = section;
                        }

                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                elem.Element.Property = idd;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer");
                                return;
                            }
                        }
                    }

                    DA.SetData(0, new GsaElement1dGoo(elem));
                }
Example #4
0
        public void TestCreateGsaElem1dFromLn()
        {
            // create new line
            Line ln = new Line(new Point3d(1, 4, 6), new Point3d(-2, 3, -5));

            // create element
            GsaElement1d elem = new GsaElement1d(new LineCurve(ln));

            // set some element class members
            elem.ID                       = 66;
            elem.Section                  = new GsaSection();
            elem.Section.ID               = 2;
            elem.Colour                   = System.Drawing.Color.Yellow;
            elem.Element.Group            = 4;
            elem.Element.IsDummy          = true;
            elem.Element.Name             = "EltonJohn";
            elem.Element.Offset.Y         = 14.3;
            elem.Element.OrientationAngle = 90;
            elem.Element.OrientationNode  = 666;
            elem.Element.Property         = 3;

            // check the line end points are correct
            Assert.AreEqual(1, elem.Line.PointAtStart.X);
            Assert.AreEqual(4, elem.Line.PointAtStart.Y);
            Assert.AreEqual(6, elem.Line.PointAtStart.Z);
            Assert.AreEqual(-2, elem.Line.PointAtEnd.X);
            Assert.AreEqual(3, elem.Line.PointAtEnd.Y);
            Assert.AreEqual(-5, elem.Line.PointAtEnd.Z);

            // check other members are valid
            Assert.AreEqual(66, elem.ID);
            Assert.AreEqual(2, elem.Section.ID);
            Assert.AreEqual(System.Drawing.Color.FromArgb(255, 255, 255, 0), elem.Element.Colour);
            Assert.AreEqual(4, elem.Element.Group);
            Assert.IsTrue(elem.Element.IsDummy);
            Assert.AreEqual("EltonJohn", elem.Element.Name);
            Assert.AreEqual(14.3, elem.Element.Offset.Y);
            Assert.AreEqual(90, elem.Element.OrientationAngle);
            Assert.AreEqual(666, elem.Element.OrientationNode);
            Assert.AreEqual(3, elem.Element.Property);
        }
Example #5
0
        public static void ConvertElement1D(List <GsaElement1d> element1ds,
                                            ref Dictionary <int, Element> existingElements, ref int elementidcounter,
                                            ref Dictionary <int, Node> existingNodes,
                                            ref Dictionary <int, Section> existingSections, ref Dictionary <Guid, int> sections_guid,
                                            GrasshopperAsyncComponent.WorkerInstance workerInstance = null,
                                            Action <string, double> ReportProgress = null)
        {
            int nodeidcounter = (existingNodes.Count > 0) ? existingNodes.Keys.Max() + 1 : 1;

            // Elem1ds
            if (element1ds != null)
            {
                for (int i = 0; i < element1ds.Count; i++)
                {
                    if (workerInstance != null)
                    {
                        if (workerInstance.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        ReportProgress("Elem1D ", (double)i / (element1ds.Count - 1));
                    }


                    if (element1ds[i] != null)
                    {
                        GsaElement1d element1d = element1ds[i];

                        // Add/set element
                        ConvertElement1D(element1d, ref existingElements, ref elementidcounter,
                                         ref existingNodes, ref nodeidcounter, ref existingSections, ref sections_guid);
                    }
                }
            }
            if (workerInstance != null)
            {
                ReportProgress("Elem1D assembled", -2);
            }
        }
Example #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Line ghln = new GH_Line();

            if (DA.GetData(0, ref ghln))
            {
                Line ln = new Line();
                if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both))
                {
                    GsaElement1d elem = new GsaElement1d(new LineCurve(ln));

                    // 1 section
                    GH_ObjectWrapper gh_typ  = new GH_ObjectWrapper();
                    GsaSection       section = new GsaSection();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaSection)
                        {
                            gh_typ.CastTo(ref section);
                        }
                        else if (gh_typ.Value is GH_Number)
                        {
                            if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                section.ID = idd;
                            }
                        }
                    }
                    else
                    {
                        section.ID = 1;
                    }
                    elem.Section = section;

                    DA.SetData(0, new GsaElement1dGoo(elem));
                }
            }
        }
Example #7
0
        public void TestDuplicateElem1d()
        {
            // create new line
            Line ln = new Line(new Point3d(2, -1, 0), new Point3d(2, -1, 4));

            // create element
            GsaElement1d orig = new GsaElement1d(new LineCurve(ln));

            // set some element class members
            orig.ID                       = 3;
            orig.Section                  = new GsaSection();
            orig.Section.ID               = 7;
            orig.Colour                   = System.Drawing.Color.Aqua;
            orig.Element.Group            = 1;
            orig.Element.IsDummy          = false;
            orig.Element.Name             = "Tilman";
            orig.Element.Offset.Y         = -0.9991;
            orig.Element.OrientationAngle = -0.14;
            orig.Element.OrientationNode  = 2;
            orig.Element.Property         = 1;

            // duplicate original
            GsaElement1d dup = orig.Duplicate();

            // make some changes to original
            orig.Line                     = new LineCurve(new Line(new Point3d(1, 1, -4), new Point3d(1, 1, 0)));
            orig.ID                       = 5;
            orig.Section.ID               = 9;
            orig.Colour                   = System.Drawing.Color.Red;
            orig.Element.Group            = 2;
            orig.Element.IsDummy          = true;
            orig.Element.Name             = "Hugh";
            orig.Element.Offset.Y         = -0.99991;
            orig.Element.OrientationAngle = 0;
            orig.Element.OrientationNode  = 3;
            orig.Element.Property         = 2;

            // check that values in duplicate are not changed
            Assert.AreEqual(2, dup.Line.PointAtStart.X);
            Assert.AreEqual(-1, dup.Line.PointAtStart.Y);
            Assert.AreEqual(0, dup.Line.PointAtStart.Z);
            Assert.AreEqual(2, dup.Line.PointAtEnd.X);
            Assert.AreEqual(-1, dup.Line.PointAtEnd.Y);
            Assert.AreEqual(4, dup.Line.PointAtEnd.Z);
            Assert.AreEqual(3, dup.ID);
            Assert.AreEqual(7, dup.Section.ID);
            Assert.AreEqual(System.Drawing.Color.FromArgb(255, 0, 255, 255), dup.Element.Colour);
            Assert.AreEqual(1, dup.Element.Group);
            Assert.IsFalse(dup.Element.IsDummy);
            Assert.AreEqual("Tilman", dup.Element.Name);
            Assert.AreEqual(-0.9991, dup.Element.Offset.Y);
            Assert.AreEqual(-0.14, dup.Element.OrientationAngle);
            Assert.AreEqual(2, dup.Element.OrientationNode);
            Assert.AreEqual(1, dup.Element.Property);

            // check that original has changed values
            Assert.AreEqual(1, orig.Line.PointAtStart.X);
            Assert.AreEqual(1, orig.Line.PointAtStart.Y);
            Assert.AreEqual(-4, orig.Line.PointAtStart.Z);
            Assert.AreEqual(1, orig.Line.PointAtEnd.X);
            Assert.AreEqual(1, orig.Line.PointAtEnd.Y);
            Assert.AreEqual(0, orig.Line.PointAtEnd.Z);
            Assert.AreEqual(5, orig.ID);
            Assert.AreEqual(9, orig.Section.ID);
            Assert.AreEqual(System.Drawing.Color.FromArgb(255, 255, 0, 0), orig.Element.Colour);
            Assert.AreEqual(2, orig.Element.Group);
            Assert.IsTrue(orig.Element.IsDummy);
            Assert.AreEqual("Hugh", orig.Element.Name);
            Assert.AreEqual(-0.99991, orig.Element.Offset.Y);
            Assert.AreEqual(0, orig.Element.OrientationAngle);
            Assert.AreEqual(3, orig.Element.OrientationNode);
            Assert.AreEqual(2, orig.Element.Property);
        }
Example #8
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
        }
            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;
                }
            }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaElement1d gsaElement1d = new GsaElement1d();

            if (DA.GetData(0, ref gsaElement1d))
            {
                GsaElement1d elem = gsaElement1d.Duplicate();

                // #### inputs ####
                // 1 curve
                GH_Line ghcrv = new GH_Line();
                if (DA.GetData(1, ref ghcrv))
                {
                    Line crv = new Line();
                    if (GH_Convert.ToLine(ghcrv, ref crv, GH_Conversion.Both))
                    {
                        LineCurve    ln      = new LineCurve(crv);
                        GsaElement1d tmpelem = new GsaElement1d(ln)
                        {
                            ID           = elem.ID,
                            Element      = elem.Element,
                            ReleaseEnd   = elem.ReleaseEnd,
                            ReleaseStart = elem.ReleaseStart
                        };
                        elem = tmpelem;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(2, ref gh_typ))
                {
                    GsaSection section = new GsaSection();
                    if (gh_typ.Value is GsaSection)
                    {
                        gh_typ.CastTo(ref section);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            section.ID = idd;
                        }
                    }
                    elem.Section = section;
                }

                // 3 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(3, ref offset))
                {
                    elem.Element.Offset.X1 = offset.X1;
                    elem.Element.Offset.X2 = offset.X2;
                    elem.Element.Offset.Y  = offset.Y;
                    elem.Element.Offset.Z  = offset.Z;
                }

                // 4 start release
                GsaBool6 start = new GsaBool6();
                if (DA.GetData(4, ref start))
                {
                    elem.ReleaseStart = start; //should handle setting the release in elem.Element.SetRelease
                }

                // 5 end release
                GsaBool6 end = new GsaBool6();
                if (DA.GetData(5, ref end))
                {
                    elem.ReleaseEnd = end; //should handle setting the release in elem.Element.SetRelease
                }

                // 6 orientation angle
                GH_Number ghangle = new GH_Number();
                if (DA.GetData(6, ref ghangle))
                {
                    if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both))
                    {
                        elem.Element.OrientationAngle = angle;
                    }
                }

                // 7 orientation node
                GH_Integer ghori = new GH_Integer();
                if (DA.GetData(7, ref ghori))
                {
                    if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both))
                    {
                        elem.Element.OrientationNode = orient;
                    }
                }

                // 8 type
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(8, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        elem.Element.Type = Util.Gsa.GsaToModel.Element1dType(type);
                    }
                }

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

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

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

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

                // #### outputs ####
                DA.SetData(0, new GsaElement1dGoo(elem));

                DA.SetData(1, elem.Line);
                DA.SetData(2, elem.Section);

                GsaOffset offset1 = new GsaOffset
                {
                    X1 = elem.Element.Offset.X1,
                    X2 = elem.Element.Offset.X2,
                    Y  = elem.Element.Offset.Y,
                    Z  = elem.Element.Offset.Z
                };
                DA.SetData(3, offset1);

                DA.SetData(4, elem.ReleaseStart);
                DA.SetData(5, elem.ReleaseEnd);

                DA.SetData(6, elem.Element.OrientationAngle);
                DA.SetData(7, elem.Element.OrientationNode);

                DA.SetData(8, elem.Element.Type);

                DA.SetData(9, elem.ID);
                DA.SetData(10, elem.Element.Name);
                DA.SetData(11, elem.Element.Group);
                DA.SetData(12, elem.Element.Colour);

                try { DA.SetData(13, elem.Element.ParentMember.Member); } catch (Exception) { }
                //DA.SetData(16, gsaElement1d.Element.IsDummy);
            }
        }
Example #11
0
        public void GetGeometryComponentTest()
        {
            Assert.IsTrue(Rhino.RhinoApp.IsLicenseValidated, "Rhino must be licensed to run this test");

            // ensure model has been opened:
            if (TestModel == null)
            {
                OpenComponentTest();
            }

            // create the component
            var comp = new GhSA.Components.GetGeometry();

            comp.CreateAttributes();

            // input parameter
            GsaModelGoo modelGoo = new GsaModelGoo(TestModel);

            Component.SetInput(comp, modelGoo);

            // Get output from component
            GsaNodeGoo output00 = (GsaNodeGoo)Component.GetOutput(comp, 0, 0, 0);
            GsaNodeGoo output01 = (GsaNodeGoo)Component.GetOutput(comp, 0, 0, 1);

            GsaElement1dGoo output1 = (GsaElement1dGoo)Component.GetOutput(comp, 1);

            GsaMember1dGoo output3 = (GsaMember1dGoo)Component.GetOutput(comp, 4);

            //pManager.AddGenericParameter("Nodes", "No", "Nodes from GSA Model", GH_ParamAccess.list);
            //pManager.AddGenericParameter("1D Elements", "E1D", "1D Elements (Analysis Layer) from GSA Model", GH_ParamAccess.list);
            //pManager.AddGenericParameter("2D Elements", "E2D", "2D Elements (Analysis Layer) from GSA Model", GH_ParamAccess.list);
            //pManager.AddGenericParameter("3D Elements", "E3D", "3D Elements (Analysis Layer) from GSA Model", GH_ParamAccess.list);
            //pManager.AddGenericParameter("1D Members", "M1D", "1D Members (Design Layer) from GSA Model", GH_ParamAccess.list);
            //pManager.AddGenericParameter("2D Members", "M2D", "2D Members (Design Layer) from GSA Model", GH_ParamAccess.list);
            //pManager.AddGenericParameter("3D Members", "M3D", "3D Members (Design Layer) from GSA Model", GH_ParamAccess.list);

            // cast from -goo to Gsa-GH data type
            GsaNode node1 = new GsaNode();
            GsaNode node2 = new GsaNode();

            output00.CastTo(ref node1);
            output01.CastTo(ref node2);

            GsaElement1d elem = new GsaElement1d();

            output1.CastTo(ref elem);
            GsaMember1d mem = new GsaMember1d();

            output3.CastTo(ref mem);

            // test nodes are correct
            Assert.AreEqual(1, node1.ID);
            Assert.AreEqual(0, node1.Point.X, 1E-9);
            Assert.AreEqual(0, node1.Point.Y, 1E-9);
            Assert.AreEqual(0, node1.Point.Z, 1E-9);

            Assert.AreEqual(2, node2.ID);
            Assert.AreEqual(7.5, node2.Point.X, 1E-9);
            Assert.AreEqual(0, node2.Point.Y, 1E-9);
            Assert.AreEqual(0, node2.Point.Z, 1E-9);

            Assert.IsTrue(node1.Node.Restraint.X);
            Assert.IsTrue(node1.Node.Restraint.Y);
            Assert.IsTrue(node1.Node.Restraint.Z);
            Assert.IsTrue(node1.Node.Restraint.XX);
            Assert.IsFalse(node1.Node.Restraint.YY);
            Assert.IsFalse(node1.Node.Restraint.ZZ);

            Assert.IsFalse(node2.Node.Restraint.X);
            Assert.IsTrue(node2.Node.Restraint.Y);
            Assert.IsTrue(node2.Node.Restraint.Z);
            Assert.IsFalse(node2.Node.Restraint.XX);
            Assert.IsFalse(node2.Node.Restraint.YY);
            Assert.IsFalse(node2.Node.Restraint.ZZ);

            // test element and member
            Assert.AreEqual(1, elem.ID);
            Assert.AreEqual(0, elem.Line.PointAtStart.X, 1E-9);
            Assert.AreEqual(0, elem.Line.PointAtStart.Y, 1E-9);
            Assert.AreEqual(0, elem.Line.PointAtStart.Z, 1E-9);
            Assert.AreEqual(7.5, elem.Line.PointAtEnd.X, 1E-9);
            Assert.AreEqual(0, elem.Line.PointAtEnd.Y, 1E-9);
            Assert.AreEqual(0, elem.Line.PointAtEnd.Z, 1E-9);
            //Assert.AreEqual("CAT UB UB457x191x89", elem.Section.Section.Profile.Substring(0, 19));

            Assert.AreEqual(1, mem.ID);
            Assert.AreEqual(0, mem.PolyCurve.PointAtStart.X, 1E-9);
            Assert.AreEqual(0, mem.PolyCurve.PointAtStart.Y, 1E-9);
            Assert.AreEqual(0, mem.PolyCurve.PointAtStart.Z, 1E-9);
            Assert.AreEqual(7.5, mem.PolyCurve.PointAtEnd.X, 1E-9);
            Assert.AreEqual(0, mem.PolyCurve.PointAtEnd.Y, 1E-9);
            Assert.AreEqual(0, mem.PolyCurve.PointAtEnd.Z, 1E-9);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaElement1d gsaElement1d = new GsaElement1d();

            if (DA.GetData(0, ref gsaElement1d))
            {
                if (gsaElement1d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element1D input is null");
                }
                GsaElement1d elem = gsaElement1d.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))
                    {
                        elem.ID = id;
                    }
                }

                // 2 curve
                GH_Line ghcrv = new GH_Line();
                if (DA.GetData(2, ref ghcrv))
                {
                    Line crv = new Line();
                    if (GH_Convert.ToLine(ghcrv, ref crv, GH_Conversion.Both))
                    {
                        LineCurve    ln      = new LineCurve(crv);
                        GsaElement1d tmpelem = new GsaElement1d(ln)
                        {
                            ID           = elem.ID,
                            Element      = elem.Element,
                            ReleaseEnd   = elem.ReleaseEnd,
                            ReleaseStart = elem.ReleaseStart
                        };
                        elem = tmpelem;
                    }
                }

                // 3 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(3, ref gh_typ))
                {
                    GsaSection section = new GsaSection();
                    if (gh_typ.Value is GsaSectionGoo)
                    {
                        gh_typ.CastTo(ref section);
                        elem.Section          = section;
                        elem.Element.Property = 0;
                    }
                    else
                    {
                        if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            elem.Element.Property = idd;
                            elem.Section          = null;
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer");
                            return;
                        }
                    }
                }
        /// <summary>
        /// Method to import 1D and 2D Elements from a GSA model.
        /// Will output a tuple of GhSA GsaElement1d and GsaElement2d.
        /// Filter elements to import using elemList input;
        /// "all" or empty string ("") will import all elements. Default is "all"
        /// "Join" bool = true; will try to join 2D element mesh faces into a joined meshes.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="elemList"></param>
        /// <param name="join"></param>
        /// <returns></returns>
        public static Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> > GsaGetElem(Model model, string elemList = "all", bool join = true)
        {
            // Create dictionaries to read list of elements and nodes:
            IReadOnlyDictionary <int, Element> eDict;

            eDict = model.Elements(elemList);
            IReadOnlyDictionary <int, Node> nDict;

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

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

            pDict = model.Prop2Ds();

            GsaElement2d elem2d = new GsaElement2d();

            // Create lists for Rhino lines and meshes
            DataTree <GsaElement1dGoo> elem1ds  = new DataTree <GsaElement1dGoo>();
            DataTree <GsaElement2dGoo> elem2ds  = new DataTree <GsaElement2dGoo>();
            DataTree <Element>         elements = new DataTree <Element>();
            DataTree <Mesh>            meshes   = new DataTree <Mesh>();
            List <Point3d>             pts      = new List <Point3d>();

            GH_Path path = new GH_Path();

            if (!join)
            {
                elem1ds.EnsurePath(0);
                elem2ds.EnsurePath(0);
                int max = eDict.Count;
                if (max > 0)
                {
                    //elem1ds.Branches[0].. = new List<GsaElement1dGoo>(max);
                    //elem2ds.Branches[0] = new List<GsaElement2dGoo>(max);
                    //for (int i = 0; i < eDict.Keys.ElementAt(max - 1); i++)
                    //{
                    //    elem1ds.Branches[0].Add(null);
                    //    elem2ds.Branches[0].Add(null);
                    //}
                }
            }

            // Loop through all nodes in Node dictionary and add points to Rhino point list
            foreach (var key in eDict.Keys)
            {
                if (eDict.TryGetValue(key, out Element elem))
                {
                    List <int> topo = elem.Topology.ToList();
                    int        prop = 0;
                    if (join)
                    {
                        prop = elem.Property - 1; // actually branch not property
                    }
                    // Beams (1D elements):
                    if (topo.Count == 2)
                    {
                        for (int i = 0; i <= 1; i++)
                        {
                            if (nDict.TryGetValue(topo[i], out Node node))
                            {
                                {
                                    var p = node.Position;
                                    pts.Add(new Point3d(p.X, p.Y, p.Z));
                                }
                                node.Dispose();
                            }
                        }
                        Line         line   = new Line(pts[0], pts[1]);
                        LineCurve    ln     = new LineCurve(line);
                        GsaElement1d elem1d = new GsaElement1d(ln)
                        {
                            Element = elem
                        };
                        elem1d.ReleaseStart = new GsaBool6()
                        {
                            X  = elem.Release(0).X,
                            Y  = elem.Release(0).Y,
                            Z  = elem.Release(0).Z,
                            XX = elem.Release(0).XX,
                            YY = elem.Release(0).YY,
                            ZZ = elem.Release(0).ZZ
                        };

                        elem1d.ReleaseEnd = new GsaBool6()
                        {
                            X  = elem.Release(1).X,
                            Y  = elem.Release(1).Y,
                            Z  = elem.Release(1).Z,
                            XX = elem.Release(1).XX,
                            YY = elem.Release(1).YY,
                            ZZ = elem.Release(1).ZZ
                        };

                        GsaSection section = new GsaSection
                        {
                            ID = elem.Property
                        };
                        Section tempSection = new Section();
                        if (sDict.TryGetValue(section.ID, out tempSection))
                        {
                            section.Section = tempSection;
                        }
                        elem1d.Section = section;
                        elem1d.ID      = key;

                        pts.Clear();
                        elem1ds.EnsurePath(prop);
                        path = new GH_Path(prop);
                        if (join)
                        {
                            elem1ds.Add(new GsaElement1dGoo(elem1d), path);
                        }
                        else
                        {
                            elem1ds.Insert(new GsaElement1dGoo(elem1d), path, key - 1);
                        }
                        //elem1ds[path, key - 1] = new GsaElement1dGoo(elem1d.Duplicate());
                    }

                    // Shells (2D elements)
                    if (topo.Count > 2) // & topo.Count < 5)
                    {
                        Mesh tempMesh = new Mesh();
                        // Get verticies:
                        for (int i = 0; i < topo.Count; i++)
                        {
                            if (nDict.TryGetValue(topo[i], out Node node))
                            {
                                {
                                    var p = node.Position;
                                    tempMesh.Vertices.Add(new Point3d(p.X, p.Y, p.Z));
                                }
                                node.Dispose();
                            }
                        }

                        // Create mesh face (Tri- or Quad):
                        if (topo.Count == 3)
                        {
                            tempMesh.Faces.AddFace(0, 1, 2);
                        }
                        if (topo.Count == 4)
                        {
                            tempMesh.Faces.AddFace(0, 1, 2, 3);
                        }
                        else
                        {
                            //it must be a TRI6 or a QUAD8
                            List <Point3f> tempPts = tempMesh.Vertices.ToList();
                            double         x = 0; double y = 0; double z = 0;
                            for (int i = 0; i < tempPts.Count; i++)
                            {
                                x += tempPts[i].X; y += tempPts[i].Y; z += tempPts[i].Z;
                            }
                            x /= tempPts.Count; y /= tempPts.Count; z /= tempPts.Count;
                            tempMesh.Vertices.Add(new Point3d(x, y, z));

                            if (topo.Count == 6)
                            {
                                tempMesh.Faces.AddFace(0, 3, 6);
                                tempMesh.Faces.AddFace(3, 1, 6);
                                tempMesh.Faces.AddFace(1, 4, 6);
                                tempMesh.Faces.AddFace(4, 2, 6);
                                tempMesh.Faces.AddFace(2, 5, 6);
                                tempMesh.Faces.AddFace(5, 0, 6);
                            }

                            if (topo.Count == 8)
                            {
                                tempMesh.Faces.AddFace(0, 4, 8, 7);
                                tempMesh.Faces.AddFace(1, 5, 8, 4);
                                tempMesh.Faces.AddFace(2, 6, 8, 5);
                                tempMesh.Faces.AddFace(3, 7, 8, 6);
                            }
                        }
                        List <int> ids = new List <int>
                        {
                            key
                        };

                        elem2d.ID = ids;

                        List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                        GsaProp2d        prop2d  = new GsaProp2d
                        {
                            ID = elem.Property
                        };
                        Prop2D tempProp = new Prop2D();
                        if (pDict.TryGetValue(prop2d.ID, out tempProp))
                        {
                            prop2d.Prop2d = tempProp;
                        }
                        prop2Ds.Add(prop2d);
                        elem2d.Properties = prop2Ds;


                        if (join)
                        {
                            meshes.EnsurePath(prop);
                            elements.EnsurePath(prop);
                            path = new GH_Path(prop);

                            meshes.Add(tempMesh.DuplicateMesh(), path);
                            elements.Add(elem, path);
                        }
                        else
                        {
                            elem2d = new GsaElement2d(tempMesh);
                            List <Element> elemProps = new List <Element>
                            {
                                elem
                            };
                            elem2d.Elements   = elemProps;
                            elem2d.Properties = prop2Ds;
                            elem2d.ID         = ids;
                            elem2ds.Insert(new GsaElement2dGoo(elem2d), path, key - 1);
                            //elem2ds[path, key - 1] = new GsaElement2dGoo(elem2d.Duplicate());
                            //elem2ds.Add(new GsaElement2dGoo(elem2d.Duplicate()));
                        }

                        tempMesh.Dispose();
                        elem.Dispose();
                    }
                }
            }

            if (join)
            {
                foreach (GH_Path ipath in meshes.Paths)
                {
                    //##### Join meshes #####

                    //List of meshes in each branch
                    List <Mesh> mList = meshes.Branch(ipath);

                    //new temp mesh
                    Mesh m = new Mesh();
                    //Append list of meshes (faster than appending each mesh one by one)
                    m.Append(mList);

                    //split mesh into connected pieces
                    Mesh[] meshy = m.SplitDisjointPieces();

                    //clear whatever is in the current branch (the list in mList)
                    meshes.Branch(ipath).Clear();
                    //rewrite new joined and split meshes to new list in same path:
                    for (int j = 0; j < meshy.Count(); j++)
                    {
                        meshes.Add(meshy[j], ipath);
                    }
                }
                foreach (GH_Path ipath in meshes.Paths)
                {
                    List <Mesh> mList = meshes.Branch(ipath);
                    foreach (Mesh mesh in mList)
                    {
                        elem2d = new GsaElement2d(mesh);
                        List <Element> elemProps = new List <Element>();
                        for (int i = 0; i < mesh.Faces.Count(); i++)
                        {
                            elemProps.Add(elements[ipath, 0]);
                        }
                        elem2d.Elements = elemProps;
                        List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                        GsaProp2d        prop2d  = new GsaProp2d
                        {
                            ID = ipath.Indices[0] + 1
                        };
                        Prop2D tempProp = new Prop2D();
                        if (pDict.TryGetValue(prop2d.ID, out tempProp))
                        {
                            prop2d.Prop2d = tempProp;
                        }
                        prop2Ds.Add(prop2d);
                        elem2d.Properties = prop2Ds;

                        elem2ds.Add(new GsaElement2dGoo(elem2d));
                    }
                }
            }

            return(new Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> >(elem1ds, elem2ds));
        }