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 LinkRigidPropertyComponent : 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 LinkRigidPropertyComponent()
: base("Rigid Link Property", "RLP", "Rigid 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)
{
pManager.AddTextParameter("Name", "N", "Property name", GH_ParamAccess.item, "Rigid Link Property");
int i = pManager.AddIntegerParameter("Type", "T", "The property type", GH_ParamAccess.item, 0);
Param_Integer mtParam = pManager[i] as Param_Integer;
foreach (KeyValuePair<int, string> v in _propertyTypeOptions)
mtParam.AddNamedValue(v.Value, v.Key);
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 type = 0;
GH_FunctionDefinition cs = null;
if (!DA.GetData("Name", ref name))
return;
if (!DA.GetData("Type", ref type))
return;
bool has_cs = DA.GetData("Coordinate System", ref cs);
CoordinateSystemModel cccs = CoordinateSystemModel.Global;
if (cs != null && cs.Value is CoordinateSystemModel css)
cccs = css;
var strausRigidLinkModel = new StrausRigidLinkModel(name)
{
CoordinateSystem = cccs,
Plane = (StrausRigidLinkModel.Planes)type,
};
var gh_bp = new GH_FunctionDefinition(strausRigidLinkModel);
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("aeff881a-7806-4830-b2a2-f4d224edc095");
}
}