Skip to content

Commit 1fad289

Browse files
committed
FIX typo and use not all sticky but a single namespaced key df_poses
1 parent 067903e commit 1fad289

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/gh/components/DF_pose_estimation/metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"subcategory": "PointCloud",
66
"description": "This compoment calculates the pose of a list of point clouds.",
77
"exposure": 4,
8-
"instanceGuid": "22b0c6fc-bc16-4ff5-b789-e99776277f65",
8+
"instanceGuid": "a13c4414-f5df-46e6-beae-7054bb9c3e72",
99
"ghpython": {
1010
"hideOutput": true,
1111
"hideInput": true,
@@ -16,7 +16,7 @@
1616
{
1717
"name": "i_clouds",
1818
"nickname": "i_clouds",
19-
"description": "clouds whose main axes are to be calculated",
19+
"description": "clouds whose pose is to be calculated",
2020
"optional": false,
2121
"allowTreeAccess": true,
2222
"showTypeHints": true,
@@ -28,7 +28,7 @@
2828
{
2929
"name": "i_assembly",
3030
"nickname": "i_assembly",
31-
"description": "The DFAssembly object to deconstruct.",
31+
"description": "The DFAssembly corresponding to the list of clouds.",
3232
"optional": false,
3333
"allowTreeAccess": true,
3434
"showTypeHints": true,
@@ -74,7 +74,7 @@
7474
{
7575
"name": "o_history",
7676
"nickname": "o_history",
77-
"description": "The history of poses of all the elements.",
77+
"description": "The history of poses per elements.",
7878
"optional": false,
7979
"sourceCount": 0,
8080
"graft": false

src/gh/diffCheck/diffCheck/df_poses.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
import json
66
from dataclasses import dataclass, field
77

8+
# use a key and not all the sticky
9+
_STICKY_KEY = "df_poses"
10+
11+
def _get_store():
12+
# returns private sub-dict inside rhino sticky
13+
return rh_sticky_dict.setdefault(_STICKY_KEY, {})
14+
815
@dataclass
916
class DFPose:
1017
"""
@@ -29,14 +36,14 @@ class DFPosesBeam:
2936
This class contains the poses of a single beam, at different times in the assembly process.
3037
It also contains the number of faces detected for this element, based on which the poses are calculated.
3138
"""
32-
poses_dictionnary: dict
39+
poses_dictionary: dict
3340
n_faces: int = 3
3441

3542
def add_pose(self, pose: DFPose, step_number: int):
3643
"""
3744
Add a pose to the dictionary of poses.
3845
"""
39-
self.poses_dictionnary[f"pose_{step_number}"] = pose
46+
self.poses_dictionary[f"pose_{step_number}"] = pose
4047

4148
def set_n_faces(self, n_faces: int):
4249
"""
@@ -47,7 +54,7 @@ def set_n_faces(self, n_faces: int):
4754
@dataclass
4855
class DFPosesAssembly:
4956
n_step: int = 0
50-
poses_per_element_dictionary: dict = field(default_factory=lambda: rh_sticky_dict)
57+
poses_per_element_dictionary: dict = field(default_factory=_get_store)
5158

5259
"""
5360
This class contains the poses of the different elements of the assembly, at different times in the assembly process.
@@ -58,7 +65,7 @@ def __post_init__(self):
5865
"""
5966
lengths = []
6067
for element in self.poses_per_element_dictionary:
61-
lengths.append(len(self.poses_per_element_dictionary[element].poses_dictionnary))
68+
lengths.append(len(self.poses_per_element_dictionary[element].poses_dictionary))
6269
self.n_step = max(lengths) if lengths else 0
6370

6471
def add_step(self, new_poses: list[DFPose]):
@@ -78,15 +85,18 @@ def get_last_poses(self):
7885
return None
7986
last_poses = []
8087
for i in range(len(self.poses_per_element_dictionary)):
81-
last_poses.append(self.poses_per_element_dictionary[f"element_{i}"].poses_dictionnary[f"pose_{self.n_step-1}"])
88+
last_poses.append(self.poses_per_element_dictionary[f"element_{i}"].poses_dictionary[f"pose_{self.n_step-1}"])
8289
return last_poses
8390

8491
def reset(self):
8592
"""
8693
Reset the assembly poses to the initial state.
8794
"""
8895
self.n_step = 0
89-
rh_sticky_dict.clear()
96+
# clear only namespace
97+
rh_sticky_dict[_STICKY_KEY] = {}
98+
# refresh the local reference to the (now empty) store
99+
self.poses_per_element_dictionary = _get_store()
90100

91101
def save(self, file_path: str):
92102
"""
@@ -102,7 +112,7 @@ def to_gh_tree(self):
102112
list_of_poses = []
103113
for element, poses in self.poses_per_element_dictionary.items():
104114
list_of_pose_of_element = []
105-
for pose in poses.poses_dictionnary.values():
115+
for pose in poses.poses_dictionary.values():
106116
list_of_pose_of_element.append(pose.to_rh_plane() if pose is not None else None)
107117
list_of_poses.append(list_of_pose_of_element)
108118
return th.list_to_tree(list_of_poses)

0 commit comments

Comments
 (0)