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

namespace FeMM.Grasshopper.Components.Elements
{
#if NETCOREAPP
    [SupportedOSPlatform("windows")]
#endif
    public class BeamComponentV2 : BeamComponentBase
    {
        public BeamComponentV2() : base()
        {
        }

        public override GH_Exposure Exposure => GH_Exposure.primary;

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("76afe381-4b15-4072-bfb1-75708f72068b");

        protected override void RegisterAdditionalInputs(GH_InputParamManager pManager)
        {
            pManager.AddIntegerParameter("AlignmentX", "AX", "Alignment for X (only used with tapered beams)", GH_ParamAccess.item, (int)BeamTaperAttributeModel.AlignmentCodes.Center);
            Param_Integer type_param = (Param_Integer)pManager[pManager.ParamCount - 1];
            foreach (Enum code in Enum.GetValues(typeof(BeamTaperAttributeModel.AlignmentCodes)))
            {
                type_param.AddNamedValue(code.GetDescription(), (int)(BeamTaperAttributeModel.AlignmentCodes)code);
            }
            pManager.AddIntegerParameter("AlignmentY", "AY", "Alignment for Y (only used with tapered beams)", GH_ParamAccess.item, (int)BeamTaperAttributeModel.AlignmentCodes.Top);
            type_param = (Param_Integer)pManager[pManager.ParamCount - 1];
            foreach (Enum code in Enum.GetValues(typeof(BeamTaperAttributeModel.AlignmentCodes)))
            {
                type_param.AddNamedValue(code.GetDescription(), (int)(BeamTaperAttributeModel.AlignmentCodes)code);
            }
        }

        protected override void AddAlignmentProperties(IGH_DataAccess DA, GH_FunctionDefinition bp)
        {
            if (bp.IsValid && bp.Value is BeamNonPrismaticPropertyModel bnpProperty)
            {
                var alignmentX = (int)BeamTaperAttributeModel.AlignmentCodes.Center;
                var alignmentY = (int)BeamTaperAttributeModel.AlignmentCodes.Top;

                if (!DA.GetData("AlignmentX", ref alignmentX))
                    return;
                if (!DA.GetData("AlignmentY", ref alignmentY))
                    return;

                bnpProperty.AlignmentX = (BeamTaperAttributeModel.AlignmentCodes)alignmentX;
                bnpProperty.AlignmentY = (BeamTaperAttributeModel.AlignmentCodes)alignmentY;
            }
        }
    }
}
303 files24 directories