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 FixedAxialForceComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the FixedAxialForceComponent class.
/// </summary>
public FixedAxialForceComponent()
: base("Target Axial Force", "FAF", "The target axial force 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 axial force value", GH_ParamAccess.item);
pManager.AddNumberParameter("Weight", "W", "The weight of the fixed axial force 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 FixedAxialForceModel((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.FixedAxialForceIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("a88a3d74-f64d-4062-8e6b-4d5d50657b5b");
}
}