Skip to content

Commit 58e3f68

Browse files
committed
Merge remote-tracking branch 'origin/joint_preview_assembly'
2 parents aa39358 + eacb55f commit 58e3f68

File tree

4 files changed

+117
-17
lines changed

4 files changed

+117
-17
lines changed

src/gh/components/DF_preview_assembly/code.py

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import System
44

5+
import typing
6+
57
import Rhino.Geometry as rg
68

79
from ghpythonlib.componentbase import executingcomponent as component
10+
import Grasshopper as gh
11+
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
812

913
import diffCheck
1014
from diffCheck.df_geometries import DFAssembly
@@ -14,24 +18,88 @@
1418
import numpy as np
1519

1620

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

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

2680
self._dfassembly = i_assembly
2781

82+
self._joint_rnd_clr = [System.Drawing.Color.FromArgb(
83+
System.Convert.ToInt32(255 * np.random.rand()),
84+
System.Convert.ToInt32(255 * np.random.rand()),
85+
System.Convert.ToInt32(255 * np.random.rand())) for _ in range(len(self._dfassembly.beams))]
86+
87+
self._are_joints_visible = i_are_joints_visible
88+
89+
return None
90+
2891
# Preview overrides
2992
def DrawViewportWires(self, args):
3093
for beam in self._dfassembly.beams:
94+
#######################################
95+
## DFBeams
96+
#######################################
3197
# beams' obb
3298
df_cloud = diffCheck.diffcheck_bindings.dfb_geometry.DFPointCloud()
33-
df_cloud.points = [np.array([vertex.Location.X, vertex.Location.Y, vertex.Location.Z]).reshape(3, 1) for vertex in beam.to_brep().Vertices]
99+
vertices_pt3d_rh : typing.List[rg.Point3d] = [vertex.to_rg_point3d() for vertex in beam.vertices]
100+
df_cloud.points = [np.array([vertex.X, vertex.Y, vertex.Z]).reshape(3, 1) for vertex in vertices_pt3d_rh]
34101
obb: rg.Brep = diffCheck.df_cvt_bindings.cvt_dfOBB_2_rhbrep(df_cloud.get_tight_bounding_box())
102+
# args.Display.DrawBrepWires(obb, System.Drawing.Color.Red) ## keep for debugging
35103

36104
# axis arrow
37105
obb_faces = obb.Faces
@@ -49,3 +117,28 @@ def DrawViewportWires(self, args):
49117
System.Drawing.Color.Violet,
50118
anchor_pt,
51119
True, 18)
120+
121+
#######################################
122+
## DFJoints
123+
#######################################
124+
if self._are_joints_visible:
125+
for idx_joint, joint in enumerate(beam.joints):
126+
joint_faces = joint.faces
127+
for idx_face, face in enumerate(joint_faces):
128+
face_center = face.to_brep_face().GetBoundingBox(False).Center
129+
args.Display.DrawPoint(face_center, self._joint_rnd_clr[idx_joint])
130+
131+
vector_face_center_2_beam_center = face_center - beam.center
132+
vector_face_center_2_beam_center.Unitize()
133+
vector_face_center_2_beam_center *= 0.4 * extension_length
134+
135+
ln = rg.Line(face_center, face_center + vector_face_center_2_beam_center)
136+
args.Display.DrawDottedLine(ln, self._joint_rnd_clr[idx_joint])
137+
138+
ghenv.Component.AddRuntimeMessage(RML.Remark, "legend joint naming: the beam index - the joint index - the face index by list order") # noqa: F821
139+
name_face_joint: str = f"{beam.index_assembly}-{joint.id}-{idx_face}"
140+
args.Display.Draw2dText(
141+
name_face_joint,
142+
self._joint_rnd_clr[idx_joint],
143+
ln.To,
144+
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": [

src/gh/components/DF_visualization_settings/code.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,6 @@ def RunScript(self,
183183
i_legend_width: float,
184184
i_legend_plane: rg.Plane,
185185
i_histogram_scale_factor: float):
186-
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
198-
199-
:returns o_viz_settings: the results of the comparison all in one object
200-
"""
201186
# set default values
202187
if i_value_type is not None:
203188
if i_value_type not in self.poss_value_types:

src/gh/diffCheck/diffCheck/df_geometries.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def __post_init__(self):
287287
self.faces = self.faces or []
288288
self._joint_faces = []
289289
self._side_faces = []
290+
self._vertices = []
290291

291292
self._joints = []
292293

@@ -388,6 +389,15 @@ def index_assembly(self):
388389
raise ValueError("The beam is not added to an assembly")
389390
return self._index_assembly
390391

392+
@property
393+
def vertices(self):
394+
self._vertices = []
395+
for face in self.faces:
396+
all_loops_cpy = face.all_loops.copy()
397+
for loop in all_loops_cpy:
398+
self._vertices.extend(loop)
399+
return self._vertices
400+
391401

392402
@dataclass
393403
class DFAssembly:

0 commit comments

Comments
 (0)