using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using System;
using System.Linq;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Attributes
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class ElementCoordinateSystemComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the SuperElementComponent class.
/// </summary>
public ElementCoordinateSystemComponent()
: base("Element Coordinate System", "ECS", "Assign coordinate system to selected element", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_ATTRIBUTES)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Element", "E", "The element where assign the element ID", GH_ParamAccess.item);
pManager.AddGenericParameter("Coordinate System", "CS", "The coordinate system", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Element", "E", "The modified element", 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)
{
IGH_GeometricGoo element = null;
GH_FunctionDefinition gH_CoordinateSystem = null;
if (!DA.GetData(0, ref element))
return;
if (!DA.GetData(1, ref gH_CoordinateSystem))
return;
CoordinateSystemModel coordinateSystemModel = null;
if(gH_CoordinateSystem == null || gH_CoordinateSystem.Value == null)
return;
if (gH_CoordinateSystem.Value is CoordinateSystemModel cs)
coordinateSystemModel = cs;
if (coordinateSystemModel != null)
{
if (element is GH_Beam beam)
{
var new_beam = new GH_Beam(beam);
new_beam.Value.CoordinateSystem = coordinateSystemModel;
DA.SetData(0, new_beam);
}
else if (element is GH_Plate plate)
{
var new_plate = new GH_Plate(plate);
new_plate.Value.CoordinateSystem = coordinateSystemModel;
DA.SetData(0, new_plate);
}
else if (element is GH_Node node)
{
var new_node = new GH_Node(node);
new_node.Value.CoordinateSystem = coordinateSystemModel;
DA.SetData(0, new_node);
}
else
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unsupported element type");
}
}
}
public override GH_Exposure Exposure => GH_Exposure.quarternary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.AlignNodeAxisIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("e6b7c388-a413-4696-867a-4528d8680e9a");
}
}