using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Collections.Generic;

namespace FeMM.Grasshopper.Components.Elements
{
    public class LinkComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the BeamComponent class.
        /// </summary>
        public LinkComponent()
          : base("Link", "L", "Define a Link", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_ELEMENTS)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddCurveParameter("Line", "L", "The generating line", GH_ParamAccess.item);
            pManager.AddGenericParameter("Link Property", "LT", "The link property to assign to the generated link", GH_ParamAccess.item);
            pManager.AddGenericParameter("Groups", "G", "The groups to assign to the beam", GH_ParamAccess.list);
            pManager[2].Optional = true;
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Link", "L", "The generated link", 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)
        {
            Curve line = null;
            GH_FunctionDefinition bp = null;
            var groups = new List<GH_Group>();

            if (!DA.GetData(0, ref line))
                return;
            if (!DA.GetData(1, ref bp))
                return;
            DA.GetDataList(2, groups);

            var link = new GH_Link(line.PointAtStart, line.PointAtEnd, bp, [.. groups]);

            DA.SetData(0, link);
        }

        public override GH_Exposure Exposure => GH_Exposure.primary;

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("a57f2ef1-d366-419a-97fa-6c91f647550d");
    }
}
303 files24 directories