public override bool CastFrom(object source) { // This function is called when Grasshopper needs to convert other data // into GsaSection. if (source == null) { return(false); } //Cast from GsaSection if (typeof(GsaSection).IsAssignableFrom(source.GetType())) { Value = (GsaSection)source; return(true); } //Cast from string if (GH_Convert.ToString(source, out string name, GH_Conversion.Both)) { Value.Section.Profile = name; return(true); } //Cast from integer if (GH_Convert.ToInt32(source, out int idd, GH_Conversion.Both)) { Value.ID = idd; } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection sect = new GsaSection(); //profile GH_String gh_profile = new GH_String(); if (DA.GetData(0, ref gh_profile)) { if (GH_Convert.ToString(gh_profile, out string profile, GH_Conversion.Both)) { sect.Section.Profile = profile; // 1 material // to be implemented // 2 pool GH_Integer gh_pool = new GH_Integer(); if (DA.GetData(2, ref gh_pool)) { if (GH_Convert.ToInt32(gh_pool, out int pool, GH_Conversion.Both)) { sect.Section.Pool = pool; } } // 3 ID GH_Integer gh_id = new GH_Integer(); if (DA.GetData(3, ref gh_id)) { if (GH_Convert.ToInt32(gh_id, out int idd, GH_Conversion.Both)) { sect.ID = idd; } } // 4 name GH_String gh_n = new GH_String(); if (DA.GetData(4, ref gh_n)) { if (GH_Convert.ToString(gh_n, out string name, GH_Conversion.Both)) { sect.Section.Name = name; } } // 5 colour GH_Colour gh_Colour = new GH_Colour(); if (DA.GetData(5, ref gh_Colour)) { if (GH_Convert.ToColor(gh_Colour, out System.Drawing.Color colour, GH_Conversion.Both)) { sect.Section.Colour = colour; } } } DA.SetData(0, new GsaSectionGoo(sect)); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMaterial material = new GsaMaterial(); GH_Integer gh_anal = new GH_Integer(); if (DA.GetData(0, ref gh_anal)) { int anal = 0; GH_Convert.ToInt32(gh_anal, out anal, GH_Conversion.Both); material.AnalysisProperty = anal; } GH_Integer gh_grade = new GH_Integer(); if (DA.GetData(1, ref gh_grade)) { int grade = 1; GH_Convert.ToInt32(gh_grade, out grade, GH_Conversion.Both); material.Grade = grade; } // element type (picked in dropdown) if (_mode == FoldMode.Generic) { material.Type = GsaMaterial.MatType.GENERIC; } if (_mode == FoldMode.Steel) { material.Type = GsaMaterial.MatType.STEEL; } if (_mode == FoldMode.Concrete) { material.Type = GsaMaterial.MatType.CONCRETE; } if (_mode == FoldMode.Timber) { material.Type = GsaMaterial.MatType.TIMBER; } if (_mode == FoldMode.Aluminium) { material.Type = GsaMaterial.MatType.ALUMINIUM; } if (_mode == FoldMode.FRP) { material.Type = GsaMaterial.MatType.FRP; } if (_mode == FoldMode.Glass) { material.Type = GsaMaterial.MatType.GLASS; } if (_mode == FoldMode.Fabric) { material.Type = GsaMaterial.MatType.FABRIC; } DA.SetData(0, new GsaMaterialGoo(material)); }
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)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection sect = new GsaSection(); GsaSection gsaSection = new GsaSection(); if (DA.GetData(0, ref sect)) { gsaSection = sect.Clone(); } if (gsaSection != null) { // #### input #### // 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)) { gsaSection.ID = id; } } // 2 profile string profile = ""; if (DA.GetData(2, ref profile)) { gsaSection.Section.Profile = profile; } // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Section.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) { GsaGravityLoad gravityLoad = new GsaGravityLoad(); //Load case int lc = 1; GH_Integer gh_lc = new GH_Integer(); if (DA.GetData(0, ref gh_lc)) { GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both); } gravityLoad.GravityLoad.Case = lc; //element/beam list string beamList = "all"; GH_String gh_bl = new GH_String(); if (DA.GetData(1, ref gh_bl)) { GH_Convert.ToString(gh_bl, out beamList, GH_Conversion.Both); } gravityLoad.GravityLoad.Elements = beamList; // 2 Name string name = ""; GH_String gh_name = new GH_String(); if (DA.GetData(2, ref gh_name)) { if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both)) { gravityLoad.GravityLoad.Name = name; } } //factor Vector3 factor = new Vector3(); Vector3d vect = new Vector3d(0, 0, -1); GH_Vector gh_factor = new GH_Vector(); if (DA.GetData(3, ref gh_factor)) { GH_Convert.ToVector3d(gh_factor, ref vect, GH_Conversion.Both); } factor.X = vect.X; factor.Y = vect.Y; factor.Z = vect.Z; gravityLoad.GravityLoad.Factor = factor; GsaLoad gsaLoad = new GsaLoad(gravityLoad); DA.SetData(0, new GsaLoadGoo(gsaLoad)); }
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) { GsaSection gsaSection = new GsaSection(); //profile GH_String gh_profile = new GH_String(); if (DA.GetData(0, ref gh_profile)) { if (GH_Convert.ToString(gh_profile, out string profile, GH_Conversion.Both)) { gsaSection.Section = new Section(); gsaSection.Section.Profile = profile; // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(1, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Material = new GsaMaterial(idd); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } else { gsaSection.Material = new GsaMaterial(7); } }
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) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { if (ghln == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Line input is null"); } Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); elem.Section = section; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Element.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaElement1dGoo(elem)); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } } else { section.ID = 1; } elem.Section = section; DA.SetData(0, new GsaElement1dGoo(elem)); } } }
public override bool CastFrom(object source) { // This function is called when Grasshopper needs to convert other data // into GsaMaterial. if (source == null) { return(false); } //Cast from GsaMaterial if (typeof(GsaMaterial).IsAssignableFrom(source.GetType())) { Value = (GsaMaterial)source; return(true); } //Cast from string if (GH_Convert.ToString(source, out string mat, GH_Conversion.Both)) { if (mat.ToUpper() == "STEEL") { Value.Type = GsaMaterial.MatType.STEEL; return(true); } if (mat.ToUpper() == "CONCRETE") { Value.Type = GsaMaterial.MatType.CONCRETE; return(true); } if (mat.ToUpper() == "FRP") { Value.Type = GsaMaterial.MatType.FRP; return(true); } if (mat.ToUpper() == "ALUMINIUM") { Value.Type = GsaMaterial.MatType.ALUMINIUM; return(true); } if (mat.ToUpper() == "TIMBER") { Value.Type = GsaMaterial.MatType.TIMBER; return(true); } if (mat.ToUpper() == "GLASS") { Value.Type = GsaMaterial.MatType.GLASS; return(true); } if (mat.ToUpper() == "FABRIC") { Value.Type = GsaMaterial.MatType.FABRIC; return(true); } if (mat.ToUpper() == "GENERIC") { Value.Type = GsaMaterial.MatType.GENERIC; return(true); } return(false); } //Cast from integer if (GH_Convert.ToInt32(source, out int idd, GH_Conversion.Both)) { Value.AnalysisProperty = idd; } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { GsaNode gsaNode = new GsaNode(); Point3d tempPt = new Point3d(); if (gh_typ.Value is GsaNodeGoo) { gh_typ.CastTo(ref gsaNode); if (gsaNode == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } if (gsaNode.Node == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } } else if (GH_Convert.ToPoint3d(gh_typ.Value, ref tempPt, GH_Conversion.Both)) { gsaNode = new GsaNode(tempPt); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert input to Node"); return; } GsaNode node = gsaNode.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghInt = new GH_Integer(); if (DA.GetData(1, ref ghInt)) { if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both)) { node.ID = id; } } // 2 Point GH_Point ghPt = new GH_Point(); if (DA.GetData(2, ref ghPt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both)) { node.Point = pt; node.Node.Position.X = pt.X; node.Node.Position.Y = pt.Y; node.Node.Position.Z = pt.Z; } } // 3 plane GH_Plane ghPln = new GH_Plane(); if (DA.GetData(3, ref ghPln)) { Plane pln = new Plane(); if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both)) { pln.Origin = node.Point; node.LocalAxis = pln; } } // 4 Restraint GsaBool6 restraint = new GsaBool6(); if (DA.GetData(4, ref restraint)) { node.Node.Restraint.X = restraint.X; node.Node.Restraint.Y = restraint.Y; node.Node.Restraint.Z = restraint.Z; node.Node.Restraint.XX = restraint.XX; node.Node.Restraint.YY = restraint.YY; node.Node.Restraint.ZZ = restraint.ZZ; } // 5 Spring GsaSpring spring = new GsaSpring(); if (DA.GetData(5, ref spring)) { if (spring != null) { node.Spring = spring; } } // 6 Name GH_String ghStr = new GH_String(); if (DA.GetData(6, ref ghStr)) { if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both)) { node.Node.Name = name; } } // 7 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(7, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { node.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaNodeGoo(node)); DA.SetData(1, node.ID); DA.SetData(2, node.Point); DA.SetData(3, node.LocalAxis); GsaBool6 restraint1 = new GsaBool6 { X = node.Node.Restraint.X, Y = node.Node.Restraint.Y, Z = node.Node.Restraint.Z, XX = node.Node.Restraint.XX, YY = node.Node.Restraint.YY, ZZ = node.Node.Restraint.ZZ }; DA.SetData(4, restraint1); GsaSpring spring1 = new GsaSpring(); if (node.Spring != null) { spring1 = node.Spring.Duplicate(); } DA.SetData(5, new GsaSpringGoo(spring1)); DA.SetData(6, node.Node.Name); DA.SetData(7, node.Colour); try { DA.SetDataList(8, node.Node.ConnectedElements); } catch (Exception) { } try { DA.SetDataList(9, node.Node.ConnectedMembers); } catch (Exception) { } } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember3d gsaMember3d = new GsaMember3d(); if (DA.GetData(0, ref gsaMember3d)) { if (gsaMember3d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member3D input is null"); } GsaMember3d mem = gsaMember3d.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 geometry GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaMember3d tempMem = new GsaMember3d(); Brep brep = new Brep(); Mesh mesh = new Mesh(); if (GH_Convert.ToBrep(gh_typ.Value, ref brep, GH_Conversion.Both)) { tempMem = new GsaMember3d(brep); } else if (GH_Convert.ToMesh(gh_typ.Value, ref mesh, GH_Conversion.Both)) { tempMem = new GsaMember3d(mesh); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input to a 3D Member"); return; } mem.SolidMesh = tempMem.SolidMesh; } // 3 prop3d -- to be implemented GsaAPI gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; } //GsaProp3d prop3d = new GsaProp3d(); //if (gh_typ.Value is GsaProp3dGoo) // gh_typ.CastTo(ref prop3d); //else //{ // if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) // prop3d.ID = idd; // else // { // AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 3D Property of reference integer"); // return; // } //} //mem.Property = prop3d; } // 4 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(4, ref ghmsz)) { if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both)) { mem.Member.MeshSize = msz; } } // 5 mesh with others GH_Boolean ghbool = new GH_Boolean(); if (DA.GetData(5, ref ghbool)) { if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both)) { //mem.member.MeshWithOthers } } // 6 name GH_String ghnm = new GH_String(); if (DA.GetData(6, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { mem.Member.Name = name; } } // 7 Group GH_Integer ghgrp = new GH_Integer(); if (DA.GetData(7, ref ghgrp)) { if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both)) { mem.Member.Group = grp; } } // 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)) { mem.Member.Colour = col; } } // 9 Dummy GH_Boolean ghdum = new GH_Boolean(); if (DA.GetData(9, ref ghdum)) { if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both)) { mem.Member.IsDummy = dum; } } // #### outputs #### DA.SetData(0, new GsaMember3dGoo(mem)); DA.SetData(1, mem.ID); DA.SetData(2, mem.SolidMesh); //DA.SetData(3, mem.Property); DA.SetData(4, mem.Member.MeshSize); //DA.SetData(5, mem.Member.MeshWithOthers); DA.SetData(6, mem.Member.Name); DA.SetData(7, mem.Member.Group); DA.SetData(8, mem.Member.Colour); DA.SetData(9, mem.Member.IsDummy); } }
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)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement1d gsaElement1d = new GsaElement1d(); if (DA.GetData(0, ref gsaElement1d)) { GsaElement1d elem = gsaElement1d.Duplicate(); // #### inputs #### // 1 curve GH_Line ghcrv = new GH_Line(); if (DA.GetData(1, ref ghcrv)) { Line crv = new Line(); if (GH_Convert.ToLine(ghcrv, ref crv, GH_Conversion.Both)) { LineCurve ln = new LineCurve(crv); GsaElement1d tmpelem = new GsaElement1d(ln) { ID = elem.ID, Element = elem.Element, ReleaseEnd = elem.ReleaseEnd, ReleaseStart = elem.ReleaseStart }; elem = tmpelem; } } // 2 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } elem.Section = section; } // 3 offset GsaOffset offset = new GsaOffset(); if (DA.GetData(3, ref offset)) { elem.Element.Offset.X1 = offset.X1; elem.Element.Offset.X2 = offset.X2; elem.Element.Offset.Y = offset.Y; elem.Element.Offset.Z = offset.Z; } // 4 start release GsaBool6 start = new GsaBool6(); if (DA.GetData(4, ref start)) { elem.ReleaseStart = start; //should handle setting the release in elem.Element.SetRelease } // 5 end release GsaBool6 end = new GsaBool6(); if (DA.GetData(5, ref end)) { elem.ReleaseEnd = end; //should handle setting the release in elem.Element.SetRelease } // 6 orientation angle GH_Number ghangle = new GH_Number(); if (DA.GetData(6, ref ghangle)) { if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both)) { elem.Element.OrientationAngle = angle; } } // 7 orientation node GH_Integer ghori = new GH_Integer(); if (DA.GetData(7, ref ghori)) { if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both)) { elem.Element.OrientationNode = orient; } } // 8 type GH_Integer ghinteg = new GH_Integer(); if (DA.GetData(8, ref ghinteg)) { if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both)) { elem.Element.Type = Util.Gsa.GsaToModel.Element1dType(type); } } // 9 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(9, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { elem.ID = id; } } // 10 name GH_String ghnm = new GH_String(); if (DA.GetData(10, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { elem.Element.Name = name; } } // 11 Group GH_Integer ghgrp = new GH_Integer(); if (DA.GetData(11, ref ghgrp)) { if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both)) { elem.Element.Group = grp; } } // 12 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(12, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { elem.Element.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaElement1dGoo(elem)); DA.SetData(1, elem.Line); DA.SetData(2, elem.Section); GsaOffset offset1 = new GsaOffset { X1 = elem.Element.Offset.X1, X2 = elem.Element.Offset.X2, Y = elem.Element.Offset.Y, Z = elem.Element.Offset.Z }; DA.SetData(3, offset1); DA.SetData(4, elem.ReleaseStart); DA.SetData(5, elem.ReleaseEnd); DA.SetData(6, elem.Element.OrientationAngle); DA.SetData(7, elem.Element.OrientationNode); DA.SetData(8, elem.Element.Type); DA.SetData(9, elem.ID); DA.SetData(10, elem.Element.Name); DA.SetData(11, elem.Element.Group); DA.SetData(12, elem.Element.Colour); try { DA.SetData(13, elem.Element.ParentMember.Member); } catch (Exception) { } //DA.SetData(16, gsaElement1d.Element.IsDummy); } }
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; } } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaFaceLoad faceLoad = new GsaFaceLoad(); // 0 Load case int lc = 1; GH_Integer gh_lc = new GH_Integer(); if (DA.GetData(0, ref gh_lc)) { GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both); } faceLoad.FaceLoad.Case = lc; // 1 element/beam list string elemList = ""; GH_String gh_el = new GH_String(); if (DA.GetData(1, ref gh_el)) { GH_Convert.ToString(gh_el, out elemList, GH_Conversion.Both); } //var isNumeric = int.TryParse(elemList, out int n); //if (isNumeric) // elemList = "PA" + n; faceLoad.FaceLoad.Elements = elemList; // 2 Name string name = ""; GH_String gh_name = new GH_String(); if (DA.GetData(2, ref gh_name)) { if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both)) { faceLoad.FaceLoad.Name = name; } } // 3 axis int axis = -1; faceLoad.FaceLoad.AxisProperty = 0; //Note there is currently a bug/undocumented in GsaAPI that cannot translate an integer into axis type (Global, Local or edformed local) GH_Integer gh_ax = new GH_Integer(); if (DA.GetData(3, ref gh_ax)) { GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both); if (axis == 0 || axis == -1) { faceLoad.FaceLoad.AxisProperty = axis; } } // 4 direction string dir = "Z"; Direction direc = Direction.Z; GH_String gh_dir = new GH_String(); if (DA.GetData(4, ref gh_dir)) { GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both); } dir = dir.ToUpper().Trim(); if (dir == "X") { direc = Direction.X; } if (dir == "Y") { direc = Direction.Y; } faceLoad.FaceLoad.Direction = direc; switch (_mode) { case FoldMode.Uniform: if (_mode == FoldMode.Uniform) { faceLoad.FaceLoad.Type = FaceLoadType.CONSTANT; //projection bool prj = false; GH_Boolean gh_prj = new GH_Boolean(); if (DA.GetData(5, ref gh_prj)) { GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both); } faceLoad.FaceLoad.IsProjected = prj; double load1 = 0; if (DA.GetData(6, ref load1)) { if (direc == Direction.Z) { load1 *= -1000; //convert to kN } else { load1 *= 1000; } } // set position and value faceLoad.FaceLoad.SetValue(0, load1); } break; case FoldMode.Variable: if (_mode == FoldMode.Variable) { faceLoad.FaceLoad.Type = FaceLoadType.GENERAL; //projection bool prj = false; GH_Boolean gh_prj = new GH_Boolean(); if (DA.GetData(5, ref gh_prj)) { GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both); } faceLoad.FaceLoad.IsProjected = prj; double load1 = 0; if (DA.GetData(6, ref load1)) { if (direc == Direction.Z) { load1 *= -1000; //convert to kN } else { load1 *= 1000; } } double load2 = 0; if (DA.GetData(7, ref load2)) { if (direc == Direction.Z) { load2 *= -1000; //convert to kN } else { load2 *= 1000; } } double load3 = 0; if (DA.GetData(8, ref load3)) { if (direc == Direction.Z) { load3 *= -1000; //convert to kN } else { load3 *= 1000; } } double load4 = 0; if (DA.GetData(9, ref load4)) { if (direc == Direction.Z) { load4 *= -1000; //convert to kN } else { load4 *= 1000; } } // set value faceLoad.FaceLoad.SetValue(0, load1); faceLoad.FaceLoad.SetValue(1, load2); faceLoad.FaceLoad.SetValue(2, load3); faceLoad.FaceLoad.SetValue(3, load4); } break; case FoldMode.Point: if (_mode == FoldMode.Point) { faceLoad.FaceLoad.Type = FaceLoadType.POINT; //projection bool prj = false; GH_Boolean gh_prj = new GH_Boolean(); if (DA.GetData(5, ref gh_prj)) { GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both); } faceLoad.FaceLoad.IsProjected = prj; double load1 = 0; if (DA.GetData(6, ref load1)) { if (direc == Direction.Z) { load1 *= -1000; //convert to kN } else { load1 *= 1000; } } double r = 0; DA.GetData(7, ref r); double s = 0; DA.GetData(8, ref s); // set position and value faceLoad.FaceLoad.SetValue(0, load1); //faceLoad.Position.X = r; //note Vector2 currently only get in GsaAPI //faceLoad.Position.Y = s; } break; case FoldMode.Edge: if (_mode == FoldMode.Edge) { //faceLoad.Type = BeamLoadType.EDGE; GsaAPI implementation missing // get data int edge = 1; DA.GetData(5, ref edge); double load1 = 0; if (DA.GetData(6, ref load1)) { if (direc == Direction.Z) { load1 *= -1000; //convert to kN } else { load1 *= 1000; } } double load2 = 0; if (DA.GetData(7, ref load2)) { if (direc == Direction.Z) { load2 *= -1000; //convert to kN } else { load2 *= 1000; } } // set value faceLoad.FaceLoad.SetValue(0, load1); faceLoad.FaceLoad.SetValue(1, load2); //faceLoad.Edge = edge; //note implementation of edge-load is not yet supported in GsaAPI faceLoad = null; } break; default: throw new ArgumentOutOfRangeException(); } GsaLoad gsaLoad = new GsaLoad(faceLoad); DA.SetData(0, new GsaLoadGoo(gsaLoad)); }
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) { GsaNode gsaNode = new GsaNode(); if (!DA.GetData(0, ref gsaNode)) { gsaNode = new GsaNode(new Point3d(0, 0, 0)); } if (gsaNode != null) { // #### inputs #### GH_Integer ghInt = new GH_Integer(); if (DA.GetData(1, ref ghInt)) { if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both)) { gsaNode.ID = id; } } GH_String ghStr = new GH_String(); if (DA.GetData(2, ref ghStr)) { if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both)) { gsaNode.Node.Name = name; } } GH_Point ghPt = new GH_Point(); if (DA.GetData(3, ref ghPt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both)) { gsaNode.Point = pt; gsaNode.Node.Position.X = pt.X; gsaNode.Node.Position.Y = pt.Y; gsaNode.Node.Position.Z = pt.Z; } } GH_Plane ghPln = new GH_Plane(); if (DA.GetData(4, ref ghPln)) { Plane pln = new Plane(); if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both)) { pln.Origin = gsaNode.Point; gsaNode.LocalAxis = pln; } } GsaBool6 restraint = new GsaBool6(); if (DA.GetData(5, ref restraint)) { restraint.X = gsaNode.Node.Restraint.X; restraint.Y = gsaNode.Node.Restraint.Y; restraint.Z = gsaNode.Node.Restraint.Z; restraint.XX = gsaNode.Node.Restraint.XX; restraint.YY = gsaNode.Node.Restraint.YY; restraint.ZZ = gsaNode.Node.Restraint.ZZ; } GsaSpring spring = new GsaSpring(); if (DA.GetData(6, ref spring)) { if (gsaNode.Spring != null) { gsaNode.Spring = spring; } } // #### outputs #### DA.SetData(0, new GsaNodeGoo(gsaNode)); DA.SetData(1, gsaNode.ID); DA.SetData(2, gsaNode.Node.Name); DA.SetData(3, gsaNode.Point); DA.SetData(4, gsaNode.LocalAxis); GsaBool6 restraint1 = new GsaBool6 { X = gsaNode.Node.Restraint.X, Y = gsaNode.Node.Restraint.Y, Z = gsaNode.Node.Restraint.Z, XX = gsaNode.Node.Restraint.XX, YY = gsaNode.Node.Restraint.YY, ZZ = gsaNode.Node.Restraint.ZZ }; DA.SetData(5, restraint1); GsaSpring spring1 = new GsaSpring(); if (gsaNode.Spring != null) { spring1 = gsaNode.Spring.Duplicate(); } DA.SetData(6, new GsaSpringGoo(spring1)); try { DA.SetDataList(7, gsaNode.Node.ConnectedElements); } catch (Exception) { } try { DA.SetDataList(8, gsaNode.Node.ConnectedMembers); } catch (Exception) { } } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(0, ref ghcrv)) { if (ghcrv == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Curve input is null"); } Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d mem = new GsaMember1d(crv); GsaBool6 rel1 = new GsaBool6 { X = x1, Y = y1, Z = z1, XX = xx1, YY = yy1, ZZ = zz1 }; mem.ReleaseStart = rel1; GsaBool6 rel2 = new GsaBool6 { X = x2, Y = y2, Z = z2, XX = xx2, YY = yy2, ZZ = zz2 }; mem.ReleaseEnd = rel2; // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); mem.Section = section; } 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 PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaMember1dGoo(mem)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection gsaSection = new GsaSection(); if (DA.GetData(0, ref gsaSection)) { if (gsaSection != null) { // #### input #### // 1 profile string profile = ""; if (DA.GetData(1, ref profile)) { gsaSection.Section.Profile = profile; } // 2 Material // to be implemented // 3 analysis type int analtype = 0; //prop.Prop2d.Thickness; if (DA.GetData(3, ref analtype)) { gsaSection.Section.MaterialAnalysisProperty = analtype; } // 4 section pool int pool = 0; //prop.Prop2d.Thickness; if (DA.GetData(4, ref pool)) { gsaSection.Section.Pool = pool; } // 5 offset int offset = 0; 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)) { gsaSection.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)) { gsaSection.Section.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)) { gsaSection.Section.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaSectionGoo(gsaSection)); DA.SetData(1, gsaSection.Section.Profile.Replace("%", " ")); //DA.SetData(2, gsaProp2d.Prop2d.Material); // to be implemented DA.SetData(3, gsaSection.Section.MaterialAnalysisProperty); DA.SetData(4, gsaSection.Section.Pool); //DA.SetData(5, gsaSection.Section.Offset); DA.SetData(6, gsaSection.ID); DA.SetData(7, gsaSection.Section.Name); DA.SetData(8, gsaSection.Section.Colour); } } }
protected override void SolveInstance(IGH_DataAccess DA) { // Model to work on GsaModel in_Model = new GsaModel(); // Get Model GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { #region Inputs if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref in_Model); if (gsaModel != null) { if (in_Model.GUID != gsaModel.GUID) { gsaModel = in_Model; getresults = true; } } else { gsaModel = in_Model; } } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } // Get analysis case GH_Integer gh_aCase = new GH_Integer(); DA.GetData(1, ref gh_aCase); GH_Convert.ToInt32(gh_aCase, out int tempanalCase, GH_Conversion.Both); // Get node filter list GH_String gh_noList = new GH_String(); DA.GetData(2, ref gh_noList); GH_Convert.ToString(gh_noList, out string tempnodeList, GH_Conversion.Both); // Get colours List <Grasshopper.Kernel.Types.GH_Colour> gh_Colours = new List <Grasshopper.Kernel.Types.GH_Colour>(); List <System.Drawing.Color> colors = new List <System.Drawing.Color>(); if (DA.GetDataList(3, gh_Colours)) { for (int i = 0; i < gh_Colours.Count; i++) { System.Drawing.Color color = new System.Drawing.Color(); GH_Convert.ToColor(gh_Colours[i], out color, GH_Conversion.Both); colors.Add(color); } } Grasshopper.GUI.Gradient.GH_Gradient gH_Gradient = UI.Colour.Stress_Gradient(colors); // Get scalar GH_Number gh_Scale = new GH_Number(); DA.GetData(4, ref gh_Scale); double scale = 1; GH_Convert.ToDouble(gh_Scale, out scale, GH_Conversion.Both); #endregion #region get results? // check if we must get results or just update display if (analCase == 0 || analCase != tempanalCase) { analCase = tempanalCase; getresults = true; } if (nodeList == "" || nodeList != tempnodeList) { nodeList = tempnodeList; getresults = true; } #endregion if (getresults) { #region Get results from GSA // ### Get results ### //Get analysis case from model AnalysisCaseResult analysisCaseResult = null; gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult); if (analysisCaseResult == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file"); return; } IReadOnlyDictionary <int, NodeResult> results = analysisCaseResult.NodeResults(nodeList); IReadOnlyDictionary <int, Node> nodes = gsaModel.Model.Nodes(nodeList); #endregion #region Create results output // ### Loop through results ### // clear any existing lists of vectors to output results in: xyz = new List <Vector3d>(); xxyyzz = new List <Vector3d>(); // maximum and minimum result values for colouring later dmax_x = 0; dmax_y = 0; dmax_z = 0; dmax_xx = 0; dmax_yy = 0; dmax_zz = 0; dmax_xyz = 0; dmax_xxyyzz = 0; dmin_x = 0; dmin_y = 0; dmin_z = 0; dmin_xx = 0; dmin_yy = 0; dmin_zz = 0; dmin_xyz = 0; dmin_xxyyzz = 0; double unitfactorxyz = 1; double unitfactorxxyyzz = 1; // if reaction type, then we reuse the nodeList to filter support nodes from the rest if (_mode == FoldMode.Reaction) { nodeList = ""; } foreach (var key in results.Keys) { NodeResult result; Double6 values = null; if (_mode == FoldMode.Reaction) { bool isSupport = false; Node node = new Node(); nodes.TryGetValue(key, out node); NodalRestraint rest = node.Restraint; if (rest.X || rest.Y || rest.Z || rest.XX || rest.YY || rest.ZZ) { isSupport = true; } if (!isSupport) { continue; } else { if (nodeList == "") { nodeList = key.ToString(); } else { nodeList += " " + key; } } } results.TryGetValue(key, out result); switch (_mode) { case (FoldMode.Displacement): values = result.Displacement; unitfactorxyz = 0.001; unitfactorxxyyzz = 1; break; case (FoldMode.Reaction): values = result.Reaction; unitfactorxyz = 1000; unitfactorxxyyzz = 1000; break; case (FoldMode.SpringForce): values = result.SpringForce; unitfactorxyz = 1000; unitfactorxxyyzz = 1000; break; case (FoldMode.Constraint): values = result.Constraint; break; } // update max and min values if (values.X / unitfactorxyz > dmax_x) { dmax_x = values.X / unitfactorxyz; } if (values.Y / unitfactorxyz > dmax_y) { dmax_y = values.Y / unitfactorxyz; } if (values.Z / unitfactorxyz > dmax_z) { dmax_z = values.Z / unitfactorxyz; } if (Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz > dmax_xyz) { dmax_xyz = Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz; } if (values.XX / unitfactorxxyyzz > dmax_xx) { dmax_xx = values.XX / unitfactorxxyyzz; } if (values.YY / unitfactorxxyyzz > dmax_yy) { dmax_yy = values.YY / unitfactorxxyyzz; } if (values.ZZ / unitfactorxxyyzz > dmax_zz) { dmax_zz = values.ZZ / unitfactorxxyyzz; } if (Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz > dmax_xxyyzz) { dmax_xxyyzz = Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz; } if (values.X / unitfactorxyz < dmin_x) { dmin_x = values.X / unitfactorxyz; } if (values.Y / unitfactorxyz < dmin_y) { dmin_y = values.Y / unitfactorxyz; } if (values.Z / unitfactorxyz < dmin_z) { dmin_z = values.Z / unitfactorxyz; } if (Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz < dmin_xyz) { dmin_xyz = Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz; } if (values.XX / unitfactorxxyyzz < dmin_xx) { dmin_xx = values.XX / unitfactorxxyyzz; } if (values.YY / unitfactorxxyyzz < dmin_yy) { dmin_yy = values.YY / unitfactorxxyyzz; } if (values.ZZ / unitfactorxxyyzz < dmin_zz) { dmin_zz = values.ZZ / unitfactorxxyyzz; } if (Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz < dmin_xxyyzz) { dmin_xxyyzz = Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz; } // add the values to the vector lists xyz.Add(new Vector3d(values.X / unitfactorxyz, values.Y / unitfactorxyz, values.Z / unitfactorxyz)); xxyyzz.Add(new Vector3d(values.XX / unitfactorxxyyzz, values.YY / unitfactorxxyyzz, values.ZZ / unitfactorxxyyzz)); } #endregion getresults = false; } #region Result point values // ### Coloured Result Points ### // Get nodes for point location and restraint check in case of reaction force IReadOnlyDictionary <int, Node> nDict = gsaModel.Model.Nodes(nodeList); List <GsaNodeGoo> gsanodes = Util.Gsa.FromGSA.GetNodes(nDict, gsaModel.Model); //Find Colour and Values for legend output List <double> ts = new List <double>(); List <System.Drawing.Color> cs = new List <System.Drawing.Color>(); // round max and min to reasonable numbers double dmax = 0; double dmin = 0; switch (_disp) { case (DisplayValue.X): dmax = dmax_x; dmin = dmin_x; break; case (DisplayValue.Y): dmax = dmax_y; dmin = dmin_y; break; case (DisplayValue.Z): dmax = dmax_z; dmin = dmin_z; break; case (DisplayValue.resXYZ): dmax = dmax_xyz; dmin = dmin_xyz; break; case (DisplayValue.XX): dmax = dmax_xx; dmin = dmin_xx; break; case (DisplayValue.YY): dmax = dmax_yy; dmin = dmin_yy; break; case (DisplayValue.ZZ): dmax = dmax_zz; dmin = dmin_zz; break; case (DisplayValue.resXXYYZZ): dmax = dmax_xxyyzz; dmin = dmin_xxyyzz; break; } List <double> rounded = Util.Gsa.ResultHelper.SmartRounder(dmax, dmin); dmax = rounded[0]; dmin = rounded[1]; // Loop through nodes and set result colour into ResultPoint format List <ResultPoint> pts = new List <ResultPoint>(); List <System.Drawing.Color> col = new List <System.Drawing.Color>(); for (int i = 0; i < gsanodes.Count; i++) { if (gsanodes[i].Value != null) { if (!(dmin == 0 & dmax == 0)) { double t = 0; Vector3d translation = new Vector3d(0, 0, 0); // pick the right value to display switch (_disp) { case (DisplayValue.X): t = xyz[i].X; translation.X = t * Value / 1000; break; case (DisplayValue.Y): t = xyz[i].Y; translation.Y = t * Value / 1000; break; case (DisplayValue.Z): t = xyz[i].Z; translation.Z = t * Value / 1000; break; case (DisplayValue.resXYZ): t = Math.Sqrt(Math.Pow(xyz[i].X, 2) + Math.Pow(xyz[i].Y, 2) + Math.Pow(xyz[i].Z, 2)); translation.X = xyz[i].X * Value / 1000; translation.Y = xyz[i].Y * Value / 1000; translation.Z = xyz[i].Z * Value / 1000; break; case (DisplayValue.XX): t = xxyyzz[i].X; break; case (DisplayValue.YY): t = xxyyzz[i].Y; break; case (DisplayValue.ZZ): t = xxyyzz[i].Z; break; case (DisplayValue.resXXYYZZ): t = Math.Sqrt(Math.Pow(xxyyzz[i].X, 2) + Math.Pow(xxyyzz[i].Y, 2) + Math.Pow(xxyyzz[i].Z, 2)); break; } //normalised value between -1 and 1 double tnorm = 2 * (t - dmin) / (dmax - dmin) - 1; // get colour for that normalised value System.Drawing.Color valcol = gH_Gradient.ColourAt(tnorm); // set the size of the point for ResultPoint class. Size is calculated from 0-base, so not a normalised value between extremes float size = (t >= 0 && dmax != 0) ? Math.Max(2, (float)(t / dmax * scale)) : Math.Max(2, (float)(Math.Abs(t) / Math.Abs(dmin) * scale)); // create deflection point Point3d def = new Point3d(gsanodes[i].Value.Point); def.Transform(Transform.Translation(translation)); // add our special resultpoint to the list of points pts.Add(new ResultPoint(def, t, valcol, size)); // add the colour to the colours list col.Add(valcol); } } } #endregion #region Legend // ### Legend ### // loop through number of grip points in gradient to create legend for (int i = 0; i < gH_Gradient.GripCount; i++) { double t = dmin + (dmax - dmin) / ((double)gH_Gradient.GripCount - 1) * (double)i; double scl = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(t))) + 1); scl = Math.Max(scl, 1); t = scl * Math.Round(t / scl, 3); ts.Add(t); System.Drawing.Color gradientcolour = gH_Gradient.ColourAt(2 * (double)i / ((double)gH_Gradient.GripCount - 1) - 1); cs.Add(gradientcolour); } #endregion // set outputs DA.SetDataList(0, xyz); DA.SetDataList(1, xxyyzz); DA.SetDataList(2, pts); DA.SetDataList(3, col); DA.SetDataList(4, cs); DA.SetDataList(5, ts); } }
public override bool CastFrom(object source) { if (source == null) { return(false); } int val; LayerTable LT = Rhino.RhinoDoc.ActiveDoc.Layers; if (GH_Convert.ToInt32(source, out val, GH_Conversion.Both)) { Rhino.DocObjects.Layer La = LT.FindIndex(val); if (La == null) { Value = null; return(false); } else { Value = La; return(true); } } Guid id; if (GH_Convert.ToGUID(source, out id, GH_Conversion.Both)) { Rhino.DocObjects.Layer La = LT.FindId(id); if (La == null) { Value = null; return(false); } else { Value = La; return(true); } } string Name; if (GH_Convert.ToString(source, out Name, GH_Conversion.Both)) { int Index = LT.FindByFullPath(Name, -1); if (Index == -1) { Rhino.DocObjects.Layer La = new Layer(); La.Name = Name; Value = La; return(true); } else { Value = LT.FindIndex(Index); return(true); } } if (source.GetType() == typeof(Layer)) { Value = (Layer)source; return(true); } if (source.GetType() == typeof(Hu_Layer)) { Value = ((Hu_Layer)source).Value; return(true); } return(false); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { if (GH_Document.IsEscapeKeyDown()) { GH_Document GHDocument = OnPingDocument(); GHDocument.RequestAbortSolution(); return; } ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("culebra")); ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("IKVM.OpenJDK.Core")); bool reset = new bool(); int iterations = new int(); List <object> init_Settings = new List <object>(); List <object> move_Settings = new List <object>(); IGH_VisualData visual_Settings = null; object behavioral_Settings = null; if (!DA.GetDataList(0, init_Settings) || init_Settings.Count == 0 || init_Settings == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Init Settings Detected, please connect Init Settings to enable the component"); return; } if (!DA.GetDataList(1, move_Settings) || move_Settings.Count == 0 || move_Settings == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Move Settings Detected, please connect Move Settings to enable the component"); return; } if (!DA.GetData(3, ref visual_Settings) || visual_Settings == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Visual Settings Detected, please connect Visual Settings to enable the component"); return; } if (!DA.GetData(4, ref iterations)) { return; } if (!DA.GetData(5, ref reset)) { return; } Random rnd = new Random(); if (!DA.GetData(2, ref behavioral_Settings) || behavioral_Settings == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input Object is Null"); return; } string objtype = behavioral_Settings.GetType().Name.ToString(); if (!(behavioral_Settings.GetType() == typeof(IGH_BehaviorData))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You did not input a Behavior Data Object, please ensure input is Behavior Data Object and not " + objtype); return; } else { #region Initialize / Data Parse //------------------------Init Settings-------------------------- if (init_Settings.Count != 0) { String init_Convert = ""; if (init_Settings[0].GetType() == typeof(GH_String)) { GH_String value = (GH_String)init_Settings[0]; init_Convert = value.Value; } if (init_Convert == "Box") { this.spawnData = "box"; GH_Convert.ToBox_Primary(init_Settings[3], ref this.box); GH_Convert.ToInt32(init_Settings[4], out this.spawnType, GH_Conversion.Primary); GH_Convert.ToInt32(init_Settings[5], out this.pointCount, GH_Conversion.Primary); GH_Convert.ToInt32(init_Settings[1], out this.dimensions, GH_Conversion.Primary); } else if (init_Convert == "Points") { this.spawnData = "Points"; var wrapperToGoo = GH_Convert.ToGoo(init_Settings[3]); wrapperToGoo.CastTo <List <Point3d> >(out this.ptList); GH_Convert.ToInt32(init_Settings[1], out this.dimensions, GH_Conversion.Primary); GH_Convert.ToBox_Primary(init_Settings[4], ref this.box); } GH_Convert.ToInt32(init_Settings[2], out this.bounds, GH_Conversion.Primary); } //------------------------Move Settings-------------------------- Vector3d initialVector = new Vector3d(); if (move_Settings.Count != 0) { if (move_Settings[0].GetType() == typeof(GH_Vector)) { GH_Vector value = (GH_Vector)move_Settings[0]; initialVector = value.Value; } else if (move_Settings[0].GetType() == typeof(GH_Number)) { GH_Number value = (GH_Number)move_Settings[0]; this.initialSpeed = value.Value; } GH_Convert.ToDouble(move_Settings[1], out this.maxSpeed, GH_Conversion.Primary); GH_Convert.ToDouble(move_Settings[2], out this.maxForce, GH_Conversion.Primary); GH_Convert.ToDouble(move_Settings[3], out this.velMultiplier, GH_Conversion.Primary); } //------------------------Visual Settings-------------------------- TrailData td = visual_Settings.Value.trailData; ColorData cd = visual_Settings.Value.colorData; this.trail = td.createTrail; this.displayMode = visual_Settings.Value.displayMode; this.trailStep = td.trailStep; this.maxTrailSize = td.maxTrailSize; this.particleTexture = cd.particleTexture; this.graphicType = cd.colorDataType; this.useTexture = visual_Settings.Value.useTexture; if (cd.colorDataType == "Gradient") { this.maxthick = cd.maxThickness; this.minthick = cd.minThickness; this.redValues[0] = cd.redChannel[0]; this.redValues[1] = cd.redChannel[1]; this.greenValues[0] = cd.greenChannel[0]; this.greenValues[1] = cd.greenChannel[1]; this.blueValues[0] = cd.blueChannel[0]; this.blueValues[1] = cd.blueChannel[1]; } else if (cd.colorDataType == "GraphicPolyline") { this.polylineColor = cd.color; this.dotted = cd.dotted; this.maxthick = cd.maxThickness; } else if (cd.colorDataType == "Disco") { this.maxthick = cd.maxThickness; this.minthick = cd.minThickness; } else if (cd.colorDataType == "Base") { this.maxthick = 3; this.minthick = 1; } //----------------------------------------------------------------- IGH_PreviewObject comp = (IGH_PreviewObject)this; if (comp.Hidden && (this.displayMode == 0)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Component preview must be enabled to see Graphic Mode on Canvas, right click on component and set preview on"); } #endregion #region Pre Simulation Code //------------------------RESET STARTS HERE-------------------------- if (reset) { //We are using the reset to reinitialize all the variables and positions //----------------------------------------------------------------- this.bb = new BoundingBox(); int loopCount = new int(); bool create = new bool(); if (this.spawnData == "box") { this.bb = this.box.BoundingBox; loopCount = this.pointCount; create = true; } else if (this.spawnData == "Points") { loopCount = this.ptList.Count; create = false; this.bb = this.box.BoundingBox; } //----------------------------------------------------------------- this.moveList = new List <Vector3d>(); this.startList = new List <Vector3d>(); this.creepList = new List <CulebraObject>(); this.currentPosList = new List <Point3d>(); this.networkList = new List <Line>(); flattenedTrails = new List <Vector3d>(); for (int i = 0; i < loopCount; i++) { if (this.dimensions == 0) { //If we want 2D General.setViewport("Top", "Shaded"); if (create) { //If are creating random points inside bbox if (this.spawnType == 0 || this.spawnType == 2) { this.startPos = new Vector3d((int)bb.Min[0], rnd.Next((int)bb.Min[1], (int)bb.Max[1]), 0); //spawn along the y axis of the bounding area } else if (this.spawnType == 1 || this.spawnType == 3) { this.startPos = new Vector3d(rnd.Next((int)bb.Min[0], (int)bb.Max[0]), rnd.Next((int)bb.Min[1], (int)bb.Max[1]), 0); //spawn randomly inside the bounding area } if (initialVector.Length > 0) { this.moveVec = initialVector; //move in the user specified direction } else { this.moveVec = new Vector3d(rnd.Next(-1, 2) * initialSpeed, rnd.Next(-1, 2) * initialSpeed, 0); //move randomly in any direction 2d } } else { //If we are using user defined points this.startPos = (Vector3d)this.ptList[i]; if (initialVector.Length > 0) { this.moveVec = initialVector; //move in the user specified direction } else { this.moveVec = new Vector3d(rnd.Next(-1, 2) * initialSpeed, rnd.Next(-1, 2) * initialSpeed, 0); //move randomly in any direction 2d } } this.creep = new Creeper(this.startPos, this.moveVec, true, false); this.creepList.Add(this.creep); } else { //If we want 3D General.setViewport("Perspective", "Shaded"); if (create) { //If are creating random points inside bbox if (this.spawnType == 0 || this.spawnType == 2) { this.startPos = new Vector3d(rnd.Next((int)bb.Min[0], (int)bb.Max[0]), rnd.Next((int)bb.Min[1], (int)bb.Max[1]), (int)bb.Min[2]); //start randomly on the lowest plane of the 3d bounds if (initialVector.Length > 0) { this.moveVec = initialVector; //move in the user specified direction } else { this.moveVec = new Vector3d(rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed, 1 * initialSpeed); //move randomly in the xy axis and up in the z axis } } else if (this.spawnType == 1 || this.spawnType == 3) { this.startPos = new Vector3d(rnd.Next((int)bb.Min[0], (int)bb.Max[0]), rnd.Next((int)bb.Min[1], (int)bb.Max[1]), rnd.Next((int)bb.Min[2], (int)bb.Max[2])); //start randomly inside the 3d bounds if (initialVector.Length > 0) { this.moveVec = initialVector; //move in the user specified direction } else { this.moveVec = new Vector3d(rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed); //move randomly in any direction 3d } } } else { //If we are using user defined points this.startPos = (Vector3d)this.ptList[i]; if (initialVector.Length > 0) { this.moveVec = initialVector; //move in the user specified direction } else { this.moveVec = new Vector3d(rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed); //move randomly in any direction 3d } } this.creep = new Creeper(this.startPos, this.moveVec, true, true); this.creepList.Add(this.creep); } this.startList.Add(this.startPos); //add the initial starting positions to the list to pass once we start running this.moveList.Add(this.moveVec); //add the initial move vectors to the list to pass once we start running } #endregion #region Simulation Code this.trailTree = new DataTree <Point3d>(); this.globalEngine = new Engine_Global(); for (int z = 0; z < iterations; z++) { this.particleSet = new DataTree <Point3d>(); this.currentPosList = new List <Point3d>(); this.trailTree.Clear(); this.networkTree.Clear(); this.trailTree.TrimExcess(); this.networkTree.TrimExcess(); if (this.moveList == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please Reset the CreepyCrawlers Component"); return; } try { globalEngine.Action(this.creepList, this.dimensions, behavioral_Settings, this.displayMode, this.networkList, this.maxSpeed, this.maxForce, this.velMultiplier, this.flattenedTrails, this.particleList, this.particleSet, networkTree, trailStep, maxTrailSize, bounds, bb, currentPosList, trail, trailTree); } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.ToString()); return; } this.flattenedTrails.Clear(); this.flattenedTrails.TrimExcess(); #endregion } DA.SetDataList(0, this.currentPosList); DA.SetDataTree(2, networkTree); if (this.displayMode == 1 && this.trail) { DA.SetDataTree(1, trailTree); } } } }
///////////////////////////////////////// CastFrom ////////////////////////////////////////// public override bool CastFrom(object source) { //Abort immediately on bogus data. if (source == null) { return(false); } //Type t = source.GetType(); // I don't yet understand this method very well. If I use a recommended conversion like: // GH_Convert.ToInt32(source, out val, GH_Conversion.Both) // I think I will get reals converted to ints (?). Likewise, if I do GH_Convert.ToDouble(), I think // I will get integers converted to reals. I don't want either of these, so instead I first try // inspecting the raw type. LAter I fall through to GH_Convert methods. // I don't know what types Grasshopper will ever give me. Maybe it never uses float, for example? What about, say, char or uint? if (source is int || source is long || source is float || source is double || source is bool || source is string) { Value = new Expr(source); return(true); } else if (source is GH_Integer) { int val; GH_Convert.ToInt32(source, out val, GH_Conversion.Both); this.Value = new Expr(val); return(true); } else if (source is GH_Number) { double val; GH_Convert.ToDouble(source, out val, GH_Conversion.Both); this.Value = new Expr(val); return(true); } else if (source is GH_Boolean) { bool val; GH_Convert.ToBoolean(source, out val, GH_Conversion.Both); this.Value = new Expr(val); return(true); } // Try a series of conversions. double dval; if (GH_Convert.ToDouble(source, out dval, GH_Conversion.Both)) { this.Value = new Expr(dval); return(true); } int ival; if (GH_Convert.ToInt32(source, out ival, GH_Conversion.Both)) { this.Value = new Expr(ival); return(true); } string str = null; if (GH_Convert.ToString(source, out str, GH_Conversion.Both)) { this.Value = new Expr(str); return(true); } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { // Model to work on GsaModel gsaModel = new GsaModel(); // Get Model GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { #region Inputs if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref gsaModel); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } // Get analysis case GH_Integer gh_aCase = new GH_Integer(); DA.GetData(1, ref gh_aCase); int analCase = 1; GH_Convert.ToInt32(gh_aCase, out analCase, GH_Conversion.Both); #endregion #region Get results from GSA // ### Get results ### //Get analysis case from model AnalysisCaseResult analysisCaseResult = null; gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult); if (analysisCaseResult == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file"); return; } #endregion double unitfactorForce = 1000; double unitfactorMoment = 1000; Vector3d force = new Vector3d( analysisCaseResult.Global.TotalLoad.X / unitfactorForce, analysisCaseResult.Global.TotalLoad.Y / unitfactorForce, analysisCaseResult.Global.TotalLoad.Z / unitfactorForce); Vector3d moment = new Vector3d( analysisCaseResult.Global.TotalLoad.XX / unitfactorMoment, analysisCaseResult.Global.TotalLoad.YY / unitfactorMoment, analysisCaseResult.Global.TotalLoad.ZZ / unitfactorMoment); Vector3d reaction = new Vector3d( analysisCaseResult.Global.TotalReaction.X / unitfactorForce, analysisCaseResult.Global.TotalReaction.Y / unitfactorForce, analysisCaseResult.Global.TotalReaction.Z / unitfactorForce); Vector3d reactionmoment = new Vector3d( analysisCaseResult.Global.TotalReaction.XX / unitfactorMoment, analysisCaseResult.Global.TotalReaction.YY / unitfactorMoment, analysisCaseResult.Global.TotalReaction.ZZ / unitfactorMoment); Vector3d effMass = new Vector3d( analysisCaseResult.Global.EffectiveMass.X, analysisCaseResult.Global.EffectiveMass.Y, analysisCaseResult.Global.EffectiveMass.Z); Vector3d effStiff; if (analysisCaseResult.Global.EffectiveInertia != null) { effStiff = new Vector3d( analysisCaseResult.Global.EffectiveInertia.X, analysisCaseResult.Global.EffectiveInertia.Y, analysisCaseResult.Global.EffectiveInertia.Z); } else { effStiff = new Vector3d(); } Vector3d modal = new Vector3d( analysisCaseResult.Global.ModalMass, analysisCaseResult.Global.ModalStiffness, analysisCaseResult.Global.ModalGeometricStiffness); DA.SetData(0, force); DA.SetData(1, moment); DA.SetData(2, reaction); DA.SetData(3, reactionmoment); DA.SetData(4, effMass); DA.SetData(5, effStiff); DA.SetData(6, analysisCaseResult.Global.Mode); DA.SetData(7, modal); DA.SetData(8, analysisCaseResult.Global.Frequency); DA.SetData(9, analysisCaseResult.Global.LoadFactor); } }
protected override void SolveInstance(IGH_DataAccess DA) { // Model to work on GsaModel in_Model = new GsaModel(); // Get Model GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { #region Inputs if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref in_Model); if (gsaModel != null) { if (in_Model.GUID != gsaModel.GUID) { gsaModel = in_Model; getresults = true; } } else { gsaModel = in_Model; } } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } // Get analysis case GH_Integer gh_aCase = new GH_Integer(); DA.GetData(1, ref gh_aCase); GH_Convert.ToInt32(gh_aCase, out int tempanalCase, GH_Conversion.Both); // Get element filter list GH_String gh_elList = new GH_String(); DA.GetData(2, ref gh_elList); GH_Convert.ToString(gh_elList, out string tempelemList, GH_Conversion.Both); // Get colours List <Grasshopper.Kernel.Types.GH_Colour> gh_Colours = new List <Grasshopper.Kernel.Types.GH_Colour>(); List <System.Drawing.Color> colors = new List <System.Drawing.Color>(); if (DA.GetDataList(3, gh_Colours)) { for (int i = 0; i < gh_Colours.Count; i++) { System.Drawing.Color color = new System.Drawing.Color(); GH_Convert.ToColor(gh_Colours[i], out color, GH_Conversion.Both); colors.Add(color); } } Grasshopper.GUI.Gradient.GH_Gradient gH_Gradient = UI.Colour.Stress_Gradient(colors); #endregion #region get results? // check if we must get results or just update display if (analCase == 0 || analCase != tempanalCase) { analCase = tempanalCase; getresults = true; } if (elemList == "" || elemList != tempelemList) { elemList = tempelemList; getresults = true; } #endregion #region Create results output if (getresults) { #region Get results from GSA // ### Get results ### //Get analysis case from model AnalysisCaseResult analysisCaseResult = null; gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult); if (analysisCaseResult == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file"); return; } IReadOnlyDictionary <int, Element3DResult> globalResults = analysisCaseResult.Element3DResults(elemList); #endregion // ### Loop through results ### // clear existing result lists xyz_out = new DataTree <Vector3d>(); xxyyzz_out = new DataTree <Vector3d>(); // maximum and minimum result values for colouring later dmax_x = 0; dmax_y = 0; dmax_z = 0; dmax_xx = 0; dmax_yy = 0; dmax_zz = 0; dmax_xyz = 0; dmax_xxyyzz = 0; dmin_x = 0; dmin_y = 0; dmin_z = 0; dmin_xx = 0; dmin_yy = 0; dmin_zz = 0; dmin_xyz = 0; dmin_xxyyzz = 0; keys = new List <int>(); double unitfactorxyz = 1; double unitfactorxxyyzz = 1; foreach (int key in globalResults.Keys) { keys.Add(key); // lists for results Element3DResult elementResults; if (globalResults.TryGetValue(key, out elementResults)) { List <Vector3d> xyz = new List <Vector3d>(); List <Vector3d> xxyyzz = new List <Vector3d>(); switch (_mode) { case FoldMode.Displacement: unitfactorxyz = 0.001; List <Double3> trans_vals = elementResults.Displacement.ToList(); foreach (Double3 val in trans_vals) { Vector3d valxyz = new Vector3d { X = val.X / unitfactorxyz, Y = val.Y / unitfactorxyz, Z = val.Z / unitfactorxyz }; xyz.Add(valxyz); } break; case FoldMode.Stress: unitfactorxxyyzz = 1000000; List <Tensor3> stress_vals = elementResults.Stress.ToList(); foreach (Tensor3 val in stress_vals) { Vector3d valxxyyzz = new Vector3d { X = val.XX / unitfactorxxyyzz, Y = val.YY / unitfactorxxyyzz, Z = val.ZZ / unitfactorxxyyzz }; Vector3d valxyyzzx = new Vector3d { X = val.XY / unitfactorxxyyzz, Y = val.YZ / unitfactorxxyyzz, Z = val.ZX / unitfactorxxyyzz }; xyz.Add(valxxyyzz); xxyyzz.Add(valxyyzzx); } break; } // update max and min values dmax_x = Math.Max(xyz.Max(val => val.X), dmax_x); dmax_y = Math.Max(xyz.Max(val => val.Y), dmax_y); dmax_z = Math.Max(xyz.Max(val => val.Z), dmax_z); dmax_xyz = Math.Max( xyz.Max(val => Math.Sqrt( Math.Pow(val.X, 2) + Math.Pow(val.Y, 2) + Math.Pow(val.Z, 2))), dmax_xyz); dmin_x = Math.Min(xyz.Min(val => val.X), dmin_x); dmin_y = Math.Min(xyz.Min(val => val.Y), dmin_y); dmin_z = Math.Min(xyz.Min(val => val.Z), dmin_z); if (_mode == FoldMode.Stress) { dmax_xx = Math.Max(xxyyzz.Max(val => val.X), dmax_xx); dmax_yy = Math.Max(xxyyzz.Max(val => val.Y), dmax_yy); dmax_zz = Math.Max(xxyyzz.Max(val => val.Z), dmax_zz); dmin_xx = Math.Min(xxyyzz.Min(val => val.X), dmin_xx); dmin_yy = Math.Min(xxyyzz.Min(val => val.Y), dmin_yy); dmin_zz = Math.Min(xxyyzz.Min(val => val.Z), dmin_zz); } // add vector lists to main lists xyz_out.AddRange(xyz, new GH_Path(key - 1)); xxyyzz_out.AddRange(xxyyzz, new GH_Path(key - 1)); } } getresults = false; } #endregion #region Result mesh values // ### Coloured Result Meshes ### // round max and min to reasonable numbers double dmax = 0; double dmin = 0; switch (_disp) { case (DisplayValue.X): dmax = dmax_x; dmin = dmin_x; break; case (DisplayValue.Y): dmax = dmax_y; dmin = dmin_y; break; case (DisplayValue.Z): dmax = dmax_z; dmin = dmin_z; break; case (DisplayValue.resXYZ): dmax = dmax_xyz; dmin = dmin_xyz; break; case (DisplayValue.XX): dmax = dmax_xx; dmin = dmin_xx; break; case (DisplayValue.YY): dmax = dmax_yy; dmin = dmin_yy; break; case (DisplayValue.ZZ): dmax = dmax_zz; dmin = dmin_zz; break; case (DisplayValue.resXXYYZZ): dmax = dmax_xxyyzz; dmin = dmin_xxyyzz; break; } List <double> rounded = Util.Gsa.ResultHelper.SmartRounder(dmax, dmin); dmax = rounded[0]; dmin = rounded[1]; #region create mesh // create mesh // get elements and nodes from model elemList = string.Join(" ", keys.ToList()); IReadOnlyDictionary <int, Element> elems = gsaModel.Model.Elements(elemList); IReadOnlyDictionary <int, Node> nodes = gsaModel.Model.Nodes(); List <int> elemID = new List <int>(); List <int> parentMember = new List <int>(); List <ResultMesh> resultMeshes = new List <ResultMesh>(); List <Mesh> meshes = new List <Mesh>(); // loop through elements foreach (int key in elems.Keys) { elems.TryGetValue(key, out Element element); Mesh tempmesh = GhSA.Util.Gsa.FromGSA.ConvertElement3D(element, nodes); if (tempmesh == null) { continue; } List <Vector3d> transformation = null; // add mesh colour List <double> vals = new List <double>(); GH_Path path = new GH_Path(key - 1); List <Vector3d> tempXYZ = xyz_out.Branch(path); List <Vector3d> tempXXYYZZ = xxyyzz_out.Branch(path); switch (_disp) { case (DisplayValue.X): vals = tempXYZ.ConvertAll(val => val.X); transformation = new List <Vector3d>(); for (int i = 0; i < vals.Count; i++) { transformation.Add(new Vector3d(vals[i] * Value / 1000, 0, 0)); } break; case (DisplayValue.Y): vals = tempXYZ.ConvertAll(val => val.Y); transformation = new List <Vector3d>(); for (int i = 0; i < vals.Count; i++) { transformation.Add(new Vector3d(0, vals[i] * Value / 1000, 0)); } break; case (DisplayValue.Z): vals = tempXYZ.ConvertAll(val => val.Z); transformation = new List <Vector3d>(); for (int i = 0; i < vals.Count; i++) { transformation.Add(new Vector3d(0, 0, vals[i] * Value / 1000)); } break; case (DisplayValue.resXYZ): vals = tempXYZ.ConvertAll(val => ( Math.Sqrt( Math.Pow(val.X, 2) + Math.Pow(val.Y, 2) + Math.Pow(val.Z, 2)))); transformation = tempXYZ.ConvertAll(vec => Vector3d.Multiply(Value / 1000, vec)); break; case (DisplayValue.XX): vals = tempXXYYZZ.ConvertAll(val => val.X); break; case (DisplayValue.YY): vals = tempXXYYZZ.ConvertAll(val => val.Y); break; case (DisplayValue.ZZ): vals = tempXXYYZZ.ConvertAll(val => val.Z); break; case (DisplayValue.resXXYYZZ): vals = tempXXYYZZ.ConvertAll(val => ( Math.Sqrt( Math.Pow(val.X, 2) + Math.Pow(val.Y, 2) + Math.Pow(val.Z, 2)))); break; } for (int i = 1; i < vals.Count; i++) // start at i=1 as the first index is the centre point in GsaAPI output { //normalised value between -1 and 1 double tnorm = 2 * (vals[i] - dmin) / (dmax - dmin) - 1; System.Drawing.Color col = (double.IsNaN(tnorm)) ? System.Drawing.Color.Transparent : gH_Gradient.ColourAt(tnorm); tempmesh.VertexColors.Add(col); if (transformation != null) { Point3f def = tempmesh.Vertices[i - 1]; def.Transform(Transform.Translation(transformation[i])); tempmesh.Vertices[i - 1] = def; } } ResultMesh resultMesh = new ResultMesh(tempmesh, vals); meshes.Add(tempmesh); resultMeshes.Add(resultMesh); #endregion elemID.Add(key); parentMember.Add(element.ParentMember.Member); } #endregion #region Legend // ### Legend ### // loop through number of grip points in gradient to create legend //Find Colour and Values for legend output List <double> ts = new List <double>(); List <System.Drawing.Color> cs = new List <System.Drawing.Color>(); for (int i = 0; i < gH_Gradient.GripCount; i++) { double t = dmin + (dmax - dmin) / ((double)gH_Gradient.GripCount - 1) * (double)i; double scl = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(t))) + 1); scl = Math.Max(scl, 1); t = scl * Math.Round(t / scl, 3); ts.Add(t); System.Drawing.Color gradientcolour = gH_Gradient.ColourAt(2 * (double)i / ((double)gH_Gradient.GripCount - 1) - 1); cs.Add(gradientcolour); } #endregion // set outputs int outind = 0; DA.SetDataTree(outind++, xyz_out); if (_mode == FoldMode.Stress) { DA.SetDataTree(outind++, xxyyzz_out); } DA.SetDataList(outind++, resultMeshes); DA.SetDataList(outind++, cs); DA.SetDataList(outind++, ts); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember1d gsaMember1d = new GsaMember1d(); if (DA.GetData(0, ref gsaMember1d)) { if (gsaMember1d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member1D input is null"); } GsaMember1d mem = gsaMember1d.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 curve GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(2, ref ghcrv)) { Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d tempmem = new GsaMember1d(crv); mem.PolyCurve = tempmem.PolyCurve; mem.Topology = tempmem.Topology; mem.TopologyType = tempmem.TopologyType; } } // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); mem.Section = section; mem.Member.Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; mem.Section = null; } 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) { 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; }