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;
namespace FeMM.Grasshopper.Components.Definitions
{
public class LoadCaseConstructionStageOperationComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the LoadCaseComponent class.
/// </summary>
public LoadCaseConstructionStageOperationComponent()
: base("Load Case Stage Op", "LCSO", "A load case stage operation definition", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_DEFINITIONS)
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
int i = pManager.AddIntegerParameter("Operation Code", "OC", "The operation code:\r\n" +
"1 = Add structure\r\n" +
"2 = Remove structure\r\n" +
"3 = Load objects if new\r\n" +
"4 = Load objects\r\n" +
"5 = Change section properties\r\n" +
"6 = Change section propertymodifiers\r\n" +
"7 = Change releases\r\n" +
"11 = Change section propertiesand age", GH_ParamAccess.item);
Param_Integer mtParam = pManager[i] as Param_Integer;
foreach (Enum en in Enum.GetValues(typeof(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)))
mtParam.AddNamedValue(en.GetDescription(), (int)(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)en);
i = pManager.AddIntegerParameter("Object type", "OT", "The object type associatedwith the specified operation: \r\n" +
"Group, Frame, Cable, Tendon, Area, Solid, Link, Point.\r\n" +
"The following list shows which object types are applicableto each operation type:\r\n" +
"Operation = 1 (Add structure): Allobject types\r\n" +
"Operation = 2 (Removestructure): All object types\r\n" +
"Operation = 3 (Load objectsif new): All object types\r\n" +
"Operation = 4 (Load objects): Allobject types\r\n" +
"Operation = 5 (Changesection properties): All object types except Point\r\n" +
"Operation = 6 (Changesection property modifiers): Group, Frame, Cable, Area\r\n" +
"Operation = 7 (Change releases): Group,Frame\r\n" +
"Operation = 11 (Change sectionproperties and age): All object types except Point", GH_ParamAccess.item, 0);
mtParam = pManager[i] as Param_Integer;
foreach (Enum en in Enum.GetValues(typeof(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)))
mtParam.AddNamedValue(en.GetDescription(), (int)(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)en);
pManager.AddTextParameter("Object name", "ON", "the name of the objectassociated with the specified operation.\r\n" +
"This is the name of a Group,Frame object, Cable object, Tendon object, Area object, Solid object,Link object or Point object, depending on the ObjectType item", GH_ParamAccess.item, "");
pManager.AddNumberParameter("Age", "A", "The age of the addedstructure, at the time it is added, in days. This item applies only tooperations with Operation = 1", GH_ParamAccess.item, 0);
pManager[pManager.ParamCount - 1].Optional = true;
i = pManager.AddIntegerParameter("Type", "T", "The includes a load type or an objecttype, depending on what is specified for the Operation item.\r\n" +
"This itemapplies only to operations with Operation = 3, 4, 5, 6, 7, or 11.\r\n" +
"When Operation = 3 or 4, this is an array that includesLoad or Accel, indicating the load type of an added load.\r\n" +
"When Operation = 5 or 11, and the ObjectType item isGroup, this is an array that includes Frame, Cable, Tendon, Area, Solidor Link, indicating the object type for which the section property ischanged.\r\n" +
"When Operation = 6 and the ObjectType item is Group,this is an array that includes Frame, Cable or Area, indicating the objecttype for which the section property modifiers are changed.\r\n" +
"When Operation = 7 and the ObjectType item is Group,this is an array that includes Frame, indicating the object type for whichthe releases are changed.\r\n" +
"When Operation = 5, 6, 7, or 11, and the ObjectTypeitem is not Group and not Point, this item is ignored and the type ispicked up from the ObjectType item.", GH_ParamAccess.item);
pManager[pManager.ParamCount - 1].Optional = true;
mtParam = pManager[i] as Param_Integer;
foreach (Enum en in Enum.GetValues(typeof(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)))
mtParam.AddNamedValue(en.GetDescription(), (int)(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)en);
pManager.AddTextParameter("Name", "N", "includes a load assignment oran object name, depending on what is specified for the Operation item." +
"This item applies only to operations with Operation = 3, 4, 5, 6,7 or 11.\r\n" +
"When Operation = 3 or 4, this is an array that includesthe name of the load assigned to the operation. If the associated LoadTypeitem is Load, this item is the name of a defined load pattern. " +
"If theassociated LoadType item is Accel, this item is UX, UY, UZ, RX, RY orRZ, indicating the direction of the load.\r\n" +
"When Operation = 5 or 11, this is the name of a Frame,Cable, Tendon, Area, Solid or Link object, depending on the object typespecified.\r\n" +
"When Operation = 6, this is the name of a Frame, Cableor Area object, depending on the object type specified.\r\n" +
"When Operation = 7, this is the name of a Frame object.", GH_ParamAccess.item, "");
pManager[pManager.ParamCount - 1].Optional = true;
pManager.AddNumberParameter("Scale Factor", "SF", "The scale factor forthe load assigned to the operation, if any. [L/s2]for Accel UX UY and UZ; otherwise unitless\r\n" +
"This item applies only to operations with Operation= 3 or 4.", GH_ParamAccess.item, 1);
pManager[pManager.ParamCount - 1].Optional = true;
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Load Case Stage Operation", "LCSO", "The defined load case stage operation", 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)
{
int operationCode = -1;
int objectType = -1;
string objectName = "";
double age = 0;
int type = 0;
string name = "";
double scaleFactor = 1;
if (!DA.GetData(0, ref operationCode))
return;
if (!DA.GetData(1, ref objectType))
return;
if (!DA.GetData(2, ref objectName))
return;
DA.GetData(3, ref age);
DA.GetData(4, ref type);
DA.GetData(5, ref name);
DA.GetData(6, ref scaleFactor);
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionProperties ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionPropertiesAndAge)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Point)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Object type cannot be apply to selected Operation");
}
}
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionPropertyModifiers)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Group &&
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Frame &&
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Cable &&
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Area)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Object type cannot be apply to selected Operation");
}
}
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeReleases)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Group &&
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Frame)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Object type cannot be apply to selected Operation");
}
}
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.LoadObjects ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.LoadObjectsIfNew ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionProperties ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionPropertyModifiers ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeReleases ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionPropertiesAndAge)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.LoadObjects ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.LoadObjectsIfNew)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.LoadCase &&
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.Acceleration)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Type cannot be apply to selected Operation");
}
}
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionProperties ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionPropertiesAndAge)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Group)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.LoadCase ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.Acceleration)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Type cannot be apply to selected Operation");
}
}
}
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeSectionPropertyModifiers)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Group)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.LoadCase ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.Acceleration ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.Solid ||
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.Tendon)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Type cannot be apply to selected Operation");
}
}
}
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes.ChangeReleases)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType == StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes.Group)
{
if ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type != StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes.Frame)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Type cannot be apply to selected Operation");
}
}
}
}
var operation = new StageConstructionLoadCaseModel.ConstructionStage.OperationModel(
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode,
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.ObjectTypes)objectType, objectName, age,
(StageConstructionLoadCaseModel.ConstructionStage.OperationModel.TypeCodes)type, name, scaleFactor);
Message = ((StageConstructionLoadCaseModel.ConstructionStage.OperationModel.Codes)operationCode).ToString();
DA.SetData(0, new GH_StageConstructionOperation(operation));
}
public override GH_Exposure Exposure => GH_Exposure.quarternary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.StagedConstructionOperationIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("8233fe68-b2a8-4f00-a031-da1ec2823fe1");
}
}