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.ElementProperties
{
public class BeamNonPrismaticPropertyComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the BeamReleasesComponent class.
/// </summary>
public BeamNonPrismaticPropertyComponent()
: base("Beam Non Prismatic Property", "NPP", "Non Prismatic Section Property (only for SAP)", 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", "The name of the non prismatic section", GH_ParamAccess.item);
pManager.AddGenericParameter("i-end Section", "SS", "The names of the frame section properties at the start of segment", GH_ParamAccess.item);
pManager.AddGenericParameter("j-end Section", "ES", "The names of the frame section properties at the end of segment", GH_ParamAccess.item);
pManager.AddGenericParameter("Material", "M", "Material", GH_ParamAccess.item);
pManager.AddNumberParameter("Length", "L", "Includes the length", GH_ParamAccess.item, 0.5);
pManager.AddIntegerParameter("LengthType", "LT", "The length type", GH_ParamAccess.item, 0);
Param_Integer type_param = (Param_Integer)pManager[pManager.ParamCount - 1];
foreach (Enum code in Enum.GetValues(typeof(BeamNonPrismaticPropertyModel.LengthTypes)))
type_param.AddNamedValue(code.GetDescription(), (int)(BeamNonPrismaticPropertyModel.LengthTypes)code);
pManager.AddIntegerParameter("EI33 Variation", "EI33", "Indicating the variation type for EI33", GH_ParamAccess.item, 2);
type_param = (Param_Integer)pManager[pManager.ParamCount - 1];
foreach (Enum code in Enum.GetValues(typeof(BeamNonPrismaticPropertyModel.InertiaTypes)))
type_param.AddNamedValue(code.GetDescription(), (int)(BeamNonPrismaticPropertyModel.InertiaTypes)code);
pManager.AddIntegerParameter("EI22 Variation", "EI22", "Indicating the variation type for EI22", GH_ParamAccess.item, 0);
type_param = (Param_Integer)pManager[pManager.ParamCount - 1];
foreach (Enum code in Enum.GetValues(typeof(BeamNonPrismaticPropertyModel.InertiaTypes)))
type_param.AddNamedValue(code.GetDescription(), (int)(BeamNonPrismaticPropertyModel.InertiaTypes)code);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Property", "P", "Beam 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 = null;
GH_BeamSection startSection = null;
GH_BeamSection endSection = null;
GH_Material material = null;
double length = 0;
int lengthType = 0;
int inertia33Type = 0;
int inertia22Type = 0;
if (!DA.GetData(0, ref name))
return;
if (!DA.GetData(1, ref startSection))
return;
if (!DA.GetData(2, ref endSection))
return;
if (!DA.GetData(3, ref material))
return;
if (!DA.GetData(4, ref length))
return;
if (!DA.GetData(5, ref lengthType))
return;
if (!DA.GetData(6, ref inertia33Type))
return;
if (!DA.GetData(7, ref inertia22Type))
return;
var sectionModelStart = new SectionModel();
if (startSection.SectionType != SectionModel.SectionTypes.Generic)
{
sectionModelStart.SectionType = startSection.SectionType;
sectionModelStart.D = startSection.D;
sectionModelStart.B = startSection.B;
sectionModelStart.B1 = startSection.B1;
sectionModelStart.B2 = startSection.B2;
sectionModelStart.L = startSection.L;
sectionModelStart.T = startSection.T;
sectionModelStart.T1 = startSection.T1;
sectionModelStart.T2 = startSection.T2;
sectionModelStart.T3 = startSection.T3;
sectionModelStart.Mirror = startSection.MirrorType;
sectionModelStart.MirrorGapA = startSection.MirrorGapA;
sectionModelStart.MirrorGapB = startSection.MirrorGapB;
sectionModelStart.GenericShapes = startSection.GenericShapes;
sectionModelStart.CalculateSection();
if (startSection.IsDBSection)
{
sectionModelStart.SectionArea = startSection.SectionArea;
sectionModelStart.I11 = startSection.I11;
sectionModelStart.I22 = startSection.I22;
sectionModelStart.J = startSection.J;
sectionModelStart.ShearL1 = startSection.SL1;
sectionModelStart.ShearL2 = startSection.SL2;
sectionModelStart.ShearA1 = startSection.SA1;
sectionModelStart.ShearA2 = startSection.SA2;
sectionModelStart.W11 = startSection.W11;
sectionModelStart.W22 = startSection.W22;
sectionModelStart.Centroid = startSection.Centroid;
sectionModelStart.AngleX1Rad = startSection.AngleX1;
}
}
else
{
sectionModelStart.SectionType = SectionModel.SectionTypes.Generic;
sectionModelStart.SectionArea = startSection.SectionArea;
sectionModelStart.I11 = startSection.I11;
sectionModelStart.I22 = startSection.I22;
sectionModelStart.J = startSection.J;
sectionModelStart.ShearL1 = startSection.SL1;
sectionModelStart.ShearL2 = startSection.SL2;
sectionModelStart.ShearA1 = startSection.SA1;
sectionModelStart.ShearA2 = startSection.SA2;
sectionModelStart.W11 = startSection.W11;
sectionModelStart.W22 = startSection.W22;
sectionModelStart.Centroid = startSection.Centroid;
sectionModelStart.AngleX1Rad = startSection.AngleX1;
};
var sectionModelEnd = new SectionModel();
if (sectionModelEnd.SectionType != SectionModel.SectionTypes.Generic)
{
sectionModelEnd.SectionType = endSection.SectionType;
sectionModelEnd.D = endSection.D;
sectionModelEnd.B = endSection.B;
sectionModelEnd.B1 = endSection.B1;
sectionModelEnd.B2 = endSection.B2;
sectionModelEnd.L = endSection.L;
sectionModelEnd.T = endSection.T;
sectionModelEnd.T1 = endSection.T1;
sectionModelEnd.T2 = endSection.T2;
sectionModelEnd.T3 = endSection.T3;
sectionModelEnd.Mirror = endSection.MirrorType;
sectionModelEnd.MirrorGapA = endSection.MirrorGapA;
sectionModelEnd.MirrorGapB = endSection.MirrorGapB;
sectionModelEnd.GenericShapes = endSection.GenericShapes;
sectionModelEnd.CalculateSection();
if (endSection.IsDBSection)
{
sectionModelEnd.SectionArea = endSection.SectionArea;
sectionModelEnd.I11 = endSection.I11;
sectionModelEnd.I22 = endSection.I22;
sectionModelEnd.J = endSection.J;
sectionModelEnd.ShearL1 = endSection.SL1;
sectionModelEnd.ShearL2 = endSection.SL2;
sectionModelEnd.ShearA1 = endSection.SA1;
sectionModelEnd.ShearA2 = endSection.SA2;
sectionModelEnd.W11 = endSection.W11;
sectionModelEnd.W22 = endSection.W22;
sectionModelEnd.Centroid = endSection.Centroid;
sectionModelEnd.AngleX1Rad = endSection.AngleX1;
}
}
else
{
sectionModelEnd.SectionType = SectionModel.SectionTypes.Generic;
sectionModelEnd.SectionArea = endSection.SectionArea;
sectionModelEnd.I11 = endSection.I11;
sectionModelEnd.I22 = endSection.I22;
sectionModelEnd.J = endSection.J;
sectionModelEnd.ShearL1 = endSection.SL1;
sectionModelEnd.ShearL2 = endSection.SL2;
sectionModelEnd.ShearA1 = endSection.SA1;
sectionModelEnd.ShearA2 = endSection.SA2;
sectionModelEnd.W11 = endSection.W11;
sectionModelEnd.W22 = endSection.W22;
sectionModelEnd.Centroid = endSection.Centroid;
sectionModelEnd.AngleX1Rad = endSection.AngleX1;
};
var model = new BeamNonPrismaticPropertyModel()
{
Name = name,
Section = sectionModelStart,
EndSection = sectionModelEnd,
Material = material.Value,
Length = length,
LengthType = (BeamNonPrismaticPropertyModel.LengthTypes)lengthType,
Inertia33Type = (BeamNonPrismaticPropertyModel.InertiaTypes)inertia33Type,
Inertia22Type = (BeamNonPrismaticPropertyModel.InertiaTypes)inertia22Type,
};
var gh_bp = new GH_FunctionDefinition(model);
DA.SetData(0, gh_bp);
}
public override GH_Exposure Exposure => GH_Exposure.primary;
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => Properties.Resources.BeamNonPrismaticSectionIcon;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid => new("4d3f7a2a-69de-47df-9323-ed4b57ff1910");
}
}