Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSAGH-561 contour legend in rhino is cropped #732

Merged
merged 58 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2a330e7
bugfix: added Legend, drawContour and TextWrapper class.
DominikaLos Nov 27, 2024
ec588cf
bugfix: little fix
DominikaLos Nov 28, 2024
2e4f791
bugfix: renaming Legend variables
DominikaLos Nov 28, 2024
91da2c7
bugfix: apply renaming
DominikaLos Nov 28, 2024
047ab28
bugfix: contour2d refactoring
DominikaLos Nov 28, 2024
9358352
bugfix: refactor DrawContour
DominikaLos Nov 28, 2024
eeace8c
bugfix: apply changes into contour3d
DominikaLos Nov 28, 2024
7758447
bugfix: refactor contour node results
DominikaLos Nov 28, 2024
47df405
bugfix: refactor AsemblyResults
DominikaLos Nov 28, 2024
099d771
bugfix: legend refactor
DominikaLos Nov 28, 2024
b2bc3a4
bugfix: apply refactoring for drawContour
DominikaLos Nov 28, 2024
1e2b5c5
bugfix: apply refactoring to contour node results
DominikaLos Nov 28, 2024
fe05341
bugfix: apply refactoring to contour 1d results
DominikaLos Nov 28, 2024
12d592b
bugfix: apply refactoring to assembly results
DominikaLos Nov 28, 2024
ad48523
bugfix: apply refactoring to contour2d results
DominikaLos Nov 28, 2024
a93230c
bugfix: apply refactoring to contour3d results
DominikaLos Nov 28, 2024
ed594d6
bugfix: init bitmap when creating legend object
DominikaLos Nov 28, 2024
7dfc454
bugfix: fix for wrapping : scaling extraOffset
DominikaLos Nov 28, 2024
fd5387e
bugfix: rename from DrawContour to DrawLegend
DominikaLos Nov 28, 2024
d0050c8
Merge branch 'main' into bugfix/GSAGH-561-Contour-legend-in-Rhino-is-…
DominikaLos Nov 28, 2024
ae19734
bugfix: refactoring, renaming and moved serialisation into Legend
DominikaLos Nov 29, 2024
8eae0b1
Merge branch 'bugfix/GSAGH-561-Contour-legend-in-Rhino-is-cropped' of…
DominikaLos Nov 29, 2024
9c2f14f
bugfix: moved adding "legend scale menu" into contour legend class
DominikaLos Dec 2, 2024
72bf66b
bugfix: cleanup
DominikaLos Dec 2, 2024
a7de34b
Merge branch 'main' into bugfix/GSAGH-561-Contour-legend-in-Rhino-is-…
DominikaLos Dec 2, 2024
5f0e33d
bugfix: removed unnecessary test
DominikaLos Dec 2, 2024
26fd07f
Merge branch 'main' into bugfix/GSAGH-561-Contour-legend-in-Rhino-is-…
DominikaLos Dec 2, 2024
42b8306
bugfix: clean-up
DominikaLos Dec 3, 2024
7b09ec7
bugfix: solved issue with tests. Provide default font name when rhino…
DominikaLos Dec 3, 2024
b3404fb
Merge branch 'bugfix/GSAGH-561-Contour-legend-in-Rhino-is-cropped' of…
DominikaLos Dec 3, 2024
96962f4
bugfix: xml fix
DominikaLos Dec 3, 2024
8172fa7
bugfix: removed unused _scaleLegendTxt
DominikaLos Dec 3, 2024
0c2b2f0
bugfix: refactor. added new classes. ContourLegendManager, and Legend…
DominikaLos Dec 3, 2024
786662f
bugfix: minor clean-up
DominikaLos Dec 3, 2024
8811ab3
bugfix: changed modifiers
DominikaLos Dec 4, 2024
fed2968
bugfix: added unit tests for contour legend configuration class
DominikaLos Dec 4, 2024
6e81595
bugfix: added Moq package to use it when testing serialisation
DominikaLos Dec 4, 2024
71a87ef
bugfix: added tests for legend menu builder class
DominikaLos Dec 4, 2024
b942f3f
bugfx: changes namespace for contour tests
DominikaLos Dec 4, 2024
7166b44
bugfix: unit tests for conour legend
DominikaLos Dec 4, 2024
01f16f6
bugfix: added unit tests for text wrapping
DominikaLos Dec 4, 2024
a059668
bugfix: removed useless variable
DominikaLos Dec 4, 2024
fe55a40
Merge branch 'main' into bugfix/GSAGH-561-Contour-legend-in-Rhino-is-…
DominikaLos Dec 4, 2024
0a0bb73
bugfix: removed useless test
DominikaLos Dec 5, 2024
23dfa8d
Merge branch 'bugfix/GSAGH-561-Contour-legend-in-Rhino-is-cropped' of…
DominikaLos Dec 5, 2024
6ed39cc
bugfix: added getScale method in manager, rename test
DominikaLos Dec 5, 2024
a08e315
bugfix: added tests for contourLegend class
DominikaLos Dec 5, 2024
a9e0b1b
bugfix: added test for textWrapper
DominikaLos Dec 5, 2024
0e0fbf4
bugfix: removed unused method
DominikaLos Dec 5, 2024
01cc160
refactor: ContourLegendConfiguration: removed bitmap, added builder m…
DominikaLos Dec 12, 2024
ca85142
refactor: updated tests
DominikaLos Dec 13, 2024
0f78424
refactor: removed useless DrawLegendMethod, update tests and components
DominikaLos Dec 13, 2024
1f6a6e6
refactor: extra test for contourLegend
DominikaLos Dec 13, 2024
1770740
refactor: fixed typos, renaming
DominikaLos Dec 18, 2024
473605b
Merge branch 'main' into bugfix/GSAGH-561-Contour-legend-in-Rhino-is-…
DominikaLos Dec 18, 2024
aee067a
refactor: renaming typos
DominikaLos Dec 19, 2024
fb883f9
refactor: rrenaming + updated text wrapping
DominikaLos Dec 19, 2024
6ad1a92
Merge branch 'main' into bugfix/GSAGH-561-Contour-legend-in-Rhino-is-…
DominikaLos Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 68 additions & 134 deletions GsaGH/Components/6_Display/AssemblyResults.cs

