using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using System;
using System.Collections.Generic;

namespace FeMM.Grasshopper.Components.Attributes
{
    public class PlateTypeComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the PlateSupportComponent class.
        /// </summary>
        public PlateTypeComponent()
          : base("Plate Property Type", "PPT", "Define a plate specification for ETABS", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_ATTRIBUTES)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Plate Property", "PP", "The plate property where define the ETABS spectification", GH_ParamAccess.item);
            int i = pManager.AddIntegerParameter("Type", "T", "Plate type", GH_ParamAccess.item, 0);
            Param_Integer type_param = (Param_Integer)pManager[i];
            type_param.AddNamedValue("Slab - 0", 0);
            type_param.AddNamedValue("Wall - 1", 1);
            i = pManager.AddIntegerParameter("Slab Type", "ST", "The slab type (if Type is slab)", GH_ParamAccess.item, 0);
            type_param = (Param_Integer)pManager[i];
            type_param.AddNamedValue("Slab - 0", 0);
            type_param.AddNamedValue("Drop - 1", 1);
            type_param.AddNamedValue("Ribbed - 3", 3);
            type_param.AddNamedValue("Waffle - 4", 4);
            type_param.AddNamedValue("Mat - 5", 5);
            type_param.AddNamedValue("Footing - 6", 6);
            pManager.AddBooleanParameter("Use One Way Load Distribuition", "OWD", "If true, use the one way distribuition for loads", GH_ParamAccess.item, false);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Plate", "P", "The modified plate", GH_ParamAccess.item);
        }

        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_FunctionDefinition plate = null;
            int type = 0;
            int slabType = 0;
            bool oneWay = false;

            if (!DA.GetData(0, ref plate))
                return;
            if (!DA.GetData(1, ref type))
                return;
            if (!DA.GetData(2, ref slabType))
                return;
            if (!DA.GetData(3, ref oneWay))
                return;

            if (plate != null && plate.Value != null && plate.Value is PlatePropertyModel ppm)
            {
                var newPlate = new PlatePropertyModel(ppm)
                {
                    PlateType = (PlatePropertyModel.PlateTypes)type,
                    SlabType = (PlatePropertyModel.SlabTypes)slabType,
                    UseOneWayLoadDistribution = oneWay
                };

                DA.SetData("Plate", new GH_FunctionDefinition(newPlate));
            }
        }

        public override GH_Exposure Exposure => GH_Exposure.tertiary;

        /// <summary>
        /// Provides an Icon for the component.
        /// </summary>
        protected override System.Drawing.Bitmap Icon => Properties.Resources.PlatePropertyIcon;

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("49e503e2-290b-4108-820e-79feacc27730");
    }
}
303 files24 directories