using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using System;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Attributes
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class NodeConstraintComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the NodeRestraintsComponent class.
/// </summary>
public NodeConstraintComponent()
: base("Node Constraint", "NC", "Apply costraint to nodes", 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("Node", "N", "The node where define the restraits", GH_ParamAccess.item);
pManager.AddGenericParameter("Constraint", "C", "The defined constraint", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Node", "N", "The modified node", 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)
{
GH_Node node = null;
GH_FunctionDefinition gH_FunctionDefinition = null;
if (!DA.GetData("Node", ref node))
return;
DA.GetData(1, ref gH_FunctionDefinition);
if (gH_FunctionDefinition == null && gH_FunctionDefinition.Value != null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Null constraint");
return;
}
else
{
var newNode = new GH_Node(node);
if (gH_FunctionDefinition.Value is NodeDiaphragmConstraintModel nodeDiaphragmConstraint)
{
newNode.Value.Constraints.Add(nodeDiaphragmConstraint);
DA.SetData("Node", newNode);
}
else if (gH_FunctionDefinition.Value is NodeBodyConstraintModel nodeBodyConstraint)
{
newNode.Value.Constraints.Add(nodeBodyConstraint);
DA.SetData("Node", newNode);
}
else
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input is not a constraint");
return;
}
}
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.NodeConstraintIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("01a9edc3-2d80-4b49-884f-5d1041fb9b12");
}
}