Skip to content

Commit

Permalink
continue work on procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande committed Sep 28, 2024
1 parent 70af6d3 commit 9e6b0f9
Show file tree
Hide file tree
Showing 36 changed files with 715 additions and 478 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/ci-FEM.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,28 @@ jobs:
- name: Set DATE env var
run: echo "DATE=$(echo $(date +'%y%m%d'))" >> $GITHUB_ENV

- uses: prefix-dev/setup-[email protected]
- uses: mamba-org/setup-micromamba@v1 # https://github.com/mamba-org/setup-micromamba
with:
pixi-version: v0.30.0
cache: true
environments: tests
condarc: |
channels:
- https://repo.prefix.dev/code-aster
- conda-forge
environment-file: conda/environment.core.yml
create-args: >-
python=3.12
code-aster=*=*nompi*
paradoc
python-dotenv
pytest
- name: install latest ada-py
run: |
pip install .
- name: Create Verification Report
run: |
pixi run fem-doc
python build_verification_report.py true true --export-format=docx
working-directory: tests/fem

- uses: actions/upload-artifact@v4
if: failure()
Expand Down
2 changes: 2 additions & 0 deletions examples/procedure_example/list_server_procedures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import pathlib

from ada.comms.fb_model_gen import ProcedureStartDC, ParameterDC
from ada.comms.wsock_client_async import WebSocketClientAsync

THIS_DIR = pathlib.Path(__file__).parent
Expand All @@ -10,6 +11,7 @@
async def list_procedures():
async with WebSocketClientAsync("localhost", 8765, "local") as ws_client:
procedures = await ws_client.list_procedures()
await ws_client.run_procedure(ProcedureStartDC("add_stiffeners", [ParameterDC(name="ifc_file", value="MyBaseStructure.ifc")]))
print(procedures)


Expand Down
1 change: 0 additions & 1 deletion examples/procedure_example/start_ws_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ async def start_async_server():

if __name__ == "__main__":
logger.setLevel("DEBUG")
# start_ws_async_server()
asyncio.run(start_async_server())
102 changes: 46 additions & 56 deletions src/ada/comms/fb_deserializer.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
from ada.comms.fb_model_gen import (
CameraParamsDC,
CommandTypeDC,
ErrorDC,
FileObjectDC,
FilePurposeDC,
FileTypeDC,
MeshInfoDC,
MessageDC,
ParameterDC,
ProcedureDC,
ProcedureStoreDC,
SceneOperationDC,
SceneOperationsDC,
TargetTypeDC,
WebClientDC,
)
from ada.comms.wsock import Message

from ada.comms.fb_model_gen import WebClientDC, FileObjectDC, MeshInfoDC, CameraParamsDC, SceneOperationDC, ProcedureStoreDC, ProcedureDC, ParameterDC, ProcedureStartDC, ErrorDC, ServerReplyDC, MessageDC,CommandTypeDC, TargetTypeDC, SceneOperationsDC, FilePurposeDC, FileTypeDC, ProcedureStateDC

def deserialize_webclient(fb_obj) -> WebClientDC | None:
if fb_obj is None:
return None

return WebClientDC(
instance_id=fb_obj.InstanceId(),
name=fb_obj.Name().decode("utf-8") if fb_obj.Name() is not None else None,
address=fb_obj.Address().decode("utf-8") if fb_obj.Address() is not None else None,
port=fb_obj.Port(),
name=fb_obj.Name().decode('utf-8') if fb_obj.Name() is not None else None,
address=fb_obj.Address().decode('utf-8') if fb_obj.Address() is not None else None,
port=fb_obj.Port()
)


Expand All @@ -35,11 +19,11 @@ def deserialize_fileobject(fb_obj) -> FileObjectDC | None:
return None

return FileObjectDC(
name=fb_obj.Name().decode("utf-8") if fb_obj.Name() is not None else None,
name=fb_obj.Name().decode('utf-8') if fb_obj.Name() is not None else None,
file_type=FileTypeDC(fb_obj.FileType()),
purpose=FilePurposeDC(fb_obj.Purpose()),
filepath=fb_obj.Filepath().decode("utf-8") if fb_obj.Filepath() is not None else None,
filedata=bytes(fb_obj.FiledataAsNumpy()) if fb_obj.FiledataLength() > 0 else None,
filepath=fb_obj.Filepath().decode('utf-8') if fb_obj.Filepath() is not None else None,
filedata=bytes(fb_obj.FiledataAsNumpy()) if fb_obj.FiledataLength() > 0 else None
)


Expand All @@ -48,9 +32,9 @@ def deserialize_meshinfo(fb_obj) -> MeshInfoDC | None:
return None

return MeshInfoDC(
object_name=fb_obj.ObjectName().decode("utf-8") if fb_obj.ObjectName() is not None else None,
object_name=fb_obj.ObjectName().decode('utf-8') if fb_obj.ObjectName() is not None else None,
face_index=fb_obj.FaceIndex(),
json_data=fb_obj.JsonData().decode("utf-8") if fb_obj.JsonData() is not None else None,
json_data=fb_obj.JsonData().decode('utf-8') if fb_obj.JsonData() is not None else None
)


Expand All @@ -65,7 +49,7 @@ def deserialize_cameraparams(fb_obj) -> CameraParamsDC | None:
fov=fb_obj.Fov(),
near=fb_obj.Near(),
far=fb_obj.Far(),
force_camera=fb_obj.ForceCamera(),
force_camera=fb_obj.ForceCamera()
)


Expand All @@ -74,7 +58,8 @@ def deserialize_sceneoperation(fb_obj) -> SceneOperationDC | None:
return None

return SceneOperationDC(
operation=SceneOperationsDC(fb_obj.Operation()), camera_params=deserialize_cameraparams(fb_obj.CameraParams())
operation=SceneOperationsDC(fb_obj.Operation()),
camera_params=deserialize_cameraparams(fb_obj.CameraParams())
)


Expand All @@ -83,11 +68,9 @@ def deserialize_procedurestore(fb_obj) -> ProcedureStoreDC | None:
return None

return ProcedureStoreDC(
procedures=(
[deserialize_procedure(fb_obj.Procedures(i)) for i in range(fb_obj.ProceduresLength())]
if fb_obj.ProceduresLength() > 0
else None
)
procedures=[deserialize_procedure(fb_obj.Procedures(i)) for i in range(fb_obj.ProceduresLength())] if fb_obj.ProceduresLength() > 0 else None,
start_procedure=deserialize_procedurestart(fb_obj.StartProcedure()),
state=ProcedureStateDC(fb_obj.State())
)


Expand All @@ -96,21 +79,10 @@ def deserialize_procedure(fb_obj) -> ProcedureDC | None:
return None

return ProcedureDC(
name=fb_obj.Name().decode("utf-8") if fb_obj.Name() is not None else None,
description=fb_obj.Description().decode("utf-8") if fb_obj.Description() is not None else None,
script_file_location=(
fb_obj.ScriptFileLocation().decode("utf-8") if fb_obj.ScriptFileLocation() is not None else None
),
parameters=(
[deserialize_parameter(fb_obj.Parameters(i)) for i in range(fb_obj.ParametersLength())]
if fb_obj.ParametersLength() > 0
else None
),
input_ifc_filepath=fb_obj.InputIfcFilepath().decode("utf-8") if fb_obj.InputIfcFilepath() is not None else None,
output_ifc_filepath=(
fb_obj.OutputIfcFilepath().decode("utf-8") if fb_obj.OutputIfcFilepath() is not None else None
),
error=fb_obj.Error().decode("utf-8") if fb_obj.Error() is not None else None,
name=fb_obj.Name().decode('utf-8') if fb_obj.Name() is not None else None,
description=fb_obj.Description().decode('utf-8') if fb_obj.Description() is not None else None,
script_file_location=fb_obj.ScriptFileLocation().decode('utf-8') if fb_obj.ScriptFileLocation() is not None else None,
parameters=[deserialize_parameter(fb_obj.Parameters(i)) for i in range(fb_obj.ParametersLength())] if fb_obj.ParametersLength() > 0 else None
)


Expand All @@ -119,9 +91,19 @@ def deserialize_parameter(fb_obj) -> ParameterDC | None:
return None

return ParameterDC(
name=fb_obj.Name().decode("utf-8") if fb_obj.Name() is not None else None,
type=fb_obj.Type().decode("utf-8") if fb_obj.Type() is not None else None,
value=fb_obj.Value().decode("utf-8") if fb_obj.Value() is not None else None,
name=fb_obj.Name().decode('utf-8') if fb_obj.Name() is not None else None,
type=fb_obj.Type().decode('utf-8') if fb_obj.Type() is not None else None,
value=fb_obj.Value().decode('utf-8') if fb_obj.Value() is not None else None
)


def deserialize_procedurestart(fb_obj) -> ProcedureStartDC | None:
if fb_obj is None:
return None

return ProcedureStartDC(
procedure_name=fb_obj.ProcedureName().decode('utf-8') if fb_obj.ProcedureName() is not None else None,
parameters=[deserialize_parameter(fb_obj.Parameters(i)) for i in range(fb_obj.ParametersLength())] if fb_obj.ParametersLength() > 0 else None
)


