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

namespace FeMM.Grasshopper.Components.Checks
{
#if NETCOREAPP
    [SupportedOSPlatform("windows")]
#endif
    public class AddForceToBeamComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the ForceComponent class.
        /// </summary>
        public AddForceToBeamComponent()
          : base("Add Forces To Beam", "AFTB", "Add forces to a beam ", CategoryNameConstants.CATEGORY_CHECKS, CategoryNameConstants.SUBCATEGORY_MECHECK2)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Beam", "B", "The beam where add the forces", GH_ParamAccess.item);
            pManager.AddGenericParameter("Forces", "F", "The list of forces to add", GH_ParamAccess.list);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Beam", "B", "The beam", 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_Beam beam = null;
            var force = new List<BeamForceResultModel>();

            if (!DA.GetData("Beam", ref beam))
                return;
            DA.GetDataList(1, force);

            var beamModel = new BeamModel(beam.Value);
            for (int i = 0; i < force.Count; i++)
            {
                if(force[i] == null) 
                    continue;
                
                beamModel.Results.Add(force[i]);
            }

            DA.SetData(0, new GH_Beam(beamModel));
        }

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("d03e754d-0c38-48d5-8aee-6cef629b766b");
    }
}
303 files24 directories