Skip to content

Commit c546fec

Browse files
committed
ADD drop btns and panel with standard inputs similar to vizualization settings
1 parent 46c6d6f commit c546fec

File tree

5 files changed

+219
-120
lines changed

5 files changed

+219
-120
lines changed

src/gh/components/DF_http_listener/code.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88
import Rhino
99
import Rhino.Geometry as rg
1010
import scriptcontext as sc
11+
from diffCheck import df_gh_canvas
1112

1213

1314
class DFHTTPListener(component):
1415

16+
def __init__(self):
17+
try:
18+
ghenv.Component.ExpireSolution(True) # noqa: F821
19+
ghenv.Component.Attributes.PerformLayout() # noqa: F821
20+
except NameError:
21+
pass
22+
23+
df_gh_canvas.add_button(ghenv.Component, "Load", 0, x_offset=60) # noqa: F821
24+
df_gh_canvas.add_panel(ghenv.Component, "Ply_url", "https://github.com/diffCheckOrg/diffCheck/raw/refs/heads/main/tests/test_data/cube_mesh.ply", 1, 60, 20) # noqa: F821
25+
1526
def RunScript(self,
1627
i_load: bool,
1728
i_ply_url: str):

src/gh/components/DF_tcp_listener/code.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@
77
import scriptcontext as sc
88
import Rhino.Geometry as rg
99
import System.Drawing as sd
10+
from diffCheck import df_gh_canvas
1011

1112

1213
class DFTCPListener(component):
14+
def __init__(self):
15+
try:
16+
ghenv.Component.ExpireSolution(True) # noqa: F821
17+
ghenv.Component.Attributes.PerformLayout() # noqa: F821
18+
except NameError:
19+
pass
20+
21+
for idx, label in enumerate(("Start", "Stop", "Load")):
22+
df_gh_canvas.add_button(
23+
ghenv.Component, label, idx, x_offset=60) # noqa: F821
24+
df_gh_canvas.add_panel(ghenv.Component, "Host", "127.0.0.1", 3, 60, 20) # noqa: F821
25+
df_gh_canvas.add_panel(ghenv.Component, "Port", "5000", 4, 60, 20) # noqa: F821
26+
1327
def RunScript(self,
1428
i_start: bool,
1529
i_stop: bool,

src/gh/components/DF_visualization_settings/code.py

Lines changed: 8 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,11 @@
11
#! python3
22

3-
import System
4-
import typing
53
import Rhino
64
from ghpythonlib.componentbase import executingcomponent as component
7-
import Grasshopper as gh
8-
from Grasshopper import Instances
95
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
106

117
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
1229

12310

12411
class 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,

src/gh/components/DF_websocket_listener/code.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,23 @@
88
import Rhino.Geometry as rg
99
import System.Drawing as sd
1010
from websockets.server import serve
11+
from diffCheck import df_gh_canvas
1112

1213

1314
class DFWSServerListener(component):
15+
def __init__(self):
16+
try:
17+
ghenv.Component.ExpireSolution(True) # noqa: F821
18+
ghenv.Component.Attributes.PerformLayout() # noqa: F821
19+
except NameError:
20+
pass
21+
22+
for idx, label in enumerate(("Start", "Stop", "Load")):
23+
df_gh_canvas.add_button(
24+
ghenv.Component, label, idx, x_offset=60) # noqa: F821
25+
df_gh_canvas.add_panel(ghenv.Component, "Host", "127.0.0.1", 3, 60, 20) # noqa: F821
26+
df_gh_canvas.add_panel(ghenv.Component, "Port", "9000", 4, 60, 20) # noqa: F821
27+
1428
def RunScript(self,
1529
i_start: bool,
1630
i_stop: bool,

0 commit comments

Comments
 (0)