예제 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridPlaneSurface gps = new GsaGridPlaneSurface();

            if (DA.GetData(0, ref gps))
            {
                if (gps == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Null GridPlaneSurface");
                    return;
                }

                DA.SetData(0, gps == null? Plane.Unset : gps.Plane);
                DA.SetData(1, gps.GridPlane == null ? 0 : gps.GridPlaneID);
                DA.SetData(2, gps.GridPlane == null ? null : gps.GridPlane.Name);
                DA.SetData(3, gps.GridPlane == null ? false : gps.GridPlane.IsStoreyType);
                Plane axis = new Plane();
                if (gps.GridPlane != null)
                {
                    axis = new Plane(new Point3d(gps.Axis.Origin.X, gps.Axis.Origin.Y, gps.Axis.Origin.Z),
                                     new Vector3d(gps.Axis.XVector.X, gps.Axis.XVector.Y, gps.Axis.XVector.Z),
                                     new Vector3d(gps.Axis.XYPlane.X, gps.Axis.XYPlane.Y, gps.Axis.XYPlane.Z)
                                     );
                }
                DA.SetData(4, gps.GridPlane == null ? Plane.Unset : axis);
                DA.SetData(5, gps.AxisID);
                DA.SetData(6, gps.GridPlane == null ? 0 : gps.GridPlane.Elevation);
                DA.SetData(7, gps.GridPlane == null ? 0 : gps.GridPlane.ToleranceAbove);
                DA.SetData(8, gps.GridPlane == null ? 0 : gps.GridPlane.ToleranceBelow);

                DA.SetData(9, gps.GridSurfaceID);
                DA.SetData(10, gps.GridSurface.Name);
                DA.SetData(11, gps.GridSurface.Elements);
                string elemtype = gps.GridSurface.ElementType.ToString();
                DA.SetData(12, Char.ToUpper(elemtype[0]) + elemtype.Substring(1).ToLower().Replace("_", " "));
                DA.SetData(13, gps.GridSurface.Tolerance);
                string spantype = gps.GridSurface.SpanType.ToString();
                DA.SetData(14, Char.ToUpper(spantype[0]) + spantype.Substring(1).ToLower().Replace("_", " "));
                DA.SetData(15, gps.GridSurface.Direction);
                string expantype = gps.GridSurface.ExpansionType.ToString();
                DA.SetData(16, Char.ToUpper(expantype[0]) + expantype.Substring(1).ToLower().Replace("_", " "));
                bool simple = false;
                if (gps.GridSurface.SpanType == GridSurface.Span_Type.TWO_WAY_SIMPLIFIED_TRIBUTARY_AREAS)
                {
                    simple = true;
                }
                DA.SetData(17, simple);
            }
        }
        /// <summary>
        /// Method to convert a list of GridPlaneSurfaces and set Axes, GridPlanes and GridSurfaces in ref Dictionaries
        /// </summary>
        /// <param name="gridPlaneSurfaces"></param>
        /// <param name="existingAxes"></param>
        /// <param name="existingGridPlanes"></param>
        /// <param name="existingGridSurfaces"></param>
        /// <param name="gp_guid"></param>
        /// <param name="gs_guid"></param>
        /// <param name="workerInstance"></param>
        /// <param name="ReportProgress"></param>
        public static void ConvertGridPlaneSurface(List <GsaGridPlaneSurface> gridPlaneSurfaces,
                                                   ref Dictionary <int, Axis> existingAxes, ref Dictionary <int, GridPlane> existingGridPlanes,
                                                   ref Dictionary <int, GridSurface> existingGridSurfaces,
                                                   ref Dictionary <Guid, int> gp_guid, ref Dictionary <Guid, int> gs_guid,
                                                   GrasshopperAsyncComponent.WorkerInstance workerInstance = null,
                                                   Action <string, double> ReportProgress = null)
        {
            if (gridPlaneSurfaces != null)
            {
                if (workerInstance != null)
                {
                    ReportProgress("Initiating GridPlaneSurfaces assembly", -2);
                }

                // create a counter for creating new axes, gridplanes and gridsurfaces
                int axisidcounter        = (existingAxes.Count > 0) ? existingAxes.Keys.Max() + 1 : 1;
                int gridplaneidcounter   = (existingGridPlanes.Count > 0) ? existingGridPlanes.Keys.Max() + 1 : 1;
                int gridsurfaceidcounter = (existingGridSurfaces.Count > 0) ? existingGridSurfaces.Keys.Max() + 1 : 1;

                // get the highest gridplaneID+1 and gridsurfaceID+1
                GetGridPlaneSurfaceCounters(gridPlaneSurfaces, ref gridplaneidcounter, ref gridsurfaceidcounter);

                for (int i = 0; i < gridPlaneSurfaces.Count; i++)
                {
                    if (gridPlaneSurfaces[i] != null)
                    {
                        GsaGridPlaneSurface gps = gridPlaneSurfaces[i];

                        if (gps.GridPlane != null)
                        {
                            // add / set Axis and set the id in the grid plane
                            gps.GridPlane.AxisProperty = SetAxis(ref gps, ref existingAxes, ref axisidcounter);

                            // add / set Grid Plane and set the id in the grid surface
                            gps.GridSurface.GridPlane = SetGridPlane(ref gps, ref existingGridPlanes, ref gridplaneidcounter, ref gp_guid, existingAxes);
                        }
                        // add / set Grid Surface
                        SetGridSurface(ref gps, ref existingGridSurfaces, ref gridsurfaceidcounter, ref gs_guid, existingGridPlanes, existingAxes);
                    }
                }
            }
            if (workerInstance != null)
            {
                ReportProgress("GridPlaneSurfaces assembled", -2);
            }
        }
        /// <summary>
        /// Method to set a single axis in ref dictionary, looking up existing axes to reference. Returns axis ID set in dictionary or existing axis ID if similar already exist.
        /// </summary>
        /// <param name="gridplanesurface"></param>
        /// <param name="existingAxes"></param>
        /// <param name="axisidcounter"></param>
        /// <returns></returns>
        public static int SetAxis(ref GsaGridPlaneSurface gridplanesurface,
                                  ref Dictionary <int, Axis> existingAxes, ref int axisidcounter)
        {
            int  axis_id = gridplanesurface.AxisID;
            Axis axis    = gridplanesurface.Axis;

            if (axis.Name == "")
            {
                axis.Name = "Axis " + axisidcounter;
            }

            // see if AXIS has been set
            if (gridplanesurface.AxisID > 0)
            {
                // assign the axis property to the grid plane (in the load)
                gridplanesurface.GridPlane.AxisProperty = axis_id;
                // set the axis in existing dictionary
                if (existingAxes.ContainsKey(axis_id))
                {
                    existingAxes[axis_id] = axis;
                }
                else
                {
                    existingAxes.Add(axis_id, axis);
                }
            }
            else
            {
                // check if there's already an axis with same properties in the model:
                axis_id = Axes.GetExistingAxisID(existingAxes, axis);
                if (axis_id > 0)
                {
                    gridplanesurface.GridPlane.AxisProperty = axis_id; // set the id if axis exist
                }
                else
                {
                    // else add the axis to the model and assign the new axis number to the grid plane
                    axis_id = axisidcounter;
                    gridplanesurface.GridPlane.AxisProperty = axisidcounter;

                    existingAxes.Add(gridplanesurface.GridPlane.AxisProperty, axis);
                    axisidcounter++;
                }
            }
            return(axis_id);
        }
        /// <summary>
        /// Method to loop through a list of GridPlaneSurfaces and return the highest set ID + 1 for gridplan and gridsurface
        /// </summary>
        /// <param name="gridPlaneSurfaces"></param>
        /// <param name="gridplaneidcounter"></param>
        /// <param name="gridsurfaceidcounter"></param>
        public static void GetGridPlaneSurfaceCounters(List <GsaGridPlaneSurface> gridPlaneSurfaces, ref int gridplaneidcounter, ref int gridsurfaceidcounter)
        {
            for (int i = 0; i < gridPlaneSurfaces.Count; i++)
            {
                if (gridPlaneSurfaces[i] != null)
                {
                    GsaGridPlaneSurface gps = gridPlaneSurfaces[i];

                    if (gps.GridPlaneID > 0)
                    {
                        gridplaneidcounter = Math.Max(gridplaneidcounter, gps.GridPlaneID + 1);
                    }
                    if (gps.GridSurfaceID > 0)
                    {
                        gridsurfaceidcounter = Math.Max(gridsurfaceidcounter, gps.GridSurfaceID + 1);
                    }
                }
            }
        }
