Skip to content

Commit

Permalink
refactor: renaming typos
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaLos committed Dec 19, 2024
1 parent 473605b commit aee067a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 55 deletions.
14 changes: 7 additions & 7 deletions GsaGH/Components/6_Display/AssemblyResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ Parameters.Results.AssemblyForcesAndMoments forces
}
});

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

Expand All @@ -793,12 +793,12 @@ Parameters.Results.AssemblyForcesAndMoments forces
t = Math.Round(t, significantDigits);
}

Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientcolour);
Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientColor);

int starty = i * gripheight;
int endy = starty + gripheight;
_gradients.Add((starty, endy, gradientcolour));
int startY = i * gripHeight;
int endY = startY + gripHeight;
_gradients.Add((startY, endY, gradientColor));

switch (_mode) {
case FoldMode.Displacement when (int)_disp < 4:
Expand Down Expand Up @@ -843,7 +843,7 @@ Parameters.Results.AssemblyForcesAndMoments forces
legendValues[i] = legendValues[i].Replace(",", string.Empty);
}

legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2);
}

_contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);
Expand Down
14 changes: 7 additions & 7 deletions GsaGH/Components/6_Display/Contour1dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ IEntity0dResultCache<ISteelUtilisation, SteelUtilisationExtremaKeys> utilisation
}
}
});
int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount;
int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand All @@ -1044,12 +1044,12 @@ IEntity0dResultCache<ISteelUtilisation, SteelUtilisationExtremaKeys> utilisation
t = Math.Round(t, significantDigits);
}

Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientcolour);
Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientColor);

int starty = i * gripheight;
int endy = starty + gripheight;
_gradients.Add((starty, endy, gradientcolour));
int startY = i * gripHeight;
int endY = startY + gripHeight;
_gradients.Add((startY, endY, gradientColor));

switch (_mode) {
case FoldMode.Displacement when (int)_disp < 4:
Expand Down Expand Up @@ -1107,7 +1107,7 @@ IEntity0dResultCache<ISteelUtilisation, SteelUtilisationExtremaKeys> utilisation
legendValues[i] = legendValues[i].Replace(",", string.Empty);
}

legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2);
}

_contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);
Expand Down
14 changes: 7 additions & 7 deletions GsaGH/Components/6_Display/Contour2dResults.cs
Original file line number Diff line number Diff line change
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 = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount;
int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand All @@ -878,12 +878,12 @@ IEntity0dResultSubset<IFootfall, ResultFootfall<Entity0dExtremaKey>> nodeFootfal
t = Math.Round(t, significantDigits);
}

Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientcolour);
Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientColor);

int starty = i * gripheight;
int endy = starty + gripheight;
_gradients.Add((starty, endy, gradientcolour));
int startY = i * gripHeight;
int endY = startY + gripHeight;
_gradients.Add((startY, endY, gradientColor));

switch (_mode) {
case FoldMode.Displacement when (int)_disp < 4: {
Expand Down Expand Up @@ -932,7 +932,7 @@ IEntity0dResultSubset<IFootfall, ResultFootfall<Entity0dExtremaKey>> nodeFootfal
legendValues[i] = legendValues[i].Replace(",", string.Empty);
}

legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2);
}

_contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);
Expand Down
14 changes: 7 additions & 7 deletions GsaGH/Components/6_Display/Contour3dResults.cs
Original file line number Diff line number Diff line change
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 = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount;
int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount;
var legendValues = new List<string>();
var legendValuePositionsY = new List<int>();

Expand All @@ -591,12 +591,12 @@ IMeshResultSubset<IMeshQuantity<IStress>, IStress, ResultTensor3<Entity2dExtrema
t = Math.Round(t, significantDigits);
}

Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientcolour);
Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientColor);

int starty = i * gripheight;
int endy = starty + gripheight;
_gradients.Add((starty, endy, gradientcolour));
int startY = i * gripHeight;
int endY = startY + gripHeight;
_gradients.Add((startY, endY, gradientColor));

switch (_mode) {
case FoldMode.Displacement when (int)_disp < 4: {
Expand All @@ -623,7 +623,7 @@ IMeshResultSubset<IMeshQuantity<IStress>, IStress, ResultTensor3<Entity2dExtrema
legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator
}

legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2);
}

_contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY);
Expand Down
15 changes: 7 additions & 8 deletions GsaGH/Components/6_Display/ContourNodeResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ IEntity0dResultSubset<IReactionForce, ResultVector6<Entity0dExtremaKey>> springF
pts[kvp.Key] = new PointResultGoo(pt, t, valcol, size, kvp.Key);
});

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

Expand All @@ -781,13 +781,12 @@ IEntity0dResultSubset<IReactionForce, ResultVector6<Entity0dExtremaKey>> springF
t = Math.Round(t, significantDigits);
}

Color gradientcolour
= ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientcolour);
Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1);
cs.Add(gradientColor);

int starty = i * gripheight;
int endy = starty + gripheight;
_gradients.Add((starty, endy, gradientcolour));
int startY = i * gripHeight;
int endY = startY + gripHeight;
_gradients.Add((startY, endY, gradientColor));

switch (_mode) {
case FoldMode.Displacement when (int)_disp < 4:
Expand Down Expand Up @@ -827,7 +826,7 @@ Color gradientcolour
legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator
}

_legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2);
_legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2);
}

_contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(_legendValuePositionsY);
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Helpers/GH/Legend/ContourLegend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public int BitmapWidth {
get => _width;
set {
if (value <= 0) {
throw new ArgumentOutOfRangeException(nameof(_width), "Width must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(BitmapWidth), "Width must be greater than zero.");
}

_width = value;
Expand Down
6 changes: 3 additions & 3 deletions GsaGH/Helpers/GH/Legend/ContourLegendConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public double Scale {
get => _scale;
set {
if (value <= 0) {
throw new ArgumentOutOfRangeException(nameof(_scale), "Scale must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(Scale), "Scale must be greater than zero.");
}

_scale = value;
Expand All @@ -39,7 +39,7 @@ public int Width {
get => _width;
set {
if (value <= 0) {
throw new ArgumentOutOfRangeException(nameof(_width), "Width must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(Width), "Width must be greater than zero.");
}

_width = value;
Expand All @@ -49,7 +49,7 @@ public int Height {
get => _height;
set {
if (value <= 0) {
throw new ArgumentOutOfRangeException(nameof(_height), "Height must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(Height), "Height must be greater than zero.");
}

_height = value;
Expand Down
4 changes: 1 addition & 3 deletions GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public ToolStripMenuItem CreateLegendToolStripMenuItem(
ImageScaling = ToolStripItemImageScaling.SizeToFit,
};

var menuControl
= new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true,
200); // needed! don't remove
var menuControl = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, 200);

legendScaleMenuItem.DropDownItems[1].MouseUp += (s, e) => {
UpdateLegendScale(component, updateUI, setLegendScaleDelegate);
Expand Down
19 changes: 7 additions & 12 deletions GsaGH/Helpers/GH/TextWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
namespace GsaGH.Helpers.GH {

public static class TextWrapper {
private static Bitmap _bitmap = new Bitmap(1, 1);
private static System.Drawing.Graphics _graphics = System.Drawing.Graphics.FromImage(_bitmap);

/// <summary>
/// Wraps the given text to fit within the specified maximum width.
/// </summary>
Expand All @@ -17,10 +20,10 @@ public static string WrapText(string text, int maxWidth, Font font) {
}

string[] words = GetTextToWrap(text, out List<string> lines);
string currentLine = "";
string currentLine = string.Empty;
foreach (string word in words) {
string testLine = string.IsNullOrEmpty(currentLine) ? word : $"{currentLine} {word}";
float testLineWidth = CalculateTextWidth(testLine, font, maxWidth);
float testLineWidth = CalculateTextWidth(testLine, font);

if (testLineWidth > maxWidth) {
lines.Add(currentLine);
Expand Down Expand Up @@ -52,16 +55,8 @@ private static string[] GetTextToWrap(string text, out List<string> lines) {
return textToWrap.Split(' ');
}

/// <summary>
/// Gets the width of the given text from the cache or measures and caches it.
/// </summary>
/// <param name="text">The text to measure.</param>
/// <param name="font">Font used for rendering text</param>
/// <param name="maxWidth">Maximum possible width for text</param>
/// <returns>The width of the text in pixels.</returns>
private static float CalculateTextWidth(string text, Font font, int maxWidth) {
var graphics = System.Drawing.Graphics.FromImage(new Bitmap(maxWidth, 1)); //we care only about width
return graphics.MeasureString(text, font).Width;
private static float CalculateTextWidth(string text, Font font) {
return _graphics.MeasureString(text, font).Width;
}
}
}

0 comments on commit aee067a

Please sign in to comment.