Large diffs are not rendered by default.

278 changes: 103 additions & 175 deletions GsaGH/Components/6_Display/Contour1dResults.cs
psarras marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

572 changes: 248 additions & 324 deletions GsaGH/Components/6_Display/Contour2dResults.cs

Large diffs are not rendered by default.

227 changes: 77 additions & 150 deletions GsaGH/Components/6_Display/Contour3dResults.cs

Large diffs are not rendered by default.

144 changes: 40 additions & 104 deletions GsaGH/Components/6_Display/ContourNodeResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

using GH_IO.Serialization;

using Grasshopper.GUI;
using Grasshopper.GUI.Gradient;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
Expand Down Expand Up @@ -38,7 +37,6 @@
using OasysUnits;
using OasysUnits.Units;

using Rhino.Display;
using Rhino.Geometry;

using AngleUnit = OasysUnits.Units.AngleUnit;
Expand Down Expand Up @@ -112,25 +110,22 @@ private enum FoldMode {
"SpringForce",
"Footfall",
});
private readonly ContourLegendManager _contourLegendManager = ContourLegendManager.GetDefault();
private string _case = string.Empty;
private double _defScale = 250;
private DisplayValue _disp = DisplayValue.ResXyz;
private ForceUnit _forceUnit = DefaultUnits.ForceUnit;
private Bitmap _legend = new Bitmap(15, 120);
private double _legendScale = 1;
private List<string> _legendValues;
private List<int> _legendValuesPosY;
private LengthUnit _lengthResultUnit = DefaultUnits.LengthUnitResult;
private double _maxValue = 1000;
private double _minValue;
private FoldMode _mode = FoldMode.Displacement;
private MomentUnit _momentUnit = DefaultUnits.MomentUnit;
private int _noDigits;
private string _resType;
private string _scaleLegendTxt = string.Empty;
private bool _showLegend = true;
private bool _slider = true;
private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute;
private List<(int startY, int endY, Color gradientColor)> _gradients
= new List<(int startY, int endY, Color gradientColor)>();

