Skip to content

Commit

Permalink
fix(context): Restrict port collection by diagram type
Browse files Browse the repository at this point in the history
Before there was only a generic set of attribute names for ports, which
lead to physical ports (PP) in the context. These are only in the
stylesheet for certain diagrams (e.g. `PAB`). This commit restricts the
used port attribute names from the diagram type.
  • Loading branch information
ewuerger committed Aug 23, 2023
1 parent 1844bea commit b928d3e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
7 changes: 3 additions & 4 deletions capellambse_context_diagrams/collectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion capellambse_context_diagrams/collectors/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down
20 changes: 16 additions & 4 deletions capellambse_context_diagrams/collectors/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b928d3e

Please sign in to comment.