using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Patterning
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class BeamPreLoadResultrComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the ElementFilterComponent class.
/// </summary>
public BeamPreLoadResultrComponent()
: base("Beam Pretension Results", "BPTR", "Beam Pretension Results after form finding analysis", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_RESULTS)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Beams", "Bs", "The beams to filter", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddNumberParameter("Pre Load", "PL", "The pre load value", GH_ParamAccess.list);
pManager.AddTextParameter("Type", "T", "The pre load type", GH_ParamAccess.list);
pManager.AddGenericParameter("Load Case", "LC", "The pre load load case", GH_ParamAccess.list);
}
/// <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)
{
var beam = new GH_Beam();
if (!DA.GetData(0, ref beam))
return;
if (beam == null)
return;
var result = new List<double>();
var loadTypes = new List<string>();
var loadCases = new List<GH_Case>();
List<LoadModel> preStrainLoad = [.. beam.Value.Loads.Where(j => j is BeamPreLoadModel)];
if (preStrainLoad != null && preStrainLoad.Count > 0)
{
for (int j = 0; j < preStrainLoad.Count; j++)
{
BeamPreLoadModel beamPreLoadModel = (BeamPreLoadModel)preStrainLoad[j];
result.Add(beamPreLoadModel.Value);
loadTypes.Add(beamPreLoadModel.PreLoadType.ToString());
loadCases.Add(new GH_Case(beamPreLoadModel.LoadCase));
}
}
DA.SetDataList(0, result);
DA.SetDataList(1, loadTypes);
DA.SetDataList(2, loadCases);
}
public override GH_Exposure Exposure => GH_Exposure.secondary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.BeamPreTensionIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("bd99c783-e1f9-47e7-bec4-95795d35de92");
}
}