using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using System;

namespace FeMM.Grasshopper.Components.Sections
{
    public class CableSectionComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the SolidCircleBeamSectionComponent class.
        /// </summary>
        public CableSectionComponent()
          : base("Cable section", "CS", "Defines a solid circle cable section", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_SECTIONS)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddNumberParameter("Diameter", "D", "The section diameter", GH_ParamAccess.item);
            pManager.AddNumberParameter("Equivalent Area", "EA", "The equivalent area of the section", GH_ParamAccess.item);
            pManager.AddNumberParameter("Equivalent Density", "ED", "The equivalent density of the section", GH_ParamAccess.item);
            pManager.AddNumberParameter("Equivalent E", "EM", "The equivalent modulus of the section", GH_ParamAccess.item);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Section", "S", "The solid circular section", 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)
        {
            double d = 0;
            double equivalentArea = 0;
            double equivalentDensity = 0;
            double equivalentModulus = 0;

            if (!DA.GetData(0, ref d))
                return;
            if (!DA.GetData(1, ref equivalentArea))
                return;
            if (!DA.GetData(2, ref equivalentDensity))
                return;
            if (!DA.GetData(3, ref equivalentModulus))
                return;

            var sectionModel = new SectionModel()
            {
                SectionType = SectionModel.SectionTypes.SolidCircle,
                D = d,
                UseEquivalent = true,
                EquivalentArea = equivalentArea,
                EquivalentDiameter = Math.Sqrt(equivalentArea / Math.PI) * 2,
                EquivalentDensity = equivalentDensity,
                EquivalentModulus = equivalentModulus
            };
            sectionModel.CalculateSection();

            var section = new GH_BeamSection(sectionModel);
            DA.SetData(0, section);
        }

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("0fbf0b45-a594-400e-a1fc-2f20a7b11823");
    }
}
303 files24 directories