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 🔗

init() -> None

Initialize the extension.

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

install_elk 🔗

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.

Source code in capellambse_context_diagrams/__init__.py
52
53
54
55
56
57
58
59
60
61
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()

register_cable_tree_view 🔗

register_cable_tree_view() -> None

Add the cable_tree_view attribute to PhysicalLinks.

Source code in capellambse_context_diagrams/__init__.py
306
307
308
309
310
311
312
313
314
315
def register_cable_tree_view() -> None:
    """Add the `cable_tree_view` attribute to `PhysicalLink`s."""
    m.set_accessor(
        cs.PhysicalLink,
        "cable_tree",
        context.CableTreeAccessor(
            DiagramType.PAB.value,
            {},
        ),
    )

register_classes 🔗

register_classes() -> None

Add the context_diagram property to the relevant model objects.

Source code in capellambse_context_diagrams/__init__.py
 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def register_classes() -> None:
    """Add the `context_diagram` property to the relevant model objects."""
    supported_classes: list[SupportedContextClass] = [
        (oa.Entity, DiagramType.OAB, {}),
        (
            oa.OperationalActivity,
            DiagramType.OAB,
            {"display_parent_relation": True},
        ),
        (oa.OperationalCapability, DiagramType.OCB, {}),
        (sa.Mission, DiagramType.MCB, {}),
        (
            sa.Capability,
            DiagramType.MCB,
            {"display_symbols_as_boxes": False},
        ),
        (
            sa.SystemComponent,
            DiagramType.SAB,
            {
                "display_symbols_as_boxes": True,
                "display_parent_relation": True,
                "display_derived_interfaces": True,
                "render_styles": styling.BLUE_ACTOR_FNCS,
            },
        ),
        (
            sa.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,
                "display_derived_interfaces": 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,
                "display_port_labels": True,
                "display_derived_interfaces": True,
            },
        ),
        (pa.PhysicalFunction, DiagramType.PAB, {}),
    ]
    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: dict[str, CSSdef] = {
        "fill": COLORS["_CAP_xAB_Function_Border_Green"],
    }
    class_: type[m.ModelElement]
    for class_, dgcls, default_render_params in supported_classes:
        accessor = context.ContextAccessor(dgcls.value, default_render_params)
        m.set_accessor(class_, ATTR_NAME, accessor)
        capstyle.STYLES[dgcls.value][
            "Circle.FunctionalExchange"
        ] = circle_style

register_functional_context 🔗

register_functional_context() -> None

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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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[m.ModelElement], DiagramType]] = [
        (oa.Entity, DiagramType.OAB),
        (sa.SystemComponent, DiagramType.SAB),
        (la.LogicalComponent, DiagramType.LAB),
        (pa.PhysicalComponent, DiagramType.PAB),
    ]
    class_: type[m.ModelElement]
    for class_, dgcls in supported_classes:
        m.set_accessor(
            class_,
            attr_name,
            context.FunctionalContextAccessor(dgcls.value),
        )

register_interface_context 🔗

register_interface_context() -> None

Add the context_diagram property to interface model objects.

Source code in capellambse_context_diagrams/__init__.py
163
164
165
166
167
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
def register_interface_context() -> None:
    """Add the `context_diagram` property to interface model objects."""
    supported_classes: list[SupportedInterfaceContextClass] = [
        (
            oa.CommunicationMean,
            {
                oa.EntityPkg: DiagramType.OAB.value,
                oa.Entity: DiagramType.OAB.value,
            },
            {"include_interface": True},
        ),
        (
            fa.ComponentExchange,
            {
                sa.SystemComponentPkg: DiagramType.SAB.value,
                sa.SystemComponent: DiagramType.SAB.value,
                la.LogicalComponentPkg: DiagramType.LAB.value,
                la.LogicalComponent: DiagramType.LAB.value,
                pa.PhysicalComponentPkg: DiagramType.PAB.value,
                pa.PhysicalComponent: DiagramType.PAB.value,
            },
            {"include_interface": True, "include_port_allocations": True},
        ),
        (
            cs.PhysicalLink,
            {
                sa.SystemComponentPkg: DiagramType.SAB.value,
                sa.SystemComponent: DiagramType.SAB.value,
                la.LogicalComponentPkg: DiagramType.LAB.value,
                la.LogicalComponent: DiagramType.LAB.value,
                pa.PhysicalComponentPkg: DiagramType.PAB.value,
                pa.PhysicalComponent: DiagramType.PAB.value,
            },
            {"include_interface": True, "display_port_labels": True},
        ),
    ]
    class_: type[m.ModelElement]
    for class_, dgclasses, default_render_params in supported_classes:
        accessor = context.InterfaceContextAccessor(
            dgclasses, default_render_params
        )
        m.set_accessor(class_, ATTR_NAME, accessor)

    port_alloc_output_style: dict[str, CSSdef] = {
        "fill": COLORS["_CAP_xAB_Function_Border_Green"],
        "stroke": COLORS["_CAP_xAB_Function_Border_Green"],
        "stroke-dasharray": "2",
        "text_fill": COLORS["black"],
    }
    port_alloc_input_style: dict[str, CSSdef] = {
        "fill": COLORS["dark_orange"],
        "stroke": COLORS["dark_orange"],
        "stroke-dasharray": "2",
        "text_fill": COLORS["black"],
    }
    for dt in (DiagramType.SAB, DiagramType.LAB, DiagramType.PAB):
        capstyle.STYLES[dt.value][
            "Edge.PortInputAllocation"
        ] = port_alloc_input_style
        capstyle.STYLES[dt.value][
            "Edge.PortOutputAllocation"
        ] = port_alloc_output_style

register_realization_view 🔗

register_realization_view() -> None

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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
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[SupportedContextClass] = [
        (oa.Entity, DiagramType.OAB, {}),
        (oa.OperationalActivity, DiagramType.OAIB, {}),
        (sa.SystemComponent, DiagramType.SAB, {}),
        (sa.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:
        m.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 🔗

register_tree_view() -> None

Add the tree_view attribute to Classes.

Source code in capellambse_context_diagrams/__init__.py
250
251
252
253
254
255
256
def register_tree_view() -> None:
    """Add the ``tree_view`` attribute to ``Class``es."""
    m.set_accessor(
        information.Class,
        "tree_view",
        context.ClassTreeAccessor(DiagramType.CDB.value),
    )