Skip to content

helpers

get_model_object 🔗

get_model_object(model: MelodyModel, uuid: str) -> m.ModelElement | None

Try to return a Capella model element.

Source code in src/capellambse_context_diagrams/helpers.py
 8
 9
10
11
12
13
def get_model_object(model: m.MelodyModel, uuid: str) -> m.ModelElement | None:
    """Try to return a Capella model element."""
    try:
        return model.by_uuid(uuid)
    except KeyError:
        return None

has_same_type 🔗

has_same_type(obj1: ModelElement, obj2: ModelElement) -> bool

Check if two model elements have the same type.

Source code in src/capellambse_context_diagrams/helpers.py
16
17
18
def has_same_type(obj1: m.ModelElement, obj2: m.ModelElement) -> bool:
    """Check if two model elements have the same type."""
    return type(obj1).__name__ == type(obj2).__name__

is_allocation 🔗

is_allocation(obj: ModelElement) -> bool

Check if the object is an allocation.

Source code in src/capellambse_context_diagrams/helpers.py
41
42
43
def is_allocation(obj: m.ModelElement) -> bool:
    """Check if the object is an allocation."""
    return obj.xtype is not None and obj.xtype.endswith("PortAllocation")

is_exchange 🔗

is_exchange(obj: ModelElement) -> bool

Check if the object is an exchange.

Source code in src/capellambse_context_diagrams/helpers.py
36
37
38
def is_exchange(obj: m.ModelElement) -> bool:
    """Check if the object is an exchange."""
    return hasattr(obj, "source") and hasattr(obj, "target")

is_function 🔗

is_function(obj: ModelElement) -> bool

Check if the object is a function.

Source code in src/capellambse_context_diagrams/helpers.py
21
22
23
def is_function(obj: m.ModelElement) -> bool:
    """Check if the object is a function."""
    return isinstance(obj, fa.AbstractFunction)

is_functional_chain 🔗

is_functional_chain(obj: ModelElement) -> bool

Check if the object is a functional chain or operational process.

Source code in src/capellambse_context_diagrams/helpers.py
46
47
48
49
50
def is_functional_chain(obj: m.ModelElement) -> bool:
    """Check if the object is a functional chain or operational process."""
    return type(obj).__name__.endswith(
        ("FunctionalChain", "OperationalProcess")
    )

is_part 🔗

is_part(obj: ModelElement) -> bool

Check if the object is a part.

Source code in src/capellambse_context_diagrams/helpers.py
26
27
28
def is_part(obj: m.ModelElement) -> bool:
    """Check if the object is a part."""
    return obj.xtype is not None and obj.xtype.endswith("Part")

is_port 🔗

is_port(obj: ModelElement) -> bool

Check if the object is a port.

Source code in src/capellambse_context_diagrams/helpers.py
31
32
33
def is_port(obj: m.ModelElement) -> bool:
    """Check if the object is a port."""
    return obj.xtype is not None and obj.xtype.endswith("Port")