Skip to content

Commit

Permalink
refactor: ContourLegendConfiguration: removed bitmap, added builder m…
Browse files Browse the repository at this point in the history
…ethods,. Legend: added bitmap, bitmapWidth, getFont, updated TextWrapper, removed interfaces, updated components
  • Loading branch information
DominikaLos committed Dec 12, 2024
1 parent 0e0fbf4 commit 01cc160
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 353 deletions.
13 changes: 6 additions & 7 deletions GsaGH/Components/6_Display/AssemblyResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private enum FoldMode {
private string _resType;
private bool _slider = true;
private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute;
private readonly ContourLegendManager _contourLegendMenager = new ContourLegendManager();
private static readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault();
private List<(int startY, int endY, Color gradientColor)> _gradients
= new List<(int startY, int endY, Color gradientColor)>();

Expand Down Expand Up @@ -314,7 +314,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men
ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope);
menu.Items.Add(envelopeMenu);

Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.IsLegendVisible);
Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible);

var gradient = new GH_GradientControl();
gradient.CreateAttributes();
Expand Down Expand Up @@ -776,7 +776,7 @@ Parameters.Results.AssemblyForcesAndMoments forces
}
});

int gripheight = _contourLegendMenager.GetBitmapSize().Height / ghGradient.GripCount;
int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand Down Expand Up @@ -843,11 +843,10 @@ Parameters.Results.AssemblyForcesAndMoments forces
legendValues[i] = legendValues[i].Replace(",", string.Empty);
}

legendValuePositionsY.Add(_contourLegendMenager.GetBitmapSize().Height - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
}

_contourLegendMenager.SetTextValues(legendValues);
_contourLegendMenager.SetPositionYValues(legendValuePositionsY);
_contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);

da.SetDataTree(0, resultLines);
da.SetDataList(1, cs);
Expand Down Expand Up @@ -927,7 +926,7 @@ private void ReDrawComponent() {
}

internal void ShowLegend(object sender, EventArgs e) {
_contourLegendMenager.ToggleVisibility();
_contourLegendMenager.Configuration.ToggleLegendVisibility();
ExpirePreview(true);
}

Expand Down
13 changes: 6 additions & 7 deletions GsaGH/Components/6_Display/Contour1dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private enum FoldMode {
private bool _slider = true;
private PressureUnit _stressUnit = DefaultUnits.StressUnitResult;
private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute;
private readonly ContourLegendManager _contourLegendMenager = new ContourLegendManager();
private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault();
private List<(int startY, int endY, Color gradientColor)> _gradients
= new List<(int startY, int endY, Color gradientColor)>();

Expand Down Expand Up @@ -420,7 +420,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men
ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope);
menu.Items.Add(envelopeMenu);

Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.IsLegendVisible);
Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible);

var gradient = new GH_GradientControl();
gradient.CreateAttributes();
Expand Down Expand Up @@ -1027,7 +1027,7 @@ IEntity0dResultCache<ISteelUtilisation, SteelUtilisationExtremaKeys> utilisation
}
}
});
int gripheight = _contourLegendMenager.GetBitmapSize().Height / ghGradient.GripCount;
int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand Down Expand Up @@ -1107,11 +1107,10 @@ IEntity0dResultCache<ISteelUtilisation, SteelUtilisationExtremaKeys> utilisation
legendValues[i] = legendValues[i].Replace(",", string.Empty);
}

legendValuePositionsY.Add(_contourLegendMenager.GetBitmapSize().Height - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
}

_contourLegendMenager.SetTextValues(legendValues);
_contourLegendMenager.SetPositionYValues(legendValuePositionsY);
_contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);

da.SetDataTree(0, resultLines);
da.SetDataList(1, cs);
Expand Down Expand Up @@ -1215,7 +1214,7 @@ private void ReDrawComponent() {
}

internal void ShowLegend(object sender, EventArgs e) {
_contourLegendMenager.ToggleVisibility();
_contourLegendMenager.Configuration.ToggleLegendVisibility();
ExpirePreview(true);
}

Expand Down
13 changes: 6 additions & 7 deletions GsaGH/Components/6_Display/Contour2dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private enum FoldMode {
private bool _slider = true;
private PressureUnit _stressUnitResult = DefaultUnits.StressUnitResult;
private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute;
private readonly ContourLegendManager _contourLegendMenager = new ContourLegendManager();
private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault();
private List<(int startY, int endY, Color gradientColor)> _gradients
= new List<(int startY, int endY, Color gradientColor)>();

Expand Down Expand Up @@ -407,7 +407,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men
ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope);
menu.Items.Add(envelopeMenu);

Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.IsLegendVisible);
Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible);

