using FeMM.Common.Helpers;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Versioning;
namespace FeMM.Grasshopper.Components.MeCheck2
{
#if NETCOREAPP
[SupportedOSPlatform("windows")]
#endif
public class PrintCheckImageAddCurveComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the MyComponent1 class.
/// </summary>
public PrintCheckImageAddCurveComponent()
: base("Add Curve to Graphic", "ACTG", "Add a curve to MeCheck2.0 graphic creator", CategoryNameConstants.CATEGORY_CHECKS, CategoryNameConstants.SUBCATEGORY_MECHECK2)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddNumberParameter("X Values", "XV", "The abscissa values", GH_ParamAccess.list);
pManager.AddNumberParameter("Y Values", "YV", "The ordinate values", GH_ParamAccess.list);
pManager.AddTextParameter("Title", "T", "The title of the curve", GH_ParamAccess.item, "");
pManager.AddColourParameter("Colour", "C", "The curve colour", GH_ParamAccess.item, Color.Black);
pManager.AddNumberParameter("Line Thickness", "LT", "The line thickness", GH_ParamAccess.item, 1);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Curve", "C", "The curve", 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)
{
var xValues = new List<double>();
var yValues = new List<double>();
string title = string.Empty;
Color color = Color.Black;
double thickness = 1;
int nnn = 0;
if (!DA.GetDataList(nnn++, xValues))
return;
if (!DA.GetDataList(nnn++, yValues))
return;
DA.GetData(nnn++, ref title);
DA.GetData(nnn++, ref color);
DA.GetData(nnn++, ref thickness);
if (xValues.Count == 0 || yValues.Count == 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"X or Y values count == 0");
return;
}
if (xValues.Count != yValues.Count)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"X and Y values must have the same length");
return;
}
if (xValues.Count == 1 || yValues.Count == 1)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Must be must be at least 2 values");
return;
}
try
{
var curveValue = new List<double[]>();
for (int i = 0; i < xValues.Count; i++)
curveValue.Add([xValues[i], yValues[i]]);
var curve = new GraphicCreator.Curve(title, color)
{
Values = curveValue,
Thickness = thickness,
};
DA.SetData(0, curve);
}
catch (Exception)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Fail to create the curve");
return;
}
return;
}
public override GH_Exposure Exposure => GH_Exposure.tertiary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override Bitmap Icon => Properties.Resources.PrintCompositeSectionResultsIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("375b11cc-7ffd-4f45-bf21-bc479062436e");
}
}