public ContourNodeResults() : base("Contour Node Results", "NodeContour",
"Diplays GSA Node Results as Contours", CategoryName.Name(), SubCategoryName.Cat6()) { }
Expand All @@ -140,32 +135,14 @@ 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) {
base.DrawViewportWires(args);
if (!((_legendValues != null) & _showLegend)) {
return;
}

int defaultTextHeight = 12;
args.Display.DrawBitmap(new DisplayBitmap(_legend),
args.Viewport.Bounds.Right - (int)(110 * _legendScale), (int)(20 * _legendScale));
for (int i = 0; i < _legendValues.Count; i++) {
args.Display.Draw2dText(_legendValues[i], Color.Black,
new Point2d(args.Viewport.Bounds.Right - (int)(85 * _legendScale), _legendValuesPosY[i]),
false, (int)(defaultTextHeight * _legendScale));
}

args.Display.Draw2dText(_resType, Color.Black,
new Point2d(args.Viewport.Bounds.Right - (int)(110 * _legendScale),
(int)(7 * _legendScale)), false, (int)(defaultTextHeight * _legendScale));
args.Display.Draw2dText(_case, Color.Black,
new Point2d(args.Viewport.Bounds.Right - (int)(110 * _legendScale),
(int)(145 * _legendScale)), false, (int)(defaultTextHeight * _legendScale));
_contourLegendManager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients);
}

public override bool Read(GH_IReader reader) {
Expand All @@ -176,20 +153,17 @@ public override bool Read(GH_IReader reader) {
_maxValue = reader.GetDouble("valMax");
_minValue = reader.GetDouble("valMin");
_defScale = reader.GetDouble("val");
if (reader.ItemExists("legendScale")) {
_legendScale = reader.GetDouble("legendScale");
}

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

_showLegend = reader.GetBoolean("legend");
_lengthResultUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("length"));
_forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), reader.GetString("force"));
_momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), reader.GetString("moment"));
_legend = new Bitmap((int)(15 * _legendScale), (int)(120 * _legendScale));

_contourLegendManager.DeserialiseLegendState(reader);

return base.Read(reader);
}

Expand Down Expand Up @@ -309,12 +283,13 @@ public override bool Write(GH_IWriter writer) {
writer.SetDouble("valMax", _maxValue);
writer.SetDouble("valMin", _minValue);
writer.SetDouble("val", _defScale);
writer.SetDouble("legendScale", _legendScale);
writer.SetBoolean("legend", _showLegend);
writer.SetString("length", Length.GetAbbreviation(_lengthResultUnit));
writer.SetString("force", Force.GetAbbreviation(_forceUnit));
writer.SetString("moment", Moment.GetAbbreviation(_momentUnit));
writer.SetString("envelope", _envelopeType.ToString());

_contourLegendManager.SerialiseLegendState(writer);

return base.Write(writer);
}

Expand All @@ -328,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, _showLegend);
Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendManager.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 All @@ -357,21 +331,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men

menu.Items.Add(unitsMenu);

var legendScale = new ToolStripTextBox {
Text = _legendScale.ToString(),
};
legendScale.TextChanged += (s, e) => MaintainScaleLegendText(legendScale);
var legendScaleMenu = new ToolStripMenuItem("Scale Legend") {
Enabled = true,
ImageScaling = ToolStripItemImageScaling.SizeToFit,
};
var menu2 = new GH_MenuCustomControl(legendScaleMenu.DropDown, legendScale.Control, true,
200);
legendScaleMenu.DropDownItems[1].MouseUp += (s, e) => {
UpdateLegendScale();
(this as IGH_VariableParameterComponent).VariableParameterMaintenance();
ExpireSolution(true);
};
ToolStripMenuItem legendScaleMenu = _contourLegendManager.CreateMenu(this, () => base.UpdateUI());
menu.Items.Add(legendScaleMenu);

Menu_AppendSeparator(menu);
Expand Down Expand Up @@ -436,21 +396,20 @@ 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);
}

