public static List <Member> ConvertMember2D(List <GsaMember2d> member2ds, ref List <Node> nodes, ref int nodeidcounter) { // ensure node id is at least 1 if (nodeidcounter < 1) { nodeidcounter = 1; } // List to set members in List <Member> mems = new List <Member>(); #region member2d // member2Ds if (member2ds != null) { if (member2ds.Count > 0) { for (int i = 0; i < member2ds.Count; i++) { if (member2ds[i] != null) { GsaMember2d member2d = member2ds[i]; Member apiMember = Members.ConvertMember2D(member2d, ref nodes, ref nodeidcounter); mems.Add(apiMember); } } } } #endregion return(mems); }
public void TestCreateGsaMem2dFromBrep() { // create a list of corner points List <Point3d> pts = new List <Point3d>(); pts.Add(new Point3d(-3, -4, 0)); pts.Add(new Point3d(5, -2, 0)); pts.Add(new Point3d(6, 7, 0)); pts.Add(new Point3d(-1, 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]; // empty lists for inclusion points and lines List <Point3d> inclpts = new List <Point3d>(); List <Curve> inclcrvs = new List <Curve>(); // create 2d member from brep GsaMember2d mem = new GsaMember2d(brep, inclcrvs, inclpts); // set some members mem.Colour = System.Drawing.Color.White; mem.ID = 4; mem.Member.MeshSize = 0.56; mem.Member.Name = "meminem"; mem.Member.IsDummy = true; mem.Member.Offset.Z = -0.45; mem.Member.Property = 2; mem.Member.Type2D = AnalysisOrder.LINEAR; mem.Member.Type = MemberType.SLAB; Assert.AreEqual(mem.Brep.Vertices[0].Location.X, mem.Topology[0].X); Assert.AreEqual(mem.Brep.Vertices[0].Location.Y, mem.Topology[0].Y); Assert.AreEqual(mem.Brep.Vertices[1].Location.X, mem.Topology[1].X); Assert.AreEqual(mem.Brep.Vertices[1].Location.Y, mem.Topology[1].Y); Assert.AreEqual(mem.Brep.Vertices[2].Location.X, mem.Topology[2].X); Assert.AreEqual(mem.Brep.Vertices[2].Location.Y, mem.Topology[2].Y); Assert.AreEqual(mem.Brep.Vertices[3].Location.X, mem.Topology[3].X); Assert.AreEqual(mem.Brep.Vertices[3].Location.Y, mem.Topology[3].Y); Assert.AreEqual(mem.Brep.Vertices[0].Location.X, mem.Topology[4].X); Assert.AreEqual(mem.Brep.Vertices[0].Location.Y, mem.Topology[4].Y); Assert.AreEqual(System.Drawing.Color.FromArgb(255, 255, 255, 255), mem.Member.Colour); Assert.AreEqual(4, mem.ID); Assert.AreEqual(0.56, mem.Member.MeshSize); Assert.AreEqual("meminem", mem.Member.Name); Assert.IsTrue(mem.Member.IsDummy); Assert.AreEqual(-0.45, mem.Member.Offset.Z); Assert.AreEqual(2, mem.Member.Property); Assert.AreEqual(AnalysisOrder.LINEAR, mem.Member.Type2D); Assert.AreEqual(MemberType.SLAB, mem.Member.Type); }
public static void ConvertMember2D(List <GsaMember2d> member2ds, ref Dictionary <int, Member> existingMembers, ref int memberidcounter, ref Dictionary <int, Node> existingNodes, ref Dictionary <int, Prop2D> existingProp2Ds, ref Dictionary <Guid, int> prop2d_guid, GrasshopperAsyncComponent.WorkerInstance workerInstance = null, Action <string, double> ReportProgress = null) { // create a counter for creating new elements, nodes and properties int nodeidcounter = (existingNodes.Count > 0) ? existingNodes.Keys.Max() + 1 : 1; if (member2ds != null) { for (int i = 0; i < member2ds.Count; i++) { if (workerInstance != null) { if (workerInstance.CancellationToken.IsCancellationRequested) { return; } ReportProgress("Mem2D ", (double)i / (member2ds.Count - 1)); } if (member2ds[i] != null) { GsaMember2d member2d = member2ds[i]; ConvertMember2D(member2d, ref existingMembers, ref memberidcounter, ref existingNodes, ref nodeidcounter, ref existingProp2Ds, ref prop2d_guid); } } } if (workerInstance != null) { ReportProgress("Mem2D assembled", -2); } }
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; } }
public static void ConvertMember2D(GsaMember2d member2d, ref Dictionary <int, Member> existingMembers, ref int memberidcounter, ref Dictionary <int, Node> existingNodes, ref int nodeidcounter, ref Dictionary <int, Prop2D> existingProp2Ds, ref Dictionary <Guid, int> prop2d_guid) { Member apiMember = member2d.Member; // update topology list to fit model nodes string topo = ""; // Loop through the topology list for (int i = 0; i < member2d.Topology.Count; i++) { Point3d pt = member2d.Topology[i]; string topologyType = member2d.TopologyType[i]; if (i > 0) { if (topologyType == "" | topologyType == " ") { topo += " "; } else { topo += topologyType.ToLower() + " "; // add topology type (nothing or "a") in front of node id } } int id = Nodes.GetExistingNodeID(existingNodes, pt); if (id > 0) { topo += id; } else { existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(pt)); topo += nodeidcounter; nodeidcounter++; } if (i != member2d.Topology.Count - 1) { topo += " "; } } // Loop through the voidtopology list if (member2d.VoidTopology != null) { for (int i = 0; i < member2d.VoidTopology.Count; i++) { for (int j = 0; j < member2d.VoidTopology[i].Count; j++) { Point3d pt = member2d.VoidTopology[i][j]; string voidtopologytype = member2d.VoidTopologyType[i][j]; if (j == 0) { topo += " V("; } if (voidtopologytype == "" | voidtopologytype == " ") { topo += " "; } else { topo += voidtopologytype.ToLower() + " "; // add topology type (nothing or "a") in front of node id } int id = Nodes.GetExistingNodeID(existingNodes, pt); if (id > 0) { topo += id; } else { existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(pt)); topo += nodeidcounter; nodeidcounter++; } if (j != member2d.VoidTopology[i].Count - 1) { topo += " "; } else { topo += ")"; } } } } // Loop through the inclusion lines topology list if (member2d.IncLinesTopology != null) { for (int i = 0; i < member2d.IncLinesTopology.Count; i++) { for (int j = 0; j < member2d.IncLinesTopology[i].Count; j++) { Point3d pt = member2d.IncLinesTopology[i][j]; string inclineTopologytype = member2d.IncLinesTopologyType[i][j]; if (j == 0) { topo += " L("; } if (inclineTopologytype == "" | inclineTopologytype == " ") { topo += " "; } else { topo += inclineTopologytype.ToLower() + " "; // add topology type (nothing or "a") in front of node id } int id = Nodes.GetExistingNodeID(existingNodes, pt); if (id > 0) { topo += id; } else { existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(pt)); topo += nodeidcounter; nodeidcounter++; } if (j != member2d.IncLinesTopology[i].Count - 1) { topo += " "; } else { topo += ")"; } } } } // Loop through the inclucion point topology list if (member2d.InclusionPoints != null) { for (int i = 0; i < member2d.InclusionPoints.Count; i++) { Point3d pt = member2d.InclusionPoints[i]; if (i == 0) { topo += " P("; } int id = Nodes.GetExistingNodeID(existingNodes, pt); if (id > 0) { topo += id; } else { existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(pt)); topo += nodeidcounter; nodeidcounter++; } if (i != member2d.InclusionPoints.Count - 1) { topo += " "; } else { topo += ")"; } } } // update topology for api member apiMember.Topology = string.Copy(topo); // section if (apiMember.Property == 0) { apiMember.Property = Prop2ds.ConvertProp2d(member2d.Property, ref existingProp2Ds, ref prop2d_guid); } // set apimember in dictionary if (member2d.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list { existingMembers[member2d.ID] = apiMember; } else { existingMembers.Add(memberidcounter, apiMember); memberidcounter++; } }
public static Member ConvertMember2D(GsaMember2d member2d, ref List <Node> nodes, ref int nodeidcounter) { // take out api member Member apimember = member2d.Member; // create string to build topology string topo = ""; #region outline topology // Loop through the topology list for (int j = 0; j < member2d.Topology.Count; j++) { string topologyType = member2d.TopologyType[j]; if (j > 0) { if (topologyType == "" | topologyType == " ") { topo += " "; } else { topo += topologyType.ToLower() + " "; // add topology type (nothing or "a") in front of node id } } Point3d pt = member2d.Topology[j]; Node node = new Node(); node.Position.X = pt.X; node.Position.Y = pt.Y; node.Position.Z = pt.Z; nodes.Add(node); topo += nodeidcounter++; if (j != member2d.Topology.Count - 1) { topo += " "; } } #endregion #region voids // Loop through the voidtopology list if (member2d.VoidTopology != null) { for (int j = 0; j < member2d.VoidTopology.Count; j++) { for (int k = 0; k < member2d.VoidTopology[j].Count; k++) { string voidtopologytype = member2d.VoidTopologyType[j][k]; if (k == 0) { topo += " V("; } if (voidtopologytype == "" | voidtopologytype == " ") { topo += " "; } else { topo += voidtopologytype.ToLower() + " "; // add topology type (nothing or "a") in front of node id } Point3d pt = member2d.VoidTopology[j][k]; Node node = new Node(); node.Position.X = pt.X; node.Position.Y = pt.Y; node.Position.Z = pt.Z; nodes.Add(node); topo += nodeidcounter++; if (k != member2d.VoidTopology[j].Count - 1) { topo += " "; } else { topo += ")"; } } } } #endregion #region inclusion lines // Loop through the inclusion lines topology list if (member2d.IncLinesTopology != null) { for (int j = 0; j < member2d.IncLinesTopology.Count; j++) { for (int k = 0; k < member2d.IncLinesTopology[j].Count; k++) { string inclineTopologytype = member2d.IncLinesTopologyType[j][k]; if (k == 0) { topo += " L("; } if (inclineTopologytype == "" | inclineTopologytype == " ") { topo += " "; } else { topo += inclineTopologytype.ToLower() + " "; // add topology type (nothing or "a") in front of node id } Point3d pt = member2d.IncLinesTopology[j][k]; Node node = new Node(); node.Position.X = pt.X; node.Position.Y = pt.Y; node.Position.Z = pt.Z; nodes.Add(node); topo += nodeidcounter++; if (k != member2d.IncLinesTopology[j].Count - 1) { topo += " "; } else { topo += ")"; } } } } #endregion #region inclusion points // Loop through the inclucion point topology list if (member2d.InclusionPoints != null) { for (int j = 0; j < member2d.InclusionPoints.Count; j++) { if (j == 0) { topo += " P("; } Point3d pt = member2d.InclusionPoints[j]; Node node = new Node(); node.Position.X = pt.X; node.Position.Y = pt.Y; node.Position.Z = pt.Z; nodes.Add(node); topo += nodeidcounter++; if (j != member2d.InclusionPoints.Count - 1) { topo += " "; } else { topo += ")"; } } } #endregion // update topology for api member apimember.Topology = string.Copy(topo); return(apimember); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // first import points and curves for inclusion before building member // 2 Points List <Point3d> pts = new List <Point3d>(); List <GH_Point> ghpts = new List <GH_Point>(); if (DA.GetDataList(2, 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); } } } // 3 Curves List <Curve> crvs = new List <Curve>(); List <GH_Curve> ghcrvs = new List <GH_Curve>(); if (DA.GetDataList(3, 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); } } } // now build new member with brep, crv and pts GsaMember2d mem = new GsaMember2d(brep, crvs, pts); // add the rest // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { 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; } } } else { prop2d.ID = 1; } mem.Property = prop2d; // 4 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); mem.Member.MeshSize = m_size; } DA.SetData(0, new GsaMember2dGoo(mem)); } } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { if (ghbrep == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null"); } Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // 1 Points List <Point3d> pts = new List <Point3d>(); List <GH_Point> ghpts = new List <GH_Point>(); if (DA.GetDataList(1, 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); } } } // 2 Curves List <Curve> crvs = new List <Curve>(); List <GH_Curve> ghcrvs = new List <GH_Curve>(); if (DA.GetDataList(2, 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); } } } // build new member with brep, crv and pts GsaMember2d mem = new GsaMember2d(brep, crvs, pts); // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(3, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); mem.Property = prop2d; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } // 4 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); mem.Member.MeshSize = m_size; } DA.SetData(0, new GsaMember2dGoo(mem)); }
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); } }
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)); }
protected override void SolveInstance(IGH_DataAccess DA) { #region inputs // Get Member1d input GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); if (DA.GetDataList(0, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Node input"); return; } } } List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); if (DA.GetDataList(1, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem1D input"); return; } } } // Get Member2d input gh_types = new List <GH_ObjectWrapper>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem2D input"); return; } } } // Get Member3d input gh_types = new List <GH_ObjectWrapper>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(3, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem3D input"); return; } } } // manually add a warning if no input is set, as all three inputs are optional if (in_mem1ds.Count < 1 & in_mem2ds.Count < 1 & in_mem3ds.Count < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); } #endregion // Assemble model Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(null, in_nodes, null, null, null, in_mem1ds, in_mem2ds, in_mem3ds, null, null, null, null); #region meshing // Create elements from members gsa.CreateElementsFromMembers(); #endregion // extract nodes from model List <GsaNodeGoo> nodes = Util.Gsa.FromGSA.GetNodes(gsa.Nodes(), gsa); // extract elements from model Tuple <List <GsaElement1dGoo>, List <GsaElement2dGoo>, List <GsaElement3dGoo> > elementTuple = Util.Gsa.FromGSA.GetElements(gsa.Elements(), gsa.Nodes(), gsa.Sections(), gsa.Prop2Ds()); // expose internal model if anyone wants to use it GsaModel outModel = new GsaModel(); outModel.Model = gsa; DA.SetDataList(0, nodes); DA.SetDataList(1, elementTuple.Item1); DA.SetDataList(2, elementTuple.Item2); DA.SetDataList(3, elementTuple.Item3); DA.SetData(4, new GsaModelGoo(outModel)); // custom display settings for element2d mesh element2ds = elementTuple.Item2; }