public void TestCreateProp2d() { // create new 2D property GsaProp2d prop = new GsaProp2d(); Prop2D apiProp = new Prop2D { AxisProperty = 1, MaterialGradeProperty = 4, MaterialAnalysisProperty = 42, MaterialType = MaterialType.GENERIC, Name = "mariam", Description = "awesome property", Type = Property2D_Type.LOAD }; prop.Prop2d = apiProp; Assert.AreEqual(1, prop.Prop2d.AxisProperty); Assert.AreEqual(4, prop.Prop2d.MaterialGradeProperty); Assert.AreEqual(42, prop.Prop2d.MaterialAnalysisProperty); Assert.AreEqual(MaterialType.GENERIC.ToString(), prop.Prop2d.MaterialType.ToString()); Assert.AreEqual("mariam", prop.Prop2d.Name); Assert.AreEqual("awesome property", prop.Prop2d.Description); Assert.AreEqual(Property2D_Type.LOAD.ToString(), prop.Prop2d.Type.ToString()); Assert.AreEqual(0, prop.ID); }
public void TestDuplicateProp2d() { // create new 2D property GsaProp2d orig = new GsaProp2d { ID = 14, Prop2d = new Prop2D { AxisProperty = 0, MaterialGradeProperty = 2, MaterialAnalysisProperty = 13, MaterialType = MaterialType.UNDEF, Name = "mariam", Description = "awesome property", Type = Property2D_Type.SHELL } }; // duplicate prop GsaProp2d dup = orig.Duplicate(); // make some changes to original orig.ID = 4; Prop2D apiProp = new Prop2D { AxisProperty = 1, MaterialGradeProperty = 4, MaterialAnalysisProperty = 42, MaterialType = MaterialType.FABRIC, Name = "kris", Description = "less cool property", Type = Property2D_Type.CURVED_SHELL }; orig.Prop2d = apiProp; Assert.AreEqual(0, dup.Prop2d.AxisProperty); Assert.AreEqual(2, dup.Prop2d.MaterialGradeProperty); Assert.AreEqual(13, dup.Prop2d.MaterialAnalysisProperty); Assert.AreEqual(MaterialType.UNDEF.ToString(), dup.Prop2d.MaterialType.ToString()); Assert.AreEqual("mariam", dup.Prop2d.Name); Assert.AreEqual("awesome property", dup.Prop2d.Description); Assert.AreEqual(Property2D_Type.SHELL.ToString(), dup.Prop2d.Type.ToString()); Assert.AreEqual(14, dup.ID); Assert.AreEqual(1, orig.Prop2d.AxisProperty); Assert.AreEqual(4, orig.Prop2d.MaterialGradeProperty); Assert.AreEqual(42, orig.Prop2d.MaterialAnalysisProperty); Assert.AreEqual(MaterialType.FABRIC.ToString(), orig.Prop2d.MaterialType.ToString()); Assert.AreEqual("kris", orig.Prop2d.Name); Assert.AreEqual("less cool property", orig.Prop2d.Description); Assert.AreEqual(Property2D_Type.CURVED_SHELL.ToString(), orig.Prop2d.Type.ToString()); Assert.AreEqual(4, orig.ID); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { if (ghmesh == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh input is null"); } Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 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 GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { for (int i = 0; i < elem.Elements.Count; i++) { elem.Elements[i].Property = idd; } prop2d = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d = null; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); }
private static Dictionary<int, GsaProp2d> GetGsaPropDict() { var propsKeyword = GsaRecord.GetKeyword<GsaProp2d>(); var gsaPropGwas = Initialiser.AppResources.Cache.GetGwa(propsKeyword); var gsaProps = new Dictionary<int, GsaProp2d>(); foreach (var gwa in gsaPropGwas) { var gsaProp = new GsaProp2d(); gsaProp.FromGwa(gwa); if (gsaProp.Index.HasValue) { gsaProps.Add(gsaProp.Index.Value, gsaProp); } } return gsaProps; }
//public static int ConvertProp2d(GsaProp2d prop2d, ref Dictionary<int, Prop2D> existingProp2Ds, ref int prop2didcounter) //{ // if (prop2d == null) { return 0; } // // int prop2dID = prop2d.ID; // // if (prop2d.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list // { // if (prop2d.Prop2d != null) // existingProp2Ds[prop2d.ID] = prop2d.Prop2d; // } // else // { // if (prop2d.Prop2d != null) // { // prop2dID = prop2didcounter; // existingProp2Ds.Add(prop2didcounter, prop2d.Prop2d); // prop2didcounter++; // } // } // return prop2dID; //} public static int ConvertProp2d(GsaProp2d prop2d, ref Dictionary <int, Prop2D> existingProp2Ds, ref Dictionary <Guid, int> prop2d_guid) { if (prop2d == null) { return(0); } if (prop2d_guid.ContainsKey(prop2d.GUID)) { prop2d_guid.TryGetValue(prop2d.GUID, out int sID); // if guid exist in our dictionary it has been added to the model return(sID); } int outID = prop2d.ID; // section if (prop2d.ID > 0) { if (prop2d.Prop2d != null) // section can refer to an ID only, meaning that the section must already exist in the model. Else we set it in the model: { existingProp2Ds[prop2d.ID] = prop2d.Prop2d; } } else { if (prop2d.Prop2d != null) { if (existingProp2Ds.Count > 0) { outID = existingProp2Ds.Keys.Max() + 1; } else { outID = 1; } existingProp2Ds.Add(outID, prop2d.Prop2d); } } // set guid in dictionary prop2d_guid.Add(prop2d.GUID, outID); return(outID); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaProp2d gsaProp2d = new GsaProp2d(); GsaProp2d prop = new GsaProp2d(); if (DA.GetData(0, ref gsaProp2d)) { prop = gsaProp2d.Clone(); } // #### 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)) { prop.ID = id; } } // 2 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); prop.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop.Prop2d.MaterialAnalysisProperty = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 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; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); } } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement2d gsaElement2d = new GsaElement2d(); if (DA.GetData(0, ref gsaElement2d)) { if (gsaElement2d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element2D input is null"); } GsaElement2d elem = gsaElement2d.Duplicate(); // #### inputs #### // no good way of updating location of mesh on the fly // // suggest users re-create from scratch // // 1 ID List <GH_Integer> ghID = new List <GH_Integer>(); List <int> in_ids = new List <int>(); if (DA.GetDataList(1, ghID)) { for (int i = 0; i < ghID.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "ID input List Length is longer than number of elements." + System.Environment.NewLine + "Excess ID's have been ignored"); continue; } if (GH_Convert.ToInt32(ghID[i], out int id, GH_Conversion.Both)) { if (in_ids.Contains(id)) { if (id > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "ID input(" + i + ") = " + id + " already exist in your input list." + System.Environment.NewLine + "You must provide a list of unique IDs, or set ID = 0 if you want to let GSA handle the numbering"); continue; } } in_ids.Add(id); } } } // 2 section List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <GsaProp2d> in_prop2Ds = new List <GsaProp2d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "PA input List Length is longer than number of elements." + System.Environment.NewLine + "Excess PA's have been ignored"); } GH_ObjectWrapper gh_typ = gh_types[i]; GsaProp2d prop2d = new GsaProp2d(); if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); in_prop2Ds.Add(prop2d); elem.Elements[i].Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Elements[i].Property = idd; elem.Properties[i] = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } }
public static void ConvertProp2d(List <GsaProp2d> prop2Ds, 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 properties int prop2didcounter = (existingProp2Ds.Count > 0) ? existingProp2Ds.Keys.Max() + 1 : 1; //checking the existing model // Prop2Ds if (prop2Ds != null) { if (prop2Ds.Count != 0) { // update counter if new prop2ds have set ID higher than existing max int existingProp2dMaxID = prop2Ds.Max(x => x.ID); // max ID in new if (existingProp2dMaxID > prop2didcounter) { prop2didcounter = existingProp2dMaxID + 1; } for (int i = 0; i < prop2Ds.Count; i++) { if (workerInstance != null) { if (workerInstance.CancellationToken.IsCancellationRequested) { return; } ReportProgress("Prop2D ", (double)i / (prop2Ds.Count - 1)); } if (prop2Ds[i] != null) { GsaProp2d prop2d = prop2Ds[i]; Prop2D apiProp2d = prop2d.Prop2d; if (prop2d_guid.ContainsKey(prop2d.GUID)) { prop2d_guid.TryGetValue(prop2d.GUID, out int sID); // if guid exist in our dictionary it has been added to the model continue; } if (prop2d.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list { existingProp2Ds[prop2d.ID] = apiProp2d; // set guid in dictionary prop2d_guid.Add(prop2d.GUID, prop2d.ID); } else { existingProp2Ds.Add(prop2didcounter, apiProp2d); // set guid in dictionary prop2d_guid.Add(prop2d.GUID, prop2didcounter); prop2didcounter++; } } } } } if (workerInstance != null) { ReportProgress("Prop2D assembled", -2); } }
/// <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)); }
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 <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <Point3d> pts = new List <Point3d>(); List <GsaNode> nodes = new List <GsaNode>(); if (DA.GetDataList(1, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Point3d pt = new Point3d(); if (gh_types[i].Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_types[i].CastTo(ref gsanode); nodes.Add(gsanode); } else if (GH_Convert.ToPoint3d(gh_types[i].Value, ref pt, GH_Conversion.Both)) { pts.Add(pt); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Point/Node input parameter of type " + type + " to point or node"); } } } // 2 Curves gh_types = new List <GH_ObjectWrapper>(); List <Curve> crvs = new List <Curve>(); List <GsaMember1d> mem1ds = new List <GsaMember1d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Curve crv = null; if (gh_types[i].Value is GsaMember1dGoo) { GsaMember1d gsamem1d = new GsaMember1d(); gh_types[i].CastTo(ref gsamem1d); mem1ds.Add(gsamem1d); } else if (GH_Convert.ToCurve(gh_types[i].Value, ref crv, GH_Conversion.Both)) { crvs.Add(crv); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Curve/Mem1D input parameter of type " + type + " to curve or 1D Member"); } } } // 4 mesh size GH_Number ghmsz = new GH_Number(); double meshSize = 0; if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); meshSize = m_size; } // build new element2d with brep, crv and pts GsaElement2d elem2d = new GsaElement2d(brep, crvs, pts, meshSize, mem1ds, nodes); // 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); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d.ID = 1; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem2d.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem2d.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem2d)); }
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) { #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 }
protected override void SolveInstance(IGH_DataAccess DA) { GsaProp2d prop = new GsaProp2d(); prop.Prop2d = new Prop2D(); prop.ID = 0; // element type (picked in dropdown) prop.Prop2d.Type = Property2D_Type.UNDEF; if (_mode == FoldMode.PlaneStress) prop.Prop2d.Type = Property2D_Type.PL_STRESS; if (_mode == FoldMode.Fabric) prop.Prop2d.Type = Property2D_Type.FABRIC; if (_mode == FoldMode.FlatPlate) prop.Prop2d.Type = Property2D_Type.PLATE; if (_mode == FoldMode.Shell) prop.Prop2d.Type = Property2D_Type.SHELL; if (_mode == FoldMode.CurvedShell) prop.Prop2d.Type = Property2D_Type.CURVED_SHELL; if (_mode == FoldMode.LoadPanel) prop.Prop2d.Type = Property2D_Type.LOAD; if (_mode != FoldMode.LoadPanel) { prop.Prop2d.AxisProperty = 0; if (_mode != FoldMode.Fabric) { // 0 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); prop.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop.Material = new GsaMaterial(idd); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } else prop.Material = new GsaMaterial(2); // 1 thickness //GH_String gh_THK = new GH_String(); //string thickness = "0.2"; //if (DA.GetData(1, ref gh_THK)) // GH_Convert.ToString(gh_THK, out thickness, GH_Conversion.Both); //prop.Prop2d.Description = thickness; GH_Number gh_THK = new GH_Number(); double thickness = 200; if (DA.GetData(1, ref gh_THK)) GH_Convert.ToDouble(gh_THK, out thickness, GH_Conversion.Both); prop.Thickness = thickness; }
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) { 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) { GsaElement2d gsaElement2d = new GsaElement2d(); if (DA.GetData(0, ref gsaElement2d)) { GsaElement2d elem = gsaElement2d.Duplicate(); // #### inputs #### // no good way of updating location of mesh on the fly // // suggest users re-create from scratch // // 1 section List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; 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; } } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int j = 0; j < elem.Elements.Count; j++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; } } // 2 offset List <GsaOffset> offset = new List <GsaOffset>(); if (DA.GetDataList(2, offset)) { for (int i = 0; i < offset.Count; i++) { elem.Elements[i].Offset.Z = offset[i].Z; } } // 3 element type / analysis order List <GH_Integer> ghinteg = new List <GH_Integer>(); if (DA.GetDataList(3, ghinteg)) { for (int i = 0; i < ghinteg.Count; i++) { if (GH_Convert.ToInt32(ghinteg[i], out int type, GH_Conversion.Both)) { //elem.Elements[i].Type = Util.Gsa.GsaToModel.Element2dType(type); Note: Type on 2D element should be analysis order - GsaAPI bug? } } } // 4 ID List <GH_Integer> ghID = new List <GH_Integer>(); if (DA.GetDataList(4, ghID)) { for (int i = 0; i < ghID.Count; i++) { if (GH_Convert.ToInt32(ghID[i], out int id, GH_Conversion.Both)) { elem.ID[i] = id; } } } // 5 name List <GH_String> ghnm = new List <GH_String>(); if (DA.GetDataList(5, ghnm)) { for (int i = 0; i < ghnm.Count; i++) { if (GH_Convert.ToString(ghnm[i], out string name, GH_Conversion.Both)) { elem.Elements[i].Name = name; } } } // 6 Group List <GH_Integer> ghgrp = new List <GH_Integer>(); if (DA.GetDataList(6, ghgrp)) { for (int i = 0; i < ghgrp.Count; i++) { if (GH_Convert.ToInt32(ghgrp[i], out int grp, GH_Conversion.Both)) { elem.Elements[i].Group = grp; } } } // 7 Colour List <GH_Colour> ghcol = new List <GH_Colour>(); if (DA.GetDataList(7, ghcol)) { for (int i = 0; i < ghcol.Count; i++) { if (GH_Convert.ToColor(ghcol[i], out System.Drawing.Color col, GH_Conversion.Both)) { elem.Elements[i].Colour = col; } } } // #### outputs #### DA.SetData(0, new GsaElement2dGoo(elem)); DA.SetData(1, elem.Mesh); List <GsaOffset> offsets = new List <GsaOffset>(); //List<int> anal = new List<int>(); List <string> names = new List <string>(); List <int> groups = new List <int>(); List <System.Drawing.Color> colours = new List <System.Drawing.Color>(); List <int> pmems = new List <int>(); for (int i = 0; i < elem.Elements.Count; i++) { GsaOffset offset1 = new GsaOffset { Z = elem.Elements[i].Offset.Z }; offsets.Add(offset1); //anal.Add(gsaElement2d.Elements[i].Type); names.Add(elem.Elements[i].Name); groups.Add(elem.Elements[i].Group); colours.Add((System.Drawing.Color)elem.Elements[i].Colour); try { pmems.Add(elem.Elements[i].ParentMember.Member); } catch (Exception) { pmems.Add(0); } ; } DA.SetDataList(2, elem.Properties); DA.SetDataList(3, offsets); //DA.SetDataList(4, anal); DA.SetDataList(5, elem.ID); DA.SetDataList(6, names); DA.SetDataList(7, groups); DA.SetDataList(8, colours); DA.SetDataList(9, pmems); } }
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)); }
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) { GsaProp2d gsaProp2d = new GsaProp2d(); if (DA.GetData(0, ref gsaProp2d)) { GsaProp2d prop = gsaProp2d.Duplicate(); // #### inputs #### // 1 thickness string thk = ""; //prop.Prop2d.Thickness; if (DA.GetData(1, ref thk)) { //prop.Prop2d.Thickness = thk; } // 2 Material // to be implemented // 3 analysis type int analtype = 0; //prop.Prop2d.Thickness; if (DA.GetData(3, ref analtype)) { prop.Prop2d.MaterialAnalysisProperty = analtype; } // 4 alignment string ali = ""; if (DA.GetData(4, ref ali)) { // to be implement / GsaAPI can handle alignment / reference surface } // 5 offset GsaOffset offsetGSA = new GsaOffset(); double offset = 0; if (DA.GetData(5, ref offsetGSA)) { //prop.Prop2d.Offeset = offsetGSA.Z; } else if (DA.GetData(5, ref offset)) { //prop.Prop2d.Offeset = offset; } // 6 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(6, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { prop.ID = id; } } // 7 name GH_String ghnm = new GH_String(); if (DA.GetData(7, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { prop.Prop2d.Name = name; } } // 8 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(8, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { prop.Prop2d.Colour = col; } } //#### outputs #### DA.SetData(0, new GsaProp2dGoo(prop)); //DA.SetData(1, gsaProp2d.Thickness); // GsaAPI to be updated //DA.SetData(2, gsaProp2d.Prop2d.Material); // to be implemented DA.SetData(3, prop.Prop2d.MaterialAnalysisProperty); // GsaAPI to be updated //DA.SetData(4, gsaProp2d.??); GsaAPI to include alignment / reference surface GsaOffset gsaoffset = new GsaOffset(); //offset.Z = gsaProp2d.Prop2d.Offset; // GsaAPI to include prop2d offset DA.SetData(5, gsaoffset); DA.SetData(6, prop.ID); DA.SetData(7, prop.Prop2d.Name); DA.SetData(8, prop.Prop2d.Colour); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaProp2d prop = new GsaProp2d(); // element type (picked in dropdown) prop.Prop2d.Type = Property2D_Type.UNDEF; if (_mode == FoldMode.PlaneStress) { prop.Prop2d.Type = Property2D_Type.PL_STRESS; } if (_mode == FoldMode.Fabric) { prop.Prop2d.Type = Property2D_Type.FABRIC; } if (_mode == FoldMode.FlatPlate) { prop.Prop2d.Type = Property2D_Type.PLATE; } if (_mode == FoldMode.Shell) { prop.Prop2d.Type = Property2D_Type.SHELL; } if (_mode == FoldMode.CurvedShell) { prop.Prop2d.Type = Property2D_Type.CURVED_SHELL; } if (_mode == FoldMode.LoadPanel) { prop.Prop2d.Type = Property2D_Type.LOAD; } //id GH_Integer gh_ID = new GH_Integer(); DA.GetData(0, ref gh_ID); int idd = 0; GH_Convert.ToInt32_Primary(gh_ID, ref idd); prop.ID = idd; //name GH_String gh_Name = new GH_String(); DA.GetData(1, ref gh_Name); string name = ""; GH_Convert.ToString_Primary(gh_Name, ref name); prop.Prop2d.Name = name; //colour GH_Colour gh_Colour = new GH_Colour(); DA.GetData(2, ref gh_Colour); System.Drawing.Color colour = new System.Drawing.Color(); GH_Convert.ToColor_Primary(gh_Colour, ref colour); prop.Prop2d.Colour = (ValueType)colour; if (_mode != FoldMode.LoadPanel) { //axis GH_Integer gh_Axis = new GH_Integer(); DA.GetData(3, ref gh_Axis); int axis = 0; GH_Convert.ToInt32_Primary(gh_Axis, ref axis); prop.Prop2d.AxisProperty = axis; if (_mode != FoldMode.Fabric) { //Material type GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); MaterialType matType = MaterialType.CONCRETE; if (DA.GetData(4, ref gh_typ)) { if (gh_typ.Value is MaterialType) { gh_typ.CastTo(ref matType); } if (gh_typ.Value is GH_String) { string typ = "CONCRETE"; GH_Convert.ToString_Primary(gh_typ, ref typ); if (typ.ToUpper() == "STEEL") { matType = MaterialType.STEEL; } if (typ.ToUpper() == "CONCRETE") { matType = MaterialType.CONCRETE; } if (typ.ToUpper() == "FRP") { matType = MaterialType.FRP; } if (typ.ToUpper() == "ALUMINIUM") { matType = MaterialType.ALUMINIUM; } if (typ.ToUpper() == "TIMBER") { matType = MaterialType.TIMBER; } if (typ.ToUpper() == "GLASS") { matType = MaterialType.GLASS; } if (typ.ToUpper() == "FABRIC") { matType = MaterialType.FABRIC; } if (typ.ToUpper() == "GENERIC") { matType = MaterialType.GENERIC; } } } prop.Prop2d.MaterialType = matType; //thickness GH_Number gh_THK = new GH_Number(); double thickness = 0.2; if (DA.GetData(7, ref gh_THK)) { GH_Convert.ToDouble_Primary(gh_THK, ref thickness); } //prop.Prop2d.Thickness = thickness; } else { prop.Prop2d.MaterialType = MaterialType.FABRIC; } //handle that the last two inputs are at different -1 index for fabric mode int fab = 0; if (_mode == FoldMode.Fabric) { fab = 1; } //grade GH_Integer gh_grd = new GH_Integer(); DA.GetData(5 - fab, ref gh_grd); int grade = 1; GH_Convert.ToInt32_Primary(gh_grd, ref grade); prop.Prop2d.MaterialGradeProperty = grade; //analysis GH_Integer gh_anal = new GH_Integer(); DA.GetData(6 - fab, ref gh_anal); int analysis = 1; GH_Convert.ToInt32_Primary(gh_anal, ref analysis); prop.Prop2d.MaterialAnalysisProperty = analysis; } DA.SetData(0, new GsaProp2dGoo(prop)); }