using FeMM.Common.Helpers;
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 BeamPropertyMaffeisNomenclatureComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the BeamPropertyComponent class.
        /// </summary>
        public BeamPropertyMaffeisNomenclatureComponent()
          : base("Maffeis Beam Property Nomenclature", "MBPN", "Beam properties", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_PROPERTIES)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Beam Property", "BP", "Beam property", GH_ParamAccess.item);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddTextParameter("Maffeis Nomenclature", "MN", "Maffeis Nomenclature", 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_FunctionDefinition gH_BeamProperty = null;

            if (!DA.GetData(0, ref gH_BeamProperty))
                return;

            if (gH_BeamProperty.Value is BeamPropertyModel beamPropertyModel)
            {
                string name = NamingConventionHelper.GetMaffeisName(beamPropertyModel);
                if (name == "")
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Fail to read the section");
                    return;
                }
                DA.SetData(0, name);
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input must be a Beam Property");
            }
        }

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("34443c86-859b-4021-907e-9ae17cf53bc9");
    }
}
303 files24 directories