11#! python3
22
3- import System
4- import typing
53import Rhino
64from ghpythonlib .componentbase import executingcomponent as component
7- import Grasshopper as gh
8- from Grasshopper import Instances
95from Grasshopper .Kernel import GH_RuntimeMessageLevel as RML
106
117from diffCheck import df_visualization
12-
13-
14- def add_str_valuelist (self ,
15- values_list : typing .List [str ],
16- nickname : str ,
17- indx : int ,
18- X_param_coord : float ,
19- Y_param_coord : float ,
20- X_offset : int = 87
21- ) -> None :
22- """
23- Adds a value list of string values to the component input
24-
25- :param values_list: a list of string values to add to the value list
26- :param nickname: the nickname of the value list
27- :param indx: the index of the input parameter
28- :param X_param_coord: the x coordinate of the input parameter
29- :param Y_param_coord: the y coordinate of the input parameter
30- :param X_offset: the offset of the value list from the input parameter
31- """
32- param = ghenv .Component .Params .Input [indx ] # noqa: F821
33- if param .SourceCount == 0 :
34- valuelist = gh .Kernel .Special .GH_ValueList ()
35- valuelist .NickName = nickname
36- valuelist .Description = "Select the value to use with DFVizSettings"
37- selected = valuelist .FirstSelectedItem
38- valuelist .ListItems .Clear ()
39- for v in values_list :
40- vli = gh .Kernel .Special .GH_ValueListItem (str (v ),str ('"' + v + '"' ))
41- valuelist .ListItems .Add (vli )
42- if selected in values_list :
43- valuelist .SelectItem (values_list .index (selected ))
44- valuelist .CreateAttributes ()
45- valuelist .Attributes .Pivot = System .Drawing .PointF (
46- X_param_coord - (valuelist .Attributes .Bounds .Width ) - X_offset ,
47- Y_param_coord - (valuelist .Attributes .Bounds .Height / 2 + 0.1 )
48- )
49- valuelist .Attributes .ExpireLayout ()
50- gh .Instances .ActiveCanvas .Document .AddObject (valuelist , False )
51- ghenv .Component .Params .Input [indx ].AddSource (valuelist ) # noqa: F821
52-
53- def add_slider (self ,
54- nickname : str ,
55- indx : int ,
56- lower_bound : float ,
57- upper_bound : float ,
58- default_value : float ,
59- X_param_coord : float ,
60- Y_param_coord : float ,
61- X_offset : int = 100
62- ) -> None :
63- """
64- Adds a slider to the component input
65-
66- :param nickname: the nickname of the slider
67- :param indx: the index of the input parameter
68- :param X_param_coord: the x coordinate of the input parameter
69- :param Y_param_coord: the y coordinate of the input parameter
70- :param X_offset: the offset of the slider from the input parameter
71- """
72- param = ghenv .Component .Params .Input [indx ] # noqa: F821
73- if param .SourceCount == 0 :
74- slider = gh .Kernel .Special .GH_NumberSlider ()
75- slider .NickName = nickname
76- slider .Description = "Set the value for the threshold"
77- slider .Slider .Minimum = System .Decimal (lower_bound )
78- slider .Slider .Maximum = System .Decimal (upper_bound )
79- slider .Slider .DecimalPlaces = 3
80- slider .Slider .SmallChange = System .Decimal (0.001 )
81- slider .Slider .LargeChange = System .Decimal (0.01 )
82- slider .Slider .Value = System .Decimal (default_value )
83- slider .CreateAttributes ()
84- slider .Attributes .Pivot = System .Drawing .PointF (
85- X_param_coord - (slider .Attributes .Bounds .Width ) - X_offset ,
86- Y_param_coord - (slider .Attributes .Bounds .Height / 2 - 0.1 )
87- )
88- slider .Attributes .ExpireLayout ()
89- gh .Instances .ActiveCanvas .Document .AddObject (slider , False )
90- ghenv .Component .Params .Input [indx ].AddSource (slider ) # noqa: F821
91-
92- def add_plane_object (self ,
93- nickname : str ,
94- indx : int ,
95- X_param_coord : float ,
96- Y_param_coord : float ,
97- X_offset : int = 75
98- ) -> None :
99- """
100- Adds a plane object to the component input
101-
102- :param nickname: the nickname of the plane object
103- :param indx: the index of the input parameter
104- :param X_param_coord: the x coordinate of the input parameter
105- :param Y_param_coord: the y coordinate of the input parameter
106- :param X_offset: the offset of the plane object from the input parameter
107- """
108- param = ghenv .Component .Params .Input [indx ] # noqa: F821
109- if param .SourceCount == 0 :
110- doc = Instances .ActiveCanvas .Document
111- if doc :
112- plane = gh .Kernel .Parameters .Param_Plane ()
113- plane .NickName = nickname
114- plane .CreateAttributes ()
115- plane .Attributes .Pivot = System .Drawing .PointF (
116- X_param_coord - (plane .Attributes .Bounds .Width ) - X_offset ,
117- Y_param_coord
118- )
119- plane .Attributes .ExpireLayout ()
120- doc .AddObject (plane , False )
121- ghenv .Component .Params .Input [indx ].AddSource (plane ) # noqa: F821
8+ from diffCheck import df_gh_canvas
1229
12310
12411class DFVisualizationSettings (component ):
@@ -129,43 +16,44 @@ def __init__(self):
12916 ghenv .Component .ExpireSolution (True ) # noqa: F821
13017 ghenv .Component .Attributes .PerformLayout () # noqa: F821
13118 params = getattr (ghenv .Component .Params , "Input" ) # noqa: F821
19+
13220 for j in range (len (params )):
13321 Y_cord = params [j ].Attributes .InputGrip .Y
13422 X_cord = params [j ].Attributes .Pivot .X
13523 input_indx = j
13624 if "i_value_type" == params [j ].NickName :
137- add_str_valuelist (
25+ df_gh_canvas . add_str_valuelist (
13826 ghenv .Component , # noqa: F821
13927 self .poss_value_types ,
14028 "DF_value_t" ,
14129 input_indx , X_cord , Y_cord )
14230 if "i_palette" == params [j ].NickName :
143- add_str_valuelist (
31+ df_gh_canvas . add_str_valuelist (
14432 ghenv .Component , # noqa: F821
14533 self .poss_palettes ,
14634 "DF_palette" ,
14735 input_indx , X_cord , Y_cord )
14836 if "i_legend_height" == params [j ].NickName :
149- add_slider (
37+ df_gh_canvas . add_slider (
15038 ghenv .Component , # noqa: F821
15139 "DF_legend_height" ,
15240 input_indx ,
15341 0.000 , 20.000 , 10.000 ,
15442 X_cord , Y_cord )
15543 if "i_legend_width" == params [j ].NickName :
156- add_slider (
44+ df_gh_canvas . add_slider (
15745 ghenv .Component , # noqa: F821
15846 "DF_legend_width" ,
15947 input_indx ,
16048 0.000 , 2.000 , 0.500 ,
16149 X_cord , Y_cord )
16250 if "i_legend_plane" == params [j ].NickName :
163- add_plane_object (
51+ df_gh_canvas . add_plane_object (
16452 ghenv .Component , # noqa: F821
16553 "DF_legend_plane" ,
16654 input_indx , X_cord , Y_cord )
16755 if "i_histogram_scale_factor" == params [j ].NickName :
168- add_slider (
56+ df_gh_canvas . add_slider (
16957 ghenv .Component , # noqa: F821
17058 "DF_histogram_scale_factor" ,
17159 input_indx ,
0 commit comments