From c3f6db92fd3cabf15996d899747dd45638a5124e Mon Sep 17 00:00:00 2001 From: huyenngn Date: Tue, 12 Mar 2024 15:29:44 +0100 Subject: [PATCH] fix: Revert add association for every composition --- capella_ros_tools/importer.py | 41 +++++------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/capella_ros_tools/importer.py b/capella_ros_tools/importer.py index 12e8a3d..b110f3f 100644 --- a/capella_ros_tools/importer.py +++ b/capella_ros_tools/importer.py @@ -65,18 +65,12 @@ def _convert_package( classes = [] enums = [] packages = [] - associations = [] for msg_def in pkg_def.messages: + if msg_def.fields: + classes.append(self._convert_class(pkg_def.name, msg_def)) for enum_def in msg_def.enums: enums.append(self._convert_enum(enum_def)) - if not msg_def.fields: - continue - for new_class, associations in self._convert_class( - pkg_def.name, msg_def - ): - classes.append(new_class) - associations.extend(associations) for new_pkg in pkg_def.packages: promise_id = f"{pkg_def.name}.{new_pkg.name}" @@ -100,29 +94,23 @@ def _convert_package( sync["enumerations"] = enums if packages: sync["packages"] = packages - if associations: - sync["associations"] = associations return sync def _convert_class( self, pkg_name: str, msg_def: data_model.MessageDef - ) -> tuple[dict, list[dict]]: + ) -> dict: promise_id = f"{pkg_name}.{msg_def.name}" self._promise_ids.add(promise_id) props = [] - associations = [] - for i, field_def in enumerate(msg_def.fields): + for field_def in msg_def.fields: promise_ref = ( f"{field_def.type.package or pkg_name}.{field_def.type.name}" ) self._promise_id_refs.add(promise_ref) - prop_promise_id = f"{promise_id}.prop{i}" prop_yml = { - "promise_id": prop_promise_id, "name": field_def.name, "type": decl.Promise(promise_ref), - "kind": "COMPOSITION", "description": field_def.description, "min_card": decl.NewObject( "LiteralNumericValue", value=field_def.type.card.min @@ -131,25 +119,6 @@ def _convert_class( "LiteralNumericValue", value=field_def.type.card.max ), } - association_yml = { - "navigable_members": [decl.Promise(prop_promise_id)], - "members": [ - { - "_type": "Property", - "type": decl.Promise(promise_id), - "kind": "ASSOCIATION", - "min_card": decl.NewObject( - "LiteralNumericValue", - value="1", - ), - "max_card": decl.NewObject( - "LiteralNumericValue", - value="1", - ), - }, - ], - } - associations.append(association_yml) if field_def.type.range: prop_yml["min_value"] = decl.NewObject( "LiteralNumericValue", value=field_def.type.range.min @@ -169,7 +138,7 @@ def _convert_class( "properties": props, }, } - return yml, associations + return yml def _convert_enum(self, enum_def: data_model.EnumDef) -> dict: promise_id = f"types.{enum_def.name}"