mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
add retrieving drawings data from blender to web ui
This commit is contained in:
@@ -49,19 +49,12 @@ class WebNamespace(socketio.AsyncNamespace):
|
|||||||
async def on_disconnect(self, sid):
|
async def on_disconnect(self, sid):
|
||||||
print(f"Web client disconnected: {sid}")
|
print(f"Web client disconnected: {sid}")
|
||||||
|
|
||||||
async def on_join_room(self, sid, data):
|
|
||||||
room = data["room"]
|
|
||||||
await sio.enter_room(sid, room=room)
|
|
||||||
|
|
||||||
if room == "drawings":
|
|
||||||
await sio.emit("get_drawings_data", namespace="/blender")
|
|
||||||
|
|
||||||
async def on_web_operator(self, sid, data):
|
async def on_web_operator(self, sid, data):
|
||||||
await sio.emit(
|
await sio.emit(
|
||||||
"web_operator",
|
"web_operator",
|
||||||
data,
|
data,
|
||||||
namespace="/blender",
|
namespace="/blender",
|
||||||
room=data["blenderId"],
|
room=data.get("blenderId", None),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_cached_messages(self, sid):
|
async def send_cached_messages(self, sid):
|
||||||
@@ -109,6 +102,7 @@ class BlenderNamespace(socketio.AsyncNamespace):
|
|||||||
|
|
||||||
async def on_drawings_data(self, sid, data):
|
async def on_drawings_data(self, sid, data):
|
||||||
print(f"Drawings directory from Blender client {sid}")
|
print(f"Drawings directory from Blender client {sid}")
|
||||||
|
print(data)
|
||||||
blender_messages[sid]["drwings_data"] = data
|
blender_messages[sid]["drwings_data"] = data
|
||||||
await sio.emit("drawings_data", {"blenderId": sid, "data": data}, namespace="/web")
|
await sio.emit("drawings_data", {"blenderId": sid, "data": data}, namespace="/web")
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,15 @@ function connectSocket() {
|
|||||||
// socket.on("default_data", handleDefaultData);
|
// socket.on("default_data", handleDefaultData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function used to join drawings room
|
// function used to get drawings data from blenderbim
|
||||||
function handleWebConnect() {
|
function handleWebConnect() {
|
||||||
socket.emit("join_room", { room: "drawings" });
|
const msg = {
|
||||||
|
sourcePage: "drawings",
|
||||||
|
operator: {
|
||||||
|
type: "getDrawings",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
socket.emit("web_operator", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to handle 'blender_connect' event
|
// Function to handle 'blender_connect' event
|
||||||
@@ -57,7 +63,7 @@ function handleBlenderDisconnect(blenderId) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDrawingsData(blenderId) {
|
function handleDrawingsData(data) {
|
||||||
const blenderId = data["blenderId"];
|
const blenderId = data["blenderId"];
|
||||||
|
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|||||||
@@ -56,11 +56,9 @@
|
|||||||
<!-- Dropdown menu -->
|
<!-- Dropdown menu -->
|
||||||
<div class="dropdown mb-3">
|
<div class="dropdown mb-3">
|
||||||
<label for="dropdown-menu">IFC File</label>
|
<label for="dropdown-menu">IFC File</label>
|
||||||
<select class="w-50 p-0 pl-2" id="dropdown-menu">
|
<select class="p-0 pl-2" id="dropdown-menu">
|
||||||
<!-- IFC files will be dynamically populated here -->
|
<!-- IFC files will be dynamically populated here -->
|
||||||
<option value="option1">Option 1</option>
|
<option value="" selected disabled hidden>Select IFC File</option>
|
||||||
<option value="option2">Option 2</option>
|
|
||||||
<option value="option3">Option 3</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<!-- Panel with sub-panels -->
|
<!-- Panel with sub-panels -->
|
||||||
|
|||||||
@@ -280,6 +280,8 @@ class Web(blenderbim.core.tool.Web):
|
|||||||
cls.handle_csv_operator(operator["operator"])
|
cls.handle_csv_operator(operator["operator"])
|
||||||
elif operator["sourcePage"] == "gantt":
|
elif operator["sourcePage"] == "gantt":
|
||||||
cls.handle_gantt_operator(operator["operator"])
|
cls.handle_gantt_operator(operator["operator"])
|
||||||
|
elif operator["sourcePage"] == "drawings":
|
||||||
|
cls.handle_drawings_operator(operator["operator"])
|
||||||
return 1.0
|
return 1.0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -324,6 +326,29 @@ class Web(blenderbim.core.tool.Web):
|
|||||||
gantt_data = {"tasks": task_json, "work_schedule": work_schedule.get_info(recursive=True)}
|
gantt_data = {"tasks": task_json, "work_schedule": work_schedule.get_info(recursive=True)}
|
||||||
cls.send_webui_data(data=gantt_data, data_key="gantt_data", event="gantt_data")
|
cls.send_webui_data(data=gantt_data, data_key="gantt_data", event="gantt_data")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def handle_drawings_operator(cls, operator_data: dict) -> None:
|
||||||
|
if operator_data["type"] == "getDrawings":
|
||||||
|
drawings_data = []
|
||||||
|
sheets_data = []
|
||||||
|
ifc_file_dir = os.path.dirname(bpy.context.scene.BIMProperties.ifc_file)
|
||||||
|
|
||||||
|
sheets = [d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "SHEET"]
|
||||||
|
for sheet in sorted(sheets, key=lambda s: getattr(s, "Identification", getattr(s, "DocumentId", None))):
|
||||||
|
for reference in tool.Drawing.get_document_references(sheet):
|
||||||
|
reference_description = tool.Drawing.get_reference_description(reference)
|
||||||
|
reference_location = tool.Drawing.get_reference_location(reference)
|
||||||
|
reference_name = os.path.basename(reference_location)
|
||||||
|
reference_path = os.path.join(ifc_file_dir, reference_location)
|
||||||
|
if reference_description == "SHEET":
|
||||||
|
sheets_data.append({"name": reference_name, "path": reference_path})
|
||||||
|
if reference_description == "DRAWING":
|
||||||
|
drawings_data.append({"name": reference_name, "path": reference_path})
|
||||||
|
|
||||||
|
cls.send_webui_data(
|
||||||
|
data={"drawings": drawings_data, "sheets": sheets_data}, data_key="drawings_data", event="drawings_data"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def open_web_browser(cls, port: int) -> None:
|
def open_web_browser(cls, port: int) -> None:
|
||||||
webbrowser.open(f"http://127.0.0.1:{port}/")
|
webbrowser.open(f"http://127.0.0.1:{port}/")
|
||||||
|
|||||||
Reference in New Issue
Block a user