/// <summary>
        /// Method to convert a single of loads into dictionaries containing GsaAPI objects. Maintains the referenced dictionaries and counters.
        /// </summary>
        /// <param name="load"></param>
        /// <param name="gravityLoads"></param>
        /// <param name="nodeLoads_node"></param>
        /// <param name="nodeLoads_displ"></param>
        /// <param name="nodeLoads_settle"></param>
        /// <param name="beamLoads"></param>
        /// <param name="faceLoads"></param>
        /// <param name="gridPointLoads"></param>
        /// <param name="gridLineLoads"></param>
        /// <param name="gridAreaLoads"></param>
        /// <param name="existingAxes"></param>
        /// <param name="axisidcounter"></param>
        /// <param name="existingGridPlanes"></param>
        /// <param name="gridplaneidcounter"></param>
        /// <param name="existingGridSurfaces"></param>
        /// <param name="gridsurfaceidcounter"></param>
        /// <param name="gp_guid"></param>
        /// <param name="gs_guid"></param>
        public static void ConvertLoad(GsaLoad load,
                                       ref List <GravityLoad> gravityLoads,
                                       ref List <NodeLoad> nodeLoads_node, ref List <NodeLoad> nodeLoads_displ, ref List <NodeLoad> nodeLoads_settle,
                                       ref List <BeamLoad> beamLoads, ref List <FaceLoad> faceLoads,
                                       ref List <GridPointLoad> gridPointLoads, ref List <GridLineLoad> gridLineLoads, ref List <GridAreaLoad> gridAreaLoads,
                                       ref Dictionary <int, Axis> existingAxes, ref int axisidcounter,
                                       ref Dictionary <int, GridPlane> existingGridPlanes, ref int gridplaneidcounter,
                                       ref Dictionary <int, GridSurface> existingGridSurfaces, ref int gridsurfaceidcounter,
                                       ref Dictionary <Guid, int> gp_guid, ref Dictionary <Guid, int> gs_guid)
        {
            switch (load.LoadType)
            {
            case GsaLoad.LoadTypes.Gravity:
                gravityLoads.Add(load.GravityLoad.GravityLoad);
                break;

            case GsaLoad.LoadTypes.Node:
                if (load.NodeLoad.NodeLoadType == GsaNodeLoad.NodeLoadTypes.APPLIED_DISP)
                {
                    nodeLoads_displ.Add(load.NodeLoad.NodeLoad);
                }
                if (load.NodeLoad.NodeLoadType == GsaNodeLoad.NodeLoadTypes.NODE_LOAD)
                {
                    nodeLoads_node.Add(load.NodeLoad.NodeLoad);
                }
                if (load.NodeLoad.NodeLoadType == GsaNodeLoad.NodeLoadTypes.SETTLEMENT)
                {
                    nodeLoads_settle.Add(load.NodeLoad.NodeLoad);
                }
                break;

            case GsaLoad.LoadTypes.Beam:
                beamLoads.Add(load.BeamLoad.BeamLoad);
                break;

            case GsaLoad.LoadTypes.Face:
                faceLoads.Add(load.FaceLoad.FaceLoad);
                break;

            case GsaLoad.LoadTypes.GridPoint:
                if (load.PointLoad.GridPlaneSurface == null)     // if gridsurface id has been set
                {
                    // add the load to our list of loads to be set later
                    gridPointLoads.Add(load.PointLoad.GridPointLoad);
                    break;
                }

                // set grid point load and grid plane surface
                GsaGridPointLoad    gridptref  = load.PointLoad;
                GsaGridPlaneSurface gridplnsrf = gridptref.GridPlaneSurface;

                if (gridplnsrf.GridPlane != null)
                {
                    // - grid load references a grid surface number
                    // -- grid surface references a grid plane number
                    // --- grid plane references an Axis number
                    // toggle through the members in reverse order, set/add to model in each step

                    // ### AXIS ###
                    // set axis property in grid plane, add/set axis in model
                    gridplnsrf.GridPlane.AxisProperty = SetAxis(ref gridplnsrf, ref existingAxes, ref axisidcounter);

                    // ### GRID PLANE ###
                    // set grid plane number in grid surface, add/set grid plane in model
                    gridplnsrf.GridSurface.GridPlane = SetGridPlane(ref gridplnsrf, ref existingGridPlanes, ref gridplaneidcounter, ref gp_guid, existingAxes);

                    // ### GRID SURFACE ###
                    // set the surface number in the load, add/set the surface in the model
                    gridptref.GridPointLoad.GridSurface = SetGridSurface(ref gridplnsrf, ref existingGridSurfaces, ref gridsurfaceidcounter, ref gs_guid, existingGridPlanes, existingAxes);
                }

                // add the load to our list of loads to be set later
                gridPointLoads.Add(gridptref.GridPointLoad);
                break;

            case GsaLoad.LoadTypes.GridLine:
                if (load.LineLoad.GridPlaneSurface == null)     // if gridsurface id has been set
                {
                    // add the load to our list of loads to be set later
                    gridLineLoads.Add(load.LineLoad.GridLineLoad);
                    break;
                }

                // set grid line load and grid plane surface
                GsaGridLineLoad gridlnref = load.LineLoad;
                gridplnsrf = gridlnref.GridPlaneSurface;

                if (gridplnsrf.GridPlane != null)
                {
                    // - grid load references a grid surface number
                    // -- grid surface references a grid plane number
                    // --- grid plane references an Axis number
                    // toggle through the members in reverse order, set/add to model in each step

                    // ### AXIS ###
                    // set axis property in grid plane, add/set axis in model
                    gridplnsrf.GridPlane.AxisProperty = SetAxis(ref gridplnsrf, ref existingAxes, ref axisidcounter);

                    // ### GRID PLANE ###
                    // set grid plane number in grid surface, add/set grid plane in model
                    gridplnsrf.GridSurface.GridPlane = SetGridPlane(ref gridplnsrf, ref existingGridPlanes, ref gridplaneidcounter, ref gp_guid, existingAxes);

                    // ### GRID SURFACE ###
                    // set the surface number in the load, add/set the surface in the model
                    gridlnref.GridLineLoad.GridSurface = SetGridSurface(ref gridplnsrf, ref existingGridSurfaces, ref gridsurfaceidcounter, ref gs_guid, existingGridPlanes, existingAxes);
                }
                // add the load to our list of loads to be set later
                gridLineLoads.Add(gridlnref.GridLineLoad);
                break;

            case GsaLoad.LoadTypes.GridArea:
                if (load.AreaLoad.GridPlaneSurface == null)     // if gridsurface id has been set
                {
                    // add the load to our list of loads to be set later
                    gridAreaLoads.Add(load.AreaLoad.GridAreaLoad);
                    break;
                }

                // set grid line load and grid plane surface
                GsaGridAreaLoad gridarref = load.AreaLoad;
                gridplnsrf = gridarref.GridPlaneSurface;

                if (gridplnsrf.GridPlane != null)
                {
                    // - grid load references a grid surface number
                    // -- grid surface references a grid plane number
                    // --- grid plane references an Axis number
                    // toggle through the members in reverse order, set/add to model in each step

                    // ### AXIS ###
                    // set axis property in grid plane, add/set axis in model
                    gridplnsrf.GridPlane.AxisProperty = SetAxis(ref gridplnsrf, ref existingAxes, ref axisidcounter);

                    // ### GRID PLANE ###
                    // set grid plane number in grid surface, add/set grid plane in model
                    gridplnsrf.GridSurface.GridPlane = SetGridPlane(ref gridplnsrf, ref existingGridPlanes, ref gridplaneidcounter, ref gp_guid, existingAxes);

                    // ### GRID SURFACE ###
                    // set the surface number in the load, add/set the surface in the model
                    gridarref.GridAreaLoad.GridSurface = SetGridSurface(ref gridplnsrf, ref existingGridSurfaces, ref gridsurfaceidcounter, ref gs_guid, existingGridPlanes, existingAxes);
                }
                // add the load to our list of loads to be set later
                gridAreaLoads.Add(gridarref.GridAreaLoad);
                break;
            }
        }
