-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
682 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server_temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
[procedures] | ||
script_dir = "./procedures" | ||
script_dir = "./procedures" | ||
|
||
[websockets] | ||
server_temp_dir = "./server_temp" | ||
auto_load_files = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,50 @@ | ||
from __future__ import annotations | ||
|
||
import pathlib | ||
import platform | ||
import shutil | ||
import subprocess | ||
from typing import TYPE_CHECKING | ||
|
||
import ada | ||
from ada.cadit.ifc.ifc2sql import Ifc2SqlPatcher | ||
from ada.cadit.ifc.sql_model import IfcSqlModel | ||
from ada.comms.fb_model_gen import FileTypeDC, MessageDC | ||
from ada.comms.fb_model_gen import FileObjectDC, FileTypeDC | ||
from ada.config import logger | ||
|
||
if TYPE_CHECKING: | ||
from ada.comms.wsock_server import ConnectedClient, WebSocketAsyncServer | ||
|
||
|
||
def update_server(server: WebSocketAsyncServer, client: ConnectedClient, message: MessageDC) -> None: | ||
def update_server(server: WebSocketAsyncServer, client: ConnectedClient, add_file: FileObjectDC) -> None: | ||
logger.info(f"Received message from {client} to update server") | ||
logger.info(f"Message: {message}") | ||
add_file = message.server.add_file_object | ||
if add_file.file_type == FileTypeDC.IFC and add_file.filepath: | ||
tmp_ifc_fp = pathlib.Path(add_file.filepath) | ||
if not tmp_ifc_fp.exists(): | ||
raise FileNotFoundError(f"File not found: {tmp_ifc_fp}") | ||
tmp_sql_fp = tmp_ifc_fp.with_suffix(".sqlite") | ||
|
||
Ifc2SqlPatcher(tmp_ifc_fp, logger, dest_sql_file=tmp_sql_fp).patch() | ||
|
||
server.scene.ifc_sql_store = IfcSqlModel(tmp_sql_fp) | ||
remove_existing_idx = None | ||
for i, fo in enumerate(server.scene.file_objects): | ||
if fo.name == add_file.name: | ||
remove_existing_idx = i | ||
if remove_existing_idx is not None: | ||
server.scene.file_objects.pop(remove_existing_idx) | ||
|
||
server.scene.file_objects.append(add_file) | ||
if add_file.ifcsqlite_file is None: | ||
tmp_sql_fp = tmp_ifc_fp.with_suffix(".sqlite") | ||
Ifc2SqlPatcher(tmp_ifc_fp, logger, dest_sql_file=tmp_sql_fp).patch() | ||
add_file.ifcsqlite_file = FileObjectDC( | ||
name=add_file.name, filepath=tmp_sql_fp, file_type=FileTypeDC.SQLITE, purpose=add_file.purpose | ||
) | ||
|
||
if add_file.glb_file is None: | ||
tmp_glb_fp = tmp_ifc_fp.with_suffix(".glb") | ||
ifc_convert_exe = shutil.which("ifcconvert") | ||
if platform.platform().startswith("Windows"): | ||
ifc_convert_exe = shutil.which("ifcconvert.exe") | ||
|
||
if ifc_convert_exe: | ||
subprocess.run([ifc_convert_exe, tmp_ifc_fp.as_posix(), tmp_glb_fp.as_posix()]) | ||
else: | ||
a = ada.from_ifc(add_file.filepath) | ||
a.to_gltf(tmp_glb_fp) | ||
|
||
add_file.glb_file = FileObjectDC( | ||
name=add_file.name, filepath=tmp_glb_fp, file_type=FileTypeDC.GLB, purpose=add_file.purpose | ||
) | ||
|
||
server.scene.ifc_sql_store = IfcSqlModel(add_file.ifcsqlite_file.filepath) | ||
server.scene.add_file_object(add_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
import io | ||
from typing import TYPE_CHECKING | ||
|
||
import trimesh | ||
|
||
from ada.comms.exceptions import ServerError | ||
from ada.comms.fb_model_gen import ( | ||
CommandTypeDC, | ||
FileObjectDC, | ||
FileTypeDC, | ||
MessageDC, | ||
SceneDC, | ||
ServerReplyDC, | ||
) | ||
from ada.comms.fb_serializer import serialize_message | ||
from ada.config import logger | ||
|
||
if TYPE_CHECKING: | ||
from ada.comms.wsock_server import ConnectedClient, WebSocketAsyncServer | ||
|
||
|
||
def view_file_object(server: WebSocketAsyncServer, client: ConnectedClient, message: MessageDC) -> None: | ||
logger.info(f"Received message from {client} to get file object") | ||
file_object_name = message.server.get_file_object_by_name | ||
result = server.scene.get_file_object(file_object_name) | ||
if result is None: | ||
raise ServerError(f"File object {file_object_name} not found") | ||
|
||
glb_file_obj = result.glb_file | ||
scene = trimesh.load(glb_file_obj.filepath) | ||
with io.BytesIO() as data: | ||
scene.export( | ||
file_obj=data, | ||
file_type="glb", | ||
) | ||
file_object = FileObjectDC( | ||
name=glb_file_obj.name, file_type=FileTypeDC.GLB, purpose=glb_file_obj.purpose, filedata=data.getvalue() | ||
) | ||
|
||
msg = MessageDC( | ||
instance_id=server.instance_id, | ||
command_type=CommandTypeDC.SERVER_REPLY, | ||
server_reply=ServerReplyDC(reply_to=message.command_type, file_object=file_object), | ||
scene=SceneDC(current_file=file_object), | ||
target_id=client.instance_id, | ||
target_group=client.group_type, | ||
) | ||
|
||
fb_message = serialize_message(msg) | ||
asyncio.run(client.websocket.send(fb_message)) |
Oops, something went wrong.