Skip to content

Commit 33fe7b8

Browse files
committed
MERGE: viz settings merging mods
1 parent 698fdd2 commit 33fe7b8

File tree

5 files changed

+223
-26
lines changed

5 files changed

+223
-26
lines changed

deps/eigen

Submodule eigen updated from f91f8e9 to c5189ac

deps/pybind11

src/gh/components/DF_visualization_settings/code.py

Lines changed: 193 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,216 @@
11
#! python3
22

3+
import System
4+
import typing
35

46
import Rhino.Geometry as rg
5-
from ghpythonlib.componentbase import executingcomponent as component
67

8+
from ghpythonlib.componentbase import executingcomponent as component
9+
import Grasshopper as gh
10+
from Grasshopper import Instances
711
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
812

913
from diffCheck import df_visualization
1014

15+
16+
def add_str_valuelist(self,
17+
values_list: typing.List[str],
18+
nickname: str,
19+
indx: int,
20+
X_param_coord: float,
21+
Y_param_coord: float,
22+
X_offset: int=87
23+
) -> None:
24+
"""
25+
Adds a value list of string values to the component input
26+
27+
:param values_list: a list of string values to add to the value list
28+
:param nickname: the nickname of the value list
29+
:param indx: the index of the input parameter
30+
:param X_param_coord: the x coordinate of the input parameter
31+
:param Y_param_coord: the y coordinate of the input parameter
32+
:param X_offset: the offset of the value list from the input parameter
33+
"""
34+
param = ghenv.Component.Params.Input[indx] # noqa: F821
35+
if param.SourceCount == 0:
36+
valuelist = gh.Kernel.Special.GH_ValueList()
37+
valuelist.NickName = nickname
38+
valuelist.Description = "Select the value to use with DFVizSettings"
39+
selected = valuelist.FirstSelectedItem
40+
valuelist.ListItems.Clear()
41+
for v in values_list:
42+
vli = gh.Kernel.Special.GH_ValueListItem(str(v),str('"' + v + '"'))
43+
valuelist.ListItems.Add(vli)
44+
if selected in values_list:
45+
valuelist.SelectItem(values_list.index(selected))
46+
valuelist.CreateAttributes()
47+
valuelist.Attributes.Pivot = System.Drawing.PointF(
48+
X_param_coord - (valuelist.Attributes.Bounds.Width) - X_offset,
49+
Y_param_coord - (valuelist.Attributes.Bounds.Height / 2 + 0.1)
50+
)
51+
valuelist.Attributes.ExpireLayout()
52+
gh.Instances.ActiveCanvas.Document.AddObject(valuelist, False)
53+
ghenv.Component.Params.Input[indx].AddSource(valuelist) # noqa: F821
54+
55+
def add_slider(self,
56+
nickname: str,
57+
indx: int,
58+
lower_bound: float,
59+
upper_bound: float,
60+
default_value: float,
61+
X_param_coord: float,
62+
Y_param_coord: float,
63+
X_offset: int=100
64+
) -> None:
65+
"""
66+
Adds a slider to the component input
67+
68+
:param nickname: the nickname of the slider
69+
:param indx: the index of the input parameter
70+
:param X_param_coord: the x coordinate of the input parameter
71+
:param Y_param_coord: the y coordinate of the input parameter
72+
:param X_offset: the offset of the slider from the input parameter
73+
"""
74+
param = ghenv.Component.Params.Input[indx] # noqa: F821
75+
if param.SourceCount == 0:
76+
slider = gh.Kernel.Special.GH_NumberSlider()
77+
slider.NickName = nickname
78+
slider.Description = "Set the value for the threshold"
79+
slider.Slider.Minimum = System.Decimal(lower_bound)
80+
slider.Slider.Maximum = System.Decimal(upper_bound)
81+
slider.Slider.DecimalPlaces = 3
82+
slider.Slider.SmallChange = System.Decimal(0.001)
83+
slider.Slider.LargeChange = System.Decimal(0.01)
84+
slider.Slider.Value = System.Decimal(default_value)
85+
slider.CreateAttributes()
86+
slider.Attributes.Pivot = System.Drawing.PointF(
87+
X_param_coord - (slider.Attributes.Bounds.Width) - X_offset,
88+
Y_param_coord - (slider.Attributes.Bounds.Height / 2 - 0.1)
89+
)
90+
slider.Attributes.ExpireLayout()
91+
gh.Instances.ActiveCanvas.Document.AddObject(slider, False)
92+
ghenv.Component.Params.Input[indx].AddSource(slider) # noqa: F821
93+
94+
def add_plane_object(self,
95+
nickname: str,
96+
indx: int,
97+
X_param_coord: float,
98+
Y_param_coord: float,
99+
X_offset: int=75
100+
) -> None:
101+
"""
102+
Adds a plane object to the component input
103+
104+
:param nickname: the nickname of the plane object
105+
:param indx: the index of the input parameter
106+
:param X_param_coord: the x coordinate of the input parameter
107+
:param Y_param_coord: the y coordinate of the input parameter
108+
:param X_offset: the offset of the plane object from the input parameter
109+
"""
110+
param = ghenv.Component.Params.Input[indx] # noqa: F821
111+
if param.SourceCount == 0:
112+
doc = Instances.ActiveCanvas.Document
113+
if doc:
114+
plane = gh.Kernel.Parameters.Param_Plane()
115+
plane.NickName = nickname
116+
plane.CreateAttributes()
117+
plane.Attributes.Pivot = System.Drawing.PointF(
118+
X_param_coord - (plane.Attributes.Bounds.Width) - X_offset,
119+
Y_param_coord
120+
)
121+
plane.Attributes.ExpireLayout()
122+
doc.AddObject(plane, False)
123+
ghenv.Component.Params.Input[indx].AddSource(plane) # noqa: F821
124+
125+
11126
class DFVisualizationSettings(component):
127+
def __init__(self):
128+
self.poss_value_types = ["Dist", "RMSE", "MAX", "MIN", "STD"]
129+
self.poss_palettes = ["Jet", "Rainbow", "RdPu", "Viridis"]
130+
131+
ghenv.Component.ExpireSolution(True) # noqa: F821
132+
ghenv.Component.Attributes.PerformLayout() # noqa: F821
133+
params = getattr(ghenv.Component.Params, "Input") # noqa: F821
134+
for j in range(len(params)):
135+
Y_cord = params[j].Attributes.InputGrip.Y
136+
X_cord = params[j].Attributes.Pivot.X
137+
input_indx = j
138+
if "i_value_type" == params[j].NickName:
139+
add_str_valuelist(
140+
ghenv.Component, # noqa: F821
141+
self.poss_value_types,
142+
"DF_value_t",
143+
input_indx, X_cord, Y_cord)
144+
if "i_palette" == params[j].NickName:
145+
add_str_valuelist(
146+
ghenv.Component, # noqa: F821
147+
self.poss_palettes,
148+
"DF_palette",
149+
input_indx, X_cord, Y_cord)
150+
if "i_legend_height" == params[j].NickName:
151+
add_slider(
152+
ghenv.Component, # noqa: F821
153+
"DF_legend_height",
154+
input_indx,
155+
0.000, 20.000, 10.000,
156+
X_cord, Y_cord)
157+
if "i_legend_width" == params[j].NickName:
158+
add_slider(
159+
ghenv.Component, # noqa: F821
160+
"DF_legend_width",
161+
input_indx,
162+
0.000, 2.000, 0.500,
163+
X_cord, Y_cord)
164+
if "i_legend_plane" == params[j].NickName:
165+
add_plane_object(
166+
ghenv.Component, # noqa: F821
167+
"DF_legend_plane",
168+
input_indx, X_cord, Y_cord)
169+
if "i_histogram_scale_factor" == params[j].NickName:
170+
add_slider(
171+
ghenv.Component, # noqa: F821
172+
"DF_histogram_scale_factor",
173+
input_indx,
174+
0.000, 1.000, 0.01,
175+
X_cord, Y_cord)
176+
12177
def RunScript(self,
13178
i_value_type: str,
179+
i_palette: str,
14180
i_upper_threshold: float,
15181
i_lower_threshold: float,
16-
i_palette: str,
17182
i_legend_height: float,
18183
i_legend_width: float,
19184
i_legend_plane: rg.Plane,
20185
i_histogram_scale_factor: float):
21-
if i_palette not in ["Jet", "Rainbow", "RdPu", "Viridis"]:
22-
ghenv.Component.AddRuntimeMessage(RML.Warning, "Possible values for i_palette are: Jet, Rainbow, RdPu, Viridis") # noqa: F821
23-
return None
24186

