Skip to content

Commit

Permalink
fix: Revert add association for every composition
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Mar 12, 2024
1 parent f25dc07 commit c3f6db9
Showing 1 changed file with 5 additions and 36 deletions.
41 changes: 5 additions & 36 deletions capella_ros_tools/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}"
Expand Down

0 comments on commit c3f6db9

Please sign in to comment.