예제 #5
0
        public override bool CastTo <Q>(ref Q target)
        {
            // This function is called when Grasshopper needs to convert this
            // instance of GsaLoad into some other type Q.


            if (typeof(Q).IsAssignableFrom(typeof(GsaLoad)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    target = (Q)(object)Value.Duplicate();
                }
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GsaGridPlaneSurfaceGoo)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.AreaLoad != null)
                    {
                        GsaGridPlaneSurface    gridplane = Value.AreaLoad.GridPlaneSurface;
                        GsaGridPlaneSurfaceGoo gpgoo     = new GsaGridPlaneSurfaceGoo(gridplane);
                        target = (Q)(object)gpgoo;
                        return(true);
                    }
                    if (Value.LineLoad != null)
                    {
                        GsaGridPlaneSurface    gridplane = Value.LineLoad.GridPlaneSurface;
                        GsaGridPlaneSurfaceGoo gpgoo     = new GsaGridPlaneSurfaceGoo(gridplane);
                        target = (Q)(object)gpgoo;
                        return(true);
                    }
                    if (Value.PointLoad != null)
                    {
                        GsaGridPlaneSurface    gridplane = Value.PointLoad.GridPlaneSurface;
                        GsaGridPlaneSurfaceGoo gpgoo     = new GsaGridPlaneSurfaceGoo(gridplane);
                        target = (Q)(object)gpgoo;
                        return(true);
                    }
                }
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Plane)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.LoadType == GsaLoad.LoadTypes.GridArea)
                    {
                        GH_Plane ghpln = new GH_Plane();
                        GH_Convert.ToGHPlane(Value.AreaLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln);
                        target = (Q)(object)ghpln;
                        return(true);
                    }
                    if (Value.LoadType == GsaLoad.LoadTypes.GridLine)
                    {
                        GH_Plane ghpln = new GH_Plane();
                        GH_Convert.ToGHPlane(Value.LineLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln);
                        target = (Q)(object)ghpln;
                        return(true);
                    }
                    if (Value.LoadType == GsaLoad.LoadTypes.GridPoint)
                    {
                        GH_Plane ghpln = new GH_Plane();
                        GH_Convert.ToGHPlane(Value.PointLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln);
                        target = (Q)(object)ghpln;
                        return(true);
                    }
                }
                return(false);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Point)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.LoadType == GsaLoad.LoadTypes.GridPoint)
                    {
                        Point3d point = new Point3d
                        {
                            X = Value.PointLoad.GridPointLoad.X,
                            Y = Value.PointLoad.GridPointLoad.Y,
                            Z = Value.PointLoad.GridPlaneSurface.Plane.OriginZ
                        };
                        GH_Point ghpt = new GH_Point();
                        GH_Convert.ToGHPoint(point, GH_Conversion.Both, ref ghpt);
                        target = (Q)(object)ghpt;
                        return(true);
                    }
                }
                return(false);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.LoadType == GsaLoad.LoadTypes.GridLine)
                    {
                        List <Point3d> pts = new List <Point3d>();
                        string         def = Value.LineLoad.GridLineLoad.PolyLineDefinition; //implement converter
                        // to be done
                        //target = (Q)(object)ghpt;
                        //return true;
                    }
                }
                return(false);
            }

            target = default;
            return(false);
        }