示例#2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridAreaLoad gridareaload = new GsaGridAreaLoad();

            // 0 Load case
            int        lc    = 1;
            GH_Integer gh_lc = new GH_Integer();

            if (DA.GetData(0, ref gh_lc))
            {
                GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both);
            }
            gridareaload.GridAreaLoad.Case = lc;

            // Do plane input first as to see if we need to project polyline onto grid plane
            // 2 Plane
            Plane pln      = Plane.WorldXY;
            bool  planeSet = false;
            GsaGridPlaneSurface grdplnsrf = new GsaGridPlaneSurface();
            GH_ObjectWrapper    gh_typ    = new GH_ObjectWrapper();

            if (DA.GetData(2, ref gh_typ))
            {
                if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                {
                    GsaGridPlaneSurface temppln = new GsaGridPlaneSurface();
                    gh_typ.CastTo(ref temppln);
                    grdplnsrf = temppln.Duplicate();
                    pln       = grdplnsrf.Plane;
                    planeSet  = true;
                }
                else if (gh_typ.Value is Plane)
                {
                    gh_typ.CastTo(ref pln);
                    grdplnsrf = new GsaGridPlaneSurface(pln);
                    planeSet  = true;
                }
                else
                {
                    int id = 0;
                    if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                    {
                        gridareaload.GridAreaLoad.GridSurface = id;
                        gridareaload.GridPlaneSurface         = null;
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in GPS input. Accepted inputs are Grid Plane Surface or Plane. " +
                                          System.Environment.NewLine + "If no input here then the brep's best-fit plane will be used");
                        return;
                    }
                }
            }

            // we wait setting the gridplanesurface until we have run the polyline input

            // 1 Polyline
            Brep brep = new Brep();


            GH_Brep gh_brep = new GH_Brep();

            if (DA.GetData(1, ref gh_brep))
            {
                GH_Convert.ToBrep(gh_brep, ref brep, GH_Conversion.Both);

                // get edge curves
                Curve[] edgeSegments = brep.DuplicateEdgeCurves();
                Curve[] edges        = Curve.JoinCurves(edgeSegments);
                Curve   crv          = edges[0];

                //convert to polyline
                Polyline ln = new Polyline();
                if (crv.TryGetPolyline(out ln))
                {
                    // get control points
                    List <Point3d> ctrl_pts = ln.ToList();

                    // plane
                    if (!planeSet)
                    {
                        // create nice plane from pts
                        pln = Util.GH.Convert.CreateBestFitUnitisedPlaneFromPts(ctrl_pts);

                        // create grid plane surface from best fit plane
                        grdplnsrf = new GsaGridPlaneSurface(pln, true);
                    }

                    // project original curve onto grid plane
                    crv = Curve.ProjectToPlane(crv, pln);

                    // convert to polyline again
                    crv.TryGetPolyline(out ln);

                    //get control points again
                    ctrl_pts = ln.ToList();

                    // string to write polyline description to
                    string desc = "";

                    // loop through all points
                    for (int i = 0; i < ctrl_pts.Count - 1; i++)
                    {
                        if (i > 0)
                        {
                            desc += " ";
                        }

                        // get control points in local plane coordinates
                        Point3d temppt = new Point3d();
                        pln.RemapToPlaneSpace(ctrl_pts[i], out temppt);

                        // write point to string
                        // format accepted by GSA: (0,0) (0,1) (1,2) (3,4) (4,0)(m)
                        desc += "(" + temppt.X + "," + temppt.Y + ")";
                    }
                    // add units to the end
                    desc += "(" + Units.LengthLarge + ")";

                    // set polyline in grid line load
                    gridareaload.GridAreaLoad.Type = GridAreaPolyLineType.POLYGON;
                    gridareaload.GridAreaLoad.PolyLineDefinition = desc;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Brep edge to Polyline");
                }
            }

            // now we can set the gridplanesurface:
            if (gridareaload.GridPlaneSurface != null)
            {
                if (gridareaload.GridPlaneSurface.GridSurfaceID == 0)
                {
                    gridareaload.GridPlaneSurface = grdplnsrf;
                }
            }

            // 3 direction
            string    dir   = "Z";
            Direction direc = Direction.Z;

            GH_String gh_dir = new GH_String();

            if (DA.GetData(3, ref gh_dir))
            {
                GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both);
            }
            dir = dir.ToUpper();
            if (dir == "X")
            {
                direc = Direction.X;
            }
            if (dir == "Y")
            {
                direc = Direction.Y;
            }

            gridareaload.GridAreaLoad.Direction = direc;

            // 4 Axis
            int axis = 0;

            gridareaload.GridAreaLoad.AxisProperty = 0;
            GH_Integer gh_ax = new GH_Integer();

            if (DA.GetData(4, ref gh_ax))
            {
                GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both);
                if (axis == 0 || axis == -1)
                {
                    gridareaload.GridAreaLoad.AxisProperty = axis;
                }
            }

            // 5 Projected
            bool       proj    = false;
            GH_Boolean gh_proj = new GH_Boolean();

            if (DA.GetData(5, ref gh_proj))
            {
                if (GH_Convert.ToBoolean(gh_proj, out proj, GH_Conversion.Both))
                {
                    gridareaload.GridAreaLoad.IsProjected = proj;
                }
            }

            // 6 Name
            string    name    = "";
            GH_String gh_name = new GH_String();

            if (DA.GetData(6, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    gridareaload.GridAreaLoad.Name = name;
                }
            }

            // 7 load value
            double load1 = 0;

            if (DA.GetData(7, ref load1))
            {
                load1 *= -1000; //convert to kN
            }
            gridareaload.GridAreaLoad.Value = load1;

            // convert to goo
            GsaLoad gsaLoad = new GsaLoad(gridareaload);

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }