Skip to content

Commit

Permalink
#1067 GlobalConfigurations dynamic GH comp (sqashed commit)
Browse files Browse the repository at this point in the history
commit a74c768
Author: lorinczandrea <[email protected]>
Date:   Fri Aug 30 15:06:41 2024 +0200

    :bug: error handling

    #1067

commit 09ed39e
Author: lorinczandrea <[email protected]>
Date:   Thu Aug 29 20:42:26 2024 +0200

    :construction: fix SetGlobalCfg

    #1067

    still testing

commit fa3d3fb
Author: lorinczandrea <[email protected]>
Date:   Wed Aug 28 19:59:54 2024 +0200

    :construction: dynamic GlobalConfig GH component

    #1067
    waiting for test
  • Loading branch information
lorinczandrea committed Aug 30, 2024
1 parent acb4136 commit c4be0e8
Show file tree
Hide file tree
Showing 21 changed files with 1,659 additions and 163 deletions.
721 changes: 608 additions & 113 deletions FemDesign.Core/Calculate/CmdGlobalCfg.cs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions FemDesign.Core/FemDesignConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ public void SetGlobalConfig(Calculate.CmdGlobalCfg cmdglobalconfig)
this.RunScript(script, "SetGlobalConfig");
}

/// <summary>
/// Set global settings for a FEM-Design model.
/// </summary>
/// <param name="globConfig">Can be any type of configuration from CmdGlobalCfg (e.g. MeshGeneral, MeshSettings, Meshfunctions, etc.). See the properties of Calculate.CmdGlobalCfg class.</param>
public void SetGlobalConfig(params Calculate.GlobConfig[] globConfig)
{
var cmd = new CmdGlobalCfg(globConfig);
this.SetGlobalConfig(cmd);
}

/// <summary>
/// Set global settings for a FEM-Design model using a global configuration file.
/// </summary>
Expand Down
34 changes: 33 additions & 1 deletion FemDesign.Core/GenericClasses/RestrictedDouble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ internal static double NonNegMax_1(double val)
return RestrictedDouble.ValueInClosedInterval(val, 0, 1);
}

/// <summary>
/// non_neg_max_5
/// </summary>
internal static double NonNegMax_5(double val)
{
return RestrictedDouble.ValueInClosedInterval(val, 0, 5);
}

/// <summary>
/// non_neg_max_10
/// </summary>
Expand All @@ -144,13 +152,21 @@ internal static double NonZeroMax_10_2(double val)
}

/// <summary>
/// non_neg_max_10
/// non_neg_max_20
/// </summary>
internal static double NonNegMax_20(double val)
{
return RestrictedDouble.ValueInClosedInterval(val, 0, 20);
}

/// <summary>
/// non_neg_max_90
/// </summary>
internal static double NonNegMax_90(double val)
{
return RestrictedDouble.ValueInClosedInterval(val, 0, 90);
}

/// <summary>
/// non_neg_max_100
/// </summary>
Expand Down Expand Up @@ -247,6 +263,22 @@ internal static double NonZeroMax_1e30(double val)
return RestrictedDouble.ValueInClosedInterval(val, 1E-5, 1E30);
}

/// <summary>
/// Check if val in range [90.0, 180.0]
/// </summary>
internal static double MeshMaxAngle(double val)
{
return RestrictedDouble.ValueInClosedInterval(val, 90, 180);
}

/// <summary>
/// Check if val in range [2.0, 500.0]
/// </summary>
internal static double MeshMaxRatio(double val)
{
return RestrictedDouble.ValueInClosedInterval(val, 2, 500);
}

/// <summary>
/// material_base_value
/// </summary>
Expand Down
18 changes: 17 additions & 1 deletion FemDesign.Core/GenericClasses/RestrictedInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ internal static int ValueInRange(int val, int min, int max)
}
else
{
throw new System.ArgumentOutOfRangeException($"Value should be between {min} and {max}");
throw new System.ArgumentOutOfRangeException($"Value should be between or equal to {min} and {max}");
}
}

