2019-08-14 00:00:54 +08:00
|
|
|
import bpy
|
|
|
|
from .libs.replication.constants import *
|
2019-08-14 03:32:15 +08:00
|
|
|
from .libs import debug
|
2019-08-14 20:25:20 +08:00
|
|
|
from . import operators, utils
|
2019-08-14 03:32:15 +08:00
|
|
|
from .bl_types.bl_user import BlUser
|
2019-08-14 00:00:54 +08:00
|
|
|
|
|
|
|
class Delayable():
|
2019-08-14 21:01:30 +08:00
|
|
|
"""Delayable task interface
|
|
|
|
"""
|
2019-08-14 00:00:54 +08:00
|
|
|
def register(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def unregister(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
class Timer(Delayable):
|
|
|
|
"""Timer binder interface for blender
|
|
|
|
|
|
|
|
Run a bpy.app.Timer in the background looping at the given rate
|
|
|
|
"""
|
|
|
|
def __init__(self, duration=1):
|
|
|
|
self._timeout = duration
|
|
|
|
|
|
|
|
def register(self):
|
|
|
|
"""Register the timer into the blender timer system
|
|
|
|
"""
|
|
|
|
bpy.app.timers.register(self.execute)
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
"""Main timer loop
|
|
|
|
"""
|
|
|
|
return self._timeout
|
|
|
|
|
|
|
|
def unregister(self):
|
|
|
|
"""Unnegister the timer of the blender timer system
|
|
|
|
"""
|
2019-08-14 03:32:15 +08:00
|
|
|
try:
|
|
|
|
bpy.app.timers.unregister(self.execute)
|
|
|
|
except:
|
|
|
|
print("timer already unregistered")
|
2019-08-14 00:00:54 +08:00
|
|
|
|
|
|
|
class ApplyTimer(Timer):
|
|
|
|
def __init__(self, timout=1,target_type=None):
|
|
|
|
self._type = target_type
|
|
|
|
super().__init__(timout)
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
if operators.client:
|
|
|
|
nodes = operators.client.list(filter=self._type)
|
|
|
|
|
|
|
|
for node in nodes:
|
|
|
|
node_ref = operators.client.get(node)
|
|
|
|
|
|
|
|
if node_ref.state == FETCHED:
|
|
|
|
operators.client.apply(uuid=node)
|
|
|
|
|
|
|
|
return self._timeout
|
|
|
|
|
|
|
|
class Draw(Delayable):
|
|
|
|
def __init__(self):
|
|
|
|
self._handler = None
|
|
|
|
|
|
|
|
def register(self):
|
|
|
|
self._handler = bpy.types.SpaceView3D.draw_handler_add(
|
|
|
|
self.execute,(), 'WINDOW', 'POST_VIEW')
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def unregister(self):
|
2019-08-14 03:32:15 +08:00
|
|
|
try:
|
|
|
|
bpy.types.SpaceView3D.draw_handler_remove(
|
|
|
|
self._handler, "WINDOW")
|
|
|
|
except:
|
|
|
|
print("draw already unregistered")
|
|
|
|
|
2019-08-14 00:00:54 +08:00
|
|
|
class ClientUpdate(Draw):
|
|
|
|
def __init__(self, client_uuid=None):
|
|
|
|
assert(client_uuid)
|
|
|
|
self._client_uuid = client_uuid
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def execute(self):
|
2019-08-22 21:35:21 +08:00
|
|
|
if hasattr(operators,"client") and self._client_uuid:
|
2019-08-14 03:32:15 +08:00
|
|
|
client = operators.client.get(self._client_uuid)
|
|
|
|
|
|
|
|
if client:
|
|
|
|
client.pointer.update_location()
|
2019-08-14 20:25:20 +08:00
|
|
|
|