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); }
/// <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)); }