예제 #6
0
        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
        }
예제 #7
0
            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;
                }
            }
        /// <summary>
        /// Method to set a single gridsurface in ref dictionary, looking up existing axes and gridplanes to reference. Returns the GridSurface ID set in dictionary or existing ID if similar already exist. Maintains the gridplane and axis dictionary
        /// </summary>
        /// <param name="gridplanesurface"></param>
        /// <param name="existingGridSurfaces"></param>
        /// <param name="gridsurfaceidcounter"></param>
        /// <param name="gs_guid"></param>
        /// <param name="existingGridPlanes"></param>
        /// <param name="existingAxes"></param>
        /// <returns></returns>
        public static int SetGridSurface(ref GsaGridPlaneSurface gridplanesurface,
                                         ref Dictionary <int, GridSurface> existingGridSurfaces, ref int gridsurfaceidcounter, ref Dictionary <Guid, int> gs_guid,
                                         Dictionary <int, GridPlane> existingGridPlanes, Dictionary <int, Axis> existingAxes)
        {
            if (existingGridSurfaces.Count > 0)
            {
                gridsurfaceidcounter = Math.Max(existingGridSurfaces.Keys.Max() + 1, gridsurfaceidcounter);
            }

            int gs_ID = gridplanesurface.GridSurfaceID;

            if (gridplanesurface.GridSurface.Name == "")
            {
                gridplanesurface.GridSurface.Name = "Grid surface " + gridsurfaceidcounter;
            }

            // see if grid surface ID has been set by user
            if (gridplanesurface.GridSurfaceID > 0)
            {
                // set the grid surface in model
                existingGridSurfaces[gs_ID] = gridplanesurface.GridSurface;
            }
            else
            {
                // check first if guid is 0000-0000 indicating that we want to try use existing axis
                if (gridplanesurface.GridSurfaceGUID == new Guid())
                {
                    // check if there's already an axis with same properties in the model:
                    int axis_id = Axes.GetExistingAxisID(existingAxes, gridplanesurface.Axis);

                    if (axis_id > 0)
                    {
                        // if axis is found, the loop through existing gridplanes to find the first that is using this axis
                        foreach (int keyPln in existingGridPlanes.Keys)
                        {
                            if (existingGridPlanes[keyPln].AxisProperty == axis_id)
                            {
                                // if grid plane is found loop through existing grid surfaces to
                                // find the first that is referencing this grid plane
                                foreach (int keySrf in existingGridSurfaces.Keys)
                                {
                                    if (existingGridSurfaces[keySrf].GridPlane == keyPln)
                                    {
                                        if (existingGridSurfaces[keySrf].Direction == gridplanesurface.GridSurface.Direction &
                                            existingGridSurfaces[keySrf].Elements == gridplanesurface.GridSurface.Elements &
                                            existingGridSurfaces[keySrf].ElementType == gridplanesurface.GridSurface.ElementType &
                                            existingGridSurfaces[keySrf].ExpansionType == gridplanesurface.GridSurface.ExpansionType &
                                            existingGridSurfaces[keySrf].SpanType == gridplanesurface.GridSurface.SpanType &
                                            existingGridSurfaces[keySrf].Tolerance == gridplanesurface.GridSurface.Tolerance)
                                        {
                                            return(keySrf);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (gs_guid.ContainsKey(gridplanesurface.GridSurfaceGUID)) // check if grid surface has already been added to model by other loads
                {
                    gs_guid.TryGetValue(gridplanesurface.GridSurfaceGUID, out int gsID);
                    // if guid exist in our dictionary it has been added to the model
                    // and we just assign the value to the load
                    //gs_ID = gsID;
                    return(gsID);
                }

                // if it does not exist we add the grid surface to the model
                existingGridSurfaces.Add(gridsurfaceidcounter, gridplanesurface.GridSurface);
                gs_ID = gridsurfaceidcounter;
                // and add it to the our list of grid surfaces
                if (gridplanesurface.GridSurfaceGUID != new Guid())
                {
                    gs_guid.Add(gridplanesurface.GridSurfaceGUID, gs_ID);
                }
                gridsurfaceidcounter++;
            }
            return(gs_ID);
        }
        /// <summary>
        /// Method to set a single gridplane in ref dictionary, looking up existing axes to reference. Returns the GridPlane ID set in dictionary or existing ID if similar already exist. Maintains the axis dictionary
        /// </summary>
        /// <param name="gridplanesurface"></param>
        /// <param name="existingGridPlanes"></param>
        /// <param name="gridplaneidcounter"></param>
        /// <param name="gp_guid"></param>
        /// <param name="existingAxes"></param>
        /// <returns></returns>
        public static int SetGridPlane(ref GsaGridPlaneSurface gridplanesurface,
                                       ref Dictionary <int, GridPlane> existingGridPlanes, ref int gridplaneidcounter, ref Dictionary <Guid, int> gp_guid, Dictionary <int, Axis> existingAxes)
        {
            if (existingGridPlanes.Count > 0)
            {
                gridplaneidcounter = Math.Max(existingGridPlanes.Keys.Max() + 1, gridplaneidcounter);
            }

            if (gridplanesurface.GridPlane.Name == "")
            {
                gridplanesurface.GridPlane.Name = "Grid plane " + gridplaneidcounter;
            }

            int gp_ID = gridplanesurface.GridPlaneID;

            // see if grid plane ID has been set by user
            if (gridplanesurface.GridPlaneID > 0)
            {
                // assign the grid plane number set by user in the load's grid surface
                gp_ID = gridplanesurface.GridPlaneID;
                // set grid plane in model
                existingGridPlanes[gp_ID] = gridplanesurface.GridPlane;
            }
            else
            {
                // check first if guid is 0000-0000 indicating that we want to try use existing axis
                if (gridplanesurface.GridPlaneGUID == new Guid())
                {
                    // check if there's already an axis with same properties in the model:
                    int axis_id = Axes.GetExistingAxisID(existingAxes, gridplanesurface.Axis);

                    if (axis_id > 0)
                    {
                        // if axis is found, the loop through existing gridplanes to find the first that is using this axis
                        foreach (int key in existingGridPlanes.Keys)
                        {
                            if (existingGridPlanes[key].AxisProperty == axis_id)
                            {
                                if (existingGridPlanes[key].Elevation == gridplanesurface.GridPlane.Elevation &
                                    existingGridPlanes[key].ToleranceAbove == gridplanesurface.GridPlane.ToleranceAbove &
                                    existingGridPlanes[key].ToleranceBelow == gridplanesurface.GridPlane.ToleranceBelow)
                                {
                                    return(key);
                                }
                            }
                        }
                    }
                }
                else if (gp_guid.ContainsKey(gridplanesurface.GridPlaneGUID)) // check if grid plane has already been added to model by other loads
                {
                    gp_guid.TryGetValue(gridplanesurface.GridPlaneGUID, out int gpID);
                    // if guid exist in our dictionary it has been added to the model
                    // and we just assign the value to the grid surface
                    return(gpID);
                }

                // if it does not exist we add the grid plane to the model
                existingGridPlanes.Add(gridplaneidcounter, gridplanesurface.GridPlane);
                // then set the id to grid surface
                gp_ID = gridplaneidcounter;
                // and add it to the our list of grid planes
                if (gridplanesurface.GridPlaneGUID != new Guid())
                {
                    gp_guid.Add(gridplanesurface.GridPlaneGUID, gridplaneidcounter);
                }
                gridplaneidcounter++;
            }
            return(gp_ID);
        }
예제 #10
0
        /// <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;
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridLineLoad gridlineload = new GsaGridLineLoad();

            // 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);
            }
            gridlineload.GridLineLoad.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))
                    {
                        gridlineload.GridLineLoad.GridSurface = id;
                        gridlineload.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 line's best-fit plane will be used");
                        return;
                    }
                }
            }

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

            // 1 Polyline
            Polyline ln     = new Polyline();
            GH_Curve gh_crv = new GH_Curve();

            if (DA.GetData(1, ref gh_crv))
            {
                Curve crv = null;
                GH_Convert.ToCurve(gh_crv, ref crv, GH_Conversion.Both);

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

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

                        // create grid plane surface from best fit plane
                        grdplnsrf = new GsaGridPlaneSurface(pln, true);
                    }
                    else
                    {
                        // 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; 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
                    gridlineload.GridLineLoad.Type = GridLineLoad.PolyLineType.EXPLICIT_POLYLINE;
                    gridlineload.GridLineLoad.PolyLineDefinition = desc;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Curve to Polyline");
                }
            }

            // now we can set the gridplanesurface:
            if (gridlineload.GridPlaneSurface != null)
            {
                if (gridlineload.GridPlaneSurface.GridSurfaceID == 0)
                {
                    gridlineload.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;
            }

            gridlineload.GridLineLoad.Direction = direc;

            // 4 Axis
            int axis = 0;

            gridlineload.GridLineLoad.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)
                {
                    gridlineload.GridLineLoad.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))
                {
                    gridlineload.GridLineLoad.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))
                {
                    gridlineload.GridLineLoad.Name = name;
                }
            }

            // 7 load value
            double load1 = 0;

            if (DA.GetData(7, ref load1))
            {
                load1 *= -1000; //convert to kN
            }
            gridlineload.GridLineLoad.ValueAtStart = load1;

            // 8 load value
            double load2 = load1;

            if (DA.GetData(8, ref load2))
            {
                load2 *= -1000; //convert to kN
            }
            gridlineload.GridLineLoad.ValueAtEnd = load2;

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

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0 Plane
            Plane pln = Plane.Unset;
            GsaGridPlaneSurface gps;
            bool idSet = false;

            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                {
                    GsaGridPlaneSurface temppln = new GsaGridPlaneSurface();
                    gh_typ.CastTo(ref temppln);
                    gps = temppln.Duplicate();
                }
                else
                {
                    if (gh_typ.CastTo(ref pln))
                    {
                        gps = new GsaGridPlaneSurface(pln);
                    }
                    else
                    {
                        int id = 0;
                        if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                        {
                            gps = new GsaGridPlaneSurface();
                            gps.GridSurface.GridPlane = id;
                            gps.GridPlane             = null;
                            idSet = true;
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Cannot convert your input to GridPlaneSurface or Plane");
                            return;
                        }
                    }
                }
            }
            else
            {
                pln = Plane.WorldXY;
                gps = new GsaGridPlaneSurface(pln);
            }

            // record if changes has been made from default type
            bool        changeGS = false;
            GridSurface gs       = new GridSurface(); // new GridSurface to make changes to, set it back to GPS in the end

            if (idSet)
            {
                gs.GridPlane = gps.GridSurface.GridPlane;
            }

            // 1 ID
            GH_Integer ghint = new GH_Integer();

            if (DA.GetData(1, ref ghint))
            {
                int id = 0;
                GH_Convert.ToInt32(ghint, out id, GH_Conversion.Both);
                gps.GridSurfaceID = id;
            }

            // 2 Elements
            GH_String ghelem = new GH_String();

            if (DA.GetData(2, ref ghelem))
            {
                string elem = "";
                if (GH_Convert.ToString(ghelem, out elem, GH_Conversion.Both))
                {
                    gs.Elements = elem;
                    changeGS    = true;
                }
            }

            // 3 Name
            GH_String ghtxt = new GH_String();

            if (DA.GetData(3, ref ghtxt))
            {
                string name = "";
                if (GH_Convert.ToString(ghtxt, out name, GH_Conversion.Both))
                {
                    gs.Name  = name;
                    changeGS = true;
                }
            }

            // 4 Tolerance
            GH_Number ghtol = new GH_Number();

            if (DA.GetData(4, ref ghtol))
            {
                double tol = 10;
                if (GH_Convert.ToDouble(ghtol, out tol, GH_Conversion.Both))
                {
                    gs.Tolerance = tol;
                    changeGS     = true;
                }
            }

            switch (_mode)
            {
            case FoldMode.One_Dimensional_One_Way:
                gs.ElementType = GridSurface.Element_Type.ONE_DIMENSIONAL;
                gs.SpanType    = GridSurface.Span_Type.ONE_WAY;

                // 5 span direction
                GH_Number ghdir = new GH_Number();
                if (DA.GetData(5, ref ghdir))
                {
                    double dir = 0;
                    if (GH_Convert.ToDouble(ghdir, out dir, GH_Conversion.Both))
                    {
                        if (dir > 180 || dir < -180)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Angle value must be between -180 and 180 degrees");     // to be updated when GsaAPI support units
                        }
                        gs.Direction = dir;
                        if (dir != 0)
                        {
                            changeGS = true;
                        }
                    }
                }
                break;

            case FoldMode.One_Dimensional_Two_Way:
                changeGS       = true;
                gs.ElementType = GridSurface.Element_Type.ONE_DIMENSIONAL;

                // 5 expansion method
                int        exp   = 0;
                GH_Integer ghexp = new GH_Integer();
                if (DA.GetData(5, ref ghexp))
                {
                    GH_Convert.ToInt32_Primary(ghexp, ref exp);
                }
                gs.ExpansionType = GridSurfaceExpansionType.PLANE_CORNER;
                if (exp == 1)
                {
                    gs.ExpansionType = GridSurfaceExpansionType.PLANE_SMOOTH;
                }
                if (exp == 2)
                {
                    gs.ExpansionType = GridSurfaceExpansionType.PLANE_ASPECT;
                }
                if (exp == 3)
                {
                    gs.ExpansionType = GridSurfaceExpansionType.LEGACY;
                }

                // 6 simplify tributary area
                bool       simple = true;
                GH_Boolean ghsim  = new GH_Boolean();
                if (DA.GetData(6, ref ghsim))
                {
                    GH_Convert.ToBoolean(ghsim, out simple, GH_Conversion.Both);
                }
                if (simple)
                {
                    gs.SpanType = GridSurface.Span_Type.TWO_WAY_SIMPLIFIED_TRIBUTARY_AREAS;
                }
                else
                {
                    gs.SpanType = GridSurface.Span_Type.TWO_WAY;
                }
                break;

            case FoldMode.Two_Dimensional:
                changeGS       = true;
                gs.ElementType = GridSurface.Element_Type.TWO_DIMENSIONAL;
                break;
            }
            if (changeGS)
            {
                gps.GridSurface = gs;
            }

            DA.SetData(0, new GsaGridPlaneSurfaceGoo(gps));
        }
