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); }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GH_String) { string tempfile = ""; if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both)) { if (!tempfile.EndsWith(".gwb")) { tempfile = tempfile + ".gwb"; } GsaModel.FileName = tempfile; } } else if (gh_typ.Value is GsaAPI.Model) { GsaAPI.Model model = new Model(); gh_typ.CastTo(ref model); GsaModel.Model = model; } } }
public static object To_String(object in_val) { string n = ""; var y = GH_Convert.ToString(in_val, out n, GH_Conversion.Both); return((object)n); }
public bool GetParameterValueArray(int dataAccessIndexNames, int dataAccessIndexValues, ref List <string> parameterNames, out GH_Structure <GH_String> parameterValues, out string[,] parameterArray) { GetInput(dataAccessIndexNames, ref parameterNames); GetInput(dataAccessIndexValues, out parameterValues); if ((parameterNames == null) || (parameterValues == null)) { parameterArray = null; return(false); } if ((parameterValues.Branches.Count == 0) || (parameterNames.Count == 0)) { parameterArray = null; return(false); } parameterArray = new string[parameterValues.Branches.Count, parameterNames.Count]; for (int i = 0; i < parameterValues.Branches.Count; i++) { List <Grasshopper.Kernel.Types.GH_String> branch = parameterValues.Branches[i]; for (int j = 0; j < branch.Count; j++) { string valueString = null; GH_Convert.ToString(branch[j], out valueString, GH_Conversion.Both); parameterArray[i, j] = valueString; } } return(true); }
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) { 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)); }
public override bool CastFrom(object source) { if (source == null) { return(false); } string Name = ""; if (GH_Convert.ToString(source, out Name, GH_Conversion.Both)) { //bold, Italic都为false Value = new System.Drawing.Font(Name, 12F); return(true); } return(false); }
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) { 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); } }
/// <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) { List <Object> Spawn_Type = new List <Object>(); int Dimension = new int(); int Bounds = new int(); if (!DA.GetDataList(0, Spawn_Type)) { return; } if (!DA.GetData(1, ref Dimension)) { return; } if (!DA.GetData(2, ref Bounds)) { return; } if (Dimension > 1 || Dimension < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Dimension value cannot be less than 0 and higher than 1, please adjust"); return; } if (Bounds > 2 || Bounds < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Boundary value cannot be less than 0 and higher than 2, please adjust"); return; } GH_Convert.ToString(Spawn_Type[0], out this.text, GH_Conversion.Both); ArrayList myAL = new ArrayList(); myAL.Add(Spawn_Type[0]); myAL.Add(Dimension); myAL.Add(Bounds); if (this.text == "Box") { myAL.Add(Spawn_Type[1]); myAL.Add(Spawn_Type[2]); myAL.Add(Spawn_Type[3]); DA.SetDataList(0, myAL); } else if (this.text == "Points") { myAL.Add(Spawn_Type[1]); myAL.Add(Spawn_Type[2]); DA.SetDataList(0, myAL); } else if (this.text == "Mesh") { myAL.Add(Spawn_Type[1]); myAL.Add(Spawn_Type[2]); myAL.Add(Spawn_Type[3]); DA.SetDataList(0, myAL); } else if (this.text == "Curve") { myAL.Add(Spawn_Type[1]); myAL.Add(Spawn_Type[2]); myAL.Add(Spawn_Type[3]); DA.SetDataList(0, myAL); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please input a valid spawn type"); return; } }
protected override void SolveInstance(IGH_DataAccess DA) { UpdateMessage(); PythonScript script = PythonScript.Create(); string outDir = ""; try { script.ExecuteScript("import scriptcontext as sc\nV=sc.sticky['NOAH_PROJECT']\nT=sc.sticky['TASK_TICKET']\nG=sc.sticky['NOAH_GENERATOR']\nID=sc.sticky['UUID']"); NOAH_PROJECT = (string)script.GetVariable("V"); TASK_TICKET = (string)script.GetVariable("T"); NOAH_GENERATOR = (string)script.GetVariable("G"); UUID = (string)script.GetVariable("ID"); if (File.Exists(NOAH_PROJECT)) { outDir = Path.Combine(Path.GetDirectoryName(NOAH_PROJECT), ".noah", "tasks", UUID, TASK_TICKET, "out"); ProjectInfo = JObject.Parse(File.ReadAllText(NOAH_PROJECT)); JArray generators = JArray.Parse(ProjectInfo["generators"].ToString()); FindJobjectFromJArray(generators, NOAH_GENERATOR, out Generator, out GeneratorIndex); } } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, ex.Message); } int outIndex = 0; DA.GetData(1, ref outIndex); JArray output = JArray.Parse(Generator["output"].ToString()); if (outIndex >= output.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "定义时未指定此输出端口"); } switch (m_mode) { case ExportMode.None: Message = null; break; case ExportMode.Rhino: string fileName = Convert.ToString(outIndex) + ".3dm"; string filePath = Path.Combine(outDir, fileName); File3dmWriter writer = new File3dmWriter(filePath); List <int> ll = new List <int>(); List <ObjectLayerInfo> layeredObj = new List <ObjectLayerInfo>(); DA.GetDataList(0, layeredObj); layeredObj.ForEach(x => { writer.ChildLayerSolution(x.Name); ll.Add(writer.CreateLayer(x.Name, x.Color)); }); if (layeredObj.Count > 0) { writer.Write(layeredObj, ll); if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } } break; case ExportMode.Text: if (!exported) { string outputData = ""; DA.GetData(0, ref outputData); ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = outputData; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; case ExportMode.Data: fileName = Convert.ToString(outIndex) + ".noahdata"; filePath = Path.Combine(outDir, fileName); if (string.IsNullOrWhiteSpace(filePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "未指定文件."); return; } GH_LooseChunk val = new GH_LooseChunk("Grasshopper Data"); val.SetGuid("OriginId", base.InstanceGuid); val.SetInt32("Count", base.Params.Input.Count); IGH_Param iGH_Param = base.Params.Input[0]; IGH_Structure volatileData = iGH_Param.VolatileData; GH_IWriter val2 = val.CreateChunk("Block", 0); val2.SetString("Name", iGH_Param.NickName); val2.SetBoolean("Empty", volatileData.IsEmpty); if (!volatileData.IsEmpty) { GH_Structure <IGH_Goo> tree = null; DA.GetDataTree(0, out tree); if (!tree.Write(val2.CreateChunk("Data"))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"There was a problem writing the {iGH_Param.NickName} data."); } } byte[] bytes = val.Serialize_Binary(); try { File.WriteAllBytes(filePath, bytes); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; case ExportMode.CSV: fileName = Convert.ToString(outIndex) + ".csv"; filePath = Path.Combine(outDir, fileName); List <object> oList = new List <object>(); List <string> sList = new List <string>(); DA.GetDataList(0, oList); oList.ForEach(el => { string tmp = ""; GH_Convert.ToString(el, out tmp, GH_Conversion.Both); sList.Add(tmp); }); File.WriteAllText(filePath, string.Join(Environment.NewLine, sList)); if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; } }
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); } }
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); }
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); }
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) { 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); } }
protected override void SolveInstance(IGH_DataAccess DA) { bool update = false; GH_String ghstr = new GH_String(); if (DA.GetData(0, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Force = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(1, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.LengthLarge = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(2, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.LengthSmall = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(3, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.LengthSection = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(4, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Mass = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(5, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Temperature = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(6, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Stress = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(7, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Strain = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(8, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Velocity = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(9, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Acceleration = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(10, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Energy = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(11, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.Angle = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(12, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.TimeShort = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(13, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.TimeMedium = unit; update = true; } } ghstr = new GH_String(); if (DA.GetData(14, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string unit, GH_Conversion.Both)) { Util.Unit.TimeLong = unit; update = true; } } List <string> units = new List <string> { "Force: " + Util.Unit.Force, "Length Large: " + Util.Unit.LengthLarge + ((Util.Unit.LengthLarge == Util.Unit.RhinoDocUnit) ? "" : System.Environment.NewLine + "NB: Not similar to Rhino Document units!"), "Length Small: " + Util.Unit.LengthSmall, "Length Section: " + Util.Unit.LengthSection, "Mass: " + Util.Unit.Mass, "Temperature: " + Util.Unit.Temperature, "Stress: " + Util.Unit.Stress, "Strain: " + Util.Unit.Strain, "Velocity: " + Util.Unit.Velocity, "Acceleration: " + Util.Unit.Acceleration, "Energy: " + Util.Unit.Energy, "Angle: " + Util.Unit.Angle, "Time - short: " + Util.Unit.TimeShort, "Time - medium: " + Util.Unit.TimeMedium, "Time - long: " + Util.Unit.TimeLong, }; if (update) { UpdateCanvas(); } DA.SetDataList(0, units); }
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) { 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) { 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); } }
private void StoreOutput() { DebugEvent("Start Store Output"); GH_DocumentServer doc_server = Instances.DocumentServer; if (doc_server == null) { throw new Exception("No Document Server exist!"); } GH_Document doc = doc_server.ToList().Find(x => x.Properties.ProjectFileName == ID.ToString()); if (doc == null) { throw new Exception("Tasker 未找到GH_Document"); } if (string.IsNullOrEmpty(workspace) || string.IsNullOrEmpty(ticket)) { throw new Exception("工作目录和Ticket为空"); } string outDir = Path.Combine(taskspace, ID.ToString(), ticket); var hooks = doc.ClusterOutputHooks(); if (hooks == null) { return; } foreach (var hook in hooks) { string info = hook.CustomDescription; if (string.IsNullOrEmpty(info)) { continue; } var paraMap = ConvertUrlParam(info); if (!paraMap.TryGetValue("Index", out string index) || !paraMap.TryGetValue("Type", out string type)) { continue; } DebugEvent($"Index: {index}; Type: {type}"); string fileName = Path.Combine(outDir, index + "@" + DateTime.Now.ToString("HH-mm-ss MM-dd")); var volatileData = hook.VolatileData; if (volatileData.IsEmpty) { continue; } dynamic content = null; switch (type) { case "CSV": { var allData = volatileData.AllData(true); List <string> sList = new List <string>(); allData.ToList().ForEach(el => { GH_Convert.ToString(el, out string tmp, GH_Conversion.Both); sList.Add(tmp); }); string csv = string.Join(Environment.NewLine, sList); fileName += ".csv"; File.WriteAllText(fileName, csv, Encoding.UTF8); content = fileName; break; } case "3DM": { fileName += ".3dm"; File3dmWriter writer = new File3dmWriter(fileName); foreach (var data in volatileData.AllData(true)) { GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } string layer = obj.GetUserString("Layer"); if (layer == null) { continue; } ObjectAttributes att = new ObjectAttributes { LayerIndex = writer.GetLayer(layer, Color.Black) }; writer.ObjectMap.Add(att, obj); } writer.Write(); content = fileName; break; } case "Data": { try { GH_Structure <IGH_Goo> tree = volatileData as GH_Structure <IGH_Goo>; content = IO.SerializeGrasshopperData(tree, hook.CustomName, volatileData.IsEmpty); } catch (Exception ex) { ErrorEvent(this, ex.Message); } break; } case "EPS": { List <GeometryBase> objs = new List <GeometryBase>(); foreach (var data in volatileData.AllData(true)) { if (data == null) { continue; } GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } objs.Add(obj); } if (!Directory.Exists(fileName)) { Directory.CreateDirectory(fileName); } content = JsonConvert.SerializeObject(SaveAdobeDocument(fileName, objs, AdobeDocType.EPS)); break; } case "PDF": { List <GeometryBase> objs = new List <GeometryBase>(); fileName += ".pdf"; foreach (var data in volatileData.AllData(true)) { if (data == null) { continue; } GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } objs.Add(obj); } var res = SaveAdobeDocument(fileName, objs, AdobeDocType.PDF); if (res == null || res.Count == 0) { break; } content = res[0]; break; } case "RhinoPDF": { var pdf = FilePdf.Create(); fileName += ".pdf"; DebugEvent("RhinoPDF Begin"); foreach (var page in volatileData.AllData(true)) { DebugEvent("RhinoPDF got 1 page"); if (!page.CastTo(out RhinoPageView view)) { DebugEvent(string.Format("{0} can not convert to RhinoPageView", page.GetType())); continue; } DebugEvent("Data is converted to RhinoPage"); ViewCaptureSettings settings = new ViewCaptureSettings(view, 300) { OutputColor = ViewCaptureSettings.ColorMode.DisplayColor, RasterMode = true }; pdf.AddPage(settings); } pdf.Write(fileName); content = fileName; break; } case "DXF": { break; } default: break; } StoreEvent(this, new JObject { ["route"] = "task-stored", ["id"] = ID.ToString(), ["index"] = index.ToString(), ["type"] = type, ["content"] = content }.ToString()); } }
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) { GsaNodeLoad nodeLoad = new GsaNodeLoad(); // Node load type switch (_mode) { case FoldMode.Node: nodeLoad.NodeLoadType = GsaNodeLoad.NodeLoadTypes.NODE_LOAD; break; case FoldMode.Applied_Displ: nodeLoad.NodeLoadType = GsaNodeLoad.NodeLoadTypes.APPLIED_DISP; break; case FoldMode.Settlements: nodeLoad.NodeLoadType = GsaNodeLoad.NodeLoadTypes.SETTLEMENT; break; } // 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); } nodeLoad.NodeLoad.Case = lc; // 1 element/beam list string nodeList = "all"; GH_String gh_nl = new GH_String(); if (DA.GetData(1, ref gh_nl)) { GH_Convert.ToString(gh_nl, out nodeList, GH_Conversion.Both); } nodeLoad.NodeLoad.Nodes = nodeList; // 3 Name string name = ""; GH_String gh_name = new GH_String(); if (DA.GetData(3, ref gh_name)) { if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both)) { nodeLoad.NodeLoad.Name = name; } } // 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().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; } nodeLoad.NodeLoad.Direction = direc; double load = 0; if (DA.GetData(4, ref load)) { if (direc == Direction.Z) { load *= -1000; //convert to kN } else { load *= 1000; } } nodeLoad.NodeLoad.Value = load; GsaLoad gsaLoad = new GsaLoad(nodeLoad); DA.SetData(0, new GsaLoadGoo(gsaLoad)); }
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 number of divisions GH_Integer gh_Div = new GH_Integer(); DA.GetData(3, ref gh_Div); GH_Convert.ToInt32(gh_Div, out int temppositionsCount, 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(4, 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(5, 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 (elemList == "" || elemList != tempelemList) { elemList = tempelemList; getresults = true; } if (positionsCount == 0 || positionsCount != temppositionsCount) { positionsCount = temppositionsCount; 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, Element1DResult> globalResults = analysisCaseResult.Element1DResults(elemList, positionsCount); IReadOnlyDictionary <int, Element> elems = gsaModel.Model.Elements(elemList); IReadOnlyDictionary <int, Node> nodes = gsaModel.Model.Nodes(); #endregion // ### Loop through results ### // clear existing result lists xyz_out = new DataTree <Vector3d>(); xxyyzz_out = new DataTree <Vector3d>(); segmentlines = new DataTree <Line>(); List <int> elemID = new List <int>(); List <int> parentMember = new List <int>(); // 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; foreach (int key in globalResults.Keys) { // lists for results Element1DResult elementResults; globalResults.TryGetValue(key, out elementResults); List <Double6> values = new List <Double6>(); List <Vector3d> xyz = new List <Vector3d>(); List <Vector3d> xxyyzz = new List <Vector3d>(); // list for element geometry and info Element element = new Element(); elems.TryGetValue(key, out element); Node start = new Node(); nodes.TryGetValue(element.Topology[0], out start); Node end = new Node(); nodes.TryGetValue(element.Topology[1], out end); Line ln = new Line( new Point3d(start.Position.X, start.Position.Y, start.Position.Z), new Point3d(end.Position.X, end.Position.Y, end.Position.Z)); elemID.Add(key); parentMember.Add(element.ParentMember.Member); // set the result type dependent on user selection in dropdown switch (_mode) { case (FoldMode.Displacement): values = elementResults.Displacement.ToList(); unitfactorxyz = 0.001; unitfactorxxyyzz = 1; break; case (FoldMode.Force): values = elementResults.Force.ToList(); unitfactorxyz = 1000; unitfactorxxyyzz = 1000; break; } // prepare the line segments int segments = Math.Max(1, values.Count - 1); // number of segment lines is 1 less than number of points int segment = 0; // counter for segments List <Line> segmentedlines = new List <Line>(); // loop through the results foreach (Double6 result in values) { // update max and min values if (result.X / unitfactorxyz > dmax_x) { dmax_x = result.X / unitfactorxyz; } if (result.Y / unitfactorxyz > dmax_y) { dmax_y = result.Y / unitfactorxyz; } if (result.Z / unitfactorxyz > dmax_z) { dmax_z = result.Z / unitfactorxyz; } if (Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz > dmax_xyz) { dmax_xyz = Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz; } if (result.XX / unitfactorxxyyzz > dmax_xx) { dmax_xx = result.XX / unitfactorxxyyzz; } if (result.YY / unitfactorxxyyzz > dmax_yy) { dmax_yy = result.YY / unitfactorxxyyzz; } if (result.ZZ / unitfactorxxyyzz > dmax_zz) { dmax_zz = result.ZZ / unitfactorxxyyzz; } if (Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz > dmax_xxyyzz) { dmax_xxyyzz = Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz; } if (result.X / unitfactorxyz < dmin_x) { dmin_x = result.X / unitfactorxyz; } if (result.Y / unitfactorxyz < dmin_y) { dmin_y = result.Y / unitfactorxyz; } if (result.Z / unitfactorxyz < dmin_z) { dmin_z = result.Z / unitfactorxyz; } if (Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz < dmin_xyz) { dmin_xyz = Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz; } if (result.XX / unitfactorxxyyzz < dmin_xx) { dmin_xx = result.XX / unitfactorxxyyzz; } if (result.YY / unitfactorxxyyzz < dmin_yy) { dmin_yy = result.YY / unitfactorxxyyzz; } if (result.ZZ / unitfactorxxyyzz < dmin_zz) { dmin_zz = result.ZZ / unitfactorxxyyzz; } if (Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz < dmin_xxyyzz) { dmin_xxyyzz = Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz; } // add the values to the vector lists xyz.Add(new Vector3d(result.X / unitfactorxyz, result.Y / unitfactorxyz, result.Z / unitfactorxyz)); xxyyzz.Add(new Vector3d(result.XX / unitfactorxxyyzz, result.YY / unitfactorxxyyzz, result.ZZ / unitfactorxxyyzz)); // create ResultLines if (segment < segments) { Line segmentline = new Line( ln.PointAt((double)segment / segments), ln.PointAt((double)(segment + 1) / segments) ); segment++; segmentedlines.Add(segmentline); } } // add the vector list to the out tree xyz_out.AddRange(xyz, new GH_Path(key - 1)); xxyyzz_out.AddRange(xxyyzz, new GH_Path(key - 1)); segmentlines.AddRange(segmentedlines, new GH_Path(key - 1)); } getresults = false; } #endregion #region Result line values // ### Coloured Result Lines ### // 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 segmented lines and set result colour into ResultLine format DataTree <ResultLine> lines_out = new DataTree <ResultLine>(); DataTree <System.Drawing.Color> col_out = new DataTree <System.Drawing.Color>(); foreach (GH_Path path in segmentlines.Paths) { List <ResultLine> lns = new List <ResultLine>(); List <System.Drawing.Color> col = new List <System.Drawing.Color>(); List <Line> segmentedlines = segmentlines.Branch(path); for (int j = 0; j < segmentedlines.Count; j++) { if (!(dmin == 0 & dmax == 0)) { Vector3d startTranslation = new Vector3d(0, 0, 0); Vector3d endTranslation = new Vector3d(0, 0, 0); double t1 = 0; double t2 = 0; // pick the right value to display switch (_disp) { case (DisplayValue.X): t1 = xyz_out[path, j].X; t2 = xyz_out[path, j + 1].X; startTranslation.X = t1 * Value / 1000; endTranslation.X = t2 * Value / 1000; break; case (DisplayValue.Y): t1 = xyz_out[path, j].Y; t2 = xyz_out[path, j + 1].Y; startTranslation.Y = t1 * Value / 1000; endTranslation.Y = t2 * Value / 1000; break; case (DisplayValue.Z): t1 = xyz_out[path, j].Z; t2 = xyz_out[path, j + 1].Z; startTranslation.Z = t1 * Value / 1000; endTranslation.Z = t2 * Value / 1000; break; case (DisplayValue.resXYZ): t1 = Math.Sqrt(Math.Pow(xyz_out[path, j].X, 2) + Math.Pow(xyz_out[path, j].Y, 2) + Math.Pow(xyz_out[path, j].Z, 2)); t2 = Math.Sqrt(Math.Pow(xyz_out[path, j + 1].X, 2) + Math.Pow(xyz_out[path, j + 1].Y, 2) + Math.Pow(xyz_out[path, j + 1].Z, 2)); startTranslation.X = xyz_out[path, j].X * Value / 1000; endTranslation.X = xyz_out[path, j + 1].X * Value / 1000; startTranslation.Y = xyz_out[path, j].Y * Value / 1000; endTranslation.Y = xyz_out[path, j + 1].Y * Value / 1000; startTranslation.Z = xyz_out[path, j].Z * Value / 1000; endTranslation.Z = xyz_out[path, j + 1].Z * Value / 1000; break; case (DisplayValue.XX): t1 = xxyyzz_out[path, j].X; t2 = xxyyzz_out[path, j + 1].X; break; case (DisplayValue.YY): t1 = xxyyzz_out[path, j].Y; t2 = xxyyzz_out[path, j + 1].Y; break; case (DisplayValue.ZZ): t1 = xxyyzz_out[path, j].Z; t2 = xxyyzz_out[path, j + 1].Z; break; case (DisplayValue.resXXYYZZ): t1 = Math.Sqrt(Math.Pow(xxyyzz_out[path, j].X, 2) + Math.Pow(xxyyzz_out[path, j].Y, 2) + Math.Pow(xxyyzz_out[path, j].Z, 2)); t2 = Math.Sqrt(Math.Pow(xxyyzz_out[path, j + 1].X, 2) + Math.Pow(xxyyzz_out[path, j + 1].Y, 2) + Math.Pow(xxyyzz_out[path, j + 1].Z, 2)); break; } Point3d start = new Point3d(segmentedlines[j].PointAt(0)); start.Transform(Transform.Translation(startTranslation)); Point3d end = new Point3d(segmentedlines[j].PointAt(1)); end.Transform(Transform.Translation(endTranslation)); Line segmentline = new Line(start, end); //normalised value between -1 and 1 double tnorm1 = 2 * (t1 - dmin) / (dmax - dmin) - 1; double tnorm2 = 2 * (t2 - dmin) / (dmax - dmin) - 1; // get colour for that normalised value System.Drawing.Color valcol1 = double.IsNaN(tnorm1) ? System.Drawing.Color.Black : gH_Gradient.ColourAt(tnorm1); System.Drawing.Color valcol2 = double.IsNaN(tnorm2) ? System.Drawing.Color.Black : gH_Gradient.ColourAt(tnorm2); // set the size of the line ends for ResultLine class. Size is calculated from 0-base, so not a normalised value between extremes float size1 = (t1 >= 0 && dmax != 0) ? Math.Max(2, (float)(t1 / dmax * scale)) : Math.Max(2, (float)(Math.Abs(t1) / Math.Abs(dmin) * scale)); if (double.IsNaN(size1)) { size1 = 1; } float size2 = (t2 >= 0 && dmax != 0) ? Math.Max(2, (float)(t2 / dmax * scale)) : Math.Max(2, (float)(Math.Abs(t2) / Math.Abs(dmin) * scale)); if (double.IsNaN(size2)) { size2 = 1; } // add our special resultline to the list of lines lns.Add(new ResultLine(segmentline, t1, t2, valcol1, valcol2, size1, size2)); // add the colour to the colours list col.Add(valcol1); if (j == segmentedlines.Count - 1) { col.Add(valcol2); } } } lines_out.AddRange(lns, path); col_out.AddRange(col, path); } #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 DA.SetDataTree(0, xyz_out); DA.SetDataTree(1, xxyyzz_out); DA.SetDataTree(2, lines_out); DA.SetDataTree(3, col_out); DA.SetDataList(4, cs); DA.SetDataList(5, ts); } }
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)); }
///////////////////////////////////////// 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) { 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) { Model model = new Model(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GH_String) { string tempfile = ""; if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both)) { fileName = tempfile; } if (!fileName.EndsWith(".gwb")) { fileName = fileName + ".gwb"; } ReturnValue status = model.Open(fileName); if (status == 0) { GsaModel gsaModel = new GsaModel { Model = model, FileName = fileName }; Titles.GetTitlesFromGSA(model); string mes = Path.GetFileName(fileName); mes = mes.Substring(0, mes.Length - 4); Message = mes; DA.SetData(0, new GsaModelGoo(gsaModel)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model" + System.Environment.NewLine + status.ToString()); return; } } else if (gh_typ.Value is GsaAPI.Model) { gh_typ.CastTo(ref model); GsaModel gsaModel = new GsaModel { Model = model, }; DA.SetData(0, new GsaModelGoo(gsaModel)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model"); return; } } else { ReturnValue status = model.Open(fileName); if (status == 0) { GsaModel gsaModel = new GsaModel { Model = model, FileName = fileName }; Titles.GetTitlesFromGSA(model); string mes = Path.GetFileName(fileName); mes = mes.Substring(0, mes.Length - 4); Message = mes; DA.SetData(0, new GsaModelGoo(gsaModel)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model" + System.Environment.NewLine + status.ToString()); return; } } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_String ghstr = new GH_String(); if (DA.GetData(0, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string title, GH_Conversion.Both)) { Titles.SetJobNumber(title); } } ghstr = new GH_String(); if (DA.GetData(1, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string title, GH_Conversion.Both)) { Titles.SetInitials(title); } } ghstr = new GH_String(); if (DA.GetData(2, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string title, GH_Conversion.Both)) { Titles.SetTitle(title); } } ghstr = new GH_String(); if (DA.GetData(3, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string title, GH_Conversion.Both)) { Titles.SetSubTitle(title); } } ghstr = new GH_String(); if (DA.GetData(4, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string title, GH_Conversion.Both)) { Titles.SetCalculation(title); } } ghstr = new GH_String(); if (DA.GetData(5, ref ghstr)) { if (GH_Convert.ToString(ghstr, out string title, GH_Conversion.Both)) { Titles.SetNotes(title); } } List <string> titles = new List <string> { "Job Number: " + Titles.JobNumber, "Initials: " + Titles.Initials, "Title: " + Titles.Title, "Sub Title: " + Titles.SubTitle, "Calculation Header: " + Titles.Calculation, "Notes: " + Titles.Notes }; DA.SetDataList(0, titles); }