using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Collections.Generic;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Elements
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public abstract class BeamComponentBase : GH_Component
{
/// <summary>
/// Initializes a new instance of the BeamComponent class.
/// </summary>
public BeamComponentBase()
: base("Beam", "B", "Define a Beam", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_ELEMENTS)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddCurveParameter("Line", "L", "The generating line", GH_ParamAccess.item);
pManager.AddGenericParameter("Property", "BP", "The property to assign to the generated beam", GH_ParamAccess.item);
pManager.AddGenericParameter("Groups", "G", "The groups to assign to the beam", GH_ParamAccess.list);
pManager[2].Optional = true;
pManager.AddNumberParameter("Angle", "A", "The rotation angle along the principal axis [deg]", GH_ParamAccess.item, 0);
pManager.AddVectorParameter("Offset", "O", "The translation offset along the principal axis", GH_ParamAccess.item);
pManager[4].Optional = true;
RegisterAdditionalInputs(pManager);
}
protected abstract void RegisterAdditionalInputs(GH_InputParamManager pManager);
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Beam", "B", "The generated beam", 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)
{
Curve line = null;
GH_FunctionDefinition bp = null;
var groups = new List<GH_Group>();
double angle = 0;
Vector3d offset = Vector3d.Unset;
if (!DA.GetData("Line", ref line))
return;
if (!DA.GetData("Property", ref bp))
return;
DA.GetDataList("Groups", groups);
DA.GetData("Angle", ref angle);
bool has_offset = DA.GetData("Offset", ref offset);
AddAlignmentProperties(DA, bp);
var beam = new GH_Beam(line.PointAtStart, line.PointAtEnd, bp, [.. groups]);
if (angle != 0)
beam.Value.AngleDeg = angle;
if (has_offset)
beam.Value.Offset = new Vector2d(offset.X, offset.Y);
DA.SetData("Beam", beam);
}
protected abstract void AddAlignmentProperties(IGH_DataAccess DA, GH_FunctionDefinition bp);
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.BeamIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("a5b774a8-51ec-4c79-bfe7-e19558f444a9");
}
}