Skip to content

Commit

Permalink
fix: Raise error when attempting to create duplicate element
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Mar 15, 2024
1 parent 20e17ee commit 5f1988b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
13 changes: 4 additions & 9 deletions capella_ros_tools/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def _convert_package(
def _convert_class(
self, pkg_name: str, msg_def: data_model.MessageDef
) -> tuple[dict, list[dict]]:
promise_id = self._register_promise_id(f"{pkg_name}.{msg_def.name}")
promise_id = f"{pkg_name}.{msg_def.name}"
self._promise_ids.add(promise_id)
props = []
associations = []
for field_def in msg_def.fields:
Expand Down Expand Up @@ -176,7 +177,8 @@ def _convert_class(
def _convert_enum(
self, pkg_name: str, enum_def: data_model.EnumDef
) -> dict:
promise_id = self._register_promise_id(f"{pkg_name}.{enum_def.name}")
promise_id = f"{pkg_name}.{enum_def.name}"
self._promise_ids.add(promise_id)
yml = {
"promise_id": promise_id,
"find": {
Expand All @@ -199,13 +201,6 @@ def _convert_enum(

return yml

def _register_promise_id(self, promise_id: str) -> str:
while promise_id in self._promise_ids:
promise_id += "_"

self._promise_ids.add(promise_id)
return promise_id

def to_yaml(self, layer_data_uuid: str, sa_data_uuid: str) -> str:
"""Import ROS messages into a Capella data package."""
logger.info("Generating decl YAML")
Expand Down
26 changes: 16 additions & 10 deletions docs/source/howtos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,41 @@ Import ROS2 Messages:
---------------------
.. code-block:: bash
python -m capella_ros_tools import \
python -m capella_ros_tools \
import \
-i tests/data/data_model/example_msgs \
-m tests/data/empty_project_60 -l la \
--port=5000 --no-deps
-m tests/data/empty_project_60 \
-l la \
--no-deps
Import ROS2 Messages from Git Repository:
-----------------------------------------
.. code-block:: bash
python -m capella_ros_tools import \
python -m capella_ros_tools \
import \
-i git+https://github.com/DSD-DBS/dsd-ros-msg-definitions-oss \
-m tests/data/ empty_project_60 -l la \
--port=5000
-m tests/data/ empty_project_60 \
-l la
Export Capella data package:
------------------------------------
.. code-block:: bash
python -m capella_ros_tools export \
python -m capella_ros_tools \
export \
-m tests/data/melody_model_60 -l la \
-o tests/data/melody_msgs
Export Capella data package from Git Repository:
--------------------------------------------------------
.. code-block:: bash
python -m capella_ros_tools export \
-m git+https://github.com/DSD-DBS/coffee-machine -l oa \
python -m capella_ros_tools \
export \
-m git+https://github.com/DSD-DBS/coffee-machine \
-l oa \
-o tests/data/coffee_msgs
.. note::
When exporting Capella enumerations, if the enumeration literal values are not defined in the Capella model, the values will be set to 0, 1, 2, 3, etc. and the value's type will be set to unit8.
When exporting Capella enumerations, if the enumeration literal values are not defined in the Capella model, the values will be assumed to be 0, 1, 2, 3, etc. and the value's type will be set to unit8.
20 changes: 8 additions & 12 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ Import ROS2 Messages:
----------------------
.. code-block:: bash
python -m capella_ros_tools import -i <INPUT> -m <MODEL> -l <LAYER> -p <PORT> --no-deps
* **-i/--input**, import ROS2 messages from <INPUT>
* **-m/--model**, export to Capella model <CAPELLA_MODEL_PATH>
* **-l/--layer**, use Capella model layer <CAPELLA_MODEL_LAYER>
* **-p/--port**, start Capella model explorer at <PORT> (optional)
* **--no-deps**, do not import ROS2 dependencies (e.g. std_msgs) (flag)

.. note::
The `--port` option can be used to start the Capella model explorer on a specific port. The Capella model viewer can then be downloaded to be viewed at a later time using `wget` eg. `wget http://localhost:<PORT> -E -r`.
python -m capella_ros_tools import -i <INPUT> -m <MODEL> -l <LAYER> -o <OUTPUT> --no-deps
* **-i/--input**, import ROS2 messages from path <INPUT>
* **-m/--model**, write to Capella model at path <MODEL>
* **-l/--layer**, use Capella model layer <LAYER>
* **-o/--out**, write generated decl YAML to path <OUT> (optional)
* **--no-deps**, flag to disable import of ROS2 dependencies (e.g. std_msgs)

Export Capella Model (experimental):
------------------------------------
.. code-block:: bash
python -m capella_ros_tools export -m <MODEL> -l <LAYER> -o <OUTPUT>
* **-m/--model**, import Capella model from <MODEL>
* **-m/--model**, export Capella model from path <MODEL>
* **-l/--layer**, use Capella model layer <LAYER>
* **-o/--output**, export ROS2 messages to <OUTPUT>
* **-o/--output**, write ROS2 messages to <OUTPUT>

0 comments on commit 5f1988b

Please sign in to comment.