From 1e371a2e606b3b2dcd72d9ba779079fbbbd67976 Mon Sep 17 00:00:00 2001 From: Swann Date: Tue, 24 Sep 2019 14:42:59 +0200 Subject: [PATCH] feat: expose presence draw settings --- __init__.py | 19 +++++++++++++++-- bl_types/bl_user.py | 9 +++++--- delayable.py | 4 ++-- libs/replication | 2 +- presence.py | 49 +++++++++++++++++++++++++++++++++++++------- ui.py | 50 +++++++++++++++++++++++++++++++++++---------- 6 files changed, 107 insertions(+), 26 deletions(-) diff --git a/__init__.py b/__init__.py index ae2a55d..7e8f744 100644 --- a/__init__.py +++ b/__init__.py @@ -18,6 +18,8 @@ import bpy from bpy.app.handlers import persistent from . import environment, utils +from .libs.replication.replication.constants import RP_COMMON + # TODO: remove dependency as soon as replication will be installed as a module DEPENDENCIES = { @@ -54,7 +56,7 @@ def client_list_callback(scene, context): from . import operators from .bl_types.bl_user import BlUser - items = [("Common", "Common", "")] + items = [(RP_COMMON, RP_COMMON, "")] username = bpy.context.window_manager.session.username cli = operators.client @@ -144,7 +146,20 @@ class SessionProps(bpy.types.PropertyGroup): enable_presence: bpy.props.BoolProperty( name="Presence overlay", description='Enable overlay drawing module', - default=True + default=True, + update=presence.update_presence + ) + presence_show_selected: bpy.props.BoolProperty( + name="Show selected objects", + description='Enable selection overlay ', + default=True, + update=presence.update_overlay_settings + ) + presence_show_user: bpy.props.BoolProperty( + name="Show users", + description='Enable user overlay ', + default=True, + update=presence.update_overlay_settings ) supported_datablock: bpy.props.CollectionProperty( type=ReplicatedDatablock, diff --git a/bl_types/bl_user.py b/bl_types/bl_user.py index 0fa741d..406e9d6 100644 --- a/bl_types/bl_user.py +++ b/bl_types/bl_user.py @@ -29,12 +29,15 @@ class BlUser(BlDatablock): if self.pointer: self.load(data=self.buffer, target=self.pointer) + settings = bpy.context.window_manager.session self.state = UP #TODO: refactor in order to redraw in cleaner ways area, region, rv3d = presence.view3d_find() - if presence.renderer and area and region and rv3d : - presence.renderer.draw_client_camera(self.buffer['name'], self.buffer['location'],self.buffer['color']) - presence.renderer.draw_client_selection(self.buffer['name'], self.buffer['color'],self.buffer['selected_objects']) + if presence.renderer and area and region and rv3d and settings.enable_presence: + if settings.presence_show_user: + presence.renderer.draw_client_camera(self.buffer['name'], self.buffer['location'],self.buffer['color']) + if settings.presence_show_selected: + presence.renderer.draw_client_selection(self.buffer['name'], self.buffer['color'],self.buffer['selected_objects']) presence.refresh_3d_view() diff --git a/delayable.py b/delayable.py index 59d1f46..b7b5e64 100644 --- a/delayable.py +++ b/delayable.py @@ -3,7 +3,7 @@ import logging from . import operators, utils, presence from .bl_types.bl_user import BlUser -from .libs.replication.replication.constants import FETCHED +from .libs.replication.replication.constants import FETCHED, RP_COMMON logger = logging.getLogger(__name__) @@ -95,7 +95,7 @@ class DynamicRightSelectTimer(Timer): node = operators.client.get(reference=bpy.data.objects[obj]) if node: node.owner = settings.username - operators.client.change_owner(node.uuid, 'common') + operators.client.change_owner(node.uuid, RP_COMMON) # update our rights for obj in obj_ours: diff --git a/libs/replication b/libs/replication index 3d4a4b0..ba50a9c 160000 --- a/libs/replication +++ b/libs/replication @@ -1 +1 @@ -Subproject commit 3d4a4b0b862680baa81f44bbf6c4a0df212da8df +Subproject commit ba50a9c379f615dcc5bb112af337105d71d8a434 diff --git a/presence.py b/presence.py index 1813c5e..29b31ea 100644 --- a/presence.py +++ b/presence.py @@ -110,9 +110,23 @@ class User(): def update_selected_objects(self, context): self.selected_objects = utils.get_selected_objects(context.scene) +def update_presence(self, context): + global renderer + + if renderer and self.enable_presence: + renderer.run() + else: + renderer.stop() + +def update_overlay_settings(self, context): + global renderer + + if renderer and not self.presence_show_selected: + renderer.flush_selection() + if renderer and not self.presence_show_user: + renderer.flush_users() class DrawFactory(object): - def __init__(self): self.d3d_items = {} self.d2d_items = {} @@ -148,16 +162,37 @@ class DrawFactory(object): self.d3d_items.clear() self.d2d_items.clear() + def flush_selection(self): + key_to_remove = [] + for k in self.d3d_items.keys(): + if "select" in k: + key_to_remove.append(k) + + for k in key_to_remove: + del self.d3d_items[k] + + def flush_users(self): + key_to_remove = [] + for k in self.d3d_items.keys(): + if "select" not in k: + key_to_remove.append(k) + + for k in key_to_remove: + del self.d3d_items[k] + + self.d2d_items.clear() + def draw_client_selection(self, client_uuid, client_color, client_selection): local_username = bpy.context.window_manager.session.username - key_to_remove = [] - for k in self.d3d_items.keys(): - if "{}_select".format(client_uuid) in k: - key_to_remove.append(k) + self.flush_selection() + # key_to_remove = [] + # for k in self.d3d_items.keys(): + # if "{}_select".format(client_uuid) in k: + # key_to_remove.append(k) - for k in key_to_remove: - del self.d3d_items[k] + # for k in key_to_remove: + # del self.d3d_items[k] if client_selection: diff --git a/ui.py b/ui.py index cece76a..8cdabf7 100644 --- a/ui.py +++ b/ui.py @@ -1,6 +1,6 @@ import bpy from . import operators -from .libs.replication.replication.constants import FETCHED, ERROR, MODIFIED, UP, ADDED +from .libs.replication.replication.constants import FETCHED, ERROR, MODIFIED, UP, ADDED, RP_COMMON from .bl_types.bl_user import BlUser @@ -36,7 +36,6 @@ class SESSION_PT_settings(bpy.types.Panel): else: # STATE ACTIVE if operators.client.state == 2: - row = layout.row() row.operator("session.stop", icon='QUIT', text="Exit") row = layout.row() @@ -69,9 +68,9 @@ class SESSION_PT_settings_network(bpy.types.Panel): row = layout.row() # USER SETTINGS - row.label(text="Presence overlay:") - row.prop(settings, "enable_presence", text="") - row = layout.row() + # row.label(text="Presence overlay:") + # row.prop(settings, "enable_presence", text="") + # row = layout.row() row.label(text="Own selection:") row.prop(settings, "use_select_right", text="") row = layout.row() @@ -136,6 +135,7 @@ class SESSION_PT_settings_replication(bpy.types.Panel): bl_region_type = 'UI' bl_category = "Multiuser" bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel' + bl_options = {'DEFAULT_CLOSED'} @classmethod def poll(cls, context): @@ -217,6 +217,32 @@ class SESSION_PT_user(bpy.types.Panel): row = layout.row() +class SESSION_PT_presence(bpy.types.Panel): + bl_idname = "MULTIUSER_MODULE_PT_panel" + bl_label = "Presence overlay" + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_category = "Multiuser" + bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel' + + @classmethod + def poll(cls, context): + return True + + def draw_header(self, context): + self.layout.prop(context.window_manager.session, "enable_presence", text="") + + def draw(self, context): + layout = self.layout + + settings = context.window_manager.session + layout.active = settings.enable_presence + col = layout.column() + col.prop(settings,"presence_show_selected") + col.prop(settings,"presence_show_user") + row = layout.row() + + def draw_property(context, parent, property_uuid, level=0): settings = context.window_manager.session item = operators.client.get(uuid=property_uuid) @@ -240,12 +266,15 @@ def draw_property(context, parent, property_uuid, level=0): # Operations - have_right_to_modify = settings.is_admin or item.owner == settings.username + have_right_to_modify = settings.is_admin or \ + item.owner == settings.username or \ + item.owner == RP_COMMON + detail_item_box.operator( "session.commit", text="", icon='TRIA_UP').target = item.uuid - detail_item_box.separator() + detail_item_box.separator() if item.state in [FETCHED, UP]: detail_item_box.operator( "session.apply", @@ -260,7 +289,7 @@ def draw_property(context, parent, property_uuid, level=0): detail_item_box.label(text="", icon=ICONS_PROP_STATES[item.state]) right_icon = "DECORATE_UNLOCKED" - if item.owner != settings.username: + if not have_right_to_modify: right_icon = "DECORATE_LOCKED" if have_right_to_modify: @@ -305,7 +334,6 @@ class SESSION_PT_outliner(bpy.types.Panel): col = flow.column(align=True) col.prop(item, "use_as_filter", text="", icon=item.icon) - row = layout.row(align=True) row.prop(settings, "filter_owned", text="Show only owned") @@ -334,11 +362,11 @@ class SESSION_PT_outliner(bpy.types.Panel): classes = ( SESSION_PT_settings, SESSION_PT_settings_user, + SESSION_PT_presence, SESSION_PT_settings_network, SESSION_PT_settings_replication, SESSION_PT_user, - SESSION_PT_outliner, - + SESSION_PT_outliner )