using FeMM.Common.Helpers;
using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using System;
namespace FeMM.Grasshopper.Components.Definitions
{
public class LoadCaseComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the LoadCaseComponent class.
/// </summary>
public LoadCaseComponent()
: base("Load Case", "LC", "A load case definition", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_DEFINITIONS)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "N", "The load case name", GH_ParamAccess.item);
pManager.AddBooleanParameter("Gravity NSM", "NSM", "Apply gravity to non-structural mass (for straus7)", GH_ParamAccess.item, false);
int i = pManager.AddIntegerParameter("Load Type", "T", "The load pattern type (for sap)", GH_ParamAccess.item, 1);
Param_Integer mtParam = pManager[i] as Param_Integer;
foreach (Enum en in Enum.GetValues(typeof(LoadCaseModel.LoadPatternTypes)))
mtParam.AddNamedValue(en.GetDescription(), (int)(LoadCaseModel.LoadPatternTypes)en);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("LoadCase", "LC", "The defined load case", 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)
{
string name = "";
bool nsm = false;
int patternType = 0;
if (!DA.GetData(0, ref name))
return;
DA.GetData(1, ref nsm);
DA.GetData(2, ref patternType);
LoadCaseModel lc;
if (name == LoadCaseModel.Dead.Name)
{
if (nsm)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid nsm");
return;
}
if (patternType != (int)LoadCaseModel.LoadPatternTypes.Dead)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Load Pattern Type are setted to Dead");
patternType = (int)LoadCaseModel.LoadPatternTypes.Dead;
}
lc = new LoadCaseModel(LoadCaseModel.Dead);
}
else
{
lc = new LoadCaseModel(-1, name);
if (nsm)
{
lc.GlobalInertiaLoad = LoadCaseModel.GlobalInertiaLoads.Gravity;
lc.GravityDirection = LoadCaseModel.GravityDirections.Z;
lc.GravityValue = -ModelModel.GRAVITY_mmSuS2;
lc.StructuralMassAcceleration = false;
lc.NonStructuralMassAcceleration = true;
}
lc.LoadPatternType = (LoadCaseModel.LoadPatternTypes)patternType;
}
Message = ((LoadCaseModel.LoadPatternTypes)patternType).ToString() + " : " + name;
DA.SetData(0, new GH_Case(lc));
}
public override GH_Exposure Exposure => GH_Exposure.senary;
protected override System.Drawing.Bitmap Icon => Properties.Resources.LoadCaseIcon;
public override Guid ComponentGuid => new("fc022fd8-4ebf-4c56-a428-3a9efeff43b3");
}
}