var gradient = new GH_GradientControl();
gradient.CreateAttributes();
Expand Down Expand Up @@ -861,7 +861,7 @@ IEntity0dResultSubset<IFootfall, ResultFootfall<Entity0dExtremaKey>> nodeFootfal
resultMeshes.AddRange(meshes.Values.ToList(), values.Values.ToList(), verticies.Values.ToList(),
meshes.Keys.ToList());

int gripheight = _contourLegendMenager.GetBitmapSize().Height / ghGradient.GripCount;
int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand Down Expand Up @@ -932,11 +932,10 @@ IEntity0dResultSubset<IFootfall, ResultFootfall<Entity0dExtremaKey>> nodeFootfal
legendValues[i] = legendValues[i].Replace(",", string.Empty);
}

legendValuePositionsY.Add(_contourLegendMenager.GetBitmapSize().Height - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
}

_contourLegendMenager.SetTextValues(legendValues);
_contourLegendMenager.SetPositionYValues(legendValuePositionsY);
_contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);

da.SetData(0, resultMeshes);
da.SetDataList(1, cs);
Expand Down Expand Up @@ -1028,7 +1027,7 @@ private void ReDrawComponent() {
}

internal void ShowLegend(object sender, EventArgs e) {
_contourLegendMenager.ToggleVisibility();
_contourLegendMenager.Configuration.ToggleLegendVisibility();
ExpirePreview(true);
}

Expand Down
13 changes: 6 additions & 7 deletions GsaGH/Components/6_Display/Contour3dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private enum FoldMode {
private bool _slider = true;
private PressureUnit _stressUnitResult = DefaultUnits.StressUnitResult;
private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute;
private readonly ContourLegendManager _contourLegendMenager = new ContourLegendManager();
private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault();
private List<(int startY, int endY, Color gradientColor)> _gradients
= new List<(int startY, int endY, Color gradientColor)>();

Expand Down Expand Up @@ -259,7 +259,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men
ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope);
menu.Items.Add(envelopeMenu);

Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.IsLegendVisible);
Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible);

var gradient = new GH_GradientControl();
gradient.CreateAttributes();
Expand Down Expand Up @@ -574,7 +574,7 @@ IMeshResultSubset<IMeshQuantity<IStress>, IStress, ResultTensor3<Entity2dExtrema
resultMeshes.AddRange(meshes.Values.ToList(), values.Values.ToList(), verticies.Values.ToList(),
meshes.Keys.ToList());

int gripheight = _contourLegendMenager.GetBitmapSize().Height / ghGradient.GripCount;
int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand Down Expand Up @@ -623,11 +623,10 @@ IMeshResultSubset<IMeshQuantity<IStress>, IStress, ResultTensor3<Entity2dExtrema
legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator
}

legendValuePositionsY.Add(_contourLegendMenager.GetBitmapSize().Height - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
}

_contourLegendMenager.SetTextValues(legendValues);
_contourLegendMenager.SetPositionYValues(legendValuePositionsY);
_contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);

da.SetData(0, resultMeshes);
da.SetDataList(1, cs);
Expand Down Expand Up @@ -683,7 +682,7 @@ private void ReDrawComponent() {
}

internal void ShowLegend(object sender, EventArgs e) {
_contourLegendMenager.ToggleVisibility();
_contourLegendMenager.Configuration.ToggleLegendVisibility();
ExpirePreview(true);
}

Expand Down
34 changes: 14 additions & 20 deletions GsaGH/Components/6_Display/ContourNodeResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private enum FoldMode {
private string _resType;
private bool _slider = true;
private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute;
private readonly ContourLegendManager _contourLegendMenager = new ContourLegendManager();
private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault();
private List<(int startY, int endY, Color gradientColor)> _gradients
= new List<(int startY, int endY, Color gradientColor)>();

Expand All @@ -135,9 +135,8 @@ public override void CreateAttributes() {
InitialiseDropdowns();
}

m_attributes = new DropDownSliderComponentAttributes(this, SetSelected, _dropDownItems,
_selectedItems, _slider, SetVal, SetMaxMin, _defScale, _maxValue, _minValue, _noDigits,
_spacerDescriptions);
m_attributes = new DropDownSliderComponentAttributes(this, SetSelected, _dropDownItems, _selectedItems, _slider,
SetVal, SetMaxMin, _defScale, _maxValue, _minValue, _noDigits, _spacerDescriptions);
}

