public static string ToNative(this StructuralStorey storey) { if (string.IsNullOrEmpty(storey.ApplicationId) && Helper.IsZeroAxis(storey.Axis)) { return(""); } return(Helper.ToNativeTryCatch(storey, () => { var keyword = GsaRecord.GetKeyword <GsaGridPlane>(); var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, storey.ApplicationId); var streamId = Initialiser.AppResources.Cache.LookupStream(storey.ApplicationId); var gsaPlane = new GsaGridPlane() { Index = index, ApplicationId = storey.ApplicationId, StreamId = streamId, Name = storey.Name, Elevation = storey.Elevation, Type = GridPlaneType.Storey, }; gsaPlane.StoreyToleranceAboveAuto = (!storey.ToleranceAbove.HasValue || storey.ToleranceAbove.Value == 0); if (storey.ToleranceBelow.HasValue && storey.ToleranceBelow.Value != 0) { gsaPlane.StoreyToleranceBelow = storey.ToleranceBelow; } gsaPlane.StoreyToleranceBelowAuto = (!storey.ToleranceBelow.HasValue || storey.ToleranceBelow.Value == 0); if (!gsaPlane.StoreyToleranceAboveAuto) { gsaPlane.StoreyToleranceAbove = storey.ToleranceAbove; } if (storey.ValidNonZero()) { gsaPlane.AxisRefType = GridPlaneAxisRefType.Reference; //Create new axis on the fly here var gsaAxis = StructuralAxisToNative.ToNativeSchema(storey.Axis); StructuralAxisToNative.ToNative(gsaAxis); gsaPlane.AxisIndex = gsaAxis.Index; } else { gsaPlane.AxisRefType = GridPlaneAxisRefType.Global; } if (gsaPlane.Gwa(out var gsaPlaneGwaLines, true)) { Initialiser.AppResources.Cache.Upsert(keyword, index, gsaPlaneGwaLines.First(), streamId, storey.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaLoadCase>()); } return ""; }));
private static bool Add0dLoadsWithoutAppId(string keyword, string nodeKeyword, string loadCaseKeyword, IEnumerable <GsaLoadNode> gsaLoads, List <GSANode> gsaNodes, ref List <Structural0DLoad> structural0DLoads, ref List <int> nodeIndicesReferenced) { var summaries = new List <D0LoadingSummary>(); var uniqueLoadings = new List <StructuralVectorSix>(); foreach (var gl in gsaLoads.Where(l => l.Value != null)) { var relevantGsaNodes = gsaNodes.Where(n => gl.NodeIndices.Any(ni => ni == n.GSAId)).ToList(); foreach (var n in relevantGsaNodes) { var loading = Helper.GsaLoadToLoading(gl.LoadDirection, gl.Value.Value); int?uniqueLoadingIndex = null; if (!gl.GlobalAxis) { var loadAxis = (StructuralAxis)SpeckleStructuralGSA.Helper.Parse0DAxis(gl.AxisIndex.Value, out string _, n.Value.Value.ToArray()); if (!Helper.IsZeroAxis(loadAxis)) { //Converts from loads on an axis to their global equivalent loading.TransformOntoAxis(loadAxis); } } if (loading != null) { var matching = uniqueLoadings.Where(k => k.Value.SequenceEqual(loading.Value)); if (matching.Count() > 0) { uniqueLoadingIndex = uniqueLoadings.IndexOf(matching.First()); } else { uniqueLoadingIndex = uniqueLoadings.Count(); uniqueLoadings.Add(loading); } } summaries.Add(new D0LoadingSummary(gl.Index.Value, gl.LoadCaseIndex, n.GSAId) { UniqueLoadingIndex = uniqueLoadingIndex, Name = gl.Name }); } } var groups = summaries.GroupBy(s => new { s.LoadCaseIndex, s.UniqueLoadingIndex }); var allNodeIndices = nodeIndicesReferenced.ToList(); foreach (var group in groups) { var indices = group.Select(i => i.Index).Distinct().ToList(); var nodeIndices = group.Select(i => i.NodeIndex).Where(i => i != null).Distinct().ToList(); allNodeIndices.AddRange(nodeIndices.Where(ni => ni.HasValue && !allNodeIndices.Contains(ni.Value)).Select(ni => ni.Value)); var nodeRefs = nodeIndices.Select(ni => SpeckleStructuralGSA.Helper.GetApplicationId(nodeKeyword, ni.Value)).OrderBy(r => r).ToList(); var loadCaseRef = SpeckleStructuralGSA.Helper.GetApplicationId(loadCaseKeyword, group.First().LoadCaseIndex.Value); var applicationId = SpeckleStructuralGSA.Helper.FormatApplicationId(keyword, indices); var name = string.Join("-", group.Where(i => !string.IsNullOrEmpty(i.Name)).Select(i => i.Name)); var loading = uniqueLoadings[group.First().UniqueLoadingIndex.Value]; var obj = new Structural0DLoad() { ApplicationId = applicationId, Loading = loading, NodeRefs = nodeRefs, LoadCaseRef = loadCaseRef }; if (!string.IsNullOrEmpty(name)) { obj.Name = name; } Helper.AddCustomStructuralProperty(obj, indices.Count() == 1 ? "NativeId" : "NativeIds", indices.Count() == 1 ? (object)indices.First().ToString() : indices.Select(i => i.ToString()).ToList()); structural0DLoads.Add(obj); } nodeIndicesReferenced = allNodeIndices; return(true); }