using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Elements
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class PlateComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the PlateComponent class.
/// </summary>
public PlateComponent()
: base("Plate", "PL", "Define a Plate", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_ELEMENTS)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddMeshParameter("Mesh", "M", "The generating mesh face", GH_ParamAccess.item);
pManager.AddGenericParameter("Property", "PP", "The property to assign to the generated plate", GH_ParamAccess.item);
pManager.AddGenericParameter("Groups", "G", "The group to assign to the plate", GH_ParamAccess.list);
pManager[2].Optional = true;
pManager.AddNumberParameter("Angle", "A", "The local axis angle [deg]", GH_ParamAccess.item, 0);
pManager.AddNumberParameter("Offset", "O", "The plate offset", GH_ParamAccess.item, 0);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Plate", "P", "The generated 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)
{
var face = new Mesh();
GH_FunctionDefinition pp = null;
var groups = new List<GH_Group>();
double angle = 0;
double offset = 0;
if (!DA.GetData("Mesh", ref face))
return;
if (!DA.GetData("Property", ref pp))
return;
DA.GetDataList("Groups", groups);
DA.GetData("Angle", ref angle);
DA.GetData("Offset", ref offset);
if (face.Vertices.Count < 3)
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh with less than 3 vertices");
if (face.Vertices.Count > 4)
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning: Mesh have more than 4 vertices");
Polyline edges = face.GetNakedEdges().FirstOrDefault();
Point3d[] vertexes = new Point3d[edges.Count - 1];
for (int i = 0; i < edges.Count - 1; i++)
vertexes[i] = edges[i];
if (pp != null && pp.Value is PlatePropertyModel)
{
var plate = new GH_Plate(vertexes, pp, [.. groups]);
if (angle != 0)
plate.Value.AngleDeg = angle;
if (offset != 0)
plate.Value.Offset = offset;
DA.SetData("Plate", plate);
}
else
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Property input is not a plate property");
}
public override GH_Exposure Exposure => GH_Exposure.primary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.PlateIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("2e9fcc4d-5f9b-403c-be31-40804205df1a");
}
}