@ -7,30 +7,23 @@ from .. import presence
|
||||
from .bl_datablock import BlDatablock
|
||||
from ..libs.replication.replication.constants import UP
|
||||
|
||||
|
||||
class BlUser(BlDatablock):
|
||||
def construct(self, name):
|
||||
return presence.User()
|
||||
|
||||
def load(self, data, target):
|
||||
target.name = data['name']
|
||||
target.location = data['location']
|
||||
target.selected_objects = data['selected_objects']
|
||||
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
def apply(self):
|
||||
|
||||
if self.pointer:
|
||||
self.load(data=self.data, target=self.pointer)
|
||||
for obj in bpy.data.objects:
|
||||
if obj.hide_select and obj.uuid not in self.data['selected_objects']:
|
||||
obj.hide_select = False
|
||||
elif not obj.hide_select and obj.uuid in self.data['selected_objects']:
|
||||
obj.hide_select = True
|
||||
|
||||
presence.refresh_3d_view()
|
||||
|
||||
self.state = UP
|
||||
|
||||
|
||||
|
||||
|
||||
def dump(self,pointer=None):
|
||||
def dump(self, pointer=None):
|
||||
data = utils.dump_anything.dump(pointer)
|
||||
data['location'] = pointer.location
|
||||
data['color'] = pointer.color
|
||||
@ -42,20 +35,10 @@ class BlUser(BlDatablock):
|
||||
def update(self):
|
||||
self.pointer.is_dirty = True
|
||||
|
||||
# def diff(self):
|
||||
# if not self.pointer:
|
||||
# return False
|
||||
# if self.pointer.is_dirty:
|
||||
# self.pointer.is_dirty = False
|
||||
# return True
|
||||
|
||||
# for i,coord in enumerate(self.pointer.location):
|
||||
# if coord != self.data['location'][i]:
|
||||
# return True
|
||||
# return False
|
||||
|
||||
def is_valid(self):
|
||||
return True
|
||||
|
||||
|
||||
bl_id = "users"
|
||||
bl_class = presence.User
|
||||
bl_rep_class = BlUser
|
||||
|
@ -74,74 +74,91 @@ class ApplyTimer(Timer):
|
||||
try:
|
||||
operators.client.apply(node)
|
||||
except Exception as e:
|
||||
logger.error("fail to apply {}: {}".format(node_ref.uuid,e))
|
||||
logger.error(
|
||||
"fail to apply {}: {}".format(node_ref.uuid, e))
|
||||
|
||||
|
||||
class DynamicRightSelectTimer(Timer):
|
||||
def __init__(self, timout=.1):
|
||||
super().__init__(timout)
|
||||
self.last_selection = []
|
||||
self._last_selection = []
|
||||
self._user = None
|
||||
self._user_node = None
|
||||
self._right_strategy = RP_COMMON
|
||||
|
||||
def execute(self):
|
||||
if operators.client:
|
||||
users = operators.client.list(filter=BlUser)
|
||||
|
||||
for user in users:
|
||||
user_ref = operators.client.get(uuid=user)
|
||||
repo = operators.client
|
||||
if repo:
|
||||
settings = bpy.context.window_manager.session
|
||||
|
||||
# Local user
|
||||
if user_ref.pointer:
|
||||
# Find user
|
||||
if self._user is None:
|
||||
users = repo.list(filter=BlUser)
|
||||
|
||||
for user in users:
|
||||
user_node = repo.get(uuid=user)
|
||||
if user_node.pointer:
|
||||
self._user = user_node.pointer
|
||||
self._user_node = user_node
|
||||
|
||||
if self._right_strategy is None:
|
||||
self._right_strategy = repo.get_config()[
|
||||
'right_strategy']
|
||||
|
||||
if self._user:
|
||||
current_selection = utils.get_selected_objects(
|
||||
bpy.context.scene)
|
||||
if current_selection != self.last_selection:
|
||||
right_strategy = operators.client.get_config()[
|
||||
'right_strategy']
|
||||
if right_strategy == RP_COMMON:
|
||||
if current_selection != self._last_selection:
|
||||
if self._right_strategy == RP_COMMON:
|
||||
obj_common = [
|
||||
o for o in self.last_selection if o not in current_selection]
|
||||
o for o in self._last_selection if o not in current_selection]
|
||||
obj_ours = [
|
||||
o for o in current_selection if o not in self.last_selection]
|
||||
o for o in current_selection if o not in self._last_selection]
|
||||
|
||||
# change old selection right to common
|
||||
for obj in obj_common:
|
||||
node = repo.get(uuid=obj)
|
||||
|
||||
if node and (node.owner == settings.username or node.owner == RP_COMMON):
|
||||
recursive = True
|
||||
if node.data and 'instance_type' in node.data.keys():
|
||||
recursive = node.data['instance_type'] != 'COLLECTION'
|
||||
repo.change_owner(
|
||||
node.uuid,
|
||||
RP_COMMON,
|
||||
recursive=recursive)
|
||||
|
||||
# change new selection to our
|
||||
for obj in obj_ours:
|
||||
node = operators.client.get(uuid=obj)
|
||||
node = repo.get(uuid=obj)
|
||||
|
||||
if node and node.owner == RP_COMMON:
|
||||
recursive = True
|
||||
if node.data and 'instance_type' in node.data.keys():
|
||||
recursive = node.data['instance_type'] != 'COLLECTION'
|
||||
|
||||
operators.client.change_owner(
|
||||
repo.change_owner(
|
||||
node.uuid,
|
||||
settings.username,
|
||||
recursive=recursive)
|
||||
else:
|
||||
return
|
||||
|
||||
self.last_selection = current_selection
|
||||
user_ref.pointer.update_selected_objects(
|
||||
self._last_selection = current_selection
|
||||
self._user.update_selected_objects(
|
||||
bpy.context)
|
||||
user_ref.update()
|
||||
repo.push(self._user_node.uuid)
|
||||
|
||||
# change old selection right to common
|
||||
for obj in obj_common:
|
||||
node = operators.client.get(uuid=obj)
|
||||
|
||||
if node and (node.owner == settings.username or node.owner == RP_COMMON):
|
||||
recursive = True
|
||||
if node.data and 'instance_type' in node.data.keys():
|
||||
recursive = node.data['instance_type'] != 'COLLECTION'
|
||||
operators.client.change_owner(
|
||||
node.uuid,
|
||||
# Fix deselection until right managment refactoring (with Roles concepts)
|
||||
if len(current_selection) == 0 and self._right_strategy == RP_COMMON:
|
||||
owned_keys = repo.list(filter_owner=settings.username)
|
||||
for key in owned_keys:
|
||||
node = repo.get(uuid=key)
|
||||
if not isinstance(node, BlUser):
|
||||
repo.change_owner(
|
||||
key,
|
||||
RP_COMMON,
|
||||
recursive=recursive)
|
||||
else:
|
||||
for obj in bpy.data.objects:
|
||||
if obj.hide_select and obj.uuid not in user_ref.data['selected_objects']:
|
||||
obj.hide_select = False
|
||||
elif not obj.hide_select and obj.uuid in user_ref.data['selected_objects']:
|
||||
obj.hide_select = True
|
||||
|
||||
|
||||
class Draw(Delayable):
|
||||
|
Reference in New Issue
Block a user