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

namespace FeMM.Grasshopper.Components.Loads
{
#if NETCOREAPP
    [SupportedOSPlatform("windows")]
#endif
    public class PlatePreStressComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the PlatePreStressComponent class.
        /// </summary>
        public PlatePreStressComponent()
          : base("Plate PreStress", "PPre", "Assign prestress in plate using its local coordinate system", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_LOADS)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Plate", "P", "The plate where add the pressure", GH_ParamAccess.item);
            pManager.AddGenericParameter("LoadCase", "LC", "The load case", GH_ParamAccess.item);
            pManager.AddNumberParameter("Px", "px", "Value of prestress in x local direction", GH_ParamAccess.item);
            pManager.AddNumberParameter("Py", "py", "Value of prestress in y local direction", GH_ParamAccess.item);
            pManager.AddNumberParameter("Pz", "pz", "Value of prestress in z local direction", GH_ParamAccess.item);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Plate", "P", "The modified plate", 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_Plate plate = null;
            GH_Case lc = null;

            if (!DA.GetData("Plate", ref plate))
                return;
            if (!DA.GetData("LoadCase", ref lc))
                return;
            double px = 0;
            if (!DA.GetData("Px", ref px))
                return;
            double py = 0;
            if (!DA.GetData("Py", ref py))
                return;
            double pz = 0;
            if (!DA.GetData("Pz", ref pz))
                return;

            var value = new Vector3d(px, py, pz);

            var load_value = new PlatePreStressModel.LoadData()
            {
                LocalPressure = value                
            };
            var load = new PlatePreStressModel((LoadCaseModel)lc.Value, load_value) { CoordinateSystem = CoordinateSystemModel.Local };
            var newPlate = new GH_Plate(plate);
            newPlate.Value.Loads.Add(load);
            Message = string.Format("Coordinate System: {0}", load.CoordinateSystem.Name);
            DA.SetData(0, newPlate);
        }

        public override GH_Exposure Exposure => GH_Exposure.tertiary;

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


        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("5c58e992-3792-45ec-ad19-d3474bf4f31f");
    }
}
303 files24 directories