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

namespace FeMM.Grasshopper.Components.Definitions
{
    public class CoordinateSystemComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the GroupComponent class.
        /// </summary>
        public CoordinateSystemComponent()
          : base("Coordinate System", "CS", "Defines a custom coordinate system", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_DEFINITIONS)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddTextParameter("Name", "N", "The load case name", GH_ParamAccess.item);
            pManager.AddPointParameter("Origin", "O", "The coordinate system origin", GH_ParamAccess.item);
            pManager.AddPointParameter("P1", "P1", "The first point vector coordinate system", GH_ParamAccess.item);
            pManager.AddPointParameter("P2", "P2", "The second point vector coordinate system", GH_ParamAccess.item);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Coordinate System", "CS", "The defined coordinate system", 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)
        {
            string name = "";
            var origin = new Point3d();
            var P1 = new Point3d();
            var P2 = new Point3d();

            if (!DA.GetData(0, ref name))
                return;
            if (!DA.GetData(1, ref origin))
                return;
            if (!DA.GetData(2, ref P1))
                return;
            if (!DA.GetData(3, ref P2))
                return;

            Message = "CS: " + name;

            var coordinateSystemModel = new CoordinateSystemModel(name)
            {
                Origin = origin,
                Point1 = P1,
                Point2 = P2,
            };

            DA.SetData(0, new GH_FunctionDefinition(coordinateSystemModel));
        }

        public override GH_Exposure Exposure => GH_Exposure.primary;

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

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("2315ba54-2f0f-407b-93dd-6fbe9a0fbf51");
    }
}
303 files24 directories