using FeMM.Common.Helpers;
using FeMM.Common.Models;
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.Definitions
{
public class LoadCaseConstructionStageComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the LoadCaseComponent class.
/// </summary>
public LoadCaseConstructionStageComponent()
: base("Stage Construction Load Case", "SCLC", "A stage construction load case definition", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_DEFINITIONS)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "N", "The load case name", GH_ParamAccess.item);
pManager.AddGenericParameter("Construction Stages", "CS", "A list of construction stage", GH_ParamAccess.list);
int i = pManager.AddIntegerParameter("Save Options", "O", "The operation type", GH_ParamAccess.item, 0);
var mtParam = pManager[i] as Param_Integer;
foreach (Enum en in Enum.GetValues(typeof(StageConstructionLoadCaseModel.StagedSaveOptions)))
mtParam.AddNamedValue(en.GetDescription(), (int)(StageConstructionLoadCaseModel.StagedSaveOptions)en);
i = pManager.AddGenericParameter("Initial Load Case", "ILC", "This is blank, None, or the name of an existing analysis case. " +
"This item specifies if the load case starts from zero initial conditions, that is, an unstressed state, " +
"or if it starts from the state at the end of a nonlinear static or nonlinear direct integration time history.\r\n" +
"If the specified initial case is a nonlinear static or nonlinear direct integration time history load case, " +
"the state at the end of that case is used. If the initial case is anything else, " +
"zero initial conditions are assumed.\r\n", GH_ParamAccess.item);
pManager[i].Optional = true;
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Construction Stage Load Case", "CSLC", "The defined load case", 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 = "";
var constructionStage = new List<GH_ConstructionStage>();
int saveOptions = 0;
GH_Case gH_LoadCase = null;
if (!DA.GetData(0, ref name))
return;
if (!DA.GetDataList(1, constructionStage))
return;
DA.GetData(2, ref saveOptions);
DA.GetData(3, ref gH_LoadCase);
LoadCaseModel loadCaseModel = null;
if (gH_LoadCase != null)
{
if (gH_LoadCase.Value != null && gH_LoadCase.Value is LoadCaseModel lccc)
loadCaseModel = new LoadCaseModel(lccc);
else
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input case must be a load case");
return;
}
}
var stageConstructionLoadCaseModel = new StageConstructionLoadCaseModel(name)
{
StagedSaveOption = (StageConstructionLoadCaseModel.StagedSaveOptions)saveOptions,
InitialCase = gH_LoadCase != null ? loadCaseModel : null,
};
for (int i = 0; i < constructionStage.Count; i++)
stageConstructionLoadCaseModel.ConstructionStages.Add(constructionStage[i].Value);
Message = name;
DA.SetData(0, new GH_Case(stageConstructionLoadCaseModel));
}
public override GH_Exposure Exposure => GH_Exposure.senary;
protected override System.Drawing.Bitmap Icon => Properties.Resources.LoadCaseStageIcon;
public override Guid ComponentGuid => new("5caad23b-a9e1-43b1-9f74-5011caf71d89");
}
}