1
1
#! python3
2
2
3
- import System
4
- import typing
5
3
import Rhino
6
4
from ghpythonlib .componentbase import executingcomponent as component
7
- import Grasshopper as gh
8
- from Grasshopper import Instances
9
5
from Grasshopper .Kernel import GH_RuntimeMessageLevel as RML
10
6
11
7
from 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
122
9
123
10
124
11
class DFVisualizationSettings (component ):
@@ -129,43 +16,44 @@ def __init__(self):
129
16
ghenv .Component .ExpireSolution (True ) # noqa: F821
130
17
ghenv .Component .Attributes .PerformLayout () # noqa: F821
131
18
params = getattr (ghenv .Component .Params , "Input" ) # noqa: F821
19
+
132
20
for j in range (len (params )):
133
21
Y_cord = params [j ].Attributes .InputGrip .Y
134
22
X_cord = params [j ].Attributes .Pivot .X
135
23
input_indx = j
136
24
if "i_value_type" == params [j ].NickName :
137
- add_str_valuelist (
25
+ df_gh_canvas . add_str_valuelist (
138
26
ghenv .Component , # noqa: F821
139
27
self .poss_value_types ,
140
28
"DF_value_t" ,
141
29
input_indx , X_cord , Y_cord )
142
30
if "i_palette" == params [j ].NickName :
143
- add_str_valuelist (
31
+ df_gh_canvas . add_str_valuelist (
144
32
ghenv .Component , # noqa: F821
145
33
self .poss_palettes ,
146
34
"DF_palette" ,
147
35
input_indx , X_cord , Y_cord )
148
36
if "i_legend_height" == params [j ].NickName :
149
- add_slider (
37
+ df_gh_canvas . add_slider (
150
38
ghenv .Component , # noqa: F821
151
39
"DF_legend_height" ,
152
40
input_indx ,
153
41
0.000 , 20.000 , 10.000 ,
154
42
X_cord , Y_cord )
155
43
if "i_legend_width" == params [j ].NickName :
156
- add_slider (
44
+ df_gh_canvas . add_slider (
157
45
ghenv .Component , # noqa: F821
158
46
"DF_legend_width" ,
159
47
input_indx ,
160
48
0.000 , 2.000 , 0.500 ,
161
49
X_cord , Y_cord )
162
50
if "i_legend_plane" == params [j ].NickName :
163
- add_plane_object (
51
+ df_gh_canvas . add_plane_object (
164
52
ghenv .Component , # noqa: F821
165
53
"DF_legend_plane" ,
166
54
input_indx , X_cord , Y_cord )
167
55
if "i_histogram_scale_factor" == params [j ].NickName :
168
- add_slider (
56
+ df_gh_canvas . add_slider (
169
57
ghenv .Component , # noqa: F821
170
58
"DF_histogram_scale_factor" ,
171
59
input_indx ,
0 commit comments