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); }
//GsaMaterial m_material; #endregion #region constructors public GsaProp2d() { m_prop2d = new Prop2D(); m_idd = 0; }
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); } }
public GsaProp2d() { m_prop2d = new Prop2D(); m_guid = Guid.NewGuid(); }
/// <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)); }