Skip to content

filters

Functions and registry for filter functionality.

EX_ITEMS module-attribute ๐Ÿ”—

EX_ITEMS = 'show.exchange.items.filter'

Show ExchangeItems wrapped in [E1,...] and separated by ',' - filter in Capella.

EX_ITEMS_OR_EXCH module-attribute ๐Ÿ”—

EX_ITEMS_OR_EXCH = 'capellambse_context_diagrams-show.exchanges.or.exchange.items.filter'

Show the names of ExchangeItems wrapped in [E1,...] and separated by ',' - Custom filter or the name of the ComponentExchange or FunctionalExchange, not available in Capella.

FILTER_LABEL_ADJUSTERS module-attribute ๐Ÿ”—

FILTER_LABEL_ADJUSTERS: dict[str, Callable[[ModelElement, str | None], str]] = {EX_ITEMS: lambda obj, _: exchange_items(obj), SHOW_EX_ITEMS: exchange_name_and_items, EX_ITEMS_OR_EXCH: lambda obj, label: exchange_items(obj) if getattr(obj, 'exchange_items', '') else label or name, NO_UUID: uuid_filter, SYSTEM_EX_RELABEL: relabel_system_exchange}

Label adjuster registry.

LABEL_CONVERSION module-attribute ๐Ÿ”—

LABEL_CONVERSION: Final[dict[str, str]] = {'AbstractCapabilityExtend': 'extends', 'AbstractCapabilityGeneralization': 'specializes', 'AbstractCapabilityInclude': 'includes', 'CapabilityExploitation': 'exploits', 'CapabilityInvolvement': 'involves', 'EntityOperationalCapabilityInvolvement': 'involves', 'MissionInvolvement': 'involves'}

A map that for relabelling specific ModelObject types.

NO_UUID module-attribute ๐Ÿ”—

NO_UUID = 'capellambse_context_diagrams-hide.uuids.filter'

Filter out UUIDs from label text.

RENDER_ADJUSTERS module-attribute ๐Ÿ”—

RENDER_ADJUSTERS: dict[str, Callable[[bool, ModelElement, dict[str, Any]], None]] = {'sorted_exchangedItems': sort_exchange_items_label}

Available custom render parameter-solvers registry.

SHOW_EX_ITEMS module-attribute ๐Ÿ”—

SHOW_EX_ITEMS = 'show.functional.exchanges.exchange.items.filter'

Show the name of ComponentExchange or FunctionalExchange and its ExchangeItems wrapped in [E1,...] and separated by ',' - filter in Capella.

SYSTEM_EX_RELABEL module-attribute ๐Ÿ”—

SYSTEM_EX_RELABEL = 'capellambse_context_diagrams-relabel.system.analysis.exchange'

Relabel exchanges from the SystemAnalysis layer. E.g. ยซ i ยป is converted to includes or involves, based on the type.

UUID_PTRN module-attribute ๐Ÿ”—

UUID_PTRN = compile('\\s*\\([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\\)')

Regular expression pattern for UUIDs of ModelObjects.

exchange_items ๐Ÿ”—

exchange_items(obj: m.ModelElement) -> str

Return obj's ExchangeItems wrapped in [E1,...] and separated by ','.

Source code in capellambse_context_diagrams/filters.py
56
57
58
59
60
61
62
63
def exchange_items(obj: m.ModelElement) -> str:
    """Return `obj`'s `ExchangeItem`s wrapped in [E1,...] and separated
    by ','.
    """
    assert isinstance(obj, (fa.FunctionalExchange, fa.ComponentExchange))
    if items := ", ".join(item.name for item in obj.exchange_items):
        return f"[{items}]"
    return ""

exchange_name_and_items ๐Ÿ”—

exchange_name_and_items(obj: m.ModelElement, label: str | None = None) -> str

Return obj's name and ExchangeItems if there are any.

Source code in capellambse_context_diagrams/filters.py
66
67
68
69
70
71
72
73
def exchange_name_and_items(
    obj: m.ModelElement, label: str | None = None
) -> str:
    """Return `obj`'s name and `ExchangeItem`s if there are any."""
    label = label or obj.name
    if ex_items := exchange_items(obj):
        label += " " + ex_items
    return label

relabel_system_exchange ๐Ÿ”—

relabel_system_exchange(obj: m.ModelElement, label: str | None) -> str

Return converted label from obj, a system exchanges.

Source code in capellambse_context_diagrams/filters.py
83
84
85
86
87
88
def relabel_system_exchange(obj: m.ModelElement, label: str | None) -> str:
    """Return converted label from obj, a system exchanges."""
    label_map = LABEL_CONVERSION
    if patch := label_map.get(type(obj).__name__):
        return f"ยซ {patch} ยป"
    return label or obj.name

sort_exchange_items_label ๐Ÿ”—

sort_exchange_items_label(value: bool, exchange: m.ModelElement, adjustments: dict[str, t.Any]) -> None

Sort the exchange items in the exchange label if value is true.

Source code in capellambse_context_diagrams/filters.py
107
108
109
110
111
112
113
114
115
116
def sort_exchange_items_label(
    value: bool,
    exchange: m.ModelElement,
    adjustments: dict[str, t.Any],
) -> None:
    """Sort the exchange items in the exchange label if value is true."""
    items = [item.name for item in exchange.exchange_items]
    if value:
        items = sorted(items)
    adjustments["labels_text"] = ", ".join(items)

uuid_filter ๐Ÿ”—

uuid_filter(obj: m.ModelElement, label: str | None = None) -> str

Return obj's name or obj if string w/o UUIDs in it.

Source code in capellambse_context_diagrams/filters.py
76
77
78
79
80
def uuid_filter(obj: m.ModelElement, label: str | None = None) -> str:
    """Return `obj`'s name or `obj` if string w/o UUIDs in it."""
    filtered_label = label if label is not None else obj.name
    assert isinstance(filtered_label, str)
    return UUID_PTRN.sub("", filtered_label)