Ejemplo n.º 1
0
 public static string ToNative(this Structural2DLoadPanel load)
 {
     return(new GSAGridAreaLoad()
     {
         Value = load
     }.SetGWACommand());
 }
Ejemplo n.º 2
0
        public void ParseGWACommand()
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural2DLoadPanel();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            obj.Name          = pieces[counter++].Trim(new char[] { '"' });
            obj.ApplicationId = Helper.GetApplicationId(this.GetGSAKeyword(), this.GSAId);

            Helper.GetGridPlaneRef(Convert.ToInt32(pieces[counter++]), out int gridPlaneRefRet, out string gridSurfaceRec);
            Helper.GetGridPlaneData(gridPlaneRefRet, out int gridPlaneAxis, out double gridPlaneElevation, out string gridPlaneRec);

            this.SubGWACommand.Add(gridSurfaceRec);
            this.SubGWACommand.Add(gridPlaneRec);

            string gwaRec = null;
            var    axis   = Helper.Parse0DAxis(gridPlaneAxis, Initialiser.Interface, out gwaRec);

            if (gwaRec != null)
            {
                this.SubGWACommand.Add(gwaRec);
            }
            double elevation = gridPlaneElevation;

            var polylineDescription = "";

            switch (pieces[counter++])
            {
            case "PLANE":
                // TODO: Do not handle for now
                return;

            case "POLYREF":
                var    polylineRef = pieces[counter++];
                string newRec      = null;
                Helper.GetPolylineDesc(Convert.ToInt32(polylineRef), out polylineDescription, out newRec);
                this.SubGWACommand.Add(newRec);
                break;

            case "POLYGON":
                polylineDescription = pieces[counter++];
                break;
            }
            var polyVals = Helper.ParsePolylineDesc(polylineDescription);

            for (var i = 2; i < polyVals.Length; i += 3)
            {
                polyVals[i] = elevation;
            }

            obj.Value  = Helper.MapPointsLocal2Global(polyVals, axis).ToList();
            obj.Closed = true;

            var loadCaseIndex = Convert.ToInt32(pieces[counter++]);

            if (loadCaseIndex > 0)
            {
                obj.LoadCaseRef = Helper.GetApplicationId(typeof(GSALoadCase).GetGSAKeyword(), loadCaseIndex);
            }

            var            loadAxisId   = 0;
            var            loadAxisData = pieces[counter++];
            StructuralAxis loadAxis;

            if (loadAxisData == "LOCAL")
            {
                loadAxis = axis;
            }
            else
            {
                loadAxisId = loadAxisData == "GLOBAL" ? 0 : Convert.ToInt32(loadAxisData);
                loadAxis   = Helper.Parse0DAxis(loadAxisId, Initialiser.Interface, out gwaRec);
                if (gwaRec != null)
                {
                    this.SubGWACommand.Add(gwaRec);
                }
            }
            var projected = pieces[counter++] == "YES";
            var direction = pieces[counter++];
            var value     = Convert.ToDouble(pieces[counter++]);

            obj.Loading = new StructuralVectorThree(new double[3]);
            switch (direction.ToUpper())
            {
            case "X":
                obj.Loading.Value[0] = value;
                break;

            case "Y":
                obj.Loading.Value[1] = value;
                break;

            case "Z":
                obj.Loading.Value[2] = value;
                break;

            default:
                // TODO: Error case maybe?
                break;
            }
            obj.Loading.TransformOntoAxis(loadAxis);

            if (projected)
            {
                var scale = (obj.Loading.Value[0] * axis.Normal.Value[0] +
                             obj.Loading.Value[1] * axis.Normal.Value[1] +
                             obj.Loading.Value[2] * axis.Normal.Value[2]) /
                            (axis.Normal.Value[0] * axis.Normal.Value[0] +
                             axis.Normal.Value[1] * axis.Normal.Value[1] +
                             axis.Normal.Value[2] * axis.Normal.Value[2]);

                obj.Loading = new StructuralVectorThree(axis.Normal.Value[0], axis.Normal.Value[1], axis.Normal.Value[2]);
                obj.Loading.Scale(scale);
            }

            this.Value = obj;
        }
Ejemplo n.º 3
0
        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("");
        }
