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

namespace FeMM.Grasshopper.Components.ElementProperties
{
    public class SpringDamperDataComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the PlatePropertyComponent class.
        /// </summary>
        public SpringDamperDataComponent()
          : base("Spring Damper Data", "SDD", "Define the data required by the Spring-Damper beam property type", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_PROPERTIES)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddNumberParameter("Spring Stiffness Axial", "SSA", "Spring Stiffness Axial", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Spring Stiffness Lateral", "SSL", "Spring Stiffness Lateral", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Spring Stiffness Torsion", "SST", "Spring Stiffness Torsion", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Damper Axial", "DA", "Damper Axial", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Damper Lateral", "DL", "Damper Lateral", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Damper Torsion", "DT", "Damper Torsion", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Mass", "M", "Element mass ", GH_ParamAccess.item, 0);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Property Data", "PD", "Spring-Damper beam property data", 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 springStiffnessAxial = 0;
            double springStiffnessLateral = 0;
            double springStiffnessTorsion = 0;
            double damperAxial = 0;
            double damperLateral = 0;
            double damperTorsion = 0;
            double mass = 0;

            if (!DA.GetData(0, ref springStiffnessAxial))
                return;
            if (!DA.GetData(1, ref springStiffnessLateral))
                return;
            if (!DA.GetData(2, ref springStiffnessTorsion))
                return;
            if (!DA.GetData(3, ref damperAxial))
                return;
            if (!DA.GetData(4, ref damperLateral))
                return;
            if (!DA.GetData(5, ref damperTorsion))
                return;
            if (!DA.GetData(5, ref mass))
                return;

            SpringDamperDataModel data = new(springStiffnessAxial, springStiffnessLateral, springStiffnessTorsion, damperAxial, damperLateral, damperTorsion, mass);

            DA.SetData(0, new GH_SpringDamperData(data));
        }

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("9d0b8bd2-772f-43f3-8e4c-c462bdf6d399");
    }
}
303 files24 directories