예제 #13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Plane pln = Plane.WorldXY;

            // 0 Plane
            GH_Plane gh_pln = new GH_Plane();

            if (DA.GetData(0, ref gh_pln))
            {
                GH_Convert.ToPlane(gh_pln, ref pln, GH_Conversion.Both);
            }

            // create gsa gridplanesurface from plane
            GsaGridPlaneSurface gps = new GsaGridPlaneSurface(pln);

            // 1 Grid plane ID
            GH_Integer ghint = new GH_Integer();

            if (DA.GetData(1, ref ghint))
            {
                int id = 0;
                GH_Convert.ToInt32(ghint, out id, GH_Conversion.Both);
                gps.GridPlaneID = id;
            }

            // 2 Grid elevation
            GH_Number ghnum = new GH_Number();

            if (DA.GetData(2, ref ghnum))
            {
                double elev = 0;
                if (GH_Convert.ToDouble(ghnum, out elev, GH_Conversion.Both))
                {
                    gps.GridPlane.Elevation = elev;

                    // if elevation is set we want to move the plane in it's normal direction
                    Vector3d vec = pln.Normal;
                    vec.Unitize();
                    vec.X *= elev;
                    vec.Y *= elev;
                    vec.Z *= elev;
                    Transform xform = Transform.Translation(vec);
                    pln.Transform(xform);
                    gps.Plane = pln;
                    // note this wont move the Grid Plane Axis gps.Axis
                }
            }

            // 3 Name
            GH_String ghtxt = new GH_String();

            if (DA.GetData(3, ref ghtxt))
            {
                string name = "";
                if (GH_Convert.ToString(ghtxt, out name, GH_Conversion.Both))
                {
                    gps.GridPlane.Name = name;
                }
            }

            // set is story
            if (_mode == FoldMode.General)
            {
                gps.GridPlane.IsStoreyType = false;
            }
            else
            {
                gps.GridPlane.IsStoreyType = true;

                // 4 tolerance above
                GH_Number ghtola = new GH_Number();
                if (DA.GetData(4, ref ghtola))
                {
                    double tola = 0;
                    if (GH_Convert.ToDouble(ghtola, out tola, GH_Conversion.Both))
                    {
                        gps.GridPlane.ToleranceAbove = tola;
                    }
                }

                // 5 tolerance above
                GH_Number ghtolb = new GH_Number();
                if (DA.GetData(5, ref ghtolb))
                {
                    double tolb = 0;
                    if (GH_Convert.ToDouble(ghtolb, out tolb, GH_Conversion.Both))
                    {
                        gps.GridPlane.ToleranceBelow = tolb;
                    }
                }
            }

            DA.SetData(0, new GsaGridPlaneSurfaceGoo(gps));
        }