protected override void SolveInternal(IGH_DataAccess da) {
GsaResult result;
_gradients = new List<(int startY, int endY, Color gradientColor)>();
string nodeList = "All";
_case = string.Empty;
_resType = string.Empty;
var ghTyp = new GH_ObjectWrapper();
da.GetData(0, ref ghTyp);
result = Inputs.GetResultInput(this, ghTyp);
GsaResult result = Inputs.GetResultInput(this, ghTyp);
if (result == null) {
return;
}
Expand Down Expand Up @@ -805,10 +764,9 @@ IEntity0dResultSubset<IReactionForce, ResultVector6<Entity0dExtremaKey>> springF
pts[kvp.Key] = new PointResultGoo(pt, t, valcol, size, kvp.Key);
});


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

var ts = new List<GH_UnitNumber>();
var cs = new List<Color>();
Expand All @@ -823,60 +781,56 @@ 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;
for (int y = starty; y < endy; y++) {
for (int x = 0; x < _legend.Width; x++) {
_legend.SetPixel(x, _legend.Height - y - 1, gradientcolour);
}
}
int startY = i * gripHeight;
int endY = startY + gripHeight;
_gradients.Add((startY, endY, gradientColor));

switch (_mode) {
case FoldMode.Displacement when (int)_disp < 4:
var displacement = new Length(t, _lengthResultUnit);
_legendValues.Add(displacement.ToString("f" + significantDigits));
legendValues.Add(displacement.ToString("f" + significantDigits));
ts.Add(new GH_UnitNumber(displacement));
break;

case FoldMode.Displacement:
var rotation = new Angle(t, AngleUnit.Radian);
_legendValues.Add(rotation.ToString("s" + significantDigits));
legendValues.Add(rotation.ToString("s" + significantDigits));
ts.Add(new GH_UnitNumber(rotation));
break;

case FoldMode.Reaction when (int)_disp < 4:
case FoldMode.SpringForce when (int)_disp < 4:
var reactionForce = new Force(t, _forceUnit);
_legendValues.Add(reactionForce.ToString("s" + significantDigits));
legendValues.Add(reactionForce.ToString("s" + significantDigits));
ts.Add(new GH_UnitNumber(reactionForce));
break;

case FoldMode.Reaction:
case FoldMode.SpringForce:
var reactionMoment = new Moment(t, _momentUnit);
_legendValues.Add(reactionMoment.ToString("s" + significantDigits));
legendValues.Add(reactionMoment.ToString("s" + significantDigits));
ts.Add(new GH_UnitNumber(reactionMoment));
break;

case FoldMode.Footfall:
var responseFactor = new Ratio(t, RatioUnit.DecimalFraction);
_legendValues.Add(responseFactor.ToString("s" + significantDigits));
legendValues.Add(responseFactor.ToString("s" + significantDigits));
ts.Add(new GH_UnitNumber(responseFactor));
break;
}

if (Math.Abs(t) > 1) {
_legendValues[i] = _legendValues[i]
.Replace(",", string.Empty); // remove thousand separator
legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator
}

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

_contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(_legendValuePositionsY);

da.SetDataList(0, pts.OrderBy(x => x.Key).Select(y => y.Value).ToList());
da.SetDataList(1, cs);
da.SetDataList(2, ts);
Expand All @@ -903,8 +857,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 @@ -956,7 +909,7 @@ private void ReDrawComponent() {
}

internal void ShowLegend(object sender, EventArgs e) {
_showLegend = !_showLegend;
_contourLegendManager.Configuration.ToggleLegendVisibility();
ExpirePreview(true);
}

Expand All @@ -983,22 +936,5 @@ internal void UpdateMoment(string unit) {
ExpirePreview(true);
base.UpdateUI();
}

internal void UpdateLegendScale() {
try {
_legendScale = double.Parse(_scaleLegendTxt);
} catch (Exception e) {
this.AddRuntimeWarning(e.Message);
return;
}

_legend = new Bitmap((int)(15 * _legendScale), (int)(120 * _legendScale));
ExpirePreview(true);
base.UpdateUI();
}

internal void MaintainScaleLegendText(ToolStripItem menuitem) {
_scaleLegendTxt = menuitem.Text;
}
}
}
Loading
Loading