Skip to content

Commit

Permalink
fix send stream object cases (#207)
Browse files Browse the repository at this point in the history
* fix send stream object cases

* clean logs

* revert workaround

* revert unnecessary logic

* revert unnecessary logic

* rename set_user

---------

Co-authored-by: Soylu <[email protected]>
  • Loading branch information
overengineer and Soylu authored Aug 5, 2024
1 parent 8c3885e commit 4c381bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion bpy_speckle/operators/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -380,6 +380,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()

Expand Down
18 changes: 13 additions & 5 deletions bpy_speckle/properties/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_commits(self, context):
def commit_update_hook(self, context: bpy.types.Context):
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
Expand Down Expand Up @@ -95,6 +96,7 @@ 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)
# 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
Expand Down Expand Up @@ -123,6 +125,7 @@ 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
# 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)

Expand Down Expand Up @@ -164,15 +167,15 @@ 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)

active_user: EnumProperty(
items=get_users,
name="Account",
description="Select account",
update=set_user,
update=user_update_hook,
get=None,
set=None,
) # type: ignore
Expand Down Expand Up @@ -200,7 +203,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):
Expand Down Expand Up @@ -282,17 +285,22 @@ def restore_selection_state(speckle: SpeckleSceneSettings) -> None:
# Restore branch selection state
if selection_state.selected_branch_id != None:
(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:
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):
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(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
Expand Down

0 comments on commit 4c381bd

Please sign in to comment.