Skip to content

tree_view

Collector for the Class-Tree diagram.

ClassInfo dataclass 🔗

ClassInfo(
    source: Class,
    target: Class | None,
    prop: Property | None,
    partition: int,
    multiplicity: tuple[str, str] | None,
    generalizes: Class | None = None,
    primitive: bool = False,
)

All information needed for a Class box.

collector 🔗

collector(
    diagram: ClassTreeDiagram, params: dict[str, Any]
) -> tuple[_elkjs.ELKInputData, _elkjs.ELKInputData]

Return the class tree data for ELK.

Source code in src/capellambse_context_diagrams/collectors/tree_view.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
def collector(
    diagram: context.ClassTreeDiagram, params: dict[str, t.Any]
) -> tuple[_elkjs.ELKInputData, _elkjs.ELKInputData]:
    """Return the class tree data for ELK."""
    del params
    assert isinstance(diagram.target, information.Class)
    processor = ClassProcessor(diagram)
    for _, cls in get_all_classes(
        diagram.target,
        max_partition=diagram._depth,
        super=diagram._super,
        sub=diagram._sub,
    ):
        processor.process_class(cls)

    legend = _makers.make_diagram(diagram)
    legend.layoutOptions = copy.deepcopy(_elkjs.RECT_PACKING_LAYOUT_OPTIONS)  # type: ignore[arg-type]
    legend.children = processor.legend_boxes
    return processor.data, legend

get_all_classes 🔗

get_all_classes(
    root: Class,
    partition: int = 0,
    classes: dict[str, ClassInfo] | None = None,
    max_partition: int | None = None,
    super: Literal["ROOT"] | Literal["ALL"] = "ALL",
    sub: Literal["ROOT"] | Literal["ALL"] = "ALL",
) -> cabc.Iterator[tuple[str, ClassInfo]]

Yield all classes of the class tree.

Source code in src/capellambse_context_diagrams/collectors/tree_view.py
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def get_all_classes(
    root: information.Class,
    partition: int = 0,
    classes: dict[str, ClassInfo] | None = None,
    max_partition: int | None = None,
    super: t.Literal["ROOT"] | t.Literal["ALL"] = "ALL",
    sub: t.Literal["ROOT"] | t.Literal["ALL"] = "ALL",
) -> cabc.Iterator[tuple[str, ClassInfo]]:
    """Yield all classes of the class tree."""
    partition += 1
    classes = classes or {}
    if max_partition is not None and partition > max_partition:
        return

    for prop in root.owned_properties:
        property = _PropertyInfo(
            root, prop, partition, classes, None, max_partition, super, sub
        )
        process_property(property)

    if (
        (super == "ALL" or (super == "ROOT" and partition == 1))
        and isinstance(root.super, information.Class)
        and not root.super.is_primitive
    ):
        for prop in root.super.owned_properties:
            process_property(
                _PropertyInfo(
                    root.super,
                    prop,
                    partition + 1,
                    classes,
                    root,
                    max_partition,
                    super,
                    sub,
                )
            )

        if (edge_id := f"{root.uuid} {root.super.uuid}") not in classes:
            classes[edge_id] = _make_class_info(
                root.super,
                None,
                partition,
                generalizes=root,
            )
            classes.update(
                get_all_classes(
                    root.super,
                    partition,
                    classes,
                    max_partition,
                    super,
                    sub,
                )
            )

    if sub == "ALL" or (sub == "ROOT" and partition == 1):
        for cls in root.sub:
            assert isinstance(cls, information.Class)
            if cls.is_primitive:
                continue

            for prop in cls.owned_properties:
                process_property(
                    _PropertyInfo(
                        cls,
                        prop,
                        partition,
                        classes,
                        None,
                        max_partition,
                        super,
                        sub,
                    )
                )

            if (edge_id := f"{root.uuid} {cls.uuid}") not in classes:
                classes[edge_id] = _make_class_info(
                    root, None, partition, generalizes=cls
                )
                classes.update(
                    get_all_classes(
                        cls, partition, classes, max_partition, super, sub
                    )
                )

    yield from classes.items()

process_property 🔗

process_property(property: _PropertyInfo) -> None

Process a single property for class information.

Source code in src/capellambse_context_diagrams/collectors/tree_view.py
221
222
223
224
225
226
227
228
229
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
def process_property(
    property: _PropertyInfo,
) -> None:
    """Process a single property for class information."""
    prop = property.prop
    if not prop.type:
        logger.debug("Ignoring property without type: %s", prop._short_repr_())
        return

    if not isinstance(prop.type, information.Class) or prop.type.is_primitive:
        logger.debug("Ignoring non-class property: %s", prop._short_repr_())
        return

    if (
        property.max_partition is not None
        and property.partition > property.max_partition
    ):
        return

    edge_id = f"{property.source.uuid} {prop.uuid} {prop.type.uuid}"
    if edge_id not in property.classes:
        property.classes[edge_id] = _make_class_info(
            property.source,
            prop,
            property.partition,
            generalizes=property.generalizes,
        )
        property.classes.update(
            get_all_classes(
                prop.type,
                property.partition,
                property.classes,
                property.max_partition,
                property.super,
                property.sub,
            )
        )