diff --git a/capellambse_context_diagrams/collectors/__init__.py b/capellambse_context_diagrams/collectors/__init__.py index 319752a4..3d60a7d3 100644 --- a/capellambse_context_diagrams/collectors/__init__.py +++ b/capellambse_context_diagrams/collectors/__init__.py @@ -38,10 +38,9 @@ def get_elkdata( elkdata The data that can be fed into elkjs. """ - - if diagram.type in generic.PORTLESS_DIAGRAM_TYPES: - collector = portless.collector - else: + if generic.DIAGRAM_TYPE_TO_CONNECTOR_NAMES[diagram.type]: collector = default.collector + else: + collector = portless.collector return collector(diagram, params) diff --git a/capellambse_context_diagrams/collectors/default.py b/capellambse_context_diagrams/collectors/default.py index b14b9079..c9785e4f 100644 --- a/capellambse_context_diagrams/collectors/default.py +++ b/capellambse_context_diagrams/collectors/default.py @@ -12,6 +12,7 @@ from capellambse import helpers from capellambse.model import common from capellambse.model.crosslayer import cs, fa +from capellambse.model.modeltypes import DiagramType as DT from .. import _elkjs, context from . import exchanges, generic, makers @@ -22,7 +23,7 @@ def collector( ) -> _elkjs.ELKInputData: """Collect context data from ports of centric box.""" data = generic.collector(diagram, no_symbol=True) - ports = port_collector(diagram.target) + ports = port_collector(diagram.target, diagram.type) centerbox = data["children"][0] centerbox["ports"] = [makers.make_port(i.uuid) for i in ports] connections = port_exchange_collector(ports) @@ -85,13 +86,13 @@ def collector( def port_collector( - target: common.GenericElement | common.ElementList, + target: common.GenericElement | common.ElementList, diagram_type: DT ) -> list[common.GenericElement]: """Savely collect ports from `target`.""" def __collect(target): all_ports: list[common.GenericElement] = [] - for attr in generic.CONNECTOR_ATTR_NAMES | {"ports"}: + for attr in generic.DIAGRAM_TYPE_TO_CONNECTOR_NAMES[diagram_type]: try: ports = getattr(target, attr) if ports and isinstance( diff --git a/capellambse_context_diagrams/collectors/exchanges.py b/capellambse_context_diagrams/collectors/exchanges.py index ee5ec999..c0ce776c 100644 --- a/capellambse_context_diagrams/collectors/exchanges.py +++ b/capellambse_context_diagrams/collectors/exchanges.py @@ -107,7 +107,7 @@ def make_ports_and_update_children_size( elif target in port_ids: inputs.append(target) - if self.diagram.type not in generic.PORTLESS_DIAGRAM_TYPES: + if generic.DIAGRAM_TYPE_TO_CONNECTOR_NAMES[self.diagram.type]: child["ports"] = [ makers.make_port(i) for i in set(inputs + outputs) ] diff --git a/capellambse_context_diagrams/collectors/generic.py b/capellambse_context_diagrams/collectors/generic.py index 42c088f9..955f7656 100644 --- a/capellambse_context_diagrams/collectors/generic.py +++ b/capellambse_context_diagrams/collectors/generic.py @@ -23,11 +23,23 @@ SourceAndTarget = tuple[common.GenericElement, common.GenericElement] - -CONNECTOR_ATTR_NAMES = {"inputs", "outputs", "physical_ports"} +PHYSICAL_CONNECTOR_ATTR_NAMES = {"physical_ports"} +"""Attribute of PhysicalComponents for receiving connections.""" +CONNECTOR_ATTR_NAMES = {"ports", "inputs", "outputs"} """Attribute of GenericElements for receiving connections.""" -PORTLESS_DIAGRAM_TYPES = {DT.OAB, DT.OAIB, DT.OCB, DT.MCB} -"""Supported diagram types without connectors (i.e. ports).""" +DIAGRAM_TYPE_TO_CONNECTOR_NAMES: dict[DT, set[str]] = { + DT.OAB: set(), + DT.OAIB: set(), + DT.OCB: set(), + DT.MCB: set(), + DT.SAB: CONNECTOR_ATTR_NAMES, + DT.SDFB: CONNECTOR_ATTR_NAMES, + DT.LAB: CONNECTOR_ATTR_NAMES, + DT.LDFB: CONNECTOR_ATTR_NAMES, + DT.PAB: CONNECTOR_ATTR_NAMES | PHYSICAL_CONNECTOR_ATTR_NAMES, + DT.PDFB: CONNECTOR_ATTR_NAMES | PHYSICAL_CONNECTOR_ATTR_NAMES, +} +"""Supported diagram types mapping to the attribute name of connectors.""" MARKER_SIZE = 3 """Default size of marker-ends in pixels.""" MARKER_PADDING = makers.PORT_PADDING