using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using MeChecksApi;
using System;
using System.Collections.Generic;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.MeCheck
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class AutoTensionComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the AutoTensionComponent class.
/// </summary>
public AutoTensionComponent()
: base("AutoTension", "AT", "Define the Auto Tensions", CategoryNameConstants.CATEGORY_CHECKS, CategoryNameConstants.SUBCATEGORY_MECHECK)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Beam", "Beam", "Beam", GH_ParamAccess.item);
pManager.AddTextParameter("LC", "LC", "Load Case", GH_ParamAccess.item);
pManager.AddNumberParameter("AutoTensionI", "AutoTensionI", "Autotension End I", GH_ParamAccess.list);
pManager.AddNumberParameter("AutoTensionJ", "AutoTensionJ", "Autotension End J", GH_ParamAccess.list);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
}
/// <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("Beam", ref beam))
{
return;
}
string LC = "";
if (!DA.GetData("LC", ref LC))
return;
var autotensionI = new List<double>();
if (!DA.GetDataList("AutoTensionI", autotensionI))
{
return;
}
if (autotensionI.Count != 6)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Set 6 autotension for section I");
return;
}
var autotensionJ = new List<double>();
if (!DA.GetDataList("AutoTensionJ", autotensionJ))
{
return;
}
if (autotensionJ.Count != 6)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Set 6 autotension for section J");
return;
}
IMeChecksApi api = ApiHelper.Connect();
//conversion to string because of API
string[] autoTensI = new string[6];
string[] autoTensJ = new string[6];
for (int i = 0; i < 6; i++)
{
autoTensI[i] = autotensionI[i].ToString();
autoTensJ[i] = autotensionJ[i].ToString();
}
api.CallPluginApi("MixSecsBeamSecCheck", "SetAutoTension", beam.Value.BeamId, LC, autoTensI, autoTensJ);
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.AutoTensionIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("ad982c12-9981-4496-8613-577439f67508");
}
}