Skip to content

capellambse_context_diagrams

The Context Diagrams model extension.

This extension adds a new property to many model elements called context_diagram, which allows access automatically generated diagrams of an element's "context".

The context of an element is defined as the collection of the element itself, its ports, the exchanges that flow into or out of the ports, as well as the ports on the other side of the exchange and the ports' direct parent elements.

The element of interest uses the regular styling (configurable via function), other elements use a white background color to distinguish them.

init() 🔗

Initialize the extension.

Source code in capellambse_context_diagrams/__init__.py
62
63
64
65
66
67
68
def init() -> None:
    """Initialize the extension."""
    register_classes()
    register_interface_context()
    register_tree_view()
    register_realization_view()
    register_data_flow_view()

install_elk() 🔗

Install elk.js and its dependencies into the local cache directory.

When rendering a context diagram, elk.js will be installed automatically into a persistent local cache directory. This function may be called while building a container, starting a server or similar tasks in order to prepare the elk.js execution environment ahead of time.

Source code in capellambse_context_diagrams/__init__.py
50
51
52
53
54
55
56
57
58
59
def install_elk() -> None:
    """Install elk.js and its dependencies into the local cache directory.

    When rendering a context diagram, elk.js will be installed
    automatically into a persistent local cache directory. This function
    may be called while building a container, starting a server or
    similar tasks in order to prepare the elk.js execution environment
    ahead of time.
    """
    _elkjs._install_required_npm_pkg_versions()

patch_styles(classes) 🔗

Add missing default styling to default styles.

See Also🔗

[capstyle.get_style][capellambse.aird.capstyle.get_style] : Default style getter.

Source code in capellambse_context_diagrams/__init__.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def patch_styles(classes: cabc.Iterable[SupportedClass]) -> None:
    """Add missing default styling to default styles.

    See Also
    --------
    [capstyle.get_style][capellambse.aird.capstyle.get_style] : Default
        style getter.
    """
    cap: dict[str, CSSdef] = {
        "fill": [COLORS["_CAP_Entity_Gray_min"], COLORS["_CAP_Entity_Gray"]],
        "stroke": COLORS["dark_gray"],
        "text_fill": COLORS["black"],
    }
    capstyle.STYLES["Missions Capabilities Blank"].update(
        {"Box.Capability": cap, "Box.Mission": cap}
    )
    capstyle.STYLES["Operational Capabilities Blank"][
        "Box.OperationalCapability"
    ] = cap
    circle_style = {"fill": COLORS["_CAP_xAB_Function_Border_Green"]}
    for _, dt, _ in classes:
        capstyle.STYLES[dt.value]["Circle.FunctionalExchange"] = circle_style

register_classes() 🔗

Add the context_diagram property to the relevant model objects.