예제 #14
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridPointLoad gridpointload = new GsaGridPointLoad();

            // 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);
            }
            gridpointload.GridPointLoad.Case = lc;

            // 1 Point
            Point3d  pt    = new Point3d();
            GH_Point gh_pt = new GH_Point();

            if (DA.GetData(1, ref gh_pt))
            {
                GH_Convert.ToPoint3d(gh_pt, ref pt, GH_Conversion.Both);
            }
            gridpointload.GridPointLoad.X = pt.X;
            gridpointload.GridPointLoad.Y = pt.Y;

            // 2 Plane
            GsaGridPlaneSurface grdplnsrf;
            Plane            pln    = Plane.WorldXY;
            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();
                    gridpointload.GridPlaneSurface = grdplnsrf;
                }
                else if (gh_typ.Value is Plane)
                {
                    gh_typ.CastTo(ref pln);
                    grdplnsrf = new GsaGridPlaneSurface(pln);
                    gridpointload.GridPlaneSurface = grdplnsrf;
                }
                else
                {
                    int id = 0;
                    if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                    {
                        gridpointload.GridPointLoad.GridSurface = id;
                        gridpointload.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 point's z-coordinate will be used for an xy-plane at that elevation");
                        return;
                    }
                }
            }
            else
            {
                pln        = Plane.WorldXY;
                pln.Origin = pt;
                grdplnsrf  = new GsaGridPlaneSurface(pln);
                gridpointload.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;
            }

            gridpointload.GridPointLoad.Direction = direc;

            // 4 Axis
            int axis = 0;

            gridpointload.GridPointLoad.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)
                {
                    gridpointload.GridPointLoad.AxisProperty = axis;
                }
            }

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

            if (DA.GetData(5, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    gridpointload.GridPointLoad.Name = name;
                }
            }

            // 6 load value
            double load = 0;

            if (DA.GetData(6, ref load))
            {
                load *= -1000; //convert to kN
            }
            gridpointload.GridPointLoad.Value = load;

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

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