feat: parent reloading support for file dependent nodes

This commit is contained in:
Swann 2020-12-09 14:49:26 +01:00
parent 2ab0a75608
commit af6d54296a
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
27 changed files with 74 additions and 38 deletions

View File

@ -137,6 +137,7 @@ class BlAction(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'ACTION_TWEAK'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.actions.new(data["name"])

View File

@ -33,6 +33,7 @@ class BlArmature(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'ARMATURE_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.armatures.new(data["name"])

View File

@ -31,6 +31,7 @@ class BlCamera(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'CAMERA_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.cameras.new(data["name"])

View File

@ -89,6 +89,7 @@ class BlCollection(BlDatablock):
bl_delay_apply = 1
bl_automatic_push = True
bl_check_common = True
bl_reload_parent = False
def _construct(self, data):
if self.is_library:

View File

@ -146,6 +146,7 @@ class BlCurve(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'CURVE_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.curves.new(data["name"], data["type"])

View File

@ -111,8 +111,10 @@ class BlDatablock(ReplicatedDatablock):
bl_automatic_push : boolean
bl_icon : type icon (blender icon name)
bl_check_common: enable check even in common rights
bl_reload_parent: reload parent
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
instance = kwargs.get('instance', None)

View File

@ -54,11 +54,12 @@ class BlFile(ReplicatedDatablock):
bl_id = 'file'
bl_name = "file"
bl_class = Path
bl_delay_refresh = 0
bl_delay_refresh = 2
bl_delay_apply = 1
bl_automatic_push = True
bl_check_common = False
bl_icon = 'FILE'
bl_reload_parent = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -118,11 +119,7 @@ class BlFile(ReplicatedDatablock):
"""
Writing the file
"""
# TODO: check for empty data
if target.exists() and not self.diff():
logging.info(f"{data['name']} already on the disk, skipping.")
return
try:
file = open(target, "wb")
file.write(data['file'])
@ -140,4 +137,4 @@ class BlFile(ReplicatedDatablock):
else:
memory_size = sys.getsizeof(self.data['file'])-33
disk_size = self.instance.stat().st_size
return memory_size == disk_size
return memory_size != disk_size

View File

@ -35,6 +35,7 @@ class BlFont(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'FILE_FONT'
bl_reload_parent = False
def _construct(self, data):
filename = data.get('filename')

View File

@ -235,6 +235,7 @@ class BlGpencil(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'GREASEPENCIL'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.grease_pencils.new(data["name"])

View File

@ -56,6 +56,7 @@ class BlImage(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'IMAGE_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.images.new(
@ -71,7 +72,6 @@ class BlImage(BlDatablock):
target.source = 'FILE'
target.filepath_raw = get_filepath(data['filename'])
target.colorspace_settings.name = data["colorspace_settings"]["name"]
def _dump(self, instance=None):
assert(instance)
@ -103,21 +103,21 @@ class BlImage(BlDatablock):
def _resolve_deps_implementation(self):
deps = []
if self.instance.packed_file:
filename = Path(bpy.path.abspath(self.instance.filepath)).name
self.instance.filepath_raw = get_filepath(filename)
self.instance.save()
# An image can't be unpacked to the modified path
# TODO: make a bug report
self.instance.unpack(method="REMOVE")
elif self.instance.source == "GENERATED":
filename = f"{self.instance.name}.png"
self.instance.filepath = get_filepath(filename)
self.instance.save()
if self.instance.filepath:
if self.instance.packed_file:
filename = Path(bpy.path.abspath(self.instance.filepath)).name
self.instance.filepath_raw = get_filepath(filename)
self.instance.save()
# An image can't be unpacked to the modified path
# TODO: make a bug report
self.instance.unpack(method="REMOVE")
elif self.instance.source == "GENERATED":
filename = f"{self.instance.name}.png"
self.instance.filepath = get_filepath(filename)
self.instance.save()
deps.append(Path(bpy.path.abspath(self.instance.filepath)))
return deps

View File

@ -34,6 +34,7 @@ class BlLattice(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'LATTICE_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.lattices.new(data["name"])

View File

@ -31,6 +31,7 @@ class BlLibrary(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'LIBRARY_DATA_DIRECT'
bl_reload_parent = False
def _construct(self, data):
with bpy.data.libraries.load(filepath=data["filepath"], link=True) as (sourceData, targetData):

View File

@ -31,6 +31,7 @@ class BlLight(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'LIGHT_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.lights.new(data["name"], data["type"])

View File

@ -32,6 +32,7 @@ class BlLightprobe(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'LIGHTPROBE_GRID'
bl_reload_parent = False
def _construct(self, data):
type = 'CUBE' if data['type'] == 'CUBEMAP' else data['type']

View File

@ -327,6 +327,7 @@ class BlMaterial(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'MATERIAL_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.materials.new(data["name"])

View File

@ -54,6 +54,7 @@ class BlMesh(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'MESH_DATA'
bl_reload_parent = False
def _construct(self, data):
instance = bpy.data.meshes.new(data["name"])

View File

@ -70,6 +70,7 @@ class BlMetaball(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'META_BALL'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.metaballs.new(data["name"])

View File

@ -33,6 +33,7 @@ class BlNodeGroup(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'NODETREE'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.node_groups.new(data["name"], data["type"])

View File

@ -102,6 +102,7 @@ class BlObject(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'OBJECT_DATA'
bl_reload_parent = False
def _construct(self, data):
instance = None

View File

@ -278,6 +278,7 @@ class BlScene(BlDatablock):
bl_automatic_push = True
bl_check_common = True
bl_icon = 'SCENE_DATA'
bl_reload_parent = False
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -130,6 +130,7 @@ class BlSequencer(BlDatablock):
bl_automatic_push = True
bl_check_common = True
bl_icon = 'SEQUENCE'
bl_reload_parent = False
def _construct(self, data):
# Get the scene

View File

@ -35,6 +35,7 @@ class BlSound(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'SOUND'
bl_reload_parent = False
def _construct(self, data):
filename = data.get('filename')

View File

@ -31,6 +31,7 @@ class BlSpeaker(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'SPEAKER'
bl_reload_parent = False
def _load_implementation(self, data, target):
loader = Loader()

View File

@ -31,6 +31,7 @@ class BlTexture(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'TEXTURE'
bl_reload_parent = False
def _load_implementation(self, data, target):
loader = Loader()

View File

@ -32,6 +32,7 @@ class BlVolume(BlDatablock):
bl_automatic_push = True
bl_check_common = False
bl_icon = 'VOLUME_DATA'
bl_reload_parent = False
def _load_implementation(self, data, target):
loader = Loader()

View File

@ -34,6 +34,7 @@ class BlWorld(BlDatablock):
bl_automatic_push = True
bl_check_common = True
bl_icon = 'WORLD_DATA'
bl_reload_parent = False
def _construct(self, data):
return bpy.data.worlds.new(data["name"])

View File

@ -41,10 +41,12 @@ from replication.constants import (FETCHED,
from replication.interface import session
from replication.exception import NonAuthorizedOperationError
def is_annotating(context:bpy.types.Context):
def is_annotating(context: bpy.types.Context):
""" Check if the annotate mode is enabled
"""
return bpy.context.workspace.tools.from_space_view3d_mode('OBJECT', create=False).idname == 'builtin.annotate'
return bpy.context.workspace.tools.from_space_view3d_mode('OBJECT', create=False).idname == 'builtin.annotate'
class Delayable():
"""Delayable task interface
@ -126,7 +128,14 @@ class ApplyTimer(Timer):
session.apply(node)
except Exception as e:
logging.error(f"Fail to apply {node_ref.uuid}: {e}")
else:
if self._type.bl_reload_parent:
parents = []
for n in session.list():
deps = session.get(uuid=n).dependencies
if deps and node in deps:
session.apply(n, force=True)
class DynamicRightSelectTimer(Timer):
def __init__(self, timout=.1):
@ -146,27 +155,28 @@ class DynamicRightSelectTimer(Timer):
if self._user:
ctx = bpy.context
annotation_gp = ctx.scene.grease_pencil
annotation_gp = ctx.scene.grease_pencil
# if an annotation exist and is tracked
if annotation_gp and annotation_gp.uuid:
registered_gp = session.get(uuid=annotation_gp.uuid)
if is_annotating(bpy.context):
if is_annotating(bpy.context):
# try to get the right on it
if registered_gp.owner == RP_COMMON:
self._annotating = True
logging.debug("Getting the right on the annotation GP")
logging.debug(
"Getting the right on the annotation GP")
session.change_owner(
registered_gp.uuid,
settings.username,
ignore_warnings=True,
affect_dependencies=False)
elif self._annotating:
registered_gp.uuid,
settings.username,
ignore_warnings=True,
affect_dependencies=False)
elif self._annotating:
session.change_owner(
registered_gp.uuid,
RP_COMMON,
ignore_warnings=True,
affect_dependencies=False)
registered_gp.uuid,
RP_COMMON,
ignore_warnings=True,
affect_dependencies=False)
current_selection = utils.get_selected_objects(
bpy.context.scene,
@ -193,7 +203,8 @@ class DynamicRightSelectTimer(Timer):
ignore_warnings=True,
affect_dependencies=recursive)
except NonAuthorizedOperationError:
logging.warning(f"Not authorized to change {node} owner")
logging.warning(
f"Not authorized to change {node} owner")
# change new selection to our
for obj in obj_ours:
@ -211,7 +222,8 @@ class DynamicRightSelectTimer(Timer):
ignore_warnings=True,
affect_dependencies=recursive)
except NonAuthorizedOperationError:
logging.warning(f"Not authorized to change {node} owner")
logging.warning(
f"Not authorized to change {node} owner")
else:
return
@ -237,7 +249,8 @@ class DynamicRightSelectTimer(Timer):
ignore_warnings=True,
affect_dependencies=recursive)
except NonAuthorizedOperationError:
logging.warning(f"Not authorized to change {key} owner")
logging.warning(
f"Not authorized to change {key} owner")
for obj in bpy.data.objects:
object_uuid = getattr(obj, 'uuid', None)
@ -246,6 +259,7 @@ class DynamicRightSelectTimer(Timer):
if obj.hide_select != is_selectable:
obj.hide_select = is_selectable
class ClientUpdate(Timer):
def __init__(self, timout=.1):
super().__init__(timout)