Expand All @@ -130,7 +112,18 @@ def deserialize_error(fb_obj) -> ErrorDC | None:
return None

return ErrorDC(
code=fb_obj.Code(), message=fb_obj.Message().decode("utf-8") if fb_obj.Message() is not None else None
code=fb_obj.Code(),
message=fb_obj.Message().decode('utf-8') if fb_obj.Message() is not None else None
)


def deserialize_serverreply(fb_obj) -> ServerReplyDC | None:
if fb_obj is None:
return None

return ServerReplyDC(
message=fb_obj.Message().decode('utf-8') if fb_obj.Message() is not None else None,
error=deserialize_error(fb_obj.Error())
)


Expand All @@ -147,12 +140,9 @@ def deserialize_message(fb_obj) -> MessageDC | None:
client_type=TargetTypeDC(fb_obj.ClientType()),
scene_operation=deserialize_sceneoperation(fb_obj.SceneOperation()),
target_id=fb_obj.TargetId(),
web_clients=(
[deserialize_webclient(fb_obj.WebClients(i)) for i in range(fb_obj.WebClientsLength())]
if fb_obj.WebClientsLength() > 0
else None
),
web_clients=[deserialize_webclient(fb_obj.WebClients(i)) for i in range(fb_obj.WebClientsLength())] if fb_obj.WebClientsLength() > 0 else None,
procedure_store=deserialize_procedurestore(fb_obj.ProcedureStore()),
server_reply=deserialize_serverreply(fb_obj.ServerReply())
)


Expand Down
43 changes: 23 additions & 20 deletions src/ada/comms/fb_model_gen.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

import pathlib
from dataclasses import dataclass
from enum import Enum
from typing import List, Optional
from dataclasses import dataclass
from typing import Optional, List
import pathlib



class CommandTypeDC(Enum):
Expand All @@ -16,33 +16,35 @@ class CommandTypeDC(Enum):
LIST_WEB_CLIENTS = 6
LIST_FILE_OBJECTS = 7
LIST_PROCEDURES = 8
ERROR = 9
SERVER_REPLY = 10

RUN_PROCEDURE = 9
ERROR = 10
SERVER_REPLY = 11

class TargetTypeDC(Enum):
WEB = 0
LOCAL = 1
SERVER = 2


class SceneOperationsDC(Enum):
ADD = 0
REMOVE = 1
REPLACE = 2


class FilePurposeDC(Enum):
DESIGN = 0
ANALYSIS = 1
FABRICATE = 2


class FileTypeDC(Enum):
IFC = 0
GLB = 1
SQLITE = 2

class ProcedureStateDC(Enum):
IDLE = 0
RUNNING = 1
FINISHED = 2
ERROR = 3

@dataclass
class WebClientDC:
Expand All @@ -51,7 +53,6 @@ class WebClientDC:
address: str = ""
port: int = None


@dataclass
class FileObjectDC:
name: str = ""
Expand All @@ -60,14 +61,12 @@ class FileObjectDC:
filepath: pathlib.Path | str = ""
filedata: bytes = None


@dataclass
class MeshInfoDC:
object_name: str = ""
face_index: int = None
json_data: str = ""


@dataclass
class CameraParamsDC:
position: List[float] = None
Expand All @@ -78,41 +77,44 @@ class CameraParamsDC:
far: float = None
force_camera: bool = None


@dataclass
class SceneOperationDC:
operation: Optional[SceneOperationsDC] = None
camera_params: Optional[CameraParamsDC] = None


@dataclass
class ProcedureStoreDC:
procedures: Optional[List[ProcedureDC]] = None

start_procedure: Optional[ProcedureStartDC] = None
state: Optional[ProcedureStateDC] = None

@dataclass
class ProcedureDC:
name: str = ""
description: str = ""
script_file_location: str = ""
parameters: Optional[List[ParameterDC]] = None
input_ifc_filepath: pathlib.Path | str = ""
output_ifc_filepath: pathlib.Path | str = ""
error: str = ""


@dataclass
class ParameterDC:
name: str = ""
type: str = ""
value: str = ""

@dataclass
class ProcedureStartDC:
procedure_name: str = ""
parameters: Optional[List[ParameterDC]] = None

@dataclass
class ErrorDC:
code: int = None
message: str = ""

@dataclass
class ServerReplyDC:
message: str = ""
error: Optional[ErrorDC] = None

@dataclass
class MessageDC:
Expand All @@ -126,3 +128,4 @@ class MessageDC:
target_id: int = None
web_clients: Optional[List[WebClientDC]] = None
procedure_store: Optional[ProcedureStoreDC] = None
server_reply: Optional[ServerReplyDC] = None
Loading

0 comments on commit 9e6b0f9

Please sign in to comment.