refactor web ui operator handling

This commit is contained in:
Ziad-I
2024-06-29 01:51:43 +03:00
parent b7662a122b
commit ddd07b4894
3 changed files with 25 additions and 17 deletions
@@ -38,7 +38,7 @@ class WebNamespace(socketio.AsyncNamespace):
async def on_web_operator(self, sid, data):
await sio.emit(
"web_operator",
data["operator"],
data,
namespace="/blender",
room=data["blenderId"],
)
@@ -167,10 +167,11 @@ function addTableElement(blenderId, csvData, filename) {
var tableId = row.getTable().element.id.substr(6);
const msg = {
sourcePage: "csv",
blenderId: tableId,
operator: {
type: "selection",
GlobalId: index,
globalId: index,
},
};
socket.emit("web_operator", msg);
+22 -15
View File
@@ -141,20 +141,29 @@ class Web(blenderbim.core.tool.Web):
return None # unregister timer if not connected
while not web_operator_queue.empty():
operator_data = web_operator_queue.get_nowait()
if not operator_data:
operator = web_operator_queue.get_nowait()
if not operator:
continue
if operator_data["type"] == "selection":
bpy.ops.object.select_all(action="DESELECT")
guid = operator_data["GlobalId"]
ele = tool.Ifc.get().by_guid(guid)
obj = tool.Ifc.get_object(ele)
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
if operator["sourcePage"] == "csv":
cls.handle_csv_operator(operator["operator"])
elif operator["sourcePage"] == "gantt":
cls.handle_gantt_operator(operator["operator"])
return 1.0
@classmethod
def handle_csv_operator(cls, operator_data):
if operator_data["type"] == "selection":
bpy.ops.object.select_all(action="DESELECT")
guid = operator_data["globalId"]
ele = tool.Ifc.get().by_guid(guid)
obj = tool.Ifc.get_object(ele)
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
@classmethod
def handle_gantt_operator(cls, operator_data):
pass
@classmethod
def open_web_browser(cls, port):
webbrowser.open(f"http://127.0.0.1:{port}/")
@@ -162,9 +171,7 @@ class Web(blenderbim.core.tool.Web):
@classmethod
async def sio_connect(cls, url):
await sio.connect(url, transports=["websocket"], namespaces="/blender")
# TODO: register event handlers to handle incoming messages
sio.on("web_operator", cls.sio_handle_web_operator, namespace="/blender")
sio.on("web_operator", cls.sio_listen_web_operator, namespace="/blender")
@classmethod
async def sio_disconnect(cls):
@@ -175,7 +182,7 @@ class Web(blenderbim.core.tool.Web):
await sio.emit(event, data, namespace=namespace)
@classmethod
async def sio_handle_web_operator(cls, data):
async def sio_listen_web_operator(cls, data):
try:
web_operator_queue.put_nowait(data)
except queue.Full: