From 8aa4c6c2314ea0fd321431a4ad005de296a02855 Mon Sep 17 00:00:00 2001 From: Soylu Date: Thu, 1 Aug 2024 15:14:40 +0300 Subject: [PATCH 1/6] fix send stream object cases --- bpy_speckle/operators/streams.py | 8 ++++++- bpy_speckle/operators/users.py | 1 + bpy_speckle/properties/scene.py | 41 ++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/bpy_speckle/operators/streams.py b/bpy_speckle/operators/streams.py index 36ddb89..38d6e6c 100644 --- a/bpy_speckle/operators/streams.py +++ b/bpy_speckle/operators/streams.py @@ -33,7 +33,7 @@ ) from bpy_speckle.clients import speckle_clients from bpy_speckle.operators.users import LoadUserStreams, add_user_stream -from bpy_speckle.properties.scene import SpeckleSceneSettings, SpeckleStreamObject, SpeckleUserObject, get_speckle +from bpy_speckle.properties.scene import SpeckleSceneSettings, SpeckleStreamObject, SpeckleUserObject, get_speckle, selection_state from bpy_speckle.convert.util import ConversionSkippedException, add_to_hierarchy from specklepy.core.api.models import Commit from specklepy.core.api import operations, host_applications @@ -285,6 +285,7 @@ def execute(self, context): return {"FINISHED"} def send(self, context: Context) -> None: + print("SendStreamObjects") selected = context.selected_objects if len(selected) < 1: @@ -380,6 +381,11 @@ def send(self, context: Context) -> None: _report(f"Commit Created {sent_url}") + selection_state.selected_commit_id = COMMIT_ID + selection_state.selected_branch_id = branch.id + selection_state.selected_stream_id = stream.id + selection_state.selected_user_id = user.id + bpy.ops.speckle.load_user_streams() # refresh loaded commits context.view_layer.update() diff --git a/bpy_speckle/operators/users.py b/bpy_speckle/operators/users.py index ce16067..bd88da5 100644 --- a/bpy_speckle/operators/users.py +++ b/bpy_speckle/operators/users.py @@ -161,6 +161,7 @@ def execute(self, context): def load_user_stream(self, context: Context) -> None: + print("LoadUserStreams") speckle = get_speckle(context) user = speckle.validate_user_selection() diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index a252692..330b495 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -40,8 +40,10 @@ def get_commits(self, context): return [("0", "", "", 0)] def commit_update_hook(self, context: bpy.types.Context): + print("commit_update_hook") selection_state.selected_commit_id = SelectionState.get_item_id_by_index(self.commits, self.commit) selection_state.selected_branch_id = self.id + print(f"commit_update_hook: {selection_state.selected_commit_id=}, {selection_state.selected_branch_id=}") name: StringProperty(default="main") # type: ignore id: StringProperty(default="") # type: ignore @@ -94,7 +96,10 @@ def get_branches(self, context): return [("0", "", "", 0)] def branch_update_hook(self, context: bpy.types.Context): + print("branch_update_hook") selection_state.selected_branch_id = SelectionState.get_item_id_by_index(self.branches, self.branch) + selection_state.selected_stream_id = self.id + print(f"branch_update_hook: {selection_state.selected_branch_id=}, {selection_state.selected_stream_id=}") name: StringProperty(default="") # type: ignore description: StringProperty(default="") # type: ignore @@ -121,8 +126,11 @@ def fetch_stream_branches(self, context: bpy.types.Context, stream: SpeckleStrea stream.load_stream_branches(sstream) def stream_update_hook(self, context: bpy.types.Context): + print("stream_update_hook") stream = SelectionState.get_item_by_index(self.streams, self.active_stream) selection_state.selected_stream_id = stream.id + selection_state.selected_user_id = self.id + print(f"stream_update_hook: {selection_state.selected_stream_id=}, {selection_state.selected_user_id=}") if len(stream.branches) == 0: # do not reload on selection, same as the old behavior self.fetch_stream_branches(context, stream) @@ -200,7 +208,7 @@ def set_user(self, context): ) # type: ignore def get_active_user(self) -> Optional[SpeckleUserObject]: - if not self.active_user: + if self.active_user is None: return None selected_index = int(self.active_user) if 0 <= selected_index < len(self.users): @@ -279,20 +287,35 @@ def get_item_index_by_id(collection: Iterable[SpeckleCommitObject], id: Optional selection_state = SelectionState() def restore_selection_state(speckle: SpeckleSceneSettings) -> None: + print("restore_selection_state") # Restore branch selection state if selection_state.selected_branch_id != None: + print("restore_selection_state: branch") (active_user, active_stream) = speckle.validate_stream_selection() + print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}") + print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") is_same_user = active_user.id == selection_state.selected_user_id - is_same_stream = active_stream.id == selection_state.selected_stream_id - if is_same_user and is_same_stream: + if is_same_user: + print("restore_selection_state: branch: same user") + active_user.active_stream = int(SelectionState.get_item_index_by_id(active_user.streams, selection_state.selected_stream_id)) + active_stream = SelectionState.get_item_by_index(active_user.streams, active_user.active_stream) if branch := SelectionState.get_item_index_by_id(active_stream.branches, selection_state.selected_branch_id): + print("restore_selection_state: found branch") active_stream.branch = branch # Restore commit selection state if selection_state.selected_commit_id != None: - (active_user, active_stream, active_branch) = speckle.validate_branch_selection() + print("restore_selection_state: commit") + (active_user, active_stream) = speckle.validate_stream_selection() + + active_branch = active_stream.get_active_branch() + + if active_branch is None: + active_branch = active_stream.branches[0] + print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}, {active_branch.id=}") + print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") is_same_user = active_user.id == selection_state.selected_user_id is_same_stream = active_stream.id == selection_state.selected_stream_id @@ -300,4 +323,12 @@ def restore_selection_state(speckle: SpeckleSceneSettings) -> None: if is_same_user and is_same_stream and is_same_branch: if commit := SelectionState.get_item_index_by_id(active_branch.commits, selection_state.selected_commit_id): - active_branch.commit = commit \ No newline at end of file + active_branch.commit = commit + + print("restore_selection_state: save") + (active_user, active_stream, active_branch, active_commit) = speckle.validate_commit_selection() + # selection_state.selected_user_id = active_user.id + # selection_state.selected_stream_id = active_stream.id + selection_state.selected_branch_id = active_branch.id + selection_state.selected_commit_id = active_commit.id + print("restore_selection_state: done") \ No newline at end of file From 2c6c165989e6cb5f7b37e98e915ca4356fc84ecd Mon Sep 17 00:00:00 2001 From: Soylu Date: Thu, 1 Aug 2024 15:23:14 +0300 Subject: [PATCH 2/6] clean logs --- bpy_speckle/operators/streams.py | 1 - bpy_speckle/operators/users.py | 1 - bpy_speckle/properties/scene.py | 26 ++++++++------------------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/bpy_speckle/operators/streams.py b/bpy_speckle/operators/streams.py index 38d6e6c..ac40b4a 100644 --- a/bpy_speckle/operators/streams.py +++ b/bpy_speckle/operators/streams.py @@ -285,7 +285,6 @@ def execute(self, context): return {"FINISHED"} def send(self, context: Context) -> None: - print("SendStreamObjects") selected = context.selected_objects if len(selected) < 1: diff --git a/bpy_speckle/operators/users.py b/bpy_speckle/operators/users.py index bd88da5..ce16067 100644 --- a/bpy_speckle/operators/users.py +++ b/bpy_speckle/operators/users.py @@ -161,7 +161,6 @@ def execute(self, context): def load_user_stream(self, context: Context) -> None: - print("LoadUserStreams") speckle = get_speckle(context) user = speckle.validate_user_selection() diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index 330b495..2bc32cd 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -40,10 +40,9 @@ def get_commits(self, context): return [("0", "", "", 0)] def commit_update_hook(self, context: bpy.types.Context): - print("commit_update_hook") selection_state.selected_commit_id = SelectionState.get_item_id_by_index(self.commits, self.commit) selection_state.selected_branch_id = self.id - print(f"commit_update_hook: {selection_state.selected_commit_id=}, {selection_state.selected_branch_id=}") + # print(f"commit_update_hook: {selection_state.selected_commit_id=}, {selection_state.selected_branch_id=}") name: StringProperty(default="main") # type: ignore id: StringProperty(default="") # type: ignore @@ -96,10 +95,9 @@ def get_branches(self, context): return [("0", "", "", 0)] def branch_update_hook(self, context: bpy.types.Context): - print("branch_update_hook") selection_state.selected_branch_id = SelectionState.get_item_id_by_index(self.branches, self.branch) selection_state.selected_stream_id = self.id - print(f"branch_update_hook: {selection_state.selected_branch_id=}, {selection_state.selected_stream_id=}") + # print(f"branch_update_hook: {selection_state.selected_branch_id=}, {selection_state.selected_stream_id=}") name: StringProperty(default="") # type: ignore description: StringProperty(default="") # type: ignore @@ -126,11 +124,10 @@ def fetch_stream_branches(self, context: bpy.types.Context, stream: SpeckleStrea stream.load_stream_branches(sstream) def stream_update_hook(self, context: bpy.types.Context): - print("stream_update_hook") stream = SelectionState.get_item_by_index(self.streams, self.active_stream) selection_state.selected_stream_id = stream.id selection_state.selected_user_id = self.id - print(f"stream_update_hook: {selection_state.selected_stream_id=}, {selection_state.selected_user_id=}") + # print(f"stream_update_hook: {selection_state.selected_stream_id=}, {selection_state.selected_user_id=}") if len(stream.branches) == 0: # do not reload on selection, same as the old behavior self.fetch_stream_branches(context, stream) @@ -287,35 +284,30 @@ def get_item_index_by_id(collection: Iterable[SpeckleCommitObject], id: Optional selection_state = SelectionState() def restore_selection_state(speckle: SpeckleSceneSettings) -> None: - print("restore_selection_state") # Restore branch selection state if selection_state.selected_branch_id != None: - print("restore_selection_state: branch") (active_user, active_stream) = speckle.validate_stream_selection() - print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}") - print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") + # print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}") + # print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") is_same_user = active_user.id == selection_state.selected_user_id if is_same_user: - print("restore_selection_state: branch: same user") active_user.active_stream = int(SelectionState.get_item_index_by_id(active_user.streams, selection_state.selected_stream_id)) active_stream = SelectionState.get_item_by_index(active_user.streams, active_user.active_stream) if branch := SelectionState.get_item_index_by_id(active_stream.branches, selection_state.selected_branch_id): - print("restore_selection_state: found branch") active_stream.branch = branch # Restore commit selection state if selection_state.selected_commit_id != None: - print("restore_selection_state: commit") (active_user, active_stream) = speckle.validate_stream_selection() active_branch = active_stream.get_active_branch() if active_branch is None: active_branch = active_stream.branches[0] - print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}, {active_branch.id=}") - print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") + # print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}, {active_branch.id=}") + # print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") is_same_user = active_user.id == selection_state.selected_user_id is_same_stream = active_stream.id == selection_state.selected_stream_id @@ -325,10 +317,8 @@ def restore_selection_state(speckle: SpeckleSceneSettings) -> None: if commit := SelectionState.get_item_index_by_id(active_branch.commits, selection_state.selected_commit_id): active_branch.commit = commit - print("restore_selection_state: save") (active_user, active_stream, active_branch, active_commit) = speckle.validate_commit_selection() # selection_state.selected_user_id = active_user.id # selection_state.selected_stream_id = active_stream.id selection_state.selected_branch_id = active_branch.id - selection_state.selected_commit_id = active_commit.id - print("restore_selection_state: done") \ No newline at end of file + selection_state.selected_commit_id = active_commit.id \ No newline at end of file From 2a90224dd35ccdde8e02819de6865331ea836d8d Mon Sep 17 00:00:00 2001 From: Soylu Date: Thu, 1 Aug 2024 15:25:49 +0300 Subject: [PATCH 3/6] revert workaround --- bpy_speckle/properties/scene.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index 2bc32cd..0c00c01 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -300,12 +300,7 @@ def restore_selection_state(speckle: SpeckleSceneSettings) -> None: # Restore commit selection state if selection_state.selected_commit_id != None: - (active_user, active_stream) = speckle.validate_stream_selection() - - active_branch = active_stream.get_active_branch() - - if active_branch is None: - active_branch = active_stream.branches[0] + (active_user, active_stream, active_branch) = speckle.validate_branch_selection() # print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}, {active_branch.id=}") # print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") From 729faf553d4867e83317a97cca6da8b1feb5f897 Mon Sep 17 00:00:00 2001 From: Soylu Date: Thu, 1 Aug 2024 15:29:30 +0300 Subject: [PATCH 4/6] revert unnecessary logic --- bpy_speckle/properties/scene.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index 0c00c01..b684adc 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -96,7 +96,6 @@ def get_branches(self, context): def branch_update_hook(self, context: bpy.types.Context): selection_state.selected_branch_id = SelectionState.get_item_id_by_index(self.branches, self.branch) - selection_state.selected_stream_id = self.id # print(f"branch_update_hook: {selection_state.selected_branch_id=}, {selection_state.selected_stream_id=}") name: StringProperty(default="") # type: ignore @@ -126,7 +125,6 @@ def fetch_stream_branches(self, context: bpy.types.Context, stream: SpeckleStrea def stream_update_hook(self, context: bpy.types.Context): stream = SelectionState.get_item_by_index(self.streams, self.active_stream) selection_state.selected_stream_id = stream.id - selection_state.selected_user_id = self.id # print(f"stream_update_hook: {selection_state.selected_stream_id=}, {selection_state.selected_user_id=}") if len(stream.branches) == 0: # do not reload on selection, same as the old behavior self.fetch_stream_branches(context, stream) From b0888132e010885a7ba617e64806b40af9e95338 Mon Sep 17 00:00:00 2001 From: Soylu Date: Thu, 1 Aug 2024 15:36:35 +0300 Subject: [PATCH 5/6] revert unnecessary logic --- bpy_speckle/properties/scene.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index b684adc..bad8922 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -308,10 +308,4 @@ def restore_selection_state(speckle: SpeckleSceneSettings) -> None: if is_same_user and is_same_stream and is_same_branch: if commit := SelectionState.get_item_index_by_id(active_branch.commits, selection_state.selected_commit_id): - active_branch.commit = commit - - (active_user, active_stream, active_branch, active_commit) = speckle.validate_commit_selection() - # selection_state.selected_user_id = active_user.id - # selection_state.selected_stream_id = active_stream.id - selection_state.selected_branch_id = active_branch.id - selection_state.selected_commit_id = active_commit.id \ No newline at end of file + active_branch.commit = commit \ No newline at end of file From ee306aae3a28b3bb7335436a0f7a3172b051b510 Mon Sep 17 00:00:00 2001 From: Soylu Date: Thu, 1 Aug 2024 16:01:27 +0300 Subject: [PATCH 6/6] rename set_user --- bpy_speckle/properties/scene.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index bad8922..9e4bbfa 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -167,7 +167,7 @@ def get_users(self, context): for i, user in enumerate(USERS) ] - def set_user(self, context): + def user_update_hook(self, context): bpy.ops.speckle.load_user_streams() # type: ignore selection_state.selected_user_id = SelectionState.get_item_id_by_index(self.users, self.active_user) @@ -175,7 +175,7 @@ def set_user(self, context): items=get_users, name="Account", description="Select account", - update=set_user, + update=user_update_hook, get=None, set=None, ) # type: ignore