using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using FeMM.Rhino.Elements;
using FeMM.Rhino.Models;
using Grasshopper.Kernel;
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Input;
using Rhino.Input.Custom;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.Parameters
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class BeamParam : GH_PersistentParam<GH_Beam>
{
public BeamParam()
: base("Beam", "B", "Contains a collection of beams", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_PARAMETERS)
{
}
protected override GH_Beam InstantiateT()
{
return new GH_Beam();
}
protected override GH_GetterResult Prompt_Singular(ref GH_Beam value)
{
RhinoDoc doc = RhinoDoc.ActiveDoc;
if (doc == null)
return GH_GetterResult.cancel;
var go = new GetObject();
go.SetCommandPrompt("Select a beam");
GetResult res = go.Get();
if (res == GetResult.Object)
{
RhinoObject rhinoObject = go.Object(0).Object();
if (rhinoObject is BeamObject beamObject)
{
BeamModel beam = ((BeamUserData)beamObject.Model).Data;
value = new GH_Beam(beam);
return GH_GetterResult.success;
}
}
return GH_GetterResult.cancel;
}
protected override GH_GetterResult Prompt_Plural(ref List<GH_Beam> values)
{
RhinoDoc doc = RhinoDoc.ActiveDoc;
if (doc == null)
return GH_GetterResult.cancel;
values = [];
var go = new GetObject();
go.SetCommandPrompt("Select beams");
go.GetMultiple(1, 0);
if (go.CommandResult() == Result.Success)
{
for (int i = 0; i < go.ObjectCount; i++)
{
RhinoObject rhinoObject = go.Object(i).Object();
if (rhinoObject is BeamObject beamObject)
{
BeamModel beam = ((BeamUserData)beamObject.Model).Data;
values.Add(new GH_Beam(beam));
}
}
doc.Views.Redraw();
return GH_GetterResult.success;
}
return GH_GetterResult.cancel;
}
protected override Bitmap Icon => Properties.Resources.BeamParamIcon;
public override Guid ComponentGuid => new("1DC4AA30-82A1-40E2-B90C-CA9A72090567");
}
}