using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using FeMM.Rhino.Elements;
using FeMM.Rhino.Models;
using Grasshopper.Kernel;
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Input;
using Rhino.Input.Custom;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Versioning;

namespace FeMM.Grasshopper.Components.Parameters
{
#if NETCOREAPP
    [SupportedOSPlatform("windows")]
#endif
    public class PlateParam : GH_PersistentParam<GH_Plate>
    {
        public PlateParam()
            : base("Plate", "P", "Contains a collection of plates", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_PARAMETERS)
        {
        }

        protected override GH_Plate InstantiateT()
        {
            return new GH_Plate();
        }

        protected override GH_GetterResult Prompt_Singular(ref GH_Plate value)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;
            if (doc == null)
                return GH_GetterResult.cancel;

            var go = new GetObject();
            go.SetCommandPrompt("Select a plate");
            GetResult res = go.Get();
            if (res == GetResult.Object)
            {
                RhinoObject rhinoObject = go.Object(0).Object();
                if (rhinoObject is PlateObject plateObject)
                {
                    PlateModel plate = ((PlateUserData)plateObject.Model).Data;
                    value = new GH_Plate(plate);
                    return GH_GetterResult.success;
                }
            }

            return GH_GetterResult.cancel;
        }

        protected override GH_GetterResult Prompt_Plural(ref List<GH_Plate> values)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;
            if (doc == null)
                return GH_GetterResult.cancel;

            values = [];

            var go = new GetObject();
            go.SetCommandPrompt("Select plates");
            go.GetMultiple(1, 0);
            if (go.CommandResult() == Result.Success)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (rhinoObject is PlateObject plateObject)
                    {
                        PlateModel plate = ((PlateUserData)plateObject.Model).Data;
                        values.Add(new GH_Plate(plate));
                    }
                }
                doc.Views.Redraw();
                return GH_GetterResult.success;
            }

            return GH_GetterResult.cancel;
        }

        protected override Bitmap Icon => Properties.Resources.PlateParamIcon;

        public override Guid ComponentGuid => new("DD0920B4-14B2-4A91-BA3F-46A91EC067B6");
    }
}
303 files24 directories