public override void DrawViewportWires(IGH_PreviewArgs args) {
Expand All @@ -156,8 +155,7 @@ public override bool Read(GH_IReader reader) {
_defScale = reader.GetDouble("val");

if (reader.ItemExists("envelope")) {
_envelopeType = (EnvelopeMethod)Enum.Parse(
typeof(EnvelopeMethod), reader.GetString("envelope"));
_envelopeType = (EnvelopeMethod)Enum.Parse(typeof(EnvelopeMethod), reader.GetString("envelope"));
}

_lengthResultUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("length"));
Expand Down Expand Up @@ -305,19 +303,18 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men
ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope);
menu.Items.Add(envelopeMenu);

Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.IsLegendVisible);
Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible);

var gradient = new GH_GradientControl();
gradient.CreateAttributes();
var extract = new ToolStripMenuItem("Extract Default Gradient", gradient.Icon_24x24,
(s, e) => CreateGradient());
var extract = new ToolStripMenuItem("Extract Default Gradient", gradient.Icon_24x24, (s, e) => CreateGradient());
menu.Items.Add(extract);

ToolStripMenuItem lengthUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Displacement",
EngineeringUnits.Length, Length.GetAbbreviation(_lengthResultUnit), UpdateLength);

ToolStripMenuItem forceUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Force",
EngineeringUnits.Force, Force.GetAbbreviation(_forceUnit), UpdateForce);
ToolStripMenuItem forceUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Force", EngineeringUnits.Force,
Force.GetAbbreviation(_forceUnit), UpdateForce);

ToolStripMenuItem momentUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Moment",
EngineeringUnits.Moment, Moment.GetAbbreviation(_momentUnit), UpdateMoment);
Expand Down Expand Up @@ -399,8 +396,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
IQuantity length = new Length(0, _lengthResultUnit);
string lengthunitAbbreviation = string.Concat(length.ToString().Where(char.IsLetter));

pManager.AddGenericParameter("Result Point", "P", "Contoured Points with result values",
GH_ParamAccess.list);
pManager.AddGenericParameter("Result Point", "P", "Contoured Points with result values", GH_ParamAccess.list);
pManager.AddGenericParameter("Colours", "LC", "Legend Colours", GH_ParamAccess.list);
pManager.AddGenericParameter("Values [" + lengthunitAbbreviation + "]", "LT", "Legend Values",
GH_ParamAccess.list);
Expand Down Expand Up @@ -768,7 +764,7 @@ IEntity0dResultSubset<IReactionForce, ResultVector6<Entity0dExtremaKey>> springF
pts[kvp.Key] = new PointResultGoo(pt, t, valcol, size, kvp.Key);
});

int gripheight = _contourLegendMenager.GetBitmapSize().Height / ghGradient.GripCount;
int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var _legendValuePositionsY = new List<int>();

Expand Down Expand Up @@ -831,11 +827,10 @@ Color gradientcolour
legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator
}

_legendValuePositionsY.Add(_contourLegendMenager.GetBitmapSize().Height - starty + (gripheight / 2) - 2);
_legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
}

_contourLegendMenager.SetTextValues(legendValues);
_contourLegendMenager.SetPositionYValues(_legendValuePositionsY);
_contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(_legendValuePositionsY);

da.SetDataList(0, pts.OrderBy(x => x.Key).Select(y => y.Value).ToList());
da.SetDataList(1, cs);
Expand Down Expand Up @@ -863,8 +858,7 @@ internal GH_GradientControl CreateGradient(GH_Document doc = null) {
1,
});

gradient.Attributes.Pivot = new PointF(
Attributes.Bounds.X - gradient.Attributes.Bounds.Width - 50,
gradient.Attributes.Pivot = new PointF(Attributes.Bounds.X - gradient.Attributes.Bounds.Width - 50,
Params.Input[2].Attributes.Bounds.Y - (gradient.Attributes.Bounds.Height / 4) - 6);

doc.AddObject(gradient, false);
Expand Down Expand Up @@ -916,7 +910,7 @@ private void ReDrawComponent() {
}

internal void ShowLegend(object sender, EventArgs e) {
_contourLegendMenager.ToggleVisibility();
_contourLegendMenager.Configuration.ToggleLegendVisibility();
ExpirePreview(true);
}

Expand Down
Loading

0 comments on commit 01cc160

Please sign in to comment.