25-
if i_value_type not in ["Dist", "RMSE", "MAX", "MIN", "STD"]:
26-
ghenv.Component.AddRuntimeMessage(RML.Warning, "Possible values for i_value_type are: dist, RMSE, MAX, MIN, STD") # noqa: F821
27-
return None
187+
"""
188+
Compiles all the visualization settings to feed to the visualization component
189+
190+
:param i_value_type: selected type indicates Which values to display. Possible values: "dist", "RMSE", "MAX", "MIN", "STD"
191+
:param i_palette: Select a color palette to map the values to. Possible values: "Jet", "Rainbow", "RdPu", "Viridis"
192+
:param i_upper_threshold: Thresholds the values with a maximum value
193+
:param i_lower_threshold: Thresholds the values with a minimum value
194+
:param i_legend_height: the total height of the legend
195+
:param i_legend_width: the total width of the legend
196+
:param i_legend_plane: the construction plane of the legend
197+
:param i_histogram_scale_factor: Scales the height of the histogram with a factor
28198
199+
:returns o_viz_settings: the results of the comparison all in one object
200+
"""
29201
# set default values
202+
if i_value_type is not None:
203+
if i_value_type not in self.poss_value_types:
204+
ghenv.Component.AddRuntimeMessage(RML.Warning, "Possible values for i_value_type are: dist, RMSE, MAX, MIN, STD") # noqa: F821
205+
return None
206+
else:
207+
i_value_type = "Dist"
208+
if i_palette is not None:
209+
if i_palette not in self.poss_palettes:
210+
ghenv.Component.AddRuntimeMessage(RML.Warning, "Possible values for i_palette are: Jet, Rainbow, RdPu, Viridis") # noqa: F821
211+
return None
212+
else:
213+
i_palette = "Jet"
30214
if i_legend_height is None:
31215
i_legend_height = 10
32216
if i_legend_width is None:
@@ -38,9 +222,9 @@ def RunScript(self,
38222

39223
# pack settings
40224
o_viz_settings = df_visualization.DFVizSettings(i_value_type,
225+
i_palette,
41226
i_upper_threshold,
42227
i_lower_threshold,
43-
i_palette,
44228
i_legend_height,
45229
i_legend_width,
46230
i_legend_plane,

src/gh/components/DF_visualization_settings/metadata.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
"sourceCount": 0,
2626
"typeHintID": "str"
2727
},
28+
{
29+
"name": "i_palette",
30+
"nickname": "i_palette",
31+
"description": "Select a color palette to map the values to",
32+
"optional": false,
33+
"allowTreeAccess": false,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "str"
39+
},
2840
{
2941
"name": "i_upper_threshold",
3042
"nickname": "i_upper_threshold",
@@ -49,18 +61,6 @@
4961
"sourceCount": 0,
5062
"typeHintID": "float"
5163
},
52-
{
53-
"name": "i_palette",
54-
"nickname": "i_palette",
55-
"description": "Select a color palette to map the values to",
56-
"optional": false,
57-
"allowTreeAccess": false,
58-
"showTypeHints": true,
59-
"scriptParamAccess": "item",
60-
"wireDisplay": "default",
61-
"sourceCount": 0,
62-
"typeHintID": "str"
63-
},
6464
{
6565
"name": "i_legend_height",
6666
"nickname": "i_legend_height",

src/gh/diffCheck/diffCheck/df_visualization.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,31 @@ class DFVizSettings:
1313
This class compiles the settings for the visualization into one object
1414
"""
1515

16-
def __init__(self, valueType, upper_threshold, lower_threshold, palette, legend_height, legend_width, legend_plane, histogram_scale_factor):
16+
def __init__(self,
17+
valueType,
18+
palette,
19+
upper_threshold,
20+
lower_threshold,
21+
legend_height,
22+
legend_width,
23+
legend_plane,
24+
histogram_scale_factor):
1725

1826
self.valueType = valueType
19-
27+
self.palette = df_visualization.DFColorMap(palette)
2028
self.upper_threshold = upper_threshold
2129
self.lower_threshold = lower_threshold
22-
self.palette = df_visualization.DFColorMap(palette)
2330
self.legend_height = legend_height
2431
self.legend_width = legend_width
2532
self.legend_plane = legend_plane
2633
self.histogram_scale_factor = histogram_scale_factor
2734

35+
self.str_repr = f"DFVizSettings: \n\t- Value type: {self.valueType}\n\t- Palette: {self.palette}\n\t- Upper threshold: {self.upper_threshold}\n\t- Lower threshold: {self.lower_threshold}\n\t- Legend height: {self.legend_height}\n\t- Legend width: {self.legend_width}\n\t- Legend plane: {self.legend_plane}\n\t- Histogram scale factor: {self.histogram_scale_factor}"
36+
37+
def __repr__(self):
38+
return self.str_repr
39+
def __str__(self):
40+
return self.str_repr
2841

2942
class DFColorMap:
3043
"""

0 commit comments

Comments
 (0)