feat: expose bl_implementations settings

This commit is contained in:
Swann Martinez 2019-08-28 18:58:18 +02:00
parent c90c347f74
commit 42f896b389
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
15 changed files with 115 additions and 144 deletions

View File

@ -18,6 +18,7 @@ import bpy
from bpy.app.handlers import persistent from bpy.app.handlers import persistent
from . import environment, utils from . import environment, utils
# from . import bl_types
DEPENDENCIES = { DEPENDENCIES = {
("zmq","zmq"), ("zmq","zmq"),
@ -31,6 +32,20 @@ logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
# UTILITY FUNCTIONS # UTILITY FUNCTIONS
def generate_supported_types():
stype_dict = {'supported_types':{}}
for type in bl_types.types_to_register():
_type = getattr(bl_types, type)
props = {}
props['bl_delay_refresh']=_type.bl_delay_refresh
props['bl_delay_apply']=_type.bl_delay_apply
props['use_as_filter'] = False
props['icon'] = _type.bl_icon
# stype_dict[type]['bl_delay_apply']=_type.bl_delay_apply
stype_dict['supported_types'][_type.bl_rep_class.__name__] = props
return stype_dict
def client_list_callback(scene, context): def client_list_callback(scene, context):
from . import operators from . import operators
from .bl_types.bl_user import BlUser from .bl_types.bl_user import BlUser
@ -62,7 +77,8 @@ def randomColor():
def save_session_config(self,context): def save_session_config(self,context):
config = environment.load_config() config = environment.load_config()
if "supported_types" not in config:
config = generate_supported_types()
config["username"] = self.username config["username"] = self.username
config["ip"] = self.ip config["ip"] = self.ip
config["port"] = self.port config["port"] = self.port
@ -72,10 +88,11 @@ def save_session_config(self,context):
rep_type = {} rep_type = {}
for bloc in self.supported_datablock: for bloc in self.supported_datablock:
config["replicated_types"][bloc.type_name] = bloc.is_replicated config["supported_types"][bloc.type_name]['bl_delay_refresh'] = bloc.bl_delay_refresh
config["supported_types"][bloc.type_name]['bl_delay_apply'] = bloc.bl_delay_apply
config["supported_types"][bloc.type_name]['use_as_filter'] = bloc.use_as_filter
config["supported_types"][bloc.type_name]['icon'] = bloc.icon
# Generate ordered replicate types
environment.genererate_replicated_types()
# Save out the configuration file # Save out the configuration file
environment.save_config(config) environment.save_config(config)
@ -84,8 +101,10 @@ def save_session_config(self,context):
class ReplicatedDatablock(bpy.types.PropertyGroup): class ReplicatedDatablock(bpy.types.PropertyGroup):
'''name = StringProperty() ''' '''name = StringProperty() '''
type_name: bpy.props.StringProperty() type_name: bpy.props.StringProperty()
is_replicated: bpy.props.BoolProperty() bl_delay_refresh: bpy.props.FloatProperty()
bl_delay_apply: bpy.props.FloatProperty()
use_as_filter: bpy.props.BoolProperty(default=False)
icon: bpy.props.StringProperty()
class SessionProps(bpy.types.PropertyGroup): class SessionProps(bpy.types.PropertyGroup):
username: bpy.props.StringProperty( username: bpy.props.StringProperty(
@ -147,11 +166,14 @@ class SessionProps(bpy.types.PropertyGroup):
supported_datablock: bpy.props.CollectionProperty( supported_datablock: bpy.props.CollectionProperty(
type=ReplicatedDatablock, type=ReplicatedDatablock,
) )
session_filter: bpy.props.CollectionProperty(
type=ReplicatedDatablock,
)
def load(self): def load(self):
config = environment.load_config() config = environment.load_config()
logger.info(config) logger.info(config)
if "username" in config: if "username" in config.keys():
self.username = config["username"] self.username = config["username"]
self.ip = config["ip"] self.ip = config["ip"]
self.port = config["port"] self.port = config["port"]
@ -163,13 +185,15 @@ class SessionProps(bpy.types.PropertyGroup):
if len(self.supported_datablock)>0: if len(self.supported_datablock)>0:
self.supported_datablock.clear() self.supported_datablock.clear()
if "supported_types" not in config:
for datablock,enabled in config["replicated_types"].items(): config = generate_supported_types()
for datablock in config["supported_types"].keys():
rep_value = self.supported_datablock.add() rep_value = self.supported_datablock.add()
rep_value.name = datablock rep_value.name = datablock
rep_value.type_name = datablock rep_value.type_name = datablock
rep_value.is_replicated = enabled rep_value.bl_delay_refresh = config["supported_types"][datablock]['bl_delay_refresh']
rep_value.bl_delay_apply = config["supported_types"][datablock]['bl_delay_apply']
rep_value.icon = config["supported_types"][datablock]['icon']
def save(self,context): def save(self,context):
config = environment.load_config() config = environment.load_config()
@ -182,8 +206,10 @@ class SessionProps(bpy.types.PropertyGroup):
for bloc in self.supported_datablock: for bloc in self.supported_datablock:
config["replicated_types"][bloc.type_name] = bloc.is_replicated config["supported_types"][bloc.type_name]['bl_delay_refresh'] = bloc.bl_delay_refresh
config["supported_types"][bloc.type_name]['bl_delay_apply'] = bloc.bl_delay_apply
config["supported_types"][bloc.type_name]['use_as_filter'] = bloc.use_as_filter
config["supported_types"][bloc.type_name]['icon'] = bloc.icon
environment.save_config(config) environment.save_config(config)

View File

@ -36,4 +36,5 @@ bl_class = bpy.types.Camera
bl_rep_class = BlCamera bl_rep_class = BlCamera
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'CAMERA_DATA'

View File

@ -6,11 +6,6 @@ from .bl_datablock import BlDatablock
class BlCollection(BlDatablock): class BlCollection(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'FILE_FOLDER'
super().__init__(*args, **kwargs)
def construct(self,data): def construct(self,data):
return bpy.data.collections.new(data["name"]) return bpy.data.collections.new(data["name"])
@ -65,6 +60,7 @@ class BlCollection(BlDatablock):
return deps return deps
bl_id = "collections" bl_id = "collections"
bl_icon = 'FILE_FOLDER'
bl_class = bpy.types.Collection bl_class = bpy.types.Collection
bl_rep_class = BlCollection bl_rep_class = BlCollection
bl_delay_refresh = 1 bl_delay_refresh = 1

View File

@ -6,11 +6,6 @@ from .. import utils
from .bl_datablock import BlDatablock from .bl_datablock import BlDatablock
class BlCurve(BlDatablock): class BlCurve(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'CURVE_DATA'
super().__init__( *args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.curves.new(data["name"], 'CURVE') return bpy.data.curves.new(data["name"], 'CURVE')
@ -57,4 +52,5 @@ bl_class = bpy.types.Curve
bl_rep_class = BlCurve bl_rep_class = BlCurve
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'CURVE_DATA'

View File

@ -34,11 +34,6 @@ def load_gpencil_layer(target=None, data=None, create=False):
class BlGpencil(BlDatablock): class BlGpencil(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'GREASEPENCIL'
super().__init__(*args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.grease_pencils.new(data["name"]) return bpy.data.grease_pencils.new(data["name"])
@ -91,4 +86,5 @@ bl_class = bpy.types.GreasePencil
bl_rep_class = BlGpencil bl_rep_class = BlGpencil
bl_delay_refresh = 5 bl_delay_refresh = 5
bl_delay_apply = 5 bl_delay_apply = 5
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'GREASEPENCIL'

View File

@ -23,11 +23,6 @@ def dump_image(image):
return pixels return pixels
class BlImage(BlDatablock): class BlImage(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'IMAGE_DATA'
super().__init__( *args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.images.new( return bpy.data.images.new(
name=data['name'], name=data['name'],
@ -73,4 +68,5 @@ bl_class = bpy.types.Image
bl_rep_class = BlImage bl_rep_class = BlImage
bl_delay_refresh = 0 bl_delay_refresh = 0
bl_delay_apply = 0 bl_delay_apply = 0
bl_automatic_push = False bl_automatic_push = False
bl_icon = 'IMAGE_DATA'

View File

@ -7,11 +7,6 @@ from .bl_datablock import BlDatablock
class BlLight(BlDatablock): class BlLight(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'LIGHT_DATA'
super().__init__(*args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.lights.new(data["name"], data["type"]) return bpy.data.lights.new(data["name"], data["type"])
@ -37,4 +32,5 @@ bl_class = bpy.types.Light
bl_rep_class = BlLight bl_rep_class = BlLight
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'LIGHT_DATA'

View File

@ -7,11 +7,6 @@ from .bl_datablock import BlDatablock
class BlMaterial(BlDatablock): class BlMaterial(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'MATERIAL_DATA'
super().__init__(*args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.materials.new(data["name"]) return bpy.data.materials.new(data["name"])
@ -104,4 +99,5 @@ bl_class = bpy.types.Material
bl_rep_class = BlMaterial bl_rep_class = BlMaterial
bl_delay_refresh = 5 bl_delay_refresh = 5
bl_delay_apply = 5 bl_delay_apply = 5
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'MATERIAL_DATA'

View File

@ -71,11 +71,6 @@ def dump_mesh(mesh, data={}):
return mesh_data return mesh_data
class BlMesh(BlDatablock): class BlMesh(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'MESH_DATA'
super().__init__( *args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.meshes.new(data["name"]) return bpy.data.meshes.new(data["name"])
@ -181,3 +176,4 @@ bl_rep_class = BlMesh
bl_delay_refresh = 10 bl_delay_refresh = 10
bl_delay_apply = 10 bl_delay_apply = 10
bl_automatic_push = False bl_automatic_push = False
bl_icon = 'MESH_DATA'

View File

@ -6,11 +6,6 @@ from .bl_datablock import BlDatablock
class BlObject(BlDatablock): class BlObject(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'OBJECT_DATA'
super().__init__(*args, **kwargs)
def construct(self, data): def construct(self, data):
pointer = None pointer = None
@ -85,4 +80,5 @@ bl_class = bpy.types.Object
bl_rep_class = BlObject bl_rep_class = BlObject
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'OBJECT_DATA'

View File

@ -6,11 +6,6 @@ from .. import utils
from .bl_datablock import BlDatablock from .bl_datablock import BlDatablock
class BlScene(BlDatablock): class BlScene(BlDatablock):
def __init__(self, *args, **kwargs):
self.icon = 'SCENE_DATA'
super().__init__( *args, **kwargs)
def construct(self, data): def construct(self, data):
return bpy.data.scenes.new(data["name"]) return bpy.data.scenes.new(data["name"])
@ -76,4 +71,5 @@ bl_class = bpy.types.Scene
bl_rep_class = BlScene bl_rep_class = BlScene
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'SCENE_DATA'

View File

@ -12,11 +12,10 @@ from ..libs.debug import draw_point
class BlUser(BlDatablock): class BlUser(BlDatablock):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__( *args, **kwargs) super().__init__( *args, **kwargs)
self.icon = 'CON_ARMATURE'
if self.buffer: if self.buffer:
self.load(self.buffer, self.pointer) self.load(self.buffer, self.pointer)
def construct(self, name): def construct(self, name):
return presence.User() return presence.User()
@ -59,4 +58,5 @@ bl_class = presence.User
bl_rep_class = BlUser bl_rep_class = BlUser
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_icon = 'CON_ARMATURE'

View File

@ -15,28 +15,6 @@ THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache") CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache")
PYTHON_PATH = None PYTHON_PATH = None
SUBPROCESS_DIR = None SUBPROCESS_DIR = None
DEFAULT_CONFIG = {
"replicated_types": {
'Client': True,
'Image': True,
'Texture': True,
'Curve': True,
'Material': True,
'Light': True,
'SunLight': True,
'SpotLight': True,
'AreaLight': True,
'PointLight': True,
'Camera': True,
'Mesh': True,
'Armature': True,
'GreasePencil': True,
'Object': True,
'Action': True,
'Collection': True,
'Scene': True
}
}
ORDERED_TYPES = [ ORDERED_TYPES = [
'Image', 'Image',
@ -69,31 +47,7 @@ def load_config():
return yaml.safe_load(config_file) return yaml.safe_load(config_file)
except FileNotFoundError: except FileNotFoundError:
logger.info("no config") logger.info("no config")
return {}
return DEFAULT_CONFIG
def get_replicated_types():
config = load_config()
rtpyes = config["replicated_types"]
tlist = []
for t in ORDERED_TYPES:
if rtpyes[t]:
tlist.append(t)
return tlist
def genererate_replicated_types():
rtypes.clear()
cfg = load_config()
replicated_types = cfg['replicated_types']
for t in ORDERED_TYPES:
if replicated_types[t]:
rtypes.append(t)
def save_config(config): def save_config(config):
import yaml import yaml

View File

@ -74,16 +74,16 @@ class SessionStartOperator(bpy.types.Operator):
for type in bl_types.types_to_register(): for type in bl_types.types_to_register():
_type = getattr(bl_types, type) _type = getattr(bl_types, type)
supported_bl_types.append(_type.bl_id) supported_bl_types.append(_type.bl_id)
type_local_config = settings.supported_datablock[_type.bl_rep_class.__name__]
bpy_factory.register_type( bpy_factory.register_type(
_type.bl_class, _type.bl_class,
_type.bl_rep_class, _type.bl_rep_class,
timer=_type.bl_delay_refresh, timer=type_local_config.bl_delay_refresh,
automatic=_type.bl_automatic_push) automatic=_type.bl_automatic_push)
if _type.bl_delay_apply > 0: if type_local_config.bl_delay_apply > 0:
delayables.append(delayable.ApplyTimer( delayables.append(delayable.ApplyTimer(
timout=_type.bl_delay_apply, timout=type_local_config.bl_delay_apply,
target_type=_type.bl_rep_class)) target_type=_type.bl_rep_class))
client = Session(factory=bpy_factory) client = Session(factory=bpy_factory)

74
ui.py
View File

@ -4,12 +4,12 @@ from .libs.replication.replication.constants import FETCHED, ERROR, MODIFIED, UP
from .bl_types.bl_user import BlUser from .bl_types.bl_user import BlUser
PROP_STATES = ['FILE_REFRESH', # ADDED ICONS_PROP_STATES = ['FILE_REFRESH', # ADDED
'TRIA_UP', # COMMITED 'TRIA_UP', # COMMITED
'KEYTYPE_KEYFRAME_VEC', # PUSHED 'KEYTYPE_KEYFRAME_VEC', # PUSHED
'TRIA_DOWN', # FETCHED 'TRIA_DOWN', # FETCHED
'FILE_REFRESH', # UP 'FILE_REFRESH', # UP
'TRIA_UP'] # CHANGED 'TRIA_UP'] # CHANGED
class SESSION_PT_settings(bpy.types.Panel): class SESSION_PT_settings(bpy.types.Panel):
@ -33,17 +33,6 @@ class SESSION_PT_settings(bpy.types.Panel):
if not operators.client \ if not operators.client \
or (operators.client and operators.client.state == 0): or (operators.client and operators.client.state == 0):
pass pass
# REPLICATION SETTINGS
# row = layout.row()
# box = row.box()
# row = box.row()
# row.label(text="REPLICATION", icon='TRIA_RIGHT')
# row = box.row()
# for item in window_manager.session.supported_datablock:
# row.label(text=item.type_name,icon=ICONS[item.type_name])
# row.prop(item, "is_replicated", text="")
# row = box.row()
else: else:
# STATE ACTIVE # STATE ACTIVE
if operators.client.state == 2: if operators.client.state == 2:
@ -138,6 +127,34 @@ class SESSION_PT_settings_user(bpy.types.Panel):
row = layout.row() row = layout.row()
class SESSION_PT_settings_replication(bpy.types.Panel):
bl_idname = "MULTIUSER_SETTINGS_REPLICATION_PT_panel"
bl_label = "Replication"
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 not operators.client \
or (operators.client and operators.client.state == 0)
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
flow = layout.grid_flow(
row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
for item in settings.supported_datablock:
line = flow.column(align=True)
line.label(text=item.type_name,icon=item.icon)
line.prop(item, "bl_delay_refresh", text="refresh time")
line.prop(item, "bl_delay_apply", text="apply timer")
class SESSION_PT_user(bpy.types.Panel): class SESSION_PT_user(bpy.types.Panel):
bl_idname = "MULTIUSER_USER_PT_panel" bl_idname = "MULTIUSER_USER_PT_panel"
bl_label = "Users" bl_label = "Users"
@ -208,7 +225,8 @@ def draw_property(context, parent, property_uuid, level=0):
detail_item_box = line.row(align=True) detail_item_box = line.row(align=True)
detail_item_box.label(text="", icon=item.icon) detail_item_box.label(text="",
icon=settings.supported_datablock[item.str_type].icon)
detail_item_box.label(text="{} ".format(name)) detail_item_box.label(text="{} ".format(name))
# Operations # Operations
@ -219,14 +237,14 @@ def draw_property(context, parent, property_uuid, level=0):
detail_item_box.operator( detail_item_box.operator(
"session.apply", "session.apply",
text="", text="",
icon=PROP_STATES[item.state]).target = item.uuid icon=ICONS_PROP_STATES[item.state]).target = item.uuid
elif item.state == MODIFIED: elif item.state == MODIFIED:
detail_item_box.operator( detail_item_box.operator(
"session.commit", "session.commit",
text="", text="",
icon=PROP_STATES[item.state]).target = item.uuid icon=ICONS_PROP_STATES[item.state]).target = item.uuid
else: else:
detail_item_box.label(text="", icon=PROP_STATES[item.state]) detail_item_box.label(text="", icon=ICONS_PROP_STATES[item.state])
right_icon = "DECORATE_UNLOCKED" right_icon = "DECORATE_UNLOCKED"
if item.owner != settings.username: if item.owner != settings.username:
@ -240,7 +258,8 @@ def draw_property(context, parent, property_uuid, level=0):
detail_item_box.operator( detail_item_box.operator(
"session.remove_prop", text="", icon="X").property_path = property_uuid "session.remove_prop", text="", icon="X").property_path = property_uuid
else: else:
detail_item_box.label( text="", icon="DECORATE_LOCKED") detail_item_box.label(text="", icon="DECORATE_LOCKED")
class SESSION_PT_outliner(bpy.types.Panel): class SESSION_PT_outliner(bpy.types.Panel):
bl_idname = "MULTIUSER_PROPERTIES_PT_panel" bl_idname = "MULTIUSER_PROPERTIES_PT_panel"
@ -262,8 +281,14 @@ class SESSION_PT_outliner(bpy.types.Panel):
if hasattr(context.window_manager, 'session'): if hasattr(context.window_manager, 'session'):
settings = context.window_manager.session settings = context.window_manager.session
row = layout.row() # row.prop(settings, 'outliner_filter', text="")
row.prop(settings, 'outliner_filter', text="") flow = layout.grid_flow(
row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
for item in settings.supported_datablock:
col = flow.column()
col.prop(item,"use_as_filter",text="", icon=item.icon)
# row.prop(item, "is_replicated", text="")
row = layout.row(align=True) row = layout.row(align=True)
# Property area # Property area
@ -283,6 +308,7 @@ classes = (
SESSION_PT_settings, SESSION_PT_settings,
SESSION_PT_settings_user, SESSION_PT_settings_user,
SESSION_PT_settings_network, SESSION_PT_settings_network,
SESSION_PT_settings_replication,
SESSION_PT_user, SESSION_PT_user,
SESSION_PT_outliner, SESSION_PT_outliner,