Skip to content

Commit dfbc705

Browse files
committed
MILESTONE: integrated the bool switch
1 parent 09341d6 commit dfbc705

File tree

2 files changed

+87
-29
lines changed

2 files changed

+87
-29
lines changed

src/gh/components/DF_preview_assembly/code.py

Lines changed: 75 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import Rhino.Geometry as rg
88

99
from ghpythonlib.componentbase import executingcomponent as component
10+
import Grasshopper as gh
1011

1112
import diffCheck
1213
from diffCheck.df_geometries import DFAssembly
@@ -16,22 +17,74 @@
1617
import numpy as np
1718

1819

20+
def add_bool_toggle(self,
21+
nickname: str,
22+
indx: int,
23+
X_param_coord: float,
24+
Y_param_coord: float,
25+
X_offset: int=87
26+
) -> None:
27+
"""
28+
Adds a boolean toggle to the component input
29+
30+
:param nickname: the nickname of the value list
31+
:param indx: the index of the input parameter
32+
:param X_param_coord: the x coordinate of the input parameter
33+
:param Y_param_coord: the y coordinate of the input parameter
34+
:param X_offset: the offset of the value list from the input parameter
35+
"""
36+
param = ghenv.Component.Params.Input[indx] # noqa: F821
37+
if param.SourceCount == 0:
38+
toggle = gh.Kernel.Special.GH_BooleanToggle()
39+
toggle.NickName = nickname
40+
toggle.Description = "Toggle the value to use with DFVizSettings"
41+
toggle.CreateAttributes()
42+
toggle.Attributes.Pivot = System.Drawing.PointF(
43+
X_param_coord - (toggle.Attributes.Bounds.Width) - X_offset,
44+
Y_param_coord - (toggle.Attributes.Bounds.Height / 2 + 0.1)
45+
)
46+
toggle.Attributes.ExpireLayout()
47+
gh.Instances.ActiveCanvas.Document.AddObject(toggle, False)
48+
ghenv.Component.Params.Input[indx].AddSource(toggle) # noqa: F821
49+
1950
class DFPreviewAssembly(component):
2051
def __init__(self):
2152
super(DFPreviewAssembly, self).__init__()
2253
self._dfassembly = None
2354
self._joint_rnd_clr = None
2455

25-
def RunScript(self, i_assembly: DFAssembly=None):
56+
ghenv.Component.ExpireSolution(True) # noqa: F821
57+
ghenv.Component.Attributes.PerformLayout() # noqa: F821
58+
params = getattr(ghenv.Component.Params, "Input") # noqa: F821
59+
for j in range(len(params)):
60+
Y_cord = params[j].Attributes.InputGrip.Y + 1
61+
X_cord = params[j].Attributes.Pivot.X + 20
62+
input_indx = j
63+
if "i_are_joints_visible" == params[j].NickName:
64+
add_bool_toggle(
65+
ghenv.Component, # noqa: F821
66+
"show_joints",
67+
input_indx, X_cord, Y_cord)
68+
69+
70+
def RunScript(self,
71+
i_assembly: DFAssembly=None,
72+
i_are_joints_visible: bool=None
73+
):
2674
if i_assembly is None:
2775
return None
76+
if i_are_joints_visible is None:
77+
i_are_joints_visible = False
2878

2979
self._dfassembly = i_assembly
3080

3181
self._joint_rnd_clr = [System.Drawing.Color.FromArgb(
3282
System.Convert.ToInt32(255 * np.random.rand()),
3383
System.Convert.ToInt32(255 * np.random.rand()),
3484
System.Convert.ToInt32(255 * np.random.rand())) for _ in range(len(self._dfassembly.beams))]
85+
86+
self._are_joints_visible = i_are_joints_visible
87+
3588
return None
3689

3790
# Preview overrides
@@ -67,31 +120,24 @@ def DrawViewportWires(self, args):
67120
#######################################
68121
## DFJoints
69122
#######################################
70-
# draw an hatch for each joint's face
71-
# beam_center = beam.center
72-
# beam_idx
73-
for idx_joint, joint in enumerate(beam.joints):
74-
joint_faces = joint.faces
75-
for idx_face, face in enumerate(joint_faces):
76-
face_center = face.to_brep_face().GetBoundingBox(False).Center
77-
args.Display.DrawPoint(face_center, self._joint_rnd_clr[idx_joint])
78-
79-
vector_face_center_2_beam_center = face_center - beam.center
80-
vector_face_center_2_beam_center.Unitize()
81-
vector_face_center_2_beam_center *= 0.4 * extension_length
82-
83-
ln = rg.Line(face_center, face_center + vector_face_center_2_beam_center)
84-
args.Display.DrawDottedLine(ln, self._joint_rnd_clr[idx_joint])
85-
86-
# name of the joint is defined by: 1) the beam index, 2) the joint index, 3) the face index
87-
name_face_joint: str = f"{beam.index_assembly}-{idx_joint}-{idx_face}"
88-
args.Display.Draw2dText(
89-
name_face_joint,
90-
self._joint_rnd_clr[idx_joint],
91-
ln.To,
92-
True, 18)
93-
# joint_faces = joint.faces
94-
# for face in joint_faces:
95-
# mesh_rh = face.to_mesh()
96-
97-
# args.Display.DrawMeshWires(mesh_rh, System.Drawing.Color.Blue)
123+
if self._are_joints_visible:
124+
for idx_joint, joint in enumerate(beam.joints):
125+
joint_faces = joint.faces
126+
for idx_face, face in enumerate(joint_faces):
127+
face_center = face.to_brep_face().GetBoundingBox(False).Center
128+
args.Display.DrawPoint(face_center, self._joint_rnd_clr[idx_joint])
129+
130+
vector_face_center_2_beam_center = face_center - beam.center
131+
vector_face_center_2_beam_center.Unitize()
132+
vector_face_center_2_beam_center *= 0.4 * extension_length
133+
134+
ln = rg.Line(face_center, face_center + vector_face_center_2_beam_center)
135+
args.Display.DrawDottedLine(ln, self._joint_rnd_clr[idx_joint])
136+
137+
# name of the joint is defined by: 1) the beam index, 2) the joint index, 3) the face index by list order
138+
name_face_joint: str = f"{beam.index_assembly}-{joint.id}-{idx_face}"
139+
args.Display.Draw2dText(
140+
name_face_joint,
141+
self._joint_rnd_clr[idx_joint],
142+
ln.To,
143+
True, 18)

src/gh/components/DF_preview_assembly/metadata.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
"wireDisplay": "default",
2525
"sourceCount": 0,
2626
"typeHintID": "ghdoc"
27+
},
28+
{
29+
"name": "i_are_joints_visible",
30+
"nickname": "i_are_joints_visible",
31+
"description": "Show the joints' identifiers widgets.",
32+
"optional": false,
33+
"allowTreeAccess": true,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "bool"
2739
}
2840
],
2941
"outputParameters": [

0 commit comments

Comments
 (0)