Source code in capellambse_context_diagrams/__init__.py
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def register_classes() -> None:
    """Add the `context_diagram` property to the relevant model objects."""
    supported_classes: list[SupportedClass] = [
        (oa.Entity, DiagramType.OAB, {}),
        (
            oa.OperationalActivity,
            DiagramType.OAB,
            {"display_parent_relation": True},
        ),
        (oa.OperationalCapability, DiagramType.OCB, {}),
        (ctx.Mission, DiagramType.MCB, {}),
        (ctx.Capability, DiagramType.MCB, {"display_symbols_as_boxes": False}),
        (
            ctx.SystemComponent,
            DiagramType.SAB,
            {
                "display_symbols_as_boxes": True,
                "display_parent_relation": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
        (
            ctx.SystemFunction,
            DiagramType.SAB,
            {
                "display_symbols_as_boxes": True,
                "display_parent_relation": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
        (
            la.LogicalComponent,
            DiagramType.LAB,
            {
                "display_symbols_as_boxes": True,
                "display_parent_relation": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
        (
            la.LogicalFunction,
            DiagramType.LAB,
            {
                "display_symbols_as_boxes": True,
                "display_parent_relation": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
        (
            pa.PhysicalComponent,
            DiagramType.PAB,
            {
                "display_parent_relation": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
        (
            pa.PhysicalFunction,
            DiagramType.PAB,
            {
                "display_parent_relation": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
    ]
    patch_styles(supported_classes)
    class_: type[common.GenericElement]
    for class_, dgcls, default_render_params in supported_classes:
        accessor = context.ContextAccessor(dgcls.value, default_render_params)
        common.set_accessor(class_, ATTR_NAME, accessor)

register_functional_context() 🔗

Add the functional_context_diagram attribute to ModelObjects.

Full of bugs

The functional context diagrams will be available soon.

Source code in capellambse_context_diagrams/__init__.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
def register_functional_context() -> None:
    """Add the `functional_context_diagram` attribute to `ModelObject`s.

    !!! bug "Full of bugs"

        The functional context diagrams will be available soon.
    """
    attr_name = f"functional_{ATTR_NAME}"
    supported_classes: list[
        tuple[type[common.GenericElement], DiagramType]
    ] = [
        (oa.Entity, DiagramType.OAB),
        (ctx.SystemComponent, DiagramType.SAB),
        (la.LogicalComponent, DiagramType.LAB),
        (pa.PhysicalComponent, DiagramType.PAB),
    ]
    class_: type[common.GenericElement]
    for class_, dgcls in supported_classes:
        common.set_accessor(
            class_,
            attr_name,
            context.FunctionalContextAccessor(dgcls.value),
        )

register_interface_context() 🔗

Add the context_diagram property to interface model objects.

Source code in capellambse_context_diagrams/__init__.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def register_interface_context() -> None:
    """Add the `context_diagram` property to interface model objects."""
    common.set_accessor(
        oa.CommunicationMean,
        ATTR_NAME,
        context.InterfaceContextAccessor(
            {
                oa.EntityPkg: DiagramType.OAB.value,
                oa.Entity: DiagramType.OAB.value,
            }
        ),
    )
    common.set_accessor(
        fa.ComponentExchange,
        ATTR_NAME,
        context.InterfaceContextAccessor(
            {
                ctx.SystemComponentPkg: DiagramType.SAB.value,
                ctx.SystemComponent: DiagramType.SAB.value,
                la.LogicalComponentPkg: DiagramType.LAB.value,
                la.LogicalComponent: DiagramType.LAB.value,
                pa.PhysicalComponentPkg: DiagramType.PAB.value,
                pa.PhysicalComponent: DiagramType.PAB.value,
            },
        ),
    )

register_realization_view() 🔗

Add the realization_view attribute to various objects.

Adds realization_view to Activities, Functions and Components of all layers.

Source code in capellambse_context_diagrams/__init__.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def register_realization_view() -> None:
    """Add the ``realization_view`` attribute to various objects.

    Adds ``realization_view`` to Activities, Functions and Components
    of all layers.
    """
    supported_classes: list[SupportedClass] = [
        (oa.Entity, DiagramType.OAB, {}),
        (oa.OperationalActivity, DiagramType.OAIB, {}),
        (ctx.SystemComponent, DiagramType.SAB, {}),
        (ctx.SystemFunction, DiagramType.SDFB, {}),
        (la.LogicalComponent, DiagramType.LAB, {}),
        (la.LogicalFunction, DiagramType.LDFB, {}),
        (pa.PhysicalComponent, DiagramType.PAB, {}),
        (pa.PhysicalFunction, DiagramType.PDFB, {}),
    ]
    styles: dict[str, dict[str, capstyle.CSSdef]] = {}
    for class_, dgcls, _ in supported_classes:
        common.set_accessor(
            class_,
            "realization_view",
            context.RealizationViewContextAccessor("RealizationView Diagram"),
        )
        styles.update(capstyle.STYLES.get(dgcls.value, {}))

    capstyle.STYLES["RealizationView Diagram"] = styles
    capstyle.STYLES["RealizationView Diagram"].update(
        capstyle.STYLES["__GLOBAL__"]
    )
    capstyle.STYLES["RealizationView Diagram"]["Edge.Realization"] = {
        "stroke": capstyle.COLORS["dark_gray"],
        "marker-end": "FineArrowMark",
        "stroke-dasharray": "5",
    }

register_tree_view() 🔗

Add the tree_view attribute to Classes.

Source code in capellambse_context_diagrams/__init__.py
221
222
223
224
225
226
227
def register_tree_view() -> None:
    """Add the ``tree_view`` attribute to ``Class``es."""
    common.set_accessor(
        information.Class,
        "tree_view",
        context.ClassTreeAccessor(DiagramType.CDB.value),
    )