add data.py for web module and sending data via ws connection

This commit is contained in:
Ziad-I
2024-06-15 14:40:33 +03:00
committed by Dion Moult
parent f7d55a4a4a
commit 0aad3d99b5
4 changed files with 53 additions and 11 deletions
+2
View File
@@ -191,6 +191,8 @@ def refresh_ui_data():
tool.Ifc.get().clear_cache()
bpy.context.scene.DocProperties.should_draw_decorations = bpy.context.scene.DocProperties.should_draw_decorations
if bpy.context.scene.WebProperties.is_connected:
tool.Web.send_webui_data()
@persistent
@@ -0,0 +1,40 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.tool as tool
def refresh():
WebData.is_loaded = False
class WebData:
data = {}
is_loaded = False
@classmethod
def load(cls):
cls.data = {
"IFC_File": cls.ifc_file_name(),
}
cls.is_loaded = True
@classmethod
def ifc_file_name(cls):
return bpy.context.scene.BIMProperties.ifc_file
@@ -17,6 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
from bpy.types import Panel
from blenderbim.bim.module.web.data import WebData
class BIM_PT_webui(Panel):
@@ -29,6 +30,10 @@ class BIM_PT_webui(Panel):
bl_parent_id = "BIM_PT_tab_collaboration"
def draw(self, context):
if not WebData.is_loaded:
WebData.load()
layout = self.layout
scene = context.scene
+6 -11
View File
@@ -17,9 +17,8 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import json
from blenderbim.bim.module.web.data import WebData
import blenderbim.core.tool
from typing import Union, Literal
import socket
import os
import subprocess
@@ -27,8 +26,6 @@ import webbrowser
import asyncio
import socketio
import threading
import json
sio = None
ws_process = None
@@ -79,6 +76,7 @@ class Web(blenderbim.core.tool.Web):
ws_url = f"ws://localhost:{port}/blender"
ws_thread.run_coro(cls.sio_connect(ws_url))
cls.set_is_connected(True)
cls.send_webui_data()
@classmethod
def disconnect_websocket_server(cls):
@@ -110,14 +108,11 @@ class Web(blenderbim.core.tool.Web):
@classmethod
def send_webui_data(cls):
global ws_thread
data = cls.get_webui_data()
ws_thread.run_coro(cls.sio_send(data))
@classmethod
def get_webui_data(cls):
data = {}
data["ifc_file"] = bpy.context.scene.BIMProperties.ifc_file
return json.dumps(data)
if not WebData.is_loaded:
WebData.load()
ws_thread.run_coro(cls.sio_send(WebData.data))
@classmethod
def open_web_browser(cls, port):