From bb2c0db8493588a67f33f6a3e679a08c026c3e7d Mon Sep 17 00:00:00 2001 From: ewuerger Date: Fri, 2 Feb 2024 17:04:19 +0100 Subject: [PATCH] fix(context): Fix default render styles --- capellambse_context_diagrams/__init__.py | 47 ++++++++++++++++++------ capellambse_context_diagrams/context.py | 4 +- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/capellambse_context_diagrams/__init__.py b/capellambse_context_diagrams/__init__.py index 9ebbcc04..e3786726 100644 --- a/capellambse_context_diagrams/__init__.py +++ b/capellambse_context_diagrams/__init__.py @@ -29,7 +29,7 @@ from capellambse.model.layers import ctx, la, oa, pa from capellambse.model.modeltypes import DiagramType -from . import context +from . import context, styling try: __version__ = metadata.version("capellambse-context-diagrams") @@ -38,7 +38,7 @@ del metadata DefaultRenderParams = dict[str, t.Any] -ClassPair = tuple[ +SupportedClass = tuple[ type[common.GenericElement], DiagramType, DefaultRenderParams ] logger = logging.getLogger(__name__) @@ -58,7 +58,7 @@ def init() -> None: def register_classes() -> None: """Add the `context_diagram` property to the relevant model objects.""" - supported_classes: list[ClassPair] = [ + supported_classes: list[SupportedClass] = [ (oa.Entity, DiagramType.OAB, {}), (oa.OperationalActivity, DiagramType.OAIB, {}), (oa.OperationalCapability, DiagramType.OCB, {}), @@ -67,13 +67,36 @@ def register_classes() -> None: ( ctx.SystemComponent, DiagramType.SAB, - {"display_symbols_as_boxes": True}, + { + "display_symbols_as_boxes": True, + "render_styles": styling.BLUE_ACTOR_FNCS, + }, + ), + ( + ctx.SystemFunction, + DiagramType.SDFB, + {"render_styles": styling.BLUE_ACTOR_FNCS}, + ), + ( + la.LogicalComponent, + DiagramType.LAB, + {"render_styles": styling.BLUE_ACTOR_FNCS}, + ), + ( + la.LogicalFunction, + DiagramType.LDFB, + {"render_styles": styling.BLUE_ACTOR_FNCS}, + ), + ( + pa.PhysicalComponent, + DiagramType.PAB, + {"render_styles": styling.BLUE_ACTOR_FNCS}, + ), + ( + pa.PhysicalFunction, + DiagramType.PDFB, + {"render_styles": styling.BLUE_ACTOR_FNCS}, ), - (ctx.SystemFunction, DiagramType.SDFB, {}), - (la.LogicalComponent, DiagramType.LAB, {}), - (la.LogicalFunction, DiagramType.LDFB, {}), - (pa.PhysicalComponent, DiagramType.PAB, {}), - (pa.PhysicalFunction, DiagramType.PDFB, {}), ] patch_styles(supported_classes) class_: type[common.GenericElement] @@ -82,7 +105,7 @@ def register_classes() -> None: common.set_accessor(class_, ATTR_NAME, accessor) -def patch_styles(classes: cabc.Iterable[ClassPair]) -> None: +def patch_styles(classes: cabc.Iterable[SupportedClass]) -> None: """Add missing default styling to default styles. See Also @@ -174,7 +197,7 @@ def register_realization_view() -> None: Adds ``realization_view`` to Activities, Functions and Components of all layers. """ - supported_classes: list[ClassPair] = [ + supported_classes: list[SupportedClass] = [ (oa.Entity, DiagramType.OAB, {}), (oa.OperationalActivity, DiagramType.OAIB, {}), (ctx.SystemComponent, DiagramType.SAB, {}), @@ -205,7 +228,7 @@ def register_realization_view() -> None: def register_data_flow_view() -> None: - supported_classes: list[ClassPair] = [ + supported_classes: list[SupportedClass] = [ (oa.OperationalCapability, DiagramType.OAIB, {}), # portless (ctx.Capability, DiagramType.SDFB, {}), # default ] diff --git a/capellambse_context_diagrams/context.py b/capellambse_context_diagrams/context.py index b4755337..53b84cb3 100644 --- a/capellambse_context_diagrams/context.py +++ b/capellambse_context_diagrams/context.py @@ -48,7 +48,7 @@ def __init__( self._default_render_params = render_params or {} @t.overload - def __get__(self, obj: None, objtype=None) -> common.Accessor: + def __get__(self, obj: None, objtype: type[t.Any]) -> ContextAccessor: ... @t.overload @@ -260,7 +260,7 @@ def __init__( self.target = obj self.styleclass = class_ - self.render_styles = render_styles or styling.BLUE_ACTOR_FNCS + self.render_styles = render_styles or {} self.serializer = serializers.DiagramSerializer(self) self.__filters: cabc.MutableSet[str] = self.FilterSet(self) self.display_symbols_as_boxes = display_symbols_as_boxes