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

namespace FeMM.Grasshopper.Components.Results
{
    public class BeamSteelDesignResultsComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the BeamResultsComponent class.
        /// </summary>
        public BeamSteelDesignResultsComponent()
          : base("Beam Steel Results", "BSR", "The Beam steel design results", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_RESULTS)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Beam", "B", "The beam with results", GH_ParamAccess.item);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddTextParameter("Combs.", "C", "The combinations name", GH_ParamAccess.list);
            pManager.AddNumberParameter("Stations", "ST", "The stations", GH_ParamAccess.list);
            pManager.AddNumberParameter("Ratios", "R", "The utilization ratio of the check", GH_ParamAccess.list);
            pManager.AddTextParameter("Type", "T", "The ratio type of the check", GH_ParamAccess.list);
        }

        /// <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_BeamResults beam = null;
            if (!DA.GetData(0, ref beam))
                return;

            var combos = new List<string>();
            var stations = new List<double>();
            var ratios = new List<double>();
            var types = new List<string>();
            var resultModels = beam.Value.Where(r => r is BeamSteelDesignResultModel).Cast<BeamSteelDesignResultModel>();

            foreach (BeamSteelDesignResultModel result in resultModels)
            {
                combos.Add(result.LoadCase.Name);
                stations.Add(result.Station);
                ratios.Add(result.Ratio);
                types.Add(result.ResultCode.GetDescription());
            }
            DA.SetDataList(0, combos);
            DA.SetDataList(1, stations);
            DA.SetDataList(2, ratios);
            DA.SetDataList(3, types);
        }

        public override GH_Exposure Exposure => GH_Exposure.secondary;

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("94C5115A-97AB-4BCF-AAC2-CA9EB05D0FC2");
    }
}
303 files24 directories