public void GetPropertiesComponentTest() { // ensure model has been opened: if (TestModel == null) { OpenComponentTest(); } // create the component var comp = new GhSA.Components.GetProperties(); comp.CreateAttributes(); // input parameter GsaModelGoo modelGoo = new GsaModelGoo(TestModel); Component.SetInput(comp, modelGoo); //pManager.AddGenericParameter("Sections", "PB", "Section Properties from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("2D Properties", "PA", "2D Properties from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("Springs", "PS", "Spring Properties from GSA Model", GH_ParamAccess.list); // get output GsaSectionGoo output = (GsaSectionGoo)Component.GetOutput(comp, 0); GsaSection sect = new GsaSection(); Assert.IsTrue(output.CastTo(ref sect)); Assert.AreEqual(1, sect.ID); //Assert.AreEqual("CAT UB UB457x191x89", sect.Section.Profile); }
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)); } }
public void TestDuplicateEmptySection() { GsaSection section = new GsaSection(); GsaSection dup = section.Duplicate(); Assert.IsNotNull(dup); }
public void TestCreateGsaSectionCat() { string profile = "CAT HE HE200.B"; GsaSection section = new GsaSection(profile); double area = section.Section.Area * Math.Pow(10, 6); Assert.AreEqual(7808.121, area); }
//create a section public bool Create1dSection(string description, int sectionNumber, int material, out GsaSection section) { section = new GsaSection(); section.SectDesc = description; section.Name = description; section.Material = material; section.Ref = sectionNumber; return(true); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection sect = new GsaSection(); GsaSection gsaSection = new GsaSection(); if (DA.GetData(0, ref sect)) { gsaSection = sect.Clone(); } if (gsaSection != null) { // #### input #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { gsaSection.ID = id; } } // 2 profile string profile = ""; if (DA.GetData(2, ref profile)) { gsaSection.Section.Profile = profile; } // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Section.MaterialAnalysisProperty = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }
public static SpeckleObject ToSpeckle(this GsaSection dummyObject) { var newLines = Initialiser.AppResources.Cache.GetGwaToSerialise(dummyObject.Keyword); var structural1DPropertyExplicits = new List <Structural1DPropertyExplicit>(); var concreteMaterials = Initialiser.GsaKit.GSASenderObjects.Get <GSAMaterialConcrete>().ToDictionary(o => o.GSAId, o => ((StructuralMaterialConcrete)o.SpeckleObject).ApplicationId); var steelMaterials = Initialiser.GsaKit.GSASenderObjects.Get <GSAMaterialSteel>().ToDictionary(o => o.GSAId, o => ((StructuralMaterialSteel)o.SpeckleObject).ApplicationId); //Currently only handles explicit 1D properties //Filtering out all but explicit properties: //1. First exclude any GWA lines with the exact string "EXP" - make first pass at filtering them out //2. Call FromGwa for all and perform logic check of values of GsaSection (and subclass) instances var keysContainingEXP = newLines.Keys.Where(k => newLines[k].Contains("EXP")).ToList(); var gsaSectionsExp = new List <GsaSection>(); foreach (var k in keysContainingEXP) { var gsaSection = new GsaSection(); if (gsaSection.FromGwa(newLines[k]) && FindExpDetails(gsaSection, out var comp, out var pde)) { var structuralProp = new Structural1DPropertyExplicit() { Name = gsaSection.Name, ApplicationId = gsaSection.ApplicationId, Area = pde.Area, Iyy = pde.Iyy, Izz = pde.Izz, J = pde.J, Ky = pde.Ky, Kz = pde.Kz }; //No support for any other material type at this stage if (comp.MaterialType == Section1dMaterialType.CONCRETE || comp.MaterialType == Section1dMaterialType.STEEL) { var materialIndex = comp.MaterialIndex ?? 0; var materialDict = (comp.MaterialType == Section1dMaterialType.CONCRETE) ? concreteMaterials : steelMaterials; structuralProp.MaterialRef = (materialIndex > 0 && materialDict.ContainsKey(materialIndex)) ? materialDict[materialIndex] : null; } structural1DPropertyExplicits.Add(structuralProp); } } var props = structural1DPropertyExplicits.Select(pe => new GSA1DPropertyExplicit() { Value = pe }).ToList(); Initialiser.GsaKit.GSASenderObjects.AddRange(props); return((props.Count() > 0) ? new SpeckleObject() : new SpeckleNull()); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection gsaSection = new GsaSection(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref gsaSection); } else { string profile = ""; gh_typ.CastTo(ref profile); gsaSection = new GsaSection(profile); } } if (gsaSection != null) { double conversionfactor = 1; if (Util.Unit.LengthSection != "m") { switch (Util.Unit.LengthSection) { case "mm": conversionfactor = 1000; break; case "cm": conversionfactor = 100; break; case "in": conversionfactor = 1000 / 25.4; break; case "ft": conversionfactor = 1000 / (12 * 25.4); break; } } DA.SetData(0, gsaSection.Section.Area * Math.Pow(conversionfactor, 2)); DA.SetData(1, gsaSection.Section.Iyy * Math.Pow(conversionfactor, 4)); DA.SetData(2, gsaSection.Section.Izz * Math.Pow(conversionfactor, 4)); DA.SetData(3, gsaSection.Section.Iyz * Math.Pow(conversionfactor, 4)); DA.SetData(4, gsaSection.Section.J * Math.Pow(conversionfactor, 4)); DA.SetData(5, gsaSection.Section.Ky); DA.SetData(6, gsaSection.Section.Kz); DA.SetData(7, gsaSection.Section.SurfaceAreaPerLength * Math.Pow(conversionfactor, 2)); DA.SetData(8, gsaSection.Section.VolumePerLength * Math.Pow(conversionfactor, 3)); } }
public void TestCreateSectionProfile() { // string defining the profile string profile = "STD R 15 20"; double myarea = 15 * 20; // create new section with profile and ID GsaSection sect = new GsaSection(profile, 15); double area = sect.Section.Area * Math.Pow(10, 6); // unit conversion Assert.AreEqual(myarea, area); Assert.AreEqual(15, sect.ID); }
public void TestDuplicateSection() { string profile = "CAT HE HE200.B"; double myarea1 = 7808.121; GsaSection orig = new GsaSection(profile); // set other properties in section orig.Section.MaterialAnalysisProperty = 1; orig.Section.MaterialGradeProperty = 2; orig.Section.MaterialType = MaterialType.STEEL; orig.Section.Name = "mariam"; orig.Section.Pool = 12; // duplicate original GsaSection dup = orig.Duplicate(); // make some changes to original string profile2 = "STD%R%15%20"; double myarea2 = 15 * 20; orig.Section.Profile = profile2; orig.Section.MaterialAnalysisProperty = 4; orig.Section.MaterialGradeProperty = 6; orig.Section.MaterialType = MaterialType.TIMBER; orig.Section.Name = "kris"; orig.Section.Pool = 99; double area2 = orig.Section.Area * Math.Pow(10, 6); Assert.AreEqual(profile2, orig.Section.Profile); Assert.AreEqual(myarea2, area2); double area1 = dup.Section.Area * Math.Pow(10, 6); Assert.AreEqual(profile, dup.Section.Profile); Assert.AreEqual(myarea1, area1); Assert.AreEqual(1, dup.Section.MaterialAnalysisProperty); Assert.AreEqual(2, dup.Section.MaterialGradeProperty); Assert.AreEqual(MaterialType.STEEL.ToString(), dup.Section.MaterialType.ToString()); Assert.AreEqual("mariam", dup.Section.Name); Assert.AreEqual(12, dup.Section.Pool); Assert.AreEqual(4, orig.Section.MaterialAnalysisProperty); Assert.AreEqual(6, orig.Section.MaterialGradeProperty); Assert.AreEqual(MaterialType.TIMBER.ToString(), orig.Section.MaterialType.ToString()); Assert.AreEqual("kris", orig.Section.Name); Assert.AreEqual(99, orig.Section.Pool); }
private static bool FindExpDetails(GsaSection gsaSection, out SectionComp comp, out ProfileDetailsExplicit profileDetailsExplicit) { profileDetailsExplicit = null; comp = null; if (gsaSection.Components != null && gsaSection.Components.Count() > 0) { var compExps = gsaSection.Components.Where(c => c is SectionComp && ((SectionComp)c).ProfileDetails != null && ((SectionComp)c).ProfileDetails is ProfileDetailsExplicit); if (compExps.Count() > 0) { comp = (SectionComp)compExps.First(); profileDetailsExplicit = (ProfileDetailsExplicit)comp.ProfileDetails; return(true); } } return(false); }
public static int ConvertSection(GsaSection section, ref Dictionary <int, Section> existingSections, ref Dictionary <Guid, int> sections_guid) { if (section == null) { return(0); } if (sections_guid.ContainsKey(section.GUID)) { sections_guid.TryGetValue(section.GUID, out int sID); // if guid exist in our dictionary it has been added to the model return(sID); } int outID = section.ID; // section if (section.ID > 0) { if (section.Section != null) // section can refer to an ID only, meaning that the section must already exist in the model. Else we set it in the model: { existingSections[section.ID] = section.Section; } } else { if (section.Section != null) { if (existingSections.Count > 0) { outID = existingSections.Keys.Max() + 1; } else { outID = 1; } existingSections.Add(outID, section.Section); } } // set guid in dictionary sections_guid.Add(section.GUID, outID); return(outID); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection gsaSection = new GsaSection(); //profile GH_String gh_profile = new GH_String(); if (DA.GetData(0, ref gh_profile)) { if (GH_Convert.ToString(gh_profile, out string profile, GH_Conversion.Both)) { gsaSection.Section = new Section(); gsaSection.Section.Profile = profile; // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(1, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Material = new GsaMaterial(idd); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } else { gsaSection.Material = new GsaMaterial(7); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { if (ghln == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Line input is null"); } Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); elem.Section = section; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Element.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaElement1dGoo(elem)); }
public void TestCreateSection() { // create new section GsaSection sect = new GsaSection(); // string defining the profile string profile = "STD CHS 200 10"; double myarea = Math.Round( Math.PI / 4 * Math.Pow(200, 2) - Math.PI / 4 * Math.Pow(200 - 2 * 10, 2), 10); // set profile in section sect.Section.Profile = profile; double area = Math.Round( sect.Section.Area * Math.Pow(10, 6), // unit conversion 10); Assert.AreEqual(myarea, area); // set other properties in section Section apiSection = new Section { MaterialAnalysisProperty = 1, MaterialGradeProperty = 2, MaterialType = MaterialType.CONCRETE, Name = "mariam", Pool = 4, }; sect.Section = apiSection; Assert.AreEqual(1, sect.Section.MaterialAnalysisProperty); Assert.AreEqual(2, sect.Section.MaterialGradeProperty); Assert.AreEqual(MaterialType.CONCRETE.ToString(), sect.Section.MaterialType.ToString()); Assert.AreEqual("mariam", sect.Section.Name); Assert.AreEqual(4, sect.Section.Pool); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } } else { section.ID = 1; } elem.Section = section; DA.SetData(0, new GsaElement1dGoo(elem)); } } }
protected override void SolveInstance(IGH_DataAccess DA) { #region GetData Models = null; Nodes = null; Elem1ds = null; Elem2ds = null; Elem3ds = null; Mem1ds = null; Mem2ds = null; Mem3ds = null; Loads = null; Sections = null; Prop2Ds = null; GridPlaneSurfaces = null; // Get Model input List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, gh_types)) { List <GsaModel> in_models = new List <GsaModel>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ == null) { Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input is null"); return; } if (gh_typ.Value is GsaModelGoo) { GsaModel in_model = new GsaModel(); gh_typ.CastTo(ref in_model); in_models.Add(in_model); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " + type + " to GsaModel"); return; } } Models = in_models; } // Get Section Property input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(1, gh_types)) { List <GsaSection> in_sect = new List <GsaSection>(); List <GsaProp2d> in_prop = new List <GsaProp2d>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaSectionGoo) { GsaSection gsasection = new GsaSection(); gh_typ.CastTo(ref gsasection); in_sect.Add(gsasection.Duplicate()); } else if (gh_typ.Value is GsaProp2dGoo) { GsaProp2d gsaprop = new GsaProp2d(); gh_typ.CastTo(ref gsaprop); in_prop.Add(gsaprop.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " + type + " to GsaSection or GsaProp2d"); return; } } if (in_sect.Count > 0) { Sections = in_sect; } if (in_prop.Count > 0) { Prop2Ds = in_prop; } } // Get Geometry input gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); List <GsaElement1d> in_elem1ds = new List <GsaElement1d>(); List <GsaElement2d> in_elem2ds = new List <GsaElement2d>(); List <GsaElement3d> in_elem3ds = new List <GsaElement3d>(); List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode.Duplicate()); } else if (gh_typ.Value is GsaElement1dGoo) { GsaElement1d gsaelem1 = new GsaElement1d(); gh_typ.CastTo(ref gsaelem1); in_elem1ds.Add(gsaelem1.Duplicate()); } else if (gh_typ.Value is GsaElement2dGoo) { GsaElement2d gsaelem2 = new GsaElement2d(); gh_typ.CastTo(ref gsaelem2); in_elem2ds.Add(gsaelem2.Duplicate()); } else if (gh_typ.Value is GsaElement3dGoo) { GsaElement3d gsaelem3 = new GsaElement3d(); gh_typ.CastTo(ref gsaelem3); in_elem3ds.Add(gsaelem3.Duplicate()); } else if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1.Duplicate()); } else if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2.Duplicate()); } else if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " + type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D"); return; } } if (in_nodes.Count > 0) { Nodes = in_nodes; } if (in_elem1ds.Count > 0) { Elem1ds = in_elem1ds; } if (in_elem2ds.Count > 0) { Elem2ds = in_elem2ds; } if (in_elem3ds.Count > 0) { Elem3ds = in_elem3ds; } if (in_mem1ds.Count > 0) { Mem1ds = in_mem1ds; } if (in_mem2ds.Count > 0) { Mem2ds = in_mem2ds; } if (in_mem3ds.Count > 0) { Mem3ds = in_mem3ds; } } // Get Loads input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(3, gh_types)) { List <GsaLoad> in_loads = new List <GsaLoad>(); List <GsaGridPlaneSurface> in_gps = new List <GsaGridPlaneSurface>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaLoadGoo) { GsaLoad gsaload = null; gh_typ.CastTo(ref gsaload); in_loads.Add(gsaload.Duplicate()); } else if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface(); gh_typ.CastTo(ref gsaGPS); in_gps.Add(gsaGPS.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " + type + " to Load or GridPlaneSurface"); return; } } if (in_loads.Count > 0) { Loads = in_loads; } if (in_gps.Count > 0) { GridPlaneSurfaces = in_gps; } } // manually add a warning if no input is set, as all inputs are optional if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null & Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); return; } #endregion #region DoWork GsaModel analysisModel = null; if (Models != null) { if (Models.Count > 0) { if (Models.Count > 1) { analysisModel = Util.Gsa.ToGSA.Models.MergeModel(Models); } else { analysisModel = Models[0].Clone(); } } } if (analysisModel != null) { OutModel = analysisModel; } else { OutModel = new GsaModel(); } // Assemble model Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(analysisModel, Nodes, Elem1ds, Elem2ds, Elem3ds, Mem1ds, Mem2ds, Mem3ds, Sections, Prop2Ds, Loads, GridPlaneSurfaces); //gsa.SaveAs(@"C:\Users\Kristjan.Nielsen\Desktop\test3.gwb"); #region meshing // Create elements from members gsa.CreateElementsFromMembers(); #endregion #region analysis //analysis IReadOnlyDictionary <int, AnalysisTask> gsaTasks = gsa.AnalysisTasks(); if (gsaTasks.Count < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Model contains no Analysis Tasks"); } foreach (KeyValuePair <int, AnalysisTask> task in gsaTasks) { if (!(gsa.Analyse(task.Key))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning Analysis Case " + task.Key + " could not be analysed"); } } #endregion OutModel.Model = gsa; //gsa.SaveAs("C:\\Users\\Kristjan.Nielsen\\Desktop\\GsaGH_test.gwb"); #endregion #region SetData DA.SetData(0, new GsaModelGoo(OutModel)); #endregion }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember1d gsaMember1d = new GsaMember1d(); if (DA.GetData(0, ref gsaMember1d)) { if (gsaMember1d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member1D input is null"); } GsaMember1d mem = gsaMember1d.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { mem.ID = id; } } // 2 curve GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(2, ref ghcrv)) { Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d tempmem = new GsaMember1d(crv); mem.PolyCurve = tempmem.PolyCurve; mem.Topology = tempmem.Topology; mem.TopologyType = tempmem.TopologyType; } } // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); mem.Section = section; mem.Member.Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; mem.Section = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }
/// <summary> /// Method to import 1D and 2D Elements from a GSA model. /// Will output a tuple of GhSA GsaElement1d and GsaElement2d. /// Filter elements to import using elemList input; /// "all" or empty string ("") will import all elements. Default is "all" /// "Join" bool = true; will try to join 2D element mesh faces into a joined meshes. /// </summary> /// <param name="model"></param> /// <param name="elemList"></param> /// <param name="join"></param> /// <returns></returns> public static Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> > GsaGetElem(Model model, string elemList = "all", bool join = true) { // Create dictionaries to read list of elements and nodes: IReadOnlyDictionary <int, Element> eDict; eDict = model.Elements(elemList); IReadOnlyDictionary <int, Node> nDict; nDict = model.Nodes("all"); IReadOnlyDictionary <int, Section> sDict; sDict = model.Sections(); IReadOnlyDictionary <int, Prop2D> pDict; pDict = model.Prop2Ds(); GsaElement2d elem2d = new GsaElement2d(); // Create lists for Rhino lines and meshes DataTree <GsaElement1dGoo> elem1ds = new DataTree <GsaElement1dGoo>(); DataTree <GsaElement2dGoo> elem2ds = new DataTree <GsaElement2dGoo>(); DataTree <Element> elements = new DataTree <Element>(); DataTree <Mesh> meshes = new DataTree <Mesh>(); List <Point3d> pts = new List <Point3d>(); GH_Path path = new GH_Path(); if (!join) { elem1ds.EnsurePath(0); elem2ds.EnsurePath(0); int max = eDict.Count; if (max > 0) { //elem1ds.Branches[0].. = new List<GsaElement1dGoo>(max); //elem2ds.Branches[0] = new List<GsaElement2dGoo>(max); //for (int i = 0; i < eDict.Keys.ElementAt(max - 1); i++) //{ // elem1ds.Branches[0].Add(null); // elem2ds.Branches[0].Add(null); //} } } // Loop through all nodes in Node dictionary and add points to Rhino point list foreach (var key in eDict.Keys) { if (eDict.TryGetValue(key, out Element elem)) { List <int> topo = elem.Topology.ToList(); int prop = 0; if (join) { prop = elem.Property - 1; // actually branch not property } // Beams (1D elements): if (topo.Count == 2) { for (int i = 0; i <= 1; i++) { if (nDict.TryGetValue(topo[i], out Node node)) { { var p = node.Position; pts.Add(new Point3d(p.X, p.Y, p.Z)); } node.Dispose(); } } Line line = new Line(pts[0], pts[1]); LineCurve ln = new LineCurve(line); GsaElement1d elem1d = new GsaElement1d(ln) { Element = elem }; elem1d.ReleaseStart = new GsaBool6() { X = elem.Release(0).X, Y = elem.Release(0).Y, Z = elem.Release(0).Z, XX = elem.Release(0).XX, YY = elem.Release(0).YY, ZZ = elem.Release(0).ZZ }; elem1d.ReleaseEnd = new GsaBool6() { X = elem.Release(1).X, Y = elem.Release(1).Y, Z = elem.Release(1).Z, XX = elem.Release(1).XX, YY = elem.Release(1).YY, ZZ = elem.Release(1).ZZ }; GsaSection section = new GsaSection { ID = elem.Property }; Section tempSection = new Section(); if (sDict.TryGetValue(section.ID, out tempSection)) { section.Section = tempSection; } elem1d.Section = section; elem1d.ID = key; pts.Clear(); elem1ds.EnsurePath(prop); path = new GH_Path(prop); if (join) { elem1ds.Add(new GsaElement1dGoo(elem1d), path); } else { elem1ds.Insert(new GsaElement1dGoo(elem1d), path, key - 1); } //elem1ds[path, key - 1] = new GsaElement1dGoo(elem1d.Duplicate()); } // Shells (2D elements) if (topo.Count > 2) // & topo.Count < 5) { Mesh tempMesh = new Mesh(); // Get verticies: for (int i = 0; i < topo.Count; i++) { if (nDict.TryGetValue(topo[i], out Node node)) { { var p = node.Position; tempMesh.Vertices.Add(new Point3d(p.X, p.Y, p.Z)); } node.Dispose(); } } // Create mesh face (Tri- or Quad): if (topo.Count == 3) { tempMesh.Faces.AddFace(0, 1, 2); } if (topo.Count == 4) { tempMesh.Faces.AddFace(0, 1, 2, 3); } else { //it must be a TRI6 or a QUAD8 List <Point3f> tempPts = tempMesh.Vertices.ToList(); double x = 0; double y = 0; double z = 0; for (int i = 0; i < tempPts.Count; i++) { x += tempPts[i].X; y += tempPts[i].Y; z += tempPts[i].Z; } x /= tempPts.Count; y /= tempPts.Count; z /= tempPts.Count; tempMesh.Vertices.Add(new Point3d(x, y, z)); if (topo.Count == 6) { tempMesh.Faces.AddFace(0, 3, 6); tempMesh.Faces.AddFace(3, 1, 6); tempMesh.Faces.AddFace(1, 4, 6); tempMesh.Faces.AddFace(4, 2, 6); tempMesh.Faces.AddFace(2, 5, 6); tempMesh.Faces.AddFace(5, 0, 6); } if (topo.Count == 8) { tempMesh.Faces.AddFace(0, 4, 8, 7); tempMesh.Faces.AddFace(1, 5, 8, 4); tempMesh.Faces.AddFace(2, 6, 8, 5); tempMesh.Faces.AddFace(3, 7, 8, 6); } } List <int> ids = new List <int> { key }; elem2d.ID = ids; List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); GsaProp2d prop2d = new GsaProp2d { ID = elem.Property }; Prop2D tempProp = new Prop2D(); if (pDict.TryGetValue(prop2d.ID, out tempProp)) { prop2d.Prop2d = tempProp; } prop2Ds.Add(prop2d); elem2d.Properties = prop2Ds; if (join) { meshes.EnsurePath(prop); elements.EnsurePath(prop); path = new GH_Path(prop); meshes.Add(tempMesh.DuplicateMesh(), path); elements.Add(elem, path); } else { elem2d = new GsaElement2d(tempMesh); List <Element> elemProps = new List <Element> { elem }; elem2d.Elements = elemProps; elem2d.Properties = prop2Ds; elem2d.ID = ids; elem2ds.Insert(new GsaElement2dGoo(elem2d), path, key - 1); //elem2ds[path, key - 1] = new GsaElement2dGoo(elem2d.Duplicate()); //elem2ds.Add(new GsaElement2dGoo(elem2d.Duplicate())); } tempMesh.Dispose(); elem.Dispose(); } } } if (join) { foreach (GH_Path ipath in meshes.Paths) { //##### Join meshes ##### //List of meshes in each branch List <Mesh> mList = meshes.Branch(ipath); //new temp mesh Mesh m = new Mesh(); //Append list of meshes (faster than appending each mesh one by one) m.Append(mList); //split mesh into connected pieces Mesh[] meshy = m.SplitDisjointPieces(); //clear whatever is in the current branch (the list in mList) meshes.Branch(ipath).Clear(); //rewrite new joined and split meshes to new list in same path: for (int j = 0; j < meshy.Count(); j++) { meshes.Add(meshy[j], ipath); } } foreach (GH_Path ipath in meshes.Paths) { List <Mesh> mList = meshes.Branch(ipath); foreach (Mesh mesh in mList) { elem2d = new GsaElement2d(mesh); List <Element> elemProps = new List <Element>(); for (int i = 0; i < mesh.Faces.Count(); i++) { elemProps.Add(elements[ipath, 0]); } elem2d.Elements = elemProps; List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); GsaProp2d prop2d = new GsaProp2d { ID = ipath.Indices[0] + 1 }; Prop2D tempProp = new Prop2D(); if (pDict.TryGetValue(prop2d.ID, out tempProp)) { prop2d.Prop2d = tempProp; } prop2Ds.Add(prop2d); elem2d.Properties = prop2Ds; elem2ds.Add(new GsaElement2dGoo(elem2d)); } } } return(new Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> >(elem1ds, elem2ds)); }
protected override void SolveInstance(IGH_DataAccess DA) { 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); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(0, ref ghcrv)) { if (ghcrv == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Curve input is null"); } Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d mem = new GsaMember1d(crv); GsaBool6 rel1 = new GsaBool6 { X = x1, Y = y1, Z = z1, XX = xx1, YY = yy1, ZZ = zz1 }; mem.ReleaseStart = rel1; GsaBool6 rel2 = new GsaBool6 { X = x2, Y = y2, Z = z2, XX = xx2, YY = yy2, ZZ = zz2 }; mem.ReleaseEnd = rel2; // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); mem.Section = section; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaMember1dGoo(mem)); }
public static SpeckleObject ToSpeckle(this GsaSection dummyObject) { var settings = Initialiser.AppResources.Settings; var element1dResults = settings.ResultTypes != null && settings.ResultTypes.Any(rt => rt.ToString().ToLower().Contains("1d")); if (settings.TargetLayer == GSATargetLayer.Analysis && settings.StreamSendConfig == StreamContentConfig.TabularResultsOnly && !element1dResults) { return(new SpeckleNull()); } var kw = GsaRecord.GetKeyword <GsaSection>(); var newLines = Initialiser.AppResources.Cache.GetGwaToSerialise(kw); int numAdded = 0; var structural1DPropertyExplicits = new List <Structural1DPropertyExplicit>(); var concreteMaterials = Initialiser.GsaKit.GSASenderObjects.Get <GSAMaterialConcrete>().ToDictionary(o => o.GSAId, o => ((StructuralMaterialConcrete)o.SpeckleObject).ApplicationId); var steelMaterials = Initialiser.GsaKit.GSASenderObjects.Get <GSAMaterialSteel>().ToDictionary(o => o.GSAId, o => ((StructuralMaterialSteel)o.SpeckleObject).ApplicationId); //Currently only handles explicit 1D properties //Filtering out all but explicit properties: //1. First exclude any GWA lines with the exact string "EXP" - make first pass at filtering them out //2. Call FromGwa for all and perform logic check of values of GsaSection (and subclass) instances var indicesContainingEXP = newLines.Keys.Where(k => newLines[k].Contains("EXP")).ToList(); var gsaSectionsExp = new List <GsaSection>(); foreach (var i in indicesContainingEXP) { var obj = Helper.ToSpeckleTryCatch(dummyObject.Keyword, i, () => { var gsaSection = new GsaSection(); if (gsaSection.FromGwa(newLines[i]) && FindExpDetails(gsaSection, out var comp, out var pde)) { if (string.IsNullOrEmpty(gsaSection.ApplicationId)) { gsaSection.ApplicationId = SpeckleStructuralGSA.Helper.FormatApplicationId(kw, i); } var structuralProp = new Structural1DPropertyExplicit() { Name = gsaSection.Name, ApplicationId = gsaSection.ApplicationId, Area = pde.Area, Iyy = pde.Iyy, Izz = pde.Izz, J = pde.J, Ky = pde.Ky, Kz = pde.Kz }; //No support for any other material type at this stage if (comp.MaterialType == Section1dMaterialType.CONCRETE || comp.MaterialType == Section1dMaterialType.STEEL) { var materialIndex = comp.MaterialIndex ?? 0; var materialDict = (comp.MaterialType == Section1dMaterialType.CONCRETE) ? concreteMaterials : steelMaterials; structuralProp.MaterialRef = (materialIndex > 0 && materialDict.ContainsKey(materialIndex)) ? materialDict[materialIndex] : null; } return(structuralProp); } return(new SpeckleNull()); });
public static void ConvertSection(List <GsaSection> sections, ref Dictionary <int, Section> existingSections, ref Dictionary <Guid, int> sections_guid, GrasshopperAsyncComponent.WorkerInstance workerInstance = null, Action <string, double> ReportProgress = null) { // create a counter for creating new nodes int sectionidcounter = (existingSections.Count > 0) ? existingSections.Keys.Max() + 1 : 1; //checking the existing model // Add/Set Nodes if (sections != null) { if (sections.Count != 0) { // update counter if new sections have set ID higher than existing max int existingSectionsMaxID = sections.Max(x => x.ID); // max ID in new if (existingSectionsMaxID > sectionidcounter) { sectionidcounter = existingSectionsMaxID + 1; } for (int i = 0; i < sections.Count; i++) { if (workerInstance != null) { if (workerInstance.CancellationToken.IsCancellationRequested) { return; } ReportProgress("Sections ", (double)i / (sections.Count - 1)); } if (sections[i] != null) { GsaSection section = sections[i]; Section apiSection = section.Section; if (sections_guid.ContainsKey(section.GUID)) { sections_guid.TryGetValue(section.GUID, out int sID); // if guid exist in our dictionary it has been added to the model continue; } if (section.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list { existingSections[section.ID] = apiSection; // set guid in dictionary sections_guid.Add(section.GUID, section.ID); } else { existingSections.Add(sectionidcounter, apiSection); // set guid in dictionary sections_guid.Add(section.GUID, sectionidcounter); sectionidcounter++; } } } } } if (workerInstance != null) { ReportProgress("Sections assembled", -2); } }
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); } } }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { #region GetData Models = null; Nodes = null; Elem1ds = null; Elem2ds = null; Elem3ds = null; Mem1ds = null; Mem2ds = null; Mem3ds = null; Loads = null; Sections = null; Prop2Ds = null; GridPlaneSurfaces = null; OutModel = null; component = Params.Owner; // Get Model input List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, gh_types)) { List <GsaModel> in_models = new List <GsaModel>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaModelGoo) { GsaModel in_model = new GsaModel(); gh_typ.CastTo(ref in_model); in_models.Add(in_model); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " + type + " to GsaModel"); return; } } Models = in_models; } // Get Section Property input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(1, gh_types)) { List <GsaSection> in_sect = new List <GsaSection>(); List <GsaProp2d> in_prop = new List <GsaProp2d>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaSectionGoo) { GsaSection gsasection = new GsaSection(); gh_typ.CastTo(ref gsasection); in_sect.Add(gsasection.Duplicate()); } else if (gh_typ.Value is GsaProp2dGoo) { GsaProp2d gsaprop = new GsaProp2d(); gh_typ.CastTo(ref gsaprop); in_prop.Add(gsaprop.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " + type + " to GsaSection or GsaProp2d"); return; } } if (in_sect.Count > 0) { Sections = in_sect; } if (in_prop.Count > 0) { Prop2Ds = in_prop; } } // Get Geometry input gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); List <GsaElement1d> in_elem1ds = new List <GsaElement1d>(); List <GsaElement2d> in_elem2ds = new List <GsaElement2d>(); List <GsaElement3d> in_elem3ds = new List <GsaElement3d>(); List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode.Duplicate()); } else if (gh_typ.Value is GsaElement1dGoo) { GsaElement1d gsaelem1 = new GsaElement1d(); gh_typ.CastTo(ref gsaelem1); in_elem1ds.Add(gsaelem1.Duplicate()); } else if (gh_typ.Value is GsaElement2dGoo) { GsaElement2d gsaelem2 = new GsaElement2d(); gh_typ.CastTo(ref gsaelem2); in_elem2ds.Add(gsaelem2.Duplicate()); } else if (gh_typ.Value is GsaElement3dGoo) { GsaElement3d gsaelem3 = new GsaElement3d(); gh_typ.CastTo(ref gsaelem3); in_elem3ds.Add(gsaelem3.Duplicate()); } else if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1.Duplicate()); } else if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2.Duplicate()); } else if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " + type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D"); return; } } if (in_nodes.Count > 0) { Nodes = in_nodes; } if (in_elem1ds.Count > 0) { Elem1ds = in_elem1ds; } if (in_elem2ds.Count > 0) { Elem2ds = in_elem2ds; } if (in_elem3ds.Count > 0) { Elem3ds = in_elem3ds; } if (in_mem1ds.Count > 0) { Mem1ds = in_mem1ds; } if (in_mem2ds.Count > 0) { Mem2ds = in_mem2ds; } if (in_mem3ds.Count > 0) { Mem3ds = in_mem3ds; } } // Get Loads input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(3, gh_types)) { List <GsaLoad> in_loads = new List <GsaLoad>(); List <GsaGridPlaneSurface> in_gps = new List <GsaGridPlaneSurface>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaLoadGoo) { GsaLoad gsaload = null; gh_typ.CastTo(ref gsaload); in_loads.Add(gsaload.Duplicate()); } else if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface(); gh_typ.CastTo(ref gsaGPS); in_gps.Add(gsaGPS.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " + type + " to Load or GridPlaneSurface"); return; } } if (in_loads.Count > 0) { Loads = in_loads; } if (in_gps.Count > 0) { GridPlaneSurfaces = in_gps; } } #endregion // manually add a warning if no input is set, as all inputs are optional if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null & Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null) { hasInput = false; Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); return; } else { hasInput = true; } }
protected override void SolveInstance(IGH_DataAccess DA) { 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); } }
/// <summary> /// Method to import 1D and 2D Members from a GSA model. /// Will output a tuple of GhSA GsaMember1d and GsaMember2d. /// Filter members to import using memList input; /// "all" or empty string ("") will import all elements. Default is "all" /// "propGraft" bool = true; will put members in Grasshopper branch corrosponding to its property /// </summary> /// <param name="model"></param> /// <param name="memList"></param> /// <param name="propGraft"></param> /// <returns></returns> public static Tuple <DataTree <GsaMember1dGoo>, DataTree <GsaMember2dGoo> > GsaGetMemb(Model model, string memList = "all", bool propGraft = true) { // Create dictionaries to read list of elements and nodes: IReadOnlyDictionary <int, Member> mDict; mDict = model.Members(memList); IReadOnlyDictionary <int, Node> nDict; nDict = model.Nodes("all"); IReadOnlyDictionary <int, Section> sDict; sDict = model.Sections(); IReadOnlyDictionary <int, Prop2D> pDict; pDict = model.Prop2Ds(); // Create lists for Rhino lines and meshes DataTree <GsaMember1dGoo> mem1ds = new DataTree <GsaMember1dGoo>(); DataTree <GsaMember2dGoo> mem2ds = new DataTree <GsaMember2dGoo>(); if (!propGraft) { mem1ds.EnsurePath(0); mem2ds.EnsurePath(0); int max = mDict.Count; if (max > 0) { for (int i = 0; i < mDict.Keys.ElementAt(max - 1); i++) { mem1ds.Branches[0].Add(null); mem2ds.Branches[0].Add(null); } } } // Loop through all members in Member dictionary foreach (var key in mDict.Keys) { if (mDict.TryGetValue(key, out Member mem)) { int prop = 0; if (propGraft) { prop = mem.Property - 1; } // Build topology lists string toporg = mem.Topology; //original topology list Tuple <Tuple <List <int>, List <string> >, Tuple <List <List <int> >, List <List <string> > >, Tuple <List <List <int> >, List <List <string> > >, List <int> > topologyTuple = Topology_detangler(toporg); Tuple <List <int>, List <string> > topoTuple = topologyTuple.Item1; Tuple <List <List <int> >, List <List <string> > > voidTuple = topologyTuple.Item2; Tuple <List <List <int> >, List <List <string> > > lineTuple = topologyTuple.Item3; List <int> topo_int = topoTuple.Item1; List <string> topoType = topoTuple.Item2; //list of polyline curve type (arch or line) for member1d/2d List <List <int> > void_topo_int = voidTuple.Item1; List <List <string> > void_topoType = voidTuple.Item2; //list of polyline curve type (arch or line) for void /member2d List <List <int> > incLines_topo_int = lineTuple.Item1; List <List <string> > inclLines_topoType = lineTuple.Item2; //list of polyline curve type (arch or line) for inclusion /member2d List <int> inclpts = topologyTuple.Item4; // replace topology integers with actual points List <Point3d> topopts = new List <Point3d>(); // list of topology points for visualisation /member1d/member2d for (int i = 0; i < topo_int.Count; i++) { if (nDict.TryGetValue(topo_int[i], out Node node)) { var p = node.Position; topopts.Add(new Point3d(p.X, p.Y, p.Z)); } node.Dispose(); } //list of lists of void points /member2d List <List <Point3d> > void_topo = new List <List <Point3d> >(); for (int i = 0; i < void_topo_int.Count; i++) { void_topo.Add(new List <Point3d>()); for (int j = 0; j < void_topo_int[i].Count; j++) { if (nDict.TryGetValue(void_topo_int[i][j], out Node node)) { var p = node.Position; void_topo[i].Add(new Point3d(p.X, p.Y, p.Z)); } node.Dispose(); } } //list of lists of line inclusion topology points /member2d List <List <Point3d> > incLines_topo = new List <List <Point3d> >(); for (int i = 0; i < incLines_topo_int.Count; i++) { incLines_topo.Add(new List <Point3d>()); for (int j = 0; j < incLines_topo_int[i].Count; j++) { if (nDict.TryGetValue(incLines_topo_int[i][j], out Node node)) { var p = node.Position; incLines_topo[i].Add(new Point3d(p.X, p.Y, p.Z)); } node.Dispose(); } } //list of points for inclusion /member2d List <Point3d> incl_pts = new List <Point3d>(); for (int i = 0; i < inclpts.Count; i++) { if (nDict.TryGetValue(inclpts[i], out Node node)) { var p = node.Position; incl_pts.Add(new Point3d(p.X, p.Y, p.Z)); } node.Dispose(); } if (mem.Type == MemberType.GENERIC_1D | mem.Type == MemberType.BEAM | mem.Type == MemberType.CANTILEVER | mem.Type == MemberType.COLUMN | mem.Type == MemberType.COMPOS | mem.Type == MemberType.PILE) { GsaMember1d mem1d = new GsaMember1d(topopts, topoType) { ID = key, Member = mem }; GsaSection section = new GsaSection { ID = mem.Property }; if (sDict.TryGetValue(section.ID, out Section tempSection)) { section.Section = tempSection; } mem1d.Section = section; mem1ds.EnsurePath(prop); GH_Path path = new GH_Path(prop); if (propGraft) { mem1ds.Add(new GsaMember1dGoo(mem1d.Duplicate()), path); } else { mem1ds[path, key - 1] = new GsaMember1dGoo(mem1d.Duplicate()); } } else { GsaMember2d mem2d = new GsaMember2d(topopts, topoType, void_topo, void_topoType, incLines_topo, inclLines_topoType, incl_pts) { Member = mem, ID = key }; GsaProp2d prop2d = new GsaProp2d { ID = mem.Property }; if (pDict.TryGetValue(prop2d.ID, out Prop2D tempProp)) { prop2d.Prop2d = tempProp; } mem2d.Property = prop2d; mem2ds.EnsurePath(prop); GH_Path path = new GH_Path(prop); if (propGraft) { mem2ds.Add(new GsaMember2dGoo(mem2d.Duplicate()), path); } else { mem2ds[path, key - 1] = new GsaMember2dGoo(mem2d.Duplicate()); } } topopts.Clear(); topoType.Clear(); void_topo.Clear(); void_topoType.Clear(); incLines_topo.Clear(); inclLines_topoType.Clear(); incl_pts.Clear(); } } return(new Tuple <DataTree <GsaMember1dGoo>, DataTree <GsaMember2dGoo> >(mem1ds, mem2ds)); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(0, ref ghcrv)) { Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d mem = new GsaMember1d(crv); GsaBool6 rel1 = new GsaBool6 { X = x1, Y = y1, Z = z1, XX = xx1, YY = yy1, ZZ = zz1 }; mem.ReleaseStart = rel1; GsaBool6 rel2 = new GsaBool6 { X = x2, Y = y2, Z = z2, XX = xx2, YY = yy2, ZZ = zz2 }; mem.ReleaseEnd = rel2; // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } } else { section.ID = 1; } mem.Section = section; DA.SetData(0, new GsaMember1dGoo(mem)); } } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement1d gsaElement1d = new GsaElement1d(); if (DA.GetData(0, ref gsaElement1d)) { if (gsaElement1d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element1D input is null"); } GsaElement1d elem = gsaElement1d.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)) { elem.ID = id; } } // 2 curve GH_Line ghcrv = new GH_Line(); if (DA.GetData(2, 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; } } // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); elem.Section = section; elem.Element.Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Element.Property = idd; elem.Section = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }