using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
namespace FeMM.Grasshopper.Components.Loads
{
public class NodeNSMassComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the NodeNSMassComponent class.
/// </summary>
public NodeNSMassComponent()
: base("Node non structural Mass", "NNSM", "Assign a node non structural mass", 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 the mass is applied", GH_ParamAccess.item);
pManager.AddGenericParameter("LoadCase", "LC", "The load case", GH_ParamAccess.item);
pManager.AddNumberParameter("Mass", "M", "The value of the mass [Mass]", GH_ParamAccess.item);
pManager.AddNumberParameter("Dyn factor", "DF", "The dynamic factor of the non structural mass", GH_ParamAccess.item);
pManager.AddVectorParameter("Offset", "O", "Offset of the mass", GH_ParamAccess.item, Vector3d.Zero);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Node", "N", "The node with the NS mass applied", 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;
double mass = 0;
double dynFactor = 0;
Vector3d offset = Vector3d.Unset;
if (!DA.GetData("Node", ref node))
return;
if (!DA.GetData("LoadCase", ref lc))
return;
if (!DA.GetData("Mass", ref mass))
return;
if (!DA.GetData("Dyn factor", ref dynFactor))
return;
if (!DA.GetData("Offset", ref offset))
return;
var load_value = new NodeNSMassModel.LoadData()
{
Mass = mass,
DynFactor = dynFactor,
Offset = offset
};
var load = new NodeNSMassModel((LoadCaseModel)lc.Value, load_value);
var newNode = new GH_Node(node);
newNode.Value.Loads.Add(load);
DA.SetData(0, newNode);
}
public override GH_Exposure Exposure => GH_Exposure.tertiary;
/// <summary>
/// Provides an Icon for the component - to be corrected
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.PlateNSMassIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("0934D00A-8C9D-42C8-8933-991B9AA14648");
}
}