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 FixedLengthComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the FixedLengthComponent class.
/// </summary>
public FixedLengthComponent()
: base("Target Length", "FL", "The target length attribute", 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("Beam", "B", "The beam where add the target Length attribute", GH_ParamAccess.item);
pManager.AddGenericParameter("LoadCase", "LC", "The load case", GH_ParamAccess.item);
pManager.AddNumberParameter("Value", "V", "The fixed length value", GH_ParamAccess.item);
pManager.AddNumberParameter("Weight", "W", "The weight of the fixed length value in the non-linear solver", GH_ParamAccess.item, 1);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Beam", "B", "The modified beam", 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_Beam beam = null;
GH_Case lc = null;
double value = 0;
double weight = 0;
if (!DA.GetData("Beam", ref beam))
return;
if (!DA.GetData("LoadCase", ref lc))
return;
if (!DA.GetData("Value", ref value))
return;
DA.GetData("Weight", ref weight);
if (weight <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Weight parameter must be > 0");
return;
}
var newBeam = new BeamModel(beam.Value);
newBeam.Loads.Add(new FixedLengthModel((LoadCaseModel)lc.Value, value, weight));
DA.SetData(0, new GH_Beam(newBeam));
}
public override GH_Exposure Exposure => GH_Exposure.secondary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.FixedLengthIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("5d89f883-1bbe-4f2e-81bc-62227bd42f59");
}
}