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 ""; }));
public static string ToNative(this Structural2DLoadPanel loadPanel) { if (string.IsNullOrEmpty(loadPanel.ApplicationId)) { return(""); } if (loadPanel.Loading == null || loadPanel.Loading.Value == null || loadPanel.Loading.Value.All(v => v == 0)) { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Structural2DLoadPanel with no loading", loadPanel.ApplicationId); return(""); } var keyword = GsaRecord.GetKeyword <GsaLoadGridArea>(); var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadGridArea>(); var streamId = Initialiser.AppResources.Cache.LookupStream(loadPanel.ApplicationId); var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>(); var loadCaseIndex = Initialiser.AppResources.Cache.ResolveIndex(loadCaseKeyword, loadPanel.LoadCaseRef); var loadingDict = ExplodeLoading(loadPanel.Loading); var originalPolyline = loadPanel.Value.ToArray(); //There are two possible axes at play here: //1. one associated with the grid surface (referred by LoadPlaneRef) applied to the coordinates of the polyline //2. one associated with the loading - i.e. applied to the load //Note: only the first is supported here //When retrieving the axis (to use in transforming the polyline etc), there are two routes here: //1. referencing a load plane (grid surface) //2. not referencing a load plane, in which case a grid surface and axis needs to be created var gridSurfaceKeyword = GsaRecord.GetKeyword <GsaGridSurface>(); var gridPlaneKeyword = GsaRecord.GetKeyword <GsaGridPlane>(); var axisKeyword = GsaRecord.GetKeyword <GsaAxis>(); StructuralAxis axis = null; int gridSurfaceIndex = 0; if (string.IsNullOrEmpty(loadPanel.LoadPlaneRef)) { //If there is no load plane (corresponding to GRID_SURFACE in GSA terms) specified, then at minimum a GRID_SURFACE still needs //to be created but it doesn't need to refer to a GRID_PLANE because that load plane can just have "GLOBAL" set for its plane. //HOWEVER, the approach taken here - which could be reviewed - is to create one anyway, whose X and y axes are based on the polyline //so that an elevation value can be set in the GRID_PLANE //Create axis based on the polyline try { axis = SpeckleStructuralGSA.Helper.Parse2DAxis(originalPolyline); axis.Name = loadPanel.Name; var gsaAxis = StructuralAxisToNative.ToNativeSchema(axis); gsaAxis.StreamId = streamId; StructuralAxisToNative.ToNative(gsaAxis); var gridPlaneIndex = Initialiser.AppResources.Cache.ResolveIndex(gridPlaneKeyword); var gsaGridPlane = new GsaGridPlane() { Index = gridPlaneIndex, Name = loadPanel.Name, StreamId = streamId, AxisRefType = GridPlaneAxisRefType.Reference, AxisIndex = gsaAxis.Index, Elevation = AxisElevation(axis, originalPolyline), Type = GridPlaneType.General, StoreyToleranceAboveAuto = true, StoreyToleranceBelowAuto = true }; if (gsaGridPlane.Gwa(out var gsaGridPlaneGwas, false)) { Initialiser.AppResources.Cache.Upsert(gridPlaneKeyword, gridPlaneIndex, gsaGridPlaneGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridPlane>()); } gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex(gridSurfaceKeyword); var gsaGridSurface = new GsaGridSurface() { Index = gridSurfaceIndex, PlaneRefType = GridPlaneAxisRefType.Reference, StreamId = streamId, PlaneIndex = gridPlaneIndex, Name = loadPanel.Name, AllIndices = true, Type = GridSurfaceElementsType.TwoD, Span = GridSurfaceSpan.One, Angle = 0, Tolerance = 0.01, Expansion = GridExpansion.PlaneCorner }; if (gsaGridSurface.Gwa(out var gsaGridSurfaceGwas, false)) { Initialiser.AppResources.Cache.Upsert(gridSurfaceKeyword, gridSurfaceIndex, gsaGridSurfaceGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridSurface>()); } } catch { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Generating axis from coordinates for 2D load panel", loadPanel.ApplicationId); } } else { //Get axis from load plane using LoadPlaneRef //Within this option, there are two routes to retrieve the axis: //1. the StructuralLoadPlane has its own axis (because AxisRefs aren't offered yet in the Structural classes) //2. the StructuralLoadPlane references a StructuralStorey, which has an axis gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex(gridSurfaceKeyword, loadPanel.LoadPlaneRef); var gsaGridSurfaceGwa = Initialiser.AppResources.Cache.GetGwa(gridSurfaceKeyword, gridSurfaceIndex).First(); var gsaGridSurface = new GsaGridSurface(); if (gsaGridSurface.FromGwa(gsaGridSurfaceGwa)) { if (gsaGridSurface.PlaneRefType == GridPlaneAxisRefType.Reference && gsaGridSurface.PlaneIndex.ValidNonZero()) { var gsaGridPlaneGwa = Initialiser.AppResources.Cache.GetGwa(gridPlaneKeyword, gsaGridSurface.PlaneIndex.Value).First(); var gsaGridPlane = new GsaGridPlane(); if (gsaGridPlane.FromGwa(gsaGridPlaneGwa)) { if (gsaGridPlane.AxisRefType == GridPlaneAxisRefType.Reference && gsaGridPlane.AxisIndex.ValidNonZero()) { var axisIndex = gsaGridPlane.AxisIndex.Value; var gsaAxisGwa = Initialiser.AppResources.Cache.GetGwa(axisKeyword, axisIndex).First(); var gsaAxis = new GsaAxis(); if (gsaAxis.FromGwa(gsaAxisGwa)) { axis = (StructuralAxis)gsaAxis.ToSpeckle(); } else { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Unable to parse AXIS GWA", loadPanel.ApplicationId); } } else { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Invalid AXIS reference", loadPanel.ApplicationId); } } else { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Unable to parse GRID_PLANE GWA", loadPanel.ApplicationId); } } else { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Invalid GRID_PLANE reference", loadPanel.ApplicationId); } } else { Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Unable to parse GRID_SURFACE GWA", loadPanel.ApplicationId); } } // Transform polygon coordinates to the relevant axis // keep in mind that the 2D load panel inherits from SpecklePolyline var polyline = SpeckleStructuralGSA.Helper.MapPointsGlobal2Local(originalPolyline, axis); foreach (var k in loadingDict.Keys) { var applicationId = string.Join("_", loadPanel.ApplicationId, k.ToString()); var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, applicationId); var gsaLoadPanel = new GsaLoadGridArea() { Index = index, ApplicationId = applicationId, StreamId = streamId, Name = loadPanel.Name, Value = loadingDict[k], GridSurfaceIndex = gridSurfaceIndex, LoadDirection = k, LoadCaseIndex = loadCaseIndex, //No support yet for an axis separate to the grid surface's, on which the loading is applied AxisRefType = AxisRefType.Global, //No support yet for whole-plane 2D load panels - all assumed to be based on polyline/polygon Area = LoadAreaOption.Polygon, Polygon = PolylineCoordsToGwaPolygon(polyline), Projected = false }; if (gsaLoadPanel.Gwa(out var gsaLoadPanelGwas, false)) { Initialiser.AppResources.Cache.Upsert(keyword, index, gsaLoadPanelGwas.First(), streamId, applicationId, GsaRecord.GetGwaSetCommandType <GsaLoadGridArea>()); } } return(""); }
public static string ToNative(this StructuralLoadPlane loadPlane) { if (string.IsNullOrEmpty(loadPlane.ApplicationId)) { return(""); } return(Helper.ToNativeTryCatch(loadPlane, () => { var keyword = GsaRecord.GetKeyword <GsaGridSurface>(); var storeyKeyword = GsaRecord.GetKeyword <GsaGridPlane>(); var streamId = Initialiser.AppResources.Cache.LookupStream(loadPlane.ApplicationId); var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, loadPlane.ApplicationId); var gsaGridSurface = new GsaGridSurface() { ApplicationId = loadPlane.ApplicationId, StreamId = streamId, Index = index, Name = loadPlane.Name, Tolerance = loadPlane.Tolerance, Angle = loadPlane.SpanAngle, Type = (loadPlane.ElementDimension.HasValue && loadPlane.ElementDimension.Value == 1) ? GridSurfaceElementsType.OneD : (loadPlane.ElementDimension.HasValue && loadPlane.ElementDimension.Value == 2) ? GridSurfaceElementsType.TwoD : GridSurfaceElementsType.NotSet, Span = (loadPlane.Span.HasValue && loadPlane.Span.Value == 1) ? GridSurfaceSpan.One : (loadPlane.Span.HasValue && loadPlane.Span.Value == 2) ? GridSurfaceSpan.Two : GridSurfaceSpan.NotSet, //There is no support for entity references in the structural schema, so leave entities blank, which is equal to "all" //There is no support for this argument in the Structural schema, and was even omitted from the GWA //in the previous version of the ToNative code Expansion = GridExpansion.PlaneCorner }; if (!string.IsNullOrEmpty(loadPlane.StoreyRef)) { var gridPlaneIndex = Initialiser.AppResources.Cache.LookupIndex(storeyKeyword, loadPlane.StoreyRef); if (gridPlaneIndex.ValidNonZero()) { gsaGridSurface.PlaneRefType = GridPlaneAxisRefType.Reference; gsaGridSurface.PlaneIndex = gridPlaneIndex; } } else if (loadPlane.Axis.ValidNonZero()) { gsaGridSurface.PlaneRefType = GridPlaneAxisRefType.Reference; //Create axis //Create new axis on the fly here var gsaAxis = StructuralAxisToNative.ToNativeSchema(loadPlane.Axis); StructuralAxisToNative.ToNative(gsaAxis); //Create plane - the key here is that it's not a storey, but a general, type of grid plane, //which is why the ToNative() method for SpeckleStorey shouldn't be used as it only creates storey-type GSA grid plane var gsaPlaneKeyword = GsaRecord.GetKeyword <GsaGridPlane>(); var planeIndex = Initialiser.AppResources.Cache.ResolveIndex(gsaPlaneKeyword); var gsaPlane = new GsaGridPlane() { Index = planeIndex, Name = loadPlane.Name, Type = GridPlaneType.General, AxisRefType = GridPlaneAxisRefType.Reference, AxisIndex = gsaAxis.Index }; if (gsaPlane.Gwa(out var gsaPlaneGwas, true)) { Initialiser.AppResources.Cache.Upsert(gsaPlaneKeyword, planeIndex, gsaPlaneGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridPlane>()); } gsaGridSurface.PlaneIndex = planeIndex; }
public static string ToNative(this Structural2DLoadPanel loadPanel) { if (string.IsNullOrEmpty(loadPanel.ApplicationId)) { return(""); } return(Helper.ToNativeTryCatch(loadPanel, () => { if (loadPanel.Loading == null || loadPanel.Loading.Value == null || loadPanel.Loading.Value.All(v => v == 0)) { Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Structural2DLoadPanel with no loading", loadPanel.ApplicationId); return ""; } var keyword = GsaRecord.GetKeyword <GsaLoadGridArea>(); var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadGridArea>(); var streamId = Initialiser.AppResources.Cache.LookupStream(loadPanel.ApplicationId); var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>(); var loadCaseIndex = Initialiser.AppResources.Cache.ResolveIndex(loadCaseKeyword, loadPanel.LoadCaseRef); var loadingDict = ExplodeLoading(loadPanel.Loading); var originalPolyline = loadPanel.Value.ToArray(); //There are two possible axes at play here: //1. one associated with the grid surface (referred by LoadPlaneRef) applied to the coordinates of the polyline //2. one associated with the loading - i.e. applied to the load //Note: only the first is supported here //When retrieving the axis (to use in transforming the polyline etc), there are two routes here: //1. referencing a load plane (grid surface) //2. not referencing a load plane, in which case a grid surface and axis needs to be created var gridSurfaceKeyword = GsaRecord.GetKeyword <GsaGridSurface>(); var gridPlaneKeyword = GsaRecord.GetKeyword <GsaGridPlane>(); var axisKeyword = GsaRecord.GetKeyword <GsaAxis>(); StructuralAxis axis = null; int gridSurfaceIndex = 0; if (string.IsNullOrEmpty(loadPanel.LoadPlaneRef)) { //If there is no load plane (corresponding to GRID_SURFACE in GSA terms) specified, then at minimum a GRID_SURFACE still needs //to be created but it doesn't need to refer to a GRID_PLANE because that load plane can just have "GLOBAL" set for its plane. //HOWEVER, the approach taken here - which could be reviewed - is to create one anyway, whose X and y axes are based on the polyline //so that an elevation value can be set in the GRID_PLANE //Create axis based on the polyline try { axis = SpeckleStructuralGSA.Helper.Parse2DAxis(originalPolyline); axis.Name = loadPanel.Name; var gsaAxis = StructuralAxisToNative.ToNativeSchema(axis); gsaAxis.StreamId = streamId; StructuralAxisToNative.ToNative(gsaAxis); var gridPlaneIndex = Initialiser.AppResources.Cache.ResolveIndex(gridPlaneKeyword); var gsaGridPlane = new GsaGridPlane() { Index = gridPlaneIndex, Name = loadPanel.Name, StreamId = streamId, AxisRefType = GridPlaneAxisRefType.Reference, AxisIndex = gsaAxis.Index, Elevation = AxisElevation(axis, originalPolyline), Type = GridPlaneType.General, StoreyToleranceAboveAuto = true, StoreyToleranceBelowAuto = true }; if (gsaGridPlane.Gwa(out var gsaGridPlaneGwas, false)) { Initialiser.AppResources.Cache.Upsert(gridPlaneKeyword, gridPlaneIndex, gsaGridPlaneGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridPlane>()); } gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex(gridSurfaceKeyword); var gsaGridSurface = new GsaGridSurface() { Index = gridSurfaceIndex, PlaneRefType = GridPlaneAxisRefType.Reference, StreamId = streamId, PlaneIndex = gridPlaneIndex, Name = loadPanel.Name, //Not setting indices should cause the code to assume "all" Type = GridSurfaceElementsType.TwoD, Span = GridSurfaceSpan.One, Angle = 0, Tolerance = 0.01, Expansion = GridExpansion.PlaneCorner }; if (gsaGridSurface.Gwa(out var gsaGridSurfaceGwas, false)) { Initialiser.AppResources.Cache.Upsert(gridSurfaceKeyword, gridSurfaceIndex, gsaGridSurfaceGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridSurface>()); } }