namespace FeMM.Grasshopper.Components.Parameters
{
/*
[SupportedOSPlatform("windows")]
public class FreedomCaseCombinationsParam : GH_PersistentParam<GH_Combination>
{
protected List<CaseModel> _freedomCases;
public List<CaseModel> LoadCaseList => _freedomCases;
public FreedomCaseCombinationsParam()
: base("Freedom Case Combinations", "LCS", "The Freedom Case definition", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_PARAMETERS)
{
_freedomCases = new List<CaseModel>();
}
public void UpdateLoadCases(IEnumerable<CaseModel> loadCases)
{
// Recreate the LoadCase names list
_freedomCases.Clear();
foreach (CaseModel loadCase in loadCases)
{
if (_freedomCases.Count(lc => lc.Name == loadCase.Name) == 0)
_freedomCases.Add(loadCase);
}
if (VolatileDataCount == 0)
return;
// Update the exiting combinations
bool changed = false;
List<GH_Combination> combinations = (List<GH_Combination>)VolatileData.get_Branch(0);
for (int i = 0; i < combinations.Count; i++)
{
GH_Combination combo = combinations[i];
// Remove the non existing values
CaseModel[] to_remove = combo.Value.Values.Where(v => !loadCases.Contains(v.Key)).Select(c => c.Key).ToArray();
for (int j = 0; j < to_remove.Length; j++)
{
CaseModel lc = to_remove[j];
combo.Value.Values.Remove(lc);
}
if (to_remove.Length > 0)
changed = true;
foreach (CaseModel loadCase in loadCases)
{
if (!combo.Value.Values.Keys.Contains(loadCase))
combo.Value.Values.Add(loadCase, 1);
}
}
if (changed)
{
PersistentData.Clear();
SetPersistentData(combinations);
ExpireSolution(true);
}
}
protected override GH_GetterResult Prompt_Plural(ref List<GH_Combination> values)
{
return GH_GetterResult.cancel;
}
protected override GH_GetterResult Prompt_Singular(ref GH_Combination value)
{
return GH_GetterResult.success;
}
public override void CreateAttributes()
{
m_attributes = new FreedomCaseCombinationsAttributes(this);
}
public override GH_Exposure Exposure => GH_Exposure.secondary;
public override Guid ComponentGuid => new Guid("7230f6d0-8033-44b0-bbf5-770353ebddf7");
protected override Bitmap Icon => Properties.Resources.LoadCombinationsParamIcon;
}
[SupportedOSPlatform("windows")]
internal class FreedomCaseCombinationsAttributes : GH_ResizableAttributes<FreedomCaseCombinationsParam>
{
private Rectangle _internalRect;
protected override Size MinimumSize => new Size(120, 60);
protected override Size MaximumSize { get { return new Size(730, 240); } }
protected override Padding SizingBorders { get { return new Padding(10); } }
public FreedomCaseCombinationsAttributes(FreedomCaseCombinationsParam owner)
: base(owner)
{
Bounds = new RectangleF(Pivot, new Size(150, 80));
}
protected override void Layout()
{
base.Layout();
_internalRect = GH_Convert.ToRectangle(Bounds);
_internalRect.Inflate(-5, -5);
}
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
if (channel == GH_CanvasChannel.Objects)
{
GH_Palette palette = GH_Palette.Normal;
// Adjust palette based on the Owner's worst case messaging level.
switch (Owner.RuntimeMessageLevel)
{
case GH_RuntimeMessageLevel.Warning:
palette = GH_Palette.Warning;
break;
case GH_RuntimeMessageLevel.Error:
palette = GH_Palette.Error;
break;
}
var capsuleBox = new RectangleF(Bounds.Location, Bounds.Size);
GH_Capsule capsule = GH_Capsule.CreateCapsule(capsuleBox, palette);
capsule.AddOutputGrip(OutputGrip.Y);
capsule.Render(graphics, Selected, Owner.Locked, false);
capsule.Dispose();
using (var pen = new Pen(Color.Black))
graphics.DrawRectangle(pen, _internalRect);
var format = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center,
Trimming = StringTrimming.EllipsisCharacter
};
RectangleF textRectangle = Bounds;
textRectangle.Y += 2;
textRectangle.Height = 20;
textRectangle.Inflate(-4, 0);
graphics.DrawString("Freedom Case Combinations", GH_FontServer.Standard, Brushes.Black, textRectangle, format);
if (!Owner.VolatileData.IsEmpty)
{
format.Alignment = StringAlignment.Near;
textRectangle.X += 2;
IList<GH_Combination> list = (IList<GH_Combination>)Owner.VolatileData.get_Branch(0);
for (int i = 0; i < list.Count; i++)
{
if (list[i] == null)
continue;
textRectangle.Y += 20;
if (textRectangle.Y + textRectangle.Height + 20 > Bounds.Y + Bounds.Height)
{
graphics.DrawString("etc.", GH_FontServer.Standard, Brushes.Black, textRectangle,
format);
break;
}
graphics.DrawString(list[i].ToString(), GH_FontServer.Standard, Brushes.Black, textRectangle,
format);
}
}
}
else
{
base.Render(canvas, graphics, channel);
}
}
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
{
if (e.Button == MouseButtons.Left)
{
List<GH_Combination> list = null;
if (!Owner.VolatileData.IsEmpty)
list = (List<GH_Combination>)Owner.VolatileData.get_Branch(0);
var form = new FreedomCaseCombinationsForm(Owner.LoadCaseList.ToArray(), list);
GH_WindowsFormUtil.CenterFormOnCursor(form, true);
if (form.ShowDialog(Instances.DocumentEditor) == DialogResult.OK)
{
Owner.PersistentData.Clear();
Owner.SetPersistentData(form.Values);
Owner.ExpireSolution(true);
}
return GH_ObjectResponse.Handled;
}
return base.RespondToMouseDoubleClick(sender, e);
}
}*/
}