protected override void SolveInstance(IGH_DataAccess DA) { GH_Boolean ghBolX = new GH_Boolean(); if (DA.GetData(0, ref ghBolX)) { GH_Convert.ToBoolean(ghBolX, out x, GH_Conversion.Both); //use Grasshopper to convert, these methods covers many cases and are consistent } GH_Boolean ghBolY = new GH_Boolean(); if (DA.GetData(1, ref ghBolY)) { GH_Convert.ToBoolean(ghBolY, out y, GH_Conversion.Both); } GH_Boolean ghBolZ = new GH_Boolean(); if (DA.GetData(2, ref ghBolZ)) { GH_Convert.ToBoolean(ghBolZ, out z, GH_Conversion.Both); } GH_Boolean ghBolXX = new GH_Boolean(); if (DA.GetData(3, ref ghBolXX)) { GH_Convert.ToBoolean(ghBolXX, out xx, GH_Conversion.Both); } GH_Boolean ghBolYY = new GH_Boolean(); if (DA.GetData(4, ref ghBolYY)) { GH_Convert.ToBoolean(ghBolYY, out yy, GH_Conversion.Both); } GH_Boolean ghBolZZ = new GH_Boolean(); if (DA.GetData(5, ref ghBolZZ)) { GH_Convert.ToBoolean(ghBolZZ, out zz, GH_Conversion.Both); } GsaBool6 bool6 = new GsaBool6 { X = x, Y = y, Z = z, XX = xx, YY = yy, ZZ = zz }; DA.SetData(0, new GsaBool6Goo(bool6.Duplicate())); // output as Goo-type for consistency. }
public override bool CastFrom(object source) { // This function is called when Grasshopper needs to convert other data // into GsaBool6. if (source == null) { return(false); } //Cast from GsaBool6 if (typeof(GsaBool6).IsAssignableFrom(source.GetType())) { Value = (GsaBool6)source; return(true); } //Cast from Bool if (GH_Convert.ToBoolean(source, out bool mybool, GH_Conversion.Both)) { Value.X = mybool; Value.Y = mybool; Value.Z = mybool; Value.XX = mybool; Value.YY = mybool; Value.ZZ = mybool; return(true); } //Cast from string if (GH_Convert.ToString(source, out string mystring, GH_Conversion.Both)) { mystring = mystring.Trim(); mystring = mystring.ToLower(); if (mystring == "free") { Value.X = false; Value.Y = false; Value.Z = false; Value.XX = false; Value.YY = false; Value.ZZ = false; return(true); } if (mystring == "pin" | mystring == "pinned") { Value.X = true; Value.Y = true; Value.Z = true; Value.XX = false; Value.YY = false; Value.ZZ = false; return(true); } if (mystring == "fix" | mystring == "fixed") { Value.X = true; Value.Y = true; Value.Z = true; Value.XX = true; Value.YY = true; Value.ZZ = true; return(true); } if (mystring == "release" | mystring == "released" | mystring == "hinge" | mystring == "hinged" | mystring == "charnier") { Value.X = false; Value.Y = false; Value.Z = false; Value.XX = false; Value.YY = true; Value.ZZ = true; return(true); } return(false); } return(false); }
///////////////////////////////////////// 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) { 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) { GsaBeamLoad beamLoad = new GsaBeamLoad(); // 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); } beamLoad.BeamLoad.Case = lc; // 1 element/beam list string beamList = ""; //pick an initial name that is sure not to be used... GH_String gh_bl = new GH_String(); if (DA.GetData(1, ref gh_bl)) { GH_Convert.ToString(gh_bl, out beamList, GH_Conversion.Both); } //var isNumeric = int.TryParse(beamList, out int n); //if (isNumeric) // beamList = "PB" + n; beamLoad.BeamLoad.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)) { beamLoad.BeamLoad.Name = name; } } // 3 axis int axis = 0; beamLoad.BeamLoad.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) { beamLoad.BeamLoad.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; } if (dir == "XX") { direc = Direction.XX; } if (dir == "YY") { direc = Direction.YY; } if (dir == "ZZ") { direc = Direction.ZZ; } beamLoad.BeamLoad.Direction = direc; // 5 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); } beamLoad.BeamLoad.IsProjected = prj; // 6 value (1) double load1 = 0; if (DA.GetData(6, ref load1)) { if (direc == Direction.Z) { load1 *= -1000; //convert to kN } else { load1 *= 1000; } } switch (_mode) { case FoldMode.Point: if (_mode == FoldMode.Point) { beamLoad.BeamLoad.Type = BeamLoadType.POINT; // 7 pos (1) double pos = 0; if (DA.GetData(7, ref pos)) { pos *= -1; } // set position and value beamLoad.BeamLoad.SetValue(0, load1); beamLoad.BeamLoad.SetPosition(0, pos); } break; case FoldMode.Uniform: if (_mode == FoldMode.Uniform) { beamLoad.BeamLoad.Type = BeamLoadType.UNIFORM; // set value beamLoad.BeamLoad.SetValue(0, load1); } break; case FoldMode.Linear: if (_mode == FoldMode.Linear) { beamLoad.BeamLoad.Type = BeamLoadType.LINEAR; // 6 value (2) double load2 = 0; if (DA.GetData(7, ref load2)) { if (direc == Direction.Z) { load2 *= -1000; //convert to kN } else { load2 *= 1000; } } // set value beamLoad.BeamLoad.SetValue(0, load1); beamLoad.BeamLoad.SetValue(1, load2); } break; case FoldMode.Patch: if (_mode == FoldMode.Patch) { beamLoad.BeamLoad.Type = BeamLoadType.PATCH; // 7 pos (1) double pos1 = 0; if (DA.GetData(7, ref pos1)) { pos1 *= -1; } // 9 pos (2) double pos2 = 1; if (DA.GetData(9, ref pos2)) { pos2 *= -1; } // 8 value (2) double load2 = 0; if (DA.GetData(8, ref load2)) { if (direc == Direction.Z) { load2 *= -1000; //convert to kN } else { load2 *= 1000; } } // set value beamLoad.BeamLoad.SetValue(0, load1); beamLoad.BeamLoad.SetValue(1, load2); beamLoad.BeamLoad.SetPosition(0, pos1); beamLoad.BeamLoad.SetPosition(1, pos2); } break; case FoldMode.Trilinear: if (_mode == FoldMode.Trilinear) { beamLoad.BeamLoad.Type = BeamLoadType.TRILINEAR; // 7 pos (1) double pos1 = 0; if (DA.GetData(7, ref pos1)) { pos1 *= -1; } // 9 pos (2) double pos2 = 1; if (DA.GetData(9, ref pos2)) { pos2 *= -1; } // 8 value (2) double load2 = 0; if (DA.GetData(8, ref load2)) { if (direc == Direction.Z) { load2 *= -1000; //convert to kN } else { load2 *= 1000; } } // set value beamLoad.BeamLoad.SetValue(0, load1); beamLoad.BeamLoad.SetValue(1, load2); beamLoad.BeamLoad.SetPosition(0, pos1); beamLoad.BeamLoad.SetPosition(1, pos2); } break; default: throw new ArgumentOutOfRangeException(); } GsaLoad gsaLoad = new GsaLoad(beamLoad); DA.SetData(0, new GsaLoadGoo(gsaLoad)); }
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) { GsaElement3d gsaElement3d = new GsaElement3d(); if (DA.GetData(0, ref gsaElement3d)) { if (gsaElement3d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element3D input is null"); } GsaElement3d elem = gsaElement3d.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); } } } List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); // 2 section //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; // } // } // } //} // 3 Group List <GH_Integer> ghgrp = new List <GH_Integer>(); List <int> in_groups = new List <int>(); if (DA.GetDataList(3, ghgrp)) { for (int i = 0; i < ghgrp.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Group input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Group numbers have been ignored"); continue; } if (GH_Convert.ToInt32(ghgrp[i], out int grp, GH_Conversion.Both)) { in_groups.Add(grp); } } } // 4 name List <GH_String> ghnm = new List <GH_String>(); List <string> in_names = new List <string>(); if (DA.GetDataList(4, ghnm)) { for (int i = 0; i < ghnm.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Name input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Names have been ignored"); continue; } if (GH_Convert.ToString(ghnm[i], out string name, GH_Conversion.Both)) { in_names.Add(name); } } } // 5 Colour List <GH_Colour> ghcol = new List <GH_Colour>(); List <System.Drawing.Color> in_colours = new List <System.Drawing.Color>(); if (DA.GetDataList(5, ghcol)) { for (int i = 0; i < ghcol.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Colour input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Colours have been ignored"); continue; } if (GH_Convert.ToColor(ghcol[i], out System.Drawing.Color col, GH_Conversion.Both)) { in_colours.Add(col); } } } // 6 Dummy List <GH_Boolean> ghdum = new List <GH_Boolean>(); List <bool> in_dummies = new List <bool>(); if (DA.GetDataList(6, ghdum)) { for (int i = 0; i < ghdum.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dummy input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Dummy booleans have been ignored"); continue; } if (GH_Convert.ToBoolean(ghdum[i], out bool dum, GH_Conversion.Both)) { in_dummies.Add(dum); } } } // loop through all elements and set collected lists. // handle too short or too long input lists here // for short lists copy last item for (int i = 0; i < elem.Elements.Count; i++) { //if (in_prop2Ds.Count > 0) //{ // if (i < in_prop2Ds.Count) // elem.Properties[i] = in_prop2Ds[i]; // else // elem.Properties[i] = in_prop2Ds[in_prop2Ds.Count - 1]; //} if (in_ids.Count > 0) { if (i < in_ids.Count) { elem.ID[i] = in_ids[i]; } else { elem.ID[i] = 0; // do not set ID (element number) as it must be unique } } if (in_names.Count > 0) { if (i < in_names.Count) { elem.Elements[i].Name = in_names[i]; } else { elem.Elements[i].Name = in_names[in_names.Count - 1]; } } if (in_groups.Count > 0) { if (i < in_groups.Count) { elem.Elements[i].Group = in_groups[i]; } else { elem.Elements[i].Group = in_groups[in_groups.Count - 1]; } } if (in_colours.Count > 0) { if (i < in_colours.Count) { elem.Elements[i].Colour = in_colours[i]; } else { elem.Elements[i].Colour = in_colours[in_colours.Count - 1]; } } if (in_dummies.Count > 0) { if (i < in_dummies.Count) { elem.Elements[i].IsDummy = in_dummies[i]; } else { elem.Elements[i].IsDummy = in_dummies[in_dummies.Count - 1]; } } } // convert mesh to output meshes List <Mesh> out_meshes = new List <Mesh>(); Mesh x = elem.NgonMesh; List <MeshNgon> ngons = x.GetNgonAndFacesEnumerable().ToList(); for (int i = 0; i < ngons.Count; i++) { Mesh m = new Mesh(); m.Vertices.AddVertices(x.Vertices.ToList()); List <int> faceindex = ngons[i].FaceIndexList().Select(u => (int)u).ToList(); for (int j = 0; j < faceindex.Count; j++) { m.Faces.AddFace(x.Faces[faceindex[j]]); } m.Vertices.CullUnused(); m.RebuildNormals(); out_meshes.Add(m); } // #### outputs #### DA.SetData(0, new GsaElement3dGoo(elem)); DA.SetDataList(1, elem.ID); DA.SetDataList(2, out_meshes); List <GsaOffset> out_offsets = new List <GsaOffset>(); List <string> type = new List <string>(); List <string> out_names = new List <string>(); List <int> out_groups = new List <int>(); List <System.Drawing.Color> out_colours = new List <System.Drawing.Color>(); List <int> pmems = new List <int>(); List <bool> out_dummies = new List <bool>(); for (int i = 0; i < elem.Elements.Count; i++) { GsaOffset offset1 = new GsaOffset { Z = elem.Elements[i].Offset.Z }; out_offsets.Add(offset1); type.Add(elem.Elements[i].TypeAsString()); out_names.Add(elem.Elements[i].Name); out_groups.Add(elem.Elements[i].Group); out_colours.Add((System.Drawing.Color)elem.Elements[i].Colour); out_dummies.Add(elem.Elements[i].IsDummy); try { pmems.Add(elem.Elements[i].ParentMember.Member); } catch (Exception) { pmems.Add(0); } ; } //DA.SetDataList(3, elem.Properties); DA.SetDataList(4, out_groups); DA.SetDataList(5, type); DA.SetDataList(6, out_names); DA.SetDataList(7, out_colours); DA.SetDataList(8, out_dummies); DA.SetDataList(9, pmems); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaGridLineLoad gridlineload = new GsaGridLineLoad(); // 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); } gridlineload.GridLineLoad.Case = lc; // Do plane input first as to see if we need to project polyline onto grid plane // 2 Plane Plane pln = Plane.WorldXY; bool planeSet = false; GsaGridPlaneSurface grdplnsrf = new GsaGridPlaneSurface(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface temppln = new GsaGridPlaneSurface(); gh_typ.CastTo(ref temppln); grdplnsrf = temppln.Duplicate(); pln = grdplnsrf.Plane; planeSet = true; } else if (gh_typ.Value is Plane) { gh_typ.CastTo(ref pln); grdplnsrf = new GsaGridPlaneSurface(pln); planeSet = true; } else { int id = 0; if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both)) { gridlineload.GridLineLoad.GridSurface = id; gridlineload.GridPlaneSurface = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in GPS input. Accepted inputs are Grid Plane Surface or Plane. " + System.Environment.NewLine + "If no input here then the line's best-fit plane will be used"); return; } } } // we wait setting the gridplanesurface until we have run the polyline input // 1 Polyline Polyline ln = new Polyline(); GH_Curve gh_crv = new GH_Curve(); if (DA.GetData(1, ref gh_crv)) { Curve crv = null; GH_Convert.ToCurve(gh_crv, ref crv, GH_Conversion.Both); //convert to polyline if (crv.TryGetPolyline(out ln)) { // get control points List <Point3d> ctrl_pts = ln.ToList(); // plane if (!planeSet) { // create best-fit plane from pts pln = Util.GH.Convert.CreateBestFitUnitisedPlaneFromPts(ctrl_pts); // create grid plane surface from best fit plane grdplnsrf = new GsaGridPlaneSurface(pln, true); } else { // project original curve onto grid plane crv = Curve.ProjectToPlane(crv, pln); // convert to polyline again crv.TryGetPolyline(out ln); //get control points again ctrl_pts = ln.ToList(); } // string to write polyline description to string desc = ""; // loop through all points for (int i = 0; i < ctrl_pts.Count; i++) { if (i > 0) { desc += " "; } // get control points in local plane coordinates Point3d temppt = new Point3d(); pln.RemapToPlaneSpace(ctrl_pts[i], out temppt); // write point to string // format accepted by GSA: (0,0) (0,1) (1,2) (3,4) (4,0)(m) desc += "(" + temppt.X + "," + temppt.Y + ")"; } // add units to the end desc += "(" + Units.LengthLarge + ")"; // set polyline in grid line load gridlineload.GridLineLoad.Type = GridLineLoad.PolyLineType.EXPLICIT_POLYLINE; gridlineload.GridLineLoad.PolyLineDefinition = desc; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Curve to Polyline"); } } // now we can set the gridplanesurface: if (gridlineload.GridPlaneSurface != null) { if (gridlineload.GridPlaneSurface.GridSurfaceID == 0) { gridlineload.GridPlaneSurface = grdplnsrf; } } // 3 direction string dir = "Z"; Direction direc = Direction.Z; GH_String gh_dir = new GH_String(); if (DA.GetData(3, ref gh_dir)) { GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both); } dir = dir.ToUpper(); if (dir == "X") { direc = Direction.X; } if (dir == "Y") { direc = Direction.Y; } gridlineload.GridLineLoad.Direction = direc; // 4 Axis int axis = 0; gridlineload.GridLineLoad.AxisProperty = 0; GH_Integer gh_ax = new GH_Integer(); if (DA.GetData(4, ref gh_ax)) { GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both); if (axis == 0 || axis == -1) { gridlineload.GridLineLoad.AxisProperty = axis; } } // 5 Projected bool proj = false; GH_Boolean gh_proj = new GH_Boolean(); if (DA.GetData(5, ref gh_proj)) { if (GH_Convert.ToBoolean(gh_proj, out proj, GH_Conversion.Both)) { gridlineload.GridLineLoad.IsProjected = proj; } } // 6 Name string name = ""; GH_String gh_name = new GH_String(); if (DA.GetData(6, ref gh_name)) { if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both)) { gridlineload.GridLineLoad.Name = name; } } // 7 load value double load1 = 0; if (DA.GetData(7, ref load1)) { load1 *= -1000; //convert to kN } gridlineload.GridLineLoad.ValueAtStart = load1; // 8 load value double load2 = load1; if (DA.GetData(8, ref load2)) { load2 *= -1000; //convert to kN } gridlineload.GridLineLoad.ValueAtEnd = load2; // convert to goo GsaLoad gsaLoad = new GsaLoad(gridlineload); DA.SetData(0, new GsaLoadGoo(gsaLoad)); }
protected override void SolveInstance(IGH_DataAccess DA) { // 0 Plane Plane pln = Plane.Unset; GsaGridPlaneSurface gps; bool idSet = false; GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface temppln = new GsaGridPlaneSurface(); gh_typ.CastTo(ref temppln); gps = temppln.Duplicate(); } else { if (gh_typ.CastTo(ref pln)) { gps = new GsaGridPlaneSurface(pln); } else { int id = 0; if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both)) { gps = new GsaGridPlaneSurface(); gps.GridSurface.GridPlane = id; gps.GridPlane = null; idSet = true; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Cannot convert your input to GridPlaneSurface or Plane"); return; } } } } else { pln = Plane.WorldXY; gps = new GsaGridPlaneSurface(pln); } // record if changes has been made from default type bool changeGS = false; GridSurface gs = new GridSurface(); // new GridSurface to make changes to, set it back to GPS in the end if (idSet) { gs.GridPlane = gps.GridSurface.GridPlane; } // 1 ID GH_Integer ghint = new GH_Integer(); if (DA.GetData(1, ref ghint)) { int id = 0; GH_Convert.ToInt32(ghint, out id, GH_Conversion.Both); gps.GridSurfaceID = id; } // 2 Elements GH_String ghelem = new GH_String(); if (DA.GetData(2, ref ghelem)) { string elem = ""; if (GH_Convert.ToString(ghelem, out elem, GH_Conversion.Both)) { gs.Elements = elem; changeGS = true; } } // 3 Name GH_String ghtxt = new GH_String(); if (DA.GetData(3, ref ghtxt)) { string name = ""; if (GH_Convert.ToString(ghtxt, out name, GH_Conversion.Both)) { gs.Name = name; changeGS = true; } } // 4 Tolerance GH_Number ghtol = new GH_Number(); if (DA.GetData(4, ref ghtol)) { double tol = 10; if (GH_Convert.ToDouble(ghtol, out tol, GH_Conversion.Both)) { gs.Tolerance = tol; changeGS = true; } } switch (_mode) { case FoldMode.One_Dimensional_One_Way: gs.ElementType = GridSurface.Element_Type.ONE_DIMENSIONAL; gs.SpanType = GridSurface.Span_Type.ONE_WAY; // 5 span direction GH_Number ghdir = new GH_Number(); if (DA.GetData(5, ref ghdir)) { double dir = 0; if (GH_Convert.ToDouble(ghdir, out dir, GH_Conversion.Both)) { if (dir > 180 || dir < -180) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Angle value must be between -180 and 180 degrees"); // to be updated when GsaAPI support units } gs.Direction = dir; if (dir != 0) { changeGS = true; } } } break; case FoldMode.One_Dimensional_Two_Way: changeGS = true; gs.ElementType = GridSurface.Element_Type.ONE_DIMENSIONAL; // 5 expansion method int exp = 0; GH_Integer ghexp = new GH_Integer(); if (DA.GetData(5, ref ghexp)) { GH_Convert.ToInt32_Primary(ghexp, ref exp); } gs.ExpansionType = GridSurfaceExpansionType.PLANE_CORNER; if (exp == 1) { gs.ExpansionType = GridSurfaceExpansionType.PLANE_SMOOTH; } if (exp == 2) { gs.ExpansionType = GridSurfaceExpansionType.PLANE_ASPECT; } if (exp == 3) { gs.ExpansionType = GridSurfaceExpansionType.LEGACY; } // 6 simplify tributary area bool simple = true; GH_Boolean ghsim = new GH_Boolean(); if (DA.GetData(6, ref ghsim)) { GH_Convert.ToBoolean(ghsim, out simple, GH_Conversion.Both); } if (simple) { gs.SpanType = GridSurface.Span_Type.TWO_WAY_SIMPLIFIED_TRIBUTARY_AREAS; } else { gs.SpanType = GridSurface.Span_Type.TWO_WAY; } break; case FoldMode.Two_Dimensional: changeGS = true; gs.ElementType = GridSurface.Element_Type.TWO_DIMENSIONAL; break; } if (changeGS) { gps.GridSurface = gs; } DA.SetData(0, new GsaGridPlaneSurfaceGoo(gps)); }
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) { GsaMember1d gsaMember1d = new GsaMember1d(); if (DA.GetData(0, ref gsaMember1d)) { GsaMember1d mem = gsaMember1d.Duplicate(); // #### inputs #### // 1 curve GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(1, ref ghcrv)) { Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d tmpmem = new GsaMember1d(crv) { ID = mem.ID, Member = mem.Member, ReleaseEnd = mem.ReleaseEnd, ReleaseStart = mem.ReleaseStart }; mem = tmpmem; } } // 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; } } mem.Section = section; } // 3 type GH_Integer ghint = new GH_Integer(); if (DA.GetData(4, ref ghint)) { if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both)) { mem.Member.Type = Util.Gsa.GsaToModel.Member1dType(type); } } // 4 element type GH_Integer ghinteg = new GH_Integer(); if (DA.GetData(4, ref ghinteg)) { if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both)) { mem.Member.Type1D = Util.Gsa.GsaToModel.Element1dType(type); } } // 5 offset GsaOffset offset = new GsaOffset(); if (DA.GetData(5, ref offset)) { mem.Member.Offset.X1 = offset.X1; mem.Member.Offset.X2 = offset.X2; mem.Member.Offset.Y = offset.Y; mem.Member.Offset.Z = offset.Z; } // 6 start release GsaBool6 start = new GsaBool6(); if (DA.GetData(6, ref start)) { mem.ReleaseStart = start; } // 7 end release GsaBool6 end = new GsaBool6(); if (DA.GetData(7, ref end)) { mem.ReleaseEnd = end; } // 8 orientation angle GH_Number ghangle = new GH_Number(); if (DA.GetData(8, ref ghangle)) { if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both)) { mem.Member.OrientationAngle = angle; } } // 9 orientation node GH_Integer ghori = new GH_Integer(); if (DA.GetData(9, ref ghori)) { if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both)) { mem.Member.OrientationNode = orient; } } // 10 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(10, ref ghmsz)) { if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both)) { mem.Member.MeshSize = msz; } } // 11 mesh with others GH_Boolean ghbool = new GH_Boolean(); if (DA.GetData(11, ref ghbool)) { if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both)) { //mem.member.MeshWithOthers } } // 12 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(12, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { mem.ID = id; } } // 13 name GH_String ghnm = new GH_String(); if (DA.GetData(13, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { mem.Member.Name = name; } } // 14 Group GH_Integer ghgrp = new GH_Integer(); if (DA.GetData(14, ref ghgrp)) { if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both)) { mem.Member.Group = grp; } } // 15 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(15, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { mem.Member.Colour = col; } } // 16 Dummy GH_Boolean ghdum = new GH_Boolean(); if (DA.GetData(16, ref ghdum)) { if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both)) { mem.Member.IsDummy = dum; } } // #### outputs #### DA.SetData(0, new GsaMember1dGoo(mem)); DA.SetData(1, mem.PolyCurve); DA.SetData(2, mem.Section); DA.SetData(3, mem.Member.Type); DA.SetData(4, mem.Member.Type1D); GsaOffset gsaOffset = new GsaOffset { X1 = mem.Member.Offset.X1, X2 = mem.Member.Offset.X2, Y = mem.Member.Offset.Y, Z = mem.Member.Offset.Z }; DA.SetData(5, gsaOffset); DA.SetData(6, mem.ReleaseStart); DA.SetData(7, mem.ReleaseEnd); DA.SetData(8, mem.Member.OrientationAngle); DA.SetData(9, mem.Member.OrientationNode); DA.SetData(10, mem.Member.MeshSize); //DA.SetData(11, mem.member.MeshSize); //mesh with others bool DA.SetData(12, mem.ID); DA.SetData(13, mem.Member.Name); DA.SetData(14, mem.Member.Group); DA.SetData(15, mem.Member.Colour); DA.SetData(16, mem.Member.IsDummy); } }