/// <summary>
/// Check if val in range [1, 250]
/// </summary>
internal static int DefaultBarElemDiv(int val)
{
return RestrictedInteger.ValueInRange(val, 1, 250);
}

/// <summary>
/// Check if val in range [1, 50]
/// </summary>
internal static int MeshSmoothSteps(int val)
{
return RestrictedInteger.ValueInRange(val, 1, 50);
}

/// <summary>
/// timber_service_class
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Configs : GH_SwitcherComponent
protected override Bitmap Icon => FemDesign.Properties.Resources.Config;

public Configs()
: base("Config", "Config",
: base("Config", "Configuration",
"Calculation and design configurations",
CategoryName.Name(), SubCategoryName.Cat7a())
{
Expand All @@ -41,7 +41,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.RegisterParam(new Param_GenericObject(), "Config", "Config", "Config");
pManager.RegisterParam(new Param_GenericObject(), "Config", "Configuration", "Configurations.");
}

protected override void RegisterEvaluationUnits(EvaluationUnitManager mngr)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using Grasshopper.Kernel.Types;
using FemDesign.Grasshopper.Components.UIWidgets;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rhino.Geometry;
using FemDesign.Grasshopper;
using System.Windows.Forms;
using FemDesign.Grasshopper.Extension.ComponentExtension;
using FemDesign.Loads;
using Grasshopper.Kernel.Special;

namespace FemDesign.Grasshopper
{
public class GlobalConfigs : GH_SwitcherComponent
{
private List<SubComponent> _subcomponents = new List<SubComponent>();
public override string UnitMenuName => "GlobalConfigs";
protected override string DefaultEvaluationUnit => _subcomponents[1].name();
public override Guid ComponentGuid => new Guid("{41175D83-48B2-4614-A074-DC8BE7F71CAC}");
public override GH_Exposure Exposure => GH_Exposure.quinary;

protected override Bitmap Icon => FemDesign.Properties.Resources.Config;

public GlobalConfigs()
: base("GlobConfig", "GlobalConfigurations",
"General calculation settings for a FEM-Design model.",
CategoryName.Name(), SubCategoryName.Cat7a())
{
((GH_Component)this).Hidden = true;
}

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.RegisterParam(new Param_GenericObject(), "GlobConfig", "GlobalConfiguration", "Global configurations.");
}

protected override void RegisterEvaluationUnits(EvaluationUnitManager mngr)
{
//_subcomponents.Add(new SoilCalculationSettings());
_subcomponents.Add(new MeshGeneralSettings());
_subcomponents.Add(new MeshElementSettings());
_subcomponents.Add(new MeshFunctionSettings());
_subcomponents.Add(new MeshPrepareSettings());
_subcomponents.Add(new PeakSmMethodSettings());
_subcomponents.Add(new PeakSmAutoSettings());

foreach (SubComponent item in _subcomponents)
{
item.registerEvaluationUnits(mngr);
}
}

protected override void OnComponentLoaded()
{
base.OnComponentLoaded();
foreach (SubComponent item in _subcomponents)
{
item.OnComponentLoaded();
}
}

protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit)
{
if (unit == null)
{
return;
}
foreach (SubComponent item in _subcomponents)
{
if (unit.Name.Equals(item.name()))
{
item.SolveInstance(DA, out var msg, out var level);
if (msg != "")
{
((GH_ActiveObject)this).AddRuntimeMessage(level, msg);
}
return;
}
}
throw new Exception("Invalid sub-component");
}
// Part of the code that allows to extend the menu with additional items
// Right click on the component to see the options
public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
base.AppendAdditionalMenuItems(menu);
if (evalUnits.Units.Count > 0)
{
Menu_AppendSeparator(menu);
ToolStripMenuItem toolStripMenuItem = Menu_AppendItem(menu, "GlobConfigs");
foreach (EvaluationUnit unit in evalUnits.Units)
{
Menu_AppendItem(toolStripMenuItem.DropDown, unit.Name, Menu_ActivateUnit, null, true, unit.Active).Tag = unit;
}
Menu_AppendSeparator(menu);
}
}
private void Menu_ActivateUnit(object sender, EventArgs e)
{
try
{
EvaluationUnit evaluationUnit = (EvaluationUnit)((ToolStripMenuItem)sender).Tag;
if (evaluationUnit != null)
{
SwitchUnit(evaluationUnit);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using Grasshopper.Kernel.Types;
using FemDesign.Grasshopper.Components.UIWidgets;


namespace FemDesign.Grasshopper
{
public class MeshElementSettings : SubComponent
{
public override string name() => "MeshElementSettings";
public override string display_name() => "MeshElementSettings";

public override void registerEvaluationUnits(EvaluationUnitManager mngr)
{
EvaluationUnit evaluationUnit = new EvaluationUnit(name(), display_name(), "Finite element mesh elements settings. For more details, see the FEM-Design GUI > Settings > Calculation > Mesh.");
mngr.RegisterUnit(evaluationUnit);

evaluationUnit.RegisterInputParam(new Param_Number(), "Scale", "Scale", "Scale.", GH_ParamAccess.item);
evaluationUnit.Inputs[evaluationUnit.Inputs.Count - 1].Parameter.Optional = true;

evaluationUnit.RegisterInputParam(new Param_Boolean(), "Correct", "Correct", "Correct according to the minimum division numbers.\nDefault is True.", GH_ParamAccess.item);
evaluationUnit.Inputs[evaluationUnit.Inputs.Count - 1].Parameter.Optional = true;

evaluationUnit.RegisterInputParam(new Param_Boolean(), "RegionByRegion", "RegionByRegion", "Region by region.\nDefault is True. If false, the `Consider all regions together` option is set.", GH_ParamAccess.item);
evaluationUnit.Inputs[evaluationUnit.Inputs.Count - 1].Parameter.Optional = true;

evaluationUnit.RegisterInputParam(new Param_Integer(), "MinDivNumber", "MinDivNumber", "Lowest minimum division number.", GH_ParamAccess.item);
evaluationUnit.Inputs[evaluationUnit.Inputs.Count - 1].Parameter.Optional = true;

evaluationUnit.RegisterInputParam(new Param_Number(), "MaxCentralAngle", "MaxCentralAngle", "Maximal central angle for arcs.", GH_ParamAccess.item);
evaluationUnit.Inputs[evaluationUnit.Inputs.Count - 1].Parameter.Optional = true;


GH_ExtendableMenu gH_ExtendableMenu0 = new GH_ExtendableMenu(0, "");
gH_ExtendableMenu0.Name = "Calculated average element size";
gH_ExtendableMenu0.RegisterInputPlug(evaluationUnit.Inputs[0]);
gH_ExtendableMenu0.RegisterInputPlug(evaluationUnit.Inputs[1]);
gH_ExtendableMenu0.RegisterInputPlug(evaluationUnit.Inputs[2]);
evaluationUnit.AddMenu(gH_ExtendableMenu0);


GH_ExtendableMenu gH_ExtendableMenu1 = new GH_ExtendableMenu(1, "");
gH_ExtendableMenu1.Name = "Bar element";
gH_ExtendableMenu1.Expand();
gH_ExtendableMenu1.RegisterInputPlug(evaluationUnit.Inputs[3]);
gH_ExtendableMenu1.RegisterInputPlug(evaluationUnit.Inputs[4]);
evaluationUnit.AddMenu(gH_ExtendableMenu1);
}

public override void SolveInstance(IGH_DataAccess DA, out string msg, out GH_RuntimeMessageLevel level)
{
msg = "";
level = GH_RuntimeMessageLevel.Warning;

double scale = 6.0;
DA.GetData(0, ref scale);

bool correct = true;
DA.GetData(1, ref correct);

bool regByReg = true;
DA.GetData(2, ref regByReg);

int minDiv = 2;
DA.GetData(3, ref minDiv);

double angle = 10.00;
DA.GetData(4, ref angle);

var meshElem = new Calculate.MeshElements(regByReg, scale, correct, minDiv, angle);
DA.SetData(0, meshElem);
}

protected void setModelProps()
{
this.Parent_Component.ExpireSolution(true);
}
}
}
Loading

0 comments on commit c4be0e8

Please sign in to comment.