using FeMM.Common.Helpers;
using FeMM.Common.Models;
using FeMM.Grasshopper.Components.Parameters;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using System;
using System.Collections.Generic;
namespace FeMM.Grasshopper.Components.ElementProperties
{
public class LinkMasterSlavePropertyComponent : GH_Component
{
protected Dictionary<int, string> _propertyTypeOptions = new()
{
{ 0, "PlaneXYZ [0]" },
{ 1, "PlaneXY [1]" },
{ 2, "PlaneYZ [2]" },
{ 3, "PlaneZX [3]" },
};
/// <summary>
/// Initializes a new instance of the RigidLinkPropertyComponent class.
/// </summary>
public LinkMasterSlavePropertyComponent()
: base("Master Slave Link Property", "MSLP", "Master Slave Link property for Straus7", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_PROPERTIES)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
Array names = Enum.GetValues(typeof(StrausMasterSlaveLinkModel.DOFTypes));
pManager.AddTextParameter("Name", "N", "Property name", GH_ParamAccess.item, "Master Slave Link");
int i = pManager.AddIntegerParameter("Dx", "Dx", "Dx", GH_ParamAccess.item, 1);
foreach (StrausMasterSlaveLinkModel.DOFTypes name in names)
((Param_Integer)pManager[i]).AddNamedValue(name.GetDescription(), (int)name);
i = pManager.AddIntegerParameter("Dy", "Dy", "Dy", GH_ParamAccess.item, 1);
foreach (StrausMasterSlaveLinkModel.DOFTypes name in names)
((Param_Integer)pManager[i]).AddNamedValue(name.GetDescription(), (int)name);
i = pManager.AddIntegerParameter("Dz", "Dz", "Dz", GH_ParamAccess.item, 1);
foreach (StrausMasterSlaveLinkModel.DOFTypes name in names)
((Param_Integer)pManager[i]).AddNamedValue(name.GetDescription(), (int)name);
i = pManager.AddIntegerParameter("Rx", "Rx", "Rx", GH_ParamAccess.item, 1);
foreach (StrausMasterSlaveLinkModel.DOFTypes name in names)
((Param_Integer)pManager[i]).AddNamedValue(name.GetDescription(), (int)name);
i = pManager.AddIntegerParameter("Ry", "Ry", "Ry", GH_ParamAccess.item, 1);
foreach (StrausMasterSlaveLinkModel.DOFTypes name in names)
((Param_Integer)pManager[i]).AddNamedValue(name.GetDescription(), (int)name);
i = pManager.AddIntegerParameter("Rz", "Rz", "Rz", GH_ParamAccess.item, 1);
foreach (StrausMasterSlaveLinkModel.DOFTypes name in names)
((Param_Integer)pManager[i]).AddNamedValue(name.GetDescription(), (int)name);
var cs_param = new CoordinateSystemParam { Optional = true };
pManager.AddParameter(cs_param, "Coordinate System", "CS", "The coordinate system of the load. Default value: Global Coordinate System", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Property", "LP", "Link property", 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 = "";
int dx = 0;
int dy = 0;
int dz = 0;
int rx = 0;
int ry = 0;
int rz = 0;
GH_FunctionDefinition cs = null;
if (!DA.GetData("Name", ref name))
return;
DA.GetData(1, ref dx);
DA.GetData(2, ref dy);
DA.GetData(3, ref dz);
DA.GetData(4, ref rx);
DA.GetData(5, ref ry);
DA.GetData(6, ref rz);
bool has_cs = DA.GetData("Coordinate System", ref cs);
CoordinateSystemModel cccs = CoordinateSystemModel.Global;
if (cs != null && cs.Value is CoordinateSystemModel css)
cccs = css;
var link = new StrausMasterSlaveLinkModel(name)
{
CoordinateSystem = cccs,
DX = (StrausMasterSlaveLinkModel.DOFTypes)dx,
DY = (StrausMasterSlaveLinkModel.DOFTypes)dy,
DZ = (StrausMasterSlaveLinkModel.DOFTypes)dz,
RX = (StrausMasterSlaveLinkModel.DOFTypes)rx,
RY = (StrausMasterSlaveLinkModel.DOFTypes)ry,
RZ = (StrausMasterSlaveLinkModel.DOFTypes)rz,
};
var gh_bp = new GH_FunctionDefinition(link);
DA.SetData(0, gh_bp);
}
public override GH_Exposure Exposure => GH_Exposure.secondary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.LinkPropertyIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("2e65b706-fd84-4687-99c6-b54094bbe4ca");
}
}