using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Loads
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class NodeMomentComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the NodeMomentComponent class.
/// </summary>
public NodeMomentComponent()
: base("Node Moment", "NM", "Defines a node moment", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_LOADS)
{
}
/// <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("LoadCase", "LC", "The load case", GH_ParamAccess.item);
pManager.AddVectorParameter("Moment", "M", "The vector moment in the global XYZ direction", GH_ParamAccess.item);
int i = pManager.AddGenericParameter("Coordinate System", "CS", "The restraint coordiante system", GH_ParamAccess.item);
pManager[i].Optional = true;
}
/// <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_Case lc = null;
Vector3d moment = Vector3d.Unset;
GH_FunctionDefinition coordinateSystemModel = null;
if (!DA.GetData("Node", ref node))
return;
if (!DA.GetData("LoadCase", ref lc))
return;
if (!DA.GetData("Moment", ref moment))
return;
bool hasCS = DA.GetData("Coordinate System", ref coordinateSystemModel);
var load = new NodeMomentLoadModel((LoadCaseModel)lc.Value, new Vector3d(moment.X, moment.Y, moment.Z));
if (hasCS)
{
if (coordinateSystemModel != null && coordinateSystemModel.Value is CoordinateSystemModel css)
load.CoordinateSystem = css;
}
else
load.CoordinateSystem = CoordinateSystemModel.Global;
var newNode = new GH_Node(node);
newNode.Value.Loads.Add(load);
Message = string.Format("Coordinate System: {0}", load.CoordinateSystem.Name);
DA.SetData("Node", newNode);
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.NodeMomentIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("42e3a363-76f6-403d-92fc-3bb4c557a303");
}
}