Ejemplo n.º 4
0
        public static List <SpeckleObject> ToSpeckle(this AreaLoad myAreaLoad)
        {
            var polylines = new List <double[]>();

            var loops = myAreaLoad.GetLoops();

            foreach (var loop in loops)
            {
                var coor = new List <double>();
                foreach (var curve in loop)
                {
                    var points = curve.Tessellate();

                    foreach (var p in points.Skip(1))
                    {
                        coor.Add(p.X / Scale);
                        coor.Add(p.Y / Scale);
                        coor.Add(p.Z / Scale);
                    }
                }

                polylines.Add(coor.ToArray());

                // Only get outer loop
                break;
            }

            var forces = new StructuralVectorThree(new double[3]);

            forces.Value[0] = myAreaLoad.ForceVector1.X;
            forces.Value[1] = myAreaLoad.ForceVector1.Y;
            forces.Value[2] = myAreaLoad.ForceVector1.Z;

            if (myAreaLoad.OrientTo == LoadOrientTo.HostLocalCoordinateSystem)
            {
                var hostTransform = myAreaLoad.HostElement.GetLocalCoordinateSystem();

                var b0 = hostTransform.get_Basis(0);
                var b1 = hostTransform.get_Basis(1);
                var b2 = hostTransform.get_Basis(2);

                var fx = forces.Value[0] * b0.X + forces.Value[1] * b1.X + forces.Value[2] * b2.X;
                var fy = forces.Value[0] * b0.Y + forces.Value[1] * b1.Y + forces.Value[2] * b2.Y;
                var fz = forces.Value[0] * b0.Z + forces.Value[1] * b1.Z + forces.Value[2] * b2.Z;

                forces = new StructuralVectorThree(new double[] { fx, fy, fz });
            }
            else if (myAreaLoad.OrientTo == LoadOrientTo.WorkPlane)
            {
                var workPlane = ((SketchPlane)Doc.GetElement(myAreaLoad.WorkPlaneId)).GetPlane();

                var b0 = workPlane.XVec;
                var b1 = workPlane.YVec;
                var b2 = workPlane.Normal;

                var fx = forces.Value[0] * b0.X + forces.Value[1] * b1.X + forces.Value[2] * b2.X;
                var fy = forces.Value[0] * b0.Y + forces.Value[1] * b1.Y + forces.Value[2] * b2.Y;
                var fz = forces.Value[0] * b0.Z + forces.Value[1] * b1.Z + forces.Value[2] * b2.Z;

                forces = new StructuralVectorThree(new double[] { fx, fy, fz });
            }

            var myLoadCase = new StructuralLoadCase();

            myLoadCase.Name          = myAreaLoad.LoadCaseName;
            myLoadCase.ApplicationId = myAreaLoad.LoadCase.UniqueId;
            switch (myAreaLoad.LoadCategoryName)
            {
            case "Dead Loads":
                myLoadCase.CaseType = StructuralLoadCaseType.Dead;
                break;

            case "Live Loads":
                myLoadCase.CaseType = StructuralLoadCaseType.Live;
                break;

            case "Seismic Loads":
                myLoadCase.CaseType = StructuralLoadCaseType.Earthquake;
                break;

            case "Snow Loads":
                myLoadCase.CaseType = StructuralLoadCaseType.Snow;
                break;

            case "Wind Loads":
                myLoadCase.CaseType = StructuralLoadCaseType.Wind;
                break;

            default:
                myLoadCase.CaseType = StructuralLoadCaseType.Generic;
                break;
            }

            var myLoads = new List <SpeckleObject>();

            var counter = 0;

            foreach (var vals in polylines)
            {
                var myLoad = new Structural2DLoadPanel();
                myLoad.Name        = myAreaLoad.Name;
                myLoad.Value       = vals.ToList();
                myLoad.Loading     = forces;
                myLoad.LoadCaseRef = myLoadCase.ApplicationId;
                myLoad.Closed      = true;

                myLoad.ApplicationId = myAreaLoad.UniqueId + "_" + (counter++).ToString();

                myLoads.Add(myLoad);
            }

            return(myLoads.Concat(new List <SpeckleObject>()
            {
                myLoadCase
            }).ToList());
        }
Ejemplo n.º 5
0
 //TODO
 public static Element ToNative(this Structural2DLoadPanel myLoad)
 {
     return(null);
 }
        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>());
                        }
                    }